fix(claudecode): handle mid-turn compaction events in readLoop#483
Open
fix(claudecode): handle mid-turn compaction events in readLoop#483
Conversation
Add two improvements to handle Claude Code's context compaction events: 1. Add default case in event switch to log unknown event types for diagnostic purposes. Previously, unknown events were silently dropped. 2. Handle compaction result events by checking subtype field. When Claude Code emits a result event with subtype "compact" or "compaction", it indicates mid-turn context compression, not turn completion. These events now set Done=false so the event loop continues processing. This prevents premature task interruption when Claude Code performs automatic context compression during long turns. Changes: - Add default case with debug logging for unknown event types - Add subtype detection in handleResult for compaction events - Set Done=false for compaction result events - Add tests for Done field behavior Closes #481 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chenhg5
commented
Apr 7, 2026
Owner
Author
chenhg5
left a comment
There was a problem hiding this comment.
LGTM. Correctly handles compaction events by checking subtype field, preventing premature turn interruption. Good diagnostic logging for unknown events.
Owner
Author
|
QA Review: ✅ LGTM
Ready for self-approval or external reviewer. |
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.
Summary
subtypefield (compactorcompaction)Done=falsefor compaction result events so the event loop continues processingProblem
When Claude Code performs automatic context compaction mid-turn, cc-connect could misinterpret compaction-related events as turn completion, causing the task to be interrupted prematurely. Unknown event types were silently dropped, making diagnosis difficult.
Solution
subtype: "compact"orsubtype: "compaction"are treated as intermediate events (Done=false), not turn completionTest plan
go build ./agent/claudecode/...passesgo vet ./agent/claudecode/...passesgo test ./agent/claudecode/...passesCloses #481
🤖 Generated with Claude Code