Skip to content

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

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

fix(session): stop prompt loop after model completion#19424
luyanhexay wants to merge 2 commits intoanomalyco: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

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