Skip to content

fix(plugins): prevent uninstalled npm plugins from coming back - #113902

Merged
steipete merged 3 commits into
mainfrom
codex/fix-plugin-keep-files-recovery-d5
Aug 9, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fix-plugin-keep-files-recovery-d5

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw plugins uninstall <id> --force --keep-files removed the install record but left the managed npm package unmarked. A fresh process then recovered that package from disk, rebuilt the install record, and loaded the plugin again.

The stale PR's marker-only repair had a second bug: Gateway idle cleanup deletes inactive marked generations, so it would have converted resurrection into delayed deletion of files the user explicitly asked to keep.

Why This Change Was Made

The canonical install-record transaction now retires retained managed npm packages while it owns the current plugin lifecycle lease and receipt-conditional rollback. It validates managed npm root ownership, protects active direct and symlinked paths, and compensates marker changes only when the tentative index revision is still current.

The marker reason distinguishes two lifecycle facts at their owner: ordinary retired generations remain cleanup-eligible, while an explicit --keep-files retirement suppresses recovery but is never deleted by Gateway idle cleanup. Reinstall uses the existing active-record path to clear the marker. Each cleared marker is recorded for rollback immediately, so a later filesystem failure cannot leave an earlier package recoverable after the index revision is restored.

No recovery fallback was disabled and no second index/config path was added. No config key, environment variable, default, public/plugin API, protocol, schema, or storage location changes.

User Impact

An npm plugin uninstalled with --keep-files stays uninstalled across fresh CLI/Gateway processes and its package/dependency files remain on disk. Reinstall works normally, and a later ordinary uninstall still removes the managed files. npm-to-npm/source-change and doctor-retired generations remain cleanup-eligible.

Evidence

  • Current-main bug: src/plugins/install-record-commit.ts required both previous and next records to be npm, but keep-files uninstall removes the next record in src/cli/plugins-uninstall-command.ts; recovery accepts an unmarked package in src/plugins/installed-plugin-index-record-reader.ts.
  • Before fix: the retained-uninstall regression failed because hasRetainedManagedNpmInstallMarker returned false after the install record was removed.
  • Exact current-base focused proof: touched transaction/retention/Gateway cleanup suites passed 31 tests; install/registry/Gateway-method sibling suites passed 259 tests, for 290 passing tests.
  • The rollback regression clears marker A, forces EIO while clearing marker B, restores the prior index revision, and proves both packages remain marked.
  • Exact packaged proof remains applicable after the conflict-free rebase because the production and harness blobs did not change: corepack pnpm test:docker:plugins passed the real install → update → keep-files uninstall → fresh-process absence/files-preserved → reinstall → ordinary uninstall lifecycle on Testbox tbx_01kzk8gkk5yh63se73yj6x10hq: https://github.com/openclaw/openclaw/actions/runs/31313803490
  • Final current-base changed gate passed on Testbox tbx_01kzkemkmvfc25s48qnx7yqr0r (exitCode=0), including production/test typechecks, core and script lint, formatting, SDK/plugin boundaries, storage/schema, cycles, webhook, and pairing guards: https://github.com/openclaw/openclaw/actions/runs/31318414416
  • Final full-branch Codex autoreview: TruffleHog clean, one complete pass, no accepted/actionable findings, correctness 0.98.
  • Production LOC: +108/-19. Tests/E2E: +350/-2. Production growth establishes the leased persistence/ownership boundary and distinguishes durable keep-files state from cleanup eligibility.

ClawSweeper rank-up moves

  • Port retention onto the current lifecycle lease and revision-conditional rollback: applied. The stale pre-lease writer and mocks were discarded.
  • Run fresh-process keep-files recovery and rollback/migration proof on the exact rebased head: applied through focused leased-SQLite tests and the packaged Docker plugin lifecycle above; the rebase was conflict-free and the package/harness patch-id remained unchanged.
  • Downstream cleanup proof: added. Actual Gateway cleanup preserves keep-files packages while existing generation/source-change/doctor markers remain cleanup-eligible.
  • Preserve unrelated transaction safety: applied. Multi-marker compensation is recorded incrementally and covered by injected later-marker failure.

Migration

No doctor migration is possible or appropriate: historical on-disk packages do not record whether the missing ledger entry came from deliberate --keep-files or recoverable index loss. Affected users can rerun the explicit keep-files uninstall after upgrading.

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Jul 25, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 9, 2026, 10:45 AM ET / 14:45 UTC.

ClawSweeper review

What this changes

The PR records an explicit retained state for managed npm plugins removed with --keep-files, preventing startup recovery from loading them again while preserving their package files.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still resurrects npm plugins uninstalled with --keep-files, and this PR repairs that at the install-record owner; however, its new cleanup classifier can delete explicitly retained files when their marker is unreadable or partially written.

Priority: P2
Reviewed head: 39305afc9ed5a4ab1fe2bbc970de7cf260ca2848

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-boundary approach and supplied lifecycle proof are strong, but a concrete cleanup safety defect needs repair before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is outside the external-contributor proof gate; its linked packaged Docker lifecycle run is nevertheless relevant supporting evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is outside the external-contributor proof gate; its linked packaged Docker lifecycle run is nevertheless relevant supporting evidence.
Evidence reviewed 6 items Current-main bug remains: Current main requires both the old and new install records to be npm before selecting a retained marker target; a keep-files uninstall removes the new record, so no marker is written and recovery can restore the package.
PR uses the correct lifecycle owner: The branch marks a removed managed npm record under the existing lifecycle lease and its revision-conditional rollback, rather than adding a second index or recovery path.
Unreadable marker becomes destructive: The proposed classifier converts every marker read or JSON parse failure to false, making cleanup eligible even though recovery treats marker existence as sufficient to suppress loading.
Findings 1 actionable finding [P2] Preserve unreadable retained markers
Security None None.

How this fits together

The plugin lifecycle records installed npm packages, startup recovery rebuilds records for untracked packages, and Gateway later cleans retired package generations. A retained uninstall must suppress recovery while telling cleanup that its files remain intentional.

flowchart LR
  A[Plugin uninstall with keep-files] --> B[Install-record transaction]
  B --> C[Retained package marker]
  C --> D[Startup recovery]
  C --> E[Gateway idle cleanup]
  D --> F[Plugin stays unloaded]
  E --> G[Package files preserved]
  B --> H[Reinstall or ordinary uninstall]
Loading

Before merge

  • Preserve unreadable retained markers (P2) - markerPreservesPackageFiles converts every marker read or JSON failure into cleanup eligibility. Recovery suppresses any marker-bearing package, and marker publication is a direct write, so an interrupted or corrupt --keep-files marker leaves the plugin unavailable but lets idle cleanup delete the files the command promised to retain. Preserve unreadable existing markers and cover legacy and generated roots; valid known non-keep reasons can remain cleanup-eligible.
  • Resolve merge risk (P2) - Existing packages uninstalled with --keep-files before this change have no durable intent marker; they remain recoverable until the operator reruns the explicit uninstall after upgrading, because old disk state cannot distinguish intentional retention from index loss.
  • Complete next step (P2) - A narrow, source-proven cleanup repair and regression tests can be applied without changing the selected lifecycle architecture.

Findings

  • [P2] Preserve unreadable retained markers — src/plugins/managed-npm-retention.ts:17-18
Agent review details

Security

None.

PR surface

Source +89, Tests +320, Other +28. Total +437 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 108 19 +89
Tests 4 322 2 +320
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 28 0 +28
Total 9 458 21 +437

Review metrics

Metric Value Why it matters
Production versus test delta production +108/-19, tests/E2E +350/-2 The production growth is justified by the leased retention and rollback boundary, but the cleanup classifier needs the targeted safety repair before it can be accepted.

Stored data model

Persistent data-model change detected: serialized state: src/plugins/managed-npm-retention.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Fail closed for unreadable markers (recommended)
    Treat an existing malformed or unreadable marker as preservation-blocking, and add legacy and generated-root regression coverage while leaving known valid non-keep markers cleanup-eligible.
  2. Keep the explicit upgrade recovery
    Retain the documented requirement to rerun the explicit keep-files uninstall for historical unmarked packages because their on-disk state cannot safely be classified.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve unreadable existing retained markers during cleanup; add legacy and generated-root regressions, while keeping valid non-keep marker cleanup behavior.

Technical review

Best possible solution:

Before merge, preserve any existing unreadable retention marker during cleanup while retaining cleanup for known valid non-keep marker reasons, with regressions for legacy and generated npm roots.

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

Yes, from source: create a managed package with an unreadable retained marker, then run Gateway cleanup; recovery excludes it by marker existence while the proposed classifier makes cleanup delete it.

Is this the best way to solve the issue?

No. Marking retention in the install-record transaction is the best owner boundary, but unreadable existing markers must be preserved; atomic writes alone would not protect preexisting partial markers.

