Repository navigation
Description
id(world_presentation): parse_surface collapses duplicate JSON keys before its checks — a forbidden version, width, lines, or rows hidden behind a duplicate is accepted
Summary
parse_surface (pkgs/id/crates/id-core/src/world_presentation.rs:419) is the gate that decides whether a world program's view output is a valid text/1 or screen/1 presentation — the module's contract is that guests never supply terminal escapes, control characters, or unsupported versions, and every presenter (web/world_ws.rs:182, world/actor.rs:1473, world_session/mod.rs:2404, the native shell) trusts its verdict.
It parses the guest document into a serde_json::Value first (world_presentation.rs:420), dispatches on value.get("kind"), and only then converts the already-collapsed value into TextPayload / ScreenPayload (:428, :445). Duplicate JSON keys therefore collapse last-wins before any check runs: the version gate (:431, :448), the width validation in TextSurface::with_width, the control-character rejection, and the screen row/shape checks only ever see the surviving value. A document whose raw form carries a forbidden value is accepted as long as a benign duplicate follows it.
This is the same defect class as #6473 (world::parse_records) and #6474 (world_fixture::decode) in sibling guest-facing parsers; parse_surface is the remaining presentation-path instance. The in-tree tests cannot express it: they build documents via serde_json::json! values (world_presentation.rs tests, fn screen(value: Value)), which cannot represent duplicate keys.
Verified (laptop, origin/main 49797df, probe ~/git/fleet/probe-surface-dup, real id crate, 1 test passed)
Controls — each single-key invalid form is rejected:
{"kind":"text","version":99,"lines":["hi"]}→ Err (unsupported version){"kind":"text","version":1,"width":0,"lines":["hi"]}→ Err (zero width){"kind":"text","version":1,"lines":["<ESC>[31mred"]}→ Err (control character){"kind":"screen","version":99,"width":2,"height":1,"rows":["hi"]}→ Err{"kind":"screen","version":1,"width":2,"height":1,"rows":["toolong"]}→ Err
Duplicate-key forms — every one is accepted (Ok(Some(..))):
{"kind":"text","version":99,"version":1,"lines":["hi"]}→ Text{"kind":"text","version":1,"width":0,"width":80,"lines":["hi"]}→ Text{"kind":"text","version":1,"lines":["<ESC>[31mred"],"lines":["clean"]}→ Text{"kind":"screen","version":99,"version":1,"width":2,"height":1,"rows":["hi"]}→ Screen{"kind":"screen","version":1,"width":2,"height":1,"rows":["toolong"],"rows":["hi"]}→ Screen{"kind":"screen","kind":"text","version":1,"lines":["hi"]}→ Text (the kind dispatch itself is last-wins)
Why it matters
- The version field is the format's compatibility gate: a document that declares an unsupported version anywhere in its raw form is not a v1 document, yet it is admitted as one. Any other reader of the same bytes — a stricter parser, a journal replay, a second implementation — sees a different document than the presenter rendered.
- The hidden values are exactly the ones this module exists to exclude (control characters/escape bytes, zero width, malformed rows). Acceptance depends on key order in a way no other pkgs/id guest parser permits after id(world): parse_records silently collapses duplicate JSON keys — an oversized value hidden behind a duplicate passes MAX_RECORD_VALUE_BYTES, and the record-count cap is checked after collapse #6473/id(world_fixture): decode accepts duplicate JSON fields in header and event lines — check_keys and the window check only ever see the collapsed last value #6474.
parse_surfaceis the single choke point for guest views on the web, SSH/session, and native-shell presenters, so one fix here closes the presentation path.
Acceptance criteria
parse_surfacerejects anykind: text/kind: screendocument containing a duplicate key at any level it inspects (top level at minimum), instead of collapsing last-wins.- Regression tests use raw string literals (not
serde_json::json!) covering at least: duplicateversion(text and screen), duplicatewidth, duplicatelinescarrying a control character, duplicaterows, and duplicatekind. - All previously valid documents still parse identically (existing world_presentation, world_session, sandbox, and native-shell tests green).
- Related: id(world): parse_records silently collapses duplicate JSON keys — an oversized value hidden behind a duplicate passes MAX_RECORD_VALUE_BYTES, and the record-count cap is checked after collapse #6473, id(world_fixture): decode accepts duplicate JSON fields in header and event lines — check_keys and the window check only ever see the collapsed last value #6474 (same class, sibling parsers), id: text/1 presentation contract — text-only as the main mode, with a text projection for every surface (#2027) #2339 (text/1 presentation contract).
Activity
developing-today commentedon Nov 6, 2026
CODE-1958
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 6, 2026
🤖 Agent note · handed off
dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
opencode, so task 10977 is handed off to the opencode claimant per the worker instruction §1b.75 remaining items
fix(id-core): reject duplicate JSON keys in parse_surface (#6491)
fix(id-core): restrict duplicate-kind rejection to the top-level obje…
fix(id-core): consume full map in duplicate-kind scan (#6491)
fix(id-core): restore top-level duplicate-kind scan lost in rebase (#…
Merge pull request #8424 from developing-today/queue/14443-6491-parse…
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — fixed and merged (task 10977, lane code-d)
parse_surfacerejects duplicate JSON keys in text/screen documents instead of collapsing them last-wins.TokenSpanstruct landed at the insertion point). Rebased onto current main (head aa60487); the conflict resolution initially dropped thetop_level_kind_is_duplicated(data)call from theparse_surfacecondition — Codex's re-review caught exactly that as a new P2 (4540059438); restored in aa60487 with the reviewer's example ({"x":1,"x":2,"kind":"screen","kind":"other"}) added to the regression list.cargo test -p id-core world_presentationon the laptop — 34 passed, 0 failed (rebased head, including main's new semantic-token tests).dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — already done (task 14983, lane code-d)
parse_surfacerejects duplicate keys in text/screen documents, with raw-string regression tests including the duplicate-kind shapes.already_donenaming task 10977 / PR fix(id-core): reject duplicate JSON keys in parse_surface (#6491) #8424 as the canonical work.feat(id-core): scene/1 WorldSurface kind — validation, projection, co…
feat(id): audio/1 WorldSurface kind — host validation, text projectio…