From 22605de0816a09a90058306ec614ea375ede67cc Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Mon, 22 Jun 2026 14:18:56 +0900 Subject: fix: trim provisional chunks during long turns (browser stays responsive) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit trimTranscript now drops oldest provisional chunks (the in-flight turn) when committed chunks are exhausted. Previously it bailed with drop=0 when committed was empty, allowing unbounded provisional growth during long generating turns (300+ chunks → browser crawls). Root cause of the syncTail approach failing: the kernel emits step-complete (line 360) BEFORE calling onStepComplete (line 542) — chunks are persisted only after tool results come back, not when step-complete fires. So syncTail on step-complete found nothing. Reverted the applyHistory + syncTail-on-step-complete changes from d354626. The new approach is simpler: trim provisional directly in trimTranscript. Dropped chunks are lost temporarily (no Show Earlier) but come back as committed when the turn seals and syncTail fetches everything from the server. 686 tests green. --- src/core/chunks/reducer.ts | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/core/chunks/reducer.ts') diff --git a/src/core/chunks/reducer.ts b/src/core/chunks/reducer.ts index 37f0164..035846c 100644 --- a/src/core/chunks/reducer.ts +++ b/src/core/chunks/reducer.ts @@ -54,10 +54,8 @@ export function applyHistory( ): TranscriptState { const seqMap = new Map(); for (const c of state.committed) seqMap.set(c.seq, c); - let addedNew = false; for (const c of chunks) { if (c.seq < state.hiddenBeforeSeq) continue; - if (!seqMap.has(c.seq)) addedNew = true; seqMap.set(c.seq, c); } const committed = Array.from(seqMap.values()).sort((a, b) => a.seq - b.seq); @@ -72,15 +70,6 @@ export function applyHistory( }; } - // During generation: if new committed chunks arrived (CR-6 — backend - // persists at step boundaries), clear provisional chunks. They're - // duplicates — the same content was folded from live events but is now - // persisted with seq. Keep the accumulating chunk (current in-progress - // step, not yet persisted). - if (addedNew && state.generating) { - return { ...state, committed, provisional: [], accumulating: state.accumulating }; - } - return { ...state, committed }; } -- cgit v1.2.3