Skip to content

fix(codex): stop resuming a session under the wrong account when a sessions tree is locked - #15093

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-4607-codex-resume-wrong-account
Aug 17, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-4607-codex-resume-wrong-account

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​294
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​93 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80

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.ts

if (!args.listSessionFiles && !existsSync(sessionsRoot)) {
  continue
}

existsSync returns false on EBUSY/EPERM, so a briefly locked sessions tree made the scan continue to 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 blanket catch { return null } around the selected account's candidate rollout lstat, 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.None lock on a rollout file leaves stat, lstat and opendir all succeeding, because those read metadata rather than file contents (unlike STA-4422's readFileSync, which did fail 100% under the same lock). Directories cannot be locked that way at all — File.Open on 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/EACCES from permissions or network/remote filesystems, EMFILE under 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/ENOTDIR now means "not bridged here". Any other error raises the typed ManagedCodexHomeTemporarilyUnavailableError that #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:

  • The fix — two accounts holding the same rollout id (the bridged state where the id alone no longer names an account), selected account's tree held with an injected EBUSY. Anchor first: with a readable tree the selected account wins. Then: refuses instead of resolving to account B.
  • Definitive absence still skips — the fix must not turn every miss into a refusal.
  • A non-selected unreadable home is still skipped — pins the scoping.

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/ and codex-accounts/.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 958715ef-9876-48cf-b39e-d4abdccf69fe

📥 Commits

Reviewing files that changed from the base of the PR and between 948c915 and 8c001a0.

📒 Files selected for processing (2)
  • src/main/codex/codex-session-resume-wrong-account.test.ts
  • src/main/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/index.ts
  • src/main/codex/codex-session-resume-wrong-account.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Codex session resume now distinguishes missing paths from temporary managed-home filesystem failures. Selected-account stat, rollout lookup, and directory-listing failures raise ManagedCodexHomeTemporarilyUnavailableError. Missing selected trees still allow fallback, and failures in non-selected homes remain skippable. Legacy session migration rethrows this error while preserving fallback behavior for other migration errors. Tests cover stat failures, listing failures, missing trees, and legacy rollout failures.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, fix, scope, linked issue, testing, and validation, but omits most required template sections and checklist items. Add the required ELI5, What Changed, Why, Visual Proof or N/A, AI Disclosure, Review, Notes, checklist, and Author sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly and concisely describes the primary fix: preventing session resume under the wrong account when the sessions tree is locked.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

…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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4607-codex-resume-wrong-account branch from 7e9000f to 948c915 Compare August 17, 2026 18:19
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Review 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 statSync on the selected sessions root was guarded, but the real directory read happens later and listCodexSessionRolloutFilesIncrementally catches every opendir failure. A lock held during enumeration — where nearly all the I/O is, so the far more likely case — still yielded nothing for the selected account and fell through to another one. The original fix only closed the window where the lock landed on the exact instant of the stat.

Now routed through the listing's existing onDirectoryError hook: a non-definitive error anywhere under the selected sessions root raises the typed refusal, while non-selected homes and definitive absence still skip.

P1b — a broad catch neutered the other half. index.ts wrapped prepareLegacySharedCodexSessionResume in a blanket catch and fell back to sessionSource.homePath, 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 — the existing comment's intent, that a genuine migration failure must not block a resume, is preserved.

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 — findTrustedCodexSessionResume, resolveCodexSessionResumeProvenance and prepareCodexSessionResume have no catches, and the PTY layer already maps the typed error before spawn.

Verification (re-run independently, not taken from the reviewer's report)

  • All three typechecks clean
  • check-changed-code-quality: 0 new findings across all 5 changed files, all three analyzers
  • Full Codex suite: 728 passed, 6 skipped
  • Mutation-checked: disabling the listing hook makes the resume resolve to the other account again (promise resolved instead of rejecting), restoring goes green

Honest coverage gap

The index.ts rethrow is protected by typecheck only, not by a behavioural test — mutating it away produces just an unused-import error, no failing test. src/main/index.ts has no unit-test entry point in this repo, which also leaves the AI Vault propagation paths (:1468-1475, :2591-2597) uncovered. Flagging rather than adding a lower-layer test that would look like coverage without being it.

Not merged.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60805f5 and 948c915.

📒 Files selected for processing (5)
  • src/main/codex/codex-legacy-session-resume.test.ts
  • src/main/codex/codex-legacy-session-resume.ts
  • src/main/codex/codex-session-resume-home.ts
  • src/main/codex/codex-session-resume-wrong-account.test.ts
  • src/main/index.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.

Comment on lines +291 to +298
(_directoryPath, error) => {
if (
selectedSessionsRoot === normalizeRuntimePathForComparison(sessionsRoot) &&
!isDefinitiveSessionTreeAbsence(error)
) {
throw new ManagedCodexHomeTemporarilyUnavailableError(undefined, { cause: error })
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
(_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 })
}
}

Comment thread src/main/index.ts
Comment on lines +1191 to +1193
if (error instanceof ManagedCodexHomeTemporarilyUnavailableError) {
throw error
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Responses to the CodeRabbit review

Both 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 pinned

The guard compares selectedSessionsRoot against sessionsRoot, which is the arrow function's parameter — the root currently being listed, not the failing directory. So while enumerating the selected account's tree, any directory error beneath it already satisfies the condition. The unused _directoryPath parameter is what makes it read otherwise.

Verified empirically rather than by re-reading: added a test that faults only sessions/2026/07/20 while the root itself stats fine, so the preliminary stat guard cannot be what catches it. It refuses, as expected. It also fails under mutation alongside the root-lock case (promise resolved instead of rejecting), so it is not passing vacuously.

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 declined

The diagnosis is right: the options omit getSelectedHostAccountCodexHomePath, so resolveSelectedAccountCodexHomeForResume returns at codex-legacy-session-resume.ts:111 before reaching the lstat, and this branch cannot fire today.

The proposed fix is declined because it would be a design reversal, not a wiring fix. This launch path deliberately pins CODEX_HOME to the account that owns the rollout:

"resume pins CODEX_HOME to the account that owns the rollout… an unverifiable rollout must never resume under whichever account is selected now." — codex-session-resume-home.ts:18-20

"a rollout Orca cannot place under a trusted home resumes nowhere instead of resuming under the selected account (#10793)." — :126-128

The asymmetry with the AI Vault path (which does wire the resolver, codex-ai-vault-session-resume.ts:23) is deliberate: the vault's session.codexHome is a dedup artifact — it keeps the lexicographically-smallest alias — so it carries no ownership meaning and must be repinned. This path's transcriptPath is the authoritative path reported by the Codex process under the CODEX_HOME it actually ran with, so it is provenance. Repinning it would replace "resume under the owning account" with "resume under the currently selected account" on the one path built specifically to refuse that.

Separately, index.ts never reads substituteCodexHome (its only consumer is the renderer's vault preparation), so the repin would be discarded anyway.

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Windows validation run — negative result, recorded honestly.

Ran on the Windows high-spec remote host against a real FileShare.None lock, the same technique that reproduced STA-4422 at 100%.

Locked target statSync(root) opendir(root) opendir(dated) lstat(rollout)
rollout file ok ok ok ok
dated dir ok ok ok ok
sessions root ok ok ok ok

And a confound check on the technique itself:

FILE_LOCK_OK
DIR_LOCK_FAIL: MethodInvocationException

Directories cannot be locked with File.Open at all, so the two directory rows were meaningless — no lock was ever held for them. Only the file-lock row is valid, and it shows every metadata operation unaffected.

That is consistent in hindsight: STA-4422's EBUSY came from readFileSync, which opens the file for contents. stat/lstat/opendir read metadata or enumerate directory entries, so they do not conflict with a content lock.

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. EPERM/EACCES from permissions or network/remote filesystems, EMFILE under descriptor exhaustion, and delete-pending states all reach these code paths, and treating "we could not read it" as "this rollout is not bridged here" is wrong whichever errno produces it — it silently resumes under another account. What changed is the strength of the claim, not the correctness of the change.

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 (icacls /deny) on the selected account's sessions tree.

Scenario statSync(root) opendir(root) opendir(dated) lstat(rollout)
baseline ok ok ok ok
dated dir read-denied ok ok EPERM definitive=false EPERM definitive=false
sessions root denied ok EPERM definitive=false EPERM EPERM
after restore ok ok ok ok

definitive=false is the fix's own classifier reporting that these are not ENOENT/ENOTDIR — so they are treated as indeterminate and the resume refuses, instead of falling through to another account.

Two things worth drawing out:

  1. The dated-directory row is the exact case the nested test pins. The sessions root stats fine while a nested directory read fails, so the preliminary stat guard cannot catch it — only the listing-phase hook does. That was the P1 the review loop found, and this is it occurring for real rather than via injected faults.
  2. EPERM is what real Windows produces here, which is inside the fix's non-definitive set. Had Windows returned something ENOENT-shaped for a denied directory, the fix would silently not have fired in production. It doesn't.

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 (cleanup exists= false).

@brennanb2025
brennanb2025 merged commit 5652fb7 into main Aug 17, 2026
87 of 89 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 20, 2026
…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.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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