fix: auto-extend compression ranges to prevent splitting tool_use/tool_result pairs (Issue #247) - #248
Merged
Merged
Conversation
…l_result pairs (Issue #247)
…ry kind Oracle review found tier misclassification risk: block anchors are compress tool_use messages (have callIDs), so forward scan would flip endReference.kind from 'compressed-block' to 'message', corrupting tier detection (T2 → T1). Two fixes: 1. Exclude 'compress' tool callIDs from the scan (compress is always force-protected, pairs survive intact regardless) 2. Only extend MESSAGE boundaries, not block boundaries (defense in depth) Added 2 tests: - block boundary: kind preserved (b1→b1 T2 distillation) - compress tool excluded from scan (message boundary with compress calls)
This was referenced Jul 30, 2026
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
Fixes #247 — compression ranges can split tool_use/tool_result pairs, creating orphaned references that cause provider API rejection.
Problem: When a compression range includes a tool_use (assistant) but not its tool_result (user), or vice versa, the pruned output has an orphaned
tool_use_id/tool_result_idreference → provider API rejects:"tool_result block does not have a corresponding tool_use".Fix:
adjustBoundariesForToolPairsinlib/compress/search.tsauto-extends range boundaries to include paired messages:callIDs in the rangeOracle Review Fixes (commit 2)
Oracle review found tier misclassification risk: block anchors are compress tool_use messages (have callIDs), so forward scan would flip
endReference.kindfrom"compressed-block"to"message", corrupting tier detection inapplyCompressionState(T2 → T1).Two fixes:
compresstool from scan:compressis always force-protected, its pairs survive intact regardless — no need to adjust for themTest Coverage (11 tests)
CI
All 5 checks pass: pr-validation ✓, test (22) ✓, test (24) ✓, build ✓, e2e ✓
949 tests (0 failures).