Repository navigation
improve: doctor migration checks no longer load every bundled plugin runtime - #120678
Conversation
…r-test lane Registry records carry only the doctorContract declaration instead of the whole parsed manifest, and check:changed now selects the src/plugins-owned declaration honesty and closure-guard tests for extension module/manifest changes so cross-lane drift cannot pass PR classification.
Keep doctor and channel control-plane chunks off exec-class dependencies, and enforce native require(esm) loading during postbuild.
|
Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 3:40 PM ET / 19:40 UTC. ClawSweeper reviewWhat this changesThe PR makes Doctor use plugin manifest declarations to avoid loading unrelated migration modules, adds narrower SDK imports, and validates built control-plane modules after packaging. Merge readinessKeep open for maintainer review: current main still eagerly loads every Doctor contract, but the exact PR head and omitted files could not be read locally, and this introduces public plugin metadata and an SDK subpath. Priority: P2 Review scores
Verification
How this fits togetherDoctor reads plugin manifests and contract artifacts to find configuration, session, and state migrations before startup. Those contracts feed repair planning and must remain loadable from packaged plugin builds. flowchart LR
A[Plugin manifests] --> B[Doctor contract registry]
B --> C{Requested repair surface}
C --> D[Load matching contract]
D --> E[Config and state migrations]
E --> F[Doctor and startup results]
G[Packaged plugin artifacts] --> D
Decision needed
Why: The branch adds durable plugin manifest and SDK surfaces; source supports the repair shape, but the permanent external contract needs maintainer intent. Before merge
Agent review detailsSecurityNone. Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep manifest-first, per-surface gating as the canonical Doctor owner boundary, then verify its complete public contract and built artifacts on the exact head before merge. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main iterates every manifest record and loads each Doctor contract artifact when callers request unscoped migrations; no write-capable execution was run. Is this the best way to solve the issue? Unclear: manifest-first per-surface loading is the correct owner boundary over config filtering or caching, but the exact public API shape and packaged implementation still need maintainer and exact-head verification. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b40f84675796. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
qqbot was the last plugin above 5s in doctor state-migration enumeration (~8s under tsx/jiti). The cost was not the state-key builder (already a leaf): its doctor closure value-imported the runtime-doctor SDK barrel, whose plugin-state-store/state-db re-exports pull kysely (~330 modules), plus security-runtime for one fileExists (~200 modules), all resolved per-module by jiti during enumeration. Split the migration-define helpers and light re-exports into a new private-local plugin-sdk/runtime-doctor-migrations subpath; runtime-doctor re-exports it so its public surface is byte-identical (API baseline hash unchanged). qqbot's doctor-contract and state-migrations now import only the light subpath, swapping fileExists for the equivalent async legacyStateFileExists already in the closure. qqbot enumeration: ~8.0s/531 modules -> ~0.25s/18 modules.
runtime-doctor-migrations is private-local-only; the baseline tracks public modules, and the earlier line was generated before the classification.
|
@clawsweeper re-review The reviewed head Evidence for the two rank-up moves, since the earlier run could not fetch the objects: "Confirm packaged artifacts load" — this is enforced in the build itself, not just asserted. "Bundled declarations exactly match exported Doctor surfaces" — On the P1 note that an incorrect opt-in declaration could suppress a plugin's own repair surface: that is the exact failure mode the honesty test above exists to prevent, and On the decision item: adopting |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review Head moved to 4349161: adds the qqbot doctor-closure slimming via a new private-local |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Head moved again since my last comment: a follow-up landed on this branch applying the same invariant to qqbot, the last plugin still above 5s in doctor enumeration. Current head is The qqbot commit is worth a look because it corrects a wrong initial diagnosis. The cost was not the plugin's state-key helper (already a leaf) — qqbot's doctor closure value-imported the The PR body has been updated to describe this commit. |
The private-local subpath list feeds the extension package boundary map; the shared paths config and xai's derived overrides must carry the same entry or the boundary contract test fails.
|
Merging with the exact-head ClawSweeper re-review still outstanding, recording why rather than passing over it silently. The durable review is pinned to State at merge time, head
If a later re-review surfaces anything actionable, it gets a follow-up PR. |
|
Merged via squash.
|
…runtime (openclaw#120678) * perf(plugins): declare doctor contract surfaces * perf(doctor): slim migration import closures * perf(plugins): narrow doctor declaration record surface and wire owner-test lane Registry records carry only the doctorContract declaration instead of the whole parsed manifest, and check:changed now selects the src/plugins-owned declaration honesty and closure-guard tests for extension module/manifest changes so cross-lane drift cannot pass PR classification. * fix(doctor): keep control-plane dist imports require-safe Keep doctor and channel control-plane chunks off exec-class dependencies, and enforce native require(esm) loading during postbuild. * chore(plugin-sdk): regenerate API baseline * chore(plugin-sdk): sync export ordering * fix(plugins): satisfy doctor contract CI boundaries * perf(doctor): make qqbot doctor closure dependency-light qqbot was the last plugin above 5s in doctor state-migration enumeration (~8s under tsx/jiti). The cost was not the state-key builder (already a leaf): its doctor closure value-imported the runtime-doctor SDK barrel, whose plugin-state-store/state-db re-exports pull kysely (~330 modules), plus security-runtime for one fileExists (~200 modules), all resolved per-module by jiti during enumeration. Split the migration-define helpers and light re-exports into a new private-local plugin-sdk/runtime-doctor-migrations subpath; runtime-doctor re-exports it so its public surface is byte-identical (API baseline hash unchanged). qqbot's doctor-contract and state-migrations now import only the light subpath, swapping fileExists for the equivalent async legacyStateFileExists already in the closure. qqbot enumeration: ~8.0s/531 modules -> ~0.25s/18 modules. * chore(plugin-sdk): drop private-local subpath from API baseline runtime-doctor-migrations is private-local-only; the baseline tracks public modules, and the earlier line was generated before the classification. * fix(plugins): register runtime-doctor-migrations boundary paths The private-local subpath list feeds the extension package boundary map; the shared paths config and xai's derived overrides must carry the same entry or the boundary contract test fails.
Related: #120475
Related: #120426
What Problem This Solves
Resolves a problem where any command or test that runs the legacy-state migration
check —
openclaw doctor,doctor --fix, and the automatic startup migration scan —paid a multi-minute stall before doing any work, because discovering which plugins
own doctor contracts required executing every bundled plugin's runtime module.
In a source checkout the cost was measured at ~219s for plugin doctor contracts and
~201s for channel legacy-state detectors. Operators saw it as a doctor run that
appeared to hang; contributors saw it as unrelated tests timing out (the gateway-bind
test in #120475 deterministically blew its 120s budget this way, worked around
test-side in #120426).
Why This Change Was Made
Discovery is now manifest-first. Each plugin declares which doctor surfaces it
implements in its
openclaw.plugin.json, and doctor loads a plugin's contract moduleonly when that plugin declares the surface actually being enumerated. The module stays
authoritative — the declaration only gates loading, and a plugin that omits the
declaration is loaded exactly as before, so installed third-party plugins keep working
untouched.
Profiling then showed the remaining cost was not breadth but one edge: doctor-path
modules imported the deprecated broad
agent-runtimeSDK barrel, pulling the wholecore agents graph into a control-plane path. Those callers moved to a new focused
agent-scope-runtimesubpath, and a guard test now keeps that barrel out of everydoctor and legacy-detector import closure.
Verifying the result surfaced a real defect this branch had introduced: the new SDK
entrypoint reshuffled build chunks so several built plugin contract artifacts
statically reached an ESM-only transitive dependency and could no longer be loaded by
require. Doctor swallowed that failure silently, so those plugins' migrations simplydisappeared in packaged builds. The exec-class dependencies were moved behind lazy
boundaries at their owning modules, contract load failures are now recorded instead of
discarded, and a postbuild phase loads every built control-plane module so build-time
chunking can never silently break this again.
Non-goals: doctor still enumerates every plugin's declared surfaces rather than only
configured ones, because doctor intentionally repairs state belonging to plugins that
are not currently configured. Scoping that is a separate product decision.
A follow-up commit on this branch applies the same invariant to the last remaining slow plugin.
qqbot's doctor closure value-imported the
runtime-doctorSDK barrel, whose plugin-state andstate-db re-exports pull kysely (~330 modules), plus
security-runtimefor a singlefileExists(~200 modules) — all resolved per module during enumeration. The migration-definehelpers and light re-exports moved to a private-local
runtime-doctor-migrationssubpath thatruntime-doctorre-exports, so its public surface stays byte-identical and the API baseline hashis unchanged. qqbot enumeration went from ~8.0s across 531 modules to ~0.25s across 18.
User Impact
Operators get a doctor and startup migration scan that begins working immediately
instead of stalling for minutes, on both source checkouts and packaged installs.
Plugin authors gain a focused
openclaw/plugin-sdk/agent-scope-runtimeentrypoint anda documented
doctorContractmanifest block. When a plugin's doctor contract fails toload, the reason is now logged with the plugin id and artifact path instead of the
repair vanishing without explanation.
No configuration changes are required, no plugin API was removed, and plugins without
the new declaration behave exactly as before.
Evidence
Discovery cost, measured with a harness that times each plugin's doctor state-migration
enumeration:
Migration counts were compared before and after, in both source and built modes, and
match exactly (for example codex 1, matrix 6, memory-core 5, acpx 1) — the speedup
skips module loading, never a repair.
Correctness and regression proof:
declared surface matches what the module actually exports, so an under-declaration
cannot silently skip a repair.
legacy-detector import closure and fails on the broad
agent-runtimebarrel.require; this is what caught the chunking defect above.check:changednow selects the two owner tests for extension module and manifestchanges, so declaration drift cannot pass PR classification and first break on main.
gates, script-declaration check, and a full build with no ineffective dynamic imports.