Plugin guides
nanocode runtime experiments
What the nanocode agent runtime was tested for, how, and the measured results
Read when: You want to know what has been tested on the nanocode agent runtime and what has not; you are sizing how many nanocode sessions one Gateway can carry; you want to reproduce or extend a nanocode runtime measurement.
These experiments test the nanocode agent runtime: does a nanocode session work as an ordinary OpenClaw Gateway session, and how many can one Gateway carry. Each test states the question it answers and what it cannot show.
All runs took place on 2026-11-25 on one shared machine, not a dedicated benchmark host. The functional tests used a real model (NVIDIA Nemotron 3 Ultra). The capacity tests used a stand-in model that replays a recorded Nemotron reply, so they measure the Gateway and nanocode, not the model provider.
Summary
- Works as a Gateway session. Turns, resume, Gateway tools, the shell and files, transcript rows and live streaming each passed on a real Gateway with a real model.
- Three defects found and fixed by these tests:
- replies were buffered whole instead of streamed;
- transcript rows collided when a model reused an item id;
- model requests bypassed the provider's own network policy.
- One Gateway completes about 8.7 nanocode turns per second. All 1,110 nanocode turns in the capacity runs succeeded, up to 100 agents at once, with Gateway memory flat near 2.2 GB.
- The ceiling is the Gateway's per-turn work, not nanocode.
- A turn costs about 250 ms of Gateway CPU; nanocode alone costs 4 to 5 ms.
- OpenClaw's built-in runtime under the same load reaches the same ceiling (about 7.8 turns per second).
- Outside the Gateway, one process ran 500 nanocode sessions at once. That run completed 1,500 turns at 4 ms of CPU each, using 12.5 MB per idle session.
- The profile puts the ceiling on the Gateway's main thread.
- The main thread is busy 90% to 99% of each second under load.
- About three quarters of its time is the Gateway's own turn work, spread over many steps of 2 to 7 ms each.
- About a quarter is nanocode. Two parts of that were waste in this plugin: every request carried 57 tool definitions (134.5 KB) where the built-in runtime sends 14, and every turn reopened the nanocode session.
- Tool search is now on. Requests dropped from 154 KB to 25 KB, with 8 tools sent directly; the model reached a hidden tool through search and dispatch on Nemotron. Gateway throughput changed little.
- The agent's instructions now reach nanocode. Workspace files such as
AGENTS.mdandSOUL.mdgo through the same prompt hooks as on the other runtimes. On Nemotron the agent answered fromAGENTS.mdand followedSOUL.md. Requests grew to 40 KB; capacity held. - Sessions now stay open between turns. Gateway CPU per turn fell by about 30% and throughput rose by about 20%, to 11 turns per second at 100 agents. The cost is memory: 16 to 21 MB per open session, about 80% of it nanocode's WebAssembly engine memory, which does not grow with the conversation.
- A swarm engine runs its agents as Gateway sessions. The unmodified swarms tree engine ran its orchestrator and 14 workers through the plugin's agent API, split its goal into four lemmas and committed their statements. Five defects were found and fixed on the way. See Swarm engine on Gateway sessions.
- Swarm workers now read and commit to their swarm's repository. With three git tools and no other tool, workers read their statements, committed proofs to their own branches and returned the commit, and the engine committed the lemmas they split off. No proof was checked: the engine's Lean verifier needs compute, which is off. See Swarm worker repository tools.
Setup
| Item | Value |
|---|---|
| Machine | Intel Core i5-13500 (20 threads), 62 GB RAM, Ubuntu 22.04.5, kernel 5.15 |
| Sharing | The machine also runs other services (database pipelines, a swarm engine); results can vary with their load |
| OpenClaw | 2026.11.3, branch feat/nanocode-harness on base 3fe26b8 |
| nanocode | nanocode-ts build 887f3cc |
| Node | 24.22.1 |
| Gateway | One process, loopback only, its own state directory, token auth |
| Real model | nvidia/nemotron-3-ultra-550b-a55b over NVIDIA's OpenAI Responses route |
| Stand-in model | bench/standin.mjs: replays one recorded Nemotron Responses stream; 1 s to first byte, then 20 events 25 ms apart (1.5 s per model call) |
Functional tests
Each test ran one or two turns through the Gateway with the real model. The evidence column names what was read to confirm the result, not just the model's own answer.
| Question | Test | Result | Evidence |
|---|---|---|---|
| Does a turn run on nanocode? | Ask for an exact sentence | Pass | Run reports agentHarnessId: "nanocode"; nanocode's session database created |
| Does the next turn resume the same nanocode session? | Ask what the previous turn asked for | Pass | The answer quoted turn one; four rows in the OpenClaw transcript |
| Can the model call a Gateway tool? | Ask for session_status |
Pass | The answer gave the exact session key; call and result rows in the transcript |
| Are tool arguments passed and validated? | Ask for sessions_list with limit: 5 |
Pass | Transcript shows {"limit": 5}; the answer listed the three real sessions |
| Can the shell write and run files? | Write a script, run it, save its output | Pass | Files read back directly from the session database |
| Do files persist, and is the shell isolated? | Next turn: read the file, list host folders, call curl |
Pass | File read back; host folders absent; curl refused with no network |
| Are nanocode's own steps in the transcript, in order? | Shell command, then session_status, then answer |
Pass | Rows: call, result, call, result, one answer |
| Does reply text stream live? | 40 numbered sentences, timed in the terminal UI | Pass after fix | Sentences 1, 10, 20, 40 first shown at 5.0 s, 9.6 s, 13.2 s, 22.4 s |
| Do model calls use the provider's transport? | One turn after switching to core's guarded model fetch | Pass | Reply transport ok on the NVIDIA route |
What these tests cannot show: behavior on Anthropic Messages routes (not run), on chat channels such as Telegram or Slack (not run), in the Control UI (only the terminal UI was used), and under approvals that ask the user (none of the tools used needed one).
Defects found
| Defect | How it showed | Cause | Fix |
|---|---|---|---|
| Replies arrived whole | All 40 sentences appeared at once, at 64.7 s | The model's response was read whole before nanocode saw it | Pass the response through as a stream |
| Second turn failed | HTTP 500 on every second turn with the stand-in | Transcript keys used the model's item id, which the stand-in repeats | Key rows by run as well |
| Local model servers unreachable | Found while setting up the stand-in on loopback | Requests used a fixed HTTPS-only policy | Use the model's own guarded transport |
The stand-in repeats item ids on purpose, but some OpenAI-compatible servers may reuse them too, so the second fix matters beyond the test.
Capacity through the Gateway
Question. How many nanocode sessions can one Gateway carry, and what limits it?
Method.
bench/load.mjsstarts N simulated agents at once. Each is its own Gateway session (one OpenAIuserper agent) and runs two turns in a row throughPOST /v1/chat/completionson the stand-in model.- The script samples the Gateway process's CPU time and resident memory, and reads the main-thread stalls the Gateway logs itself.
- Each level ran three times.
- Values. Tables show the median of the three runs.
- Latency is the client-side time for one turn, queueing included.
- Throughput is completed turns divided by wall time.
Results, nanocode runtime. All 1,110 turns succeeded.
| Agents | Turns per run | Throughput, turns/s | Turn p50, ms | Turn p95, ms | Gateway CPU per turn, ms | Gateway memory peak, MB |
|---|---|---|---|---|---|---|
| 10 | 20 | 4.4 | 2,029 | 2,521 | 271 | 2,271 |
| 25 | 50 | 7.5 | 2,738 | 3,756 | 252 | 2,462 |
| 50 | 100 | 8.1 | 5,265 | 6,813 | 250 | 2,279 |
| 100 | 200 | 8.7 | 10,659 | 12,034 | 250 | 2,221 |
Control: OpenClaw's built-in runtime, same stand-in, same load. All 960 turns succeeded.
| Agents | Throughput, turns/s | Turn p50, ms | Turn p95, ms | Gateway CPU per turn, ms | Gateway memory peak, MB |
|---|---|---|---|---|---|
| 10 | 4.1 | 2,279 | 2,747 | 246 | 2,509 |
| 50 | 7.7 | 5,246 | 8,307 | 200 | 3,144 |
| 100 | 7.8 | 11,516 | 14,204 | 199 | 3,787 |
Reading the results.
- With the model taking 1.5 s, a turn through the Gateway takes about 1.7 s when the Gateway is idle. The Gateway adds about 0.2 s.
- From 25 agents up, throughput stops rising at about 8.7 turns per second and latency grows with the number of agents: turns queue.
- Gateway CPU per turn stays at about 250 ms whatever the load. Total CPU averaged about 2.2 cores at 100 agents, on a 20-thread machine.
- The control reaches the same ceiling. The limit is in the Gateway's per-turn path shared by both runtimes, not in nanocode. nanocode uses about 50 ms more CPU per turn than the built-in runtime.
- No main-thread stall was logged during any load run.
- Memory did not grow with the number of agents.
What this means for sizing.
- One Gateway's limit is a turn rate, not a session count.
- At about 8.7 turns per second, a Gateway can serve as many agents as that rate allows. Agents each starting a turn every 30 s come to about 260 at once.
- Real turns with tool calls cost more Gateway work per turn than this one-call stand-in turn, so expect fewer.
Where it trails, and what it cannot show.
- The stand-in turn has one model call and no tools. Real swarm turns are heavier.
- The first nanocode turn after a Gateway start took 7.3 s and 10 s of CPU, and the Gateway logged main-thread stalls of up to 3.9 s. That is a one-time load; it was not investigated further.
- The Gateway's stall log is not a full event-loop delay histogram. It recorded a 472 ms stall at startup, so it catches stalls of that size, but shorter delays may go unreported.
- The control ran in the same Gateway process after the nanocode runs, so its memory figures are not a clean comparison.
- Which step of the per-turn path runs one at a time is answered in Where a turn's CPU goes.
Capacity of nanocode alone
Question. Without the Gateway, how many nanocode sessions can one Node process carry?
Method.
bench/bare.mjsopens N nanocode sessions in one process. Each has its own in-memory database.- Every session runs three turns at once against an in-process stand-in that returns the recorded reply after 1.5 s.
- The script measures memory, CPU and the event loop's delay histogram.
- Each level ran three times. The table shows medians.
| Sessions | Turns | Completed | Open time, ms | Memory per idle session, MB | Peak memory, MB | CPU per turn, ms | Busy cores | Loop delay p99, ms | Loop delay max, ms |
|---|---|---|---|---|---|---|---|---|---|
| 100 | 300 | 300 | 583 | 13.0 | 1,539 | 5 | 0.27 | 6 | 399 |
| 250 | 750 | 750 | 1,428 | 12.6 | 3,641 | 4 | 0.56 | 7 | 864 |
| 500 | 1,500 | 1,500 | 2,869 | 12.5 | 7,127 | 4 | 0.86 | 7 | 1,542 |
The 1,000-session run stopped itself at 13.6 GB while opening sessions, past the 12 GB guard set to protect the shared machine.
Reading the results.
- nanocode costs 4 to 5 ms of CPU per turn and about 12.5 MB per open session.
- Memory, not CPU, is what limits nanocode alone.
- The longest loop delay grows with the number of sessions, up to 1.5 s at 500 sessions. Most turns see under 7 ms.
Where a turn's CPU goes
Question. Why does one Gateway stop near 8.7 turns per second while most of the machine is idle, and which of that work is waste?
Method.
- The Gateway ran under
node --cpu-prof, which writes one CPU profile per thread. - The same 50-agent load as above ran once (100 turns, all succeeded), after one warm-up session and 10 s of idle time.
bench/profile-summary.mjscuts every thread's profile to the load window and attributes the samples.- Request sizes were counted with the stand-in's
REQUEST_LOG, one two-turn session per runtime.
The profiler slows the Gateway: CPU per turn was 373 ms with it against 250 ms without. The shares below hold; the absolute milliseconds are about 1.5 times too high.
Where the time goes, per turn, profiled.
| Thread | Busy, ms per turn | What it is |
|---|---|---|
| Main thread | 126.5 | Everything below; busy 90% to 99% of each second during the load |
| Agent execution worker | 82.6 | 56.6 ms of it waiting for the main thread to admit each SQLite write (Atomics.wait); about 26 ms of real work |
| Other workers (transcript, state reads, others) | 29.4 | Spread over 17 threads |
| All threads | 238.5 |
| Main thread work | ms per turn | Share |
|---|---|---|
| nanocode engine (WebAssembly) | 17.7 | 14% |
| nanocode SQLite layer | 8.4 | 7% |
| nanocode module instantiation, per turn | 3.9 | 3% |
| Garbage collection | 9.4 | 7% |
| Gateway turn work, about 30 steps of 2 to 7 ms each | about 87 | 69% |
The largest Gateway steps, inclusive: session-row projection and reads (about 4 ms), model-runtime catalog publication (3.6 ms), tool construction (3.6 ms), SQLite post-commit state publication (2.9 ms), plugin tool resolution (2.2 ms), model visibility policy (2.1 ms).
Counts.
| Per model request | nanocode runtime | Built-in runtime | nanocode alone |
|---|---|---|---|
| Request size, KB | 154 | 74 | 19 |
| Tool definitions sent | 57 | 14 | 0 |
| Tool definitions, KB | 134.5 | 17.4 | 0 |
| Per turn, nanocode runtime | Count |
|---|---|
| nanocode sessions opened and closed | 1 |
| WebAssembly runtimes instantiated | 1 |
Reading the results.
- What runs one turn at a time is the main thread. It is saturated, so turns and the SQLite writes that wait on it queue together. The other 19 threads have room.
- nanocode's share of the main thread, about 30 ms per turn profiled, is six times what nanocode costs alone. Two causes are in this plugin, and both are avoidable.
- The rest is the Gateway's own turn work. No single step dominates, so no one deletion lifts the ceiling.
Findings and fixes.
| Finding | Where | Fix | Cost |
|---|---|---|---|
Every request carries all 57 tool definitions, 134.5 KB, about 87% of the request. The built-in runtime sends 14 and reaches the rest through tool_search, tool_describe and dispatch_action. With a real model that is roughly 29,000 more input tokens per call (estimated at 4 bytes per token). |
extensions/nanocode/src/tools.ts, includeToolSearchControls: false |
Fixed: tool search on, as the built-in runtime does. See Tool search. | Done |
| Every turn reopens the nanocode session: a new WebAssembly runtime, a new SQLite connection, then a close that checkpoints the log. About 11 ms of main-thread time per turn, profiled. | openNanocodeSession in extensions/nanocode/src/runtime.ts, called per turn by harness.ts |
Fixed: sessions stay open between turns and close when idle. See Sessions kept open. | Done; open sessions measured 16 to 21 MB each |
nanocode sessions do not get the agent's workspace instructions (AGENTS.md, SOUL.md, persona). Requests carry only nanocode's own instructions, 19 KB, the same as nanocode alone. |
extensions/nanocode/harness.ts passes only extraSystemPrompt |
Fixed: instructions built through the prompt hooks, as on the Copilot runtime. See Agent instructions. | Done |
| The Gateway's own turn work saturates its main thread near 8.7 turns per second. | OpenClaw core, about 30 steps | No single deletion. For more turns per second now, run more Gateway processes per machine; lifting the per-process ceiling is work for the core's owners | Each Gateway uses about 2.2 GB and one main-thread core |
What it cannot show.
- One profiled run, not repeated runs.
- The stand-in turn has one model call and no tool calls.
- The Gateway steps were read from the profile; they were not counted one by one.
Tool search
Question. With tool search on, does a nanocode session still reach every tool it is allowed, and what does it save?
Method.
- The tool surface now uses the host's tool-search runtime. Rarely needed
tools move into a catalog; the model reaches them through
tool_search,tool_describeanddispatch_action, as on the built-in runtime. - One two-turn session counted request sizes with the stand-in's
REQUEST_LOG. - One real turn on Nemotron asked for a tool that is no longer sent directly.
- The capacity levels above were run again, three runs per level.
Defect found. nanocode refused every session once tool search was on:
the tool name tool_search is reserved by nanocode's Code Mode host, even
with Code Mode off. Of the names tried, only tool_search is reserved. The
plugin now offers it to the model as openclaw_tool_search, rewrites that
name in the tool descriptions and the tool directory it sends, and maps calls
back, so policy, hooks and the transcript see tool_search.
Counts, per model request.
| Before | After | |
|---|---|---|
| Request size, KB | 154 | 25 |
| Tool definitions sent | 57 | 8 |
| Tool definitions, KB | 134.5 | 12.8 |
End to end on Nemotron. Asked to list sessions with tool search, the
model searched, picked the sessions tool and sent it arguments it rejects,
received that error as text, searched again, dispatched sessions_list with
{"limit": 5}, and answered with the Gateway's real session keys. The
transcript records each call as tool_search or dispatch_action.
Capacity, before and after. All 1,110 turns succeeded. Medians of three runs.
| Agents | Throughput, turns/s | Turn p50, ms | Turn p95, ms | Gateway CPU per turn, ms |
|---|---|---|---|---|
| 10 | 4.4 → 4.7 | 2,029 → 1,930 | 2,521 → 2,410 | 271 → 251 |
| 25 | 7.5 → 7.9 | 2,738 → 2,542 | 3,756 → 3,617 | 252 → 237 |
| 50 | 8.1 → 8.8 | 5,265 → 4,791 | 6,813 → 6,498 | 250 → 229 |
| 100 | 8.7 → 8.7 | 10,659 → 10,617 | 12,034 → 11,844 | 250 → 251 |
Reading the results.
- Requests are 84% smaller. With a real model that is roughly 32,000 fewer input tokens per call (estimated at 4 bytes per token), which the stand-in does not charge for.
- Gateway CPU and throughput improved by up to 9% and did not get worse. The ceiling stays near 8.7 turns per second, as the profile predicts: tool definitions were part of nanocode's share, not the Gateway's.
What it cannot show.
- The before and after runs ran one after the other on the same day, not interleaved.
- One end-to-end turn; the model needed two searches to find the right tool.
Agent instructions
Question. Does a nanocode session now follow the agent's own workspace files, and what does that cost?
Method.
- The harness builds the agent's developer instructions through the SDK's
prompt path (
resolveAgentHarnessBeforePromptBuildResult), as the Copilot runtime does:- an identity line;
- the tool directory and the guidance for each callable tool;
- delegation guidance;
- guidance on visible replies;
- credential safety;
- the workspace files OpenClaw selects for the run;
- the conversation context.
- Plugins'
before_prompt_buildand turn-context hooks now apply to nanocode turns: they can add context to the prompt, replace the instructions, or narrow the turn's tools. The tools are chosen after the hooks run. AGENTS.mdis included, because nanocode does not read the agent's workspace itself.- For the proof, two markers were appended to the test agent's workspace: a
codename in
AGENTS.md, and a rule inSOUL.mdto end every reply with one word. They were removed afterwards. - Request size was counted with
REQUEST_LOG; the capacity levels were run again.
End to end on Nemotron. Asked for the project codename, the agent
answered with the codename from AGENTS.md and ended with the word SOUL.md
asked for. The model had no other source for either.
Counts, per model request.
| Tool search only | With instructions | |
|---|---|---|
| Request size, KB | 25 | 40 |
| Tool definitions sent | 8 | 8 |
The built-in runtime's request for the same agent is 74 KB.
Capacity, before and after. All 1,110 turns succeeded. Medians of three runs.
| Agents | Throughput, turns/s | Turn p50, ms | Turn p95, ms | Gateway CPU per turn, ms |
|---|---|---|---|---|
| 10 | 4.7 → 4.5 | 1,930 → 1,995 | 2,410 → 2,545 | 251 → 266 |
| 25 | 7.9 → 7.8 | 2,542 → 2,528 | 3,617 → 3,727 | 237 → 240 |
| 50 | 8.8 → 8.6 | 4,791 → 4,917 | 6,498 → 6,631 | 229 → 237 |
| 100 | 8.7 → 9.2 | 10,617 → 9,994 | 11,844 → 11,495 | 251 → 233 |
Reading the results. Every cell moved by 6% or less, in both directions. Loading the workspace files and running the prompt hooks each turn does not change the Gateway's ceiling.
What it cannot show.
- No plugin on the test Gateway narrows tools or replaces instructions, so those hook paths ran without a hook acting on them.
- The
llm_inputhook, which reports what was sent to the model, is not called for nanocode turns yet. - One end-to-end turn.
Sessions kept open
Question. Does keeping each session's nanocode runtime open between turns, as nanocode runs sessions on its own hosts, remove the per-turn reopen, and what does it cost?
Acceptance rule, set before the runs.
- Workload: the stand-in model, 50 and 100 agents, four turns per session. With two turns, half the turns would be first opens either way.
- Order: the current code (A) and keep-open (B) alternate, three pairs per level, each on a freshly restarted Gateway after one warm-up session.
- Win: nanocode database opens fall from one per turn to one per session, and Gateway CPU per turn falls.
- Stop: any user-facing metric 20% worse.
Method.
- Each session keeps one open runtime. A turn binds its own model dispatch (with its credential), Gateway tool executor and event sink to it, and unbinds them when it ends.
- A session is reused only when its model route, agent directory, instructions and tool definitions are unchanged; otherwise it reopens from its database.
- A failed or aborted turn closes the session; the next turn reopens it.
- Idle sessions close after 5 minutes. At most 256 idle sessions stay open, the least recently used closing first; sessions in use by running turns come on top. Reset and Gateway shutdown close them.
bench/keep-open-ab.shruns the comparison. Database opens were counted withstraceand sessions held open withlsof, in a separate run of 10 agents with four turns, so the tracing does not affect the timed runs.- Unit tests in
src/resident.test.tscover reuse by key, the idle close, the cap, waiting for a close in progress, and closing on shutdown.
Counts, 10 agents with four turns.
| A, reopen every turn | B, keep open | |
|---|---|---|
| nanocode database opens | 40 | 10 |
| Sessions held open after the run | 0 | 11 |
The 11th open session in B is the warm-up session.
Timed runs. All 3,600 turns succeeded. Medians of three runs; the runs within each cell agreed within a few milliseconds of CPU per turn.
| Agents | Variant | Throughput, turns/s | Turn p50, ms | Turn p95, ms | Gateway CPU per turn, ms | Gateway memory peak, MB |
|---|---|---|---|---|---|---|
| 50 | A | 8.7 | 5,222 | 6,805 | 245 | 2,603 |
| 50 | B | 10.5 | 3,993 | 6,618 | 172 | 3,406 |
| 100 | A | 9.1 | 10,370 | 11,573 | 240 | 2,574 |
| 100 | B | 11.0 | 7,952 | 11,450 | 164 | 4,692 |
End to end on Nemotron. In one kept-open session the agent was told a number in the first turn and gave it back in the second, and the Gateway still held that session's database open afterwards.
Reading the results.
- Opens fell to one per session, as intended.
- Gateway CPU per turn fell by 30% to 32%, throughput rose by 20% to 21%, and the median turn got 23% to 24% faster. The gain is larger than the profile's estimate for the main thread alone (about 11 ms per turn): closing a session also cost work on other threads.
- Memory is the cost, and it is higher than the profile's estimate. 51 open sessions added 0.8 GB and 101 added 2.1 GB: 16 to 21 MB per open session. At the cap of 256 idle sessions, they hold about 5.4 GB; sessions in use by running turns come on top.
- Memory is the one metric that got worse, by design. Every other metric improved.
What it cannot show.
- The idle close and the cap were proven in the unit tests only; no Gateway run waited 5 minutes or opened 256 sessions.
- The stand-in turn has one model call and no tool calls.
What a session's memory is
Question. What makes up the 16 to 21 MB an open session holds, and does it grow as the conversation goes on?
Method.
bench/session-memory.mjsopens 40 sessions the way the plugin does: a file database per session, the in-process shell over it, the workspace tools.- It runs turns against an in-process stand-in that returns the recorded reply
at once, and reads the process memory, nanocode's own WebAssembly memory
(
memoryBytes) and the JavaScript heap, per session. - Three runs on the test machine (Node 24.22.1); the runs agreed within 0.1 MB.
Results, per open session, median of three runs.
| Stage | Process memory, MB | WebAssembly engine memory, MB | JavaScript heap, MB |
|---|---|---|---|
| Opened, no turn yet | 12.5 | 12.2 | 1.1 |
| After 1 turn | 14.6 | 13.3 | 1.5 |
| After 4 turns | 15.1 | 13.3 | 1.5 |
Reading the results.
- About 80% to 90% of a session is nanocode's WebAssembly engine memory. The engine reserves 12.2 MB when the runtime starts, grows by about 1 MB on the first turn, then stays flat.
- The JavaScript side holds about 1.5 MB; the rest is the database and the shell.
- Memory does not grow with the conversation over these turns: the history lives in the session's database, not in memory.
- Through the Gateway the same sessions measured 16 to 21 MB: the Gateway path adds the session's tool definitions and instructions and Gateway-side state. That split was not measured.
- Ways to use less, none tried yet: close idle sessions sooner (the idle time is 5 minutes); host more than one session in one WebAssembly instance, which nanocode's per-scope API may allow; or a smaller initial engine memory in nanocode itself.
What it cannot show.
- Four turns per session, with one short reply each; long conversations and large workspace files were not measured.
Swarm engine on Gateway sessions
Question. Can an unmodified swarm engine run its orchestrator and workers as OpenClaw Gateway sessions, through the plugin's agent API?
Method.
- The engine is the swarms tree engine (
phaethonp/swarm-engineersatee68e69, no local changes), run on the test machine. ItsGATEWAY_URLpoints at a loopback stand-in for its hosted gateway,bench/swarm/plumbing.mjs:- agent calls (
/v1/agents…) go to the Gateway's/nanocode/v1/agentswith the Gateway token. The engine asks for Claude Fable 5.2; the stand-in drops the model, so agents run on the Gateway's Nemotron. - money calls answer from one $20 test deposit per test swarm. No money exists.
- git calls are served by
bench/swarm/git.mjsfrom bare repositories on disk: create, commit, list, and a read-only clone throughgit http-backend. - Every other call answers 501 and is recorded, so the log shows where the engine stops.
- agent calls (
- Every call is recorded, one JSON line each. No compute is offered: agents reason and answer, and no agent-written code runs on the machine.
- Worker transcripts were read with
bench/swarm/worker-view.sh. - Three test swarms ran on one goal, "Prove that the sum of the first n odd numbers is n squared", each after the defects found in the one before had been fixed.
Direct checks of the agent API, through the Gateway with Nemotron.
| Question | Test | Result | Evidence |
|---|---|---|---|
| Does a worker answer in the shape asked for? | Spawn with an output schema: "Is 17 a prime number?" | Pass | Output {"prime": true} in the worker listing |
| Does a closed worker keep its output? | Close the finished worker, list again | Pass | State closed, output still {"prime": true} |
| Does a Gateway restart keep agents and outputs? | Restart the Gateway, list again | Pass | Same agent id answers; output still {"prime": true} (bench/swarm/persist-proof.sh) |
| Is an agent private to its app? | List with another gateway-app |
Pass | 404 |
| Is the API closed without the token? | Call with no token | Pass | 401 |
| Does the engine's repository work? | Engine creates proofs and commits its Lean seed; clone it |
Pass | Commit 9785519 "Lean project: pinned toolchain and Mathlib…"; clone has it |
| Is the clone read-only? | Push to the clone URL | Pass | 403 |
The engine's run, third test swarm, 06:10 to 06:20 UTC.
| Step | What happened |
|---|---|
| Funding and repository | Test deposit credited; proofs created and seeded |
| Orchestrators | Two created in the same millisecond; the engine used both |
| Root, run 1 | Worker answered progress: it meant to explore the repository |
| Root, run 2 | Worker answered split into four lemmas: the sum's definition, base case, inductive step, main theorem |
| Lemma statements | The engine committed four statement files to proofs |
| First lemma, runs 1 to 12 | Eleven answers of progress ("exploring the repository"), then stuck: it could not read its statement file |
| After | No run in flight; the engine stopped scheduling the lemma, as it does after twelve runs without progress |
Each worker took about 20 seconds. All 14 workers' outputs reached the engine after it closed them. The engine's only spending was its git charges ($1.025).
Reading the results.
- The connection works: the engine created agents, ran turns, spawned and closed workers, read their outputs, split the goal into lemmas and committed their statements, all through Gateway sessions.
- Nothing can be proved yet. The engine expects a worker to read the repository and commit its proof to a branch; these workers have no tools, so they can only describe the work. Workers need repository tools (read a file, commit to a branch) before a node can be proved.
Defects found.
| Defect | How it showed | Cause | Fix |
|---|---|---|---|
| Every worker session refused | "nanocode cannot enforce this conversation's tool policy" | Subagent runs carry a restricted tool policy, which the runtime did not declare | Declare exact policy support; leave nanocode's shell and files out of restricted runs |
| One worker started six more sessions | Seven sessions running for one spawn | Workers had the Gateway's tools, and the model called sessions_spawn |
Worker runs get no tools |
| Closing a worker failed | Close answered with an error | The plugin stopped runs through a Gateway call reserved for trusted plugins | Stop runs with chat.abort through the plugin's dispatch contract |
| The engine lost its orchestrator | After a Gateway restart, every call for the agent answered 404, for good | Agents and workers were held in memory; the engine keeps an agent id for 200 runs | Keep agents and workers in the plugin's state |
| Worker answers never reached the engine | The root node stayed proposed; the engine recorded three empty results | The engine closes a finished worker before reading it; a closed worker had no output, and a restart reported finished runs as interrupted | Record a worker's result once its run finishes |
The first test swarm lost its orchestrator to the fourth defect, and the second lost its root node to the fifth: the engine stops running a node after three stuck results. Each was left as it was, and the next swarm started fresh.
What it cannot show.
- No compute: the engine's Lean verifier was not run, so no proof was checked.
- The clone URL is on loopback. The engine's verifier, which builds proofs on hosted machines, cannot reach it.
spent_usdis always 0, so the engine's money view shows only its own git charges. The engine also marks a run stalled when spending does not move for 30 minutes; no run lasted that long here.- The engine created two orchestrator agents for one swarm in a race. Both answered, so the run was not affected.
- Event streams are not served, so the run page's live progress line stays empty; the engine polls instead.
Swarm worker repository tools
Question. Can a swarm worker on a Gateway session read its swarm's repository and commit its work to a branch, with no other tool?
Method.
- The plugin registers three optional tools,
git_files,git_readandgit_commit(worker repository tools). They call the git API of the gateway that created the worker's agent, as its app. - The stand-in (
bench/swarm/plumbing.mjs) names itself as that gateway when it forwardsPOST /v1/agents. Its git hosting (bench/swarm/git.mjs) gained the read API the engine itself uses (filesandread, swarmssrc/worker/Repo.ts), and a new branch now starts frommain's newest commit. - Same engine, goal and model as above. Two more test swarms, each with its
own $20 test deposit:
- the fourth ran the first design: the git tools added to the worker's normal tool surface, and a prompt hook narrowing its turn to them;
- the fifth ran the fix: the worker run gets exactly the git tools, through
the
plugin-subagent-exact-toolsentries inproduct/server/changes.json.
- A direct check: one worker spawned through the agent API and told to search
for
terminal,dashboard,sessions_spawn,exec,web_fetchandgit, then list every tool it found. - The tool calls each worker made were read from its transcript
(
chat.history).
The fourth test swarm, 12:24 to 12:27 UTC, first design.
| Step | What happened |
|---|---|
| Root, run 1 | Read Check.lean, listed the files, committed four times to node/root; answered split into two lemmas, naming its last commit (3078fd1) |
| Lemma statements | The engine committed both statements to main |
| Lemmas, run 1 each | Each worker read its statement, committed its proof to node/<nid> (two and three commits) and answered proved, naming the commit on its branch |
| Check | Not run (no compute); both lemmas stay proposed |
| A lemma worker's tools | 23 calls through dispatch_action, 1 tool_search. The search returned core tools such as dashboard; dispatch_action reached terminal, which refused only because the run lacked the owner's authority |
The fifth test swarm, 12:47 to 12:52 UTC, the fix.
| Step | What happened |
|---|---|
| Root, run 1 | Read the files, committed to node/root; answered proved for the root, which has no Lean statement to prove |
| Root, run 2 | Answered split into a base case and an inductive step, naming its last commit (6aff80c) |
| Lemma statements | The engine committed both statements to main |
| Base case, run 1 | Read its statement, committed Prove base case n=1 to its branch |
| Workers' tools | Triage: 1 git_files, 30 git_read. Root, run 2: 1 git_files, 3 git_read, 2 git_commit. No other tool was called |
Direct check of the surface, through the Gateway with Nemotron.
| Question | Test | Result | Evidence |
|---|---|---|---|
| Can a worker find any tool beyond the three? | tool_search for terminal, dashboard, sessions_spawn, exec, web_fetch, git |
Pass | Every query but git returned no candidates; git returned the three tools (worker-tool-surface-check.json) |
| What does the worker say it can call? | Its answer, in the requested schema | Pass | {"tools": ["git_files", "git_read", "git_commit"]} |
| Does the orchestrator stay without tools? | Unit test of the run requests | Pass | disableTools with no tools added (src/swarm-api.test.ts) |
Reading the results.
- Workers now do what the engine asks of a run without a machine: read the
frozen statement and the definitions, commit the proof and notes to
node/<nid>, and return the commit's sha. The engine's tree moved past the point where the third swarm stopped. - The first design was not safe. A worker's tools must be decided where the run starts, not by a hook that an operator setting can turn off.
Defects found.
| Defect | How it showed | Cause | Fix |
|---|---|---|---|
| Workers could reach every Gateway tool | A worker's tool search listed core tools; dispatch_action reached terminal |
The prompt hook that narrowed the turn was blocked: "non-bundled plugins must set plugins.entries.nanocode.hooks.allowConversationAccess=true". The run kept the whole normal surface | Worker runs ask for exactly their tools (disableTools with toolsAlsoAllow), which a product entry lets core honor; without the entry, core refuses the run |
| Two model picks at once: one answered 500 | POST …/turns answered 500: "Subagent registration owner changed during preparation" |
The engine sent two picks to the same orchestrator session in the same second | Not fixed. The engine fell back to its default model and started the worker, so the run went on |
What it cannot show.
- No compute: no claimed proof was checked. In the fourth swarm one lemma's
statement used
nwithout binding it, so it would not compile; the verifier would have refused that proof. - A worker can claim more than it did: the fifth swarm's first root run
answered
provedfor a node with no statement. Only the verifier settles a claim. - The git calls carry no key; the stand-in accepts them on loopback. A hosted git gateway that needs one is not served yet.
Reproduce it
The scripts are in extensions/nanocode/bench/. The raw results, one JSON line
per run, are in extensions/nanocode/bench/results/2026-11-25/:
| File | What it holds |
|---|---|
gateway-nanocode.jsonl |
Capacity runs on the nanocode runtime |
gateway-openclaw-control.jsonl |
Control runs on the built-in runtime |
bare-nanocode.jsonl |
Runs of nanocode alone |
profile-n50.txt |
Output of profile-summary.mjs for the profiled run |
request-sizes.jsonl |
Request sizes per runtime, with and without tool search |
gateway-nanocode-tool-search.jsonl |
Capacity runs with tool search on |
gateway-nanocode-instructions.jsonl |
Capacity runs with tool search and agent instructions |
keep-open-ab.jsonl |
Counting and timed runs of the keep-open comparison |
session-memory.jsonl |
Per-session memory breakdown, three runs |
swarm-engine-calls.jsonl |
Every gateway call the engine made for the third test swarm |
swarm-engine-watch.txt |
That swarm's workers, their outputs, and its node tree |
swarm-git-tools-calls.jsonl |
Every gateway call for the fourth test swarm (first design) |
swarm-exact-tools-calls.jsonl |
Every gateway call for the fifth test swarm (the fix) |
worker-tool-surface-check.json |
The surface check worker's transcript |
To repeat the Gateway runs:
Start a Gateway with its own state directory. Load the plugin from
extensions/nanocodeand enablegateway.http.endpoints.chatCompletions.Add a custom provider
standinwithbaseUrl: "http://127.0.0.1:18890/v1",api: "openai-responses",agentRuntime: { id: "nanocode" }and one modelnemotron-replay. For the control, add the same provider again asstandin-openclawwithagentRuntime: { id: "openclaw" }.Run
node extensions/nanocode/bench/standin.mjs.Run one warm-up turn, then each level:
GATEWAY_TOKEN_FILE=/path/to/token OPENCLAW_STATE_DIR=/path/to/state GW_PID=<gateway pid> N=50 TURNS=2 RUN=n50-r1 node extensions/nanocode/bench/load.mjsSet
MODEL=standin-openclaw/nemotron-replayfor the control.
To repeat the profile:
Start the Gateway with
NODE_OPTIONS="--cpu-prof --cpu-prof-dir=/path/to/prof".Run one warm-up turn, wait 10 s, run
N=50 TURNS=2, wait 5 s, then stop the Gateway withSIGTERMso every thread writes its profile.Find the load window in the main thread's profile (the busy seconds after the idle gap) and run:
node extensions/nanocode/bench/profile-summary.mjs /path/to/prof <main thread profile> <from s> <to s> 100
To repeat the keep-open comparison, put both variants of harness.ts and
src/runtime.ts under variants/A and variants/B in the Gateway's folder and
run ROOT=/path/to/gateway-dir bash extensions/nanocode/bench/keep-open-ab.sh.
To count request sizes, start the stand-in with
REQUEST_LOG=/path/to/requests.jsonl and run one session per runtime.
To repeat the memory breakdown, from extensions/nanocode:
N=40 node --expose-gc bench/session-memory.mjs /path/to/empty-scratch-dir
To repeat the swarm engine run:
- Start a Gateway with the plugin loaded and a model configured for the default agent.
- Put the Gateway token in
~/.gateway-tokenand runnode extensions/nanocode/bench/swarm/plumbing.mjs. It listens on127.0.0.1:8789; add a test deposit for your swarm's app intestDeposits. - Run the swarms engine with
GATEWAY_URL=http://127.0.0.1:8789, create a tree swarm, and contribute the test deposit's hash. - Read what happened with
bash extensions/nanocode/bench/swarm/swarm-watch.sh <swarm id>, and a worker's transcript withworker-view.sh <agent id>. The scripts expect the Gateway folder at/opt/nanocode-gw; edit the paths for another layout.
To repeat the worker tools run, build the Gateway with pnpm build, which
applies product/server/changes.json, then follow the steps above with a new
swarm. The stand-in names itself as the git host of every agent it creates.
To check that a worker's output survives close and a restart, run
bash extensions/nanocode/bench/swarm/persist-proof.sh on the Gateway host.
To repeat the runs of nanocode alone, from extensions/nanocode:
N=250 TURNS=3 MODEL_MS=1500 node --expose-gc bench/bare.mjs
Related
- nanocode agent runtime
- Agent runtimes