Skip to content

fix(proxy): crash on streaming — Buffer/String + [DONE] ordering#2

Open
tbosancheros39 wants to merge 1 commit into
masterfrom
fix/streaming-crashes
Open

fix(proxy): crash on streaming — Buffer/String + [DONE] ordering#2
tbosancheros39 wants to merge 1 commit into
masterfrom
fix/streaming-crashes

Conversation

@tbosancheros39

Copy link
Copy Markdown
Owner

What

Two crash bugs in proxy.js confirmed by 3 independent reviews. Both crash the proxy on the first streaming chat request.

Bug 1 — chunk.charCodeAt is not a function

eventsource-parser.feed() expects string but Node.js HTTP data event delivers Buffer. Fix: typeof chunk === "string" ? chunk : chunk.toString("utf8")

Bug 2 — [DONE] is not valid JSON

JSON.parse(event.data) ran before the [DONE] guard. Fix: reorder — check [DONE] first, then parse.

Testing

  • deepseek-v4-flash via proxy: ✅
  • kimi-k2.7-code via OpenCode Go: ✅
  • kimi-k2.6 via OpenCode Go: ✅

Reviews

3 independent code reviews: all CORRECT. No side effects.

Closes #1

Bug 1: eventsource-parser.feed() expected string but HTTP data event
delivered Buffer. Convert chunk to string before parsing.

Bug 2: finish_reason JSON.parse ran before [DONE] guard check.
Move [DONE] guard above the JSON.parse call.

Both crash the proxy on the first streaming chat request.
Fixes #1
@tbosancheros39 tbosancheros39 force-pushed the fix/streaming-crashes branch from 1f0c5ad to 3eafe7a Compare June 24, 2026 17:11
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.

proxy.js crashes: Buffer/String mismatch + [DONE] JSON.parse ordering

1 participant