Skip to content

improve: reduce repeated plugin package ownership work - #138716

Merged
steipete merged 2 commits into
mainfrom
codex/perf-sep04-package-ownership-scan
Sep 5, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-sep04-package-ownership-scan

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

Keep Allow edits from maintainers enabled.

What Problem This Solves

Plugin package update planning and reconciliation repeat ownership work as they walk packages and runtime children. That repeated work grows with installed package inventories.

Why This Change Was Made

One resolver now prepares ownership facts for each synchronous phase, replacing the two standalone package/lifecycle resolution paths and repeated scans at internal callers. Capture and replacement reconciliation create separate resolvers; yielding or replacing paths requires a fresh resolver. First-match identity, duplicate-preserving child order, physical-path conflicts, orphan cleanup rules, and fresh returned child arrays stay intact.

Production is +148/−143, net +5 lines. The added factory lifetime replaces repeated preparation across eight internal callers/owners; it introduces no process cache, configuration, SDK, or storage contract. Tests and support are +307/−233, net +74, including a shared typed fixture and ownership-suite extraction.

User Impact

No intended behavior change. The complete capture/reconciliation component is faster on the populated fixtures below, with explicit construction costs on empty and early-error paths. This is not a whole-CLI, management-inventory, Gateway, cold-start, or memory improvement claim.

Evidence

Before/candidate whole-file proof passed the same 333 cases across 18 files, including consent, inventory, owner routing, install/uninstall/update, lifecycle and chat paths. After the test-only extraction, both complete resulting suites passed all 22 moved/retained cases, with byte-identical moved bodies and preserved case names and within-file order. The first normal changed gate failed the registry test's 1,000-line lint limit; its failure is retained. Extracting the two complete ownership cases and sharing the existing typed fixture fixed it without changing ratchets, limits, or production. The successor normal pinned-base gate passed all 30 stages.

Managed Codex P0–P2 review returned scoped-clean, no accepted findings, across three passes (aggregate confidence 0.80). Each pass saw its assigned evidence; the full report retains its per-pass unchanged-caller/dependency context limitations. No reviewer executed product code.

The fixed B0/C0/C1/B1 study times the actual exported capture operation and reconciliation on capture success, including resolver construction on every invocation. It retained 4,694 complete output envelopes, 8,210 exported calls, 512 measured batch means, 372 comparisons, and all 187 adverse comparisons. Full outputs, own-undefined fields and public identity/array-preservation assertions passed. Raw-first arithmetic exactly matched the retained report. That arithmetic auditor also authored the harness; separate source reviewers inspected it.

Complete capture/reconciliation row Median delta, forward / reverse Absolute delta, forward / reverse
Empty inventory +532.67% / +524.85% +1.318 / +1.326 µs
32 packages, zero selection +6762.79% / +6538.54% +19.198 / +20.094 µs
Single package -37.33% / -36.98% -28.380 / -28.276 µs
Missing owner, early error +215.83% / +239.06% +6.464 / +6.599 µs
Ownerless bundled entry, early error +539.58% / +600.78% +2.164 / +2.221 µs
Eight packages -57.43% / -55.54% -3585.612 / -3456.125 µs
32 packages -57.66% / -59.54% -59030.435 / -61760.190 µs
Eight changed packages plus orphan/migration -46.44% / -46.12% -4918.812 / -4835.948 µs

Sampled tree RSS increased +2.064% / +2.322%; kernel child peaks increased +1.658% / +2.020%. Both include setup, validation and retained evidence, and sampling can miss peaks. The zero-selection row's maximum batch mean regressed +69.521 / +31.182 µs and its first observations +97.792 / +107.792 µs. Empty, missing-owner and bundled-error tails also remain adverse. Every first, warm, matched batch, tail and RSS comparison is retained; none was rerun or removed. Here p95 of 16 batch means equals their maximum, not individual-call p95. There is no aggregate numerical pass threshold.

All six native hosts and the functional/gate processes closed; sources were restored and checked. First observations follow imports/fixture setup and earlier rows, so they are not independently cold filesystem or process samples. Source/dependency binding is selected, not an exhaustive loaded-image inventory. The immutable report digest is 870c605939e952ed887de10edd1d1622dc5df79eb153381d147c4d281f0d9d69.

A separate follow-up remains: management inventory historically omits its supplied custom environment when resolving ownership. This patch preserves that behavior; it does not claim to fix it. All nine existing touched files are unchanged between the measured base and inspected main 06759ea. Fresh hosted CI remains required before landing.

CI correction: the first published head exposed a missed test caller of the removed scalar ownership resolver. The existing Docker-probe test now constructs the same canonical phase resolver with its loaded index and fixture environment. Before the correction, the complete file reproduced exactly two failures; after it, all 18 cases pass in the same order. The normal incremental 15-stage gate (including root test typechecking) and independent Codex P0–P2 review passed. This adds no production lines and changes two test lines. All eight production owners and the original measurements remain unchanged. Fresh hosted CI is still required; this local macOS proof is not a claim that the whole prior Linux shard passed.

