Description
The Anthropic SSE parser silently ignores malformed JSON for message_start and content_block_delta events. A corrupted/incomplete event can therefore disappear from the stream without any error, leaving the consumer with a truncated response.
This is inconsistent with the OpenAI-compatible SSE parser, which explicitly throws on malformed JSON.
Location
src/providers/sse.ts:154-184 — parseAnthropicSseLine()
Relevant code
if (state.currentEvent === 'content_block_delta') {
try {
const parsed = JSON.parse(payload) as { delta?: { text?: string } };
if (parsed.delta?.text) {
return { kind: 'text', text: parsed.delta.text };
}
} catch {
// Skip malformed JSON
}
return null;
}
The same silent catch exists for message_start.
By contrast, parseOpenAiSseLine() throws Malformed OpenAI SSE data: invalid JSON.
Steps to reproduce
- Run
commit-echo suggest --stream with the Anthropic provider.
- Make the SSE stream contain a valid
content_block_delta event followed by a malformed data: JSON payload and then message_stop.
- The malformed event is ignored and the stream continues as if it were absent.
- Depending on the remaining content, the command may end with truncated suggestions or a generic parse failure instead of identifying the malformed provider response.
This can be reproduced with a mocked fetch() response in the existing tests/stream-sse.test.mjs setup.
Expected behavior
Malformed provider frames should fail the stream with a clear error and release the response body.
Actual behavior
Malformed Anthropic frames in these event types are swallowed, so the caller cannot distinguish “provider sent bad JSON” from “provider sent no content.”
Suggested fix
Let JSON parse failures propagate with an Anthropic-specific error (matching the OpenAI behavior), and add regression tests for malformed message_start and content_block_delta frames.
Impact
Streaming responses can be silently truncated, producing misleading or unparseable commit suggestions and making provider-side protocol failures difficult to diagnose.
Reviewed against current main at c67ff967a018d5fd4b032f6ef6a4981ac9d76a12.
Description
The Anthropic SSE parser silently ignores malformed JSON for
message_startandcontent_block_deltaevents. A corrupted/incomplete event can therefore disappear from the stream without any error, leaving the consumer with a truncated response.This is inconsistent with the OpenAI-compatible SSE parser, which explicitly throws on malformed JSON.
Location
src/providers/sse.ts:154-184—parseAnthropicSseLine()Relevant code
The same silent catch exists for
message_start.By contrast,
parseOpenAiSseLine()throwsMalformed OpenAI SSE data: invalid JSON.Steps to reproduce
commit-echo suggest --streamwith the Anthropic provider.content_block_deltaevent followed by a malformeddata:JSON payload and thenmessage_stop.This can be reproduced with a mocked
fetch()response in the existingtests/stream-sse.test.mjssetup.Expected behavior
Malformed provider frames should fail the stream with a clear error and release the response body.
Actual behavior
Malformed Anthropic frames in these event types are swallowed, so the caller cannot distinguish “provider sent bad JSON” from “provider sent no content.”
Suggested fix
Let JSON parse failures propagate with an Anthropic-specific error (matching the OpenAI behavior), and add regression tests for malformed
message_startandcontent_block_deltaframes.Impact
Streaming responses can be silently truncated, producing misleading or unparseable commit suggestions and making provider-side protocol failures difficult to diagnose.
Reviewed against current
mainatc67ff967a018d5fd4b032f6ef6a4981ac9d76a12.