Skip to content

Read every pair's record in the browser, and work out what isn't held (diffs step 4) - #119

Merged
nedtwigg merged 3 commits into
mainfrom
records-in-browser
Nov 30, 2026
Merged

nedtwigg merged 3 commits into
mainfrom
records-in-browser

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

Step 4 of docs/plans/diffs.md: the differ in a browser, and one source of a pair's record for every page.

What changes

  • One read path, records.recordOf(pair) in ui/src/client/records.ts. It checks what the tab already holds, then POST /api/derived/read, then the differ in the Web Worker. Every ask made in the same turn of the event loop goes out as one read, chunked by MAX_DERIVED_PAIRS. Anything readRecord can't make sense of is worked out again. A server that answers the read with 404, as the Worker in production does today, counts as holding nothing: fetchDerived returns [].
  • The Web Worker makes records. differ.worker.ts takes { kind: "record" } beside { kind: "highlight" }. It decodes and hash-checks both images, then runs diffImages and the shared recordOf. The highlight path is unchanged, except that it no longer returns the diff nothing read. When an image doesn't come, the failure crosses back as a RequestError (new worker-safe request-error.ts), so step 0's retries and "couldn't look at N stories" count still apply.
  • Everything that needs a PixelDiff or keys reads the record:
    • the batch list's pixel stats and its moved-and-spacing-only filter, so the cloud list has both now
    • a story's stats and hunks
    • deltas
    • RenderRow.pixelDiff and BatchViewPlatform.pixelDiffs are gone, and the UI no longer reads review.json. Its writer stays for step 6.
  • Deltas take hunk keys from the records, so exact grouping decodes no image. Only stragglers are decoded, on the page's thread as before, which took 0.6–0.9 s on the synthetic batch. repeatedSizes is gone.
  • Write-back: a local page PUTs what it worked out to /api/derived/:current/:golden/:tag. Through ReviewSource.keepDerived, selfie ui keeps it in Project.diffs. The route has the same Host/Origin/header/content-type checks as every other local write, a 64 KiB limit (derived-too-large), and shares boundedBody with sync. The cloud refuses it with read-only, for everyone.
  • Stories: generate-storybook-fixtures.ts now writes RECORDS (Node's records), and the preview holds them before every story. PartlyAccepted has the browser's differ make a record and checks it equals the one Node made, keys included.

Measured (Chromium, local, synthetic batch of 140 changed 1280×1800 stories)

Records held None held Before (main)
Diff/record requests 1 read 1 read + 140 written back 140 diffs
Deltas found 0.85–1.05 s 5.5–7.1 s 3.8–6.0 s
  • A cold record costs about 35–43 ms per pair in the single Web Worker. Locally that happens once: every record the browser wrote back was byte-identical to the one selfie review keeps.
  • A story page shows its stats at 0.2–0.3 s and its highlight by 0.3 s, whether or not the record was held, so the mask isn't cached.
  • Details are in docs/specs/ui.rationale.md.
  • selfie pull can't bring back Replace favicon and UI mark with matched tilted-phone SVGs #108's batch, since it pulls only decisions and a base, so the batch was built synthetically.

Specs

  • ui.md: Package, ReviewSource, Routes, the new "A pair's record" rules, Repeated changes (where keys come from), and Stories.
  • system.md → Diffs and grouping: what the browser reads and computes. Stale lines are dropped, and the merge keeps selfie diff paints on demand, and selfie review stops painting (step 6, CLI) #118's selfie diff row.
  • access.md and its rationale: the write route, and Future for cloud write-back.
  • cloud.md, cli.md (local layout).

Snapshots

Stories hold the same PixelDiffs as before through the fixture records, so no story should render differently. If the selfie check reports a change, I'll explain it here.

🤖 Generated with Claude Code

nedtwigg and others added 3 commits November 30, 2026 03:58
One client source of a pair's record, `records.recordOf`: what the tab holds,
then `POST /api/derived/read` for every pair asked for at once, then the
differ in the Web Worker, which now makes records as well as highlights.
A batch list's pixel stats and moved-and-spacing filter, a story's stats and
hunks, and delta keys all read it, so `RenderRow.pixelDiff` and the UI's
reading of review.json go, and the cloud list gets stats. A local page writes
back what it works out through a new `PUT /api/derived/...`, which the cloud
refuses with read-only. A server without the read route answers 404, which
counts as holding nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/specs/cli.md
#	docs/specs/system.md
…4 read in fetchDerived

From the simplify pass. A worker-safe `request-error.ts` holds `RequestError`,
which the differ's Web Worker throws and posts as it is. `fetchDerived` takes a
404 as nothing held, so the records cache has no special case. The PUT route
and sync share `boundedBody`. `Records` says what's `had` and what `failed`, and
`useRecord` reads the same store `useRowDiffs` does, told at most once a frame.
The delta scan asks for every record ahead, and a list works out what it shows
again as records arrive only when moved-and-spacing-only is what's shown. An
ahead record no longer keeps its pixels in the Web Worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nedtwigg
nedtwigg merged commit f23301c into main Nov 30, 2026
5 checks passed
@nedtwigg
nedtwigg deleted the records-in-browser branch November 30, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants