fix(ws): preserve Buffer payloads for text frames

Closed
ST
1mo ago
+45-15

The ws replacement changes text payloads according to binaryType: an arraybuffer client receives a plain Uint8Array, and server connections can receive an ArrayBuffer or Blob. npm ws always emits text as a Buffer with isBinary=false. This can turn valid JSON text into a comma-separated byte string and break decoding.

Convert text to Buffers on both client and server paths, and leave the fragments wrapper for binary messages only. Add empty/Unicode text regressions for both directions and document the behavior.

Validation:

  • Native Linux x64 build on upstream base aa8307619d8 with this patch: 114 WebSocket tests pass, three existing TODOs, across ws.test.ts, ws-proxy.test.ts, and ws-upgrade-events.test.ts.
  • Node 24.19 controls return Buffer/valid JSON. The unpatched c999 fork, whose relevant text branches match upstream, fails the arraybuffer/blob/fragments regressions; the candidate passes all four modes.
  • A standalone local WebSocket text-frame repro passes on the upstream candidate.
  • The equivalent fork patch fixes all four keyless OpenClaw Discord rendering cases: 4 failures before, 4 passes after, with 4 passing Node controls.
  • Codex P2 review: scoped-clean.