Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(openai-codex): report text() drops in characters, not bytes
Jack Rudenko4504396ea8ae
diff --git a/ai-docs/architecture/code-mode.md b/ai-docs/architecture/code-mode.mdindex 276c631d..a53bf876 100644--- a/ai-docs/architecture/code-mode.md+++ b/ai-docs/architecture/code-mode.md@@ -10,9 +10,13 @@ Codex client has driven these models this way since `tool_mode: code_mode_only`;only client still sending them classic parallel function calls.The default is `off` until the Phase 7 live validation passes; a separate change then makes `auto`-the default (on where the account's dynamic models catalog reports `code_mode_only`). Every-request with code mode off is byte-for-byte what it was before code mode existed, apart from one-`[CodeMode] off (setting-off)` log line per session.+the default (on where the account's dynamic models catalog reports `code_mode_only`). With code+mode off, everything code mode added is skipped (5r returns at once, 5d returns at the+`setting-off` gate, apart from one `[CodeMode] off (setting-off)` log line per session). The+request is NOT byte-for-byte what it was before this work, for one deliberate reason: commit+`d6629064` sends `filterIdentity(system)` as the Responses `instructions` of EVERY `cx@` and+`openai@` request, where the raw "You are Claude Code" system prompt went before. Each existing+session loses its prompt-cache prefix once after that upgrade.Design and evidence: `ai-docs/sessions/dev-feature-codex-tool-calls-20261016-143706-dc2c/`(`architecture.md`, `research-codemode.md`, `research-sandbox.md`, `evidence/r1/`, `evidence/r2/`)@@ -318,7 +322,7 @@ promise that can never settle`). `blocked([])` is unrepresentable.| calls per batch / per script | 32 / 256 | the excess call rejects with a string, so `Promise.allSettled` still finishes || one call input / one batch | 2 MiB / 8 MiB | that call rejects || tool result into the script | 1 MiB each (truncated, marked) / 8 MiB per script | rejects |-| `text()` output | 1 MiB per exec, enforced by the HOST on what it receives (a tampered prelude can waste one bounded copy, never raise the total); `text("")` adds no part; ≤ 1,024 parts (the store counts 64 bytes per part) | dropped, with a warning line; past 1,024 parts, text joins the last part |+| `text()` output | 1,048,576 characters (UTF-16 code units, not bytes) per exec, enforced by the HOST on what it receives (a tampered prelude can waste one bounded copy, never raise the total); `text("")` adds no part; ≤ 1,024 parts (the store counts 64 bytes per part) | dropped, with a warning line; past 1,024 parts, text joins the last part || output tokens | `max_output_tokens` pragma clamped to [1, 50,000]; default discovery's `truncation_policy.limit` in tokens, else 10,000 | Codex's truncation header, at 4 B/token |Why 32 MiB and 2 s: the heap limit stops one runtime's ordinary allocations; it bounds nothingdiff --git a/packages/cli/src/code-mode/sandbox/script-runtime.ts b/packages/cli/src/code-mode/sandbox/script-runtime.tsindex 2cfa7e46..67017b7b 100644--- a/packages/cli/src/code-mode/sandbox/script-runtime.ts+++ b/packages/cli/src/code-mode/sandbox/script-runtime.ts@@ -103,6 +103,7 @@ export interface SandboxLimits {batchInputBytes: number;resultBytes: number;resultBytesPerScript: number;+ /** `text()` output per exec, counted in characters (UTF-16 code units), not UTF-8 bytes. */outputBytes: number;/** Output parts kept separate; past this, text joins the last text part. */outputParts: number;@@ -605,7 +606,8 @@ class QuickJSScriptRuntime implements ScriptRuntime, LeasedRuntime {if (this.outputDropped > 0) {parts.push({type: "text",- text: `Warning: output exceeded claudish's ${describeBytes(this.limits.outputBytes)} limit; ${this.outputDropped} bytes dropped`,+ // `text()` output is counted in characters (UTF-16 code units), not bytes.+ text: `Warning: output exceeded claudish's limit of ${this.limits.outputBytes.toLocaleString("en-US")} characters; ${this.outputDropped.toLocaleString("en-US")} characters dropped`,});}const output: ExecOutput = { status, wallMs: this.wallMs(), parts };@@ -724,7 +726,9 @@ class QuickJSScriptRuntime implements ScriptRuntime, LeasedRuntime {if (handle.alive) handle.dispose();}const text = describeGuestError(value);- if (/out of memory/i.test(text)) return "out of memory: the script exceeded its 32 MiB heap";+ if (/out of memory/i.test(text)) {+ return `out of memory: the script exceeded its ${describeBytes(this.limits.memoryBytes)} heap`;+ }return text;}