Skip to content

perf(cli): stop respawning the CLI to hide a warning Node no longer emits - #206448

Merged
obviyus merged 2 commits into
mainfrom
perf/cold-first-request
Nov 27, 2026
Merged

obviyus merged 2 commits into
mainfrom
perf/cold-first-request

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

Every POSIX CLI call (including the one-shot openclaw agent --local turn that benchmark boards run) started Node twice. buildCliRespawnPlan re-executed the CLI only to add --disable-warning=ExperimentalWarning, a flag added for the node:sqlite experimental warning (165841a, 2026-01-13). node:sqlite stopped emitting that warning in Node 24.15.0 (lib/sqlite.js has emitExperimentalWarning in v24.14.0 and none in v24.15.0, v24.16.0, v26.1.0), and engines requires Node >=24.16.0 <25 || >=26.1.0. The second Node boot is pure waste.

Change

  • Delete the warning-only respawn branch from src/entry.respawn.ts and its skip policy shouldSkipRespawnForArgv from src/cli/respawn-policy.ts.
  • Respawn stays for the two cases that need a fresh process: auto-discovered NODE_EXTRA_CA_CERTS (Linux version-manager Node) and the Windows stack size.
  • Tests: the respawn tests now assert that common commands run in process unless Node must reload its trust store. Tests that used the warning respawn as a vehicle now use a CA respawn, or run on Windows only (node-runtime-recovery startup-respawn cases: POSIX no longer respawns there).

Evidence

Acceptance rule (written before the run): cold openclaw agent --local one-shot turn, built dist, fresh scratch state per run, real OpenAI gpt-5.4-nano; metric = process start to provider.request.started (diagnostics timeline) and the CLI entry stage; ABAB with the base build, 8 samples each, same load band. Win = one fewer Node process per CLI call and a lower entry stage, no metric worse.

metric (ABAB n=8, load 15-21) base b0a6e8c this PR
Node processes per CLI call 2 1
node boot + entry wrapper, median 311 ms 154 ms
node boot + entry wrapper, p90 352 ms 174 ms
start -> first provider request, median 8769 ms 7440 ms
start -> first provider request, p90 9777 ms 9640 ms

The total is noisy at this load (shared host); the entry stage drop (-157 ms median) is the attributable part.

  • No warning: an OPENCLAW_NO_RESPAWN=1 agent --local turn on Node 24.22.1 printed no ExperimentalWarning. node -e "require('module').registerHooks(...); require('node:sqlite')" prints nothing.
  • Code Mode's worker passes its own execArgv with --experimental-vm-modules; explicit worker execArgv replaces the parent flags, so its warning was never suppressed by this respawn (checked with a minimal worker on and off the flag).
  • Tests: ocx test src/entry.respawn.test.ts src/cli/cli-utils.test.ts src/infra/update-managed-service-handoff-node.test.ts src/process/respawn-child-runner.test.ts src/cli/gateway-backed-exit.process.test.ts test/scripts/node-runtime-recovery.built-cli.e2e.test.ts and importers (github-exec-launch, run-main.cleanup, entry.respawn-diagnostics) pass locally.

Diff

Production: -58 lines, +3. Tests: net -76 lines.

…mits

- The startup respawn added --disable-warning=ExperimentalWarning for node:sqlite (165841a).
- node:sqlite has emitted no experimental warning since Node 24.15.0; engines require >=24.16.0.
- POSIX CLI commands now run in the first Node process; respawn remains for CA certificates and the Windows stack size.
@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: M labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. labels Nov 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 27, 2026
@obviyus
obviyus merged commit 71f9237 into main Nov 27, 2026
120 checks passed
@obviyus
obviyus deleted the perf/cold-first-request branch November 27, 2026 07:03
obviyus added a commit that referenced this pull request Nov 27, 2026
## Problem

