Skip to content

perf(gateway): reuse admitted state during process bootstrap - #165498

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-process-bootstrap-20260919
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-process-bootstrap-20260919

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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 599bcd79e5ae versus this patch. Each built version runs from the same dist/index.js path; warm-up runs are excluded.

Measurement Before, median After, median Before range After range
Started → listening 18.388 s 12.171 s 13.470–22.477 s 9.923–14.478 s
Started → ready 23.168 s 14.730 s 16.962–27.782 s 12.602–17.733 s

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.js and 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 corrected dist/index.js rig 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

  • Blacksmith Testbox, profile openclaw-check, lease tbx_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 base 599bcd79e5ae reproduced the identical findings: GoogleMeetJoinResult, resolveGatewayWorkboardWorkspaceAccess, and MeetingRuntimeOwner. 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.
  • CI passed, including openclaw/ci-gate: run 37293652177, head 368d396330ad967ce9d236fc94b30d9a9cccb133.
  • Detached Codex review: scoped-clean, no actionable P0–P2 findings on the final patch.
  • 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.
  • Baseline comparison, original-failure regressions, and all heavy checks ran remotely. Earlier lease admission/sync failures did not execute tests. A stale native mock-export allowance was regenerated and shrunk by one row; an existing freshness fixture was adapted to intercept the real read result after the operation moved to the read worker.
Focused Testbox command
node scripts/run-vitest.mjs \
  src/cli/command-execution-startup.test.ts \
  src/infra/deferred-plugin-migrations.test.ts \
  src/config/io.health-state-scope.test.ts \
  src/config/io.health-state.test.ts \
  src/config/io.observe-freshness.test.ts \
  src/state/openclaw-state.worker.summary.test.ts \
  src/state/openclaw-state-db-readonly.worker-lifecycle.test.ts \
  src/state/openclaw-state-db-readonly.snapshot-admission.test.ts \
  src/commands/startup-config-preflight.recovery.test.ts \
  src/commands/startup-config-preflight.availability.test.ts \
  src/commands/config-preflight-snapshot.test.ts \
  src/commands/doctor-config-preflight.runtime-owners.test.ts \
  src/commands/doctor-config-preflight.plugin-persistence.test.ts \
  --maxWorkers=1

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.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 docs Improvements or additions to documentation commands Command implementations size: M labels Oct 5, 2026
@steipete
steipete marked this pull request as ready for review October 5, 2026 09:59
@steipete
steipete enabled auto-merge (squash) October 5, 2026 09:59
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 6:05 AM ET / 10:05 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 368d396330ad967ce9d236fc94b30d9a9cccb133

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with relevant runtime measurements, meaningful regressions, and clearly disclosed measurement limits.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.
Evidence reviewed 9 items Pinned introduction: Reviewed the merge-base-to-head delta, rather than endpoint drift. The introduced changes remove the two writer-worker read routes and register their replacements with the existing snapshot-aware reader.
Startup and Doctor diagnostics: Valid startup skips advisory rule collection; invalid configuration and explicit Doctor inspection retain it. Configuration validation already obtains config-wide plugin metadata, supporting removal of the redundant Doctor completion wrapper.
Recovery write protection: Health reads preserve their captured database and environment and check observation validity before and after the read. Updates retain the existing writer and raw-row compare-and-swap basis; the added SQLite regression verifies that stale recovery cannot overwrite a foreign commit.
Findings None None.
Security None None.

How this fits together

Gateway 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
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -5, Tests +129, Docs +2, Other -1. Total +125 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 12 102 107 -5
Tests 8 163 34 +129
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 22 267 142 +125

Review metrics

Metric Value Why it matters
Implementation and regression footprint production net −5 lines; tests and test support net +129 lines The implementation shrinks while added regressions protect snapshot coherence, stale-write rejection, and conditional diagnostic loading.
Matched startup measurements listening 18.388 → 12.171 s; ready 23.168 → 14.730 s Five alternating warm samples demonstrate bounded improvement on the disclosed synthetic Testbox fixture.

Stored data model

Persistent data-model change detected: migration/backfill/repair: config/test-mock-exports-baseline.txt, migration/backfill/repair: src/commands/doctor-config-preflight.ts, migration/backfill/repair: src/commands/doctor/shared/plugin-metadata-snapshot-scope.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This improves startup cost and admission-read coherence without evidence of an urgent user-facing outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.

Label justifications:

  • P2: This improves startup cost and admission-read coherence without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. Matched built-Gateway runs through dist/index.js on Blacksmith Testbox exercise the changed bootstrap path and report lower listening/readiness times with existing synthetic state. SQLite regressions supplement coherence and stale-write coverage. No stored-data contract changes require migration.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head delta, rather than endpoint drift. The introduced changes remove the two writer-worker read routes and register their replacements with the existing snapshot-aware reader. (src/state/openclaw-state-read-operation-registry.ts:31, 368d396330ad)
  • Startup and Doctor diagnostics: Valid startup skips advisory rule collection; invalid configuration and explicit Doctor inspection retain it. Configuration validation already obtains config-wide plugin metadata, supporting removal of the redundant Doctor completion wrapper. (src/commands/config-preflight-snapshot.ts:123, 368d396330ad)
  • Recovery write protection: Health reads preserve their captured database and environment and check observation validity before and after the read. Updates retain the existing writer and raw-row compare-and-swap basis; the added SQLite regression verifies that stale recovery cannot overwrite a foreign commit. (src/config/io.health-state.ts:264, 368d396330ad)
  • Existing-state compatibility: The patch changes read execution and advisory loading, not schemas, serialized rows, settings, migration transforms, or write authorization. Existing raw legacy health values retain their decoder and comparison behavior, and startup still rereads admission after acquiring its migration lease. (src/config/io.observe-freshness.test.ts:247, 368d396330ad)
  • Built Gateway behavior evidence: The captured PR body reports five alternating warm samples per version on Blacksmith Testbox with Node 24.19.0, the same dist/index.js entrypoint, 38 loaded plugins, and existing synthetic SQLite/config-backup state. Median listening time improved from 18.388 to 12.171 seconds and readiness from 23.168 to 14.730 seconds. It explicitly limits extrapolation and leaves production deployment timing and Node 26 acceptance unverified. Reported supplemental validation includes 134 focused tests and baseline reproduction of the inherited dead-export failure. (368d396330ad)
  • Still necessary on current main: Fetched main still uses the Doctor completion wrapper and collects legacy advice unconditionally in this preflight path. The requested optimization is therefore not already present there. (src/commands/config-preflight-snapshot.ts:120, 4f05baa4f524)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • victor-gurbani: 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 1b7d11d into main Oct 5, 2026
218 of 220 checks passed
@steipete
steipete deleted the steipete/perf-micro-process-bootstrap-20260919 branch October 5, 2026 10:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…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.
RomneyDa added a commit that referenced this pull request Oct 10, 2026
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.
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant