Repository navigation
fix(plugins): restrict npm project cleanup to owned roots - #124608
Conversation
Restrict recursive managed npm project deletion to canonical ordinary or exact generation roots. Preserve noncanonical sibling roots while retaining package-leaf cleanup and valid generation lifecycle behavior.\n\nFixes #123972
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 9:48 AM ET / 13:48 UTC. ClawSweeper reviewWhat this changesThe PR limits npm plugin cleanup to canonical OpenClaw-owned project roots and otherwise removes only the exact plugin package leaf. Merge readinessKeep open for maintainer review: the patch correctly closes the ownership gap left by the earlier project-root cleanup, but this maintainer-owned filesystem-deletion change should wait for its exact-head safety checks. Priority: P2 Review scores
Verification
How this fits togetherThe plugin lifecycle turns an installed plugin record into a filesystem cleanup plan during uninstall and failed-install compensation. That plan may invoke npm cleanup or recursive deletion, so it must distinguish OpenClaw-owned npm projects from adjacent operator-owned paths. flowchart LR
A[Plugin install record] --> B[Uninstall planner]
B --> C[Classify shared or isolated npm root]
C --> D[Canonical path ownership check]
D --> E[Shared npm package cleanup]
D --> F[Owned project deletion]
D --> G[Noncanonical package-leaf deletion]
Decision needed
Why: The protected maintainer label and recursive-deletion security boundary require explicit owner judgment even though no patch defect was found. Before merge
Agent review detailsSecurityNone. PR surfaceSource +176, Tests +430. Total +606 across 7 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the planner-to-apply ownership revalidation as the canonical cleanup boundary; no net-neutral alternative was found because safe deletion requires both a shared path verifier and its use at planning and mutation time. Do we have a high-confidence way to reproduce the issue? Yes—source inspection shows the current planner widens an npm project target from install-path shape alone; the PR’s focused tests encode the failing ownership cases. Is this the best way to solve the issue? Yes. Carrying root classification from the planner and revalidating it at mutation time is the narrowest owner-boundary repair; package-leaf-only cleanup would retain known managed-project debris. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2ceb18118ced. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready on exact head The original defect was an incomplete ownership boundary: ordinary uninstall needed to remove a complete package-owned isolated npm project, while malformed or stale install records must never widen deletion or npm mutation to a sibling/noncanonical project. The final planner records Fresh security review findings were all accepted and repaired: package/manifest symlink rejection, no npm mutation in noncanonical fallback projects, and no directory-shape inference for legacy-root ownership. Final general and dedicated P1 security autoreviews are clean; TruffleHog is clean. Proof:
Production LOC: +185/-9 (net +176). Peter explicitly approved the reviewed +154 baseline; the final net +22 closes the three subsequent P1 ownership gaps. Removing it recreates those findings. ClawSweeper exact-head run https://github.com/openclaw/clawsweeper/actions/runs/31950657018 completed successfully and applied No config/schema/protocol/Plugin SDK/dependency/release change and no changelog edit. |
|
Merged via squash.
|
…24608) * fix(plugins): validate npm project root ownership Restrict recursive managed npm project deletion to canonical ordinary or exact generation roots. Preserve noncanonical sibling roots while retaining package-leaf cleanup and valid generation lifecycle behavior.\n\nFixes openclaw#123972 * fix(plugins): reject substituted npm project roots * fix(plugins): pin managed npm root identity * fix(plugins): revalidate npm package removals * fix(plugins): validate npm cleanup descendants * fix(plugins): reject npm cleanup symlink aliases * fix(plugins): bind npm cleanup to planned root kind
Closes #123972
Related: #123973
What Problem This Solves
Fixes an issue where uninstalling an npm-managed plugin could either leave its isolated OpenClaw npm project behind or, after the partial repair in #123973, widen recursive cleanup without proving that the selected project root was owned by that package.
Why This Change Was Made
The plugin lifecycle owner now records whether an npm match came from the exact legacy shared root or the isolated projects topology, and validates that fact again before filesystem or npm mutation. Whole-project deletion is limited to the package's exact ordinary root or an exact lowercase-hex generation root. Every noncanonical project falls back to exact package-leaf removal without running npm in the enclosing project.
The accepted ownership matrix is:
<package-prefix>__openclaw-generation__g-[a-f0-9]{16}root--keep-filesretained generationPeter explicitly approved the reviewed +154 production baseline. Fresh security review found three additional ownership gaps in that form: package/manifest symlink acceptance, npm mutation inside noncanonical fallback projects, and inference of legacy-root ownership from directory shape. The final patch is +185/-9 production (net +176); the extra net +22 records the planner-owned root kind, validates missing leaves through canonical existing ancestors, and applies universal manifest/package checks. Removing those paths reproduces the accepted P1 findings.
Alternatives tried and rejected:
projects” remained forgeable; ownership is now recorded at the exact planner match site and cross-checked against topology.rmis path-based and does not expose descriptor-anchored recursive deletion. Hostile same-user swaps between adjacent filesystem syscalls remain outside the documented single-user trusted-host threat model; every stable pre-plan and post-plan substitution we can revalidate is covered.No config, schema, protocol, Plugin SDK, dependency, release, or migration contract changes.
User Impact
Ordinary uninstall removes all files in an OpenClaw-owned isolated npm project. Shared and noncanonical projects keep unrelated manifests, lockfiles, dependencies, and sibling packages intact. Retained update generations and
--keep-filescontinue to work, and failed or missing cleanup targets remain retryable.Evidence
OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs src/plugins/management-service.test.ts src/plugins/management-service.install-compensation.test.ts src/plugins/uninstall.test.ts src/plugins/install-record-commit.test.ts src/plugins/install-record-commit.retention.test.ts src/plugins/managed-npm-retention.test.ts src/plugins/install-persistence.test.ts— 167/167 passed. This includes the requested 135-test owner/sibling set plus retention, compensation, rollback/failure/retry, missing-target, and hostile symlink/root matrices.tbx_01m05atf16x2w15abd90c82jch, run 31948837818 — exact-head source-absent packed Docker lifecycle passed: full build and tarball integrity, tgz/local/file/npm/git/marketplace install and update, malformed npm rejection, explicit restart visibility, retained reinstall, and uninstall. Hermetic ClawHub block was intentionally offline.tbx_01m05b7wcfetgp6x0ke1h0f29m, run 31949170366 —check:changed, fullpnpm check, test types, full format, core/extensions/scripts lint, both cycle guards, plugin boundary and SDK surface checks, dead-code/dependency checks, high-severity production dependency audit, OpenGrep rule metadata, and diff hygiene passed. The OpenGrep binary was unavailable on the runner, so no binary OpenGrep scan is claimed..agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output— final whole-branch general review clean; no accepted/actionable P0 finding (0.98 confidence).../codex/codex-rs/cli/src/main.rs,../codex/codex-rs/core/src/lib.rs).Tests and test support: +508/-78 (net +430).
No
CHANGELOG.mdedit. AI-assisted, maintainer-owned, and explicitly approved for full repair landing.