Symptom
Proxy crashes on first streaming request with:
TypeError: chunk.charCodeAt is not a function
or
SyntaxError: Unexpected token D, "[DONE]" is not valid JSON
Root Cause: Two bugs in proxy/proxy.js
Bug 1 — Buffer/String type mismatch (line ~225)
eventsource-parser.feed() expects a string but HTTP data event delivers a Buffer:
// BROKEN
parser.feed(chunk)
// FIXED
parser.feed(typeof chunk === "string" ? chunk : chunk.toString("utf8"))
Bug 2 — [DONE] guard ordered after JSON.parse (lines ~192, ~201)
The JSON.parse(event.data) on line 192 runs BEFORE the [DONE] guard on line 201:
// BROKEN (line 192 fires first)
if (event.event === "done" || JSON.parse(event.data || "{}")?.choices?.[0]?.finish_reason) {
// guard comes too late:
if (!event.data || event.data === "[DONE]") return
Fix: Move the [DONE] guard BEFORE the finish_reason check.
Impact
Every user hits this on their first streaming chat request — the proxy dies and systemd restarts it, repeating the crash loop. Silent failure mode, only visible in journalctl. No non-streaming workaround.
Fix
See both patches above. Two-line fix.
Symptom
Proxy crashes on first streaming request with:
or
Root Cause: Two bugs in
proxy/proxy.jsBug 1 — Buffer/String type mismatch (line ~225)
eventsource-parser.feed()expects a string but HTTPdataevent delivers aBuffer:Bug 2 —
[DONE]guard ordered afterJSON.parse(lines ~192, ~201)The
JSON.parse(event.data)on line 192 runs BEFORE the[DONE]guard on line 201:Fix: Move the
[DONE]guard BEFORE the finish_reason check.Impact
Every user hits this on their first streaming chat request — the proxy dies and systemd restarts it, repeating the crash loop. Silent failure mode, only visible in journalctl. No non-streaming workaround.
Fix
See both patches above. Two-line fix.