Skip to content

fix: skip empty SSE data lines to avoid spurious parse errors#1326

Merged
lewis617 merged 1 commit into
mainfrom
worktree-clever-narrow-star
Jul 2, 2026
Merged

fix: skip empty SSE data lines to avoid spurious parse errors#1326
lewis617 merged 1 commit into
mainfrom
worktree-clever-narrow-star

Conversation

@lewis617

@lewis617 lewis617 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

app.log was flooded with errors every ~12s:

[ERROR] Failed to parse stream chunk {"error":{},"data":""}

Root Cause

Servers/proxies send empty data: lines as SSE keepalive heartbeats. The streaming parser in openaiClient.ts attempted JSON.parse("") on these empty payloads, throwing a SyntaxError each time. The SyntaxError object's message property is non-enumerable, so it serialized as {} in the log.

Fix

  • Skip empty data lines (if (!data) continue) before attempting JSON.parse, silently ignoring keepalive heartbeats.
  • Log actual error message (e instanceof Error ? e.message : String(e)) instead of the raw error object, so any future parse failures are diagnosable.

Testing

  • All 14 existing openaiClient tests pass.
  • Type-check and lint pass (pre-commit hooks verified).

Servers/proxies send empty data: lines as keepalive heartbeats every ~12s.
JSON.parse("") threw SyntaxError, flooding app.log with noise like:
  [ERROR] Failed to parse stream chunk {"error":{},"data":""}

- Skip empty data lines before JSON.parse
- Log actual error message instead of empty object
@lewis617 lewis617 merged commit a6a4203 into main Jul 2, 2026
1 check passed
@lewis617 lewis617 deleted the worktree-clever-narrow-star branch July 2, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant