Skip to content

fix(update): retry Windows pnpm/bun project moves instead of copying a held tree - #188498

Merged
steipete merged 1 commit into
mainfrom
codex/windows-native-swap-retries
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/windows-native-swap-retries

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 under dirname(liveProjectRoot), and moves it back during rollback. Both moves used fs-safe's movePathWithCopyFallback. 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.

movePackageRoot now 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, so package-update-swap.ts no 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 into package-update-swap.test-support.ts and 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's movePackageRoot in the native layout (live project and sibling backup). A PowerShell child held one installed file open with FileShare.Read only, the way a scanner does; a plain rename of the project is denied with EPERM.

File held main this PR
4 s Throws EBUSY after 2.4 s unlinking the held file, after a full copy was already published at the backup path; the update fails Moved after 5 retries in 7.8 s, nothing copied
75 s Throws EBUSY in 68 ms, same path Fails after 16 attempts in 59.6 s with Windows package backup rename failed after 16 attempts: <live> -> <backup>: EPERM ... Close processes holding this installation; live project intact, no backup created

Focused tests:

  • package-update-swap.windows.test.ts adds native backup-transient (commits after 3 attempts), backup-persistent (16 attempts, rolls back to 1.0.0, packageRollbackVerified) and restore-transient (refused activation, restore republishes after 3 attempts). All three fail with main's swap.
  • 56/56 pass across the Windows, launcher, filesystem and optional-dependency swap suites.
  • tsgo:core, tsgo:core:test, oxlint and oxfmt are clean; the test-lines ratchet passes.
  • Pre-existing local failures on macOS, identical on origin/main: package-update-refusal.test.ts (4), package-update-steps.native-transaction.test.ts backup-cleanup case, and package-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.

…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.
@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@steipete
steipete marked this pull request as ready for review October 30, 2026 15:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T15:58:16.860093Z 79b0f9b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The copy fallback publishes a backup, then fails deleting the held source file.
  • After: The reported Windows experiment completes the move after five retries without copying the project.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation is sound by source inspection and has useful Windows boundary evidence, but repository-required product-path validation remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A temporary scanner lock can fail a Windows pnpm or Bun update and leave the live project partly removed.
Reason: The maintainer-authored direction extends an established Windows repair to the remaining native moves without adding configuration or changing public contracts.

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
Reviewed head: 79b0f9b5eec9fe42e2f55170485ddf2c14288e73

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise the shipped Windows update command or demonstrate a latest-stable upgrade with existing settings and data intact.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Native backup and restoration changes intended behavior with a stated reason (fix: recover interrupted npm package updates #158491: Native package-manager layouts retained their existing swap owner while durable publication recovery was added for supported POSIX npm updates.)
  • Windows unjournaled activation keeps the original intent (81d4915: Exact rename retries avoid publishing a copied tree before held-source cleanup fails; the extracted shared operation preserves that policy.)
  • Forward authority and publication bookkeeping keeps the original intent (ca7ef93: Publication must register compensation before later errors, and every forward mutation must retain its initiating executor's authority.)
  • Native launcher fixture keeps the original intent (51211ac: Launcher coverage protects relocated pnpm targets and actionable warnings; moving setup into shared test support preserves those assertions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced diff routes native backup and restoration through movePackageRoot and moves the existing activation policy into that filesystem owner. (src/infra/package-update-filesystem.ts:119, 79b0f9b5eec9)
  • Current-main failure remains: Fetched main still uses movePathWithCopyFallback for native project backup and restoration; the earlier Windows activation repair did not replace these calls. (src/infra/package-update-swap.ts:626, 09c767605f82)
  • Same-filesystem layout: Native staging resolves the physical live project and creates a sibling stage; the swap target resolver places the backup under the live project's parent. (src/infra/package-update-swap-target.ts:25, 79b0f9b5eec9)
  • Verified dependency contract: OpenClaw imports @openclaw/fs-safe/atomic and pins version 0.26.13, making this dependency contract applicable: Windows EPERM selects copy fallback, destination publication precedes source cleanup, and cleanup unlinks source files. The dependency's repository policy was read. (src/move-path.ts:346, 6c8627eb55a0)
  • Windows evidence and source identity: The full PR body reports real Windows held-file experiments against bundled filesystem functions and three base-failing swap regressions; it supplies no shipped CLI upgrade capture. The captured body identity is 1515997eb00eb175fde6c248817b13c5012771400e4489ea9f8a090e8f05bb9f. (79b0f9b5eec9)
  • Update proof contract: Root AGENTS.md requires product-entry-point proof and a latest-stable upgrade for update changes; the update implementation contract additionally specifies published-driver and candidate coverage. Public docs: docs/install/updating.md. (docs/install/updating.md:124, 79b0f9b5eec9)

Likely related people:

  • Peter Steinberger: Raw commit b5555b0 adds src/infra/package-update-filesystem.ts:144 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b5555b0bd9ed; files: src/infra/package-update-filesystem.ts)
  • Vincent Koc: Raw commit d69a5e7 adds src/infra/package-update-filesystem.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d69a5e74895c; files: src/infra/package-update-filesystem.ts)

PR surface

Source +18, Tests +66. Total +84 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 54 36 +18
Tests 3 103 37 +66
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 157 73 +84

Review metrics

Metric Value Why it matters
Production versus test changes Production +54/-36; tests and shared fixtures +103/-37 The production growth centralizes platform policy; test growth covers transient backup locks, persistent backup locks, and transient restoration locks while sharing the native fixture.

Labels

Label changes:

  • add P1: Windows pnpm and Bun updates can fail after partially deleting the installed project when a scanner holds a file during copy-fallback cleanup.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Windows pnpm and Bun updates can fail after partially deleting the installed project when a scanner holds a file during copy-fallback cleanup.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 12:14 PM ET / 16:14 UTC.

@steipete
steipete merged commit 3140acb into main Oct 30, 2026
207 of 208 checks passed
@steipete
steipete deleted the codex/windows-native-swap-retries branch October 30, 2026 16:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…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]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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