Codex app-server input has no per-message byte limit #12884
What happened#
The Codex app-server protocol accepts a newline-delimited JSON message of any size. It stores fragments until a newline arrives, joins them into one string, and then parses the full JSON value. The parser has no byte limit before these allocations.
The current count limit does not address this case. MAX_BUFFERED_RAW_MESSAGES = 32 limits decoded queue entries, not the size of one input message.
This install has received Codex events containing diff strings near 49 million characters. A single valid provider notification can therefore require a large line string, a parsed object, and later runtime event objects at the same time.
Diagnosis#
makeCodexAppServerPatchedProtocol reads text chunks from the child process and stores unfinished line fragments in remainder. It tracks no byte count. When it finds a newline, it runs remainder.join(""), then decodeWireMessage parses the result through Schema.fromJsonString.
The protocol applies its 32-message sliding queue only after JSON decoding and routing. The bound cannot stop one oversized line from exhausting the heap during line assembly or parsing.
Issue #5389 fixed quadratic input scanning. The current loop scans each chunk once, so that fix is present. It did not add a per-message byte limit.
Expected behavior: the protocol should enforce a documented byte ceiling while it receives line fragments. If a message exceeds the ceiling, T3 should stop or fail that provider session with a clear error instead of joining and parsing the full value. The check must run before remainder.join("").
Steps to reproduce#
Synthetic reproduction:
- Create a fake Codex app-server standard input stream.
- Send one newline-delimited JSON notification whose
paramscontains a generated string large enough to approach the V8 heap limit. - Split the message across many input chunks so the protocol stores fragments in
remainder. - End the line with a newline.
- Observe that the protocol joins and parses the full message without checking its byte size.
A focused regression test can add an injectable low message limit, send fragments that cross it, and assert that parsing never runs and the session receives a typed transport error.
Version#
0.0.43-nightly.20260920.2005, commit 7445aa733ada.
Environment#
- T3 Code desktop app with local backend
- Darwin 25.6.0, arm64
- Node.js 26.8.2
- Codex provider
Evidence#
Current count bound:
MAX_BUFFERED_RAW_MESSAGES = 32
Unbounded line state:
const remainder: Array<string> = []
Line assembly:
remainder.push(chunk.slice(start, newline))
lines.push(remainder.join(""))
Decode order:
assembled line -> decodeWireMessage(line) -> routeMessage(decoded)
Largest decoded file-change diff seen on this install:
about 49 million characters
No home paths, thread IDs, turn IDs, project names, commands, diff text, or credentials are included.
Related issues#
- #5389 fixed quadratic scanning in the app-server input reader. It did not add a byte limit.
- #10924 and #12305 bound diagnostic event serialization after protocol decoding.
- #7075 concerns an oversized
thread/resumeresponse. This report applies to any oversized app-server message. - #12758 concerns large payloads after decoding and persistence.
No open issue or pull request found in the upstream search covers the missing pre-parse byte limit.
Fix applied or workaround#
No source patch was made. Avoiding very large provider messages reduces risk, but T3 has no local setting for a protocol message limit.
Filed by#
Codex, GPT-5, via t3 triage
juliusmarminge added labelsaccepted
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
I'd like to take this — focused per-message byte limit on the Codex app-server input path.
Keeping the heap reproduction from #18271 here, as asked when it was closed.
Setup: a temporary vitest file in
packages/effect-codex-app-server/src/that callsmakeCodexAppServerPatchedProtocolwithmakeInMemoryStdio()andlogIncoming: true.- Start a
thread/readrequest and leave it pending. - Build one ASCII
turn/diff/updatednotification of 129 MiB (135,266,304 bytes, newline excluded), paddingparams.diffwithx. - Offer it to stdin in 65,536-byte chunks, yielding after each, then offer
\non its own. - Offer
{"id":1,"result":{"ok":true}}\n. - Sample
process.memoryUsage()after every chunk.
Observed on main (Linux x64, Node v24.21.0, 4,496,293,888-byte heap limit,
NODE_OPTIONSunset):- The reader joined the full line, logged it raw and decoded (135,266,304 bytes each) and delivered the notification.
- The pending request still succeeded. Nothing ended the session.
- Peak sampled heapUsed was 435,171,264 bytes (415 MiB) and RSS 674,459,648 bytes (643 MiB) for that one message. The samples include the test's own 129 MiB input buffer.
Nothing on main bounds a single line, so heap use grows with line length until join, parse or V8's string limit fails. A smaller fix that only adds the incoming-message limit follows in a separate PR.
- Start a
juliusmarminge closed this
Sign in to join this conversation.
Triage#
Confirmed on current
main. This is a real reliability gap, not a duplicate of the later-stage heap issues.makeCodexAppServerPatchedProtocolinpackages/effect-codex-app-server/src/protocol.tsstores unfinished JSONL fragments inremainderwith no byte counter. On newline (and again on stdin end) it doesremainder.join(""), thendecodeWireMessage→Schema.fromJsonString.MAX_BUFFERED_RAW_MESSAGES = 32only bounds decoded notification/request queues and in-flight request handlers. It cannot stop one oversized line from allocating during join or parse.#5389 / #8605 already made scanning linear (each chunk is scanned once; that loop is present). They did not add a size ceiling. The existing protocol test still sends a fragmented ~4 MiB
turn/diff/updatedand expects a successful parse.This is earlier than the other Codex heap reports:
thread/resumeresponse bodyACP already has Effect
ndJsonRpc()’s 16 MiBmaxBufferSize. Codex’s custom reader does not. #11216 / #11217 show that a cap that is too low bricks legitimate large sessions.Suggested fix#
Track pending fragment bytes while chunks arrive. If a line would exceed a documented ceiling, drop
remainder, skipjoin/ parse / raw logging, and terminate the provider session with a typed transport error. Inject a tiny limit inprotocol.test.tsso the regression can prove decode never runs.Production ceiling needs to sit above real Codex diffs (the 4 MiB test and the ~49M-character events on this install) and well below a V8 heap-threatening line. 16 MiB would reject those diffs. Something in the 64–128 MiB range is the useful band. A just-under-limit message can still blow up later in persistence/queues; those stay #12758 / #12883.