Skip to content

W6: per-recording quality panel and idle preload - #596

Merged
neuromechanist merged 34 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w6-panel
Nov 26, 2026
Merged

neuromechanist merged 34 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w6-panel

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase W6 of the live quality views (#588, epic #586, nemarOrg/nemar-cli#2324; nemar-cli ADR 0137 as amended, website ADR 0035): the per-recording panel with Spectrum, Components and Signal, and the idle preload at page load.

The route and its client

  • route-contract.ts is a hand copy of nemar-cli's shared/contract/quality-route.ts: paths, words with their statuses, bounds and the recording-path rule.
    • test/quality-route-contract-drift.test.ts imports nemar-cli's module. It compares every constant by value and the words in order, and compares the functions by their answers on traversal, schemes, controls, bidirectional code points and length limits.
    • It is strict through NEMAR_CLI_QUALITY_ROUTE. CI's sparse checkout gains quality-route.ts, compute-naming.ts and compute-stamp.ts.
  • record.ts reads a record answer in this order:
    1. The digest is checked before anything is parsed. The bytes are checked against the SHA-256 in the answer's ETag. From the data plane that digest is required: no ETag, or one that names no SHA-256, is record_digest_missing. The route exposes the header to the site's origins; that is the nemar-cli epic fix. Only a loopback data plane, which means a local backend in development, reads without it.
    2. The text is read as I-JSON.
    3. The envelope is checked, and that it is the dataset, recipe and recording asked for.
    4. The dataQuality record shape, closed as neuroschema's schema is.
    5. nemar.record-checks.v1.
    6. Each view's declaration is checked by the worker's guards when it is drawn.
  • quality-api.ts gives three states:
    • none: quality_not_found;
    • unavailable: a 404 with no word of the route's ("not available on this server yet");
    • failed: with a word.
  • quality-files.ts builds file URLs. Each file is read up to its declared size only. The model checks size and SHA-256 before it parses.
  • The panel recomputes each view's nemar.view-digest.v1 with W5's verify.ts. A view whose declaration does not match the route's digest is not drawn.

The panel (components/quality/QualityPanel.astro, island quality-views/panel.ts)

  • It is a Recording quality tab in DatasetTabs. The tab is shown only when the dataset's quality summary names a recipe, nemar-ica first.
  • The island loads when the tab first opens, or when a #quality/... link opens the page.
  • Picker: the signal viewer's recording list, published by the page (panel-bridge.ts), in the visitor's navigation order, limited to recordings a record can name.
  • Tabs:
    • Spectrum, Components, Signal, and Other. Other appears only when the record has a view of another kind (today icactivity, until W7), so no view is left out.
    • Tabs follow the WAI-ARIA pattern: arrows, Home and End.
    • DatasetTabs now binds only its own tab list.
  • Deep link: #quality/<recording path>/<view key>, each segment encoded. It is written with replaceState when the visitor picks a tab or a recording, and followed on load and on hashchange.
  • Turbo toggle: one for the panel. It switches every scalp map and its legend, and is remembered per viewer in local storage, guarded.
  • Drawing: through W4's buildModel and mountView on sharedSensorFieldClient. The geometry is prepared from onLayout, and quality-views.css is loaded with the component.
  • Presets beyond their bases, ported from neuroschema.views.presets:
    • nemar.spectrum: its recorded parameters are printed. Maps are drawn at the rows initial_maps_hz snaps to, and a click or Enter on the lines picks a row (qv-pick, new in lines.ts).
    • nemar.ic-maps: one text row per component, each cell its stored text with its column's name and unit.
    • nemar.ic-classes: each class's count and its "summed variance of components classed X", as stored.
    • nemar.signal-window: all nine checks, in order.
    • Each kind's extras are a lazy chunk (extras/), and the panel's sentences are lazy too (panel-words.ts).

Bad channels and bad segments in the viewer

  • ViewerOptions.qualityMarks gives the viewer the floor's marks.
  • The Signal tab opens the page's viewer through the session's mountOptions, using registerSignalOpener in [id].astro.
  • Once the store is open, and before anything is drawn, the viewer runs the view's checks against the store: its labels, sample count and rate.
    • The serving copy publishes no content digest yet (nemar-cli#2343), so the state is not_checked and the panel says so.
    • A refusal shows its sentence in place of the traces.
  • When the checks pass:
    • the viewer opens the view's group and window;
    • the floor's bad channels are dimmed through the existing mark;
    • its bad segments are shaded under the event lines (shadedRects and drawShaded in render.ts);
    • a line above the plot says what is marked.

Idle preload (owner ruling) (preload.ts, preloaded.ts)

  • When it runs:
    • only after the page's load event and the viewer's index;
    • only once shouldPreload() passes and requestIdleCallback fires (a 500 ms timer stands in where the browser has no idle callback);
    • and only if no viewer is open.
  • What it does:
    1. Reads the default recording's record at low priority. The panel then takes that record and does not ask again.
    2. Calls prepareAhead (preloadInput): warm the worker, fetch and check the layout, prepare its geometry, then fetch and check the files of the first windows only. Those are the Spectrum and Components tabs' views, whose maps are the first on-screen batch.
  • Bounds:
    • maxBytes is exactly those files' bytes.
    • It aborts on pagehide and calls forgetPreloads().
    • It shows nothing on failure.
  • Everything else loads on demand.

Fixtures and local backend

  • scripts/capture-quality-fixtures.mjs mounts nemar-cli's real dataRoutes over a migrated D1 and Miniflare's R2, with the backend's own quality-fixture.ts helpers and nemar-ica's real product. It writes the record, 8 files and 5 refusals to test/fixtures/quality-views/route/, at nemar-cli 39e2ee3f.
  • scripts/local-backend.mjs --seed-quality seeds the same derivative, so the real route answers at localhost:<port>/data/on007823/quality/v1/nemar-ica/.... I checked it by hand (200, public, max-age=300, ETag).

Gates

  • bun run typecheck: 0 errors. bun run lint: clean.
  • Targeted Vitest, every quality-views-* file, the route drift test (pointed at the epic checkout), eeg-viewer, local-backend-guard: pass.
  • bunx astro build, then check-quality-views-size.mjs --require-build: pass (numbers below).
  • bun run test:quality-views-perf on M4: pass (numbers below).
  • Playwright: e2e/quality-panel.spec.ts (7, new), e2e/quality-views-perf.spec.ts (2), e2e/viewer-scalp-map.spec.ts (3): all pass on M4.
  • Merged the epic base after W5 (W5: dataset quality summary and verification utilities #595, b8734e8), by merge. All gates above were rerun after the merge.
  • test/quality-panel.astro.test.ts (new) renders DatasetTabs through Astro's container. It checks that the Recording quality tab and panel exist only with a recipe and a version, that the panel carries the island's data attributes, and that its tabs follow TABS.
  • Full bun run test, with every NEMAR_CLI_* variable pointed at nemar-cli dev, after the merge: 8,432 passed, 7 skipped, 8 failed.
    • The 8 failures are expected: the 6 drift tests that W4 already listed (pipeline grid, vocabulary), and the 2 of the new route drift test, because nemar-cli dev does not carry quality-route.ts until epic #2324 reaches it.
    • CI run 45756644222: lint, typecheck, the drawing budget, the build and the size step pass. Vitest fails on these same 8 drift tests and nothing else.
  • Not run: scripts/local-backend.mjs without --seed-quality fails against the epic checkout at its observer-run step (compute_disabled). That step predates this PR and has the same fault without the flag.

Measured

Panel opened after page load (the new gate): the idle preload runs through its real code, the panel opens one idle period later, and the view is built from the preloaded files with no fetch. The gate requires cacheMisses = 0 and gates the draw at 50 / 100 / 300 ms. Median of 3 fresh first views, first maps / whole view:

Where 128 sensors 256 sensors
M4, Vitest (after merging W5) 3.3 / 21.3 ms 4.8 / 67.6 ms
CI runner (run 45756644222 on 2992ab2) 6.4 / 42.0 ms 12.5 / 136.3 ms
  • The model is built from the preloaded files in 2.5 ms at 128 sensors and 7.8 ms at 256 on M4.
  • This replaces W4's printed-only 256-sensor first-visit eager case. That case is still printed, and the 128-sensor eager gate is unchanged.

Size (gzip level 9, gzipped together):

What Size Budget
First screen, Spectrum tab (panel, lines, scalp maps, spectrum extras) 27.9 KB 30 KB
First screen, Components tab (panel, scalp maps, histogram, components extras) 27.9 KB 30 KB
Spectrum tab opened before the preload ran (a deep link at load), with the record reader 29.5 KB 30 KB
Components tab, the same 29.5 KB 30 KB
Idle preload on its own 24.9 KB 30 KB
Worker with its lazy chunk (W5's guard fix included; W6 adds nothing to the worker) 11.9 KB 12 KB
Site build, largest lazy root (sensor-field-view with its static set) 29.2 KB 30 KB

Mutations (each must fail the named tests)

The script lives outside the repository. Each mutation edits one guarded line, runs the named tests, and restores the file. All 41 were caught after the merge. A 42nd, letting a declaration with no canonical form through the digest comparison, is equivalent: the record's I-JSON reader refuses such a text first. The digest mutation now lives in W5's verify.ts tests, and the browser mutations ran against the real panel module in Playwright.

Mutation Result
record: parse before the digest is checked caught
record: the ETag digest is never read caught
record: an answer for another recording accepted caught
record: root not closed caught
record: plugin name grammar not applied caught
record: store profile pairing dropped caught
record: views_skipped not closed caught
record-checks: repeated view keys pass caught
record-checks: a metric's producer not compared caught
api: quality_not_found is an error caught
api: a 404 without a route word is a failure caught
files: a file read past its declared size caught
hash: a view key read as part of the path caught
hash: segments not encoded caught
picker: every recording listed caught
preload: every tab's files caught
preload: the cap is the registry's, not the scope's caught
preload: saveData ignored caught
preload: an open viewer not respected caught
preload: leaving forgets nothing caught
preload: the page's load not awaited caught
preload: the layout not prepared caught
spectrum: sensors_mismatch not checked caught
spectrum: maps snap by floor, not nearest caught
ic-maps: components_mismatch not checked caught
ic-maps: a row's cell is the parsed number, not its text caught
ic-classes: components_total not checked caught
signal: window by a rounded product caught
signal: another recipe's tables accepted caught
signal: a store row with no channels row passes caught
signal: an unknown bad channel passes caught
signal: a near-miss status read as good caught
signal: a store digest mismatch drawn caught
viewer: shaded spans not clipped caught
viewer: spans outside the window kept caught
route contract: any file name is a recording caught
panel (browser): a view's digest not compared caught
panel (browser): a file's digest mismatch drawn caught
panel (browser): a tab writes no link caught
panel (browser): Turbo not remembered caught
panel (browser): component rows without units caught

Deviations and judgment calls

  • The panel's first-screen unions leave out the idle preload's own chunk.
    • It is parsed and compiled in idle time before the panel opens, so it does not add to the panel's opening cost, and it is measured on its own.
    • The case where the panel opens before the preload (a deep link at load) is gated as well, with the record reader included: 29.5 KB.
    • I also left the measurement's synthetic entry chunk out of the tab unions. It is only the build's list of re-exports (0.8 KB), and no page loads it.
  • Name: QualityPanel.astro is at src/components/quality/, because src/components/QualityPanel.astro is the old Phase 3 panel.
  • One recipe. The panel reads one recipe: nemar-ica if the dataset summary lists it, else the first one listed. There is no recipe picker.
  • The Signal tab's store digest is always not_checked until the serving copy publishes per-store content digests (nemar-cli#2343).
  • Activations (icactivity) are drawn under Other by the renderer rule: the fallback, with their file inputs offered. W7 moves them to an Activations tab.
  • Placement by name is still labels_pending until W2b. The one spectrum vector placed by name (spectrum_maps_names) is compared on everything but placement.
  • No "Link to this view" anchor. The address bar's hash is the deep link. qualityPermalink is in panel-model.ts for W8.
  • W5 overlap (W5: dataset quality summary and verification utilities #595):
    • In DatasetTabs.astro, my changes are the new tab button, its panel and the tab-list binding selector. I named the prop recordingQuality, because W5's is quality.
    • After the merge, the panel uses W5's verify.ts (viewDigest, verifyBytes), and view-digest.ts is gone. The merge commit also carries a fix: the Recording quality tab is hidden when there is no version. That fix is pinned by the new Astro container test.
    • The dataQuality corpus cases are replayed in test/quality-views-record.test.ts.

What W7, W8 and W9 need

  • W7:
    • Draw nemar.ic-activity as an extras/activity.ts lazy chunk, with an Activations tab in panel-model.ts TABS. The tab's union is panel, lines and activations.
    • The worker-side transform must be a lazy chunk of the worker. The worker is at 11.8 of 12 KB with guards-computed.
    • The base leaves about 2 KB under 30 KB for a tab's own chunk.
    • Shading the floor's bad segments can reuse shadedRects.
  • W8:
    • Export from SensorFieldHandle.drawnMaps().
    • The view digest is record.digests[key], already compared with viewDigest.
    • The permalink is qualityPermalink(origin, id, version, {recording, key}).
    • The verified bytes come through preloadedSource(recordFiles(...)).
  • W9: route-contract.ts holds only the public mount. Copy the admin mount and its proxy obligations from quality-route.ts, and widen the drift test to them.

Review fixes (round 1)

Important

  • The ETag is required from the data plane (readRecordAnswer(..., requireDigest) and lenientBase in quality-api.ts). The test that read without an ETag is now the opposite test: a missing, empty or unreadable ETag is record_digest_missing, and a fetched answer without one fails.
    • The capture now sends an Origin and records Access-Control-Expose-Headers. A test checks that it lists ETag once nemar-cli serves it.
    • Re-capture is needed when the nemar-cli epic fix lands. The epic head I captured from, 39e2ee3f, does not have it yet.
  • The Signal tab checks the declaration first (checks.view), and shows declaration_invalid. The e2e case uses a non-number start_s.
  • A held record is taken only when it is ok or none (recordFor in panel-bridge.ts). Otherwise it is forgotten and fetched again. Tests cover a failed preload, an aborted preload, none and ok, and a failed preload followed by a successful open.
  • A switch of recording stops the old work.
    • Each tab's draw keeps the signal it started under. That same signal goes to the file source, the mount and the extras, and it is checked after every await.
    • The e2e switch test leaves a recording while its files are still arriving. It holds that no draw and no geometry prepare happen after the switch.

Moderate

  • 5. The preload is skipped once the panel has opened (panelOpened, [data-qp-opening]).
  • 6. A signal store of another recording is refused (signal_recording_mismatch, e2e).
  • 7. No raw word is ever shown.
    • http_* statuses are worded by class, with one sentence for 5xx and one for 4xx.
    • The route's file words, recording_path_invalid and failed have sentences.
    • Every reason a view was skipped has a sentence, and any unknown word gets a generic sentence.
  • 8. "Loading…" is never left stuck. A non-abort error shows the failure sentence, a view that throws shows it in place, and the refusal-body read in quality-api.ts now has its catch.
  • 9. The floor's bad channels are a set of their own (floorBad). They are dimmed through isDimmed, never added to badChannels, and never reach getSelectedChannels. A unit test and a source check cover this.
  • 10. A hidden active tab falls back to DEFAULT_TAB.
  • 11. The qv-pick click computes its row from the click's own coordinates.
  • 12. One handle per target. A redraw into a target destroys that target's previous handle, and Turbo skips handles that are no longer on the page.
  • 13. pendingMarks is cleared once openRecording settles (finally).
  • 14. The preload plans only from checked views and files.
    • Only views whose viewDigest matches are planned (digestedViews).
    • Only files with a 64-hex sha256 and an integer size up to QUALITY_FILE_MAX_BYTES are planned.
    • readLimited refuses a NaN limit.
  • 15. "Panel opened after page load" is now measured from mount to ready. The span covers the held record (no request), the view's digest, the model, the figure's tree and the maps' draw. The budgets are unchanged at 50 / 100 / 300 ms.
    • Vitest has no DOM, so creating the DOM nodes is not inside the timed span.
    • The browser spec mounts the real panel.
  • 16. The real site-build unions are gated (siteUnions). The panel's chunk is found by a sentence only it holds. These are left out, with the reason: the idle preload's chunk, the island script and Vite's preload helper. All three load with the page before the panel opens.
  • 17. --seed-quality needs --seed-pipeline. This is documented, and the script refuses the flag without it.

Owner ruling for W7: the worker, together with the lazy chunks one tab loads, may use up to 16 KB. ADR 0035 is amended, and BUDGET.worker is 16 KB. The main-thread budget stays at 30 KB.

After the fixes (head 59e44b1, CI run 45760304741). Lint, typecheck, the budget, the build and the size step pass. Vitest fails on the same 8 drift tests only.

Mount to ready, first maps / whole view, median of 3:

Sensors Runner M4
128 19.4 / 52.1 ms 12.1 / 30.1 ms
256 32.3 / 159.7 ms 22.9 / 86.1 ms

Sizes:

What Size
Site build, Spectrum tab 27.7 KB
Site build, Components tab 27.4 KB
Site build, either tab with no idle preload 29.0 / 29.1 KB
Entry build, Spectrum tab 28.3 KB
Entry build, Components tab 28.3 KB
Entry build, either tab with no idle preload 30.0 / 30.0 KB
Idle preload 25.4 KB
Worker with its lazy chunk 11.9 of 16 KB

Mutations of the new checks:

Mutation Result
a missing ETag digest read anyway caught
every base lenient caught
the signal declaration not checked caught (e2e)
a store of another recording accepted caught (e2e)
a failed preload taken as final caught
the layout prepared for a recording left caught (e2e)
both of a view's abort checks removed caught (e2e)
the preload runs after the panel opened caught
a view whose digest differs planned caught
unfetchable files planned caught
a NaN limit read caught
an HTTP status shown raw caught
the floor's marks join the visitor's caught
a draw takes the newest signal at its call equivalent
the mount takes the newest signal layered
the mount's signal ignored layered
no check after the model is built layered
  • The draw reads the signal synchronously, so taking the newest signal at the call is the same signal: that mutation is equivalent.
  • Each of the three marked "layered" is covered by a second check, mountView's own or the view's: removed one at a time, the other still stops the work. Removing both does fail the e2e switch test.
  • No test catches mutations of fixes 10 to 13 (the tab fallback, the click row, the single handle per target and the cleared marks). In the browser, a click moves the pointer first, so the click's row equals the last pointer row. The handle and the marks are page-level lifetimes.

Review fixes (round 2)

Deploy order: the website epic must not reach dev before the nemar-cli epic. The ETag the panel now requires is exposed by nemarOrg/nemar-cli#2400 (311c71fa), which deploys with the nemar-cli epic. Without it, every record on the dataset page is record_digest_missing.

  1. The real site build is the gate.
    • Gated: each panel tab's first-screen union and every lazy root at 30 KB on the main thread, and the worker with its lazy chunks at 16 KB.
    • The entry-build unions are printed as info and are not gated, because their headroom is too thin to survive W7's first commit.
    • The script, the CI comment and ADR 0035 say so.
  2. Fixtures re-captured at nemar-cli 311c71fa. Every answer now carries Access-Control-Expose-Headers: ETag, and the test that checks this is strict.
  3. Leniency is for loopback hosts only (lenientBase). This site's own origin is no longer lenient, and the test now asserts that.
  4. "Hide bad" also hides the floor's marks.
    • The montage and its readout share one rule, hidden(), through isDimmed.
    • The floor's marks stay out of the visitor's annotation set.
    • Pinned by e2e/viewer-quality-marks.spec.ts, which runs on a public recording: the readout says "1 hidden", and the annotation layer offers no "Annotate … marked channels".
  5. ADR 0035 corrections.
    • Decision 1's 12 KB is marked "(amended, see addendum)".
    • The addendum's sentence on the check before a view is drawn no longer says "when the browser can read it".
    • The digest rule cites nemar-cli#2400 at 311c71fa, names the deploy order and is limited to loopback.
  6. Real e2e tests for fixes 10–13. Each matching mutation is caught.
    • 10: Other is active, then the visitor switches to a recording with no Other views. Spectrum is selected and shown.
    • 11: in a hasTouch context, a tap with no prior pointer move picks the row under it. The test reads the maps' caption at the stored frequency.
    • 12: three rows picked, then Turbo. Exactly one live map handle remains (PanelHandle.liveMaps()).
    • 13: the first open's store requests are aborted, then "View data" reopens the same recording. No [data-eegv-marks] appears.
      • For this to be testable, the session's mountOptions now only reads the pending marks, and the opener clears them in finally once openRecording settles, whatever its outcome.

Round 2 mutations

Mutation Result
lenient for a same-origin (any https) base caught
Hide bad ignores the floor's marks caught (e2e, viewer)
the floor's marks join the visitor's (annotation) caught (e2e, viewer)
a hidden active tab kept caught (e2e)
a click picks the last pointer row, not the tapped one caught (e2e, touch)
the previous handle of a target not destroyed caught (e2e)
marks outlive their open caught (e2e, viewer)

The three abort survivors, redundant by design.

  • Each of these checks has a second check guarding the same work: mountView's own signal check, or the view's check after the model is built.
  • When both are removed, the e2e switch test fails (caught, round 1).
  • The three survivors:
    1. "no check after the model is built" (drawView), covered by mountView's signal;
    2. "the mount's signal ignored" (mountView called without its signal), covered by the check after the model is built;
    3. "the mount takes the newest signal" (controller.signal passed to mountInto), covered by the same check.
  • "A draw takes the newest signal at its call" is equivalent, not merely redundant: the signal is read synchronously, so it is the same one.

After round 2 (head d8db332, CI run 45762844545). Lint, typecheck, the budget, the build and the size step pass. Vitest fails on the same 8 drift tests only.

Site-build sizes (the gate):

What Size
Spectrum tab 27.7 KB
Components tab 27.4 KB
Either tab with no idle preload 29.0 / 29.2 KB
Worker with its lazy chunks 11.9 of 16 KB

Mount to ready on the runner, first maps / whole view:

Sensors Result
128 20.3 / 53.9 ms
256 44.7 / 165.9 ms

The 256-sensor first maps were 32.3 ms in the run before. This run's 44.7 ms is close to the 50 ms budget.

Note on e2e/quality-views-perf.spec.ts (W4's spec). Run together with the other specs under Playwright's fullyParallel, it sometimes misses its 128-sensor median through CPU contention. Run alone, it passed twice in a row. It is unchanged.

Refs #588, nemarOrg/nemar-cli#2324

Agentic AI tools were used.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: d8db332
Status: ✅  Deploy successful!
Preview URL: https://2e59ffe6.nemar-website.pages.dev
Branch Preview URL: https://feature-issue-588-w6-panel.nemar-website.pages.dev

View logs

@neuromechanist
neuromechanist merged commit 683c0bc into feature/issue-586-epic-pipeline-progress Nov 26, 2026
3 of 4 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-588-w6-panel branch November 26, 2026 05:41
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.

1 participant