Repository navigation
fix(update): Windows package swap rolls back when a scanner holds a staged file - #186221
Conversation
…locked stage Windows npm-global updates never use the journaled activation, so the unjournaled swap published the sibling stage with fs-safe's movePathWithCopyFallback. On a transient EPERM (AV/indexer handle on a freshly extracted file) that copied the whole tree and then failed deleting the still-held stage, failing package-swap with EPERM and rolling the update back. Route that rename through the same bounded, identity-checked Windows retries the backup and rollback renames use. Refs #178004
… retries Activation renames across parents, so a retry must not follow a junction swapped into the live parent; fs-safe's guarded rename refused that.
|
🦞👀 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 retries Windows staged-package activation instead of copying a locked package tree and failing during its cleanup. Example: A Windows scanner holds a staged package file open for 4 seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR provides a focused Windows update repair, and no discrete introduced code defect was found; the linked report’s exact failure remains unconfirmed. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe package-swap owner takes a validated staged installation, backs up the installed package, activates the candidate, and either publishes its launchers or restores the previous installation. flowchart TD
A[Validated staged package] --> B[Package swap owner]
B --> C[Back up installed package]
C --> D[Windows activation rename]
D --> E[Bounded retries and identity checks]
E --> F[Publish candidate launchers]
E --> G[Restore previous package on failure]
Technical reviewBest possible solution: Keep the shared bounded rename repair and establish the linked report’s failing operation before treating that issue as resolved. Do we have a high-confidence way to reproduce the issue? Source and the supplied native Windows probe establish the scanner-lock mechanism, but the linked report’s redacted operation prevents confirming the same root cause. Is this the best way to solve the issue? Reusing the existing guarded retry owner is the smallest complete repair for this mechanism; retrying the copy fallback would repeat publication and cleanup work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 161c376d51b8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +84. Total +104 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 27, 2026, 3:18 PM ET / 19:18 UTC. |
…ename tables Keeps the change test-line neutral for the test-lines ratchet: the activation cases join the Windows swap rename scenarios, and the two rollback refusal tests plus the live-parent activation case share one table.
…ks in the merged table
|
Merged via squash auto-merge.
|
…taged file (openclaw#186221) * fix(update): retry Windows package activation instead of copying the locked stage Windows npm-global updates never use the journaled activation, so the unjournaled swap published the sibling stage with fs-safe's movePathWithCopyFallback. On a transient EPERM (AV/indexer handle on a freshly extracted file) that copied the whole tree and then failed deleting the still-held stage, failing package-swap with EPERM and rolling the update back. Route that rename through the same bounded, identity-checked Windows retries the backup and rollback renames use. Refs openclaw#178004 * fix(update): pin the destination parent during Windows package rename retries Activation renames across parents, so a retry must not follow a junction swapped into the live parent; fs-safe's guarded rename refused that.
…a held tree (#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 (#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]>
…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]>
Closes #178004
What Problem This Solves
Fixes: Windows npm-global updates fail in the package-swap phase and roll back when antivirus or the indexer still holds a file in the freshly extracted package.
User Impact
User impact: a transient file lock during the Windows package swap now waits it out (bounded, about 58 s) and the update completes instead of rolling back. A lock that never clears fails with a message naming the stage and live paths and the next step, and leaves the previous package restorable.
Why This Change Was Made
Windows never uses the journaled package activation, so the swap published the staged package with fs-safe's
movePathWithCopyFallback. On a Windows EPERM, that helper copies the whole tree into place and then deletes the stage. When a scanner still holds a stage file, the delete fails after the copy was already published, so package-swap reports an error and the update rolls back. The backup and rollback renames already use bounded Windows retries with authority and identity checks. Activation now goes through the same helper.The stage is a sibling of the live root (
<globalRoot>/.openclaw.update-stage-*, or a sibling project for pnpm/bun), so this rename cannot hit EXDEV and the copy fallback never added capability. The backup rename that runs just before it already requires a plain rename to succeed.Activation is the first of these renames whose source and destination have different parents, so the helper now also pins the destination parent on every attempt, matching the parent guard fs-safe's guarded rename provided.
Rejected alternative: retrying around
movePathWithCopyFallback. Every attempt would copy the full tree again while the same file stays held.Production LOC: +23/-5 in
package-update-filesystem.tsandpackage-update-swap.ts. Tests are net 0 (the test-lines ratchet passes): the activation cases joined the existing Windows swap rename table, and the two rollback-refusal tests merged with the live-parent case into one table.Evidence
Native Windows proof (Crabbox AWS lease
cbx_70016fb48b2f, Windows NT 10.0.26100, Node 24.19.0). The box was secretless: public network, no hydration. The proof bundledactivateStagedNpmPackageRootfromorigin/mainand from this branch, in the swap's layout. A PowerShell child held one stage file open withFileShare.Readonly, the way a scanner does. A plain rename of the stage directory is denied with EPERM.Windows package activation rename failed after 16 attempts: <stage> -> <live>: EPERM ... Close processes holding this installation. Stage intact, live root absent, so rollback restores the backupThe issue reports EPERM where this reproduction shows EBUSY. Both come from the copy-fallback path, which this change removes on Windows, but the user's report redacts the failing operation, so this is the strongest match rather than a confirmed one.
Focused tests:
package-update-swap.windows.test.tsaddsactivation-transient(commits) andactivation-persistent(rolls back to 1.0.0 with the stage and live paths in the error). Both fail on main.package-update-filesystem.test.tsadds a table case where the live parent is replaced during an activation retry. It fails without the parent pin.tsgo:core,tsgo:core:test, the oxlint core shard and oxfmt are clean.Reviews on head
1592979da26f: Codex autoreview is scoped-clean. The independent read-only Codex review found two kinds of gaps, all now fixed: the destination-parent pin (second commit) and assertions dropped while consolidating the tests. Its final pass found nothing.Gap: this release's updater still runs the first hop, so 2026.10.4 users get the fix on their next update after it ships, or through the documented manual install.