Skip to content

fix: treat "other" as a continue stop reason#20467

Closed
kkugot wants to merge 2 commits into
anomalyco:devfrom
kkugot:fix/mcp-finish-reason-20050-20465
Closed

fix: treat "other" as a continue stop reason#20467
kkugot wants to merge 2 commits into
anomalyco:devfrom
kkugot:fix/mcp-finish-reason-20050-20465

Conversation

@kkugot
Copy link
Copy Markdown

@kkugot kkugot commented Apr 1, 2026

Issue for this PR

Closes #20465

Type of change

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

What does this PR do?

Fixes blank assistant text in TUI when MCP servers are enabled, a regression introduced in v1.3.4 by the AI SDK 5 -> 6 upgrade.

Root cause: The v6 finish-reason adapter changed the default unmapped reason from unknown to other. The prompt loop continue sets in prompt.ts had unknown removed but other was never added as a replacement. This causes the loop to exit after MCP tool calls before the model produces final text. MCP amplifies this because tool-enabled requests hit this code path far more often.

Additional fix: The TUI AssistantMessage component rendered empty space for intermediate assistant messages whose parts were all hidden (completed tools with details off, empty text). Added a reactive visible memo that hides the entire message when no parts would render.

How did you verify your code works?

  • Tested locally with MCP enabled: assistant text renders correctly, symptom gone
  • Tested with MCP disabled: no behavior change
  • bun typecheck — no new errors (only pre-existing ripgrep.ts errors on dev)

Checklist

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

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. PR fix(opencode): run transformParams middleware unconditionally for all call types #19558 - "fix(opencode): run transformParams middleware unconditionally for all call types"

  2. PR fix(core): prevent agent loop from stopping after tool calls with OpenAI-compatible providers #14973 - "fix(core): prevent agent loop from stopping after tool calls with OpenAI-compatible providers"

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 6 times, most recently from df65986 to bf4dbc9 Compare April 2, 2026 07:51
@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 5 times, most recently from 5d6eef9 to 49cc60e Compare April 7, 2026 18:50
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 2 times, most recently from 8c1272b to 36d92e3 Compare April 10, 2026 10:52
@kkugot kkugot changed the title fix: blank assistant text with MCP enabled after AI SDK v6 migration fix: blank assistant text - finish-reason regression after AI SDK v6 migration Apr 10, 2026
@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 2 times, most recently from a060a89 to 4e4878b Compare April 13, 2026 13:44
@kkugot
Copy link
Copy Markdown
Author

kkugot commented Apr 13, 2026

I am keeping this branch up-to date with dev, would be thankful if this can be merged. engineers using Oracle Code Assist could not use opencode with Open AI models with responses API because of this bug. This is since version 1.3.4

@rekram1-node
Copy link
Copy Markdown
Collaborator

@kkugot let me look over this

Comment thread packages/opencode/src/session/llm.ts Outdated
@rekram1-node
Copy link
Copy Markdown
Collaborator

The LLM middleware in llm.ts targeted args.params.prompt for applying ProviderTransform.message(), but v6 Responses requests use messages or input. This meant message normalization was silently skipped on Responses requests.

Im not sure this is accurate

@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 3 times, most recently from cb401dc to c2caf33 Compare April 18, 2026 14:45
Comment thread packages/opencode/src/cli/cmd/tui/routes/session/index.tsx Outdated
@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 3 times, most recently from 6ea89bd to d0971aa Compare April 18, 2026 15:12
@kkugot
Copy link
Copy Markdown
Author

kkugot commented Apr 18, 2026

this pr has so many unrelated changes, i thought it'd be a 2 line pr?

Ready for your review

@rekram1-node
Copy link
Copy Markdown
Collaborator

Alr thanks, ill double check this logic tmr I just need to make sure failure cases dont infinitely loop from this (its almost 1am here rn so too late for me to merge if im not 100% confident)

@kkugot
Copy link
Copy Markdown
Author

kkugot commented Apr 21, 2026

@rekram1-node no pressure here, if I can help with tesing this - let me know.

@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch 2 times, most recently from 03c4e62 to 8dc2a25 Compare April 25, 2026 09:15
@kkugot kkugot changed the title fix: blank assistant text - finish-reason regression after AI SDK v6 migration fix: blank assistant text - finish-reason regression after AI SDK v6 migration when any MCP is on Apr 25, 2026
@kkugot
Copy link
Copy Markdown
Author

kkugot commented Apr 25, 2026

@rekram1-node I have checked with the recent code changes on dev and we are able to reproduce this issue only when any of the MCPs are enabled. With the proposed fix everything works correctly.

@pedantilva
Copy link
Copy Markdown

Hi @rekram1-node any idea when this will be merged? This is driving people out of OpenCode tool due to this issue.

@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch from 8dc2a25 to f54a21b Compare May 3, 2026 21:11
@rekram1-node rekram1-node changed the title fix: blank assistant text - finish-reason regression after AI SDK v6 migration when any MCP is on fix: treat "other" as a continue stop reason May 4, 2026
@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

Comment thread packages/opencode/src/session/prompt.ts Outdated
@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch from f54a21b to 1d793dc Compare May 5, 2026 23:17
kostiantyn-kugot added 2 commits May 7, 2026 13:52
The v6 upgrade changed the default unmapped finish reason from "unknown"
to "other", but the prompt loop continue sets were not updated to match.
This caused premature loop exit after MCP tool calls, before the model
produced final assistant text.

Fixes anomalyco#20050
Fixes anomalyco#20465
@kkugot kkugot force-pushed the fix/mcp-finish-reason-20050-20465 branch from 43b7797 to 32d5a37 Compare May 7, 2026 11:54
@rekram1-node
Copy link
Copy Markdown
Collaborator

This was tested and works? Im just noticing that the only test seems to assert other as a stop reason to stop rather than continue which i would have assumed was not ur intent?

@kkugot
Copy link
Copy Markdown
Author

kkugot commented May 16, 2026

Our provider emits OpenAI Responses-style structural completion events, but not enough SDK-friendly finish classification for opencode’s current parser. OpenAI Responses itself does not require finish_reason; the client must derive a finish classification from the event stream. The change in this PR works because it treats the unmapped completed function-call step as "other" instead of leaving it undefined.

@kkugot
Copy link
Copy Markdown
Author

kkugot commented May 16, 2026

To the OCA users of opencode:
I found an OCA upstream Responses streaming issue while debugging OpenCode visibility failures. For some /v1/responses stream=true post-tool requests, upstream returns HTTP 200 but then closes the SSE stream with no useful output, sometimes only lifecycle events or even bytes:0. This happens intermittently across endpoints, so it does not look like a single bad endpoint or issue with opencode. The workaround in this PR was forcing opencode to do a retry. I added OCA proxy-side protection to hide those broken attempts from the client and retry before committing downstream SSE, which resolved the OpenCode rendering issue in my local testing. We need to bring this issue to OCA team now.

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.

Blank assistant text with AI SDK v6 and MCP on: finish-reason regression when using responses api with @ai-sdk/openai

3 participants