fix(opencode): bound compaction request payload#29860
Closed
timrichardson wants to merge 3 commits into
Closed
Conversation
8a5f9a4 to
0180516
Compare
0180516 to
4484742
Compare
6 tasks
Contributor
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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.
Issue for this PR
Closes #29857
Type of change
What does this PR do?
This branch changes
/compactso very large sessions are more likely to compact successfully instead of overflowing while trying to summarize.The compaction path now builds a bounded model payload. It computes a compaction budget as
floor(usable(...) * 0.85), whereusable(...)is opencode's safe history budget for the selected model:limit.input,usable(...)islimit.input - reserved.limit.context - maxOutputTokens.reservedcomes fromconfig.compaction.reserved, or defaults tomin(20_000, maxOutputTokens).limit.context === 0keep the existing overflow-disabled behavior.For extra safety, compaction first performs a local preflight using the legacy payload shape: media stripped, reasoning preserved, and tool output capped at
2_000chars. If that estimate fits the compaction budget,/compactsends the legacy payload unchanged.If the legacy payload would exceed the budget,
/compactfalls back to a reduced payload. In that fallback it strips reasoning parts, including large provider metadata like encrypted reasoning blobs, and adaptively truncates tool outputs by binary-searching from0to2_000chars and keeping the largest preview that still fits the budget.This also fixes
toolOutputMaxChars: 0: ondev,0was treated as "no limit"; on this branch, onlyundefinedmeans "no limit", so0can fully remove tool output content while keeping the truncation marker.Net effect: before,
/compactcould fail because the summarization request itself was too large. Now it preserves the old payload when safe, and only sends a reduced, budget-aware history when needed, so sessions with huge tool outputs or reasoning metadata can be summarized rather than immediately overflowing.How did you verify your code works?
bun test test/session/compaction.test.ts(55 pass,1 skip)bun test test/session/message-v2.test.ts test/session/revert-compact.test.ts(45 pass)The compaction tests cover:
limit.input, output headroom, cache reads, disabled auto-compaction, and unknown context limitsskilltool outputI also verified the anonymized fixture from #29857 locally:
788327estimated tokens, overflows308291estimated tokens, compacts successfullyNote: local
bun typecheck/ pre-push typecheck is currently blocked by existing event-stream typing errors outside this compaction change (stream.transport.ts, TUI event/sync, desktopserver-sdk.tsx). The test commit was pushed with hook bypass after explicit maintainer authorization.Screenshots / recordings
N/A
Checklist