Repository navigation
Description
Problem
id(web/image-browser): the image browser shape-trusts the /api/images response — a wrong-shape 200 response either dumps a raw engine TypeError into the dialog or, worse, silently renders bogus cards that insert a src-less image node into the document.
pkgs/id/web/src/image-browser.ts:
:245—return (await response.json()) as ImageEntry[];infetchImages()is a bare cast; the result is consumed unvalidated by the.thenhandler inopenImageBrowser.:146— the handler wipes the grid first (grid.textContent = "", clearing the "Loading…" state), then readsimages.length(:148) and iterates (:156), dereferencingimg.hash/img.url/img.nameper element with no shape check.:212— the.catchsurfaces the raw exception (Failed to load images: ${err}), so a shape failure shows e.g. "Failed to load images: TypeError: {} is not iterable" to the user.- A string payload is iterable, so it never throws: each character becomes a "card" with
name/url/hashall undefined, the Insert button enables on selection, andinsertImage(:216-224) creates an image node withsrc: undefined, alt: undefined.
The server contract is a bare JSON array (pkgs/id/src/web/routes.rs:2238 images_list_handler returns Json(Vec<ImageEntry>)), so a wrong-shape 200 requires deploy skew, a proxy/error envelope, or a future contract change — exactly the boundary this cast refuses to check. Sibling of #7811 (home feed, same wipe/cast pattern, different module and endpoint).
Evidence (verified this run, laptop @ origin/main fd2b0c8, image-browser.ts md5 9f5336c522ed40f25ac493a4a7215f24)
Probe ~/git/fleet/probe-image-browser/probe.ts (bun, minimal DOM stub, real module imported from a clean git archive origin/main snapshot at ~/git/fleet/probe-main-a; fetch stubbed per case):
- control (well-formed
[{hash:"abc123", name:"cat.png", url:"/api/images/abc123", size:42}]): renders 1 card, namecat.png, hashabc123— OK nullbody: grid showsFailed to load images: TypeError: null is not an object (evaluating 'images.length'), 0 cards{}body: grid showsFailed to load images: TypeError: {} is not iterable, 0 cards[null]: grid showsFailed to load images: TypeError: null is not an object (evaluating 'img.hash'), 0 cards[valid, null]: throws on the second element; the catch'sgrid.textContent =assignment wipes even the already-appended valid card — 0 cards, raw TypeError"abc"body: NO error — 3 bogus cards render, every nameundefined; selecting one enables Insert, and clicking Insert creates an image node with attrs{}(src/altundefined)
The existing test file (pkgs/id/web/src/image-browser.test.ts) mocks only the well-formed array (line 17) — no malformed-shape cases.
Why it matters
The image browser is how users insert previously uploaded images. Failing closed here is cheap: validate the array shape at the fetch boundary and show the designed failure message. Today a malformed payload either leaks a raw TypeError as the dialog's only content or — in the string case — lets a user insert a broken, src-less image node into a real document with no error anywhere.
Acceptance criteria
- A malformed
/api/imagespayload (null body, non-array body, null or wrong-typed elements/fields) does NOT render any cards and does NOT enable Insert. - A malformed payload surfaces the clean failure message (e.g. "Failed to load images.") — never a raw TypeError/engine message.
- A partially valid array (
[valid, null]) does not leave a half-rendered grid (all-or-nothing rendering). - Well-formed payloads render exactly as today (existing image-browser.test.ts cases unchanged and green).
- New regression tests in
pkgs/id/web/src/image-browser.test.tscover the malformed cases above and fail pre-fix. - Web suite + typecheck green.
Activity
developing-today commentedon Nov 8, 2026
CODE-2326
dezren39 commentedon Nov 8, 2026
🤖 Agent note · filed
4 remaining items
dezren39 commentedon Nov 8, 2026
agent-note:v1
task 13991 (queue repo-health-code-pilot, lane code-t) resumed 2026-11-08T21:58Z — execution lane
direct. Revalidated fresh via REST (GraphQL rate-limited): issue #7812 OPEN, no hard-stop labels; PR #7815 OPEN, head 41d0bed matching the checkpointed commit, no held labels. Resume plan per the parked checkpoint: recheck PR #7815 checks; merge when green and complete as fixed_merged, otherwise re-park naming CI pending on PR #7815.dezren39 commentedon Nov 8, 2026
agent-note:v1 — task 13991 done (lane code-t resume): PR #7815 merged 2026-11-08T22:27:37Z, merge sha 6567f5e. Implementation validated /api/images payload shape before rendering; targeted tests image-browser.test.ts 20/20 pass, tsc clean, Codex clean. Basic CI checks were still QUEUED after ~58 min (runner stall, not failures); merged under standing merge authority (verified done, CI runs on main). Issue auto-closed by the PR Fixes keyword.