anomalyco / anomalyco/opencode
Auto-compaction infinite loop when assistant ended its turn (finish !== tool-calls)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Bug Description
When auto-compaction triggers after the assistant has naturally ended its turn (e.g., asked a question via the question tool, or simply finished responding with finish === "stop"), SessionCompaction.process() unconditionally injects a synthetic "Continue..." user message, creating an infinite loop.
Steps to Reproduce
- Start a long conversation that approaches the context window limit
- Have the assistant end its turn naturally (ask a question, or finish responding)
- Auto-compaction triggers due to context overflow
- Synthetic "Continue if you have next steps..." message is injected
- Agent responds to the synthetic continue → context overflows again → compaction → synthetic continue → ...
Expected Behavior
When the assistant had naturally ended its turn (finish === "stop"), the compaction should complete without injecting a synthetic continue message. The session loop should exit and wait for real user input.
The synthetic continue should only be injected when the assistant was in the middle of tool execution (finish === "tool-calls" or "unknown").
Actual Behavior
The synthetic continue is always injected during auto-compaction, regardless of the assistant's state. This causes an unbounded loop:
assistant responds → context overflow → auto-compaction → synthetic "Continue..." →
agent responds → overflow → compaction → synthetic "Continue..." → …
Root Cause
In packages/opencode/src/session/compaction.ts, the process() function (line ~202) checks result === "continue" && input.auto but does not check the assistant's finish reason before injecting the synthetic continue.
Environment
- OpenCode v1.2.15
- Observed with oh-my-opencode plugin (Sisyphus/Ultraworker agent)
- Model: Claude Sonnet 4
Related
- #10123 — addresses continuous compaction with min_messages threshold (different approach)
- #12970 — addresses the opposite problem (continue NOT being injected when it should be)
- #14245 — fixes other compaction bugs in headless mode
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.