Skip to content

refactor: reuse plugin source captures across Doctor phases - #167535

Merged
steipete merged 4 commits into
mainfrom
refactor/plugin-capture-custody
Oct 9, 2026
Merged

steipete merged 4 commits into
mainfrom
refactor/plugin-capture-custody

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #166526

What Problem This Solves

Idempotent Doctor repeatedly captures unchanged plugin sources across its original-state, config, convergence, and session-repair phases.

User Impact

Doctor reuses immutable source custody while each phase keeps private module files, fresh callbacks, and independent native admission and lease settlement. No config, schema, public SDK, or dependency change is introduced by this refactor.

The complete published-upgrade survivor now passes on the merged head: Doctor took 218s against the computed 717s budget, followed by a successful Gateway restart, readiness probes, identical history samples, and final state-survival checks. The state-derived budget comes unchanged from main's #167482; this is not a pass against the former fixed 60s threshold. Cold capture remains expensive, so the broader latency issue stays open.

Why This Change Was Made

The existing generation capture/recovery owner retains an unexecuted immutable source snapshot for one Doctor invocation. Original source, directory membership, dependency resolution, missing inputs, metadata selection, and effective symlink targets are fingerprinted before reuse; changed inputs receive a new capture. Destination hashing, containment, receipt checks, callback-generation independence, and cleanup-before-exit remain with their existing owners.

The follow-up merges main 50d7eb1b7fbc65d5552ac3c82d65dcb512e15b42 without rebasing. There were no conflicts. A second deslop pass removes the redundant recovery-disposal and verifier-callback factories and deduplicates the capture argument contract. It removes 22 production lines, reducing net growth from +516 to +494. No invalidation fact or reachable integrity/lifecycle guard was deleted: each protects a distinct reproduced regression or lifetime contract.

Exact-head CI then exposed a type-only cycle between file capture and source lookup. The shared PluginCapturedSourceFact type now lives beside PluginSourceInput in the existing verification module. This is a four-line relocation with no executable or public SDK change. Core/covering types, lint, Madge (zero cycles), and renewed independent reviews pass. The full checks/build/live scenario were repeated for the repaired head in a new clean checkout and state fixture on the same sole AWS lease; the earlier 556f8eef pass remains prior-head evidence.

Exact delta against merged main: production +673/-179, tests +420/-0, docs +9/-0. Detached custody, private forks, and complete invalidation facts require the remaining growth; the artifact module itself shrinks. The separate fs-safe batching change is excluded: fs-safe stays 0.24.2.

Evidence

Final head: 3e223ad15abe51e356a15b879d9f0c075f3df33f (tree 2d98dfc8f9427e60282530d9cce8c40718a434b6).

  • One fresh AWS lease, cbx_31fe7810a9e3, final run run_c5afc03d04149346201112ca9f3571f4: complete proof exited 0. The published 2026.9.4 updater succeeded; all 4,800 volume sessions, 23,890 volume events, and 2,200 volume cron jobs survived.
  • The measured budget used 4,803 sessions, 23,893 events, 2,203 jobs, and 9 enabled plugin roots. The three additional records in each state category come from baseline fixtures. Computed, effective, and summary budgets all equal 717s. No manual override; GITHUB_ACTIONS=false.
  • Initial Gateway start 285.605s; post-idempotence restart 282.317s. Readiness passed before and after. Eight conversation samples across both agents passed on each side, with identical complete sample records and message digests. Final restarted-state survival passed.
  • Fresh AWS: 731 tests passed / 3 existing skips across 64 selected module files, 457.56s. Core types passed 18.00s and the three covering test graphs 44.06s. On the preceding merged head, the local module selection plus the imported budget/config-parking tests passed 764 tests / 3 existing skips in 506.43s; all 27 core-test graphs, changed-file lint/formatting, and remaining architecture/schema/safety guards passed.
  • Build passed 331.3s; exact tarball validation passed 40s. Matrix/Discord cold-entrypoint profiles are qualified with no gaps: 103.227/100.867 MiB peak RSS, with process cleanup verified.
  • Capture-once and replacement regressions use the real Doctor contract registry. The retained production-only negative control makes all three capture-once cases fail for an extra acquisition while five replacement cases pass (27.82s). Missing-input, resolution, metadata, legacy-entry, indirect-link, and retained-copy integrity cases have demonstrated before-fix failures.
  • Deslop completed; fresh independent pre-commit and prescribed branch reviews are scoped-clean through P2. ClawSweeper completed review of the final 3e223ad head with no findings; it keeps the broader latency issue classified as a partial fix. Exact-head CI run 37878122416 reached a terminal cancelled/fail-fast result: the sole originating failure is the inherited model-catalog type cycle described below. The PR cycle is fixed, and this branch passes Madge with zero cycles. The first follow-up run on 556f8eef had reported both cycles; it is retained as failed prior-head evidence.
  • The local changed gate stops at four inherited unused exports, reproduced by the exact Knip guard on a clean independent install of merged main (73.53s): bindCliQuestionAnswerAuthority, prepareSessionEventTargetForHost, readSessionEntryCreationTransition, and RESTART_CONTINUATION_CONTEXT_PREFIX. The latter two also appear in the full-tree scan. These files are outside this PR. No guard or baseline exception was added. Builds retain the same existing UI gzip warning (365.2 KiB > 364.7 KiB).
Second Doctor phase Original main 8879e5ef Previous PR ca8cef5c Final repaired head 3e223ad
Original-state capture (two inventories) 88.332s 111.257s 110.860s
Config flow 241.043s 58.947s 59.054s
Session transcripts 90.025s 23.757s 23.867s
Provider catalog 19.854s 5.113s 5.120s
Runtime tool schemas 20.320s 5.588s 5.582s
Total second Doctor 472s 218s 218s

CI remains blocked by later main, not green. Job check-guards-architecture (113651596616) reports only src/agents/prepared-model-catalog-fingerprints.ts ↔ src/agents/prepared-model-catalog-worker.ts. CI checked merge 4603c983c08116dce9e5e72aa86f12a40478af5f, combining this PR with main ae64a98a4eb1bc45765290f5b9988c75ce7eb8ca. Both cycle files are byte-identical between that base and merge (blobs d1ca094f1b9076343ac18594df5011ed6f8f2f7f and 08ea2c6e09e08328da4b26ebce5614510484f8ba). The cycle was introduced on later main by 811d442afa2c1103ed10f33f3b64fb1afa7675f8; it does not exist on our pinned 50d7eb1 base. The originating job and aggregate CI gate failed; 25 downstream jobs were cancelled. No rerun, guard weakening, baseline exception, or green-CI claim was used. This main-side blocker remains for landing coordination.

These are single-machine observations. The final head also incorporates main; no deslop or type-relocation performance improvement is claimed. The earlier fixed-budget failure and skipped restart are superseded by the complete final proof above, not relabeled as passing.

Live command and exact provenance
GITHUB_ACTIONS=false \
[email protected] \
OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume \
pnpm test:docker:published-upgrade-survivor

OPENCLAW_LOCAL_CHECK=0 node --import tsx scripts/profile-extension-memory.mts --extension matrix --skip-combined --concurrency 1
OPENCLAW_LOCAL_CHECK=0 node --import tsx scripts/profile-extension-memory.mts --extension discord --skip-combined --concurrency 1

Final evidence excerpts:

budget counts: sessions=4803 events=23893 cronJobs=2203 pluginRoots=9
computedSeconds=717 budgetSeconds=717 summary.idempotenceBudgetSeconds=717
summary.status=passed updateOutcome=success idempotenceSeconds=218
PROOF_COMPLETE: computed budget unchanged; post-idempotence restart/readiness and eight preserved histories passed; both profiles qualified
PROOF_EXIT=0

The successful phase ledger includes assert-volume-idempotence, gateway-restart, gateway-restart-probes, gateway-restart-volume-history, and assert-restarted-survival. Both history artifacts contain eight identical samples. Budget and timing values come from persisted-state measurements and the completed scenario artifacts.

