Skip to content

fix(plugins): keep tool metadata and callbacks on the same factory instance - #139828

Merged
steipete merged 1 commit into
mainfrom
codex/plugin-tool-factory-context
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/plugin-tool-factory-context

Conversation

@steipete

@steipete steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where plugin tools could show stale descriptions, schemas, or progress visibility in later turns even though their callbacks came from the current factory. Tools built on the first resolution also lacked the retirement checks applied by the warm path.

Why This Change Was Made

Tool assembly now uses one current factory instance for metadata, argument preparation, and execution. The descriptor cache and its separate retained-runtime path are removed. Callbacks capture the existing registry/record authority once, preserving recordless SDK registrations and independently scoped registries while rejecting retired or invalidated owners. Production code decreases by 710 lines.

User Impact

Factory-created tools reflect their current context consistently. New calls through retained tool callbacks fail after their owner retires, is disabled or removed, or is reactivated as a new generation.

Evidence

  • Original code failed the stale-metadata regression and both direct and spread cold-tool retirement cases.
  • 105 tool tests and four real generated-plugin cron preparation cases passed.
  • Full changed-file checks, final targeted test typecheck, and independent P2 review passed before the mechanical rebase. The patch ID and production bytes are unchanged; all 105 tool tests and the filesystem smoke passed again on the rebased commit with refreshed dependencies.
  • Exact-commit generated-plugin smoke passed through the real loader and tool assembly: two contexts produced fresh descriptions, schemas, summaries and progress metadata; preparation and execution shared each factory instance. Four admitted executions plus their preparations wrote eight filesystem events. Four later preparations and four executions were rejected after registry retirement or authoritative record disablement, with no additional writes. The process exited normally and source remained unchanged.
  • The filesystem smoke uses isolated synthetic state. It does not exercise Gateway reload RPC, mid-await revocation, or sandbox isolation.

Related: #135599. This is an independently landable foundation for that plugin lifecycle work. The existing callback Proxy limitation around fixed properties remains in that ownership consolidation; this PR does not expand that contract.

Assemble schemas, display metadata, preparation, and execution from the same current factory instance. Remove the descriptor cache and its retained-runtime path; use existing registry and record lifecycle authority for both cold and warm callbacks.

Preserve recordless SDK registrations and never-activated scoped registries. Reject retained callbacks after retirement, record disablement or removal, and reactivation. Production LOC: -710. Validated 105 tool tests, four real cron preparation cases, the changed-file gate, focused final test types, and independent P2 review.
@clawsweeper

clawsweeper Bot commented Sep 6, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XL maintainer Maintainer-authored PR labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 6, 2026, 3:02 AM ET / 07:02 UTC.

ClawSweeper review

What this changes

Plugin tools now obtain metadata, argument preparation, and execution from one current factory instance, with retained callbacks rejected after their registry or record loses authority.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful, independently landable fix: current main and the latest release retain the metadata mismatch. No introduced correctness defect was found. The prior retirement warning describes an intentional, documented behavior change rather than an unresolved finding.

Priority: P2
Reviewed head: 7654007084f90942898a5ff981ebed5baebbf1b9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with meaningful regression coverage and sufficient reported production-boundary proof; no actionable patch defect was found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured exact-head filesystem smoke exercises the real loader and tool assembler, reports fresh metadata and shared factory callbacks, and observes no further writes when retired or disabled owners invoke retained callbacks. It proves this admission boundary, not mid-await cancellation, Gateway reload, or sandbox isolation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured exact-head filesystem smoke exercises the real loader and tool assembler, reports fresh metadata and shared factory callbacks, and observes no further writes when retired or disabled owners invoke retained callbacks. It proves this admission boundary, not mid-await cancellation, Gateway reload, or sandbox isolation.
Evidence reviewed 10 items Introduced change: The verified merge-base-to-head diff removes the descriptor cache and introduces lifecycle checks around preparation and execution. Base-only changes are excluded from this assessment.
Problem remains on main: Current main still combines cached description and input schema with a newly resolved runtime tool, allowing metadata and callbacks to describe different factory results.
Latest-release comparison: The supplied latest release, v2026.9.2, also contains cached descriptor assembly; its callback wrapper lacks the newly introduced lifecycle admission check.
Findings None None.
Security None None.

How this fits together

Plugin tool assembly combines manifest eligibility, runtime context, and plugin factories into tools presented to agents and MCP clients. Those tools expose schemas and descriptions, then invoke plugin callbacks under their owning registry.

flowchart TD
  A[Plugin manifests and tool policy] --> C[Tool assembly]
  B[Current runtime context] --> C
  C --> D[Current plugin factory instance]
  D --> E[Tool metadata and schemas]
  D --> F[Callback authority check]
  F --> G[Prepare arguments or execute]
  F --> H[Reject inactive owner]
Loading

Before merge

  • Resolve merge risk (P1) - Retained tool handles intentionally begin rejecting calls after owner retirement or invalidation; consumers crossing that boundary must assemble fresh tools. The supplied smoke covers scoped and recordless registrations, not arbitrary third-party retention patterns.
