Repository navigation
Conversation
runCompression built its summarization prompt from the entire compress zone (msgs[frozenEnd:compressEnd]) with no upper bound on its size. That zone's size is otherwise unconstrained -- it holds whatever accumulated between the frozen and active zones, which can include many rounds of tool-call output (e.g. broad code_search/file_read results across a large repository). When that content grows large enough, the resulting compression request can itself exceed the model's real context window, so the LLM call fails outright and the whole review aborts instead of compressing. Reproduced against a real Azure-hosted DeepSeek deployment: a single compression request grew to ~1.26M tokens against a 1,048,576-token model context limit, and Azure rejected it with a deterministic "input longer than context length" 400 -- which open-code-review then surfaces as an opaque "Context compression exceeded threshold, stopping" and fails every file in the review. Add boundCompressZoneStart, which trims the compress zone from its oldest end until it fits a fixed maxCompressionContextTokens ceiling (200K, independent of the per-file MaxTokens template setting and sized well under real-world model context windows), always keeping at least the single newest message so the summarization call is never left with an empty range. A <truncation_notice> is prepended when trimming occurs. Verified: existing internal/llmloop tests + new TestBoundCompressZoneStart_* pass; a full `go build ./...` is clean; and the original reproduction (previously a guaranteed 400 on the first or second compression attempt) now completes every compression call successfully, with the new truncation path visibly engaging on requests that would otherwise have overflowed. This addresses the unbounded-compress-zone-size symptom described in alibaba#838 (an oversized compression request can be produced when the compress zone's own accounting lets it grow past any sane threshold). It does not claim to resolve every defect reported in alibaba#838 -- I did not independently verify the "everything fits but still gets marked for compression" or "template-less truncation" cases described there, so this is a partial, defensively-scoped fix for the specific failure mode above rather than a full fix for that issue. Relates to alibaba#838 Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ANbui63NSJjCE9AZVsBk12
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
6 of 8 tasks
This branch has not been deployed
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
runCompressionbuilds its summarization prompt from the entire compress zone (msgs[frozenEnd:compressEnd]) with no upper bound on size. That zone is otherwise unconstrained — it holds whatever accumulated between the frozen and active zones, which can include many rounds of tool-call output (e.g. broadcode_search/file_readresults across a large repository). When that content grows large enough, the resulting compression request can itself exceed the model's real context window, so the LLM call fails outright and the whole review aborts instead of compressing.Reproduced against a real Azure-hosted DeepSeek deployment: a single compression request grew to ~1.26M tokens against a 1,048,576-token model context limit. Azure rejected it with a deterministic
"input longer than context length"400, whichopen-code-reviewthen surfaces as an opaque"Context compression exceeded threshold, stopping"and fails every file in the review.This is a real-world production failure I hit and traced end-to-end (proxied/captured the actual outgoing request and Azure's response to confirm the exact byte size and error).
Fix
Adds
boundCompressZoneStart, which trims the compress zone from its oldest end until it fits a fixedmaxCompressionContextTokensceiling (200K — independent of the per-fileMaxTokenstemplate setting, and sized well under real-world model context windows), always keeping at least the single newest message so the summarization call never ends up with an empty range. A<truncation_notice>is prepended when trimming occurs, so the summary's consumer knows some history was dropped rather than summarized.Relation to #838
This addresses the unbounded-compress-zone-size symptom described in #838 — an oversized compression request can be produced when the compress zone's own accounting lets it grow past any sane threshold. I have not independently verified the "everything fits but still gets marked for compression" or "template-less truncation" cases also described in that issue, so I'm not claiming this closes #838 outright — it's a defensively-scoped fix for the specific failure mode above.
Testing
internal/llmlooptest suite passes unchanged.TestBoundCompressZoneStart_EverythingFits,TestBoundCompressZoneStart_TrimsOldestFirst,TestBoundCompressZoneStart_SingleMessageExceedsLimit.go build ./...is clean.