Skip to content

Phase 3c: a progress bar, measured wheel caching, and an adopter guide - #451

Merged
neuromechanist merged 18 commits into
feature/issue-429-epic-browser-executionfrom
feature/issue-432-phase3-runtime-ux
Sep 23, 2026
Merged

neuromechanist merged 18 commits into
feature/issue-429-epic-browser-executionfrom
feature/issue-432-phase3-runtime-ux

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

The last of three OSA pull requests for phase 3. It gives the browser runtime a progress bar that counts the whole boot, measures in Chrome that the wheels a reader downloads once stay in the browser's cache, and writes down for any community how to adopt the runtime.

What ships

A progress bar that does not jump. Each boot phase used to restart its own count, so a reader saw "1 of 4", then "1 of 1", then "1 of 2", and runtime_loaded showed nothing. The worker core now fixes the boot's step count before it starts (one for the interpreter, one per preload name, one for micropip plus one per allow_install entry, one for the prelude) and every progress message carries step and steps; index and total are gone, and nothing read them. The widget draws a determinate role="progressbar" with aria-valuenow, aria-valuemax and an accessible name beside the label. runtime_loaded says Python downloads once and the browser keeps it, with no size figure. Once the runtime leaves booting (ready, failed, terminated or idle) the bar clears and the panel says the code is running. A step that is not a positive integer, or one past the count, draws no bar. The runtime bundle and its integrity pin are rebuilt.

Cache behavior, measured and gated. The API route and the worker already served wheels as public, max-age=31536000, immutable, but every harness run used a fresh profile and serve.js sent no-store, so the cache was never measured. serve.js now sends the same header on the wheel routes, and a drift test keeps the three copies equal and checks each file sends its own constant. chrome.js attaches to the Pyodide worker paused at its start and records its network, then boots NEMAR's runtime twice more on the same origin: a warm boot, where both overlay wheels must come from the browser cache with 0 bytes over the network, and a lock change, where one wheel renamed with a build tag (same bytes and sha256) must be the only one fetched. Both require the exact set of wheels the overlay lists, and a worker the harness could not watch fails the run. Measured on Chrome 153: zarr 377,491 B cold and 0 B warm, eegprep-lean dev2 28,852 B cold and 0 B warm. jsDelivr's interpreter and stock wheels were also cache hits; they are reported, not gated.

A guide for a community adopting the runtime. docs/community-browser-runtime.md, linked from the README's "Adding a New Community": the client_tools and runtime.python keys and what the server enforces of limits, fetch_allow as the egress control, the lock overlay and immutable wheel names, the prelude and the privileges it runs with, the Pyodide pin CI requires, the embedding page's Content-Security-Policy and why a refused runtime hangs, the measured first-load cost (18.9 MB for NEMAR on 0.29.5, 35.2 MB with scipy), and the pybids blocker. Every claim cites the file that owns it, and each citation was checked against the code. The design note's size figures now agree with nemar-cli ADR 0049's 2026-09-22 amendment.

For the release

The widget's own bytes changed, so its integrity hash changed too. Nothing in this repository pins it, but nemar.org does: the re-pin after the phase 4 release covers it.

Test plan

  • uv run pytest -m "not network": 2709 passed, 50 skipped. Two failures, neither from this branch: the known test_version_shows_version fails locally and passes in CI, because rich colorizes on a TTY #434, and test_fetch_real_document, which timed out reaching GitHub and passes on its own; it is an unmarked network test, which test: unmarked live-network tests can hang the local suite indefinitely #397 tracks. ruff check and ruff format --check are clean.
  • Every Bun suite CI runs: test-worker-core.js 135 of 135, test-widget-tools.js 127 of 127, test-runtime-lifecycle.js 166 of 166, test-data-lane.js 57 of 57, test-controller.js 77 of 77, test-egress.js 80 of 80, test-output.js 66 of 66, test-runtime-bundle.js 25 of 25, test-citation-markers.js, test-streaming.js, test-endpoint-resolution.js, and the worker's test-routing.js and test-mounted-hosts.js, all green. build-runtime-bundle.js --check is current.
  • chrome.js in headless Chrome 153: nemarlike 40 of 40, control fails to boot as it must, warm and lock change pass.
  • Worker-core tests assert the exact step/steps sequence for every boot shape: nothing to load, preload only, preload with allow_install, allow_install alone, a prelude, and a boot that fails partway.
  • Mutation-checked, each failing a test: no-store on the wheel routes (warm and lock change fail); one overlay wheel hidden from the recorder (warm fails); a worker attach that fails (every recorded run fails, naming the worker); an empty overlay list (the harness stops); a route sending another literal, or a second copy of the header (drift test); dropping micropip's step when nothing is preloaded (only the new allow_install-alone case catches it); the widget clearing only on ready, and a missing step <= steps bound (widget tests); the runtime forwarding progress without step/steps (lifecycle test).

