Repository navigation
Codex settings reach WSL accounts again: save the usual atomic way where hard links aren't available - #46060
Conversation
…links are unsupported Guarded writes publish with a hard link so they never overwrite a file another writer created. Since #44503 the Codex config mirror uses them for every managed home, including WSL account homes reached over \\wsl.localhost, where Windows can't create hard links. When the filesystem refuses links outright, publish with an exclusive copy instead: it still fails on an existing target, so the no-overwrite guarantee holds. Tracked in STA-16341.
Perf scan — blockedP1 — The capability probe copies the entire payload on the launch and edit paths. At P1 — The shared fallback bypasses the profile database's startup publication gate. At The durable caller fsyncs the containing directory after the copy. The fsynced staging inode and the copied inode are distinct. I simulated termination after publishing the first 4,096 bytes of the database to the final pathname. The next bootstrap kept the original JSON and returned Work, triggers and bounds
Retained and WSL launch routes · Baseline snapshot · Hook worker completion · Tool-file lifecycle · Versioned export Evidence and scan dispositions
|
… links are unsupported An exclusive copy wrote non-atomically under the live name, so an interrupted copy could leave a truncated config, database or credential there. Guarded updates now fall back to the usual atomic-save shape: compare the current bytes, then rename a complete temp file over them, rechecked before every retry. Create-if-absent publication is unchanged and still refuses. Tracked in STA-16341.
|
Perf scan blocked — P0 main-thread stall during managed-home launch On a filesystem that rejects hard links, an existing settings file now reaches a synchronous Windows rename and its blocking backoff. A reader that keeps the target open across two rename attempts can delay the launch and park Electron main for at least 150 ms. At the merged base the rejected hard-link probe exits before any of these waits. The managed WSL launch runs this mirror on main before returning the home, including when the caller offers to defer the host-home mirror. New fallback · Blocking retry · WSL launch · Mirror on main
Work and reachability
Six scan questions
The newly reachable synchronous main I/O is the P0. The counts above cover whole-file rereads and writes, the existing no-change gate, the successful baseline write, and retry and resource lifetime. Publication and timers use the existing settings notice only on a real credential change, with no new idle activity. The main sync-fs baseline drops two duplicate source call sites after loop consolidation. The new failure branch reaches the comparator indirectly. The added unit test was inspected. The independent probes exercised the relevant comparisons and retry controls. Reviewed PR head |
…ename once, and keep the original error A create (no expected bytes) returned false without checking, so a fresh WSL home still got no settings and a failed login import was recorded as declined. The fallback rename now runs once, so a busy file fails the pass instead of sleeping on the main thread, and a cleanup failure on the Windows retry no longer masks the original write error. Tracked in STA-16341.
Perf scan — blockedP0 — A successful fallback newly reaches blocking auth-snapshot retries on main. The introducing change is the success return at atomic-file-publication.ts:268–269. With a proven old shared credential and rotated system credential, the retained-home refresh now completes its guarded replacement, commits provenance, then calls captureSystemDefaultSnapshot. That snapshot still uses writeFileAtomically, whose ordinary rename calls synchronous Windows backoff. The PR's single-attempt rename fixes the fallback itself, but does not prevent waits in this newly reachable continuation. I reproduced this with the actual retained-auth, provenance, guarded-publication and snapshot methods, real local files, injected unsupported links, the Windows retry branch, and a snapshot destination returning Production reachability is retained-home reconciliation at startup, foreground launch and the host quota preparation route. Selection/provenance/retained-pane checks still apply. Price this as one shared auth owner × one newly reached snapshot per eligible refresh, independent of 750 worktrees or 100 agents; do not multiply it by panes. The default watched quota cadence is 900 seconds, with existing startup, launch and explicit-refresh triggers. Even one affected foreground launch exceeds the 100 ms main-thread stall threshold. The backoff predates the PR on supported filesystems; reaching it after an unsupported-link credential save is new relative to the specified base. Move the affected credential transaction, including its success-side sidecars, off main or use ordered asynchronous sidecar publication. Preserve provenance fencing, snapshots, logout behavior and recovery. A regression check should exercise this production refresh with unsupported links and busy snapshot renames, require the queued callback to run while retries are pending, then verify the credential, committed provenance and final snapshot. Include persistent failure and the next refresh. This remedy was not implemented or validated in this read-only review. Added or newly reachable work
Independent cold-call evidenceThese are first calls in fresh Node processes on disposable synthetic profile instances, with OS cache state uncontrolled. Each profile contained 10,000 transcript paths, 100,000 prompt-history records, a 10 GiB sparse legacy-journal stand-in, and the stated trust population. Valid legacy auth/provenance/snapshot records and a version-1 settings-baseline control exercised older layouts. No real application or provider home was used.
The pre-existing large-config parse/merge cost remains visible: stable 19,000-entry legacy-baseline repeats took 375 ms base and 407 ms head. Head made zero writes, links or renames on those unchanged config repeats; the changed call made one config rename and one baseline write at both sizes. This is not evidence that these pre-existing synchronous parsers are fast. The bot write preparation also already performs up to S² name comparisons before publication on both revisions. Neither existing amplification is a separate regression finding here. Six questions and regression-class dispositions
The added checked-in unit assertion was inspected, not claimed as an executed suite. Standalone production-seam workloads and operation/cleanup assertions ran through the test gate. No production code was edited, no commit was made and nothing was pushed. The synthetic host timings do not establish native ACL behavior; that host-specific cost remains an evidence gap, separate from the reproduced P0. Comparison pinned to main |
Absence for a create is now proven with lstat, so a symlink whose target is missing counts as an existing entry and the create declines instead of renaming over it. Tracked in STA-16341.
Perf scan — PASSNo P0/P1 performance regression found in this head against the supplied main baseline. The previously reported auth-snapshot stall is PRE-EXISTING, not a P0 caused by this PR. The unsupported-hard-link fallback itself performs one rename per attempt, with no retry sleep. Comparison: main Re-grade of the previous P0I verified all four points in source and exercised the relevant production methods:
Fresh execution used real local files and the actual auth/provenance/publication/snapshot methods, with only unsupported-link errors, snapshot locks, Windows platform selection and ACL operations injected. Actual synchronous sleeps ran:
These are individual calls under variable machine load, not statistical latency comparisons or evidence of a general speedup. Deterministic attempt counts and actual sleep durations establish the unchanged cost. The independently seeded unchanged-credential control also demonstrates that this snapshot was already reachable on main even on an unsupported-link filesystem, because no credential publication is needed. The old finding identified a real existing blocking operation, but attributed it to this PR because the no-hard-link baseline could not save the changed credential. Enabling that save adds the necessary existing success work; it does not introduce or amplify the snapshot's cost or cadence. The pre-existing snapshot write on unchanged refreshes remains performance debt. Added or newly reachable work, triggers, populations and bounds
Cold calls on large synthetic profilesEach entry is the first method invocation in a fresh Node process. All profile data was synthetic and isolated inside the supplied review workspace: 10,000 transcript paths, 100,000 history records, a 10 GiB sparse legacy-journal stand-in, and independently scaled trust/home/tool populations. Config controls include an older version-1 settings baseline; auth controls include valid legacy provenance and a snapshot. No real application/provider home was used. Profile creation and module loading precede the timed call; filesystem caches were uncontrolled.
The large-config parsing cost is pre-existing: it is already paid before the failed hard-link gate on main, and head still spends 387 ms on an unchanged 19,000-entry repeat despite zero writes. Likewise, bot write preparation already performs up to S² previous-name comparisons and per-server credential lookups before publication on both revisions. These are not claims that those existing paths are fast, and neither amplification was introduced by this span. Direct 64 / 640 KiB controls used 2 / 11 comparison reads including EOF, zero payload reads for size mismatch, and one read for a first-chunk mismatch. Successful replacements each renamed once (3.9 / 3.5 ms); busy failures renamed once (1.6 / 1.8 ms); denied failures renamed twice with one mocked ACL repair (2.1 / 4.3 ms). Absent/existing/dangling creates each made exactly one target Six questions and touched regression classes
Executed standalone production-seam controls through |
…write-no-hardlink-fallback
Review status: readyProblem. Since #44503, Orca's guarded file writes (the Codex settings mirror, Codex login sync, bot tool files) needed hard links. On disks without them (WSL homes opened from Windows, FAT/exFAT), every such write failed, so those Orca-managed Codex homes never received the user's Codex settings (STA-16341). Change. Where hard links are unsupported, the guarded write checks the file still holds the expected bytes (or, for a create, that nothing exists at the path, symlinks included), then renames a complete temp file into place once. Disks with hard links take exactly the old path. Fixed during review. Absent-file creates now publish (a fresh WSL home got no settings, and a failed login import could be read as declined); the fallback renames once instead of sleeping on retries; the Windows retry keeps the original error; a create no longer replaces a dangling symlink (5e8e832, with a test). Accepted and deferred. A save by another program between the final check and the rename is replaced, the same trade-off as a standard atomic save (approved). The login snapshot's existing Windows retry sleep, which this now lets these disks reach too, was graded pre-existing by the perf scan and is tracked in STA-17081. Verified on 5e8e832.
Before (main): After (this PR): |
ELI5
When Orca updates your Codex settings inside a Codex account it manages, it uses a careful save that won't overwrite a change another program just made. That careful save depended on a file-system feature that some places don't have, most importantly Linux homes opened from Windows (WSL). There the update failed every time, so a Codex account living in WSL never got your model, provider or tool settings. Now, where that feature is missing, Orca saves the ordinary safe way: it checks the file still holds what it expects, then swaps in a complete new copy in one step. Your settings arrive, and a half-written file can never appear.
What Changed
Before: on a drive or share without hard-link support, every guarded update failed. The visible case is Codex accounts whose home lives inside WSL. Orca writes them from Windows over
\\wsl.localhost, the write failed, and the account'sconfig.tomlheld only Orca's own lines (no model, provider or MCP servers). Since #44503 the Codex config mirror uses guarded updates for every managed home, so this hit every WSL account.After: when the file system refuses to make a hard link because it can't, a guarded update falls back to the usual atomic save: it compares the file's current bytes with the bytes the update was computed from, then renames a complete temp file over the target in one attempt (a busy file fails that pass and is retried on the next, instead of blocking the main thread). A create checks that no file exists. The file under the live name is always whole. A save another program makes before the comparison still wins and the update is redone; only one landing in the instant between the last comparison and the rename can be replaced.
Mechanism: in
attemptGuardedAtomicWrite, the hard-link probe (and the create-if-absent link) now catch "not supported" link errors (ENOTSUP/EOPNOTSUPP/ENOSYSanywhere,EISDIRon Windows, which is how Node reports a share's "Incorrect function", andEPERMon Linux vfat/exfat) and take the compare-then-rename path. Every other error still throws.publishFileWithoutOverwriteitself is unchanged, so create-only callers (the profile database migration, recovery exports, Claude profile seeding) still refuse on such file systems, exactly as before. The Windows permission-repair retries inwriteFileAtomicallyandwriteFileAtomicallyIfUnchangedare now single loops with unchanged behavior (one repair, one retry, the original error if it still fails). The error classifier lives inhard-link-unsupported-error.ts.Why
The guarded update exists so Orca never clobbers a newer save. Without hard links there is no atomic "publish unless something changed" operation, so the choice is between failing every time (today) and the standard atomic-save shape: compare, then rename. Renaming keeps the file whole at all times, which a copy can't. An earlier version of this PR copied instead, and review showed an interrupted copy could leave a truncated config, database or credential under the live name. Create-only paths keep refusing because a race there could drop a file another program just created.
Linked Issue
Tracked in STA-16341 (introduced by #44503).
Visual Proof
No UI change; the visible effect is in Codex's settings inside Orca. QA put an Orca-managed Codex home on a FAT disk (no hard links) on macOS.
Before (main): the managed Codex config holds only Orca's own lines; the user's settings never arrive (Orca logs
ENOTSUPfromlink()).After (this PR): the user's settings are mirrored in and Codex starts and replies.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
atomic-file-publication.test.ts: withlink()refused as unsupported, a guarded update over stale bytes is refused and leaves the file alone, an update over the expected bytes publishes, a create over an existing file is refused, a create with no file publishes, a create over a dangling symlink is refused and leaves the link, and no temp, held or probe file is left behind. It fails on main.Real app QA on macOS with a managed Codex home on a FAT16 disk image (where
lnfails with "Operation not supported") and a real Codex CLI 0.171: main leaves the user's settings out; this PR mirrors them in and Codex replies; a later settings change carries over; a hand edit in the managed config survives a relaunch; no temp or held files are left behind.Windows/WSL: not run end to end (a WSL account needs a sign-in the test machine doesn't have). The same fallback is reached there through Windows' unsupported-link errors, which the unit test covers. A WSL QA run on main showed the symptom.
Performance
File systems with hard links do no new work. On file systems without hard links, each guarded update adds one comparison of the expected bytes and one rename, on the caller's thread (the main thread for the config mirror and credential sync). A successful save there now also runs the follow-up steps a save already runs on other disks (credential provenance, logout-marker cleanup, the login snapshot in Orca's data folder), including that snapshot's existing Windows retry when the file is locked. The perf scan on this head graded that snapshot retry as existing behavior on main (tracked separately in STA-17081), and found no other added cost.
Risk
Low. File systems with hard links take exactly the old path. On file systems without them, guarded updates (the Codex config mirror, Codex credential sync, bot tool files) go from always failing to compare-then-rename. The remaining risk is a save by another program landing between the final comparison and the rename, which the rename would replace. Atomic saves accept the same trade-off, and the mirror re-runs on the next pass. Create-only publication is unchanged.
Back out with a plain revert.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)