Current landing evidence: exact-head CI run 33933305230 passed, including the aggregate gate. The pinned fs-safe dependency source and its phase-local cache contract were directly inspected; the review disposition addresses the remaining ClawSweeper dependency gap and rank-up move. No production or numerical result changed.

Keep capture and replacement reconciliation in separate synchronous resolver lifetimes. Preserve package identity, duplicate child ordering, conflict checks and independent result arrays while removing repeated preparation from internal callers.
@clawsweeper

clawsweeper Bot commented Sep 5, 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 cli CLI command changes size: L maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 8:43 PM ET / September 5, 2026, 00:43 UTC.

ClawSweeper review

What this changes

The PR prepares plugin package ownership once per synchronous operation phase, reuses those facts across management commands, and updates ownership tests without intentionally changing plugin behavior.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this remains a useful optimization absent from fetched main, and no introduced correctness defect was found. The maintainer-authored PR is not a cleanup-close candidate.

Priority: P2
Reviewed head: 59cf0b7ececa37309019391084d43ac933e19eb8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary optimization with preserved safeguards, useful regression coverage, and candidly bounded performance claims; no blocking code finding was identified.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor gate does not apply to this maintainer-authored internal refactor, and no material authority change was found. The captured body reports matching exported capture/reconciliation outputs and populated-inventory speedups; the raw study was not independently inspected.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this maintainer-authored internal refactor, and no material authority change was found. The captured body reports matching exported capture/reconciliation outputs and populated-inventory speedups; the raw study was not independently inspected.
Evidence reviewed 12 items Pinned introduction and clean checkout: The repository remote identifies openclaw/openclaw, HEAD matches the pinned original head, and the merge-base-to-head diff contains the supplied twelve introduced paths. The separate endpoint drift was not attributed to this PR. Final status was clean and diff whitespace checks passed.
Ownership invariants preserved: The factory preserves first-match plugin identity, sorted duplicate-preserving children, fresh returned arrays, duplicate-path rejection, and exact orphan handling. The unchanged install-owner reader returns no owner for ambiguous records, supporting removal of the redundant ambiguity predicates.
Separate capture and replacement phases: Capture and reconciliation each construct their own resolver. The CLI loads the replacement index after installation and later recaptures ownership before persistence; it does not reuse the earlier resolver across those awaits. Its package-child mapping now comes from the already-validated capture snapshot.
Findings None None.
Security None None.

How this fits together

Plugin management maps discovered plugin entries to their installed package and checks conflicting ownership before inspection, consent, update, or removal. The resolver consumes the installed index and package paths, then returns the package owner and its child entries or a diagnostic.

flowchart TD
  A[CLI and management requests] --> B[Installed plugin index]
  B --> C[Phase-local ownership resolver]
  D[Package filesystem paths] --> C
  C --> E{Ownership consistent?}
  E -->|Yes| F[Package owner and child entries]
  E -->|No| G[Diagnostic without mutation]
  F --> H[Inspect or plan package lifecycle]
Loading

Before merge

  • Resolve merge risk (P1) - Independent inspection of the pinned filesystem dependency's caller-provided realpath cache contract remains incomplete; this is a reviewer limitation, not evidence of a contributor defect.
  • Complete next step (P2) - Verify the caller-provided realpath-cache contract in pinned @openclaw/fs-safe 0.7.2 before merge; its implementation was unavailable to this reviewer.
Agent review details

Security

None.

PR surface

Source +5, Tests +74. Total +79 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 148 143 +5
Tests 4 307 233 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 455 376 +79

Review metrics

Metric Value Why it matters
Production versus test growth Production net +5 lines; tests and test support net +74 lines The small production increase centralizes preparation across eight production callers; extracted tests and fixture movement are not counted as new behavioral coverage.
Reported component performance 32-package median −57.66% / −59.54%; zero-selection +19.198 / +20.094 µs The forward/reverse study includes resolver construction and exposes the tradeoff rather than claiming a whole-CLI improvement.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one synchronous, phase-local ownership resolver, recreate it after package replacement or asynchronous work, and preserve existing routing without public API or persistent-cache growth.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one synchronous, phase-local ownership resolver, recreate it after package replacement or asynchronous work, and preserve existing routing without public API or persistent-cache growth.

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

Not applicable as a bug reproduction: this is a behavior-preserving performance refactor. Repeated preparation is visible in fetched-main source, but this read-only review did not execute a benchmark or tests.

Is this the best way to solve the issue?

Yes for the architectural approach: reuse belongs in the existing ownership owner, with separate capture and reconciliation lifetimes, rather than a process cache or caller-specific implementations. Independent verification of the pinned filesystem cache contract remains outstanding.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 726b15fa7b8b.

Labels

Label changes:

  • add P2: This is a bounded plugin-management performance improvement with no demonstrated active outage or release-blocking regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 external-contributor gate does not apply to this maintainer-authored internal refactor, and no material authority change was found. The captured body reports matching exported capture/reconciliation outputs and populated-inventory speedups; the raw study was not independently inspected.

Label justifications:

  • P2: This is a bounded plugin-management performance improvement with no demonstrated active outage or release-blocking regression.
  • 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 external-contributor gate does not apply to this maintainer-authored internal refactor, and no material authority change was found. The captured body reports matching exported capture/reconciliation outputs and populated-inventory speedups; the raw study was not independently inspected.

