Skip to content

perf(cli): speed up gateway call cold starts - #166722

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-cli-import-graph-20260919
Oct 7, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-cli-import-graph-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw gateway call spends cold-start time loading dependency features that an ordinary RPC never uses. Follow-up to #166657.

User Impact

One-shot Gateway calls start about 11% faster in the measured case. Credential selection, method authorization, validation errors, proxy policy, and secure temporary-directory checks are unchanged.

Why This Change Was Made

Protocol validators now use TypeBox's schema compiler. It uses the same check/error engine without loading unused value conversion, codecs, parsing, or defaulting. Managed proxy installation shares the existing synchronous lazy Proxyline loader, and temporary-root resolution uses fs-safe's focused public export. The temp-root loader also consumes the guaranteed Node module API directly instead of probing its members.

Production TypeScript LOC: −8. The full non-test diff is −9 lines, including the generated shrink-only assertion ledger. The old loader, detached built-in method alias, and redundant API probes are removed; no parallel policy, cache, or configuration option is added.

Evidence

Same Linux rig, Node 26.8.1, shipped openclaw.mjs gateway call health --url <loopback fixture> --token <synthetic token> --json, compile cache disabled. Two warmups followed by 12 fresh processes per version; every invocation returned the expected payload and exited successfully. CPU profiles and module-resolution tracing were collected separately from timings.

Measurement Before After
Median process time 847.3 ms 753.1 ms
p90 process time 867.4 ms 768.3 ms
Resolved modules in built CLI trace 1,942 1,676
TypeBox modules 680 535
Undici modules 108 0

Median improves 11.1%, p90 11.4%, with no overlap between the measured sample ranges (baseline 822.3–892.2 ms; candidate 746.7–802.5 ms). The 30% reduction and sub-500 ms stretch targets were missed. Remaining parsing cost includes the TypeBox schema-building graph and filesystem/state dependencies; this change preserves their synchronous contracts.

The final pair uses exact parent f18627321459 and runtime change at bbd27f28d4ce (before nonfunctional gate corrections), rebuilt with node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup. Medians use the average of the two middle samples. Both CLI startup builds and import guards passed. Earlier full pnpm build runs also passed on the rig before the conflict-free rebase (6m01s / 6m04s).

Validation used AWS Crabbox after Testbox tbx_01m4bt5fer85kq5pbys65028r7 remained queued for 15 minutes; it was stopped. Initial AWS lease cbx_24cc60eb026b ran the original focused suites successfully and was stopped before the rebase. Final proof used cbx_addca987a59d:

  • node scripts/check-changed.mjs: passed the full production change gate, including production and all core-test typechecking, lint, unused exports, import cycles, and policy guards. The subsequently retargeted Gateway-client mock passed node scripts/check-changed.mjs -- src/gateway/client.test.ts.
  • node scripts/run-vitest.mjs packages/gateway-protocol/src src/infra/net src/infra/tmp-openclaw-dir.test.ts src/gateway/call.test.ts src/gateway/client.test.ts src/gateway/client.device-auth.test.ts src/gateway/client.ssh.test.ts: 1,583 tests / 112 files passed, 73.45 s wrapper wall time.
  • node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mts: passed.
  • node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts test/scripts/check-cli-bootstrap-imports.test.ts: 76 tests passed, 27.43 s wrapper wall time.
  • pnpm test src/infra/net/proxy/proxy-lifecycle.test.ts --maxWorkers=1: 33 tests passed, 3.03 s wall time.
  • pnpm test src/gateway/client.test.ts --maxWorkers=1: 98 tests passed, 25.01 s wall time; most time was transformation, approximately 0.4 s was test execution. Hosted CI reported 0.464 s across these 98 cases (Bun); the lifecycle file reported 0.091 s across 33 cases. These are sums of reported case execution time and exclude transformation/runner setup.

Final successful run: run_3d7e60e8c2b8e2d89530f0c6e902541f. Earlier gate failures led to correctly placed assertion documentation, a regenerated shrink-only assertion ledger, preserved mock exports, and a bound built-in call. Two Gateway-client tests still targeted the old package mock; their mock moved to the shared lazy boundary with assertions unchanged. The existing oversized Gateway-client test emits an advisory +1-line size warning; no suppression or coverage was removed.

