You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory compression serializes an unbounded input even after the context threshold is exceeded #1876
Memory compression serializes an unbounded input even after the context threshold is exceeded
Verified in the v1.13.0 pin 1672852136fc87748249d22bce0819f33419ea79: compression.go, runCompression/buildMessageXML. Related #1171 discusses grouping; this concerns the compression request's own input.
runCompression partitions the conversation and serializes every message in the compress zone with buildMessageXML. It substitutes that XML into the compression template and sends the resulting request without checking its total input bytes/tokens. MaxTokens on ChatRequest bounds completion output, not this input. If a tool result includes a large line, the request intended to reduce context can itself exceed the provider context limit.
Suggested deterministic regression: construct a conversation with a system/user pair and tool rounds containing a 170 KB one-line result; use a fake LLM client that records request sizes and rejects requests above a small configured input budget. Assert that the compression payload stays within its explicit input bound or returns an explicit incomplete/compression-budget outcome before calling the fake client. Cover template overhead, reasoning and tool-call serialization as well as visible content.
Please define a configurable compression-input byte/token bound and an explicit policy for oversized history (bounded chunks or a reported incomplete outcome), preserving source context rather than silently pretending omitted history was reviewed. The scan-only MAX_FILE_SIZE_BYTES setting does not constrain this review compression path.
Prepared with Codex assistance; source inspected at the pinned commit. No private source, endpoint, request identifier or credential is included.
Thanks for the detailed report and the deterministic regression suggestion.
I opened #1893 to bound the compression request's own input. runCompression now runs the compress zone through boundCompressZoneInput before buildMessageXML, capping the serialized input at MaxContextTokens × 4 bytes. The largest message is truncated first with an explicit ... (truncated) suffix, so small messages keep their full content and the summarizer can see that source content was elided rather than silently pretending the full history was reviewed.
Two notes on implementation choices, for visibility:
I used a byte ceiling rather than a token estimate. CountTokens re-encodes the entire prefix on every call and takes ~10s on a single 170 KB one-line result, which would make the check itself a performance hazard on exactly the inputs it is meant to guard. A byte bound is O(1) and deterministic.
I reused the existing context ceiling (MaxContextTokens) as the default rather than introducing a new configurable knob. The serialized history being summarized can never legitimately exceed that. If maintainers prefer a separate, user-tunable compression-input budget, the truncation helper is isolated so the bound can be swapped in without touching the rest.
Happy to adjust either decision based on maintainer preference.
Another data point for this issue, from v1.13.10. In our case the oversized request did not fail. It went through and was billed.
The repository under review has a vendored, minified PDF.js worker committed as a plain file (its longest line is 1,086,386 characters). During a review, code_search for a common word matched that line, and the tool result was about 1.4 MB. On the next turn the loop crossed the 80% threshold and ran memory compression. buildMessageXML carried the whole line into the compression request.
The provider has a 1M-token context window, so it accepted both resulting compression requests: about 792K and 788K input tokens, each returning a normal-sized summary. The review model itself never received the line, because compression ran first. Nothing failed, and the review completed with normal findings. The only symptom was the bill: the review cost about 8x as much as the same review re-run with the line bounded.
So on long-context providers this is a silent cost problem, not just a 400. A bound on the compression request's own input (as in #1893) covers it whatever the source of the long line. The code_search byte limits discussed in #1827 would have prevented this instance, but file_read was bounded separately in #1878. A long line from any tool output that is not bounded yet would still reach compression without #1893.
Another data point, from v1.13.3 (GitHub Action pin 375f64cd) with claude-opus-5-5 (1M context): the memory_compression_task for a group of 7 small files (~690 changed lines in total) was rejected with 400 invalid_request_error: prompt is too long: 2321076 tokens > 1000000 maximum. This happened three times in a row on the same head. Retrying cannot help, so the review always ends partial for that group.
Since the oversized request is rejected by the provider rather than billed, it fails deterministically. For us the impact is a permanently incomplete review of an otherwise normal PR. We'd be glad to test #1893 once it is available in a release.
@alsxp Thanks for reporting this and for offering to test. I’m working with the author to get #1893 merged. If you’d like to try it before the next release, you can run gh pr checkout 1893 and make build in a local clone of alibaba/open-code-review. It would help to know whether the newly built binary completes the review on the same commit and settings that consistently left the seven-file group partial.
Could you also share a sanitized sequence of the tool calls leading up to the failed memory_compression_task? Tool names in order and approximate result sizes (lines or bytes) are enough. For example, a trace could look like code_search → 12 matches; file_read → ~2,000 lines (~200,000 bytes); memory_compression_task → 400. Those are just example numbers; there’s no need to share file paths, source code, raw tool output, or request logs.
That sequence would help us see which tool returned the most data and improve its behavior at the source, alongside the fix to bound the compression request itself.
Activity
fxia0018 commentedon Nov 10, 2026
Thanks for the detailed report and the deterministic regression suggestion.
I opened #1893 to bound the compression request's own input.
runCompressionnow runs the compress zone throughboundCompressZoneInputbeforebuildMessageXML, capping the serialized input atMaxContextTokens × 4bytes. The largest message is truncated first with an explicit... (truncated)suffix, so small messages keep their full content and the summarizer can see that source content was elided rather than silently pretending the full history was reviewed.Two notes on implementation choices, for visibility:
CountTokensre-encodes the entire prefix on every call and takes ~10s on a single 170 KB one-line result, which would make the check itself a performance hazard on exactly the inputs it is meant to guard. A byte bound is O(1) and deterministic.MaxContextTokens) as the default rather than introducing a new configurable knob. The serialized history being summarized can never legitimately exceed that. If maintainers prefer a separate, user-tunable compression-input budget, the truncation helper is isolated so the bound can be swapped in without touching the rest.Happy to adjust either decision based on maintainer preference.
mingming099 commentedon Nov 19, 2026
Another data point for this issue, from v1.13.10. In our case the oversized request did not fail. It went through and was billed.
The repository under review has a vendored, minified PDF.js worker committed as a plain file (its longest line is 1,086,386 characters). During a review,
code_searchfor a common word matched that line, and the tool result was about 1.4 MB. On the next turn the loop crossed the 80% threshold and ran memory compression.buildMessageXMLcarried the whole line into the compression request.The provider has a 1M-token context window, so it accepted both resulting compression requests: about 792K and 788K input tokens, each returning a normal-sized summary. The review model itself never received the line, because compression ran first. Nothing failed, and the review completed with normal findings. The only symptom was the bill: the review cost about 8x as much as the same review re-run with the line bounded.
So on long-context providers this is a silent cost problem, not just a 400. A bound on the compression request's own input (as in #1893) covers it whatever the source of the long line. The
code_searchbyte limits discussed in #1827 would have prevented this instance, butfile_readwas bounded separately in #1878. A long line from any tool output that is not bounded yet would still reach compression without #1893.fix(llmloop): bound the compression request's own input size
alsxp commentedon Nov 25, 2026
Another data point, from v1.13.3 (GitHub Action pin
375f64cd) withclaude-opus-5-5(1M context): thememory_compression_taskfor a group of 7 small files (~690 changed lines in total) was rejected with400 invalid_request_error: prompt is too long: 2321076 tokens > 1000000 maximum. This happened three times in a row on the same head. Retrying cannot help, so the review always endspartialfor that group.Since the oversized request is rejected by the provider rather than billed, it fails deterministically. For us the impact is a permanently incomplete review of an otherwise normal PR. We'd be glad to test #1893 once it is available in a release.
lizhengfeng101 commentedon Nov 25, 2026
@alsxp Thanks for reporting this and for offering to test. I’m working with the author to get #1893 merged. If you’d like to try it before the next release, you can run
gh pr checkout 1893andmake buildin a local clone ofalibaba/open-code-review. It would help to know whether the newly built binary completes the review on the same commit and settings that consistently left the seven-file grouppartial.Could you also share a sanitized sequence of the tool calls leading up to the failed
memory_compression_task? Tool names in order and approximate result sizes (lines or bytes) are enough. For example, a trace could look likecode_search → 12 matches; file_read → ~2,000 lines (~200,000 bytes); memory_compression_task → 400. Those are just example numbers; there’s no need to share file paths, source code, raw tool output, or request logs.That sequence would help us see which tool returned the most data and improve its behavior at the source, alongside the fix to bound the compression request itself.
fix(llmloop): bound the compression request's own input size