anomalyco / anomalyco/opencode
Session loop exit gate responds to synthetic user messages (phantom prompts)
@kitlangton is already working on this.
Since Sep 16, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Bug
The agent loop in \packages/opencode/src/session/prompt.ts\ (
unLoop, ~lines 1111-1186) exits only when \lastAssistant.parentID === lastUser.id. When any synthetic user message is appended after the last assistant turn (e.g., from compaction, subagent results, or shell execution), this equality breaks and the loop creates a new assistant message responding to the synthetic message — producing phantom AI responses to prompts the human never sent.
Reproduction
- Have a conversation approaching context overflow
- Auto-compaction triggers, creating a synthetic user message
- The loop's exit gate sees the synthetic message as \lastUser\
- A new assistant turn fires, responding to the phantom
Proposed fix
The exit gate should compare \lastAssistant.parentID\ against the last non-synthetic user message (skip any user message whose parts carry \synthetic: true). Alternatively, track the loop's own originating user message ID and compare against that.
Impact
Users see AI responses to prompts they never sent. Confusing, wastes context, and erodes trust in the tool.
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.