Independent review passed with no actionable P0–P2 findings. There are no production schema, user configuration, dependency-version, or authorization changes.

Hosted CI run 37682200012 passed on 194203f5caf4: 73 successful jobs, 21 intentionally skipped. Merged as 87f2a98ff46b; the merged tree was verified against the reviewed head and landing parent. No inherited-failure exception was needed.

Use the shared schema compiler without value conversion machinery, load Proxyline only when installing routing, and resolve secure temp roots through the focused filesystem export. Preserve synchronous proxy, validation, and temp-root contracts.
Preserve original exports when mocking the shared loader, keep the Node builtin lookup bound, and regenerate the shrink-only assertion ledger.
@clawsweeper

clawsweeper Bot commented Oct 7, 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 app: web-ui App: web-ui gateway Gateway runtime size: S labels Oct 7, 2026
@steipete
steipete marked this pull request as ready for review October 7, 2026 20:27
@steipete
steipete enabled auto-merge (squash) October 7, 2026 20:31
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 4:34 PM ET / 20:34 UTC.

ClawSweeper review

What this changes

The PR reduces Gateway CLI startup imports by using TypeBox’s focused schema compiler, sharing lazy proxy loading, and loading the secure temporary-directory resolver directly.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a useful, distinct follow-up to the merged startup optimization. No actionable introduced defect or unresolved product choice was found.

Priority: P2
Reviewed head: 194203f5caf4e901ea6ebc7b94ee4be9026f6917

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with meaningful runtime measurements and no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Linux built-CLI runs exercise the changed startup import path through gateway call health and record correct RPC payloads with improved timings; focused tests supplement validation and proxy coverage. The final corrections retain that measured path. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Linux built-CLI runs exercise the changed startup import path through gateway call health and record correct RPC payloads with improved timings; focused tests supplement validation and proxy coverage. The final corrections retain that measured path. No stored-data contract changes require migration proof.
Evidence reviewed 8 items Pinned introduced change: Read the complete merge-base-to-head patch. The changes preserve validation prechecks, proxy installation options and lifecycle decisions, and temporary-root options; test changes retarget existing mocks without removing assertions.
Pinned compiler contract: Inspected the published typebox 1.3.34 tarball and verified repository metadata. Both compiler implementations use Build(...).Evaluate() for Check. The old value Errors implementation extracts the same second tuple element now selected directly by the patch. Source inspected: build/schema/compile.mjs, build/schema/errors.mjs, build/compile/validator.mjs, and build/value/errors/errors.mjs.
Focused export preserves filesystem owner: Published fs-safe 0.24.2 metadata verifies repository ownership and maps ./secure-temp-root to dist/secure-temp-dir.js. The existing ./temp barrel reexports resolveSecureTempRoot from that exact module, so the new import retains the security and repair implementation.
Findings None None.
Security None None.

How this fits together

Gateway CLI calls load connection and validation helpers before sending an RPC to a running Gateway. These shared helpers also preserve proxy routing and secure temporary-directory selection.

flowchart TD
  A[Gateway CLI call] --> B[Connection preparation]
  B --> C[Protocol validation]
  B --> D{Managed proxy active?}
  D -->|Yes| E[Load proxy runtime]
  D -->|No| F[Gateway RPC]
  E --> F
  B --> G[Secure temporary root]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -8, Tests +2, Other -1. Total -7 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 28 36 -8
Tests 2 6 4 +2
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 3 -1
Total 10 36 43 -7

Review metrics

Metric Value Why it matters
Measured CLI startup Median 847.3 → 753.1 ms; 11.1% faster The recorded same-rig built-CLI comparison demonstrates a concrete improvement while acknowledging the remaining startup cost.

Technical review

Best possible solution:

Retain one validation, proxy, and filesystem-policy owner while loading only the dependency features each CLI invocation needs.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a bug reproduction; the captured before/after built-CLI measurements provide a concrete performance comparison, which this read-only review did not rerun.

