fix(session): bound consecutive overflow compaction cycles in the prompt loop#37584
fix(session): bound consecutive overflow compaction cycles in the prompt loop#37584a692570 wants to merge 1 commit into
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 the search results, I found several related PRs but no duplicate. The PR #37584 is the current one being reviewed. Here are the related PRs addressing similar context overflow and compaction issues: Directly Related (complementary fixes):
Related Compaction/Overflow Handling:
Note: The current PR is a complementary fix to #34029 and #34261, implementing similar overflow cycle bounding in the SessionPrompt loop ( |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #27924
Type of change
What does this PR do?
Bounds the overflow compaction retry cycle in the SessionPrompt run loop.
When a provider rejects a turn with a context overflow, the loop requests compaction and retries the turn. There is no attempt limit and no check that compaction reduced the request, so when the summary completes but does not shrink context below the limit, the session compacts forever. I hit this on 1.18.2: my session DB shows 35 consecutive assistant messages with mode "compaction", one every 30 to 90 seconds for over an hour, all finishing stop with no error, with the following turn overflowing each time.
The fix counts consecutive overflow to compaction cycles in the run loop. After 3 with no successful turn in between, it fails the assistant message with ContextOverflowError and stops instead of compacting again. Any result other than "compact" resets the counter, so long sessions that legitimately compact many times are unaffected. This works because the only way the counter reaches 3 is three provider overflows in a row with a compaction between each, which means compaction is not making progress and retrying again cannot succeed.
Note #34029 and #34261 fix related gaps in packages/core, but this loop is in packages/opencode/src/session/prompt.ts, which the server prompt handler uses, so it needs its own guard. Complementary, not a duplicate.
How did you verify your code works?
bun run typecheck passes in packages/opencode. I have been running this patch in a source build since 2026-07-17 on the same cron workloads that previously looped: the loop no longer reproduces and multi-compaction sessions still complete. I did not find a test harness for the SessionPrompt run loop; happy to add a test if you point me at the preferred fixture approach.
Screenshots / recordings
Not a UI change.
Checklist