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
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
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:
Root Cause
In
packages/opencode/src/session/compaction.ts, theprocess()function (line ~202) checksresult === "continue" && input.autobut does not check the assistant'sfinishreason before injecting the synthetic continue.Environment
Related