Skip to content

fix(opencode): bound compaction request payload#29860

Open
timrichardson wants to merge 2 commits into
anomalyco:devfrom
timrichardson:fix/compact-large-session-budget
Open

fix(opencode): bound compaction request payload#29860
timrichardson wants to merge 2 commits into
anomalyco:devfrom
timrichardson:fix/compact-large-session-budget

Conversation

@timrichardson
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?

Prevents /compact from creating a summarization request that is larger than the selected model's usable context budget.

The compaction path now:

  • strips reasoning parts from compaction input
  • strips media from compaction input as before
  • adapts retained tool output size to the model budget
  • treats toolOutputMaxChars: 0 as a real truncation limit

This fixes large restored sessions where the compaction request itself could overflow before a summary was produced.

How did you verify your code works?

  • bun test test/session/message-v2.test.ts
  • bun test test/session/compaction.test.ts
  • bun run typecheck
  • push hook also ran repo typecheck successfully

I also verified the anonymized fixture from #29857 locally:

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

Screenshots / recordings

N/A

Checklist

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant