Skip to content

refactor(plugins): decouple tool metadata from runtime loading - #132932

Merged
steipete merged 1 commit into
mainfrom
steipete/frosty-poitras-5d884f
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/frosty-poitras-5d884f

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #131503 — avoid repeated plugin preparation at startup.

What Problem This Solves

MCP command registration and catalog inspection still imported the plugin tool-construction runtime solely to read or attach tool metadata. The confirmed edge was mcp-cli.ts → agent-bundle-mcp-materialize.ts → plugins/tools.ts, where metadata accessors shared a module with loader imports. This is the separately scoped metadata-owner follow-up left out of the startup-preparation change above.

Why This Change Was Made

Move the existing metadata types, one WeakMap, and five helpers into a dependency-light canonical owner. Fresh/cached tool producers, wrapper copying, and metadata readers use that same owner. Plugin loading, registry/scope caches, optional grants, replay safety, local-media trust, side-effect policy, and approval decisions remain with their existing owners and retain their implementations.

Keep the shipped agent-harness SDK exports, retargeted directly to the new owner. Replace the old internal build-harness entry and migrate its MCP consumer; do not retain an unneeded compatibility barrel. Tests that previously used name-indexed metadata or a second WeakMap now tag concrete fixture tools through the actual owner, and clone-boundary coverage asserts preservation of the exact full metadata record. Extend the existing compiled-plugin singleton smoke to check that the public SDK reads the materializer's exact metadata record, after—not before—its existing cold-native loader assertions.

User Impact

No tool, permission, approval, configuration, or default changes. MCP metadata access no longer requires the plugin tool-construction module. The entire MCP CLI is not claimed to be loader-free: an independent transport/auth/provider import route remains a separate follow-up. This change does not claim an isolated startup-speed improvement or a fix for previously observed 30-second process timeouts.

Production LOC: +112/-101 (net +11). Tests/support: +319/-169 (net +150). Build tooling: +1/-1 (net 0). The small production increase is module/type-import scaffolding and split imports for the new ownership boundary, not a second store or new runtime policy.

Evidence

The branch was refreshed onto e7f6aaa2c3bb3651e13d79aa1e6989718fedd18b after GitHub reported conflicts. Current head is 30c5d9829c20c37e8c181acb73c0c359fe8eb980, tree cc347a81d3b3091004bd5488f3072b59b575aa40. The latest resolution preserves main's prepared tool-policy matcher and narrow provider-schema mock, while removing the obsolete metadata mock so the real normalizer/copier remain active. The earlier shared result renderer is also preserved. The metadata owner, helper/type bodies, and import-denial/materialization/native assertion sources are unchanged. Fresh review of the resolved full patch returned scoped-clean with no actionable P0 findings.

Current-head CI run 33294630435 passed, including the required openclaw/ci-gate from GitHub Actions on this exact head. The preceding head passed CI run 33288039766. The local/build/native evidence below belongs to the original pre-rebase candidate and is not represented as execution proof for this latest tree; current-head CI remains required before merge.

  • A real fresh Node/TSX import-denial regression failed on original production source at the materializer-to-plugins/tools edge, then passed on the restored candidate. It performs actual CLI registration/reload, projects a nonempty catalog, and checks inventory-only execution rejection. A separate metadata-leaf case forbids tool construction, loader imports, and channel serving. Both retain their 30-second child bounds; neither mocks the loader.
  • Initial metadata/materialization/runtime-plan/installed-bundle selection: 124 passed, including a real installed bundle and stdio tool. Actual loader suite: 183 passed, separately from mocked resolver tests.
  • Controlled original-source/candidate plugin-pair replay: 111 passed on each, in the same optional-tools-before-runtime-registry order with unchanged 120-second limits. Earlier two timeouts and a stopped broader run are retained as prior failures; the recovery does not establish their cause or a timeout fix.
  • Final hook/bridge selection: 176 before-call E2E, 153 Codex dynamic-tool, and 94 Copilot bridge tests passed (423 total), after the standard private E2E prerequisite build.
  • Normal build and all selected changed checks passed, including SDK exports/declarations/surface, core/UI/extension/script/test typechecks, lint, and the runtime import-cycle guard. No ineffective dynamic-import diagnostic was observed.
  • The existing compiled MCP harness passed against the normal local build with real stdio execution, metadata lookup across emitted entries, MCP App preview, final policy filtering, and custom-tools projection. Coding/messaging counts were 3/3; minimal/deny counts were 0/0. This was local built-output proof, not Docker or an installed npm tarball.

