fix(sse): widen max_tokens/tool_use exemption to lone empty text blocks (#12968) - #13771
Merged
diegosouzapw merged 3 commits intoSep 16, 2026
Merged
Conversation
…ks (#12968) detectMalformedNonStream (open-sse/utils/diagnostics.ts) only exempted a terminal stop_reason of max_tokens/tool_use when content was a completely empty array ([]). An Anthropic-compatible shim's tiny max_tokens:1 probe instead returns content:[{type:"text",text:""}] — one block with no visible text — which fell straight through to empty_choices regardless of stop_reason, producing a false upstream_empty_response/502. Fix hoists the stop_reason exemption check out of the content.length===0 conditional so it applies whenever detectMalformedNonStream finds no visible output, matching errorClassifier.ts's existing raw-body behavior for the same shape. Regression test: tests/unit/issue-12968-anthropic-shim-empty-text-block.test.ts
…8-anthropic-shim-tiny-probe-empty
…empty (base-red fix #13747)
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…ks (diegosouzapw#12968) (diegosouzapw#13771) Merged in the 2026-09-16 sweep of the maintainer's own open PRs, at the owner's explicit instruction. No push was made to the PR branch: the merge took the head as the owning session left it (verified OPEN, non-draft and MERGEABLE against the release tip immediately before merging).
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.
Closes #12968
Root cause (short)
detectMalformedNonStreaminopen-sse/utils/diagnostics.tsonly exempted a terminalstop_reasonofmax_tokens/tool_use(the #9971 fix) whencontentwas a completely empty array (content: []). A tinymax_tokensprobe against an Anthropic-compatible provider shim instead returnscontent: [{type:"text", text:""}]— one block with no visible text — which took a different path through the function and fell straight toempty_choicesregardless ofstop_reason, producing a falseupstream_empty_response→ 502.errorClassifier.ts's raw-bodyisEmptyContentResponsealready handles this shape correctly (it short-circuits oncontent.length > 0), so the mismatch was only in the post-translation classifier.Fix
Hoisted the
stop_reasonexemption check (max_tokens/tool_use) out of thecontent.length === 0conditional so it applies wheneverdetectMalformedNonStreamfinds no visible output — regardless of whethercontentis[]or holds only textless/empty blocks. No change toerrorClassifier.ts(already correct for this shape). The exemption's values (max_tokens,tool_use) are unchanged, only its scope test widened.Regression test
tests/unit/issue-12968-anthropic-shim-empty-text-block.test.ts— built from the exact upstream body captured in the issue.RED (unfixed code):
GREEN (fixed code):
Gates run
npx eslint --suppressions-location config/quality/eslint-suppressions.json open-sse/utils/diagnostics.ts tests/unit/issue-12968-anthropic-shim-empty-text-block.test.ts→ cleannpm run check:open-sse-typecheck→ exit 0node scripts/check/check-file-size.mjs→ no violation on touched files (pre-existingopen-sse/utils/stream.tsdrift is base, not mine — identical line count onorigin/release/v3.8.51)node scripts/check/check-complexity.mjs→ clean, no violations on touched filesnode scripts/check/check-cognitive-complexity.mjs→ OK, 1276 violations vs baseline 1437 (no regression)node scripts/check/check-test-discovery.mjs→ OK, new test file discoveredtests/unit/diagnostics.test.ts,tests/unit/issue-9971-empty-choices-contentless-claude.test.ts,tests/unit/diagnostics-claude-thinking-5108.test.ts→ 50/50 pass, no regressionsExisting tests aligned
None — no existing assertion encoded the old buggy contract; the new exemption scope is strictly additive to an already-correct set of cases (verified against all pre-existing Claude-shape tests in the files above).