Repository navigation
perf(gateway): reuse admitted state during process bootstrap - #165498
Conversation
Reuse the admitted read snapshot for config recovery and pending plugin migrations, retaining lease-bound admission and compare-and-swap writes. Avoid evaluating plugin Doctor rules for valid startup while preserving invalid-config and explicit Doctor diagnostics.
|
🦞👀 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: blocked before merge. Reviewed October 5, 2026, 6:05 AM ET / 10:05 UTC. ClawSweeper reviewWhat this changesThe PR reuses admitted SQLite snapshots for configuration recovery and pending plugin migrations, and skips unused plugin repair diagnostics during valid startup. Merge readiness⛔ Blocked before merge - 1 item remains This remains useful, distinct work beyond the merged startup-maintenance change. No actionable introduced correctness or security defect was found; the measured improvement supports the bounded optimization without establishing production startup targets. Priority: P2 Review scores
Verification
How this fits togetherGateway bootstrap validates configuration and inspects shared SQLite state before opening the listener. These reads inform recovery and migration decisions, whose existing write owners still check current state before committing. flowchart TD
A[Gateway startup] --> B[Configuration validation]
B --> C[Admitted SQLite snapshot]
C --> D[Recovery and migration reads]
B --> E{Configuration valid?}
E -->|No| F[Plugin repair guidance]
E -->|Yes| G[Listener startup]
D --> H[Current-state write checks]
H --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource -5, Tests +129, Docs +2, Other -1. Total +125 across 22 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep snapshot selection with the existing read owner and current-state publication checks with the existing writers, while reserving advisory plugin loading for diagnostics that need it. Do we have a high-confidence way to reproduce the issue? Yes, source identifies reads that bypassed an active admission snapshot, and the submitted SQLite regressions inject foreign commits at that boundary. This review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes, moving those reads to the existing snapshot-aware owner preserves write safeguards and removes redundant work; the diagnostics change retains invalid-config and explicit Doctor guidance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4f05baa4f524. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…w#165498) Reuse the admitted read snapshot for config recovery and pending plugin migrations, retaining lease-bound admission and compare-and-swap writes. Avoid evaluating plugin Doctor rules for valid startup while preserving invalid-config and explicit Doctor diagnostics.
Backports the startup gate from #165498 to release/2026.10.1. Valid Gateway startup evaluated plugin Doctor legacy-config rules on every preflight read. Each read uses a fresh plugin cache, so every read instantiated a new Doctor setup-module instance for each external plugin with a doctor contract and captured its whole package (about 3,345 files for the codex plugin), and then discarded it. Invalid config still collects plugin repair guidance, and `openclaw doctor` still inspects repair rules for valid config. macOS candidate repro with one external codex plugin: pre-ready captures went from 2 (3 on first start) to 1, and ready time went from about 28-30s to 14-17s.
Backports the startup gate from openclaw#165498 to release/2026.10.1. Valid Gateway startup evaluated plugin Doctor legacy-config rules on every preflight read. Each read uses a fresh plugin cache, so every read instantiated a new Doctor setup-module instance for each external plugin with a doctor contract and captured its whole package (about 3,345 files for the codex plugin), and then discarded it. Invalid config still collects plugin repair guidance, and `openclaw doctor` still inspects repair rules for valid config. macOS candidate repro with one external codex plugin: pre-ready captures went from 2 (3 on first start) to 1, and ready time went from about 28-30s to 14-17s. (cherry picked from commit a84bd1a) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Gateway startup loads plugin Doctor rules that valid configuration does not use, and config-recovery/pending-migration reads leave the already admitted SQLite snapshot. That adds module-loading and snapshot work before the listener can bind, and can mix database generations during one inspection.
Related: #165218.
User Impact
Startup does less work while preserving invalid-config repair guidance, migration admission, and current-state checks before writes. No new settings, persistent cache, schema migration, or update action is required.
The campaign target of listening within 10 seconds and ready within 15 seconds remains unmet. These synthetic measurements do not prove production deployment timing.
Why This Change Was Made
Config-health and deferred-plugin reads now use the existing snapshot-aware read worker. Their old writer-actor read operations are removed. Health observations retain their captured database/environment, supersession and error behavior, and compare-and-swap write basis. The two admission passes remain: startup must recheck after acquiring the migration lease.
Valid startup no longer evaluates unused Doctor advisory rules. Invalid startup and explicit Doctor inspections retain them. Generic metadata completion replaces the redundant Doctor wrapper; separate include/complete flags that callers always passed together are removed.
The requested production LOC filter reports 108 insertions / 110 deletions (net −2). Excluding its included test harness and test-ratchet row, implementation alone is net −5 lines.
Evidence
Three regression categories failed on the original implementation: valid startup executed an unused Doctor module, and both async state readers observed a later foreign commit inside an earlier admission snapshot. The new tests also prove stale recovery cannot overwrite that foreign commit and invalid config retains plugin repair advice. CPU profiles identify plugin module resolution/loading as a large baseline cost.
Measurement
Five alternating warm samples per version on the same Blacksmith Testbox, Node 24.19.0, base
599bcd79e5aeversus this patch. Each built version runs from the samedist/index.jspath; warm-up runs are excluded.The fixture has 38 loaded plugins (37 synthetic plugins plus memory-core), two agents, 810 worktree-shaped directories, approximately 510 MiB of shared SQLite padding, and an existing config backup. The directories are fixture shape; admission does not scan arbitrary worktrees. State is synthetic, plugins do not reproduce a production import graph, and the listener binds only to loopback. Small samples and variable timings limit extrapolation.
Earlier exploratory Node 26 rig measurements used
dist/entry.jsand 39 loaded plugins: listening 26.845 → 19.901 s, ready 36.441 → 25.919 s, CLI bootstrap 8.420 → 3.793 s (five-sample medians). A correcteddist/index.jsrig comparison was confounded by rising concurrent load; its attempted alternating rebuild was killed by host OOM while disk was full. The matched comparison above therefore moved to Testbox. Node 26 rig acceptance and production deployment improvement remain unverified.Proof
openclaw-check, leasetbx_01m45mxderh2m9ds3njkxka0qg: 13 focused files / 134 tests passed; four Vitest shards, 169.48 s total wrapper time with--maxWorkers=1. No new CI job or worker pin was added. CI's selected Node test jobs used 6,036 aggregate runner-seconds across all selected tests.node scripts/check-changed.mjs --base HEAD: failed only at the inherited dead-export scan. An unchanged worktree at base599bcd79e5aereproduced the identical findings:GoogleMeetJoinResult,resolveGatewayWorkboardWorkspaceAccess, andMeetingRuntimeOwner. All earlier gates passed, including core and complete test typechecks. Every remaining native-plan check was then run and passed: source/script lint, schema, legacy-store, media, sidecar, import-cycle, webhook, and pairing guards. No dead-code bypass or allowance was added. The explicit base avoids a stale remote tracking ref selecting unrelated changes.openclaw/ci-gate: run 37293652177, head368d396330ad967ce9d236fc94b30d9a9cccb133.OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build: baseline and candidate runtime builds passed on the same Testbox in 68.6 s / 56.1 s. Declarations are covered by Testbox typechecks. The complete remaining-check/baseline-reproduction/alternating-benchmark command passed in 681.6 s; its temporary worktree was removed.Focused Testbox command