Fresh c7a.8xlarge, same baseline AMI, Node 24.21.0, pnpm 12.5.1, Docker 29.8.2, fs-safe 0.24.2; no credential hydration. Exact public parents plus the checked 877-byte repair bundle reconstructed the original commit. HEAD, tree, main ancestry, and all tracked bytes were verified before bootstrap. The supported no-sync route avoids the previously measured slow local uplink. No source/provenance guard was bypassed. External exact-head instrumentation adds only Doctor trace/timeline environment variables.

Candidate package SHA256: 84c8e4ca57f1c950269a29574252d312296db1e266527c2856433a8350a16747. Complete remote payload: 48m20.264s. Exact-head CI is terminal. The sole lease was stopped successfully; authoritative inspection reports released and the final AWS list contains no active owned lease.

Historical comparison: baseline lease cbx_922fa3782c66, run run_210138ec8e89aaff53c86d5d9f5365b1, head 8879e5ef4b98e7ff17b0ac04e7695f66f3e143b2; earlier PR lease cbx_286a1084e280, run run_c601af015e78103d01153c766d58ec5c, head ca8cef5c656ab310ae027bc6f8590191cdc88395. Those prior leases are released.

Exact module/type commands and test cost
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json '["core-test-plugins-platform","core-test-commands-doctor","core-test-other"]'
node scripts/run-vitest.mjs \
  src/flows/doctor-health.legacy-update.test.ts \
  src/flows/doctor-health.update.test.ts \
  src/flows/doctor-health.managed-settlement.test.ts \
  src/flows/doctor-health.managed-approvals.test.ts \
  src/flows/doctor-health.update-schema.test.ts \
  src/flows/doctor-health.deletion-recovery.test.ts \
  src/flows/doctor-health.update-scope.test.ts \
  src/flows/doctor-health.update-budget.test.ts \
  src/flows/doctor-health.readonly-config.test.ts \
  src/flows/doctor-health.dangling-workshop-index.test.ts \
  src/flows/doctor-health.migration-refusal.test.ts \
  src/flows/doctor-health.plugin-load.test.ts \
  src/flows/doctor-health.test.ts \
  src/flows/doctor-health.fleet-preflight.test.ts \
  src/flows/doctor-health.nocow.test.ts \
  src/flows/doctor-health.managed-admission.test.ts \
  src/plugins/plugin-cache.retention.test.ts \
  src/plugins/doctor-contract-registry.generation.test.ts \
  src/commands/doctor-config-preflight.plugin-persistence.test.ts \
  src/plugins/doctor-contract-registry.test.ts \
  src/plugins/plugin-lifecycle-lease.test.ts \
  src/commands/doctor-config-preflight.state-migration-input.test.ts \
  src/commands/doctor-config-preflight.plugin-deferral.test.ts \
  src/commands/doctor-config-preflight.pristine.process.test.ts \
  src/commands/doctor-maintenance.schema-preflight.test.ts \
  src/plugins/doctor-contract-registry.retained-config.test.ts \
  src/plugins/plugin-generation-source-lookup.test.ts \
  src/commands/doctor-config-preflight.process.test.ts \
  src/commands/doctor-config-preflight.pending-read.test.ts \
  src/commands/doctor-config-preflight.refusal.process.test.ts \
  src/commands/doctor-config-preflight.admission.process.test.ts \
  src/commands/doctor-config-preflight.state-migration.test.ts \
  src/commands/doctor-config-preflight.unavailable-owner.test.ts \
  src/commands/doctor-config-preflight.test.ts \
  src/commands/doctor-config-preflight.schema-preparation.test.ts \
  src/commands/doctor-config-preflight.runtime-owners.test.ts \
  src/commands/doctor-config-preflight.plugin-action-inventory.test.ts \
  src/commands/doctor-config-preflight.container-upgrade.test.ts \
  src/plugins/plugin-cache.test.ts \
  src/plugins/plugin-module-generation.interop.test.ts \
  src/plugins/plugin-module-generation.native-layout.test.ts \
  src/commands/doctor-config-preflight.recovery.test.ts \
  src/plugins/plugin-module-generation.sdk.test.ts \
  src/plugins/doctor-contract-registry.load-paths.test.ts \
  src/plugins/plugin-module-generation.disposal.test.ts \
  src/plugins/plugin-module-generation.test.ts \
  src/commands/doctor/shared/post-core-plugin-convergence.test.ts \
  src/plugins/doctor-contract-registry.selection.test.ts \
  src/commands/doctor/shared/post-core-plugin-convergence.source-checkout.test.ts \
  src/commands/doctor/shared/post-core-plugin-convergence.persistence.test.ts \
  src/plugins/plugin-package-metadata-capture.test.ts \
  src/plugins/doctor-contract-registry.state-migrations.test.ts \
  src/plugins/doctor-contract-registry.unavailable-path.test.ts \
  src/plugins/plugin-generation-artifact.native-reference.test.ts \
  src/plugins/plugin-generation-artifact.test.ts \
  src/plugins/plugin-module-generation.update.test.ts \
  src/plugins/plugin-module-generation.bun.test.ts \
  src/plugins/plugin-module-generation.sibling-assets.test.ts \
  src/plugins/plugin-generation-artifact.streaming.test.ts \
  src/plugins/plugin-generation-artifact.admission.test.ts \
  src/plugins/doctor-contract-registry.custody.test.ts \
  src/plugins/doctor-contract-registry.webhook-pins.test.ts \
  src/plugins/plugin-native-admission-source-index.test.ts \
  src/plugins/plugin-generation-source-inspection.test.ts

