You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
V2 Code Mode silently drops null when encoding text: new TextEncoder().encode(null) returns no bytes instead of the UTF-8 bytes for "null". This changes serialized data when a script encodes a nullable tool result.
textEncoderGlobal in packages/codemode/src/stdlib/bytes.ts uses args[0] ?? "", treating explicit null like an omitted argument. Default only undefined to the empty string, then apply string conversion. This matches the TextEncoder contract.
Plugins
None required.
OpenCode version
V2 development checkout; @opencode/codemode 2.1.2.
Steps to reproduce
Save this as repro.ts in packages/codemode and run bun repro.ts:
Observed: successful result with value: [].
Expected: value: [110, 117, 108, 108], matching native TextEncoder. Omitted input and explicit undefined should still produce no bytes.
Thanks for the clear report. I reproduced this on the latest dev (c9b5a9f, @opencode/codemode 2.1.2). Inside Code Mode, new TextEncoder().encode(null) returns [], but native TextEncoder returns [110, 117, 108, 108]. encode() and encode(undefined) correctly return []. As you found, the cause looks like the args[0] ?? "" in packages/codemode/src/stdlib/bytes.ts, which turns an explicit null into an empty string. The script below reproduces it.
Reproduction script (repro.ts)
// Run from an opencode checkout: bun /workspace/repro/repro.ts [/path/to/repo]import{Effect}from"effect"constrepo=process.argv[2]??process.env.OC_DEV??"/workspace/repo"const{ CodeMode }=awaitimport(`${repo}/packages/codemode/src/index.ts`)for(constcodeof["return [...new TextEncoder().encode(null)]","return [...new TextEncoder().encode()]","return [...new TextEncoder().encode(undefined)]",]){constr=awaitEffect.runPromise(CodeMode.execute({ code,tools: {}}))console.log(code,"=>",JSON.stringify(r.value??r))}constnative=(v: any)=>[...newTextEncoder().encode(v)]console.log("native null =>",JSON.stringify(native(null))," native undefined =>",JSON.stringify(native(undefined)))
Hi @rekram1-node, I'd like to claim this issue. I've prepared a fix with regression tests: encode(null) preserves the text "null", while omitted input and undefined still produce empty bytes. The full CodeMode suite and package typecheck pass.
Could you please review the proposed fix when you have some time? I can raise a PR, but GitHub currently blocks creation with: "You've reached this repository's open pull request limit." I'll open it once a slot is available. Thanks!
im not looking to endlessly make the interpreter handle every edge case in javascript, it's a tool orchestration environment, unless ur seeing agents write code that breaks then i dont rlly want more of these styles of issues opened ideally
Not sure if u actually hit this or if u just have agents looking to find issues, but this seems like edge case
Thanks for clarifying, @rekram1-node. These reports came from compatibility testing, not failures I encountered in an actual agent workflow. I should have made that distinction clear.
I’ll leave #57633 closed, and I’m happy to close #57632 as well. Going forward, I’ll focus on issues with demonstrated impact on real V2 workflows. Thanks for the guidance.
Activity
opencode-agent commentedon Oct 21, 2026
Thanks for the clear report. I reproduced this on the latest
dev(c9b5a9f,@opencode/codemode2.1.2). Inside Code Mode,new TextEncoder().encode(null)returns[], but nativeTextEncoderreturns[110, 117, 108, 108].encode()andencode(undefined)correctly return[]. As you found, the cause looks like theargs[0] ?? ""inpackages/codemode/src/stdlib/bytes.ts, which turns an explicitnullinto an empty string. The script below reproduces it.Reproduction script (repro.ts)
Run it:
bun repro.tssdivyanshu90 commentedon Oct 21, 2026
Hi @rekram1-node, I'd like to claim this issue. I've prepared a fix with regression tests:
encode(null)preserves the text"null", while omitted input and undefined still produce empty bytes. The full CodeMode suite and package typecheck pass.Could you please review the proposed fix when you have some time? I can raise a PR, but GitHub currently blocks creation with: "You've reached this repository's open pull request limit." I'll open it once a slot is available. Thanks!
rekram1-node commentedon Oct 21, 2026
im not looking to endlessly make the interpreter handle every edge case in javascript, it's a tool orchestration environment, unless ur seeing agents write code that breaks then i dont rlly want more of these styles of issues opened ideally
Not sure if u actually hit this or if u just have agents looking to find issues, but this seems like edge case
sdivyanshu90 commentedon Oct 21, 2026
Thanks for clarifying, @rekram1-node. These reports came from compatibility testing, not failures I encountered in an actual agent workflow. I should have made that distinction clear.
I’ll leave #57633 closed, and I’m happy to close #57632 as well. Going forward, I’ll focus on issues with demonstrated impact on real V2 workflows. Thanks for the guidance.
rekram1-node commentedon Oct 21, 2026
sounds good ill close this for now then thanks.
Ideally don't look for issues, instead raise problems u actually hit. Otherwise it's a lot of noise for us.