-
Notifications
You must be signed in to change notification settings - Fork 29
🤖 fix: cancel active stream on message edit to prevent history corruption #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+19
−6
Conversation
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
95330d5 to
d76e129
Compare
…tion When editing a compacting message to change parameters (e.g., token count) while the first compaction is still streaming, the old stream would continue and corrupt the chat history by replacing everything with [truncated]. Root cause: handleCompletion would find the NEW compaction request in history and proceed to perform compaction with the OLD stream's partial summary. Fix: Cancel any active stream before processing edits. This ensures only one stream runs at a time and aligns with user intent (edit = discard old). Impact: 9 lines added to agentSession.ts sendMessage method
d76e129 to
753b35f
Compare
Critical fix: interruptStream now deletes the partial when abandonPartial=true, mirroring the IPC handler pattern. Without this, the partial would be committed by streamWithHistory's unconditional commitToHistory call, reintroducing the cancelled assistant response into history. This completes the fix for editing compacting messages - now the cancelled output is truly discarded instead of being appended after truncation.
interruptStream() now owns the complete interrupt flow including partial deletion. The IPC handler is now a thin wrapper that delegates fully. This eliminates duplication - previously both layers were deleting the partial when abandonPartial=true, making two calls to deletePartial() for IPC-triggered interrupts (though the second was idempotent). Single source of truth: AgentSession.interruptStream() handles everything.
dde0c5f to
73d8397
Compare
Member
Author
|
@codex review |
Critical fix: Reordered operations in interruptStream to delete partial.json BEFORE calling stopStream. This prevents the abort handler (which runs immediately when stopStream is called) from committing the partial back to history. Previous order (buggy): 1. stopStream → abort handler commits partial 2. delete partial (too late) New order (correct): 1. delete partial 2. stopStream → abort handler finds no partial to commit This completes the fix for editing mid-stream - now the cancelled content truly stays deleted instead of being reintroduced by the abort handler.
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.
Problem
While trying to edit the token count of a running compaction request, the entire chat history was replaced with
[truncated].Root Cause
When editing a compacting message while the first compaction stream is still running:
handleCompletionreads the current historyprocessedCompactionRequestIds, it proceeds to perform compaction[truncated]Solution
Cancel any active stream before processing message edits in
AgentSession.sendMessage:This ensures:
Changes
Testing
Generated with
mux