Skip to content

fix(windows): keep config backups writable so a read-only config can't block later writes - #44466

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/readonly-bak-windows
Nov 19, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/readonly-bak-windows

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On Windows, if a Codex config.toml is read-only when Orca writes it (for example a workspace trust grant at launch), Orca's rolling backup copies the read-only attribute into config.toml.bak. After the user makes config.toml writable again, every later Orca write to that config fails with EPERM … rename 'config.toml.bak.<pid>.<uuid>.tmp' -> 'config.toml.bak', because Windows won't rename over a read-only file. Codex launches fall back to Codex's own trust prompt, and hook/settings writes to that config keep failing until the user clears the attribute on the .bak by hand. The async hooks-JSON writer (Claude agent-view and theme settings) has its own backup rotation with the same failure. Found in Windows QA for #44244 at ~1,900 worktrees. The bug is the same on main and in stable (v1.4.263).

Fix

  • On Windows, both backup writers (writeRollingFileBackup and writeHooksJsonAsync) clear the read-only attribute on the fresh copy before renaming it over the backup.
  • They also clear it on an existing read-only backup first, so users already in this state recover on their next write.
  • A hard-linked backup is left alone, because clearing its attribute would also change the other file. Its rename still fails, as it did before.
  • On Windows the owner write bit is exactly the read-only attribute, so ACLs are untouched. POSIX behavior is unchanged: renaming over a read-only file is allowed there.
  • The main-thread sync-fs baseline for rolling-file-backup.ts goes up by one (chmodSync). It runs only on Windows, inside the existing synchronous backup copy.

Test

rolling-file-backup.win32.test.ts is added to the Windows package job's boundary tests. It has four cases:

  • a backup of a read-only source is writable;
  • a later backup succeeds after the source becomes writable again;
  • a read-only .bak left by an earlier version gets replaced;
  • the async writer handles a read-only .bak and a read-only hooks JSON.

Run on a real Windows machine:

  • All 4 cases pass with the fix.
  • With main's backup writers, the 3 tests the first version of this PR had all fail with EPERM on the rename.
  • With only the fresh-copy chmods removed, the 2 cases that cover them fail.

Fixes STA-16113

…ig can't block later writes

On Windows, copyFile keeps the read-only attribute, so backing up a
read-only config.toml produced a read-only config.toml.bak. Windows
refuses to rename over a read-only file, so once the user made the config
writable again every later Orca write to it (Codex trust grants, hook and
settings writes) failed with EPERM on the backup rename until the
attribute was cleared by hand.

The backup copy is now made writable before it replaces the old backup,
and an existing read-only backup is made writable first. POSIX is
unchanged.

Fixes STA-16113
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready

Problem: on Windows, a read-only Codex config.toml left a read-only config.toml.bak behind. Every later Orca write to that config then failed with EPERM on the rename over the backup, even after the user made the config writable again. The async hooks-JSON writer (Claude agent-view and theme settings) had the same failure.

User-facing change: once the config is writable again, writes to it work, and users who are already stuck recover on their next write. Orca's .bak files are now always writable. Nothing changes on macOS or Linux.

Fixed during review:

  • The async hooks writer had its own copy of the bug; it now gets the same fix.
  • A hard-linked .bak is no longer chmodded, so another file's attribute can't change.
  • Added tests for recovering from an existing read-only .bak and for the fresh copy being writable.
  • The helper ratchet no longer counts a local helper: the chmods now share one call site.

Deferred: none. profile-index-store.ts copies straight onto its own .bak, but that file is Orca-owned and its errors are deliberately swallowed. Noted, not changed.

Verified:

  • The 4 win32 tests ran on a real Windows machine (win-high). All pass at b2946e6.
  • With main's backup writers, the 3 earlier tests all fail with EPERM … rename. With only the fresh-copy chmods removed, the 2 cases that cover them fail.
  • remote-check PASS on b2946e6. perf-surface-detect finds no surfaces.
  • Reviewers: fresh Codex and Claude pairs on each of the 3 passes. Both are clean on the final commit.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 19, 2026 05:30
@brennanb2025
brennanb2025 marked this pull request as draft November 19, 2026 05:44
@brennanb2025
brennanb2025 marked this pull request as ready for review November 19, 2026 05:44
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Rolling-file backups now adjust permissions on Windows when replacing read-only files. A new helper identifies read-only backups with exactly one hard link as replaceable. The asynchronous hooks JSON writer uses this helper in its Windows backup path. Windows-specific tests cover rolling-file backups and hooks JSON writes, and the Windows test routing includes the new test file.

Merge Risk: Minimal · up to b2946

This change keeps Windows config backups writable so a read-only config cannot block later writes. The changes are narrowly scoped to Windows, leave other platforms unchanged, and include Windows-specific tests. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: on Windows, config backups are kept writable so a read-only config cannot block later writes. It follows the conventional commit style and matches the summary, the obj…
Description check Passed The description covers the required template sections. It has a Problem section and a Fix section, and it states the mechanism. It has a Test section with platform-specific results from a real Windows…
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: on Windows, config backups are kept writable so a read-only config cannot block later writes. It follows the conventional commit style and matches the summary, the objectives, and the code changes to rolling-file-backup.ts and hooks-json-write-async.ts. The title is 89 characters, which is slightly long but still specific.

Full details: Description check

Explanation

The description covers the required template sections. It has a Problem section and a Fix section, and it states the mechanism. It has a Test section with platform-specific results from a real Windows machine and a regression check. It states the risk for POSIX and hard-linked backups. It links the issue with 'Fixes STA-16113'. Several template sections are missing or thin: ELI5, Visual Proof (required for behavior changes, and no N/A rationale is given), an explicit Risk level, a Linked Issue in the required GitHub form (it uses a Linear-style ID rather than a '#' issue link), the checklist items, and the Agent skill upstream boundary and AI Disclosure items. The description is mostly complete, so the check passes, but the author should fill in these gaps.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a861a807-2f4f-49df-ba80-1887d934be8d
Commits

Reviewing files that changed from the base of the PR and between a7e6362 and b2946e6.

Files selected for processing: 5

  • config/main-sync-fs-baseline.txt
  • config/scripts/workflow/source-routing/pr-package-test-paths.mjs
  • src/main/agent-hooks/installation/configuration/hooks-json-write-async.ts
  • src/main/filesystem/rolling-file-backup.ts
  • src/main/filesystem/rolling-file-backup.win32.test.ts

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

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