Reviewed locally by Sonnet agents; how each finding was addressed is in a comment below.

Closes #432.
Part of epic #429.

Compute the whole boot's step count once, before it starts: one for
the interpreter, one per preload name, one for micropip plus one per
allow_install entry when there is one, and one for the prelude when
there is one. Every progress message now carries step/steps instead
of the per-phase index/total that reset mid-boot. The widget renders
a determinate progressbar from them, and runtime_loaded gets its own
reassuring label instead of rendering nothing.
serve.js sent no-store everywhere, so the browser cache was never
measured. Wheel routes now send the same "public, max-age=31536000,
immutable" the API and worker send. Named as a module constant on
the Python side (RUNTIME_WHEEL_CACHE_CONTROL) with a drift test that
keeps it equal to the worker's IMMUTABLE and the harness server's own
copy. Also adds an in-memory lock-change overlay variant (one wheel
renamed with a build tag, same bytes) for the upcoming warm-cache
measurement.
Auto-attach to the blob worker Pyodide runs in (Target.setAutoAttach
on the page session, Network.enable and runIfWaitingForDebugger per
worker session) and record its network traffic. After the nemarlike
run, a new cache-boot.html page reboots NEMAR's overlay on the same
server, port and browser: every overlay wheel request must now be
served from cache, cross-checked against encodedDataLength. A third
boot serves eegprep-lean under a renamed (same-bytes) file name, and
only that wheel should reach the network. jsDelivr's own assets are
reported, not gated. Numbers recorded in README.md.
docs/community-browser-runtime.md covers the client_tools and
runtime.python config keys, fetch_allow as the egress control, the
lock overlay and its refresh procedure (linked, not copied, since
nemar's runtime/README.md is being rewritten elsewhere), the prelude,
the Pyodide version pin CI enforces, the embedding page's CSP and why
a refused runtime hangs, the measured first-load cost and what the
cache gate found for a warm load, and the pybids blocker. Linked from
the README's Adding a New Community section. Also updates the design
note's stale scipy-era size figures to match.
progress.step and progress.steps are only ever null or a positive
integer (guarded in onRuntimeProgress), so they cannot carry a quote
character; the drift test already whitelists other numeric
interpolations for the same reason.
28,502 B, not 28,475 B: verified against a clean (non-mutated) run
rather than the earlier mutation-check run, which measured the same
wheel while every route was reverted to no-store.
Rebased onto the dev2 re-vendor; chrome.js passes its warm and
lock-change checks there, and the table now shows dev2's 28,852 bytes.
The panel kept the boot's last label and a full bar while the reader's
code ran. The widget now takes the runtime's state changes and goes
back to 'Running Python' on ready. runtime_loaded no longer says Python
is ready while its packages are still to load. Mutation-checked.
The warm and lock-change checks passed when a wheel went unobserved,
for example from a worker the recorder missed. Both now compare against
the overlay's own file names, and a failed worker attach is logged.
Mutation-checked: hiding zarr fails both.
Failed, terminated and idle now clear the bar as ready does. A step
count that is not a positive integer, or a step past it, draws no bar.
Widget tests: 127 of 127; both guards mutation-checked.
The plain boot, allow_install without preload, and a failing boot, plus
the runtime forwarding step and steps unchanged. Worker core 135 of 135,
lifecycle 166 of 166; each new case mutation-checked.
Rebuilds the runtime bundle and its integrity pin.
The drift test now fails when a route sends another literal or a file
spells the value twice. Mutation-checked on all three files.
A worker whose network could not be watched fails its run, an empty
overlay list stops the harness, and page listeners are removed after
each run. chrome.js: all checks pass; both guards mutation-checked.
Four limits are server-capped (stdout, stderr, images, image_px);
memory_mb and exec_seconds are the browser's own. jsDelivr's header has
no immutable. MCP dropped from the example; CORS, CI and API spelled
out. Reflowed to semantic line breaks.
Semantic line breaks, and the two guarantees this round added: an
unwatched worker fails its run, and the checks need the exact set.
image_px is capped by the server but defaults below the cap.
@neuromechanist

Copy link
Copy Markdown
Member Author

Local review, and what was done with each finding

The lead's pass over the implementer's commits came first, then six Sonnet reviewers: code, tests, error handling, docs accuracy, simplification, and the seams with the rest of the epic. Every finding is addressed; the two items not changed are explained at the end.

The lead's pass

  • The branch was rebased onto Phase 3b: re-vendor eegprep-lean 0.1.0.dev2 and watch upstream #450, which vendored eegprep-lean dev2, so the cache numbers were measured again against dev2. c261dc1
  • The bar stayed full while the reader's code ran, because the boot's last progress message was the last thing the panel heard. It now clears when the runtime is ready. 55e7ab3
  • The cache checks passed when only some overlay wheels were observed: "every observed request was cached" holds for a request nobody observed. Both checks now require the exact set of wheels the overlay lists; hiding zarr from the recorder fails the warm check. 7969533

Error handling

  • With an empty overlay list, the warm check compared nothing with nothing and passed. The harness now stops if the overlay names no wheel. 55b21a2
  • A worker whose network could not be watched was only logged. It now fails its run and names the worker's URL; mutation-checked by failing every attach. 55b21a2
  • The bar cleared only on ready, so a failed or stopped boot relied on another file's timing to clear it. It now clears whenever the runtime leaves booting, and the test walks every state the runtime declares. 64c455b

Tests

  • A boot that fails partway had no step assertions. It now asserts the progress sent before the failure. 37949d1
  • The plain boot and allow_install without preload had no step assertions. Both do; dropping micropip's step when nothing is preloaded is caught only by the new case. 37949d1
  • The widget's step guard had no malformed input. Eight malformed pairs (a step past the count, a string, zero, a negative, a float, a zero count, null) must keep the label and draw no bar; removing the step <= steps bound fails. 64c455b
  • Nothing showed step/steps surviving osa-runtime.js's forwarding. The lifecycle test now asserts each progress message arrives whole; forwarding only phase and package fails. 37949d1
  • The drift test proved the three values equal, not that the routes send them. It now checks each file sends its constant, and spells the value only once; a route sending no-store, or a second literal, fails. 4344ba5

Docs

  • The limits bullet said every field defaults to the server's cap. Four are server-capped (stdout_chars, stderr_chars, images, image_px), and image_px defaults below its cap; memory_mb and exec_seconds are the browser's own. 5ffd8b0, 59ed4a7
  • The example description used "MCP" without spelling it out. The example no longer needs it; CORS, CI and API are now spelled out on first use too. 5ffd8b0
  • The guide was hard-wrapped. It and the harness README's cache section now use semantic line breaks. 5ffd8b0, 842ba30
  • Found while re-checking the guide: it said jsDelivr sends the same immutable header as our wheels. It sends public, max-age=31536000, without immutable, as the harness measured. 5ffd8b0
  • Found while re-checking the design note: it called ADR 0049's "50 to 60 MB" a different package set, while nemar-cli's amendment of 2026-09-22 says it was a high estimate and records these measured figures. The note now agrees, and points at the guide's section rather than a table the guide does not have. a350712

Simplification and code

  • The four pass/fail blocks in chrome.js share one report helper, and the three recorded runs share runRecorded. 55b21a2
  • nextStep()'s return value was unused. c7da387
  • Page listeners were never removed across runs. Inert, since session ids are not reused, but cdp.on now returns an unsubscribe and each run removes its own. 55b21a2

Not changed

  • The bar is full while the last step is still loading, because step names the step starting. That is the "step N of M" convention the tests pin, and the bar clears when the boot ends.
  • No shared zip helper: the only other wheel builders are in Python and cannot serve a Bun test.
  • The seams review found no mismatch. Its one note, that the widget's own integrity hash changed, is in the description: nemar.org's re-pin after the phase 4 release covers it.

@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-432-phase3-run-demo.osc.earth
Branch feature/issue-432-phase3-runtime-ux
Commit b67b5c5

This preview will be updated automatically when you push new commits.

@neuromechanist
neuromechanist merged commit dfd1606 into feature/issue-429-epic-browser-execution Sep 23, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-432-phase3-runtime-ux branch September 23, 2026 04:44
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