Skip to content

docs: browser execution tool design note - #351

Merged
neuromechanist merged 7 commits into
developfrom
feature/browser-execution-tool-design
Sep 16, 2026
Merged

neuromechanist merged 7 commits into
developfrom
feature/browser-execution-tool-design

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Design note for a community-agnostic, client-executed execute_code tool: code runs in the user's browser in a Pyodide worker owned by the widget, the agent loop stays in LangGraph on the server, and the two meet through tool_request / tool_result events with interrupt-and-resume. Lazy loading maps a uv-style workflow onto loadPackagesFromImports, micropip, and a per-community pinned lockfile. NEMAR is the first adopter; EEGLAB, HED, and BIDS adopt through configuration.

File: .context/browser-execution-tool-design.md

Companion decision on the NEMAR side: nemarOrg/nemar-cli ADR 0049 (PR linked in a comment below).

Draft for the owner's review. No code changes. The pr-review-toolkit pass was skipped because this PR is a design document; it will run before the PR leaves draft.

Client-executed execute_code tool: Pyodide in a widget worker, LangGraph interrupt/resume on the server, per-community runtime config with lockfile-pinned lazy loading. NEMAR is the first adopter; the design is community-agnostic.
@neuromechanist

Copy link
Copy Markdown
Member Author

Companion NEMAR decision: nemarOrg/nemar-cli#1292 (ADR 0049, supersedes ADR 0025).

@neuromechanist

Copy link
Copy Markdown
Member Author

First adopter's engine work: sccn/eegprep#324 (eegprep installable under Pyodide, ONNX ICLabel loaded through the runtime's JavaScript library hook).

@neuromechanist
neuromechanist marked this pull request as ready for review September 16, 2026 20:04
@neuromechanist

Copy link
Copy Markdown
Member Author

Review folded in

Two independent reviewers went over this as a design document. They converged on the same critical findings, which is why I have revised rather than merged as written. The note is now 498 lines and carries a new What this assumes about OSA today section listing ten Phase 0 prerequisites.

Corrected inline

  • The server-change section named stream_response, which lives in an unmounted router. The live function is _stream_chat_response in src/api/routers/community.py. The diagram and the sequence named it too.
  • __interrupt__ is not a top-level streamed key under astream_events(version="v2"), which is the API this path uses. It arrives nested as event["data"]["chunk"]["__interrupt__"] on an on_chain_stream event.
  • SqliteSaver is not in the lockfile. langgraph-checkpoint-postgres already is, with nothing importing it.
  • The config example loaded src.assistants.nemar.tools, deleted in feat: load NEMAR's dataset tools from its MCP server #352, and presented mcp_servers and its consumer as unbuilt. Both shipped.
  • Images break the token budget. count_tokens_approximately does not support image content and falls back to repr() character counting, so a single 250 KB PNG measures about 85,000 tokens against an 80,000 budget and trim_messages then discards the conversation. It fails as silent context loss, not as an error. Now a required Phase 1 change with a byte cap, not only a pixel cap.
  • The Content Security Policy paragraph read website ADR 0009 backwards: wasm-unsafe-eval is granted globally on nemar.org, and what is route-scoped is the stronger 'unsafe-eval'. That ADR exists because wasm-unsafe-eval alone was not enough. connect-src and worker-src were missing entirely.
  • ADR 0049's inbound data-plane CORS requirement was absent, and is not the same thing as the outbound fetch_allow. The S3 side is now configured: nemar.org and subdomains, Pages previews, demo.osc.earth and loopback for GET and HEAD, exposing Content-Range, Content-Length and Accept-Ranges.
  • The fetch wrapper was described as a boundary. It is not: XMLHttpRequest, WebSocket, EventSource and micropip are all reachable from Python.
  • Permission default was self-contradictory. Gate on, auto-run off.
  • First load is about 33 MB, not 50 to 60. ADR 0049 carries the same wrong figure and should be corrected in the same pass.
  • ADR 0049's required engine naming and its "memory is the binding constraint" were both missing.
  • The MCP recipe's how_to.python_zarr uses boto3, which is absent from Pyodide, so a model copying it will fail.

The one thing I did not decide

The transport is unresolved and blocks Phase 1. The 120-second wall-clock abort exists independently in workers/osa-worker/index.js and in frontend/osa-chat-widget.js, and it covers the whole turn, so a stream cannot be parked across a human deciding whether to click Run. This note's own exec_seconds default of 120 consumes the entire budget.

Three options are now written up in Open Questions: raise both timeouts, move to a WebSocket, or two-run continuation with no checkpointer at all, which is what CopilotKit and the Vercel AI SDK ship and which dissolves the checkpointer, the sweep and the retention question. That is a design call for @neuromechanist, not something to fold in silently.

Also recorded: the QP precedent was cited as de-risking, but QP's agent loop is client-side, so it needed no interrupt, no checkpointer and no resume. It shares the tool contract, not the hard part.

@neuromechanist
neuromechanist merged commit f7fe4f7 into develop Sep 16, 2026
6 checks passed
@neuromechanist
neuromechanist deleted the feature/browser-execution-tool-design branch September 16, 2026 22:05
neuromechanist added a commit that referenced this pull request Sep 30, 2026
The file had sections for 0.8.10, 0.8.12, 0.8.14 and 0.8.15 only. The
three missing releases are written from the pull requests between their
tags (0.8.13: #438, #440, #441, #443; 0.8.11: #418; 0.8.9: #351 to #355
and #359 and #367), so the last seven releases are now all present.

Tested: docs only; each entry checked against its pull request's body.
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