Evidence

What I checked:

  • Pinned introduction and clean checkout: The repository remote identifies openclaw/openclaw, HEAD matches the pinned original head, and the merge-base-to-head diff contains the supplied twelve introduced paths. The separate endpoint drift was not attributed to this PR. Final status was clean and diff whitespace checks passed. (59cf0b7ececa)
  • Ownership invariants preserved: The factory preserves first-match plugin identity, sorted duplicate-preserving children, fresh returned arrays, duplicate-path rejection, and exact orphan handling. The unchanged install-owner reader returns no owner for ambiguous records, supporting removal of the redundant ambiguity predicates. (src/plugins/installed-plugin-package-ownership.ts:69, 59cf0b7ececa)
  • Separate capture and replacement phases: Capture and reconciliation each construct their own resolver. The CLI loads the replacement index after installation and later recaptures ownership before persistence; it does not reuse the earlier resolver across those awaits. Its package-child mapping now comes from the already-validated capture snapshot. (src/plugins/plugin-package-update.ts:62, 59cf0b7ececa)
  • Management and consent lifetime checks: Inventory creates its resolver after catalog loading and consumes it synchronously. Inspection, install, uninstall, and consent use fresh one-shot resolvers. Consent still rereads the installed artifact after its callback before persisting acceptance. The supplied PR body explicitly records the pre-existing inventory custom-environment omission as separate follow-up work. (src/plugins/management-service.ts:877, 59cf0b7ececa)
  • Behavior and regression coverage inspected: The extracted ownership suite retains persisted package identity, missing/ambiguous ownership, aliases, and orphan cases, and adds independent-result-array and next-phase symlink-replacement checks. Existing reconciliation tests cover retired-child cleanup, unrelated settings, restored orphans, and owner migrations. These tests were inspected, not executed. (src/plugins/manifest-registry-installed.ownership.test.ts:240, 59cf0b7ececa)
  • Missed test caller corrected: The final commit migrates the Docker-probe fixture to the canonical resolver with its fixture environment. Its existing parameterized case covers both fresh and initialized state. A complete source search found no remaining references to either removed scalar resolver. (test/scripts/plugin-update-unchanged-docker.test.ts:209, 59cf0b7ececa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • ToToKr: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Complete the pinned fs-safe realpath-cache contract inspection to resolve the reviewer-side dependency gap.

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 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

The remaining dependency-source gap is resolved by direct inspection of the installed, pinned @openclaw/fs-safe 0.7.2 package. package.json routes ./path to dist/path.js; its declaration at dist/path.d.ts:13 explicitly accepts the caller-owned Map<string, string>. The inspected implementation (dist/path.js:71–84, SHA-256 164e41f4aef5d804fd28fa5e27f347db43d91f3712e1db4837cc76c61fb36752) returns a truthy cached entry, otherwise calls synchronous fs.realpathSync, then caches both the requested path and the resolved path. Failures return null without caching that failure. This is the package actually installed for the retained proof, not an inference from OpenClaw's wrapper or a newer upstream revision.

OpenClaw's plugin and infrastructure path-safety modules directly re-export that function. The new ownership resolver creates its private map once per synchronous phase and never exposes it in returned ownership facts. Capture and post-replacement reconciliation construct separate resolvers. Inventory creates its resolver after awaiting catalog loading; one-shot inspection, install, uninstall and consent callers do not carry the resolver across asynchronous work. Successful realpaths intentionally remain stable within that phase; there is no freshness polling or process-wide cache. The resolver also memoizes ownership decisions, including decisions using lexical fallback, so the helper's uncached failures do not imply that a retained resolver observes later filesystem changes.

The retained complete ownership suite includes the real-filesystem next-phase replacement case: an initially separate symlink becomes an alias of an existing package, and a new resolver rejects both duplicate package ownership and orphan lifecycle ownership. Existing paired suites and the complete capture/reconciliation study used the pinned installed dependency. These establish the bounded owner contract; they are not an atomic filesystem snapshot or a claim that external processes cannot mutate paths during synchronous execution.

The latest exact-head CI aggregate is green for 59cf0b7ececa37309019391084d43ac933e19eb8 in run 33933305230. The former Docker-probe caller failures were repaired by the two-line canonical API migration and the full 18-case suite passed. All original timing and RSS tradeoffs remain in the PR body. This addresses ClawSweeper's dependency-inspection item and rank-up move without changing code, waiving a gate, or rerunning performance measurements.

@steipete
steipete merged commit feb2c06 into main Sep 5, 2026
190 of 192 checks passed
@steipete
steipete deleted the codex/perf-sep04-package-ownership-scan branch September 5, 2026 01:05
@steipete

steipete commented Sep 5, 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 5, 2026
* perf: prepare plugin package ownership once per phase

Keep capture and replacement reconciliation in separate synchronous resolver lifetimes. Preserve package identity, duplicate child ordering, conflict checks and independent result arrays while removing repeated preparation from internal callers.

* test: migrate plugin update fixture to prepared ownership resolver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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