Repository navigation
fix(codex): stop overwriting and deleting Codex files that were merely unreadable (STA-4737) - #15287
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between e7210749082a5ce3a1f45ae738ec5ed1e66cc0fe and df93a7d. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 1 remains after this review. 📝 WalkthroughWalkthroughAdded filesystem observation helpers that classify paths as present, definitively absent, or indeterminate. Updated configuration promotion and mirroring to preserve state when reads or statistics fail. Added symlink-aware promotion write-target resolution with permission handling and cycle detection. Updated managed-resource synchronization to remove resources only for definitive absence. Added regression tests for denied and absent files. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/shared/definitive-filesystem-absence.ts (1)
1-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the added explanatory comments. Keep only concise, non-obvious rationale; remove implementation walkthroughs and repeated justification at the listed sites.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a6b5efbb-1347-407e-9936-d7ed773e94ce
📒 Files selected for processing (9)
config/tsconfig.cli.jsonsrc/main/codex-accounts/host-codex-managed-home-ownership.tssrc/main/codex/codex-config-mirror.tssrc/main/codex/codex-home-paths.tssrc/main/codex/codex-path-observation.tssrc/main/codex/config-settings-promotion-write-target.tssrc/main/codex/config-settings-promotion.tssrc/main/codex/sta-4737-unreadable-is-not-absent.test.tssrc/shared/definitive-filesystem-absence.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 6 remain after this review.
| const sourceObservation = observeResolvedPathEntry(sourcePath) | ||
| if (sourceObservation.kind === 'indeterminate') { | ||
| return | ||
| } | ||
| if (sourceObservation.kind === 'absent') { | ||
| removeCopiedResourceIfOwned(targetPath, managedHomePath, entryName, sourcePath) | ||
| return | ||
| } | ||
| if (entryName === CODEX_GLOBAL_INSTRUCTIONS_ENTRY && !systemResourceIsRegularFile(sourcePath)) { | ||
| if (entryName === CODEX_GLOBAL_INSTRUCTIONS_ENTRY && !sourceObservation.value.isFile()) { | ||
| removeCopiedResourceIfOwned(targetPath, managedHomePath, entryName, sourcePath) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Keep the fallback copy until replacement succeeds.
A source can become unreadable after Line 111 succeeds. For an owned AGENTS.md fallback copy, copiedFileContentsMatch then returns false, the refresh path removes targetPath, and cpSync can fail. The cleanup leaves no managed copy. Stage the replacement in a sibling temporary path and replace the target only after the source copy succeeds. Add a test that denies the source after observation.
…y unreadable (STA-4737)
Three modules shared by the host and WSL Codex lanes decided a file was absent
from a read that had only failed, and then wrote over it or removed it.
- `codex-config-mirror`: `existsSync` on the RUNTIME config.toml returned false
for a locked file exactly as for an absent one, so the mirror took the
"seed a fresh runtime config" branch and replaced the user's config wholesale.
- `config-settings-promotion`: an unreadable ~/.codex/config.toml counted as
having no promoted settings, and the write path then rebuilt the user's
canonical Codex config from Orca's runtime copy.
- `codex-home-paths`: both delete branches in `linkSystemCodexResource` remove
Orca's mirrored copy because the system resource "is not there". `existsSync`
and `systemResourceIsRegularFile`'s `catch { return false }` both reported
that for a source nobody could read, so one denied read on ~/.codex/AGENTS.md
removed the managed copy on the next launch.
`src/shared/definitive-filesystem-absence.ts` now owns the one errno allowlist —
ENOENT and ENOTDIR, with every other code including unrecognised ones treated as
indeterminate — and `host-codex-managed-home-ownership.ts` drops its private
copy rather than letting the two drift. `codex-path-observation.ts` builds the
three-valued observation on top of it.
The resource sync's two `existsSync`/`statSync` probes collapse into one
resolved stat, which answers reachability and regular-file-ness together and
closes the window between them.
`config-settings-promotion.ts` crossed its max-lines budget, so the write-target
resolution moves to its own module rather than taking a lint exemption.
Deliberately not here: the hook-service trust writes that run after a refused
mirror, and the promotion write target's own classification, which is
unreachable because it always resolves to the same file the read above already
refused. Both are noted in comments rather than half-built.
a8cf83e to
e721074
Compare
e721074 to
df93a7d
Compare
VerdictPass after fixes. The review found real data-loss races in the shared Codex filesystem paths; they are fixed in Findings and changes
Sweep / clean
Mutation resultsThe per-module mutation matrix was checked against named tests:
|
…y unreadable (STA-4737) (stablyai#15287) * fix(codex): stop overwriting and deleting Codex files that were merely unreadable (STA-4737) Three modules shared by the host and WSL Codex lanes decided a file was absent from a read that had only failed, and then wrote over it or removed it. - `codex-config-mirror`: `existsSync` on the RUNTIME config.toml returned false for a locked file exactly as for an absent one, so the mirror took the "seed a fresh runtime config" branch and replaced the user's config wholesale. - `config-settings-promotion`: an unreadable ~/.codex/config.toml counted as having no promoted settings, and the write path then rebuilt the user's canonical Codex config from Orca's runtime copy. - `codex-home-paths`: both delete branches in `linkSystemCodexResource` remove Orca's mirrored copy because the system resource "is not there". `existsSync` and `systemResourceIsRegularFile`'s `catch { return false }` both reported that for a source nobody could read, so one denied read on ~/.codex/AGENTS.md removed the managed copy on the next launch. `src/shared/definitive-filesystem-absence.ts` now owns the one errno allowlist — ENOENT and ENOTDIR, with every other code including unrecognised ones treated as indeterminate — and `host-codex-managed-home-ownership.ts` drops its private copy rather than letting the two drift. `codex-path-observation.ts` builds the three-valued observation on top of it. The resource sync's two `existsSync`/`statSync` probes collapse into one resolved stat, which answers reachability and regular-file-ness together and closes the window between them. `config-settings-promotion.ts` crossed its max-lines budget, so the write-target resolution moves to its own module rather than taking a lint exemption. Deliberately not here: the hook-service trust writes that run after a refused mirror, and the promotion write target's own classification, which is unreachable because it always resolves to the same file the read above already refused. Both are noted in comments rather than half-built. * fix(codex): preserve resource copies on indeterminate reads
…y unreadable (STA-4737) (stablyai#15287) * fix(codex): stop overwriting and deleting Codex files that were merely unreadable (STA-4737) Three modules shared by the host and WSL Codex lanes decided a file was absent from a read that had only failed, and then wrote over it or removed it. - `codex-config-mirror`: `existsSync` on the RUNTIME config.toml returned false for a locked file exactly as for an absent one, so the mirror took the "seed a fresh runtime config" branch and replaced the user's config wholesale. - `config-settings-promotion`: an unreadable ~/.codex/config.toml counted as having no promoted settings, and the write path then rebuilt the user's canonical Codex config from Orca's runtime copy. - `codex-home-paths`: both delete branches in `linkSystemCodexResource` remove Orca's mirrored copy because the system resource "is not there". `existsSync` and `systemResourceIsRegularFile`'s `catch { return false }` both reported that for a source nobody could read, so one denied read on ~/.codex/AGENTS.md removed the managed copy on the next launch. `src/shared/definitive-filesystem-absence.ts` now owns the one errno allowlist — ENOENT and ENOTDIR, with every other code including unrecognised ones treated as indeterminate — and `host-codex-managed-home-ownership.ts` drops its private copy rather than letting the two drift. `codex-path-observation.ts` builds the three-valued observation on top of it. The resource sync's two `existsSync`/`statSync` probes collapse into one resolved stat, which answers reachability and regular-file-ness together and closes the window between them. `config-settings-promotion.ts` crossed its max-lines budget, so the write-target resolution moves to its own module rather than taking a lint exemption. Deliberately not here: the hook-service trust writes that run after a refused mirror, and the promotion write target's own classification, which is unreachable because it always resolves to the same file the read above already refused. Both are noted in comments rather than half-built. * fix(codex): preserve resource copies on indeterminate reads
…y unreadable (STA-4737) (stablyai#15287) * fix(codex): stop overwriting and deleting Codex files that were merely unreadable (STA-4737) Three modules shared by the host and WSL Codex lanes decided a file was absent from a read that had only failed, and then wrote over it or removed it. - `codex-config-mirror`: `existsSync` on the RUNTIME config.toml returned false for a locked file exactly as for an absent one, so the mirror took the "seed a fresh runtime config" branch and replaced the user's config wholesale. - `config-settings-promotion`: an unreadable ~/.codex/config.toml counted as having no promoted settings, and the write path then rebuilt the user's canonical Codex config from Orca's runtime copy. - `codex-home-paths`: both delete branches in `linkSystemCodexResource` remove Orca's mirrored copy because the system resource "is not there". `existsSync` and `systemResourceIsRegularFile`'s `catch { return false }` both reported that for a source nobody could read, so one denied read on ~/.codex/AGENTS.md removed the managed copy on the next launch. `src/shared/definitive-filesystem-absence.ts` now owns the one errno allowlist — ENOENT and ENOTDIR, with every other code including unrecognised ones treated as indeterminate — and `host-codex-managed-home-ownership.ts` drops its private copy rather than letting the two drift. `codex-path-observation.ts` builds the three-valued observation on top of it. The resource sync's two `existsSync`/`statSync` probes collapse into one resolved stat, which answers reachability and regular-file-ness together and closes the window between them. `config-settings-promotion.ts` crossed its max-lines budget, so the write-target resolution moves to its own module rather than taking a lint exemption. Deliberately not here: the hook-service trust writes that run after a refused mirror, and the promotion write target's own classification, which is unreachable because it always resolves to the same file the read above already refused. Both are noted in comments rather than half-built. * fix(codex): preserve resource copies on indeterminate reads
ELI5
If a virus scanner or indexer holds one of your Codex config files open for half a second, Orca reads "that file isn't there" — and then helpfully replaces it, or deletes its copy of it. Your model choice, your MCP servers, your AGENTS.md mirror.
What Changed
Three modules shared by the host and WSL Codex lanes act on absence — they overwrite a config that "isn't there yet", or delete a mirror whose source "is gone". All three learned that absence from
existsSyncor from acatchreturning a default, and both report exactly the same thing for a file that is merely locked.codex-config-mirror.tsconfig.tomltook the "seed a fresh runtime config" branch, replacing the user's config wholesaleconfig-settings-promotion.ts~/.codex/config.tomlcounted as having no promoted settings, and the write path rebuilt the user's canonical config from Orca's runtime copycodex-home-paths.tslinkSystemCodexResourcefire when the source "is not there" — one denied read on~/.codex/AGENTS.mdremoved the managed mirror on the next launchsrc/shared/definitive-filesystem-absence.tsnow owns the one errno allowlist:ENOENTandENOTDIRare absence, and every other code — including unrecognised ones — is indeterminate.host-codex-managed-home-ownership.tsdrops its private copy rather than letting two allowlists drift.codex-path-observation.tsbuilds the three-valued observation on top.One incidental simplification: the resource sync's separate
existsSyncandstatSyncprobes collapse into a single resolved stat, which answers reachability and regular-file-ness together and closes the window between them.config-settings-promotion.tscrossed itsmax-linesbudget, so the write-target resolution moved to its own module. No lint exemption.Why
STA-4606 needs these four modules correct before it can build on them — they run on every WSL launch — but they are shared with the host lane, so fixing them inside a WSL-only change would put an all-platforms blast radius inside a PR nobody would review that way. Landing them separately is the whole reason this ticket exists.
Linked Issue
Fixes STA-4737. Blocks STA-4606. Same defect class as #15046, #15093 and #15279.
Visual Proof
N/A — no UI change. The observable difference is that a file survives, which is what the tests assert.
Review round 1 — three real gaps found
A Codex reviewer went over this and found three more instances of the same defect that my first pass missed. All three are in scope for this ticket ("every target delete moves behind the target observation") and are now fixed in
df93a7d:syncSystemConfigIntoLegacySharedCodexHome— a second mirror function in the same file, carrying the identicalexistsSync ? read : ''collapse on both configs. I fixed onlysyncSystemConfigIntoManagedCodexHomeUnsafeand never checked its sibling. It throws on indeterminate, which is safe: its single caller (legacy-shared-config-compatibility.ts:12-24) already wraps it in a best-effort try/catch.pathEntryExists(targetPath)—catch { return false }, so an unreadable target read as "not there" and fell through to the copy/symlink path that overwrites it.copiedFileContentsMatch—catch { return false }meant "different", and different leads tormSync(targetPath). A failed comparison was deleting the only readable copy. It now returns'match' | 'different' | 'indeterminate'.The rig also gained a
denyReadsmode — metadata readable, content reads failing — which is the shape a Windows sharing violation actually takes, and is more faithful than the all-or-nothing denial I wrote.Testing
src/main/codex/sta-4737-unreadable-is-not-absent.test.ts— 10 tests, 6 driving the fix and 4 anchoring it.The rig models one denial coherently: a denied path throws from
readFileSync/statSync/lstatSync/openSyncand reportsfalsefromexistsSync. Faulting one call but not another lets a test pass against code that still consults the one left healthy.Mutation-checked per module, not just in aggregate:
config-settings-promotion.tsonlycodex-home-paths.tsonlycodex-config-mirror.tsonlycodex-config-mirror.tsto maincodex-home-paths.tsto mainThat last row is worth reading. My first version of the mirror test passed with the mirror change reverted, because promotion runs first and refuses on the same denied file, so the mirror's own guard was never reached. Rather than ship a guard no test drives, I added a test that stubs promotion to "succeeded, nothing to do" and then denies the runtime config — the real shape of a scanner taking the file in the window between promotion reading it and the mirror rewriting it. With that test, reverting the mirror alone goes red.
The anchors are the other half: a genuinely absent runtime config is still seeded, a readable system config is still promoted into, and a genuinely deleted source still has its mirrored copy removed. Refusing in those cases would break first launch and strand stale instructions.
1755/1755 across
codex+codex-accounts+agent-hooks.check-changed-code-quality.mjs: 0 findings.Full
pnpm typecheckclean, including the CLI project — the new modules are added toconfig/tsconfig.cli.json, which is an explicit allowlist rather than a glob.Automated tests added
Manual: not run. The trigger is a file-denial race reproduced deterministically by the rig.
Merge note
#15279 (STA-4734) touches the same predicate. Both PRs carry byte-identical copies of
src/shared/definitive-filesystem-absence.tsand of thehost-codex-managed-home-ownership.tsimport change, so they merge cleanly in either order. Neither depends on the other.AI Disclosure
N/A — internal.