Skip to content

cli: stop storing the turn's run state in chat message metadata - #1583

Merged
obadakhalili merged 1 commit into
CodebuffAI:mainfrom
Salhi-zh:cli/drop-turn-runstate-metadata
Oct 30, 2026
Merged

obadakhalili merged 1 commit into
CodebuffAI:mainfrom
Salhi-zh:cli/drop-turn-runstate-metadata

Conversation

@Salhi-zh

Copy link
Copy Markdown
Contributor

What

Each completed turn attached the entire final RunState to its AI message under metadata.runState (cli/src/hooks/helpers/send-message.ts). Nothing ever reads it back — a grep for metadata?.runState outside tests returns zero hits.

Cost

After N turns, the chat store and chat-messages.json hold N full snapshots whose individual size grows with N: O(N²) in RAM and in every checkpoint's JSON.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 only JSON.parses + shape-checks the messages array, so a stale field is safely ignored.

Safety

  • No production reader exists (grep-verified); the only assertion was in use-send-message.test.tsx and is removed with the write.
  • The authoritative live state is chatStore.runState, set separately (use-send-message.ts); resume-on-error flows go through the checkpoint path (scheduleCheckpointSave), not this field.

Tests

bun run typecheck clean; full bun test — 4332 pass / 46 skip / 0 fail (same totals as main).

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.
@obadakhalili
obadakhalili merged commit 0078695 into CodebuffAI:main Oct 30, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants