Repository navigation
fix: stop doctor --fix rewriting the plugin registry on a healthy install - #206195
Merged
fuller-stack-dev merged 3 commits intoNov 26, 2026
Merged
fuller-stack-dev merged 3 commits into
fuller-stack-dev merged 3 commits into
Conversation
Every healthy doctor --fix rewrote the persisted plugin index with a new revision. The no-op guard compared raw rediscovery with the stored index, but the store keeps only bundledDist of package build metadata, so any bundled plugin declaring worker entries, assets or a host version always looked changed. The guard now compares the rediscovered index in the form the store would write and read it back, and it is the plugin registry contribution's pending check, so the trace and the write share one predicate.
Contributor
|
🦞👀 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. |
Member
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 27, 2026
…206195) Every healthy doctor --fix rewrote the persisted plugin index with a new revision. The no-op guard compared raw rediscovery with the stored index, but the store keeps only bundledDist of package build metadata, so any bundled plugin declaring worker entries, assets or a host version always looked changed. The guard now compares the rediscovered index in the form the store would write and read it back, and it is the plugin registry contribution's pending check, so the trace and the write share one predicate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #204775
What Problem This Solves
Every
openclaw doctor --fixon a healthy install rewrote the persisted plugin registry, even when no plugin had changed. Each run stored a new revision of the whole index, so a second clean run never left the state database as it found it. This is step 3 of the plan in #204775: a clean run should write nothing. A conditional Gateway stop (step 6) can only skip the stop when every step can say "nothing to do" and mean it.User Impact
On a healthy install,
doctor --fixno longer rewrites the plugin registry. The step took 0.09 to 0.24 s instead of 0.36 to 1.19 s in the measured cells (the higher figures are runs under strace). When the registry really is stale (a plugin added or removed, a damaged record), Doctor still rebuilds it as before. WithOPENCLAW_GATEWAY_STARTUP_TRACE=1the plugin registry step now reports its real answer (pending=none check=ownerorpending=work check=owner) instead of the default.Why This Change Was Made
bundledDistof a plugin's build metadata, so every bundled plugin that declares worker entries, static assets or a host version always looked different. In the cell, 21 of 79 bundled plugins differed inpackageBuildalone.projectInstalledPluginIndexForStore: the index as the writer would store it and the reader would return it. Doctor compares through it, so "unchanged" means "the write would store the same index". Serialization moved out of the row writer into a helper both paths use, so the two cannot drift apart.checkPluginRegistryRepairPending. The repair uses it to decide whether to write, and the plugin registry contribution uses it as its step 1pendingcheck, so the trace and the write share one predicate. It runs twice per Doctor run under maintenance (trace, then repair), 0.04 to 0.13 s each in the cells. Its state reads reuse Doctor's maintenance connection: run 2 made the same number of read-only database copies on base and head. Contributionpendingchecks now receive the flow context. No other contribution declares one yet.undecidablefor them, which counts as work.Every always-firing write site from the step 1 table, checked
Two cells on unmodified
maintraced every SQL statement that changed rows in the Doctor process tree, plus every write-intent file syscall (strace -f). They also snapshotted every store before and after each run, compared against a plainsystemctl --user restartof the Gateway with no Doctor.commands/doctor-plugin-registry.ts,plugins/installed-plugin-index-store-write.ts)config_machine_state[plugins.installedIndex](newrevision, newindex)checkPluginRegistryRepairPendingstate/openclaw-state-db-permissions.ts,doctor-config-preflight.ts)applyPrivateModeSyncalready skips a same-mode chmod. Ther+open writes nothing.needsOpenClawStateDatabaseSchemaRepair(copy plus integrity check)doctor-heartbeat-migration-backup.ts)pendingMigrations)doctor-config-preflight.ts,doctor-config-flow.ts)openclaw.json, its backups or any state row. Every repair there is gated by its own detector.infra/gateway-boot-lifecycle.ts)doctor/shared/codex-route-warnings.ts)doctor-completion.ts)--non-interactive.daemon/runtime-pin-state.ts)infra/update-launcher-repair.ts)Fields that change on a clean run by design (the run's own record)
These change between the end of run 1 and the end of run 2 on this head. Each is also changed by a plain Gateway restart without Doctor, or belongs to the stop itself:
~/.openclaw.update-captures/doctor-<id>: Doctor's pre-repair capture, one per stopped run, newest kept. It is part of the stop (step 6).gateway_boot_lifecycle(the stopped boot getscompleted_at_ms,outcome,reason, and a row for the new boot),config_machine_state[gateway.crashes]and[operator.channelPolicy](updated_at_ms, the new boot's identity),config_health_entriesanddiagnostic_events[config-snapshot](observation times),official_external_plugin_catalog_snapshots(saved_at,updated_at_ms): written by the restarted Gateway.agent_databases.last_seen_at: set on every open of an agent database, by the Gateway and by Doctor.schema_versionandsize_bytesstay the same.state_leasesandagent_database_leases: custody leases. Doctor inserts and deletes its own within the run, and the remaining rows belong to the new Gateway process.~/.openclaw/logs/openclaw-<date>.log(appended), lock files under~/.openclaw/tmp/openclaw-<uid>/,~/.openclaw/tmp/plugin-captures/<id>(Gateway plugin-load scratch),openclaw.json.last-good(inode and mtime), and SQLite-waland-shmsidecars.Unchanged on both runs:
openclaw.json, the systemd unit file, the agent database file, and every other row.Update behavior
There is no update-path change. A published updater that runs Doctor on this build runs the same repairs in the same order. A plugin registry that is stale after an update (new bundled plugins or new build metadata) still differs from discovery in the stored fields and is rebuilt as before. The cells show the guard does not overreach: with a plugin record removed, the step reports
pending=workand rebuilds the index.Evidence
Real cells: Linux, systemd user Gateway, npm install of a packed build under an unpublished version, 64 MiB agent database,
/readyzprobed every 250 ms. Base ismainatd0f76989509. Head is this PR's first commit,94aa43b7f32. Each snapshot cell runsopenclaw doctor --fix --non-interactive --yesthree times. Runs 1 and 2 are understrace -fand a harness-onlynode:sqlitestatement trace (NODE_OPTIONS=--import, Doctor process tree only). A plain Gateway restart runs between runs 2 and 3. Every store is hashed and its rows are dumped before and after each step.d0f7698950994aa43b7f32config_machine_state[plugins.installedIndex]:index,revisionplugins.installedIndexrevision across runs 2 and 3agent_databasesconfig_machine_stateupsertdoctor.pending.contribution.doctor:plugin-registrypending=work check=defaultpending=none check=ownerGuard cells (same setup, no strace). After one settling run, a script seeded real work while the Gateway served: state database mode 0644, a
startup_failedboot row with a maintenance startup reason, and the persisted plugin index with one plugin record removed. Thendoctor --fixran twice:startup_failure_repairedstartup_failure_repairedpending=work check=ownerpending=none check=owner/readyzoutage, settle / work / cleanThe guard outages differ by about 2.5 s while the plugin registry step itself is 0.3 s faster on head. Host load was higher during the head guard cell (1-minute load 6.4 vs 4.1 at start), and the clean third runs of the snapshot cells went the other way (Doctor reported 28.7 s of stop on base and 23.3 s on head). I read this as host noise.
Recordings replay the raw cell logs: the trace line, Doctor's own output, the row-changing SQL, the per-store diff against a plain restart, the index revision at every snapshot, and the guard cell.
RED/BASE,
d0f76989509:doctor-plugin-registry-red-base.mp4
GREEN/HEAD,
94aa43b7f32:doctor-plugin-registry-green-head.mp4
Raw evidence, base (home paths shortened)
Raw evidence, head (home paths shortened)
Root cause, from a debug build of base that printed the guard's differences
Left is the stored index as read back. Right is fresh discovery. The store's reader admits only
packageBuild.bundledDist.Tests
src/commands/doctor-plugin-registry.test.ts, new case: a bundled plugin declaresworkerEntriesandopenclawVersionbesidebundledDist. After the first repair builds the registry, a second repair leaves the state database and its WAL byte-identical with the same mtimes, and the check returnsnone. With a plugin added, the check returnswork, the repair rewrites the index with both plugins, and the stored build metadata is{ bundledDist: true }.doctor-plugin-registry.test.ts,doctor-plugin-registry-generation-repair.test.ts,doctor-maintenance-pending.test.ts,doctor-health-contributions.test.ts,doctor-health-contributions.cancellation.test.ts,installed-plugin-index-store-write.custody.test.ts,installed-plugin-index-store-write.receipt.test.ts,installed-plugin-index-store.test.ts. The new tests from fix: shorten doctor --fix Gateway downtime by removing old updater folders before the stop #206185 (doctor-maintenance.requester-authority.test.ts,doctor-health.migration-refusal.test.ts,doctor-retained-runtime.settlement.test.ts) also pass after mergingmain: 224 tests in total.pnpm tsgo:core,pnpm tsgo:core:test, oxlint on the touched files (including the 700-line cap ondoctor-plugin-registry.ts), the session identity ratchet andgit diff --check.src/commands/doctor-plugin-registry.test.ts. The existing "refreshes an existing registry during repair" case still covers the plain no-op without build metadata, so it stays. Nothing was removed, and the file has no skips.$autoreview(Codex route, branch mode againstorigin/main, P0 to P2) returned scoped-clean.Not proven
94aa43b7f32. The branch then mergedmaintwice (fix: shorten doctor --fix Gateway downtime by removing old updater folders before the stop #206185 in retained-runtime cleanup, plus unrelated agent and channel changes). The focused suites ran again on the merged head. The cells did not.