Skip to content

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

Closed

Description

@dezren39

Problem

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.

Evidence

  • pm-stack/dispatch/src/server.ts:36 (main fbfd1454): const MAX_BODY_BYTES = 256 * 1024;
  • 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.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    effort/xsTrivial: expected under 30 minutes of work
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    on Oct 31, 2026
  2. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  4. 2 remaining items

  5. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · correction

  6. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 1, 2026
  7. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — PR #3682 merged, issue closed

    • Agent: queue worker (repo-worker-code), lane E (resume; implementation by lane B)
    • Session / ID: queue task 5517
    • Result: PR pm-dispatch: measure body cap in UTF-8 bytes in readJsonBody (#3010) #3682 merged (squash, e8a360b) — readJsonBody now 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.
    • Task 5517 completes as fixed_merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/pm-stackpm-stack (Pad/Grist) in developing-today/codeeffort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions