Skip to content

id(web/collab): INIT doc content entries unchecked — one unknown node/mark or non-string text silently discards the whole document and opens an empty editor #7884

Closed

Description

@dezren39

Problem

pkgs/id/web/src/collab.ts handleMessage validates the INIT frame's doc only at the top level (collab.ts:305-314 at origin/main 69aa168d5d): the doc must be a non-array object with type === "doc", and content, if present, must be an array. The content entries are never checked. The doc is passed to initEditor (editor.ts:659-666), where Node.fromJSON throws on the first bad entry and the catch falls back to an empty doc:

doc = Node.fromJSON(editorSchema, initialDoc);
} catch (err) {
  console.error("[editor] Failed to parse initial doc JSON, using empty doc:", err);
  doc = editorSchema.topNodeType.createAndFill() ?? editorSchema.node("doc");
}

So a single malformed entry silently discards the entire document: the editor opens empty, onEditorReady fires, the session proceeds as if the file were empty — no frame drop, no error status, no reconnect/resync. The realistic trigger is version skew: a newer server (or a peer's newer client via the server) emits a node or mark type this client predates, and every older client opens the file as empty — one edit plus autosave away from overwriting the real content with the empty state. This is the doc-content sibling of #7859 (INIT mode field, same empty-editor outcome via the raw schema); #2824 hardened INIT version/doc-type only, and no filing covers doc content entries.

Verified behavior (laptop probe, origin/main 69aa168)

Probe: ~/git/fleet/probe-creator-a-20261108/pkgs/id/web/src/probe-initdoc.test.ts (real initCollab + FakeWebSocket harness, msgpackr-packed INIT frames, mode "rich"; 5/5 probe tests run, existing collab+editor suites 146/146 green as control):

  1. Control: valid rich doc {type:"doc", content:[{type:"paragraph", content:[{type:"text", text:"hello rich"}]}]} → editor text is hello rich.
  2. One unknown node type discards everything: content = a valid paragraph (good paragraph) plus {type:"future_node_from_newer_server", …} → editor ready with text "", doc doc(paragraph) (empty). The valid paragraph is lost too.
  3. Non-string text: a text node with text: 12345 → editor ready, text "".
  4. Numeric content entry: content: [42] → editor ready, text "".
  5. Unknown mark type: a text node with marks: [{type:"future_mark"}] → editor ready, text "".

In every malformed case onEditorReady fired and the session continued (no drop/reconnect), so the user is shown an apparently-empty file with a live save path.

Why it matters

INIT is the one frame that defines what the user believes the file contains. A whole-document silent discard is a data-loss footgun (empty view + autosave) and makes client/server version skew — inevitable as node/mark types evolve — destructive instead of degrading. The frame boundary is where the rest of this file already validates (#2824); content entries are the unvalidated remainder of that same frame.

Acceptance criteria

  • INIT handling validates doc content entries deeply enough that a doc Node.fromJSON cannot parse is rejected at the frame boundary (log + drop, session/socket intact, no editor initialized from it), mirroring the malformed-INIT drop path — OR initEditor's parse failure on a server-supplied doc surfaces as a visible error/resync instead of a silent empty editor. Either way: a non-empty server doc must never present as an empty editable file.
  • The fix must not change behavior for valid docs in any content mode (rich/markdown/plain/raw), including docs with no content field.
  • Regression tests in collab.test.ts / editor.test.ts style for each probed case: unknown node type, unknown mark type, non-string text, numeric content entry — plus the valid-doc control.
  • Existing pkgs/id web vitest suite + typecheck green.

Evidence

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 9, 2026
  2. developing-today commented on Nov 9, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-a)
    • Session / ID: new-issue-creator-code-a run 2026-11-08 18:35 CST
    • Found via: filed this run
    • Task: Filed after laptop probe verification at origin/main 69aa168 (probe ~/git/fleet/probe-creator-a-20261108, real initCollab harness): INIT doc content entries are unchecked beyond type/Array.isArray(content) (collab.ts:305-314), so one unknown node/mark type, non-string text, or numeric entry makes Node.fromJSON throw in initEditor (editor.ts:659-666) and the whole document is silently replaced with an empty doc — editor ready, session live, valid paragraphs lost too. Controls: valid rich doc renders its text; collab+editor suites 146/146.
    • Expectation: effort/s — reject an unparseable INIT doc at the frame boundary (or surface a visible error/resync instead of a silent empty editor); done when the acceptance criteria tests pass.
    • Links: probe ~/git/fleet/probe-creator-a-20261108/pkgs/id/web/src/probe-initdoc.test.ts; body file hidden_files/creator-a-2026-11-08-1835/issue-body.md
  4. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 11, 2026
  5. 1 remaining item

  6. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: parked (CI wait)
    queue: repo-health-code-pilot
    task: 14237 (small_fix)
    issue: #7884
    pr: #8508
    by: queue worker (repo-worker-code), lane code-e
    at: 2026-11-11T03:57Z

    Implemented and opened PR #8508 (branch queue/14237-7884-init-doc-validation, head 6659188): the INIT handler in pkgs/id/web/src/collab.ts now validates the doc with Node.fromJSON(getSchema(mode), doc) at the frame boundary and drops an unparseable doc with a log instead of letting initEditor silently substitute an empty editor. Regression test covers unknown node type, unknown mark type, non-string text, and numeric content entry, plus a valid rich control.

    Verified on the laptop: collab.test.ts + editor.test.ts 147/147 pass (after rebase onto main 786ee93); full pkgs/id web suite 712 passed with one failure — the search-panel accessibility test, verified identical on the clean tree (pre-existing, unrelated); tsc --noEmit green. Note: the shared validInit test helper now uses a code_block doc for raw mode, because a paragraph doc in raw mode only ever passed via the silent empty-doc fallback this fix removes.

    Resume: PR #8508 checks green + Codex findings dispositioned -> merge -> close-out. Currently 12 checks QUEUED in the runner backlog, no Codex review yet. Parked as a CI wait.

  7. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 11, 2026
  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: parked
    worker: repo-worker-code
    lane: any-b
    task: 14237
    note: Resumed and re-verified PR #8508 (head 6659188): Codex review completed on the current head with no findings, no inline review comments. Blocked only on CI: 11 basic checks QUEUED in the fleet-wide backlog, 0 failed. Parked as CI wait. Resume: checks green -> merge -> complete fixed_merged.

  9. added a commit that references this issue on Nov 11, 2026
  10. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — PR merged after conflict resolution with the sibling INIT fix

  11. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions