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
{{ message }}
Repository navigation
pm-dispatch(server): the 256 KiB body cap is measured in UTF-16 code units, not bytes — a 300 KB CJK body passes readJsonBody's 'too large' check #3010
pm-dispatch's request body cap is named and documented as a byte cap, but it is measured in UTF-16 code units — so a body well over the cap in bytes passes the check whenever the prompt text is non-ASCII.
server.ts:47-48, readJsonBody: const text = await req.text(); if (text.length > MAX_BODY_BYTES) throw new ValidationError("body: too large"); — String.length counts UTF-16 code units, not bytes.
Verified this run with the runtime's own semantics: a string of 100,000 CJK characters has length 100,000 (≤ 262,144, so it passes) but encodes to 300,000 UTF-8 bytes — ~17% over the stated cap. Worst common cases: CJK text passes at up to ~3× the cap in bytes (786,432 bytes); astral-plane characters (emoji) at up to ~2× (2 code units per 4-byte character, 524,288 bytes).
Why it matters
The cap is the intake boundary's only size guard before JSON.parse and packet construction on both authenticated endpoints (POST /v1/sessions, POST /v1/tasks). Its stated unit is bytes; the enforced unit is code units, so the guard the operator thinks is in place (256 KiB) is not the guard that runs (up to ~768 KiB of actual body).
Dispatch prompts are exactly the traffic that goes non-ASCII: callers paste prompts with CJK text, emoji and smart punctuation, so the miscount is on the common path, not an exotic one.
Nothing else in the service re-checks size: the packet, issue body and queue task all carry the prompt onward at whatever size passed.
Acceptance criteria
readJsonBody rejects on the body's UTF-8 byte length (e.g. new TextEncoder().encode(text).length or Buffer.byteLength(text)), keeping the same MAX_BODY_BYTES value and the same ValidationError("body: too large") behavior for ASCII bodies.
A test in pm-stack/dispatch/test/ pins both sides of the boundary with multibyte text: a body just under the cap in bytes passes; a body under the cap in code units but over it in bytes is rejected.
Existing dispatch tests still pass (bun test in pm-stack/dispatch).
Found by new-issue-creator-code-a, run 2026-10-31; verified by direct read of server.ts on main fbfd1454 plus a runtime semantics check this run (100,000 CJK chars: length 100,000, 300,000 UTF-8 bytes). Dedup: searched open+closed issues for MAX_BODY_BYTES / dispatch body size / readJsonBody — no hits; the #2668 design doc's boundary rule covers shape/scope validation of fields, not the body-size unit.
Session / ID: new-issue-creator-code-a cron run 2026-10-31 04:35 CDT
Found via: filed this run
Task: Filed this issue: pm-dispatch(server): the 256 KiB body cap is measured in UTF-16 code units, not bytes — a 300 KB CJK body passes readJsonBody's 'too large' check
Expectation: xs; done when the acceptance criteria in the issue body are met and pinned by tests where the criteria require them.
Activity
dezren39 commentedon Oct 31, 2026
🤖 Agent note · filed
2 remaining items
dezren39 commentedon Nov 1, 2026
🤖 Agent note · correction
repo-health:v1:fix:developing-today/code:issue:3010), not 5518 as the findings note stated. Everything else in the findings stands.pm-dispatch: measure body cap in UTF-8 bytes in readJsonBody (#3010) (#…
dezren39 commentedon Nov 1, 2026
🤖 Agent note · done — PR #3682 merged, issue closed
readJsonBodynow enforces the 256 KiB cap in UTF-8 bytes; ASCII behaviour unchanged. Codex review at c97bfc1: completed, no findings. Dispatch suite 90 pass incl. 4 new boundary tests (lane B, laptop). This issue auto-closed on merge.fixed_merged.