← Back to PRs

#19134: fix(gateway): specify utf-8 encoding on SSE res.write() calls

by pierreeurope open 2026-02-17 12:17 View on GitHub →
gateway size: XS
## Problem Fixes #18897 Node.js `ServerResponse.write(string)` defaults to Latin-1 (binary) encoding. When an LLM response contains a character outside the Latin-1 range — such as ◆ (U+25C6, code point 9670) — the runtime throws: ``` TypeError: Cannot convert argument to a ByteString ``` This silently kills the SSE stream and returns no response to the client, breaking all subsequent gateway replies for that request. ## Fix Pass `"utf-8"` as the second argument to every `res.write()` call in the gateway SSE path: | File | Change | |------|--------| | `src/gateway/openai-http.ts` | `writeSse` helper | | `src/gateway/openresponses-http.ts` | `writeSseEvent` helper (both writes) | | `src/gateway/http-common.ts` | `writeDone` helper | 4-line change, no logic altered. ## Testing Reproduce by asking the model to produce a response containing ◆ (U+25C6). Before this fix the stream errors; after, it streams correctly. <!-- greptile_comment --> <h3>Greptile Summary</h3> Added `"utf-8"` encoding parameter to all `res.write()` calls in SSE streaming helpers to prevent Node.js from defaulting to Latin-1 encoding. This fixes stream crashes when LLM responses contain characters outside the Latin-1 range (e.g., ◆ U+25C6). <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is surgical (4 lines changed across 3 files), addresses a specific encoding bug with no logic changes, and all SSE write paths have been consistently updated - No files require special attention <sub>Last reviewed commit: 4304165</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs