Skip to content

refactor(plugins): make discovery invocation-owned - #130486

Merged
steipete merged 1 commit into
mainfrom
codex/architecture-cleanup-plugin-discovery
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/architecture-cleanup-plugin-discovery

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin discovery still assembles and merges separate scoped/shared result objects after the caches that needed them were removed. It also carries traversal state for recursion that has no remaining caller. This maintainer-requested structural cleanup removes those obsolete flows without changing which plugins operators can load.

Why This Change Was Made

One private, invocation-owned scanner now owns candidates, diagnostics, filesystem/package facts and phase-local attempted paths. The old result containers, merge protocol, unreachable recursive traversal and repeated state plumbing are deleted. Installed-path preparation has one owner while preserving the important distinction between preferred scan paths, all managed paths and auto-scan exclusion directories.

The two acceptance phases remain deliberately separate: a configured-path rejection must not prevent later bundled permission repair and acceptance. Physical aliases are normalized only after acceptance; the first candidate retains its origin and fields while symbol-backed install-owner/ambiguity facts merge. Configured-only discovery stays raw for Doctor's count-sensitive check. Registry duplicate-ID selection, official-install trust, package/runtime boundary checks, root ordering and metadata-cache lifecycle are unchanged.

Deleting recursion alone would leave the obsolete split-result owner. A generic discovery framework would add abstractions without replacing OpenClaw's origin-sensitive policy. This change instead consolidates the existing private owner and preserves both public entry points.

User Impact

No intended user-visible behavior or configuration change. Existing native, bundled, linked-source and bundle-style plugin discovery retains its ordering, diagnostics and safety checks. No dependency, SDK export, schema, persistence or protocol change.

Production LOC: +573/-815 (net -242). Tests: +234/-31 (net +203). Only src/plugins/discovery.ts and its existing test file change.

Evidence

Baseline: 86e208310ff2f7a66e4f0c5968e74b319234f6aa. Reviewed and proven commit: 0dd08aa6643d5635ccaf092f063a1bb7e7c3a4a3.

  • Before production editing, clean-machine discovery/registry/path suites passed 295 tests. Final identical-order baseline and candidate runs each passed 317 tests across nine files, including Doctor.
  • Added real filesystem and registry cases cover configured rejection followed by bundled repair, raw configured aliases/diagnostics, multi-entry ownership, official registry trust versus local archive/ambiguous ownership, missing preferred installs and managed source copies. The official-trust assertions use real discovery-to-registry fixtures, not a published official-package installation.
  • Independent review caught a candidate-only regression: collecting excluded parent directories before physical installed-path deduplication could hide a neighboring plugin. The regression failed on the initial refactor and passed after restoring the retained-path rule. This is not claimed as a pre-existing shipped bug.
  • node scripts/check-changed.mjs -- src/plugins/discovery.ts src/plugins/discovery.test.ts passed completely, including formatting, production/test types, lint, dead exports and selected guards. Fresh full-change P1 autoreview is clean; independent source/test review is PASS.
  • The corrected full clean-machine build passed in 10m40.3s. The real dist-backed CLI packed and installed a native plugin, linked a TypeScript plugin, listed/inspected both plus a Claude-style bundle, and started an isolated loopback Gateway. Both native plugins registered in the actual Gateway process. After changing the linked source, a stopped-and-restarted Gateway loaded its new revision. This live flow passed in 65.611s; owned processes/temp state and the Testbox lease were cleaned up.
  • Clean-machine proof used Testbox run 33020081680. The prepared runner Git HEAD is not the candidate identity: all 22,715 tracked files excluding *.test.ts were fingerprinted by content/symlink-target bytes and matched the frozen candidate. Final committed source/test blobs match the reviewed local files. The earlier remote test snapshot differs only in a Windows symlink-test guard; Linux behavior is unchanged. Workflow cleanup may mark the infrastructure run canceled; the proof command itself ended with exitCode: 0.
  • One build attempt lost its SSH connection; the recovered full build passed. The first live script then correctly hit the local-plugin trust confirmation because its linked-install command omitted --force. After explicitly acknowledging the reviewed synthetic fixture, the live-only rerun passed. Neither retry required production changes.
  • Independent final source/proof approval is bound to the exact commit above. Exact pushed-head GitHub CI and the native maintainer landing gates remain required.

The final suite command was node scripts/run-vitest.mjs src/plugins/discovery.test.ts src/plugins/discovery-threading.test.ts src/plugins/plugin-discovery-ordering.test.ts src/plugins/hardlink-policy.test.ts src/plugins/package-compat.test.ts src/plugins/manifest-registry.test.ts src/plugins/manifest-registry-installed.test.ts src/plugins/installed-plugin-index.test.ts src/commands/doctor/shared/pristine-startup-state.test.ts.

AI-assisted implementation with independent design and source review.

Remove the cache-era split result assembly, unreachable recursive scans, and repeated scan-state plumbing. Derive preferred install paths and managed classification together while keeping their distinct exclusion semantics.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 23:27
@steipete steipete self-assigned this Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 7:35 PM ET / 23:35 UTC.

ClawSweeper review

What this changes

This PR consolidates plugin discovery into one invocation-owned scanner while preserving configured, bundled, installed, and Doctor discovery behavior.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. This is a coherent maintainer-owned cleanup; source review found no discrete patch defect, while normal exact-head CI and maintainer landing review remain.

Priority: P3
Reviewed head: 0dd08aa6643d5635ccaf092f063a1bb7e7c3a4a3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-boundary refactor is coherent and behavior-focused tests cover its key preserved invariants; exact-head CI remains the material merge gate.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: Not applicable to the maintainer-authored PR proof gate; the PR body nevertheless records a dist-backed CLI and isolated Gateway exercise.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to the maintainer-authored PR proof gate; the PR body nevertheless records a dist-backed CLI and isolated Gateway exercise.
Evidence reviewed 6 items Invocation-owned discovery state: The new scanner owns candidate, diagnostic, realpath, manifest-cache, and phase-local attempt state in one invocation.
Preserved publication boundary: Configured-only discovery intentionally returns raw aliases and diagnostics for Doctor, while full discovery resets phase attempts and applies physical-path deduplication only at finish.
Caller and sibling boundary: The loader consumes the full discovery result, while Doctor uses the configured-only entry point before registry acceptance; both public entry points remain present.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/plugins/discovery.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/plugins/discovery.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/plugins/discovery.test.ts"

[test] starting test/vitest/vitest.plugins.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130486-90dVqe/target

 ✓  plugins  src/plugins/discovery.test.ts (116 tests) 362ms

 Test Files  1 passed (1)
      Tests  116 passed (116)
   Start at  23:36:04
   Duration  3.12s (transform 2.15s, setup 981ms, import 1.41s, tests 362ms, environment 0ms)

[test] passed 1 Vitest shard in 9.73s

Assertions:

  • FAIL expect_output: Test Files

How this fits together

Plugin discovery reads configured paths, bundled plugins, and install records, then produces ordered candidates and diagnostics. Plugin loading and Doctor consume those results to activate plugins and validate configured paths.

flowchart LR
A[Configured paths] --> D[Plugin discovery]
B[Bundled plugins] --> D
C[Installed plugin records] --> D
D --> E[Candidate acceptance]
E --> F[Final ordering and deduplication]
F --> G[Plugin loader and registry]
F --> H[Doctor validation]
Loading

Before merge

  • Resolve merge risk (P1) - Plugin discovery governs existing configured load paths and install ownership; exact-head CI should complete before merge to confirm ordering, diagnostics, and managed-package behavior across the full matrix.
  • Complete next step (P2) - This maintainer-owned refactor has no discrete repair task; it needs normal exact-head validation rather than an automated replacement patch.
Agent review details

Security

None.

PR surface

Source -242, Tests +203. Total -39 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 573 815 -242
Tests 1 234 31 +203
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 807 846 -39

Review metrics

Metric Value Why it matters
Production vs test LOC production -242 (+573/-815); tests +203 (+234/-31) The refactor materially reduces production code while adding coverage for retained discovery boundaries.

Merge-risk options

Maintainer options:

  1. Complete discovery compatibility validation (recommended)
    Let exact-head CI complete before merging so configured-path, ownership, ordering, and Doctor behavior are checked on the submitted commit.

Technical review

Best possible solution:

Retain one scanner as the private discovery owner, with final publication deduplication and raw configured-path output kept as distinct intentional boundaries.

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

Not applicable: this PR does not claim a pre-existing user-visible failure; its added tests exercise the affected filesystem and registry boundaries.

Is this the best way to solve the issue?

Yes. A single private scanner owns scan-local state while preserving the loader and Doctor public entry points, avoiding the former split-result merge protocol.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 02a60e0d8714.

Labels

Label changes:

  • add P3: This is a behavior-preserving structural cleanup rather than a reported user-facing regression.
  • add merge-risk: 🚨 compatibility: The refactor changes the discovery path used by existing configured plugins, install records, and Doctor validation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to the maintainer-authored PR proof gate; the PR body nevertheless records a dist-backed CLI and isolated Gateway exercise.

Label justifications:

  • P3: This is a behavior-preserving structural cleanup rather than a reported user-facing regression.
  • merge-risk: 🚨 compatibility: The refactor changes the discovery path used by existing configured plugins, install records, and Doctor validation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; 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. Not applicable: Not applicable to the maintainer-authored PR proof gate; the PR body nevertheless records a dist-backed CLI and isolated Gateway exercise.

Evidence

