anomalyco / anomalyco/opencode

Session loop exit gate responds to synthetic user messages (phantom prompts)

Open
#49,366 1 comment 0 reactions 1 assignee View on GitHub

@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

  1. Have a conversation approaching context overflow
  2. Auto-compaction triggers, creating a synthetic user message
  3. The loop's exit gate sees the synthetic message as \lastUser\
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.