From 271d56d4e038b6260acb60b869ed2df92e230e1c Mon Sep 17 00:00:00 2001 From: Jonas Heller <168646044+jheller1212@users.noreply.github.com> Date: Wed, 24 Jun 2026 20:53:32 +0200 Subject: [PATCH] Stagger the first turn of each run to de-burst synchronized starts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When ~30 participants click Start on the same cue, all fire their first provider request at the same instant — a burst the shared key can't absorb before any backoff kicks in. Add a short random delay (0-1.2s) before the opening turn so the initial wave fans out. Only the first turn of a run is staggered; respects Stop. --- src/hooks/useConversationEngine.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hooks/useConversationEngine.ts b/src/hooks/useConversationEngine.ts index 5944ac3..37533fc 100644 --- a/src/hooks/useConversationEngine.ts +++ b/src/hooks/useConversationEngine.ts @@ -273,6 +273,15 @@ export function useConversationEngine(opts: ConversationEngineOptions) { localConversationId: string, bot1StartsFirst: boolean, ) => { + // De-burst synchronized starts: when many participants click Start on the + // same cue (e.g. instructor says "go"), a short random delay before the + // first turn fans the initial requests out across the shared key instead of + // all hitting on the same beat. Only the opening turn of a run is staggered. + if (repetitionIndex === 0) { + await new Promise(resolve => setTimeout(resolve, Math.round(Math.random() * 1200))); + if (isStoppedRef.current) { setIsLoading(false); return; } + } + const dbConversationId = await createConversationRecord(userMsg, localConversationId); trackEvent(opts.userId, 'conversation_started', {