fix(stream): count thinking/reasoning_details as useful stream output (#2520)

This commit is contained in:
diegosouzapw
2026-05-21 20:29:20 -03:00
parent a886f09b3d
commit 50d549ac4e
2 changed files with 23 additions and 0 deletions

View File

@@ -28,6 +28,11 @@ function hasUsefulValue(value: unknown): boolean {
"delta",
"reasoning_content",
"reasoning",
// Mistral/Magistral thinking arrays and StepFun/OpenRouter reasoning_details are
// valid model output — without these a reasoning-only stream was misclassified as
// "no useful content" and turned into a spurious 502 (#2520).
"thinking",
"reasoning_details",
"partial_json",
"arguments",
"name",

View File

@@ -446,3 +446,21 @@ test("ensureStreamReadiness returns 502 when stream ends without useful content"
assert.equal(result.ok, false);
assert.equal(result.response.status, 502);
});
// Regression for #2520: a reasoning-only stream (Mistral `thinking` array / StepFun
// `reasoning_details`) is real output and must NOT be classified as "no useful content"
// (which produced a spurious 502).
test("hasUsefulStreamContent detects thinking[] and reasoning_details (#2520)", () => {
assert.equal(
hasUsefulStreamContent(
`data: ${JSON.stringify({ choices: [{ delta: { content: [{ type: "thinking", thinking: [{ text: "reasoning..." }] }] }, index: 0 }] })}\n\n`
),
true
);
assert.equal(
hasUsefulStreamContent(
`data: ${JSON.stringify({ choices: [{ delta: { reasoning_details: [{ type: "reasoning.text", text: "deliberating" }] }, index: 0 }] })}\n\n`
),
true
);
});