fix: bound compaction request size - #34379
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
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: 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. |
|
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. |
Issue for this PR
Related to #15556
Type of change
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?
bun run --cwd packages/opencode typecheckgit diff --checkkimi-k2.6: short prompt passed, low-budget long-context compaction pressure test passedMiniMax-M2.5: short prompt passed, low-budget long-context compaction pressure test passedScreenshots / recordings
N/A, no UI change.
Checklist