Skip to content

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

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

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

Conversation

@luyanhexay

Copy link
Copy Markdown

Issue for this PR

Closes #17982
Refs #18096
Refs #11153

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR fixes a session loop termination bug after model completion.

  • stop prompt-loop continuation when the model has already completed and no tool activity remains
  • treat finish=unknown as terminal only for non-tool responses
  • keep json-schema/tool-call paths unchanged

Why this works:

  • terminal completion state is handled explicitly so the loop cannot emit extra assistant messages in the same turn
  • tool-related paths are excluded from the terminal shortcut, preserving existing tool execution flow

How did you verify your code works?

  • 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 one user ping

Screenshots / recordings

N/A (non-UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

ngotrnghia1811 pushed a commit to ngotrnghia1811/opencode that referenced this pull request May 8, 2026
…yco#19424)

When finish='stop' (or 'unknown' with no tool activity), break out of the
prompt loop immediately instead of continuing. Prevents the LLM from being
called again after model completion, which caused the Anthropic prefill error
('conversation must end with a user message').
@rekram1-node

Copy link
Copy Markdown
Collaborator

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

2 participants