From d349cc66b76a6d545c920688a6f70186a8235c06 Mon Sep 17 00:00:00 2001 From: Salhi-zh Date: Fri, 30 Oct 2026 15:01:16 +0100 Subject: [PATCH] cli: stop storing the turn's run state in chat message metadata Each completed turn attached the entire final RunState to its AI message under metadata.runState. Nothing ever reads it back, so after N turns the chat store and chat-messages.json held N full snapshots whose individual size grows with N: O(N^2) in RAM and in every checkpoint's JSON.stringify, which adds up to hundreds of MB in long sessions. Drop the payload from markComplete. The type field stays, deprecated rather than removed: transcripts persisted by older versions carry the key, and the load path only JSON.parses and shape-checks the messages array, so a stale field is simply ignored. --- cli/src/hooks/__tests__/use-send-message.test.tsx | 1 - cli/src/hooks/helpers/send-message.ts | 3 --- cli/src/types/chat.ts | 3 ++- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/cli/src/hooks/__tests__/use-send-message.test.tsx b/cli/src/hooks/__tests__/use-send-message.test.tsx index b37f99c614..c070f4314f 100644 --- a/cli/src/hooks/__tests__/use-send-message.test.tsx +++ b/cli/src/hooks/__tests__/use-send-message.test.tsx @@ -262,7 +262,6 @@ describe('useSendMessage continuation state', () => { content: finalText, }) expect(saved.isComplete).toBe(true) - expect(saved.metadata.runState).toEqual(finalState) } finally { settlePendingRuns() await run diff --git a/cli/src/hooks/helpers/send-message.ts b/cli/src/hooks/helpers/send-message.ts index f8e91a4ffd..9a21baa2f1 100644 --- a/cli/src/hooks/helpers/send-message.ts +++ b/cli/src/hooks/helpers/send-message.ts @@ -487,9 +487,6 @@ export const handleRunCompletion = (params: { updater.markComplete({ ...(completionTime && { completionTime }), ...(actualCredits !== undefined && { credits: actualCredits }), - metadata: { - runState, - }, }) } diff --git a/cli/src/types/chat.ts b/cli/src/types/chat.ts index e3d1f7b5f0..e092893e09 100644 --- a/cli/src/types/chat.ts +++ b/cli/src/types/chat.ts @@ -243,7 +243,8 @@ export type ChatMessageMetadata = { isCollapsed?: boolean /** Whether the user manually opened this collapsed item */ userOpened?: boolean - /** RunState stored after completion */ + /** @deprecated Never written; older transcripts may still carry it and it + * is ignored on load. */ runState?: unknown }