Repository navigation
fix(translator): accept Claude Messages shape in non-stream malformed-200 guard #5156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 4 commits into
cheaper-inference:release/v3.8.39
from
NomenAK:fix/midthread-502-claude-validate
Jun 28, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c016799
fix(translator): accept Claude Messages shape in non-stream malformed…
f994548
fix(translator): treat Claude "(empty response)" placeholder as malfo…
7883515
merge: bring fix/midthread-502-claude-validate up to date with releas…
diegosouzapw c47c8e6
fix(diagnostics): dedupe Claude Messages malformed-200 guard; keep si…
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,53 @@ test("detectMalformedNonStream allows Responses API function_call items as valid | |
| assert.equal(detectMalformedNonStream(body), null); | ||
| }); | ||
|
|
||
| // ── (c2) detectMalformedNonStream — Claude Messages shape ──────────────────── | ||
|
|
||
| test("detectMalformedNonStream returns null for Claude message with text content", () => { | ||
| const body = { | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "text", text: "Hi!" }], | ||
| stop_reason: "end_turn", | ||
| }; | ||
| assert.equal(detectMalformedNonStream(body), null); | ||
| }); | ||
|
|
||
| test("detectMalformedNonStream returns null for Claude message with tool_use block", () => { | ||
| const body = { | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "tool_use", id: "toolu_1", name: "search", input: {} }], | ||
| stop_reason: "tool_use", | ||
| }; | ||
| assert.equal(detectMalformedNonStream(body), null); | ||
| }); | ||
|
|
||
| test("detectMalformedNonStream returns null for Claude message with thinking block", () => { | ||
| const body = { | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "thinking", thinking: "let me think" }], | ||
| stop_reason: "end_turn", | ||
| }; | ||
| assert.equal(detectMalformedNonStream(body), null); | ||
| }); | ||
|
|
||
| test("detectMalformedNonStream returns 'empty_choices' for Claude message with empty content", () => { | ||
| const body = { type: "message", role: "assistant", content: [], stop_reason: "end_turn" }; | ||
| assert.equal(detectMalformedNonStream(body), "empty_choices"); | ||
| }); | ||
|
|
||
| test("detectMalformedNonStream returns 'empty_choices' for Claude message with empty-text block", () => { | ||
| const body = { | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "text", text: "" }], | ||
| stop_reason: "end_turn", | ||
| }; | ||
| assert.equal(detectMalformedNonStream(body), "empty_choices"); | ||
| }); | ||
|
Comment on lines
+249
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a unit test to verify that the test("detectMalformedNonStream returns 'empty_choices' for Claude message with empty-text block", () => {
const body = {
type: "message",
role: "assistant",
content: [{ type: "text", text: "" }],
stop_reason: "end_turn",
};
assert.equal(detectMalformedNonStream(body), "empty_choices");
});
test("detectMalformedNonStream returns 'empty_choices' for Claude message with '(empty response)' placeholder", () => {
const body = {
type: "message",
role: "assistant",
content: [{ type: "text", text: "(empty response)" }],
stop_reason: "end_turn",
};
assert.equal(detectMalformedNonStream(body), "empty_choices");
}); |
||
|
|
||
| // ── (d) no stack trace leakage ─────────────────────────────────────────────── | ||
|
|
||
| test("synthOpenAIErrorChunk message does NOT contain stack trace path", () => { | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
responseTranslator.ts, the functionconvertOpenAINonStreamingToClaudetranslates empty or missing content into a placeholder block withtext: "(empty response)". SincedetectMalformedNonStreamruns after response translation, a translated empty response will containtext: "(empty response)". Currently, this block is treated as valid output because its length is greater than 0, which allows empty responses to bypass this malformed guard for Claude clients. We should explicitly exclude"(empty response)"from being considered as valid output.