Repository navigation
cli: stop storing the turn's run state in chat message metadata - #1583
Merged
obadakhalili merged 1 commit intoOct 30, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Each completed turn attached the entire final
RunStateto its AI message undermetadata.runState(cli/src/hooks/helpers/send-message.ts). Nothing ever reads it back — a grep formetadata?.runStateoutside tests returns zero hits.Cost
After N turns, the chat store and
chat-messages.jsonhold N full snapshots whose individual size grows with N: O(N²) in RAM and in every checkpoint'sJSON.stringify. In a long session (30+ turns, ~25 MB mid-session snapshot) that's hundreds of MB retained and re-serialized on every checkpoint drain.Change
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 onlyJSON.parses + shape-checks the messages array, so a stale field is safely ignored.Safety
use-send-message.test.tsxand is removed with the write.chatStore.runState, set separately (use-send-message.ts); resume-on-error flows go through the checkpoint path (scheduleCheckpointSave), not this field.Tests
bun run typecheckclean; fullbun test— 4332 pass / 46 skip / 0 fail (same totals asmain).