Repository navigation
fix(llmloop): reserve complete compression context budget - #1993
Conversation
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
| originalTokens := CountMessagesTokens(msgs) | ||
| if part.activeCount == 0 && originalTokens < limit { | ||
| return msgs, nil | ||
| } |
There was a problem hiding this comment.
When activeCount == 0 and originalTokens < limit, the function returns msgs unchanged (no error). But this means the caller (addNextMessage) will see that tokens are still above warnLimit (since this path is only reached when the caller determined CountMessagesTokens(*messages) > warnLimit), yet compression reports success with unchanged messages. The caller will then proceed to append more messages, making the situation worse.
Consider whether this should either:
- Return an error so the caller knows compression couldn't help, or
- Still attempt compression even when
originalTokens < limitifactiveCount == 0, since the goal is to reduce tokens belowwarnLimit(which islimit), not just belowMaxContextTokens.
Note: limit here IS PromptTokenLimit(MaxContextTokens) = warnLimit, so originalTokens < limit means we're already under the warning threshold. In that case returning unchanged is actually correct — the caller's pre-compression check was stale. Please verify this reasoning matches intent.
cb31c4a to
989e8cd
Compare
7abb23e to
36e924b
Compare
Description
Fixes #838.
Three-zone compression could keep recent rounds against almost the entire warning threshold, then add the fixed prompt and a new summary on top. The loop could stop with
StopCompressioneven when compressing more history would have allowed it to continue. The all-fitting and missing-template paths could also summarize or discard live context unnecessarily.Scope and compatibility
This is an independent fix on
main, without the Analysis feature commits from #1937. It applies to the shared loop used by Review and Scan.The 60%/80% compression thresholds and aggregate
--max-tokens-budgetsemantics are unchanged. Compression requests may now use a smaller output cap, particularly with small configured context limits. Unrecoverable context overflow still stops explicitly rather than silently dropping uncompressed history.Compression-request input bounding (#1876) and suppression of repeated rejected requests (#1877) remain separate work. This PR addresses the same frozen-prefix accounting problem as the unmerged #1473 and additionally reserves new-summary space and checks the rebuilt result.
Validation
make checkmake test(race-enabled, full suite)make coverage: 91.8%, above the 90% thresholdmake buildocr review --audience agent --background ...: one selected implementation file, no findings; tests and documentation were also inspected locally.internal/behaviortaskandinternal/workflowsuites passed on an isolated snapshot of feat(review): add optional behavior and impact analysis #1937 with this implementation overlaid, without adding those commits to this branch.The initial regression cases fail on the unchanged implementation and pass with the fix. A local recorded-history replay with a stubbed summary response reproduced a 160,173-token rebuilt context against a 160,000-token threshold. The fixed reconstruction used 131,291 tokens, with 143,897 tokens reserved even when allowing the full summary cap. The replay checks budgeting and history retention; it is not a fresh provider run or an evaluation of summary quality. Recorded conversation contents are not included in this PR.
Checks used project-local temporary directories and Git discovery ceilings to isolate non-repository fixtures.
AI/LLM disclosure
Implementation and PR preparation used OpenAI Codex with
gpt-6-astra. Automated pre-commit review used OpenCodeReview (ocr) withgpt-6-astra.