pnpm test src/plugins/doctor-contract-registry.custody.test.ts --maxWorkers=1: 8 tests, 13.10s wall. pnpm test src/plugins/plugin-generation-artifact.streaming.test.ts --maxWorkers=1: 28 tests, 13.38s wall. CI seconds will be recorded when available; the final AWS 64-file run took 457.56s.

Exact numstat against merged main
9	0	docs/plugins/architecture.md
12	2	src/flows/doctor-health.ts
204	0	src/plugins/doctor-contract-registry.custody.test.ts
216	0	src/plugins/plugin-generation-artifact.streaming.test.ts
64	69	src/plugins/plugin-generation-artifact.ts
38	0	src/plugins/plugin-generation-file-capture.ts
521	96	src/plugins/plugin-generation-source-lookup.ts
13	0	src/plugins/plugin-native-admission.ts
15	12	src/plugins/plugin-package-metadata-capture.ts
10	0	src/plugins/plugin-source-verification.ts

@clawsweeper

clawsweeper Bot commented Oct 9, 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.

@steipete
steipete marked this pull request as ready for review October 9, 2026 00:04
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XL labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Doctor reuses verified plugin source snapshots across maintenance phases while keeping each phase’s module files, callbacks, and cleanup independent.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong production proof and a sound implementation support the scoped optimization, while its partial resolution of the broader latency report caps the overall rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The recorded production transcript exercises the published updater, real Doctor phases, and restarted Gateway on an isolated large-state installation: repeat Doctor falls from 472 to 218 seconds, readiness and eight preserved histories pass, and final state-survival checks complete. The latest merge preserves the exercised custody implementation; source inspection verifies no stored-data contract or migration change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Users with large installations wait several minutes while Doctor repeatedly copies unchanged plugin sources during updates and repairs.
Reason: Recorded production measurements justify reuse within the existing owner, whose prior merged work establishes area ownership. Cold capture remains expensive, so the broader issue appropriately remains open.

Merge readiness

✅ Ready for maintainer review

This PR retains useful work absent from current main, with no actionable patch findings. It addresses part of the broader Doctor latency problem and is ready for normal landing checks.

Priority: P2
Reviewed head: cae98809dd9bddeb81aeff5662000fa2bb84f2b8

