Skip to content

fix(plugins): retire model-catalog scratch captures with their run - #155159

Merged
steipete merged 1 commit into
mainfrom
upd/catalog-scratch-capture-retirement
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/catalog-scratch-capture-retirement

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #154571 and #154973. Thanks @mulderp82 and @podulator for the reports and nested-directory measurements.

What Problem This Solves

Model-catalog discovery makes a second complete source capture for an external plugin whose runtime is already loaded, increasing the size of its worker scratch tree.

User Impact

Catalog discovery reuses the selected runtime's captured package and lifetime. Repeated refreshes keep one capture per plugin, and discovery callbacks cannot outlive their runtime owner. Standalone discovery keeps its existing setup lifetime. No configuration, dependency, or SQLite schema changes.

Why This Change Was Made

The provider-discovery loader now uses the existing public-surface loader only when the selected generation and current context identify the same loaded runtime owner. Derived catalog preparation refreshes discovery callbacks when its runtime registry changes, so releasing a predecessor cannot poison successor auth refreshes.

Current main already has the SQLite ownership and worker-retirement fixes that postdate 2026.9.5: cleanup after confirmed worker exit, abandoned-owner startup reclamation, CLI-exit disposal, and Doctor removal of complete legacy catalog trees. This change preserves those owners and strengthens nested-tree coverage. idleTimeoutMs: 0 keeps an active inventory warm; it does not disable explicit close. No fd/map or age-only liveness heuristic is introduced.

Evidence

The same Testbox fixture used two external plugins, each with a 1 MiB payload, across four agents and repeated catalog/auth refreshes. Sizes count regular files without following host-package symlinks.

State Capture directories Apparent bytes Allocated file bytes
Original loader 4 4,225,040 4,259,840
Patched loader 2 2,112,520 2,129,920
After repeated refreshes 2 2,112,520 2,129,920
Owner closed 0 0 0
  • The two-plugin regression failed on the original loader with expected 4 to be 2, then passed after the fix. Test time 2.086 s; runner wall 19.53 s. The existing pool case was moved into a focused file and extended, preserving its source-version and per-agent auth-isolation assertions.
  • A derived-generation regression failed with PluginInstanceUnavailableError after predecessor retirement, then passed with refreshed successor callbacks (840 ms test; 30.61 s runner wall). Exact-source and distinct-registry fallback cases passed in 87 ms (29.75 s wall).
  • The initial size probe used Node recursive readdir, which follows directory symlinks into the host package and caused a worker exit after 101.93 s. An isolated symlink canary confirmed the cause; explicit traversal of real directories fixed it without changing timeouts or assertions.
  • Focused owner/sibling coverage: 123 tests passed across the runs, including the final 45-test agent replay, live SQLite custody, SIGKILL followed by startup reclamation, worker retirement, and Doctor's nested-tree removal/live-process refusal. pnpm build passed in 6m 54.4s. All selected check:changed steps passed: after fixing a redundant assertion and two test lint issues, the exact failed lint and remaining guards were resumed through the repository command owners; nothing was skipped.
  • Independent P1 review of the complete ownership/callback change: scoped-clean.
  • Blacksmith Testbox lease tbx_01m32kaajm9jgbt56vrw9d6pv1 (run).

Production +34/-12 (net +22); tests +450/-105 (net +345, including the moved pool case); docs +20/-1.

A documentation conflict with the already-landed ClickClack troubleshooting entry was resolved by retaining both sections. Production/test blobs are unchanged by that rebase.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 20:13
@steipete
steipete enabled auto-merge (squash) September 21, 2026 20:17
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 4:22 PM ET / 20:22 UTC.

ClawSweeper review

What this changes

Model-catalog discovery reuses an already-loaded plugin’s captured files and refreshes callbacks when its runtime changes, with regression coverage and cleanup documentation.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a focused, useful repair that fetched main still lacks. The ownership checks and successor-callback refresh are coherent, and no introduced correctness or security defect was found.

Priority: P1
Reviewed head: 03816268bf4dfa35e8cb87a2221d5ba5cefbb94e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with meaningful regression coverage and reported filesystem measurements; no actionable defect was found.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied Testbox measurements exercise real catalog-worker captures and owner closure; inspected regressions also cover retired callbacks and distinct-registry fallback.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied Testbox measurements exercise real catalog-worker captures and owner closure; inspected regressions also cover retired callbacks and distinct-registry fallback.
Evidence reviewed 9 items Pinned introduction reviewed: Reviewed the merge-base-to-head delta, keeping base-only daemon and approval changes outside this PR’s ownership. The introduced production changes are confined to discovery loading and prepared catalog reuse.
Exact runtime ownership: Reuse requires agreement between the selected generation and current registry plus a loaded record matching the plugin identity and root. Otherwise the existing setup loader remains in use.
Existing lifetime enforcement retained: The public-surface loader resolves the owning instance and calls its loadModule operation, which wraps exports with that instance’s invocation and retirement checks. This reuses an existing contract without adding a plugin API or a second cleanup owner.
Findings None None.
Security None None.

How this fits together

OpenClaw builds its model catalog from plugin metadata and provider discovery callbacks. External plugins run from captured package files, whose lifetime must follow the runtime that owns them.

flowchart TD
  A[Plugin metadata] --> B[Provider discovery]
  C[Selected runtime registry] --> B
  B --> D{Matching loaded owner?}
  D -->|Yes| E[Reuse runtime capture]
  D -->|No| F[Separate setup lifetime]
  E --> G[Model catalog and auth facts]
  F --> G
  E --> H[Retire with runtime owner]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +22, Tests +345, Docs +19. Total +386 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 2 34 12 +22
Tests 5 450 105 +345
Docs 2 20 1 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 504 118 +386

Review metrics

Metric Value Why it matters
Reported capture footprint 4 → 2 captures; 50% fewer allocated file bytes The supplied two-plugin measurement stays flat through refreshes and reaches zero after owner closure.
Production versus regression coverage Production net +22 lines; tests net +345 lines Production growth connects existing lifetime owners; most added coverage protects capture bounds, callback retirement, and nested cleanup.

Technical review

Best possible solution:

Keep discovery source and callbacks under the selected runtime’s existing lifetime while preserving standalone setup ownership and safe legacy cleanup.

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

Yes, source establishes the duplicate setup capture and stale callback reuse, and the PR records failing-before/passing-after regressions. This read-only review did not independently execute them.

Is this the best way to solve the issue?

Yes: reusing the existing instance loader and rebuilding callbacks only when registry identity changes repairs the ownership boundary without new configuration, storage, or cleanup machinery.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The repair addresses excess plugin captures in a model-catalog workflow associated with substantial disk and memory pressure on current-release installations.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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: The maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied Testbox measurements exercise real catalog-worker captures and owner closure; inspected regressions also cover retired callbacks and distinct-registry fallback.

Label justifications:

  • P1: The repair addresses excess plugin captures in a model-catalog workflow associated with substantial disk and memory pressure on current-release installations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied Testbox measurements exercise real catalog-worker captures and owner closure; inspected regressions also cover retired callbacks and distinct-registry fallback.

Evidence

What I checked:

  • Pinned introduction reviewed: Reviewed the merge-base-to-head delta, keeping base-only daemon and approval changes outside this PR’s ownership. The introduced production changes are confined to discovery loading and prepared catalog reuse. (03816268bf4d)
  • Exact runtime ownership: Reuse requires agreement between the selected generation and current registry plus a loaded record matching the plugin identity and root. Otherwise the existing setup loader remains in use. (src/plugins/provider-discovery.runtime.ts:104, 03816268bf4d)
  • Existing lifetime enforcement retained: The public-surface loader resolves the owning instance and calls its loadModule operation, which wraps exports with that instance’s invocation and retirement checks. This reuses an existing contract without adding a plugin API or a second cleanup owner. (src/plugins/plugin-module-loader-cache.ts:491, 03816268bf4d)
  • Successor callbacks are rebuilt: Prepared discovery callbacks are reused only when the runtime registry is identical. The new regression retires the predecessor and checks that a subsequent auth refresh uses the successor’s credentials. (src/agents/prepared-model-runtime.facts.ts:295, 03816268bf4d)
  • Still necessary on fetched main: Fetched main still unconditionally acquires the separate setup loader for discovery and reuses the previous prepared catalog whenever a reusable generation exists. The branch’s two central repairs are therefore absent from this main snapshot. (src/plugins/provider-discovery.runtime.ts:73, a7c27c04a3d6)
  • Behavioral coverage and supplied measurements: The captured PR body reports a Testbox fixture with two external plugins and four agents: four captures before the repair, two after repeated refreshes, and zero after close. The inspected integration test exercises the production catalog worker, measures real files without following symlinks, and preserves source-version and per-agent auth-isolation assertions. The body also reports pre-fix failures, focused validation, and a successful build; this review did not execute tests. (src/agents/prepared-model-catalog-worker.captures.integration.test.ts:31, 03816268bf4d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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.

@steipete
steipete merged commit 07435fa into main Sep 21, 2026
268 checks passed
@steipete
steipete deleted the upd/catalog-scratch-capture-retirement branch September 21, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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