Repository navigation
Description
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):
- Control: valid rich doc
{type:"doc", content:[{type:"paragraph", content:[{type:"text", text:"hello rich"}]}]}→ editor text ishello rich. - One unknown node type discards everything: content = a valid paragraph (
good paragraph) plus{type:"future_node_from_newer_server", …}→ editor ready with text"", docdoc(paragraph)(empty). The valid paragraph is lost too. - Non-string text: a text node with
text: 12345→ editor ready, text"". - Numeric content entry:
content: [42]→ editor ready, text"". - 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.fromJSONcannot parse is rejected at the frame boundary (log + drop, session/socket intact, no editor initialized from it), mirroring the malformed-INIT drop path — ORinitEditor'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
contentfield. - 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
- Code:
pkgs/id/web/src/collab.ts:305-314(INIT doc validation stops attype/Array.isArray(content)),pkgs/id/web/src/editor.ts:659-666(Node.fromJSONcatch → empty doc) at origin/main69aa168d5da3aa0265f95ffdedeeed2fb4da1ce3. - Probe:
~/git/fleet/probe-creator-a-20261108/pkgs/id/web/src/probe-initdoc.test.ts(laptop, @69aa168d5d): all four malformed cases → editor ready withtextContent === ""; control rendershello rich; collab.test.ts + editor.test.ts 146/146 as control. - Dedup: id(web): collab handleMessage trusts MessagePack frame shape — a null frame throws out of onmessage, and a field-less INIT silently initializes an empty editor at an undefined version #2824 (closed) covered INIT version + doc object/type; id(web/collab): INIT frame mode shape-trusted — a non-string or unknown mode is adopted verbatim, and a falsy mode silently opens a rich doc in the raw schema as an empty editor #7859 covers the INIT mode field; id(web/collab): AUTH_OK and NEW_VERSION frame fields shape-trusted — a non-string refreshed token is persisted as the session identity, a non-string hash becomes '[object Object]' #7854 covers AUTH_OK/NEW_VERSION; id(web/collab): UPDATE and CURSOR frame fields shape-trusted — a malformed UPDATE tears the session down (close 4001 + reconnect) instead of being dropped, and a malformed CURSOR is stored verbatim as a phantom cursor #7873 covers UPDATE/CURSOR. Doc content entries are unfiled.
Activity
developing-today commentedon Nov 9, 2026
CODE-2339
dezren39 commentedon Nov 9, 2026
🤖 Agent note · filed
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.1 remaining item
dezren39 commentedon Nov 11, 2026
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.
dezren39 commentedon Nov 11, 2026
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.
Merge pull request #8508 from developing-today/queue/14237-7884-init-…
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — PR merged after conflict resolution with the sibling INIT fix