Commands used for the principal build/check and owner/bridge proofs:

pnpm build
node scripts/check-changed.mjs --base HEAD
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/plugins/tools.optional.test.ts src/plugins/loader.runtime-registry.test.ts
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/agent-tools.before-tool-call.e2e.test.ts src/agents/agent-tools.before-tool-call.integration.e2e.test.ts extensions/codex/src/app-server/dynamic-tools.test.ts extensions/copilot/src/tool-bridge.test.ts

Fresh pre-commit Codex autoreview returned scoped-clean, with no actionable P0 findings.

Clean Linux native proof also passed on Blacksmith Testbox run 33281891979, lease tbx_01m17yw2gkwa4scmt39748qjf3: exact base b3362142c72bcde6dae141e649826de10da0c000 and source tree 9cf9ed7549b680a792ff117290e9a61ab581d2ea were verified before execution and remained unchanged. Node 24.19.0, pnpm 12.0.0, frozen install, normal build, targeted script/tooling checks, and the existing native singleton smoke including the new SDK metadata-record assertion all passed. The command used isolated environment/HOME/state paths on a prepared CI machine; it was not a secretless-machine claim. The one-shot lease was stopped and its completed state verified. Its backing Actions lifecycle may show cancellation during Testbox cleanup; the command exit, exact source/success markers, and completed lease are the proof, not a PR-head CI gate.

The earlier broad native probes did not complete inside their task-local 30-second observation bounds. They remain failed observations; the canonical native smoke has no such per-command deadline, and no limit was changed. One pre-warmed Testbox attempt expired during local source preparation before any build/test ran; the supported one-shot flow corrected allocation ordering without extending a deadline. Timings were non-exclusive and do not isolate this edge's cost. No loader mock, test-mode flag, schema, or dependency workaround was added. Exact PR-head CI remains required before merge.

AI-assisted implementation and independent review.

@clawsweeper

clawsweeper Bot commented Aug 30, 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 gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added 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 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 2:35 AM ET / 06:35 UTC.

ClawSweeper review

What this changes

The branch moves plugin-tool ownership metadata into a lightweight module and retargets CLI, agent, Gateway, SDK, build, and test consumers away from the plugin tool-construction runtime.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The refactor remains necessary: current main still keeps plugin-tool metadata inside the runtime-loading module. Source review found the single WeakMap and SDK behavior preserved, with no introduced correctness or security defect; this member-authored, maintainer-labeled PR needs normal maintainer handling rather than automated closure.

Priority: P3
Reviewed head: 30c5d9829c20c37e8c181acb73c0c359fe8eb980
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving extraction with direct boundary and metadata-identity coverage has normal good merge quality.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is member-authored; the external-contributor real-behavior-proof gate does not apply, while the supplied exact-head CI and built artifact evidence remain supplemental.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is member-authored; the external-contributor real-behavior-proof gate does not apply, while the supplied exact-head CI and built artifact evidence remain supplemental.
Evidence reviewed 5 items Current-main necessity: Current main still declares the metadata WeakMap and accessors in the broad plugin tool-runtime module; it does not contain the new lightweight owner.
Single metadata owner: The introduced module retains one WeakMap and the existing set, get, copy, collision-key, and side-effect-owner helpers, while the runtime factory now delegates metadata attachment to it.
Import-boundary coverage: The added CLI-process test installs a resolver guard, exercises MCP reload plus catalog-only materialization, and rejects any import of the former tool-runtime or channel-serving module.
Findings None None.
Security None None.

How this fits together

Plugin tool factories attach ownership and MCP metadata that agent policy, CLI cataloging, and Gateway dispatch consume later. The new metadata owner separates that record from runtime plugin loading while preserving the same tool-instance identity.

flowchart LR
  A[Plugin tool factory] --> B[Tool metadata owner]
  B --> C[MCP materialization]
  B --> D[Agent and Gateway policy]
  C --> E[CLI catalog and tool list]
  D --> F[Tool dispatch]
  E --> F
Loading

Decision needed

Question Recommendation
Should this protected member-authored refactor be accepted after normal maintainer review? Accept the extraction: Merge after normal maintainer approval, preserving the single metadata store and retained SDK accessors.

Why: Repository policy keeps member-authored and maintainer-labeled items open for explicit maintainer handling even when automated review finds no defect.

Before merge

  • Complete next step (P2) - The author is a member and the PR carries the protected maintainer label, so it must remain open for normal maintainer handling rather than automated repair or closure.
Agent review details

Security

None.

PR surface

Source +7, Tests +107, Other +47. Total +161 across 73 files.

View PR surface stats
Area Files Added Removed Net
Source 38 114 107 +7
Tests 33 270 163 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 48 1 +47
Total 73 432 271 +161

Review metrics

Metric Value Why it matters
Production versus test delta production +113/-102 (net +11); tests +271/-168 (net +103); tooling +48/-1 (net +47) The modest production increase is the extracted metadata owner and import rewiring; most growth is boundary and identity coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/test-helpers/fast-tool-stubs.ts, unknown-data-model-change: src/plugins/tool-metadata.ts, vector/embedding metadata: scripts/test-built-plugin-singleton.mts, vector/embedding metadata: src/agents/agent-bundle-lsp-runtime.ts, vector/embedding metadata: src/agents/agent-bundle-mcp-harness.ts, vector/embedding metadata: src/agents/agent-bundle-mcp-materialize.ts, and 35 more. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Land the dependency-light metadata owner while retaining the existing SDK accessors and tool-instance metadata identity.

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

Not applicable: this PR refactors an internal module boundary rather than reporting a user-facing failure; the relevant behavior is covered by source-level import-boundary and metadata-identity tests.

Is this the best way to solve the issue?

Yes. Moving the existing record into one dependency-light owner removes the unnecessary runtime-loading edge without adding a parallel store or compatibility barrel.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 136eab023035.

Labels

Label justifications:

  • P3: This is a behavior-preserving internal loading-boundary refactor with no configuration or user-flow change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is member-authored; the external-contributor real-behavior-proof gate does not apply, while the supplied exact-head CI and built artifact evidence remain supplemental.

Evidence

What I checked:

Likely related people:

  • steipete: 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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-30T00:22:37.667Z sha afd6240 :: needs maintainer review before merge. :: none
  • reviewed August 29, 2026, 8:36 PM ET / August 30, 2026, 00:36 UTC sha unknown :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T02:35:27.383Z sha 493aa38 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T02:49:53.019Z sha 493aa38 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T05:31:25.123Z sha 30c5d98 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 30, 2026
@steipete
steipete force-pushed the steipete/frosty-poitras-5d884f branch from afd6240 to 493aa38 Compare August 30, 2026 02:27
@steipete
steipete marked this pull request as ready for review August 30, 2026 02:27
@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 30, 2026
Move tool metadata into one dependency-light owner so catalog and MCP
materialization no longer import the plugin tool-construction runtime.
Keep the single metadata store, shipped SDK exports, record identity,
and tool semantics unchanged; migrate internal readers and producers.

Cover the boundary with original-source import-denial reproduction and
native loader/SDK metadata singleton proof on the exact candidate tree.
Follow up on the startup preparation cleanup in #131503.
@steipete
steipete force-pushed the steipete/frosty-poitras-5d884f branch from 493aa38 to 30c5d98 Compare August 30, 2026 05:24
@steipete

steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Post-merge correction — 2026-08-30

The merged tree contained an incoming caller that this extraction missed: src/agents/embedded-agent-runner/run/code-mode-reconciliation.ts:2 still imported getPluginToolSideEffectOwnerKey from plugins/tools.js. The Code Mode recovery change in a7a1d05a46c6 added that then-valid import after the reviewed base; this metadata extraction subsequently removed the old export. My final incoming-main review checked overlap with the patch's files rather than all consumers of the removed exports, so it missed this caller. The green reviewed-head CI did not establish that final composition.

Eden's one-line canonical-owner repair, PR #133155, is merged as be5e79ca4713. It changes only that import to plugins/tool-metadata.js (+1/-1 production), retaining the single metadata store and keeping the obsolete exports removed. I verified the live merge, exact raw-parent patch, and reachability from current main; the fix PR records passing core type-check proof. No duplicate repair was published here, and this session did not rerun the build. The companion final composition proof records 159 passing tests across seven files on canonical main at bed5daf176f6d7552b27b7c87d33e7d201dd82f6: 143 MCP/runtime/harness/auth/lifecycle tests, 15 recovery tests, and one full-attempt recovery boundary test, with unchanged source and a clean checkout. The validation session additionally reports a passing full build, compiled MCP metadata/profile-policy/App-preview smoke, and isolated public Context7 CLI flow on tree c2d821bfb52ec6b28f63a97763f034b58b58a7a2: public base 41dccabf17967bcc64d6caf7a40334e6f5dca363 plus the byte-identical canonical caller repair. That build is not presented as a build of later main or a new Docker/npm installation. All validation jobs in that lane are terminal.


Land-ready for reviewed head 30c5d9829c20c37e8c181acb73c0c359fe8eb980 (tree cc347a81d3b3091004bd5488f3072b59b575aa40). Exact-head CI run 33294630435 passed, including required openclaw/ci-gate. Fresh independent scoped autoreview found no actionable P0 defects. Native review validation and preparation passed; preparation retained the same source head and verified the remote tree rather than rebasing again for unrelated mainline movement.

The latest ClawSweeper review found no correctness/security defect and asks for explicit maintainer handling. This landing is proceeding under the maintainer's explicit rebase-and-land request, not an automated closure. Its persistent-data classification does not apply: the change relocates one process-local WeakMap and its existing accessors; it changes no persisted state, database schema, serialization, or vector/embedding storage.

Exact native commands, with the installed protected GitHub shim retained:

env -u GITHUB_TOKEN -u GH_TOKEN -u HOMEBREW_GITHUB_API_TOKEN OPENCLAW_GH_BIN="$(command -v gh)" scripts/pr review-validate-artifacts 132932
env -u GITHUB_TOKEN -u GH_TOKEN -u HOMEBREW_GITHUB_API_TOKEN OPENCLAW_GH_BIN="$(command -v gh)" OPENCLAW_TESTBOX=1 scripts/pr prepare-run 132932

The PR body preserves the original-candidate red/green import-denial proof, actual loader/stdio tests, normal build and clean Linux native/SDK singleton proof. Those historical runs are not relabeled as execution of this rebased tree. Earlier timing failures remain recorded; no timeout increase or isolated speedup claim is made. The separate transport/auth/provider loader route remains outside this extraction.

Production +112/-101 (net +11); tests/support +319/-169 (net +150); build tooling +1/-1. The production increase is import/type scaffolding for the lightweight owner. Metadata identity, copying, optional/replay/media/side-effect semantics, existing SDK accessors and approval/authority implementations are preserved.

@steipete
steipete merged commit 87b7121 into main Aug 30, 2026
241 checks passed
@steipete
steipete deleted the steipete/frosty-poitras-5d884f branch August 30, 2026 07:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…aw#132932)

Move tool metadata into one dependency-light owner so catalog and MCP
materialization no longer import the plugin tool-construction runtime.
Keep the single metadata store, shipped SDK exports, record identity,
and tool semantics unchanged; migrate internal readers and producers.

Cover the boundary with original-source import-denial reproduction and
native loader/SDK metadata singleton proof on the exact candidate tree.
Follow up on the startup preparation cleanup in openclaw#131503.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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