Repository navigation
fix(update): retry Windows pnpm/bun project moves instead of copying a held tree - #188498
Conversation
…a held tree The native (pnpm/bun) swap moved the whole live project to its sibling backup, and back during rollback, with fs-safe's movePathWithCopyFallback. On a Windows EPERM that copies the tree and then deletes the source; a scanner holding one file makes the delete fail after the copy is published, leaving a partially deleted live project. npm already used the bounded, identity-checked rename retry helper for these moves (#186221). movePackageRoot now owns unjournaled package-root moves: Windows uses the shared rename retries, other platforms keep the EXDEV copy fallback. Unjournaled activation, the native backup and the native restore all go through it.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR applies guarded Windows rename retries to pnpm and Bun project backup and restoration. Example: A scanner holds an installed project file open for 4 seconds during a Windows native update.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a remaining Windows native-update failure with a focused patch and no actionable code findings. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe package-swap owner receives staged installations, backs up the live package-manager project, activates the candidate, and restores the previous project when activation fails. flowchart TD
A[Staged native installation] --> B[Package swap owner]
B --> C[Package filesystem owner]
C --> D[Windows guarded rename retries]
C --> E[POSIX move fallback]
D --> F[Live project or retained backup]
E --> F
Technical reviewBest possible solution: Keep native project moves in the existing filesystem owner and reuse guarded exact-rename retries on Windows while preserving POSIX fallback and publication bookkeeping. Do we have a high-confidence way to reproduce the issue? Current-main native moves and the pinned dependency implementation establish the EPERM-to-copy-to-source-unlink failure path; the author also reports a matching Windows held-file experiment, which this review did not rerun. Is this the best way to solve the issue? The patch fixes the responsible move policy with existing owners, preserves compensation callbacks, and adds distinct swap regressions without unnecessary production machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 09c767605f82. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +18, Tests +66. Total +84 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 30, 2026, 12:14 PM ET / 16:14 UTC. |
|
Merged via squash.
|
…a held tree (openclaw#188498) The native (pnpm/bun) swap moved the whole live project to its sibling backup, and back during rollback, with fs-safe's movePathWithCopyFallback. On a Windows EPERM that copies the tree and then deletes the source; a scanner holding one file makes the delete fail after the copy is published, leaving a partially deleted live project. npm already used the bounded, identity-checked rename retry helper for these moves (openclaw#186221). movePackageRoot now owns unjournaled package-root moves: Windows uses the shared rename retries, other platforms keep the EXDEV copy fallback. Unjournaled activation, the native backup and the native restore all go through it. Co-authored-by: Peter Steinberger <[email protected]>
Backport #188498 and its explicitly selected #189451 companion from 3140acb and 4f9c852. Preserve retained lifecycle authority, publication receipts, and fresh-copy handling for rejected hardlinks. Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: pnpm and bun global updates on Windows fail in package-swap when antivirus or the indexer briefly holds a file in the installed project. #186221 fixed this for npm (#178004); the native pnpm/bun path still used the copy fallback.
User Impact
User impact: a transient file lock during a Windows pnpm/bun update now waits it out (bounded, about 58 s) instead of failing the update. A lock that never clears fails with a message naming both paths and the next step, with the live project untouched and nothing left at the backup path.
Why This Change Was Made
The native swap moves the whole live project (
liveProjectRoot) to a sibling backup underdirname(liveProjectRoot), and moves it back during rollback. Both moves used fs-safe'smovePathWithCopyFallback. On a Windows EPERM that helper copies the tree to the destination and then deletes the source, so a scanner holding one file fails the delete with EBUSY after the copy is already published. The npm backup, unjournaled activation and npm rollback renames already use the bounded, identity-checked Windows rename retries.movePackageRootnow owns unjournaled package-root moves: Windows uses the shared rename retries (authority, source identity, absent destination and both parents rechecked per attempt), other platforms keep the EXDEV copy fallback. Unjournaled activation, the native backup move and the native rollback restore all go through it, sopackage-update-swap.tsno longer calls fs-safe's move directly. The backup is a sibling of the live project, so the rename cannot hit EXDEV.Rejected alternative: retrying around
movePathWithCopyFallback. Every attempt would copy the full project again while the same file stays held.Not in scope:
src/infra/install-package-dir.ts(plugin installs) still uses the copy fallback.Production LOC: +54/−36 (
package-update-filesystem.ts,package-update-swap.ts). Tests: a native swap fixture moved intopackage-update-swap.test-support.tsand is shared with the launcher test.Evidence
Native Windows proof (Crabbox AWS lease
cbx_c28ca2abe029, Windows NT 10.0.26100, Node 24.19.0, secretless: public network, no hydration; lease released). The proof bundled main's native backup move and this branch'smovePackageRootin the native layout (live project and sibling backup). A PowerShell child held one installed file open withFileShare.Readonly, the way a scanner does; a plain rename of the project is denied with EPERM.Windows package backup rename failed after 16 attempts: <live> -> <backup>: EPERM ... Close processes holding this installation; live project intact, no backup createdFocused tests:
package-update-swap.windows.test.tsadds nativebackup-transient(commits after 3 attempts),backup-persistent(16 attempts, rolls back to 1.0.0,packageRollbackVerified) andrestore-transient(refused activation, restore republishes after 3 attempts). All three fail with main's swap.tsgo:core,tsgo:core:test, oxlint and oxfmt are clean; the test-lines ratchet passes.package-update-refusal.test.ts(4),package-update-steps.native-transaction.test.tsbackup-cleanup case, andpackage-update-activation-lifetime.test.ts(needs the built sealed helper).Reviews on head
79b0f9b5eec9: Codex autoreview scoped-clean; independent read-only Codex review: no findings.Gap: installed updaters run the first hop, so Windows pnpm/bun users get this on the update after it ships, or through the documented manual install.