Repository navigation
feat: memory budget per step, run card heap report and whole-recording Welch recipe (E5.1, E5.2) - #699
Conversation
…the prompt (E5.1) PageContext takes memory_budget_mb (256, 512, 1024 or 2048; anything else is a 422) on /chat and /chat/resume, the agent dataclass carries it, and a budget-only request renders its own '## Browser memory budget' section. NEMAR's plan-first text now requires est_peak_mb to stay within it. Tested: pytest on the page-context, plan-first and prompt tests, including the real assistant factory and 422s over HTTP.
The worker measures Pyodide's memory after every run and sends heap_bytes beside the result. PyodideRuntime keeps it by call id (heapBytes), outside ClientToolResult, so the wire result is unchanged. New osa-memory.js holds the budget sizes, the heap report and the warning text, exported as OSARuntime.memory; the bundle and its integrity line are rebuilt. Tested: test-worker-core.js (real Pyodide), test-runtime-lifecycle.js, bundle check.
…g (E5.1) Settings gets a Browser memory field (256 MB, 512 MB default, 1 GB, 2 GB; 44 px choices, Cancel and Save unchanged), stored as memoryBudgetMb with an invalid value reading as 512. getPageContext sends memory_budget_mb on /chat and /chat/resume only when the page has the browser runtime. Each run record keeps heapMb and the budget it ran under; the run card shows 'Heap N MB of B MB' and, over budget, a warning naming the step, restored by reload and History. The plan card warns while a draft's largest step exceeds the budget. Tested: new test-widget-memory-budget.js, registered in the frontend-tests job; settings, plan-card, run-card and history suites still pass.
…ding (E5.2) Replaces the capped one-channel recipe with a per-channel loop over chunks that start every m * hop samples and span exactly their segments, averaged weighted by segment count, so the result equals one welch call over the whole channel. The chunk is the smaller of 2**28 // nperseg and what the reader's memory budget leaves room for; the 'cut short, say how many seconds' sentence is gone and the recipe prints the segments and seconds it covered. The execute_code description follows. Tested: test-data-lane.js on real Pyodide (chunked equals one welch call to 1e-9 at 250, 128.5 and 1000 Hz, a by-hand estimate, a 50-minute signal covered in full, the old limits as controls) and the NEMAR config tests.
… (E5.1, E5.2) Documents the Browser memory setting, the page_context field, the heap line and its warning, and the chunked Welch recipe with the on002718 measurement and what was used for it. CHANGELOG [Unreleased] updated. Docs only; the suites they describe are run separately.
Preview Deployment
This preview will be updated automatically when you push new commits. |
…red sizes; budget tests use the scripted chat model (tested)
…olor token, page context captured at send time (tested)
…the recording; data lane runs it against one welch call (tested)
…red heap (tested)
…asurement, real-recording script (not run in CI)
|
Review round 1: every finding has an outcome. Fix commits are on this branch (e6de8c9, bef22d1, 85564a9, 14884cf, 2ae78f4). Rerun: all
|
… line is a plain note (tested)
…ut; execute_code description teaches reading in pieces (tested)
…t comment, changelog capitalization (comment and docs only; tests rerun)
|
Review round 2 outcomes (fixes pushed to this branch; tests rerun:
No findings rejected or filed as new issues. |
|
Project manager verdict: ready to merge. The branch conflicted with develop in CHANGELOG.md; resolved by keeping both entries (merge commit 1065e2c), bundle check, memory-budget, data-lane, bundle, run-card, plan-card and settings suites, metrics and page-context pytest and ruff all pass. Every check in gh pr checks is green (Lint, Test 3.11 and 3.12, Frontend Tests, Docker, notebook site). Every review finding from rounds 1 and 2 has an outcome. All six acceptance criteria are met per the diff and tests. Merge was not performed by this run (blocked by the permission classifier); #668 and #669 remain to be closed after the squash merge. |
Summary
E5.1 (browser memory budget) and E5.2 (whole-recording power spectrum) of the NEMAR AI experience plan, on top of the merged plan-first prompt (E2.2) and the plan card's
est_peak_mbline (E2.3).E5.1, widget and runtime
memoryBudgetMbin the user settings. A stored value that is not one of the four reads as 512.page_context.memory_budget_mbis sent on/chatand/chat/resumeonly from a page whose browser runtime has loaded.page_contextis still absent when nothing else is set and there is no runtime. On/chatthe page context is now built after the wait for the client tools, since that is when the runtime is known.pyodide._module.HEAPU8.byteLength) after each run and sends it asheap_bytesbeside the result. It is not aClientToolResultfield and never reaches the server (CLIENT_TOOL_RESULT_FIELDSis unchanged);PyodideRuntime#heapBytes(callId)hands it to the widget, which storesheapMband thebudgetMbthe run was under on the run record and in the history normalizer.Heap N MB of B MBand, when N is more than B, a warning style and a line naming the step ("Step 2, Epoch the EEG, used more than the 512 MB budget. ..."; "This run" for a run no plan covers). Reload and History restore it.frontend/osa-memory.js, exported asOSARuntime.memory; the runtime bundle and its integrity line are rebuilt.E5.1, backend
PageContext(API) and the agent dataclass takememory_budget_mb, restricted to 256, 512, 1024 or 2048; any other value is a 422 on/chatand/chat/resume.## Browser memory budgetparagraph, rendered for a budget-only request too. NEMAR'splan_first_instructionsrequireest_peak_mbnot to exceed it.E5.2
Power spectrumrecipe and theexecute_codedescription now loop per channel over chunks ofmin(2**28 // nperseg, budget_mb * 2**20 // 160)samples, cut so that together they hold exactly the segments onewelchcall over the whole channel would, averaged weighted by segment count. The "cut short, say how many seconds" sentence is gone; the recipe asserts every channel averaged every segment and prints how many segments and seconds it covered.frontend/test-data-lane.jsruns the block under real Pyodide: (a) chunked equals onewelchcall per channel to 1e-9 (250, 128.5 and 1000 Hz, one chunk and many) and equals a by-hand numpy estimate; (b) a 50-minute signal at 250 Hz, which one call refuses, has all 2,999 segments counted on every channel and a tone carried only by its last tenth is found; (c) the old limits remain as controls.docs/community-browser-runtime.md,docs/community-widget.md,CHANGELOG.mdupdated;tests/test_assistants/test_nemar_runtime.pyno longer pins the old strings.Recording used for E5.2
on002718sub-002FaceRecognitionwas read, for real, not a stand-in.zarr.nemar.orgserves it (groupeeg_250hz: 74 channels, 747,750 samples, 2,991 s). I read it through NEMAR's production runtime config and prelude on real Pyodide 0.29.5 under Bun, the same worker-core lanetest-data-lane.jsuses, with the recipe taken verbatim from the prompt:read_windowof the whole recording: 11.7 s (74 x 747,750 float64, 443 MB).welchcall over a channel: refused ("array is too big"), as the controls say.Caveat: this was Pyodide under Bun, not headless Chrome, and the one-off script that ran it is not committed (it reads a live host, so it cannot run in CI). The CI evidence is the synthetic 50-minute test above.
Closes
Closes #668
Closes #669
GitHub only closes these on the default branch, so they will not close on merge into
develop; the project manager closes them after the squash merge withgh issue close N --reason completed .... #669's verification (a whole-recording spectrum onon002718sub-002) was met as described above, with the caveat that it ran under Bun, not in a browser.Commands run
uv sync --all-extras && bun install: okbun frontend/test-widget-memory-budget.js: 152 passed, 0 failedbun frontend/test-widget-settings.js: 184 passed;test-widget-run-card.js: 261 passed;test-widget-plan-card.js: 264 passedbun frontend/test-runtime-lifecycle.js: 192 passed;test-worker-core.js: 227 passed;test-data-lane.js: 152 passedbun scripts/build-runtime-bundle.js && bun scripts/build-runtime-bundle.js --check: current (109484 bytes, sha384-0SZW+yBsJvcAmUfMq94z+uml6IwbQY2M1Hl9bxCcuNNqviHEhKJdIDLRjfPzhxsU);bun frontend/test-runtime-bundle.js: 39 passedfrontend/test-*.jssuite: no failuresuv run pytest tests/test_agents/test_page_context.py tests/test_api/test_page_context.py tests/test_assistants/test_nemar_runtime.py tests/test_frontend -q: 351 passeduv run pytest tests -m "not llm"(ignoringtests/test_core/test_llm_service.py, which fails to import under this Python 3.14 environment with a pydantic v1 error): 5,700 passed, 1 failed (tests/test_tools/test_hed_suggest.py::test_real_program_suggests_a_schema_tag, a HED tool call that needs a live service and touches nothing here)uv run ruff check . && uv run ruff format --check .: cleanDeviations from the brief
budgetMbas well asheapMb, so a card read later shows the budget the run had, not whatever Settings says now. Additive.(k - 1) * hop + npersegsamples withhop = nperseg - nperseg // 2, which is the brief's(m + 1) * hopandnperseg // 2for evennpersegand exact for an odd one (128.5 Hz is tested).osa-memory.jsand to the server's list.feature/issue-669-chunked-welch.