Agent review details

Security

None.

PR surface

Source -710, Tests -319, Docs +2, Other -1. Total -1028 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 23 733 -710
Tests 4 89 408 -319
Docs 1 7 5 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 2 -1
Total 9 120 1148 -1028

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Accept the documented handle lifetime (recommended)
    Retain rejection of invalidated handles as explicitly intended by the author, with fresh assembly supplying tools for replacement generations.

Technical review

Best possible solution:

Adopt the author-documented generation-bound lifetime and single factory path while preserving valid recordless and independently scoped plugin registrations.

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

Yes, from source: resolve a factory twice with changed descriptions or progress metadata while retaining the same cache identity; main reuses the old descriptor with current callbacks. No runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Yes. Removing the competing descriptor path fixes the producer-level mismatch, and reusing existing lifecycle authority avoids a second ownership mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7feeda9b49ce.

Labels

Label justifications:

  • P2: This repairs context-dependent plugin metadata and callback lifetime behavior with a bounded runtime impact.
  • merge-risk: 🚨 compatibility: Previously callable retained handles now reject after owner invalidation, an intentional plugin callback behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured exact-head filesystem smoke exercises the real loader and tool assembler, reports fresh metadata and shared factory callbacks, and observes no further writes when retired or disabled owners invoke retained callbacks. It proves this admission boundary, not mid-await cancellation, Gateway reload, or sandbox isolation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured exact-head filesystem smoke exercises the real loader and tool assembler, reports fresh metadata and shared factory callbacks, and observes no further writes when retired or disabled owners invoke retained callbacks. It proves this admission boundary, not mid-await cancellation, Gateway reload, or sandbox isolation.

Evidence

What I checked:

  • Introduced change: The verified merge-base-to-head diff removes the descriptor cache and introduces lifecycle checks around preparation and execution. Base-only changes are excluded from this assessment. (src/plugins/tools.ts:90, 7654007084f9)
  • Problem remains on main: Current main still combines cached description and input schema with a newly resolved runtime tool, allowing metadata and callbacks to describe different factory results. (src/plugins/tools.ts:735, 7feeda9b49ce)
  • Latest-release comparison: The supplied latest release, v2026.9.2, also contains cached descriptor assembly; its callback wrapper lacks the newly introduced lifecycle admission check. (src/plugins/tools.ts:755, 3928bad9badf)
  • Existing lifecycle owner: The unchanged authority helper checks captured registry generation, retirement, record membership, enablement, loaded status, and record generation. The new wrapper checks it immediately before invoking each callback; it does not claim cancellation of already admitted plugin work. (src/plugins/registry-lifecycle.ts:146, 7654007084f9)
  • Regression and compatibility coverage: Inspected tests cover fresh metadata, matching execution context, cold and warm retained handles, direct and spread callbacks, registry reactivation, disabled or removed records, recordless registrations, and independently scoped registries. Tests were inspected, not executed during this read-only review. (src/plugins/tools.optional.test.ts:2425, 7654007084f9)
  • Reported production-boundary proof: The complete captured PR body reports an exact-head generated-plugin run through the real loader and tool assembly: two contexts exposed fresh metadata, four executions plus preparations produced eight filesystem events, and four subsequent preparations plus four executions were rejected after retirement or disablement without additional writes. This is contributor-reported observation, not reviewer execution. Captured context sourceRevision: 47137df7ade4a1ca09ac38cf8b98f93535d669f02b1c3758d67d7c331928ee0e. (7654007084f9)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ted Li: 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 (1 earlier review cycle)
  • reviewed 2026-09-06T06:20:51.593Z sha 7654007 :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 6, 2026 06:58
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

The retained-handle lifetime is intentional and accepted for this plugin lifecycle redesign. A tool callback belongs to the registry generation and plugin record that created it; after retirement, disablement, removal, or generation replacement, the consumer must assemble fresh tools. Letting an old handle silently select a replacement factory would mix generations again.

The documented behavior and current consumers were reviewed alongside the existing lifecycle authority owner. The regression and filesystem proof cover cold/warm callbacks, direct/spread copies, recordless SDK registrations, independently scoped registries, disabled/removed records, and reactivation. Calls already admitted are not cancelled by this slice; Gateway reload and full resource ownership remain in #135599. No arbitrary third-party retention compatibility is claimed.

@steipete
steipete merged commit 43a9c97 into main Sep 6, 2026
248 checks passed
@steipete
steipete deleted the codex/plugin-tool-factory-context branch September 6, 2026 08:10
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Assemble schemas, display metadata, preparation, and execution from the same current factory instance. Remove the descriptor cache and its retained-runtime path; use existing registry and record lifecycle authority for both cold and warm callbacks.

Preserve recordless SDK registrations and never-activated scoped registries. Reject retained callbacks after retirement, record disablement or removal, and reactivation. Production LOC: -710. Validated 105 tool tests, four real cron preparation cases, the changed-file gate, focused final test types, and independent P2 review.
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 maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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