Skip to content

fix(update): Windows package swap rolls back when a scanner holds a staged file - #186221

Merged
steipete merged 6 commits into
mainfrom
codex/issue-178004
Oct 27, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/issue-178004

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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.ts and package-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 bundled activateStagedNpmPackageRoot from origin/main and from this branch, in the swap's layout. A PowerShell child held one stage file open with FileShare.Read only, the way a scanner does. A plain rename of the stage directory is denied with EPERM.

Case main this PR
File held 4 s Throws EBUSY after 1.9 s unlinking the held stage file, after the copy was already published to the live root, so the swap fails and rolls back Activated after 5 retries in 7.8 s, stage consumed, nothing copied
File held 75 s Throws EBUSY in 0.1 s, same path Fails after 16 attempts in 57.8 s with 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 backup

The 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.ts adds activation-transient (commits) and activation-persistent (rolls back to 1.0.0 with the stage and live paths in the error). Both fail on main.
  • package-update-filesystem.test.ts adds a table case where the live parent is replaced during an activation retry. It fails without the parent pin.
  • 47/47 pass in the two files.
  • tsgo:core, tsgo:core:test, the oxlint core shard and oxfmt are clean.
  • The test-lines ratchet reports net delta 0.

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.

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

clawsweeper Bot commented Oct 27, 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 27, 2026 19:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T22:08:53.979899Z 93e33d8 New commits
ℹ️ 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. 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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Activation copies the package, fails removing the held staged file, and triggers rollback.
  • After: Activation waits through bounded rename retries, then publishes the staged package without copying it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and native filesystem evidence are convincing for the repaired mechanism, while complete installed-update validation remains outstanding.
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: Windows updates can roll back after a temporary scanner lock prevents removal of an already-copied staged package.
Reason: The concrete failure warrants this narrow repair, and maintainer authorship establishes direction; the linked issue’s automatic closure remains unsupported by its redacted diagnostic.

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
Reviewed head: 63443b0a13fb5b277fe802928fb0ed674fb2c78e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a Windows installed-update run from the latest stable release, preserving settings and data, and distinguish the older driver’s first hop from a subsequent update driven by the repaired updater.
Agent review details

How this fits together

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

Technical review

Best 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

  • Unjournaled package activation changes intended behavior with a stated reason (000af98: Retained package generation work preserved copy-capable unjournaled activation while binding journaled publication to exact staged identities.)
  • Windows rename retries keeps the original intent (b5555b0: Transient scanner and indexer denials require bounded retries with live authority and path-identity checks.)
  • Shared rollback rename owner keeps the original intent (d091621: Backup and rollback publication share guarded retries to avoid stranding the installed package root.)
  • Platform-selectable regression fixtures keeps the original intent (d7b0293: Select Windows retry policy without spoofing the host platform and breaking native filesystem staging.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced diff routes unjournaled Windows activation through the existing rename retry owner and pins both parent identities; other activation branches remain intact. (src/infra/package-update-filesystem.ts:81, 63443b0a13fb)
  • Current-main behavior: Fetched main retains the copy-fallback activation path and has no changes to the two production files relative to the pinned merge base, so this repair remains necessary. (src/infra/package-update-filesystem.ts:80, 161c376d51b8)
  • Staging layout and fallback scope: npm staging is created under the target global root; native pnpm/Bun staging uses a sibling of the canonical live project, supporting the Windows same-volume rename approach. (src/infra/package-update-lifecycle.ts:149, 63443b0a13fb)
  • Dependency contract inspected: The target imports and replaces use of this dependency’s move helper, making its contract applicable; version 0.26.13 falls back to copying on Windows EPERM and cleans the source after destination publication, matching the reported probe mechanism. (src/move-path.ts, 6c8627eb55a0)
  • Native Windows evidence: The complete PR body describes the real activation owner on Windows 11 with Node 24.19.0: a four-second held file recovers through rename retries, while a persistent lock exhausts the bound with the stage intact; this is filesystem-boundary evidence, not a complete installed update. (63443b0a13fb)
  • Linked report limits attribution: Update failure: package-swap (2026.10.4) #178004 records a Windows 2026.10.4 Control UI update failing with package-swap EPERM, but redacts the filesystem operation; its discussion does not establish scanner-held staged-file cleanup as the cause.

Likely related people:

  • Peter Steinberger: Raw commit b5555b0 adds src/infra/package-update-filesystem.ts:118 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)

PR surface

Source +20, Tests +84. Total +104 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 27 7 +20
Tests 2 84 0 +84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 111 7 +104

Labels

Label changes:

  • add P1: The repair addresses Windows updates rolling back under ordinary scanner locks, alongside a real released-version update failure.
  • 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: The repair addresses Windows updates rolling back under ordinary scanner locks, alongside a real released-version update failure.
  • 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.

Rank-up moves

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

  • Provide the Windows installed-upgrade evidence described in the proof assessment.

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 27, 2026, 3:18 PM ET / 19:18 UTC.

@steipete
steipete enabled auto-merge (squash) October 27, 2026 19:53
…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.
@steipete
steipete merged commit 81d4915 into main Oct 27, 2026
111 checks passed
@steipete
steipete deleted the codex/issue-178004 branch October 27, 2026 22:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…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.
steipete added a commit that referenced this pull request Oct 30, 2026
…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]>
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]>
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: S 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.

Update failure: package-swap (2026.10.4)

1 participant