GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(opencode): bound compaction request payload by timrichardson · Pull Request #29860 · anomalyco/opencode

Conversation

@timrichardson

@timrichardson timrichardson commented May 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #29857

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This branch changes /compact so 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), where usable(...) is opencode's safe history budget for the selected model:

  • If the model has limit.input, usable(...) is limit.input - reserved.
  • Otherwise it is limit.context - maxOutputTokens.
  • reserved comes from config.compaction.reserved, or defaults to min(20_000, maxOutputTokens).
  • Models with limit.context === 0 keep 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_000 chars. If that estimate fits the compaction budget, /compact sends the legacy payload unchanged.

If the legacy payload would exceed the budget, /compact falls 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 from 0 to 2_000 chars and keeping the largest preview that still fits the budget.

This also fixes toolOutputMaxChars: 0: on dev, 0 was treated as "no limit"; on this branch, only undefined means "no limit", so 0 can fully remove tool output content while keeping the truncation marker.

Net effect: before, /compact could 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:

  • overflow threshold behavior, including limit.input, output headroom, cache reads, disabled auto-compaction, and unknown context limits
  • compaction marker creation and summary process behavior
  • tool-output pruning, including protected skill tool output
  • auto-continue, overflow replay, repeated compactions, summary anchoring, abort handling, and no tool calls during summary generation
  • the new bounded payload path preserving the legacy payload when it fits
  • the new reduced payload path stripping reasoning metadata, truncating tool output, and staying within the calculated compaction budget
  • irreducibly oversized payloads failing cleanly by marking the summary message as errored
  • plugin-injected compaction context being included in budget sizing
  • message conversion behavior for compacted and truncated tool output
  • revert plus compact workflows

I also verified the anonymized fixture from #29857 locally:

  • legacy payload shape: 788327 estimated tokens, overflows
  • fixed payload shape: 308291 estimated tokens, compacts successfully

Note: 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, desktop server-sdk.tsx). The test commit was pushed with hook bypass after explicit maintainer authorization.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@timrichardson
timrichardson force-pushed the fix/compact-large-session-budget branch from 8a5f9a4 to 0180516 Compare May 31, 2026 02:09
timrichardson added 2 commits May 31, 2026 12:12
@timrichardson
fix(opencode): bound compaction request payload
4545537
@timrichardson
fix(opencode): align compaction session types
4484742
@timrichardson
timrichardson force-pushed the fix/compact-large-session-budget branch from 0180516 to 4484742 Compare May 31, 2026 02:12
@timrichardson
test(opencode): cover compaction payload regressions
bb5570b
@danielxxomg danielxxomg mentioned this pull request Jun 5, 2026
compaction.auto: false is ignored when provider throws a context overflow error #16882
Closed
@github-actions github-actions Bot mentioned this pull request Jun 17, 2026
fix(session): remove compaction buffer cap on reserved tokens #32660
Closed
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
fix: bound compaction request size #34379
Closed
3 of 6 tasks
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Jun 29, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG]: /compact can exceed model context before summarization on large sessions

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@timrichardson
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.