Skip to content

fix: bound compaction request size#34379

Open
ZhaoyangHan04 wants to merge 1 commit into
anomalyco:devfrom
ZhaoyangHan04:fix/compaction-overflow-budget
Open

fix: bound compaction request size#34379
ZhaoyangHan04 wants to merge 1 commit into
anomalyco:devfrom
ZhaoyangHan04:fix/compaction-overflow-budget

Conversation

@ZhaoyangHan04

Copy link
Copy Markdown

Issue for this PR

Related to #15556

Type of change

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

What does this PR do?

This adds a final size guard before sending a compaction request to the provider.

In some very large sessions, the selected history plus the compaction prompt can still exceed the model's usable context window. When that happens, opencode may ask the provider to summarize a request that is already too large, and the provider returns a context limit error.

The change estimates the compact request size before calling the model. If it is too large, it drops the oldest messages from the compaction request until it fits. If even the final compaction prompt cannot fit, it records a local context overflow error and stops instead of sending a request that is expected to fail.

How did you verify your code works?

  • Ran bun run --cwd packages/opencode typecheck
  • Ran git diff --check
  • Tested opencode against DashScope-compatible models:
    • kimi-k2.6: short prompt passed, low-budget long-context compaction pressure test passed
    • MiniMax-M2.5: short prompt passed, low-budget long-context compaction pressure test passed

Screenshots / recordings

N/A, no UI change.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR that should be reviewed for overlap:

PR #29860: fix(opencode): bound compaction request payload
#29860

This PR appears to address a similar issue of bounding/limiting the compaction request, which could be related to the current PR #34379. You may want to check if this was previously closed or if the fix in #29860 is being refined or expanded in the current PR.

All other compaction-related PRs found (#33330, #30304, #10123, #18941, #31527, #31613) appear to address different aspects of the compaction system (duplicating messages, stuck sessions, thresholds, cache preservation, etc.) rather than the specific issue of estimating and capping request size before sending to the provider.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant