Repository navigation
fix(codex): stop resuming a session under the wrong account when a sessions tree is locked - #15093
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: 📒 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; 4 remain after this review. 📝 WalkthroughWalkthroughCodex session resume now distinguishes missing paths from temporary managed-home filesystem failures. Selected-account stat, rollout lookup, and directory-listing failures raise 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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 |
…ssions tree is locked Two probes reported "this rollout is not bridged here" for any filesystem error, not just a genuine absence: - codex-session-resume-home.ts used existsSync on each ranked home's sessions directory. existsSync returns false on EBUSY/EPERM, so a briefly locked tree made the scan continue to the next ranked home — and the winning home becomes the resumed pane's CODEX_HOME, so it picks the account. - codex-legacy-session-resume.ts caught every lstat failure for the selected account's candidate rollout and returned null, after which the caller kept the source per-account home. Either way the session resumed under a different account's credentials while the UI still showed the selected one. Only a definitive ENOENT/ENOTDIR now means "not bridged here". Any other error raises the typed temporary-unavailability refusal the ownership gate already uses, which both PTY paths convert into a clean abort before spawn. The refusal is scoped to the SELECTED account's home. An unreadable home that is not the selected account cannot cause a wrong-account resume, so it is still skipped rather than stranding the user. These are pre-existing and independent of the STA-4422 ownership-marker failure: they route to another account today with the gate uninvolved. Fixes STA-4607
… mid-listing Review found the first pass incomplete in two places, both the same category error one layer further down. The preliminary statSync on the selected sessions root was guarded, but the real directory read happens later and listCodexSessionRolloutFilesIncrementally swallows every opendir error. A lock held during enumeration — where nearly all the I/O is, and so the far more likely case — still yielded nothing for the selected account and fell through to another one. The listing now reports directory errors through its existing onDirectoryError hook, and a non-definitive error anywhere under the selected sessions root raises the typed refusal. Non-selected homes and definitive absence still skip. Separately, index.ts wrapped prepareLegacySharedCodexSessionResume in a blanket catch and fell back to the source home, so the typed refusal from the candidate lstat was swallowed and the resume still ran under the peer account's credentials. That catch now rethrows ManagedCodexHomeTemporarilyUnavailableError while ordinary migration failures keep warning and falling back, since a genuine migration failure legitimately should not block a resume. A typed refusal is only as strong as the narrowest catch between the throw and the spawn. The frames between both throw sites and the PTY spawn were audited: findTrustedCodexSessionResume, resolveCodexSessionResumeProvenance and prepareCodexSessionResume have no catches, and the PTY layer already maps the typed error before spawn. Both fixes are mutation-checked. Disabling the listing hook makes the resume resolve to the other account again; the index.ts rethrow is covered only by typecheck, because src/main/index.ts has no unit-test entry point in this repo.
7e9000f to
948c915
Compare
Review statusReview loop found the first pass incomplete, twice — both the same category error one layer further down. Both are fixed and pushed. P1a — the listing swallowed the error. The preliminary Now routed through the listing's existing P1b — a broad catch neutered the other half. The general lesson, since this bit three times: a typed refusal is only as strong as the narrowest catch between the throw and the spawn. So the frames were audited rather than patched one at a time — Verification (re-run independently, not taken from the reviewer's report)
Honest coverage gapThe Not merged. |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 92b08296-5bc7-4053-808e-7d5064a2bd78
📒 Files selected for processing (5)
src/main/codex/codex-legacy-session-resume.test.tssrc/main/codex/codex-legacy-session-resume.tssrc/main/codex/codex-session-resume-home.tssrc/main/codex/codex-session-resume-wrong-account.test.tssrc/main/index.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.
| (_directoryPath, error) => { | ||
| if ( | ||
| selectedSessionsRoot === normalizeRuntimePathForComparison(sessionsRoot) && | ||
| !isDefinitiveSessionTreeAbsence(error) | ||
| ) { | ||
| throw new ManagedCodexHomeTemporarilyUnavailableError(undefined, { cause: error }) | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Handle failures in nested selected-home directories.
The comparison accepts only an error for the exact sessions root. If enumeration fails in sessions/2026/..., this callback ignores EBUSY. The scan can then select another account home.
Treat the root and every directory inside the selected sessions root as selected. Add a test that locks a nested dated directory.
Proposed fix
(_directoryPath, error) => {
+ const comparisonDirectoryPath =
+ normalizeRuntimePathForComparison(_directoryPath)
+ const isInsideSelectedSessionsTree =
+ selectedSessionsRoot !== null &&
+ (comparisonDirectoryPath === selectedSessionsRoot ||
+ relativePathInsideRoot(
+ selectedSessionsRoot,
+ comparisonDirectoryPath
+ ) !== null)
if (
- selectedSessionsRoot === normalizeRuntimePathForComparison(sessionsRoot) &&
+ isInsideSelectedSessionsTree &&
!isDefinitiveSessionTreeAbsence(error)
) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| (_directoryPath, error) => { | |
| if ( | |
| selectedSessionsRoot === normalizeRuntimePathForComparison(sessionsRoot) && | |
| !isDefinitiveSessionTreeAbsence(error) | |
| ) { | |
| throw new ManagedCodexHomeTemporarilyUnavailableError(undefined, { cause: error }) | |
| } | |
| } | |
| (_directoryPath, error) => { | |
| const comparisonDirectoryPath = | |
| normalizeRuntimePathForComparison(_directoryPath) | |
| const isInsideSelectedSessionsTree = | |
| selectedSessionsRoot !== null && | |
| (comparisonDirectoryPath === selectedSessionsRoot || | |
| relativePathInsideRoot( | |
| selectedSessionsRoot, | |
| comparisonDirectoryPath | |
| ) !== null) | |
| if ( | |
| isInsideSelectedSessionsTree && | |
| !isDefinitiveSessionTreeAbsence(error) | |
| ) { | |
| throw new ManagedCodexHomeTemporarilyUnavailableError(undefined, { cause: error }) | |
| } | |
| } |
| if (error instanceof ManagedCodexHomeTemporarilyUnavailableError) { | ||
| throw error | ||
| } |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Pass the selected-home resolver to legacy preparation.
This catch cannot receive ManagedCodexHomeTemporarilyUnavailableError from selected-rollout lookup. The options at Lines 1185-1188 omit getSelectedHostAccountCodexHomePath, so resolveSelectedAccountCodexHomeForResume returns at Line 111 before it calls lstat.
Pass the already-resolved selected home. This lets a locked selected rollout refuse the launch instead of resuming from the origin account home.
Proposed fix
{
isHostSystemDefaultRealHome: () => codexRuntimeHome!.isHostSystemDefaultRealHome(),
+ getSelectedHostAccountCodexHomePath: () => selectedAccountCodexHome,
systemCodexHomePath: systemHomePath
}…repin contract Review flagged the listing guard as matching only the exact sessions root, so a nested dated directory would leak. It does not — the guard keys on the root being listed, not the failing directory — but nothing pinned that. Added a test that faults only sessions/2026/07/20 while the root stats fine; it fails under mutation alongside the root case. Also documented why the index.ts rethrow cannot fire today. That launch path pins CODEX_HOME to the account that owns the rollout and deliberately refuses to repin onto whichever account is selected now (#10793), so it does not wire the selected-home resolver. The branch stays as a contract guard so the blanket catch below can never silently swallow a typed refusal if that changes.
Responses to the CodeRabbit reviewBoth comments were investigated against source rather than applied on sight. One is correct in diagnosis but wrong in remedy; the other is a misread. Details, since the reasoning matters more than the verdicts. 1. "Handle failures in nested selected-home directories" — not a defect, but now pinnedThe guard compares Verified empirically rather than by re-reading: added a test that faults only No code change — the behaviour was already correct. The test is there so this question cannot recur. 2. "Pass the selected-home resolver to legacy preparation" — diagnosis correct, fix declinedThe diagnosis is right: the options omit The proposed fix is declined because it would be a design reversal, not a wiring fix. This launch path deliberately pins
The asymmetry with the AI Vault path (which does wire the resolver, Separately, The rethrow stays, now documented as a contract guard: it cannot fire today, and it exists so the blanket catch below can never silently swallow a typed refusal if that ever changes. Caveat stated plainly: intent here is inferred from committed code and comments, not from a maintainer's word — the #10793 and #11224 discussions weren't reachable. If someone knows the desktop path should repin, that's a separate ticket and a bigger change than this PR. |
|
Windows validation run — negative result, recorded honestly. Ran on the Windows high-spec remote host against a real
And a confound check on the technique itself: Directories cannot be locked with That is consistent in hindsight: STA-4422's Consequence: the antivirus-lock trigger I attributed to this bug is not demonstrated, and I have withdrawn that claim from PR #15093's description. The fix still stands, on narrower grounds. What would still be worth doing if someone wants a demonstrated end-to-end trigger: reproduce with a genuine permission denial (ACL removal on the selected account's sessions tree) rather than a file lock. That is a different setup than the STA-4422 rig and I did not build it. |
|
Follow-up: positive result. The fix's premise IS demonstrated on real Windows — the trigger is permission denial, not file locking. Rather than leave the earlier negative result as the last word, I ran the other realistic scenario: a genuine ACL read-denial (
Two things worth drawing out:
Realistic causes of exactly this state: roaming or redirected profiles, group-policy ACL hardening, security software that tightens directory permissions, and cloud-sync folders that reapply ACLs. Net: the earlier negative result stands as written — file locks do not trigger this, and the antivirus story remains withdrawn. But the fix is no longer resting on synthetic faults alone; the classification it depends on is confirmed against real Windows behaviour. Cleanup verified: ACLs reset and the test tree removed ( |
…ssions tree is locked (#15093) * fix(codex): stop resuming a session under the wrong account when a sessions tree is locked Two probes reported "this rollout is not bridged here" for any filesystem error, not just a genuine absence: - codex-session-resume-home.ts used existsSync on each ranked home's sessions directory. existsSync returns false on EBUSY/EPERM, so a briefly locked tree made the scan continue to the next ranked home — and the winning home becomes the resumed pane's CODEX_HOME, so it picks the account. - codex-legacy-session-resume.ts caught every lstat failure for the selected account's candidate rollout and returned null, after which the caller kept the source per-account home. Either way the session resumed under a different account's credentials while the UI still showed the selected one. Only a definitive ENOENT/ENOTDIR now means "not bridged here". Any other error raises the typed temporary-unavailability refusal the ownership gate already uses, which both PTY paths convert into a clean abort before spawn. The refusal is scoped to the SELECTED account's home. An unreadable home that is not the selected account cannot cause a wrong-account resume, so it is still skipped rather than stranding the user. These are pre-existing and independent of the STA-4422 ownership-marker failure: they route to another account today with the gate uninvolved. Fixes STA-4607 * fix(codex): refuse a resume when the selected sessions tree is locked mid-listing Review found the first pass incomplete in two places, both the same category error one layer further down. The preliminary statSync on the selected sessions root was guarded, but the real directory read happens later and listCodexSessionRolloutFilesIncrementally swallows every opendir error. A lock held during enumeration — where nearly all the I/O is, and so the far more likely case — still yielded nothing for the selected account and fell through to another one. The listing now reports directory errors through its existing onDirectoryError hook, and a non-definitive error anywhere under the selected sessions root raises the typed refusal. Non-selected homes and definitive absence still skip. Separately, index.ts wrapped prepareLegacySharedCodexSessionResume in a blanket catch and fell back to the source home, so the typed refusal from the candidate lstat was swallowed and the resume still ran under the peer account's credentials. That catch now rethrows ManagedCodexHomeTemporarilyUnavailableError while ordinary migration failures keep warning and falling back, since a genuine migration failure legitimately should not block a resume. A typed refusal is only as strong as the narrowest catch between the throw and the spawn. The frames between both throw sites and the PTY spawn were audited: findTrustedCodexSessionResume, resolveCodexSessionResumeProvenance and prepareCodexSessionResume have no catches, and the PTY layer already maps the typed error before spawn. Both fixes are mutation-checked. Disabling the listing hook makes the resume resolve to the other account again; the index.ts rethrow is covered only by typecheck, because src/main/index.ts has no unit-test entry point in this repo. * test(codex): pin nested-directory lock coverage; document the resume repin contract Review flagged the listing guard as matching only the exact sessions root, so a nested dated directory would leak. It does not — the guard keys on the root being listed, not the failing directory — but nothing pinned that. Added a test that faults only sessions/2026/07/20 while the root stats fine; it fails under mutation alongside the root case. Also documented why the index.ts rethrow cannot fire today. That launch path pins CODEX_HOME to the account that owns the rollout and deliberately refuses to repin onto whichever account is selected now (#10793), so it does not wire the selected-home resolver. The branch stays as a contract guard so the blanket catch below can never silently swallow a typed refusal if that changes.
…ssions tree is locked (stablyai#15093) * fix(codex): stop resuming a session under the wrong account when a sessions tree is locked Two probes reported "this rollout is not bridged here" for any filesystem error, not just a genuine absence: - codex-session-resume-home.ts used existsSync on each ranked home's sessions directory. existsSync returns false on EBUSY/EPERM, so a briefly locked tree made the scan continue to the next ranked home — and the winning home becomes the resumed pane's CODEX_HOME, so it picks the account. - codex-legacy-session-resume.ts caught every lstat failure for the selected account's candidate rollout and returned null, after which the caller kept the source per-account home. Either way the session resumed under a different account's credentials while the UI still showed the selected one. Only a definitive ENOENT/ENOTDIR now means "not bridged here". Any other error raises the typed temporary-unavailability refusal the ownership gate already uses, which both PTY paths convert into a clean abort before spawn. The refusal is scoped to the SELECTED account's home. An unreadable home that is not the selected account cannot cause a wrong-account resume, so it is still skipped rather than stranding the user. These are pre-existing and independent of the STA-4422 ownership-marker failure: they route to another account today with the gate uninvolved. Fixes STA-4607 * fix(codex): refuse a resume when the selected sessions tree is locked mid-listing Review found the first pass incomplete in two places, both the same category error one layer further down. The preliminary statSync on the selected sessions root was guarded, but the real directory read happens later and listCodexSessionRolloutFilesIncrementally swallows every opendir error. A lock held during enumeration — where nearly all the I/O is, and so the far more likely case — still yielded nothing for the selected account and fell through to another one. The listing now reports directory errors through its existing onDirectoryError hook, and a non-definitive error anywhere under the selected sessions root raises the typed refusal. Non-selected homes and definitive absence still skip. Separately, index.ts wrapped prepareLegacySharedCodexSessionResume in a blanket catch and fell back to the source home, so the typed refusal from the candidate lstat was swallowed and the resume still ran under the peer account's credentials. That catch now rethrows ManagedCodexHomeTemporarilyUnavailableError while ordinary migration failures keep warning and falling back, since a genuine migration failure legitimately should not block a resume. A typed refusal is only as strong as the narrowest catch between the throw and the spawn. The frames between both throw sites and the PTY spawn were audited: findTrustedCodexSessionResume, resolveCodexSessionResumeProvenance and prepareCodexSessionResume have no catches, and the PTY layer already maps the typed error before spawn. Both fixes are mutation-checked. Disabling the listing hook makes the resume resolve to the other account again; the index.ts rethrow is covered only by typecheck, because src/main/index.ts has no unit-test entry point in this repo. * test(codex): pin nested-directory lock coverage; document the resume repin contract Review flagged the listing guard as matching only the exact sessions root, so a nested dated directory would leak. It does not — the guard keys on the root being listed, not the failing directory — but nothing pinned that. Added a test that faults only sessions/2026/07/20 while the root stats fine; it fails under mutation alongside the root case. Also documented why the index.ts rethrow cannot fire today. That launch path pins CODEX_HOME to the account that owns the rollout and deliberately refuses to repin onto whichever account is selected now (stablyai#10793), so it does not wire the selected-home resolver. The branch stays as a contract guard so the blanket catch below can never silently swallow a typed refusal if that changes.
…ssions tree is locked (stablyai#15093) * fix(codex): stop resuming a session under the wrong account when a sessions tree is locked Two probes reported "this rollout is not bridged here" for any filesystem error, not just a genuine absence: - codex-session-resume-home.ts used existsSync on each ranked home's sessions directory. existsSync returns false on EBUSY/EPERM, so a briefly locked tree made the scan continue to the next ranked home — and the winning home becomes the resumed pane's CODEX_HOME, so it picks the account. - codex-legacy-session-resume.ts caught every lstat failure for the selected account's candidate rollout and returned null, after which the caller kept the source per-account home. Either way the session resumed under a different account's credentials while the UI still showed the selected one. Only a definitive ENOENT/ENOTDIR now means "not bridged here". Any other error raises the typed temporary-unavailability refusal the ownership gate already uses, which both PTY paths convert into a clean abort before spawn. The refusal is scoped to the SELECTED account's home. An unreadable home that is not the selected account cannot cause a wrong-account resume, so it is still skipped rather than stranding the user. These are pre-existing and independent of the STA-4422 ownership-marker failure: they route to another account today with the gate uninvolved. Fixes STA-4607 * fix(codex): refuse a resume when the selected sessions tree is locked mid-listing Review found the first pass incomplete in two places, both the same category error one layer further down. The preliminary statSync on the selected sessions root was guarded, but the real directory read happens later and listCodexSessionRolloutFilesIncrementally swallows every opendir error. A lock held during enumeration — where nearly all the I/O is, and so the far more likely case — still yielded nothing for the selected account and fell through to another one. The listing now reports directory errors through its existing onDirectoryError hook, and a non-definitive error anywhere under the selected sessions root raises the typed refusal. Non-selected homes and definitive absence still skip. Separately, index.ts wrapped prepareLegacySharedCodexSessionResume in a blanket catch and fell back to the source home, so the typed refusal from the candidate lstat was swallowed and the resume still ran under the peer account's credentials. That catch now rethrows ManagedCodexHomeTemporarilyUnavailableError while ordinary migration failures keep warning and falling back, since a genuine migration failure legitimately should not block a resume. A typed refusal is only as strong as the narrowest catch between the throw and the spawn. The frames between both throw sites and the PTY spawn were audited: findTrustedCodexSessionResume, resolveCodexSessionResumeProvenance and prepareCodexSessionResume have no catches, and the PTY layer already maps the typed error before spawn. Both fixes are mutation-checked. Disabling the listing hook makes the resume resolve to the other account again; the index.ts rethrow is covered only by typecheck, because src/main/index.ts has no unit-test entry point in this repo. * test(codex): pin nested-directory lock coverage; document the resume repin contract Review flagged the listing guard as matching only the exact sessions root, so a nested dated directory would leak. It does not — the guard keys on the root being listed, not the failing directory — but nothing pinned that. Added a test that faults only sessions/2026/07/20 while the root stats fine; it fails under mutation alongside the root case. Also documented why the index.ts rethrow cannot fire today. That launch path pins CODEX_HOME to the account that owns the rollout and deliberately refuses to repin onto whichever account is selected now (stablyai#10793), so it does not wire the selected-home resolver. The branch stays as a contract guard so the blanket catch below can never silently swallow a typed refusal if that changes.
Fixes STA-4607. Split out of STA-4422 / #15046 as a deliberately separate change.
The bug
A Codex session could resume under a different account than the one selected, while the UI still showed the selected one. Two probes reported "this rollout is not bridged here" for any filesystem error, not just a genuine absence:
1. Legacy id rescan —
codex-session-resume-home.tsexistsSyncreturnsfalseonEBUSY/EPERM, so a briefly locked sessions tree made the scancontinueto the next ranked home. Per that file's own comment, "The winning home becomes the resumed pane's CODEX_HOME, so it picks the account."2. AI Vault repinning —
codex-legacy-session-resume.ts: a blanketcatch { return null }around the selected account's candidate rolloutlstat, after which the caller keeps the source per-account home.On what actually triggers this — corrected after Windows validation. I originally described antivirus file locks as the trigger. I tested that on a real Windows host and could not reproduce it: a
FileShare.Nonelock on a rollout file leavesstat,lstatandopendirall succeeding, because those read metadata rather than file contents (unlike STA-4422'sreadFileSync, which did fail 100% under the same lock). Directories cannot be locked that way at all —File.Openon a directory throws.So the demonstrated trigger for this pair of probes is not an antivirus lock. The fix still stands on its own terms:
EPERM/EACCESfrom permissions or network/remote filesystems,EMFILEunder descriptor exhaustion, and delete-pending states all reach these paths, and treating "couldn't read" as "not bridged here" is wrong regardless of which errno produces it. But the specific antivirus story was unverified and is withdrawn.The fix
Only a definitive
ENOENT/ENOTDIRnow means "not bridged here". Any other error raises the typedManagedCodexHomeTemporarilyUnavailableErrorthat #15046 introduced, which both PTY paths already convert into a clean abort before spawn.The refusal is scoped to the selected account's home. An unreadable home that is not the selected account cannot cause a wrong-account resume, so it is still skipped — refusing there would strand the user for no gain. That distinction is what the third test pins.
Not a regression of #15046
These route to another account today, with the ownership gate uninvolved: the selected account's marker can be perfectly owned while its sessions tree is unreadable, so #15046's eager marker gate passes and doesn't help. Filed and split precisely because they're independent.
Testing
Three tests, each with a healthy anchor:
EBUSY. Anchor first: with a readable tree the selected account wins. Then: refuses instead of resolving to account B.Mutation-checked: removing the refusal fails the first test with
promise resolved instead of rejecting, while the other two stay green — so it proves the fix without over-refusing.Verified: both typechecks clean, changed-code-quality gate 0 findings across all three sub-checks, 4,017 tests passing across
codex/,ipc/andcodex-accounts/.