fix(cli): prevent context drops from stale partial message updates #5212
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.
Summary
Fixes a bug in the CLI where delayed IPC messages with
partial=truecould overwrite completed messages, causing context loss during active sessions.Problem
Users reported that the CLI "constantly drops context" making it unreliable. The context drops happened randomly during active sessions.
Root Cause
In
updateChatMessageByTsAtom, when a delayed IPC message withpartial=truearrived after a message had already been completed (partial=false), the stale update would overwrite the completed message:{text: "Complete content here", partial: false}{text: "Partial", partial: true}Solution
Added a check in
updateChatMessageByTsAtomto prevent stale partial updates from overwriting completed messages:Testing
Files Changed
cli/src/state/atoms/extension.ts- Added the fixcli/src/state/atoms/__tests__/extension-context-drop.test.ts- Updated test to verify fixcli/src/state/atoms/__tests__/message-reconciliation.test.ts- Updated 2 testscli/src/state/atoms/__tests__/CLI_CONTEXT_DROP_INVESTIGATION.md- Investigation documentation