Repository navigation
Description
id(web/main): /api/save, /api/new, /api/rename and /api/copy responses shape-trusted — a wrong-shape 200 reports save success with dataset.hash 'undefined' or navigates to /edit/undefined
Summary
The four file-operation handlers in pkgs/id/web/src/main.ts cast their
fetch JSON responses with bare as casts and use the fields without any
runtime shape validation. A 200 response whose body is the wrong shape
(proxy error page parsed as JSON, a partial deploy, a server-side change)
is therefore treated as success, with the bad values flowing into
persistent UI state and navigation:
main.ts:1135—POST /api/save:
const result = (await response.json()) as { hash: string; name: string; archive_name: string | null },
theneditorContainer.dataset.hash = result.hash(:1139) and the
handler returns{ ok: true }.main.ts:1172—POST /api/new:
as { hash: string; name: string }, then navigates to
/edit/${encodeURIComponent(result.name)}(:1179).main.ts:1285—POST /api/rename:
as { name: string; hash: string; archived_original: string | null; archived_replaced: string | null },
sets the button torenamed!, then navigates to/edit/<result.name>(:1298).main.ts:1353—POST /api/copy:
as { name: string; hash: string }, sets the button tocopied!, then
navigates to/edit/<result.name>(:1364).
The WebSocket frames and other responses in this codebase are guarded
(e.g. the world page's isWorldSnapshot/isWorldEvent guards), and the
sibling home/image/world HTTP responses were fixed the same way this one
should be — these four casts are the remaining unguarded door in the
editor shell. This verifies the unverified lead recorded by creator lane A
on 2026-11-08 (22:33Z backlog entry).
Verified behavior (this run)
Probe: real main.ts from origin/main 1f5ac11276, driven under
vitest/happy-dom using the program-surface harness pattern from
world-program-main.test.ts (real init(), real ProseMirror collab
editor state for save, stub fetch keyed by URL, fetch-call log as the
navigation observable). Probe: ~/git/fleet/probe-main-shape/ on the
laptop (probe.log + src/main-shape-probe.test.ts in the snapshot).
Controls pass for all four endpoints (valid body → dataset.hash
updated / navigation to the real /edit/<name> / success button text).
Wrong-shape 200 bodies:
| Endpoint | Body | Observed |
|---|---|---|
/api/save |
{} |
returns { ok: true } (fake success) and sets editorContainer.dataset.hash = "undefined" — the next save posts doc_id: "undefined" |
/api/save |
{ hash: 123, … } |
returns { ok: true }, dataset.hash = "123" (silent coercion) |
/api/save |
null |
raw TypeError: Cannot read properties of null (reading 'hash') at main.ts:1139, surfaced only as a generic save failure |
/api/new |
{} or "abc" |
navigates to /edit/undefined |
/api/new |
null |
raw TypeError at main.ts:1179 in the console; the UI silently does nothing |
/api/rename |
{} |
button shows renamed! (fake success) and navigates to /edit/undefined |
/api/rename |
null |
raw TypeError at main.ts:1298; button shows generic error! |
/api/copy |
{} |
button shows copied! (fake success) and navigates to /edit/undefined |
/api/copy |
null |
raw TypeError at main.ts:1364; button shows generic error! |
Why it matters
Save is the editor's core write path: a single wrong-shape 200 both lies
to the user (the file appears saved) and corrupts the in-page state —
dataset.hash becomes the literal string "undefined", so every
subsequent save in that session targets a nonexistent document. Create /
rename / copy navigate the user to /edit/undefined, a document that
does not exist, after announcing success (renamed! / copied!).
Acceptance criteria
- Each of the four responses is validated at runtime before any field is
used: a non-null object whosename(andhashfor save) are
non-empty strings; archive fields on rename arestring | null. - On a wrong-shape 200, no state is mutated:
dataset.hashunchanged,
no navigation, no success button text; the failure is reported through
the same channel as a non-OK response (save returns{ ok: false },
rename/copy showerror!, create logs/shows a create failure). - Regression tests in the web suite (vitest) drive the real handlers (or
an extracted response-validation helper used by them) with at least
{},null, a string body, and a numeric-hashbody per endpoint,
plus the valid-body controls; the wrong-shape cases fail pre-fix. bun run testandbun run typecheckinpkgs/id/webpass (or any
pre-existing failures are shown to be identical on clean main).
Related: #7831 / #7833 (world host-view/invite, same class), #7823
(image-upload), #7812 (image-browser), #7811 (home feed) — different
modules/endpoints, independent fixes.
Activity
developing-today commentedon Nov 8, 2026
CODE-2331
developing-today commentedon Nov 8, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 11, 2026
agent-note:v1
lane: code-j
task: 14016
issue: #7837
state: triaged
note: Inline triage by lane code-j (runbook section 1c): work kind task/small-fix, priority/normal, effort/s, kind/bug - all already labelled and confirmed against the issue body (four shape-trusted fetch casts in pkgs/id/web/src/main.ts: /api/save, /api/new, /api/rename, /api/copy). Removed status/needs-triage; claim labels synced. First concrete step: add runtime response-shape guards at the four handlers following the codebase guard pattern, with vitest regression tests ({} / null / string / numeric-hash per endpoint plus valid controls). Acceptance check: wrong-shape 200 mutates no state and reports failure through the same channel as a non-OK response; bun run test and bun run typecheck in pkgs/id/web pass. Continuing to the fix in this same session.
7 remaining items
dezren39 commentedon Nov 11, 2026
agent-note:v1
lane: code-j
task: 14016
issue: #7837
stage: parked-handoff
note: Fresh revalidation: PR #8501 remains open at head 3349b41; 3 of 14 checks passed and 11 remain pending, including basic PR checks; none reported failing. Merge and final acceptance remain unverified. Copilot has not reviewed this head; the earlier handoff also calls for a clean Codex review. On resumption, verify the actual PR-tier checks and coverage against CI policy, review findings and acceptance evidence, and merge only after the checks and review are verified. Preserve parked handoff; no queue state changed.
dezren39 commentedon Nov 11, 2026
agent-note:v1
state: parked
worker: repo-worker-code
lane: any-b
task: 14016
note: Resumed and re-verified PR #8501 (head 3349b41): Codex review completed with no findings, CodeRabbit SUCCESS, no inline review comments; implementation tests were verified by the previous claim (file-op-responses 11/11, typecheck clean). Still 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.
dezren39 commentedon Nov 11, 2026
🤖 Agent note · picked up (resume)
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done