GeezerVison is showing github.com — fix(core): bound compaction summaries by the context window by wannesdecraene · Pull Request #60658 · anomalyco/opencode
Conversation
wannesdecraene
commented
Oct 30, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Fixes #60648 (the confirmed summary-budget bug; automatic-compaction policy is unchanged).
Type of change
What does this PR do?
With a 256k context override and an inherited 922k input limit, compaction sized its summary against the larger input window, leaving only 1,024 output tokens.
Summary sizing now uses the smaller known input/context limit, including the decision to send the full conversation unchanged. Lower input limits, unknown context limits, native compaction and the automatic threshold keep their existing behavior.
Related: #58492 and #59226. Input-based automatic-compaction semantics remain tracked in #52954.
How did you verify your code works?
On Windows with Bun 1.4.4:
- Both regression tests fail on the base: 1,024 instead of 40,000 output tokens, and an oversized request kept unchanged.
- Four targeted compaction/model-request suites pass: 54 tests, repeated 10 times (540 passes).
bun typecheck, bun run typecheck:tsc, focused oxlint and Prettier checks pass.
- Root
bun run check passes lint but fails on the unchanged packages/app/src/custom-elements.d.ts symlink checked out as plain text on Windows.
Reproduce from packages/core: bun run script/test.ts test/session-compaction.test.ts test/session-compaction-transport.test.ts test/session-model-request.test.ts test/session-model-request-hooks.test.ts --rerun-each 10.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
<style>
.reply { animation: reveal 3s ease-in-out infinite; }
@keyframes reveal { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .reply { animation: none; } }
</style>
<g fill="none" stroke="currentColor" stroke-width="2">
<rect x="8" y="10" width="132" height="52" rx="6" opacity=".4"/>
<path d="M20 24h82M20 36h108M20 48h62" opacity=".6"/>
<path d="M150 36h20m-6-6 6 6-6 6" opacity=".7"/>
<rect x="180" y="16" width="52" height="40" rx="6" opacity=".4"/>
<g class="reply"><path d="M190 27h32M190 36h32M190 45h22"/></g>
</g>
</svg>
Screenshots / recordings
No UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #52954, #50574
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix works. I ran the #60648 reproduction from source (context 256k, input 922k, buffer 40k, then /compact). On the base, the summary request and its retry go out with max_completion_tokens: 1024. With this PR they go out with 40000. The compaction and model-request suites pass, both new tests fail on the base, and tsc passes.
Public API: unchanged. Only internal sizing logic in packages/core/src/session/compaction.ts changes.
Concerns:
- Overlap with #60648's other PR, #60660. #60660 makes the same
min(input, context) change in both calculateCeiling and summaryRoom. That also moves the automatic compaction threshold under the context window. This PR deliberately keeps the threshold on the input limit. In the reported setup that threshold stays at 882k on a 256k window, so automatic compaction (and background precompute) can never start before the provider rejects the request; compaction then only happens through overflow recovery. Maintainers will need to pick one scope; see the inline note.
- First new test is larger than it needs to be. It also checks the auto "skipped" case and runs a five-case table. The 256k/922k manual case, plus the oversized-conversation test, already cover the fix. Trimming it down to those would keep it easy to follow.
Related: #52954, #50574
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
.pipe(Effect.orElseSucceed(() => undefined)))) ??
|
|
|
context.model
|
|
|
const ceiling = calculateCeiling(model.limit, buffer)
|
|
|
const limit = native ? model.limit : { ...model.limit, input: summaryWindow(model.limit) }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only affects the summary's size. The due check in compact (and in precompute) still uses calculateCeiling(context.model.limit, …), so with context 256k and input 922k the automatic threshold stays at 882k, past the window. Automatic compaction can then only start through provider-overflow recovery. #60660 applies min(input, context) inside calculateCeiling, which fixes both at once and avoids keeping two window definitions side by side. Is keeping the input-based threshold intended here?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}),
|
|
|
)
|
|
|
|
|
|
it.effect("summary compaction bounds its budget by the context window without changing the input threshold", () =>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks a lot for one fix: an auto "skipped" check plus a five-case table that reconfigures the shared buffer on each iteration. The 256k/922k manual case asserting maxTokens 40000 (and maybe the lower-input control) is enough. Could you cut it down to that?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|