fix(provider): treat missing/null finish_reason as stop instead of other - #2174
Open
anandlo wants to merge 1 commit into
Open
fix(provider): treat missing/null finish_reason as stop instead of other#2174anandlo wants to merge 1 commit into
anandlo wants to merge 1 commit into
Conversation
Some gateways (e.g. muse-spark-1.2-contributor via opencode.ai/zen/go/v1) never send a finish_reason chunk in streaming and return null in non-streaming. mapOpenAICompatibleFinishReason fell through to the default branch returning "other", which made classify.ts flag every such response as degraded / think-only. - add null/undefined guard in mapOpenAICompatibleFinishReason returning "stop" - change streaming initial finishReason.unified default from "other" to "stop" - add tests covering null/undefined plus regression cases Fixes XiaomiMiMo#2173
EsanRAHIMI
reviewed
Aug 20, 2026
EsanRAHIMI
left a comment
There was a problem hiding this comment.
The missing-finish-reason fallback should account for tool calls before defaulting to stop. This gateway is described as omitting finish_reason entirely, so a streamed response containing delta.tool_calls will also keep the new initial unified: "stop" value. The transform still emits the tool calls in flush(), but the final finish part now says the model stopped normally rather than tool-calls; consumers that use the finish reason to decide whether to continue the agent/tool loop can terminate early. Could flush() set the fallback to tool-calls when toolCalls.length > 0 (and no explicit reason was received), with a streaming regression test for a tool-call response that omits finish_reason?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some gateways served by the OpenCode Go gateway (
opencode.ai/zen/go/v1) do not emit afinish_reasonin streaming responses (and returnnullin non-streaming). The mapping then fell through todefault: return "other", which madeclassify.tsflag every such response as degraded / think-only even though the response was delivered normally.Affected model:
muse-spark-1.2-contributor.Evidence (live gateway streaming captures)
finish_reasondeepseek-v4-pro['stop']✓glm-5['stop']✓muse-spark-1.2-contributorChanges
map-openai-compatible-finish-reason.ts: add anull/undefinedguard before theswitchthat returns"stop".openai-compatible-chat-language-model.ts: change the streaming initialfinishReason.unifieddefault from"other"to"stop"(models that send a properfinish_reasonstill override it).test/provider/map-openai-compatible-finish-reason.test.tscoveringnull/undefinedplus regression cases (stop,length,tool_calls,other,content_filter,"").Verification
bun typecheckfrompackages/opencode/passes.bun test test/providerpasses: 482 pass / 0 fail (8 new tests included).Fixes #2173
Test plan
muse-spark-1.2-contributorand confirmfinishis reported asstop, notother.deepseek-v4-pro/glm-5still reportstopas before (no regression).