Before merge

None.

Findings

None.

Agent review details

How this fits together

Doctor loads plugin repair contracts while checking and repairing an installation. The plugin capture subsystem supplies verified private source files to those contracts and releases them when their owners finish.

flowchart TD
  A[Doctor maintenance phases] --> B[Source snapshot owner]
  C[Plugin files and dependency selections] --> B
  B --> D{Inputs unchanged?}
  D -->|Yes| E[Reuse retained snapshot]
  D -->|No| F[Capture current source]
  E --> G[Private files and fresh callbacks]
  F --> G
  G --> H[Settle cleanup and release custody]
Loading

Technical review

Best possible solution:

Keep source reuse within the existing capture owner and track remaining cold-capture and maintenance latency in the canonical issue.

Do we have a high-confidence way to reproduce the issue?

Yes: the published-upgrade volume scenario and recorded phase measurements establish repeated capture overhead, and current-main source supports that mechanism; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes for the scoped optimization: reuse extends the existing capture/recovery owner while keeping callback instances, private files, admission, and cleanup independent.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 447144510b89.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced changes: Reviewed the pinned merge-base-to-head delta. The latest main merge leaves the source-custody implementation unchanged from the previously reviewed and live-tested head; its touched Doctor changes consolidate two logging loops. (src/flows/doctor-health.ts:312, cae98809dd9b)
  • Scoped reuse and invalidation: Reuse verifies source identities and contents, directory membership, dependency roots, module resolution, missing inputs, and legacy entry selection. Adoption forks private files and checks the resulting source digest. (src/plugins/plugin-generation-source-lookup.ts:119, cae98809dd9b)
  • Admission and cleanup preserved: Retained ordinary files still undergo destination hashing and containment checks through the receipt owner. Doctor awaits source-custody disposal before invoking its requested diagnostic exit, while phase lifecycle leases continue to settle their own caches. (src/flows/doctor-health.ts:112, cae98809dd9b)
  • Complete production and upgrade proof: Read the full PR body, including the initially omitted tail; the captured source identity is f290cd3d38b0d5adc0d1167875112e54a2dae9353f7ea7796bb9a27e0aba6692. Its production transcript for 3e223ad records the published 2026.9.4 updater, repeat Doctor completing in 218 seconds within the unchanged computed 717-second budget, successful Gateway restart/readiness, eight identical conversation samples, and final survival of the volume state. These are contributor-recorded observations, not reviewer execution. (3e223ad15abe)
  • Meaningful regression coverage: The Doctor registry cases exercise fresh callback counters, distinct module locations, preserved resources, source replacement, and optional dependency changes. Capture cases cover newly appearing inputs and rejection of altered or escaping retained copies; the PR records before-fix negative controls. (src/plugins/doctor-contract-registry.custody.test.ts:74, cae98809dd9b)
  • Current-main necessity: Fetched main still lacks the Doctor source-custody scope, and no later main delta changes the touched capture implementation. The latest release therefore does not establish that this optimization has shipped. (src/flows/doctor-health.ts:106, 447144510b89)

PR surface

Source +494, Tests +420, Docs +9. Total +923 across 10 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 673 179 +494
Tests 2 420 0 +420
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 1102 179 +923

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166526
Summary: This PR addresses repeated cross-phase capture within the broader Doctor latency report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This measurably reduces lengthy Doctor maintenance on large installations without establishing an urgent runtime outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-09T00:13:31.786Z sha ca8cef5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T02:07:47.334Z sha 556f8ee :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T03:17:02.542Z sha 3e223ad :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T03:32:30.540Z sha 3e223ad :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 1:01 AM ET / 05:01 UTC (Revision 5).

@steipete
steipete merged commit 4fe38b9 into main Oct 9, 2026
116 checks passed
@steipete
steipete deleted the refactor/plugin-capture-custody branch October 9, 2026 05:09
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…#167535)

* refactor(plugins): retain source custody across Doctor phases

* refactor(plugins): keep captured source facts in verification owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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