Skip to content

[Bug] Malformed SSE JSON chunks are silently swallowed in streaming #269

Description

@404-Page-Found

Summary

parseOpenAiSseLine catches JSON.parse failures and silently returns {}. When a provider emits a truncated or corrupt data: chunk mid-stream (e.g. a network glitch), the chunk is dropped with no diagnostic. Combined with the missing body-consumption timeout in streaming requests, a broken connection can leave the user with a partial suggestion and no error at all.

Location

  • src/providers/sse.ts:77-99 (OpenAI parser), specifically the catch at :95-97

Code snippet

try {
  const parsed = JSON.parse(payload) as { ... };
  ...
  return result;
} catch {
  // Skip malformed JSON chunks
}
return {};

Suggested fix

Distinguish "not a data line" (fine to ignore) from "line starts with data: but payload is not valid JSON" (a real protocol anomaly). For the latter, surface a descriptive error to the caller (or warn) rather than continuing silently — e.g. track consecutive malformed chunks and fail the stream after a threshold.

Impact

  • Silent partial/missing streamed content with no diagnostic when a connection hiccups mid-stream.
  • In combination with the streaming timeout gap, --stream can terminate with incomplete output and the user has no signal anything went wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions