Repository navigation
perf(gateway): reuse admitted plugin migration facts in warm startup config reads - #169613
Conversation
…startup read Warm `openclaw gateway run` starts paid a synchronous artifact-preserving SQLite snapshot subprocess in the final config reread only to read pending deferred plugin migration rows. The startup preflight already read those rows inside its admitted shared-state snapshot, and the final reread already reuses that generation's plugin metadata. Config readiness now hands the accepted gateway-run preflight's migration generation to the gateway-run bootstrap record, next to the existing plugin metadata cache adoption. The final reread takes it once per start attempt and passes it as deferredPluginMigrations, so no shared-state copy is needed. Invalid, recovered, missing-config, and dev-reset starts keep reading rows.
|
🦞👀 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. What this changesThis PR reuses admitted plugin migration facts during the final Gateway startup configuration read. Example: A warm Gateway launch with an existing state database on the reported M4 Pro setup.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR provides a focused, maintainer-directed startup optimization absent from current main, with no actionable introduced defect found. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI startup admission reads configuration, plugin metadata, and migration obligations; the final configuration reader consumes accepted facts and passes its snapshot to Gateway server bootstrap. flowchart TD
A[Gateway CLI] --> B[Startup admission]
B --> C[Shared state snapshot]
C --> D[Prepared startup record]
D --> E[Final config read]
E --> F[Gateway server bootstrap]
Technical reviewBest possible solution: Carry admitted migration facts through the existing startup owner while retaining fresh reads for repair retries and runtime operations. Do we have a high-confidence way to reproduce the issue? Source tracing confirms main resolves migration rows again during its final startup read; the author reports matched warm-start measurements, and this read-only review executed no target code. Is this the best way to solve the issue? The patch uses the existing config-reader contract and bootstrap record, preserves configuration selection guards, and avoids introducing a competing cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b38650acba8f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +37, Tests +41. Total +78 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 1:29 AM ET / 05:29 UTC (Revision 2). |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…config reads (openclaw#169613) * perf(gateway): reuse accepted preflight migration facts in the final startup read Warm `openclaw gateway run` starts paid a synchronous artifact-preserving SQLite snapshot subprocess in the final config reread only to read pending deferred plugin migration rows. The startup preflight already read those rows inside its admitted shared-state snapshot, and the final reread already reuses that generation's plugin metadata. Config readiness now hands the accepted gateway-run preflight's migration generation to the gateway-run bootstrap record, next to the existing plugin metadata cache adoption. The final reread takes it once per start attempt and passes it as deferredPluginMigrations, so no shared-state copy is needed. Invalid, recovered, missing-config, and dev-reset starts keep reading rows. * test(cli): import gateway bootstrap owner statically in config guard tests
What Problem This Solves
Warm
openclaw gateway runstarts (the state database already exists, which is every start after the first, including the macOS app's Bun-hosted Gateway) spent ~170 ms synchronously copying the shared-state SQLite database in a spawned child process, only to re-read pending plugin migration rows that startup had read moments earlier.User Impact
Warm Gateway starts reach
/readyzabout 170 ms sooner (−4.3% on an idle M4 Pro Mac mini, app-identical launches on the pinned Bun 65d94e715). Fresh starts are unchanged. No config, schema, or operator action.Why This Change Was Made
Startup's config preflight already reads the pending plugin migration rows inside its admitted shared-state snapshot, and the CLI's final config reread already reuses that same preflight's plugin metadata (#136141). The migration rows describe obligations for those same installed plugins, so they belong to the same accepted generation rather than a separate artifact-preserving copy.
Config readiness now hands the accepted gateway-run preflight's migration facts to the gateway-run bootstrap record, in the branch that already adopts the preflight plugin cache. The final reread takes them once per start attempt and passes them as
deferredPluginMigrations(both shell-env rereads share them), so config IO never opens shared state there.Freshness: no Gateway owns state between the preflight and the final reread, so a later pre-ownership read is not a stronger contract — writers could commit just after it as well, and Gateway runtime reloads and config writes keep reading current rows. The startup preflight itself never writes migration rows (only Doctor flows do). Invalid preflights, interactive Doctor recovery, retries after
InvalidConfigErrorrecovery, missing config (dev bootstrap may create one), and--dev --resetnever accept facts, so they keep reading rows. The server bootstrap consumes this snapshot as-is and does not re-read migration rows.Rejected alternative:
prepareValidation: "runtime"in the final rereadInstrumented runs show it does not miss the adopted plugin-metadata cache (
resolveConfigWidePluginMetadataSnapshotAsync0.2 ms, install records ~0 ms). Its entire cost isreadDeferredPluginMigrationsAsyncreading through the async state-read worker: 1,341–1,346 ms on a fresh start and 416–419 ms warm. On a fresh start the Gateway has already created the shared database by the final reread (about 3.7 s in), so this is a real worker read with a cold Bun transpiler cache, not an absent-database probe. Reads of a missing database already return without a worker (startOpenClawStateReadOperation, since #148290):openclaw config validateand Doctor lint on fresh state spend 2–3 ms there.Evidence
Idle
steipete-mini-sf(M4 Pro, load 2.2–4.0), base04914b1ab803vs this branch, each built withpnpm buildand staged withscripts/stage-mac-runtime.sh(candidate = cloned stage refreshed with its own packed build). Launches use the staged Bun1.4.3-canary.1+65d94e715and libsqlite3, freshHOME/OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATHunder$(getconf DARWIN_USER_TEMP_DIR), a random port,{gateway:{mode:"local",auth:{mode:"token"}},logging:{file}},OPENCLAW_GATEWAY_STARTUP_TRACE=1, andOPENCLAW_GATEWAY_HOST_LIFELINE=stdinwith stdin held open. 7 interleaved pairs (order alternating), each pair a fresh then a warm start in one state dir:cli.config-snapshot/readyzcli.config-snapshot/readyzA separate instrumented copy (timing wrappers on the compiled functions) counted synchronous snapshot subprocesses (
runSqliteReadOnlyWorkerSync) across the whole startup: base warm = 1 (158–162 ms, insidereadDeferredPluginMigrations), candidate warm = 0, all fresh = 0.Tests:
config-guard.test.tscovers acceptance (pending and empty generations handed off once; missing config and invalid preflight not accepted), andrun.option-collisions.test.tsasserts the final reread receives the accepted facts. Restoringrun.tsandconfig-guard.tsfrommainfails exactly those three positive cases.run.tsandrun.option-collisions.test.tsboth shrink (line-cap ratchet).pnpm test src/cli/program/config-guard.test.ts --maxWorkers=1: 24 tests, ~3.5 s test time on a load-70 host (the first new row spends 1.5 s loading the gateway bootstrap's lazy config IO graph; the others take 5–9 ms). Localcheck:changed: typecheck, lint, format, ratchets, and boundaries pass; its dead export scan fails only onsrc/agents/agent-run-result.ts: agentRunHasVisibleReply, inherited frommainsince #169554 removed its last caller (untouched here). Autoreview (Codex, P0–P2): scoped-clean.Inherited CI failure:
checks-node-changed-4fails onsrc/cli/gateway-cli/run-loop.forced-cron.process.test.ts(all three cases:Missing process proof: held:starts=1:pending=true). This PR does not touch that test or its fixture, and none of the changed modules are in the fixture's static import graph. The file is selected only because this PR touchessrc/cli/gateway-cli/. It fails identically at clean base04914b1ab803on an idle Mac under the pinned Bun (OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs src/cli/gateway-cli/run-loop.forced-cron.process.test.ts) and under Node, so it is broken onmainindependently of this change and is tracked separately. Landing uses the inherited-failure admin exception.