[BUG] finishReason is never captured from Responses API streams — root cause of the Muse Spark "try again" errors (#193, #197)
Digging into #193 and #197 uncovered a deeper bug that predates both reports.
The short version: the truncation detector checks usageSummary.finishReason, but for Responses API streams that field is never filled. The gateway can send stop_reason perfectly fine and we still don't see it.
The flow, as it runs today:
- The engine parses each SSE event and hands the raw JSON to
updateRequestUsageSummary(src/transports/engine.ts, theonDatacallback). - That function reads
finishReasonfrom exactly two places:data.delta.stop_reason(Anthropic) anddata.choices[0].finish_reason(chat-completions). Seesrc/transports/extract.ts. - A raw Responses event like
{"type": "response.completed", "response": {"stop_reason": "completed"}}has neither. Nochoicesarray, nodelta. - The normalized object from
normalizeResponsesStreamEvent(src/core/routing.ts) does carry a mappedfinish_reason, but it only feedsextractStreamParts. It never reachesusageSummary. - So
isStreamTruncatedseesfinishReason === undefinedon every Responses stream that also lacksdata: [DONE].
Why only some models break: GPT-family requests get [DONE] forwarded by the gateway, so sawDone saves them. Muse Spark (upstream Meta) does not send [DONE], so every unterminated-looking stream is flagged as truncated. If nothing extractable arrives first, the engine retries 3 times and then throws the "try again" error. That is the exact signature in both #193 and #197.
This one gap explains the whole Muse Spark saga: #79 (throw after 12 parts), #187 (patched the symptom), #193, and #197.
Proposed fix: in updateRequestUsageSummary, treat data.type === "response.completed" as a terminal signal and set summary.finishReason from response.stop_reason, defaulting to "stop" when absent. The event itself is terminal by definition, so a stream that received it can never be a mid-response cut. A matching ?? "stop" default in the routing normalizer would be a cheap second layer.
One honest caveat: this fix stops the error, but if the Muse gateway also stopped delivering extractable text (the #197 log shows ~907 completion tokens and zero extracted parts), users would get a silent empty reply. That second half needs the raw SSE dump (diag-sse-event-* lines in the OpenCode output channel) from someone who can reproduce before we touch the extractors.
Related: #193, #197, #187, #79
I can reproduce this on OpenCode Go with gpt-5.6-luna (VS Code 1.134.0, extension 0.7.2, Windows).
The request returns HTTP 200 and the stream includes response.completed with status=completed, but no [DONE] or finish_reason. The extension retries three times and then reports response stream ended before completion.
This appears to be the same Responses API completion-signal bug, and it also affects GPT-5.6 Luna on OpenCode Go, not only Muse Spark.
how to open the diag-sse log? I tried but could not get diag-sse log .
I try to edit out/transports/engine.js +383 local and reload. reporoduce bug and get the log as below
if (rawSseData.length > 0) { options.output?.appendLine( [diag-empty-response] model=${options.modelId} completionTokens=${String(usageSummary.completionTokens)} totalEvents=${String(totalEvents)} rawSseDataCount=${String(rawSseData.length)}`
);
for (let i = 0; i < rawSseData.length; i++) {
options.output?.appendLine(
`[diag-sse-event-${String(i)}] ${(0, errors_1.truncateForLog)(JSON.stringify(rawSseData[i]))}`
);
}
}
// if (usageSummary.completionTokens && usageSummary.completionTokens > 0 && extractedPartCount === 0 && rawSseData.length > 0) {
// options.output?.appendLine([diag-empty-response] model=${options.modelId} completionTokens=${String(usageSummary.completionTokens)} totalEvents=${String(totalEvents)} rawSseDataCount=${String(rawSseData.length)});
// for (let i = 0; i < rawSseData.length; i++) {
// options.output?.appendLine([diag-sse-event-${String(i)}] ${(0, errors_1.truncateForLog)(JSON.stringify(rawSseData[i]))});
// }
// }
`
I don't understand ts grammar. but gpt give me a workaround temp. it seems work for a while. edit local extract.js file.
function updateRequestUsageSummary(summary, data) { if (!(0, utils_1.isRecord)(data)) { return; } // Responses API signals successful completion via response.completed. if (data.type === "response.completed") { summary.finishReason = "stop"; }
waiting for the author's official release.