Repository navigation
Description
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 --streamwith the Anthropic provider. - Make the SSE stream contain a valid
content_block_deltaevent followed by a malformeddata:JSON payload and thenmessage_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.
Activity
404-Page-Found commentedon Sep 20, 2026
Triage
Priority: P2 — streaming correctness
Silently dropping malformed Anthropic frames can produce partial or unparseable suggestions without identifying the protocol failure. That makes the failure mode substantially harder to diagnose than an explicit parser error.
Disposition: Fix alongside the streaming reliability work. Keep behavior consistent with the OpenAI-compatible parser and add malformed-frame regression coverage for both affected event types.
Suggested implementation: propagate JSON parse failures with an Anthropic-specific error while retaining the existing reader cleanup guarantees.
404-Page-Found commentedon Sep 24, 2026
Triage update
Disposition: P2 — valid bug; fix needed.
Confirmed against current
main:parseAnthropicSseLine()still silently swallowsJSON.parse()failures for bothmessage_startandcontent_block_delta.streamSseResponse()already performs reader cleanup in itsfinallypath, so propagating the parser error should preserve cleanup behavior.Recommended implementation
Malformed Anthropic SSE data: invalid JSON.message_startandcontent_block_deltaframes.AnthropicProvider.completeStream()test with a valid chunk followed by malformed JSON to verify the error propagates and the response body is released.Disposition: keep open and address as part of the streaming-reliability work.
404-Page-Found commentedon Sep 24, 2026
Implemented in PR #329: malformed Anthropic JSON in
message_startandcontent_block_deltanow throwsMalformed Anthropic SSE data: invalid JSONinstead of being silently discarded. Added parser regression tests for both event types and an end-to-end stream test that verifies the response body is released on the parser error. CI is running on the PR.