Repository navigation
perf(gateway): streamline startup environment health reads - #184338
Conversation
Use the existing awaited snapshot owner for cold config-health reads, preserving source identity, recovery checks, and joined cleanup. Report process RSS and main-isolate heap on completed startup phases, and cover config backup reads in the Team-shaped startup fixture. Release-note context: reduce pre-bootstrap worker overhead during Gateway environment selection and make startup memory growth visible in phase logs.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR selects the existing awaited config-health reader and adds completion-time memory readings to startup logs. Example: A Gateway starts with an existing openclaw.json.bak.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes avoidable startup worker layers with a focused change; no actionable correctness or security defects were found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway environment selection reads persisted config-health facts through the shared-state reader; startup tracers report phase completion to CLI output and Gateway logs. flowchart TD
A[Gateway CLI startup] --> B[Environment selection]
B --> C[Config health owner]
C --> D[Shared state reader]
D --> E[Awaited snapshot preparation]
E --> F[SQLite health facts]
A --> G[Startup trace owner]
G --> H[Completion logs with memory]
Technical reviewBest possible solution: Use the existing awaited reader for cold health reads and the shared startup tracer for completion-time memory. Do we have a high-confidence way to reproduce the issue? Current main selects the default retained transport for cold health reads; source and the supplied baseline regression identify the unnecessary staging-owner capture, without executing target code during this review. Is this the best way to solve the issue? The smallest complete fix is the existing reader option plus shared completion-time formatting, preserving the health query, captured source, admission checks, and cleanup owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4d560fde03f9. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +47, Docs +6, Other +172. Total +238 across 9 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 3:34 AM ET / 07:34 UTC. |
…184338) Use the existing awaited snapshot owner for cold config-health reads, preserving source identity, recovery checks, and joined cleanup. Report process RSS and main-isolate heap on completed startup phases, and cover config backup reads in the Team-shaped startup fixture. Release-note context: reduce pre-bootstrap worker overhead during Gateway environment selection and make startup memory growth visible in phase logs.
What Problem This Solves
Gateway environment selection reads config-health state when a config backup exists. Its cold promise-only read unnecessarily starts retained native supervision and snapshot staging workers before bootstrap.
User Impact
Startup uses fewer worker layers, and every completed
startup phase:line reports processrssMband main-isolateheapUsedMbin MiB. These are completion-time readings, including buffered CLI output, rather than peak measurements. No config, schema, recovery-policy, or authorization changes are required.Why This Change Was Made
Select the existing awaited snapshot path already used by plugin metadata and restart-handoff reads. Config-health reads still use strict artifact-preserving copies, captured source identity, fresh admission, final authority checks, and joined cleanup. Existing retained readers remain reusable. Retrospective bootstrap trace replays omit current memory to avoid attributing it to an earlier phase.
Production runtime delta is +13 lines: the performance change replaces one argument line, while the requested shared memory formatter and completion-log integration account for the growth. The required non-test/non-doc diff is +185 lines, of which benchmark code adds 172 lines for reproducible cold/warm CPU and allocation measurements and backup-shaped boot coverage.
The
teamBootbenchmark now creates a matching.bak, exercising the health read that a backup-free fixture misses. Usage remains in the script header; the shared performance README is unchanged.Evidence
A real work-count regression fails on the baseline because the cold health read captures a snapshot staging owner once. The candidate captures none and returns the same stored health signature; subsequent committed changes remain visible. Memory regressions also fail on the baseline and verify completion-time sampling before buffered output.
Built Gateway boots
Five boots per arm, fresh synthetic fixtures per boot: 10,000 sessions, eight agents, 44 plugins, 130 MiB shared state, matching config backup, isolated loopback ports, and an 8 GiB Node heap limit. All ten reached readiness, served the seeded session RPC, and shut down cleanly.
The boots were sequential cohorts, with materially different host load: baseline 1-minute load 47.0–63.3; candidate 22.7–30.1. Treat these as observed results, not a controlled attribution of the full wall/CPU difference. Baseline build:
99501d269444, with phase-memory probes added for diagnosis (output formatting refined in the candidate). Separate traced full-startup allocation runs were 2,686.6 → 2,697.5 MiB (+0.4%, context only); traced timings are not compared.The first diagnostic boot without a backup spent 2.6 ms in config recovery; adding a backup raised that to 1,132.9 ms. Runtime-version probes were not the cause. The change removes worker layers from that existing read rather than bypassing the recovery check.
Owner measurements
config-health-read-measure.tsuses the real owner and artifact-preserving reader against the same synthetic state. Timing is AB then BA; allocation is BA then AB, in separate fresh processes, with collected-object sampling. Two cold reads and 6,000 warm reads per arm in each measurement mode. All snapshots have identical fingerprints and non-null read bases; the fixture has an empty health table, and its database size/mtime remain unchanged.Cold allocation falls 11%; cold main CPU rises 2.421 ms (+6.8%), so this is not a cold main-CPU win. Warm allocation is neutral. Owner wall time includes source-worker startup; it excludes parent module imports and is not built-Gateway startup latency. Worker CPU/allocation and native buffers are outside this microbenchmark's scope.
A built, trace-disabled Gateway emitted:
Validation
pnpm buildbaseline andpnpm build:runtimecandidate: passed.git diff --check: passed.This is a startup-only transport selection, covered by built boot comparisons and the cold/warm owner measurement. No production Gateway was modified or load-tested. The lane's fast-path exception applies; no ten-minute whole-Gateway load campaign was run. Exact-head PR CI is green on
2da94397565e85b527f02dd6b654bbfcb82fe4c3: 74 checks passed, 51 intentionally skipped, with no failed or pending checks. The PR remains ready and unmerged for the lane owner.