Skip to content

id(web/image-browser): /api/images response shape-trusted — a wrong-shape 200 shows raw TypeErrors or bogus 'undefined' cards that insert src-less images #7812

Closed

Description

@dezren39

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[]; in fetchImages() is a bare cast; the result is consumed unvalidated by the .then handler in openImageBrowser.
  • :146 — the handler wipes the grid first (grid.textContent = "", clearing the "Loading…" state), then reads images.length (:148) and iterates (:156), dereferencing img.hash / img.url / img.name per element with no shape check.
  • :212 — the .catch surfaces 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/hash all undefined, the Insert button enables on selection, and insertImage (:216-224) creates an image node with src: 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, name cat.png, hash abc123 — OK
  • null body: grid shows Failed to load images: TypeError: null is not an object (evaluating 'images.length'), 0 cards
  • {} body: grid shows Failed to load images: TypeError: {} is not iterable, 0 cards
  • [null]: grid shows Failed to load images: TypeError: null is not an object (evaluating 'img.hash'), 0 cards
  • [valid, null]: throws on the second element; the catch's grid.textContent = assignment wipes even the already-appended valid card — 0 cards, raw TypeError
  • "abc" body: NO error — 3 bogus cards render, every name undefined; selecting one enables Insert, and clicking Insert creates an image node with attrs {} (src/alt undefined)

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/images payload (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.ts cover the malformed cases above and fail pre-fix.
  • Web suite + typecheck green.

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
    on Nov 8, 2026
  2. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  3. added
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 8, 2026
  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (new-issue-creator-code-a)
    • Session / ID: cron job new-issue-creator-code-a, run 2026-11-08T21:22Z
    • Found via: filed this run
    • Task: Validate the /api/images response shape at the fetch boundary in pkgs/id/web/src/image-browser.ts before rendering — malformed payloads show a clean failure message, render no cards, and never enable Insert; add regression tests.
    • Expectation: effort/s — done when a wrong-shape 200 can no longer dump raw TypeErrors or bogus "undefined" cards into the dialog, and the web suite + typecheck are green.
    • Links: probe ~/git/fleet/probe-image-browser/probe.ts (laptop, origin/main fd2b0c8)
  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 8, 2026
  6. 4 remaining items

  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 8, 2026
  8. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    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.

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

    @dezren39
    MemberAuthor

    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.

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/lowNice to have; do when convenientsource/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