Skip to content

fix(session): stop prompt loop after model completion#18500

Closed
luyanhexay wants to merge 2 commits intoanomalyco:devfrom
luyanhexay:debug/stable-controller-target
Closed

fix(session): stop prompt loop after model completion#18500
luyanhexay wants to merge 2 commits intoanomalyco:devfrom
luyanhexay:debug/stable-controller-target

Conversation

@luyanhexay
Copy link

@luyanhexay luyanhexay commented Mar 21, 2026

Issue for this PR

Closes #17982
Refs #18096
Refs #11153

What this PR changes

  • stops the session prompt loop when the model has already completed and there is no tool activity
  • treats finish=unknown as terminal only for non-tool responses to prevent extra assistant-message iterations
  • preserves existing json-schema and tool-call handling paths

Why this change is needed

A completed model response could still continue into another prompt-loop iteration, creating duplicate assistant outputs in one user turn. This patch makes loop termination explicit for that terminal state.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

How this was tested

  • bun test ./packages/opencode/test/session/session.test.ts (3 passed, 0 failed)
  • repeated local reproduction with anthropic/claude-sonnet-4-6 no longer produced multi-assistant emissions after a single ping

Checklist

  • I linked an existing issue
  • I tested locally
  • This PR stays focused on one bug fix area

@github-actions
Copy link
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 21, 2026
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 21, 2026
@github-actions github-actions bot closed this Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OpenCode prompt loop continues after finish=stop, triggering prefill error on claude-opus-4-6

1 participant