Is this the best way to solve the issue?

Yes: the focused dependency exports and shared synchronous loader reduce unused imports while preserving the existing policy owners and public contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 83a95401fb8a.

Labels

Label changes:

  • add P2: This bounded performance improvement reduces latency for ordinary one-shot Gateway calls without an urgent user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux built-CLI runs exercise the changed startup import path through gateway call health and record correct RPC payloads with improved timings; focused tests supplement validation and proxy coverage. The final corrections retain that measured path. No stored-data contract changes require migration proof.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This bounded performance improvement reduces latency for ordinary one-shot Gateway calls without an urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux built-CLI runs exercise the changed startup import path through gateway call health and record correct RPC payloads with improved timings; focused tests supplement validation and proxy coverage. The final corrections retain that measured path. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced change: Read the complete merge-base-to-head patch. The changes preserve validation prechecks, proxy installation options and lifecycle decisions, and temporary-root options; test changes retarget existing mocks without removing assertions. (packages/gateway-protocol/src/protocol-validator.ts:37, 194203f5caf4)
  • Pinned compiler contract: Inspected the published typebox 1.3.34 tarball and verified repository metadata. Both compiler implementations use Build(...).Evaluate() for Check. The old value Errors implementation extracts the same second tuple element now selected directly by the patch. Source inspected: build/schema/compile.mjs, build/schema/errors.mjs, build/compile/validator.mjs, and build/value/errors/errors.mjs.
  • Focused export preserves filesystem owner: Published fs-safe 0.24.2 metadata verifies repository ownership and maps ./secure-temp-root to dist/secure-temp-dir.js. The existing ./temp barrel reexports resolveSecureTempRoot from that exact module, so the new import retains the security and repair implementation.
  • Proxy dependency contract: Published proxyline 0.3.12 metadata verifies repository ownership and a single default root export, with no separate require implementation. Inspected its root and runtime code; the shared loader consumes the existing synchronous package contract. (46a8aa2e3c4b)
  • Existing proxy patch retained: The existing pinned dependency patch exports the Node proxy agent from Proxyline’s public root. This PR neither changes that patch nor adds dependency versions, installation hooks, permissions, or configuration surface. (patches/@[email protected]:1, 194203f5caf4)
  • Real CLI performance evidence: The captured PR body records built openclaw.mjs gateway call health executions against a synthetic loopback RPC fixture on Linux with Node 26.8.1 and compile cache disabled. Twelve fresh processes per version returned expected payloads successfully: median 847.3 to 753.1 ms and p90 867.4 to 768.3 ms. Runtime measurement identifies parent f186273 and candidate bbd27f2; final-head test/mock corrections have supplemental validation. Captured context identity: b68030e9580f923604953b801be268c36545174f8dfb9b561c39748c9c9ada9a. (bbd27f28d4ce)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 87f2a98 into main Oct 7, 2026
219 of 220 checks passed
@steipete
steipete deleted the steipete/perf-micro-cli-import-graph-20260919 branch October 7, 2026 20:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
* perf(cli): trim unused gateway call imports

Use the shared schema compiler without value conversion machinery, load Proxyline only when installing routing, and resolve secure temp roots through the focused filesystem export. Preserve synchronous proxy, validation, and temp-root contracts.

* test(cli): align proxy fixtures with lazy loading

Preserve original exports when mocking the shared loader, keep the Node builtin lookup bound, and regenerate the shrink-only assertion ledger.
RomneyDa pushed a commit that referenced this pull request Oct 8, 2026
Backport main's lighter CLI imports, schema/proxy/temp-root boundaries, and
reader identity normalization to the October release. Preserve the release
Gateway request executor and strict malformed-PID cleanup behavior.

Backport of #166657, #166722, and #167024 to release/2026.10.1.

(cherry picked from commit 7875352)
(cherry picked from commit 87f2a98)
(cherry picked from commit a066127)

Proof: 715 focused/sibling tests pass; one optional socat skip. The equivalent
root regression fails against the original worker. Fresh P0-P2 review clean.
No dependency, version, schema, permission, or performance-budget changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant