| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…rally
Auto-compaction triggers after an assistant turn that overflows the
context window. Before this change, compaction unconditionally injected
a synthetic "Continue if you have next steps..." user message whenever
`auto: true` and no replay was needed. When the assistant had already
ended its turn naturally (finish != "tool-calls" and no pending tool
calls), that synthetic Continue forced another model turn — which in
turn overflowed, triggered another compaction, injected another
Continue, and so on. The session got stuck in an infinite
Build → Compaction → Build → Compaction loop.
This change:
- detects whether the assistant message that triggered the auto-compaction
ended naturally, using the same finish-reason set the prompt loop uses
for its exit condition ("tool-calls"/"unknown" mean the assistant is
still mid-work),
- suppresses the synthetic Continue in that case,
- returns "stop" from `process()` so the prompt loop exits cleanly
instead of re-iterating into a fresh model call.
Manual compaction (auto=false), the overflow-with-replay path, and
truly-mid-work compactions (finish="tool-calls" or pending tool calls)
are unaffected.
Fixes anomalyco#15533
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Sorry, something went wrong.
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs addressing similar session compaction issues: Potentially Related PRs:
These PRs appear to be related to the same problem domain (session compaction infinite loops and auto-continuation issues). #27919 is particularly worth checking as it directly addresses "break infinite compaction loop" which may be a prior or concurrent attempt at fixing the same issue reported in #15533. |
Sorry, something went wrong.
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #15533.
Auto-compaction triggers after an assistant turn whose token usage overflows the model's context window. Before this change, SessionCompaction.process() unconditionally injected a synthetic Continue if you have next steps... user message whenever auto: true and no replay was needed.
When the assistant had already ended its turn naturally (finish ≠ "tool-calls" / "unknown" and no pending tool calls), that synthetic Continue pushed the model into yet another turn — which overflowed again, triggered another compaction, injected another Continue, and so on. Sessions got stuck in the Build → Compaction → Build → Compaction → … loop reported repeatedly in #15533, including reproductions with Claude Opus via Copilot, OpenAI GPT 5.5, local llama.cpp, mlx, and others.
What this PR changes
packages/opencode/src/session/compaction.ts:
This matches the finish-reason set the prompt loop itself uses at prompt.ts:1267-1275 to decide it can break out of the run loop.
What this PR does not change
Test plan
Why "stop" instead of "continue" at the end
If we only skipped the Continue injection but still returned "continue", the prompt loop in prompt.ts:1294-1304 would continue back to the top. There it would find the just-created compaction user message as lastUser, with lastUser.id > lastAssistant.id, so the lastUser.id < lastAssistant.id natural break condition (prompt.ts:1271) would be false, and the loop would call the model again with the compacted summary in context — re-triggering #15533 by a slightly different path. Returning "stop" ends the loop the moment we know the assistant had nothing more to do. The user can pick up the conversation with their next prompt; the compacted summary is preserved.
🤖 Generated with Claude Code