What I checked:

  • Invocation-owned discovery state: The new scanner owns candidate, diagnostic, realpath, manifest-cache, and phase-local attempt state in one invocation. (src/plugins/discovery.ts:811, 0dd08aa6643d)
  • Preserved publication boundary: Configured-only discovery intentionally returns raw aliases and diagnostics for Doctor, while full discovery resets phase attempts and applies physical-path deduplication only at finish. (src/plugins/discovery.ts:1280, 0dd08aa6643d)
  • Caller and sibling boundary: The loader consumes the full discovery result, while Doctor uses the configured-only entry point before registry acceptance; both public entry points remain present. (src/plugins/loader-discovery.ts:53, 0dd08aa6643d)
  • Behavior-focused regressions: Added filesystem cases cover duplicate installed-file aliases without suppressing a sibling package, trust/ownership through aliases, and Doctor’s raw configured-path behavior. (src/plugins/discovery.test.ts:1144, 0dd08aa6643d)
  • Current-main comparison: Current main still has the split-result merger and separate configured discovery plumbing; this refactor is not already implemented there. (src/plugins/discovery.ts:410, 02a60e0d8714)
  • Area provenance: Recent discovery history includes ownership-preservation and lifecycle work by Peter Steinberger and Vincent Koc; the new scanner is attributable to the PR head. (src/plugins/discovery.ts:811, 0dd08aa6643d)

Likely related people:

  • steipete: Recent history shows repeated plugin-discovery lifecycle and identity work, and the invocation-owned scanner is on this PR head. (role: recent area contributor; confidence: high; commits: 0dd08aa6643d, 5a643e354310, 3972c4151390; files: src/plugins/discovery.ts, src/plugins/discovery.test.ts)
  • Vincent Koc: History attributes bundled install-ownership preservation to this area, which the refactor deliberately retains. (role: adjacent feature contributor; confidence: high; commits: 4c60b3b985eb, 32e3bd3797f0; files: src/plugins/discovery.ts, src/plugins/discovery.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete exact-head CI for the submitted commit.

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

Copy link
Copy Markdown
Contributor Author

Land-ready review for 0dd08aa6643d5635ccaf092f063a1bb7e7c3a4a3: exact-head CI 33023430181 is complete and green. Independent source/proof review is bound to this commit, with no accepted findings; fresh full-change P1 autoreview is clean. Production net −242, tests +203, no public/config/schema/dependency change.

The latest ClawSweeper review found no discrete patch defect. Its compatibility-validation request and sole Rank-up move—complete exact-head CI—are fulfilled. Normal maintainer source/proof review is also complete. Its live-proof wrapper reported a terminal-command synchronization failure even though the included log shows 116 discovery tests passing; I am not counting that wrapper as a passing proof. Separate terminal-result reporting follow-up noted.

Completed proof: identical-order baseline and candidate suites each passed 317 tests; node scripts/check-changed.mjs -- src/plugins/discovery.ts src/plugins/discovery.test.ts passed; clean-machine node --import tsx scripts/build-all.mts passed in 10m40.3s. The isolated real CLI installed/inspected a packaged native plugin, linked TypeScript plugin and Claude bundle; two real Gateway starts verified native registration and linked-source revision change. That live command passed in 65.611s, with owned process/state and lease cleanup verified. Testbox run 33020081680; candidate identity is the verified source fingerprint and committed blobs, not the prepared runner HEAD. Local npm-pack proof is not official trust; real discovery-to-registry fixtures cover official-positive and archive/ambiguous-negative cases.

Proceeding through the repository-native preparation and merge gates. No rebase or source change was made after the reviewed proof.

@steipete
steipete merged commit 6f3cda9 into main Aug 26, 2026
276 checks passed
@steipete
steipete deleted the codex/architecture-cleanup-plugin-discovery branch August 26, 2026 23:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (26 commits)
  fix(plugins): preserve registry epoch on activation rollback (#129232)
  refactor(plugins): make discovery invocation-owned (#130486)
  feat(ui): save appearance preferences per user profile (#130340)
  fix: Buzz bots recover relay stalls and reject revoked senders (#130467)
  fix(code-mode): serialize catalog handles nested in final values (#130276)
  fix(webchat): CLI skill and harness-injected turns render as operator-sent messages (#130427)
  fix(agents): read the published model catalog owner from session_status (#130277)
  fix(channels): preserve long presentation text (#130368)
  fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
  refactor(plugins): unify setup registration and artifact selection (#130474)
  fix(memory): prevent forgotten session content from returning (#130451)
  refactor(outbound): consolidate transport completion (#130460)
  fix(workers): protect in-flight workspace manifests from concurrent retention (#130449)
  fix(portals): keep worker previews reachable and owned by the active environment (#130434)
  fix(config): keep core channels keys in the generated config schema (#120736)
  chore(deps): refresh dependencies after seven-day cooldown (#130296)
  fix(agents): remind exec models to quote shell metacharacters (#125485)
  fix(auth): honor shared-store ownership in temp-state exec and agent deletion (#130437)
  fix(openshell): preserve file writes during concurrent mirror commands (#130447)
  fix(workers): report full nodes as at capacity, not offline (#130445)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
Remove the cache-era split result assembly, unreachable recursive scans, and repeated scan-state plumbing. Derive preferred install paths and managed classification together while keeping their distinct exclusion semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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