fix(session): break infinite compaction loop#27919
Conversation
…mpts When compaction fails to reduce context below the limit (e.g. compression state lost, messages uncompressable), the session loop can enter an infinite cycle: overflow detected -> compact -> still overflow -> compact -> ... Track consecutive compaction attempts per loop iteration. Break after 2 attempts to prevent the session from spinning forever. This is a safety guard, not a fix for the underlying compaction failure. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
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 several related PRs that address similar session/compaction issues: Potentially Related PRs:
Why they're related: These PRs all address compaction loop prevention and session overflow handling in similar ways. PRs #26484 and #26235 are particularly close since they both prevent unwanted compaction repetition, similar to your counter-based approach. Note: PR #27919 is the current PR, so it's correctly excluded from duplicates. |
|
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?
The session loop in
prompt.tscan enter an infinite compaction loop when compression fails to reduce the context below the token limit. The loop spins indefinitely consuming API credits without making progress.Change in
session/prompt.ts:Add a
compactionAttemptscounter in the loop:This is a safety guard, not a fix for underlying compaction failure. The counter is per-loop-invocation (reset on each new
runLoopcall), so it doesn't persist across sessions.How did you verify your code works?
This fix has been running in our fork (based on v1.14.41) for several days without issues. The change was manually applied to the current
devbranch rather than cherry-picked due to significant code divergence.Verified that:
Checklist