OpenCode Code Mode bug: TextEncoder.encode(null) silently returns empty bytes

sdivyanshu90 · ghdev · 2026-10-21

A reproduced issue in anomalyco/opencode: V2 Code Mode silently drops null when encoding text — new TextEncoder().encode(null) returns no bytes instead of the UTF-8 bytes for "null", corrupting serialized data when scripts encode nullable tool results. The root cause is args[0] ?? "" in textEncoderGlobal (packages/codemode/src/stdlib/bytes.ts), treating explicit null like an omitted argument. Proposed fix: default only undefined to an empty string, then apply string conversion per the WHATWG TextEncoder spec. Includes a runnable repro verified on Linux + Bun 1.4.3 with @opencode/codemode 2.1.2.

Original post →

More from coding & agent

coding & agent channel →