Full review comments:

  • [P2] Preserve unreadable retained markers — src/plugins/managed-npm-retention.ts:17-18
    markerPreservesPackageFiles converts every marker read or JSON failure into cleanup eligibility. Recovery suppresses any marker-bearing package, and marker publication is a direct write, so an interrupted or corrupt --keep-files marker leaves the plugin unavailable but lets idle cleanup delete the files the command promised to retain. Preserve unreadable existing markers and cover legacy and generated roots; valid known non-keep reasons can remain cleanup-eligible.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This member-authored PR is outside the external-contributor proof gate; its linked packaged Docker lifecycle run is nevertheless relevant supporting evidence.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: The PR fixes a bounded npm plugin lifecycle regression, but its cleanup error path can violate the explicit file-retention contract.
  • merge-risk: 🚨 compatibility: It changes durable retained-package markers and the recovery/cleanup behavior that existing managed npm plugin directories receive after upgrade.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This member-authored PR is outside the external-contributor proof gate; its linked packaged Docker lifecycle run is nevertheless relevant supporting evidence.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/plugins/managed-npm-retention.test.ts src/plugins/install-record-commit.retention.test.ts src/gateway/server-retained-plugin-cleanup.test.ts.
  • [P1] corepack pnpm test:docker:plugins.

What I checked:

  • Current-main bug remains: Current main requires both the old and new install records to be npm before selecting a retained marker target; a keep-files uninstall removes the new record, so no marker is written and recovery can restore the package. (src/plugins/install-record-commit.ts:149, fc9905edb2b8)
  • PR uses the correct lifecycle owner: The branch marks a removed managed npm record under the existing lifecycle lease and its revision-conditional rollback, rather than adding a second index or recovery path. (src/plugins/install-record-commit.ts:168, 39305afc9ed5)
  • Unreadable marker becomes destructive: The proposed classifier converts every marker read or JSON parse failure to false, making cleanup eligible even though recovery treats marker existence as sufficient to suppress loading. (src/plugins/managed-npm-retention.ts:17, 39305afc9ed5)
  • Marker publication can be interrupted: The marker is published with a direct write, so a partial or unreadable marker is a concrete filesystem-failure state that the new cleanup path must handle conservatively. (src/plugins/managed-npm-retention.ts:107, 39305afc9ed5)
  • History and release check: Current cleanup and scheduling lines trace to the recent plugin lifecycle work in b869d5e; the supplied latest release v2026.7.1-2 predates this lifecycle surface, so the PR’s central repair is not shipped. (src/plugins/managed-npm-retention.ts:1, b869d5e73f59)
  • Behavior proof supplied: The PR body links a packaged Docker lifecycle run covering keep-files uninstall, a fresh-process absence check, reinstall, and ordinary uninstall. (scripts/e2e/lib/plugins/sweep.sh:223, 39305afc9ed5)

Likely related people:

  • steipete: Current-main blame attributes the retention and Gateway cleanup area to this recent plugin-lifecycle work, and this PR continues that ownership boundary. (role: recent lifecycle contributor; confidence: high; commits: b869d5e73f59, 39305afc9ed5; files: src/plugins/managed-npm-retention.ts, src/plugins/install-record-commit.ts, src/gateway/server-retained-plugin-cleanup.ts)
  • ooiuuii: History identifies the npm generation lifecycle work as adjacent ownership for the cleanup behavior affected here. (role: managed npm generation contributor; confidence: medium; commits: dd055c4f7c3a; files: src/plugins/managed-npm-retention.ts)

Rank-up moves

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

  • Preserve malformed or unreadable existing markers during cleanup and add both layout regressions.
  • Re-run the focused retention and Gateway cleanup suites on the repaired head.

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 (3 earlier review cycles)
  • reviewed 2026-07-25T22:49:41.007Z sha 0f087dd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T02:10:00.283Z sha 0f087dd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-08T01:47:23.949Z sha 0f087dd :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 8, 2026
@steipete steipete self-assigned this Aug 9, 2026
@steipete
steipete force-pushed the codex/fix-plugin-keep-files-recovery-d5 branch from 0f087dd to 94753b4 Compare August 9, 2026 13:27
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: M and removed size: L labels Aug 9, 2026
@steipete
steipete force-pushed the codex/fix-plugin-keep-files-recovery-d5 branch from 94753b4 to 39305af Compare August 9, 2026 14:36
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 9, 2026
@steipete
steipete merged commit 0fe49c5 into main Aug 9, 2026
134 checks passed
@steipete
steipete deleted the codex/fix-plugin-keep-files-recovery-d5 branch August 9, 2026 15:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…law#113902)

* fix(plugins): preserve retained uninstall files

* test(plugins): track retention temp dirs

* fix(plugins): retain rollback marker snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant