From 4e1d041c0ee34fa1b74b0d5ecbd432cdacf696e9 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Mon, 22 Jun 2026 14:07:30 +0900 Subject: feat: trim chunks during generation via step-complete syncTail (CR-6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The backend now persists chunks at step boundaries during generation (CR-6). The FE calls syncTail on each step-complete event to fetch the newly committed chunks. applyHistory clears the provisional array when new committed chunks arrive mid-generation (they're duplicates of what was folded from live events). The accumulating chunk (current in-progress step) is kept. This means trimTranscript can now drop oldest committed chunks uniformly during a long turn — no unbounded provisional growth. The browser never holds more than chatLimit chunks, even mid-generation. 3 new tests: clears provisional on new committed during generation, keeps provisional when no new chunks, keeps accumulating when clearing. 689 tests green. --- src/features/chat/store.svelte.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/features/chat') diff --git a/src/features/chat/store.svelte.ts b/src/features/chat/store.svelte.ts index 9beabfc..f6c23fc 100644 --- a/src/features/chat/store.svelte.ts +++ b/src/features/chat/store.svelte.ts @@ -284,6 +284,11 @@ export function createChatStore(deps: ChatStoreDependencies): ChatStore { if (transcript.sealedTurnId !== null) { void syncTail(); void syncMetrics(); + } else if (msg.event.type === "step-complete") { + // CR-6: backend persists chunks at step boundaries. Fetch them + // as committed so trimTranscript can unload oldest chunks + // uniformly — no unbounded provisional growth during long turns. + void syncTail(); } }, -- cgit v1.2.3