Skip to content

fix(updates): retry Windows status replacement while a reader holds it - #521

Merged
andrebrait merged 1 commit into
mainfrom
fix/windows-status-rename
Nov 17, 2026
Merged

andrebrait merged 1 commit into
mainfrom
fix/windows-status-rename

Conversation

@andrebrait

@andrebrait andrebrait commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Windows CI failed in lib/hosts/update-worker.test.mjs (#518, attempt 2) with:

EPERM: operation not permitted, rename '...\host-update\status.json.<uuid>.tmp' -> '...\host-update\status.json'

Windows refuses a rename over a file another process holds open without delete sharing. Host update status, the server worker's status and upgrade plans are polled while workers rewrite them. self-update-state.atomicWrite already retried; these three writers did not.

  • replaceFileSync in lib/hosts/update-worker.ts (kept in that file: it is copied standalone to old daemons): on win32 retry EPERM/EACCES/EBUSY up to 20 × 50 ms, never unlink the previous file.
  • Used by writeHostUpdateJson, the server worker's status write and writePlan.

Likely also the cause of the earlier #518 Windows flakes (receipt tests stuck in running).

Verified locally (Linux): typecheck, eslint; update-worker + upgrade-plan + server-update-worker tests 127 pass, 4 skip. The retry branch only runs on Windows CI.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the reliability of Windows updates when update-related files are temporarily in use. Host update status, server-worker status, and upgrade plans now retry file replacement briefly, helping prevent update failures caused by temporary file-sharing conflicts.

Windows refuses to rename over a file another process has open without
delete sharing. The server polls host update status, the server worker
status and upgrade plans while workers rewrite them, so a replacement
could fail with EPERM and fail the update. Retry briefly, as
self-update-state already does, and never unlink the previous file.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a shared file replacement helper that retries selected rename errors. Host update state, server-worker status, and upgrade plans use the helper.

Changes: Windows update replacement

Layer / File(s) Summary
Add retrying file replacement
lib/hosts/update-worker.ts, CHANGELOG.md
writeHostUpdateJson uses replaceFileSync. The helper retries EPERM, EACCES, and EBUSY up to 20 times, waiting 50 ms between attempts. The changelog describes the update.
Use the helper for plan files
lib/server-update-worker.ts, lib/upgrade-plan.ts
reportPlan and writePlan use replaceFileSync instead of renameSync. Both retain temporary-file cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to d8d02

This change makes Windows update status and plan file writes retry briefly when another process is reading the file. No concrete defect was found, so the merge risk is minimal.

Security architecture risk: Minimal · up to d8d02

The change preserves existing file validation, replacement, and cleanup behavior while tolerating brief Windows file contention. The inspected changes establish no introduced risk that materially affects update authorization, failure containment, rollback, or ownership guarantees.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated changed exposure is file publication within the existing host operation and server upgrade-attempt storage. The helper adds no network entrypoint or privilege acquisition; affected paths remain selected by existing callers under their current process authority.

Trust Boundaries and Controls

  • observed — The three writers retain their existing path checks and exclusive temporary-file creation. Host path validation rejects symbolic links, unexpected file types, multiple hard links, and applicable ownership or permission mismatches. The retry helper does not replace these caller-side controls or grant additional authority.

Resilience and Maintainability Implications

  • inferred — Repeating rename preserves the existing single-step publication boundary: a failed replacement does not deliberately remove the previous complete file. It does not add writer serialization, crash cleanup, or stronger durability guarantees; those remain outside this helper.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a retry for Windows status-file replacement while a reader holds the file. The raw summary shows replaceFileSync retrying EPERM, EACCES, and EBUSY renameSync failures …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a retry for Windows status-file replacement while a reader holds the file. The raw summary shows replaceFileSync retrying EPERM, EACCES, and EBUSY renameSync failures on Windows, and the same helper is applied to host update state, server worker status, and upgrade plan writes. The title uses the conventional fix(updates) prefix and is specific, at 70 characters and 10 words.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a158f5e4-76b8-432f-9b55-0b77d739dbd6
Commits

Reviewing files that changed from the base of the PR and between 7c13eaa and d8d0242.

Files selected for processing: 4

  • CHANGELOG.md
  • lib/hosts/update-worker.ts
  • lib/server-update-worker.ts
  • lib/upgrade-plan.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@andrebrait
andrebrait merged commit 00310fb into main Nov 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant