Repository navigation
perf(cli): speed up gateway call cold starts - #166722
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 4:34 PM ET / 20:34 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherGateway 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -8, Tests +2, Other -1. Total -7 across 10 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
* 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.
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.
What Problem This Solves
openclaw gateway callspends 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.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
f18627321459and runtime change atbbd27f28d4ce(before nonfunctional gate corrections), rebuilt withnode --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 fullpnpm buildruns also passed on the rig before the conflict-free rebase (6m01s / 6m04s).Validation used AWS Crabbox after Testbox
tbx_01m4bt5fer85kq5pbys65028r7remained queued for 15 minutes; it was stopped. Initial AWS leasecbx_24cc60eb026bran the original focused suites successfully and was stopped before the rebase. Final proof usedcbx_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 passednode 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 as87f2a98ff46b; the merged tree was verified against the reviewed head and landing parent. No inherited-failure exception was needed.