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. |
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