Repository navigation
W4: generic renderers, fallback, cold first view - #594
Merged
neuromechanist merged 36 commits intoNov 26, 2026
Merged
neuromechanist merged 36 commits into
neuromechanist merged 36 commits into
Conversation
TSV and I-JSON readers with the generic kinds' words, and hand-written guards for the view envelope, every registered kind, both transforms and the two contents, replaying neuroschema's verdict corpus (236 cases). Tested: vitest guards file.
Port of build_model: the renderer rule with the role contract, the table, lines, heatmap, histogram and sensor-field models, the fallback, digest checks before parsing, readout snapping and bin location. Held to kinds-models.v1 (269 cases, 18 refusals); 21 cases placed by name await W2b. Tested: vitest models file.
kinds.ts holds the registry, drawAs and the role contract (C2); model.ts builds models. No behavior change; models test passes.
Element-tree renderers for table, lines, heatmap, histogram (one SVG tree for server and page), scalp maps on the worker and the fallback, each a figure with caption, text alternative, readout from stored text, data table and downloads; color maps notice linked. The viewer's map-frame helpers move to render/map-frame.ts. Tested: vitest quality-views files and scalp-map.
A prepare request builds a layout's geometry ahead of its maps; SensorFieldClient.warm prepares and draws a full-size throwaway set while the values download, and a real draw cancels a warm-up still running. sharedSensorFieldClient gives a page one worker. Tests for late failure and messageerror events from a dropped worker (website#592). Tested: vitest worker file.
The live scalp map draws through sharedSensorFieldClient, prepares the geometry when its placement resolves with the panel open, and cancels its own draws on close instead of ending the shared worker. Tested: vitest eeg-viewer.
The perf step gates the first view on freshly imported code at 50/100 ms (128) and 300 ms (256), warmed while the values download, and checks the geometry was cached; the browser spec warms and gates its first view too. Tested: test:quality-views-perf and the e2e spec on M4.
The entry build measures the model and renderers with the client. The model takes map outcomes as an option and loads the layout projection on demand, so the interpolation stays in the worker: 27.7 KB of 30. Tested: astro build plus size check, vitest models and render.
markerReadout is what a pointer or key on a map's marker shows; the render test holds it to each plotted sensor's stored text on a worker-drawn map. Tested: vitest render file.
AGENTS.md lists read, guards, kinds, model, tree and render, the stylesheet and the shared, warmed client; the CI perf step's comment names the cold first view. Docs only.
Biome formatting only. Tested: bun run lint.
Deploying nemar-website with
|
| Latest commit: |
9a47bd6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://98b10d31.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-issue-588-w4-rendere.nemar-website.pages.dev |
astro check lost the sensor-field narrowing inside a closure in the render test. Tested: bun run typecheck, vitest render file.
3 tasks
The guards and the renderer rule run in the map worker (check and check-content requests; on this thread only when the worker cannot answer). Builders are keyed by kind@version. buildModel fetches a scalp map's layout beside its values and hands warmInput's rows to onLayout for prepare. warm() takes no layout (a synthetic 64-sensor one) and draws 16 maps in batches of 8. Tested: vitest checks, models, worker.
The four-map, two-cell loop over the evaluation matrix is its own function, so the engine optimizes it within a page's first view: a cold 128-map view's maps take about 21 ms on M4 instead of 36 to 43. Parity unchanged. Tested: vitest sensor-field parity, worker, models.
render/index.ts loads each renderer on demand per model type; data tables are built on first open; heatmap legend from stored texts; histogram mark text and unit in readouts; turbo legend; per-map range note; roving tabindex over scalp maps; readout spoken only on change; overflow-safe plot spans; download links only by http(s), blob or site paths; a failed renderer says so and lists the files. Tested: vitest render.
The perf step gates cold (warmed on mount, geometry prepared from the layout) and eager (cached data at mount) first views at 50/100 ms (128) and 300 ms (256), and prints a draw arriving mid-warm-up; the browser spec times all three. Tested: test:quality-views-perf and the e2e spec on M4.
Each lazy renderer chunk is measured with the entry's static set against the main-thread budget, and W7/W8 modules (transforms/, activations.ts, export/) fail the check if they load with the entry. Tested: astro build plus the size check.
AGENTS.md and the CI perf comment follow the review's changes. Docs only.
Without onLayout too. Tested: vitest checks file.
Each entry still gets the same one operation in the same order, so the factors are bit-identical (tested against the row-by-row elimination); the 256-sensor LU drops from about 5.2 to 3.3 ms on M4. Tested: vitest linalg, sensor-field parity.
The worker reads a geometry from IndexedDB before computing it (key: layout SHA-256, algorithm version, SHA-256 of the exact places and usable rows), checks it, and stores new ones after the draw answers; 16 layouts LRU; blocked storage only means computing. Stored geometries draw the computed maps bit for bit. Tested: vitest geometry-store, worker.
The perf step gates the eager view of a repeat visit (geometry read back from the earlier visit's storage) beside the first-visit eager, cold and median gates; the browser spec checks real IndexedDB reads and bit-identical maps. Tested: test:quality-views-perf, e2e spec on M4.
Docs only.
The schemas of nemar.ic-activity, nemar.signal-window and nemar.ic-activity.v1 move to guards-computed.ts. The worker answers unchecked for those views and the page checks them in local-checks.ts, a lazy chunk, so the map worker with its geometry store stays within 12 KB (11.7). The size check measures the lazy check chunks too. Tested: vitest quality-views, astro build plus size check.
And AGENTS.md names guards-computed and local-checks. Tested: vitest guards.
The elimination below each pivot is its own function, four rows per pass over the pivot row; each entry still gets the same operation in the same order, so the factors are bit-identical (tested). A cold 256-sensor LU drops from about 6.2 to 4.0 ms on M4. Tested: vitest linalg, sensor-field parity.
The interpolation and evaluation matrices fill their rows with one function (g(0) = 0 is the diagonal's 0), so the engine has optimized it on G's rows before E's many, and a synthetic warm-up's geometry warms it too. Parity unchanged. Tested: vitest sensor-field parity, worker, geometry store.
Cold, eager and repeat-visit first views are each run three times on freshly imported code and gated by their median at the same 50/100/300 ms; each run prints the draw's geometry and map times. Printed probes measure exact r2 reuse and a second thread for half the evaluation matrix. Tested: test:quality-views-perf on M4.
The interpolation matrix's factors equal those of G built entry by entry with a zero diagonal, on every drawn vector case. Tested: vitest geometry store.
prepareAhead warms the shared worker, fetches and checks a scalp map's layout and prepares its geometry, and fetches and checks the first windows' view files for preloadedSource; byte cap, AbortSignal, low-priority fetches, shouldPreload for data-saving and 2G links; idempotent, never throws. Measured in the size check. Tested: vitest checks.
By the owner's ruling the dataset page prepares the geometry at page load; W6 gates that case as panel opened after page load. Every other gate is unchanged. Tested: test:quality-views-perf on M4.
Computing now beats reading real IndexedDB, and the store had a silent-corruption path, a hang and up to ~120 MB of disk; the in-memory per-worker cache stays, and so do the faster LU and shared row function (G's bit test kept). The worker checks computed presets itself, loading guards-computed.ts as its own lazy chunk (ES module workers in astro.config and the size build), so it never answers unchecked. Repeat-visit gates go; first-visit eager at 256 stays printed. Tested: vitest quality-views, perf on M4.
The Spectrum (entry, lines, scalp maps) and Components (entry, scalp maps, histogram) first screens are gated at 30 KB gzipped together, and the worker with its lazy computed-schema chunk at 12 KB; the page's own checks, loaded only without a worker, are printed. The renderer rule's kinds table is written out (held to the registry by a test) so the worker carries no registry. Tested: astro build plus size check, vitest kinds and checks.
mountView takes a per-container token and an optional AbortSignal, so a slower, older render never replaces a newer one; lines, heatmaps and histograms carry an aria-roledescription and a keys hint as scalp maps do. Tested: vitest render (fast remount, abort, hints).
A panel opened during a preload fetches at once and the first verified bytes win; prepareAhead defaults its cap to the registry's bytes per role and its fetch stops reading past the declared size; Reader.prefetch leaves no unhandled rejection; warmInput reads places with the model's cell reader. Tested: vitest checks (hung preload, losing preload, cap, readLimited, unhandled rejection, cells).
Biome formatting only.
neuromechanist
merged commit Nov 26, 2026
25d9aef
into
feature/issue-586-epic-pipeline-progress
3 of 4 checks passed
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase W4 of the live quality views (#588, epic #586, nemarOrg/nemar-cli#2324): the generic renderers and the fallback, and the fix for the cold first view from #592.
Reading and checking a view
read.tsreads TSV under the C3 grammar and JSON as Internet JSON (I-JSON), with the generic kinds' words.guards.tsholds hand-written guards for the view envelope, every registered kind (the five generic kinds and the five presets), both transforms and both contents. The page runs no JSON Schema engine.view, the histogram content and theic-classescontent.Building the model
kinds.tsis the C2 dispatch. A known kind draws itself; otherwise a known base whose role contract the data meet draws them; otherwise the data show as tables.drawAsnever throws.model.ts(buildModel) ports neuroschema'sbuild_model. Before a file is parsed, its declared size is checked against the cap, and then the file's presence, size and SHA-256.kinds-models.v1pass, compared withObject.is, and so do every pointer snap and every bin location.nemar.sensor-labels.v1(placeByNames), and until then they show the site's wordlabels_pending.Renderers
tree.tsandrender/are pure functions from a model to an element tree. The server prints it as HTML (toHtml); the page builds elements from it (toDom).figurewith:figcaption;role="img"text alternative built from the model;details;Readouts
markerReadout).Contours
contourLinesis null for maps off screen.contoursOf, and so does the export hook for W8 (SensorFieldHandle.drawnMaps()).Cold first view (#592; the ADR 0137 budget is unchanged)
preparerequest builds a layout's geometry ahead of its maps.SensorFieldClient.warm(layout)runs as soon as the layout is known, while the values download. It starts the worker, prepares the geometry, and draws 72 throwaway maps at full size (one batch of 8 and one of 64).sharedSensorFieldClient()gives each page one client. The signal viewer now uses it: it prepares its map's geometry when its placement resolves and cancels its own draws on close, instead of ending the shared worker.website#592 leftovers
answer({type:"failure", id:null})and a latemessageerrorfrom a dropped stub, asserting the new worker's draws are unaffected. Removing eithercurrent()guard now fails the suite.contourLinesisnullfor maps off screen; everything that needs every contour callscontoursOfCOLOR_MAPS_NOTICE(/licenses/quality-views/NOTICE.txt) is linked from the rendered heatmaps and scalp mapsReview fixes (round 1)
The review found model and guard parity exact. These are the fixes for its Important and Moderate items, with the owner's two rulings.
Size: split the code, keep the 30 KB budget (owner ruling)
kinds.ts) run in the map worker, throughcheckandcheck-contentrequests (SensorFieldClient.checks()). They run on this thread, loaded on demand, only when the worker cannot answer.checks.tsholds the types the page uses.render/index.tsloads each renderer on demand for its model type, sosensor-field-viewloads only for scalp maps.transforms/,activations.ts) or W8 (export/) modules load with the entry.Instant cached data meets the budget (owner ruling)
warm()needs no layout. It draws 16 maps on a synthetic 64-sensor layout in batches of 8 only, so a real draw waits behind at most one batch of 8.buildModelfetches a scalp map's layout beside its values. ItsonLayoutcallback hands the page the layout's rows (warmInput) forprepare; these are the same rows asfieldDrawInput, so the prepared geometry is the one the draw finds cached.n/aplace:cacheHits > 0,cacheMisses = 0.Moderate fixes
kind@version. A registered kind with no builder draws by its base or as tables.qv-legend-turbo, with--qv-turbo-*tokens tested against the lookup table).absmaxit shows the sign words and the cell of the largest magnitude.HistogramMarkhas atextfield (the stored text), and the mark is part of the text alternative (markSentence).String(value)(1.50e1).detailsfirst opens.eagerTablesbuilds them up front for a server-drawn page.aria-livereadout is written only when its text changes.role="img"witharia-roledescription="scalp map";role="application"and did not use it, because it would take over screen readers' own reading keys.render/scale.ts), so a span past the largest double never puts NaN or Infinity into SVG.downloadUrlis linked only when it is http(s), blob, or a path on this site.javascript:,data:and every other scheme are shown as text.labels_pendingis recorded under Deviations: it must not reach production before W2b.Follow-up: a faster geometry (the geometry store was dropped in round 2)
These changes leave the budget and the meaning of "first maps" (the maps on screen first) as they were.
Math.log. Exact reuse of r² can skip at most 24% of the logarithms, which is not worth a cache.Follow-up 2: the first-visit eager view (owner: keep the budget and the gate)
Runner numbers below come from CI run 45746443761 on
61707f7. Each row gives first maps / whole view as the median of three fresh first views; each run imports the code afresh.The 256-sensor first-visit eager runs were 59.1, 59.1 and 60.8 ms. Inside them, building the geometry took 34.1 to 35.6 ms. The gate still fails, by 9 ms. I stopped there, as asked.
What each attempt did
buildModelalready hands the layout to the page (onLayout) as soon as it is read, beside the values, so on a real pageprepareoverlaps with hashing and parsing the values on the main thread. The gate starts its clock with the values already parsed and runs the worker on the same thread, so this overlap cannot show there.What remains: about 9 ms at 256 sensors on the runner. Of the geometry's 34–35 ms there:
Math.logcalls;I see no further exact speedup inside one thread. The options left are the owner's: measure the eager case on a real page, where the worker has its own thread; accept the 256-sensor first visit; or start the geometry before the panel mounts.
Owner ruling: prepare at page load
The gate.
prepareAhead(src/lib/quality-views/prepare-ahead.ts) preloads what the first screen needs, in idle time. It takes an option bag, so W6 can name exactly the first windows:warm: start the shared map worker;layout: {view, file}: fetch the layout file, check its size and SHA-256, read it, and prepare the geometry fromwarmInput's rows, keyed by the layout's SHA-256 as the draw is;files: fetch and check the first windows' view files, which the panel'sbuildModelthen reads throughpreloadedSourcewithout fetching them again;maxBytesandsignal.It is built to stay out of the way:
shouldPreload()turns it off onsaveDataand on 2G-class connections.Review fixes (round 2)
guards-computed.tsas a lazy chunk of its own, through a dynamic import in the ES module worker (worker.format: "es"; ours is the only worker Vite bundles), and no longer answersunchecked. The page loadslocal-checks.tsand the guards only when the worker cannot start.KIND_TABLE, held equal to the vendored registry by a test), so the worker carries no registry.mountViewtakes a per-container token and an optionalAbortSignal, so a slower, older render never replaces a newer one.prepareAheadcaps at the registry's bytes per role when it is given no cap;readLimited);Reader.prefetchleaves no unhandled rejection;warmInputreads places with the model's own cell reader ("",0x10and1e400are refused, and-0reads as 0).aria-roledescriptionand a keys hint, as the scalp maps do.Measured
First maps / whole view. The runner numbers are from CI run 45750267722 on
9a47bd6, as the median of three fresh first views; M4 is Vitest on the same head.Size (
check-quality-views-size.mjs, gzipped together; the sum of the files' own gzip sizes in brackets):guards-computedchunklocal-checkswithguards-computed), printed onlyMutations (each must fail the named tests)
The mutation script lives outside the repository; each mutation edits one guarded line, runs the tests and restores the file.
warmresolves at once) fails the cold gateonmessageacts (nocurrent()guard)onmessageerroracts (nocurrent()guard)onLayout)warmInputkeeps a row with no placewarmInputkeeps an EOG rowjavascript:download links allowed| the four-row LU pass changes the operation order | caught |
| G's diagonal is not g(0) = 0 | caught |
| the worker checks computed presets on the envelope alone | caught |
| a stale mount replaces a newer one | caught |
| the panel waits on a hung preload | caught |
| a prefetch rejection is left unhandled | caught |
|
warmInputreads cells withNumber| caught ||
prepareAheadhas no default cap | caught ||
readLimitedreads past the declared size | caught || drawings lose their role description | caught |
| the worker checks a computed preset without its schemas | caught |
One possible mutation has no test: hard-coding version 1 in the
kind@versionkey. Every registered kind is at version 1 today, so that mutation is not observable.The warm-up mutation is caught by the cold gate's check that the warm-up drew its 16 maps. The prepare mutation is caught by the same gate's check that the geometry was cached. On the runner the timing is also at the edge: in this run an unwarmed first view drew its first maps in 50.1 ms, over the 50 ms budget. W2 measured the whole unwarmed view at 107 to 137 ms there.
Deviations
placeByNames; without it, every map showslabels_pending. Those cases still compare drawing, refusal, downloads and stored texts.labels_pendingmust not reach production before W2b: no panel may ship with a scalp map placed by name untilnemar.sensor-labels.v1providesplaceByNames.mapsandpresetfields inkinds-models.v1and thepreset-checks.v1andrecord-checks.v1vectors are left to W6.dataQuality, the data paper and the dataset document are not replayed. The test names their schemas with their phases (W5/W6).kinds.ts, which holds the registry, the rule and the role contract. Dispatching a built model to its renderer lives inrender/index.ts.What W5 and W6 need
tsv.ts/verify.tsshould build onread.ts(TSV, cells, I-JSON) andmodel.ts'ssubtleSha256, not repeat them.histogramSvg(model, mark?)andtoHtml, one tree for the server and the page.markedIndexplaces one recording's value by the edges' rule; NaN marks nothing.buildModel(view, preloadedSource(fetchFile), {checks: sharedSensorFieldClient().checks(), montage: loadMontage, onLayout});mountView(container, built, ctx, {client: sharedSensorFieldClient, layoutKey, colors}, signal).mountViewignores a stale mount: a newer mount of the same container, or an abortedsignal, wins.sharedSensorFieldClient().warm()when the panel mounts. InonLayout, callprepare({layoutKey, ...places}).src/styles/quality-views.cssin the panel.renderRefusal(word, downloads, ctx)words aViewRefused.prepareAheadfromrequestIdleCallback, aftershouldPreload().prepareAheaddoes not draw maps ahead. Drawing the first batch before the panel opens would need a result cache for it, which W6 adds if it wants that.maxBytesfrom the files named above (the cap follows the scope).AbortSignalthat aborts when the user navigates away, and callforgetPreloads()on leaving the dataset;ic-activitytransform must be a lazy chunk of the worker, likeguards-computed.ts. The size check gates the worker together with its lazy chunks at 12 KB.SensorFieldHandle.drawnMaps(), which already traces contours throughcontoursOf.Testing
bun run typecheck: 0 errors.bun run lint: clean.quality-views-*files andeeg-viewer: pass.bunx astro build, then the size check: pass (numbers above).bun run test:quality-views-perfon M4: pass.bun run test:e2e e2e/quality-views-perf.spec.ts: 2 of 2 pass on M4.bun run testwith everyNEMAR_CLI_*variable set: 8,020 passed, 5 skipped. The 6 failures are the expected drift tests against nemar-clidev.9a47bd6: lint, typecheck, the drawing budget and the size step pass. Vitest fails only the same 6 drift tests.Refs #588, #592, nemarOrg/nemar-cli#2324
Agentic AI tools were used.