Cold time-to-first-request of the one-shot `openclaw agent --local` turn (the path benchmark boards run) has no regression gate. A measured turn on `b0a6e8cd` took 6.05 s median to the first provider request (warm Gateway: 0.69 s). Most of it is fan-out: every Node process and worker thread boots its own module graph before the first request. Nothing stops a change from adding another one.

## Change

Add `src/cli/agent-local-cold-start.process.test.ts`: one real `agent --local` turn from source, run on Node (the default install's runtime, also when Vitest runs on Bun), against the local fake OpenAI Responses server (`test/helpers/openai-responses-model-fixture.ts`). A ledger preload, carried by `NODE_OPTIONS` into every descendant process that inherits the environment and into every worker thread, counts up to the moment the fake provider receives the first request:

- `nodeProcesses`: Node processes that started (CLI, respawns, inheriting children),
- `nodeSpawns`: Node spawn calls from any process or thread (covers children that start with a clean environment),
- `workerThreads`: worker threads constructed in any process or thread.

The test asserts ceilings `{ nodeProcesses: 4, nodeSpawns: 5, workerThreads: 19 }`, measured on the Linux CI runner (macOS starts 18 workers). Counts, not wall time: they do not move with host load. A PR that removes work lowers the budget in the same change.

The fixture keeps the default startup (`OPENCLAW_NO_RESPAWN` unset) and marks host CA discovery done (`OPENCLAW_NODE_EXTRA_CA_CERTS_READY=1`), because that respawn depends on the host's Node install. Windows is skipped: it always respawns for its stack size, so its topology differs by design.

## Evidence

- Red on the merge base before #206448 (`b0a6e8cd`, first version of this test): the warning-only respawn adds a CLI process. Green on main with #206448.
- Counts: Linux CI (Node CLI under the Bun Vitest lane) 4 / 5 / 19; macOS arm64 Node 24.22.1, 3 runs, 4 / 5 / 18 each.
- Review round 1 findings fixed: Windows topology (skipped, documented) and descendant work (ledger now propagates through `NODE_OPTIONS` and counts in every thread; process starts and spawn calls are separate counters).
- Cost: one CLI turn from source, about 16-31 s test time locally (88 s once under host load 40); same 120 s timeout as `agent-local-rpc-cleanup.process.test.ts`. No cheaper layer proves the processes and workers a real turn starts before its first request.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…mits (openclaw#206448)

## Problem

Every POSIX CLI call (including the one-shot `openclaw agent --local` turn that benchmark boards run) started Node twice. `buildCliRespawnPlan` re-executed the CLI only to add `--disable-warning=ExperimentalWarning`, a flag added for the `node:sqlite` experimental warning (1cfcc6a, 2026-01-13). `node:sqlite` stopped emitting that warning in Node 24.15.0 (`lib/sqlite.js` has `emitExperimentalWarning` in v24.14.0 and none in v24.15.0, v24.16.0, v26.1.0), and `engines` requires Node `>=24.16.0 <25 || >=26.1.0`. The second Node boot is pure waste.

## Change

- Delete the warning-only respawn branch from `src/entry.respawn.ts` and its skip policy `shouldSkipRespawnForArgv` from `src/cli/respawn-policy.ts`.
- Respawn stays for the two cases that need a fresh process: auto-discovered `NODE_EXTRA_CA_CERTS` (Linux version-manager Node) and the Windows stack size.
- Tests: the respawn tests now assert that common commands run in process unless Node must reload its trust store. Tests that used the warning respawn as a vehicle now use a CA respawn, or run on Windows only (`node-runtime-recovery` startup-respawn cases: POSIX no longer respawns there).

## Evidence

Acceptance rule (written before the run): cold `openclaw agent --local` one-shot turn, built `dist`, fresh scratch state per run, real OpenAI `gpt-5.4-nano`; metric = process start to `provider.request.started` (diagnostics timeline) and the CLI entry stage; ABAB with the base build, 8 samples each, same load band. Win = one fewer Node process per CLI call and a lower entry stage, no metric worse.

| metric (ABAB n=8, load 15-21) | base 69bb592 | this PR |
|---|---|---|
| Node processes per CLI call | 2 | 1 |
| node boot + entry wrapper, median | 311 ms | 154 ms |
| node boot + entry wrapper, p90 | 352 ms | 174 ms |
| start -> first provider request, median | 8769 ms | 7440 ms |
| start -> first provider request, p90 | 9777 ms | 9640 ms |

The total is noisy at this load (shared host); the entry stage drop (-157 ms median) is the attributable part.

- No warning: an `OPENCLAW_NO_RESPAWN=1` `agent --local` turn on Node 24.22.1 printed no `ExperimentalWarning`. `node -e "require('module').registerHooks(...); require('node:sqlite')"` prints nothing.
- Code Mode's worker passes its own `execArgv` with `--experimental-vm-modules`; explicit worker `execArgv` replaces the parent flags, so its warning was never suppressed by this respawn (checked with a minimal worker on and off the flag).
- Tests: `ocx test src/entry.respawn.test.ts src/cli/cli-utils.test.ts src/infra/update-managed-service-handoff-node.test.ts src/process/respawn-child-runner.test.ts src/cli/gateway-backed-exit.process.test.ts test/scripts/node-runtime-recovery.built-cli.e2e.test.ts` and importers (`github-exec-launch`, `run-main.cleanup`, `entry.respawn-diagnostics`) pass locally.

## Diff

Production: -58 lines, +3. Tests: net -76 lines.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…law#206466)

## Problem

Cold time-to-first-request of the one-shot `openclaw agent --local` turn (the path benchmark boards run) has no regression gate. A measured turn on `69bb5929` took 6.05 s median to the first provider request (warm Gateway: 0.69 s). Most of it is fan-out: every Node process and worker thread boots its own module graph before the first request. Nothing stops a change from adding another one.

## Change

Add `src/cli/agent-local-cold-start.process.test.ts`: one real `agent --local` turn from source, run on Node (the default install's runtime, also when Vitest runs on Bun), against the local fake OpenAI Responses server (`test/helpers/openai-responses-model-fixture.ts`). A ledger preload, carried by `NODE_OPTIONS` into every descendant process that inherits the environment and into every worker thread, counts up to the moment the fake provider receives the first request:

- `nodeProcesses`: Node processes that started (CLI, respawns, inheriting children),
- `nodeSpawns`: Node spawn calls from any process or thread (covers children that start with a clean environment),
- `workerThreads`: worker threads constructed in any process or thread.

The test asserts ceilings `{ nodeProcesses: 4, nodeSpawns: 5, workerThreads: 19 }`, measured on the Linux CI runner (macOS starts 18 workers). Counts, not wall time: they do not move with host load. A PR that removes work lowers the budget in the same change.

The fixture keeps the default startup (`OPENCLAW_NO_RESPAWN` unset) and marks host CA discovery done (`OPENCLAW_NODE_EXTRA_CA_CERTS_READY=1`), because that respawn depends on the host's Node install. Windows is skipped: it always respawns for its stack size, so its topology differs by design.

## Evidence

- Red on the merge base before openclaw#206448 (`69bb5929`, first version of this test): the warning-only respawn adds a CLI process. Green on main with openclaw#206448.
- Counts: Linux CI (Node CLI under the Bun Vitest lane) 4 / 5 / 19; macOS arm64 Node 24.22.1, 3 runs, 4 / 5 / 18 each.
- Review round 1 findings fixed: Windows topology (skipped, documented) and descendant work (ledger now propagates through `NODE_OPTIONS` and counts in every thread; process starts and spawn calls are separate counters).
- Cost: one CLI turn from source, about 16-31 s test time locally (88 s once under host load 40); same 120 s timeout as `agent-local-rpc-cleanup.process.test.ts`. No cheaper layer proves the processes and workers a real turn starts before its first request.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. cli CLI command changes impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant