Repository navigation
fix(ai-vault): resume a bridged Codex session under the selected account's home - #11224
Conversation
…unt's home The account session bridge hardlinks every rollout into each per-account CODEX_HOME, and vault dedup keeps the lexicographically-smallest alias, so Resume could pin an inline CODEX_HOME naming a peer account — running the session under that account's auth.json and quota. At resume time the owning host now substitutes the selected account's home when it holds the same rollout at the same sessions-relative path, declining on any uncertainty so resume degrades to today's behavior instead of failing.
| const candidatePath = join(selectedCodexHome, 'sessions', relativePath) | ||
| try { | ||
| const candidateStat = await lstat(candidatePath) | ||
| // Why: the bridge is async, so an unbridged rollout is a real state — decline rather than pin a home codex cannot resume from. | ||
| return candidateStat.isFile() && !candidateStat.isSymbolicLink() ? selectedCodexHome : null | ||
| } catch { | ||
| return null | ||
| } |
There was a problem hiding this comment.
Existence check does not verify hardlink identity
resolveSelectedAccountCodexHomeForResume confirms that a file with the same sessions-relative path exists in the selected home, but it does not verify that the candidate is actually a hardlink of args.filePath (same dev/ino). The PR's stated invariant is "the selected account's home holds the same rollout," but the runtime check only confirms "some file with that name is there." UUID-based filenames make a false positive essentially impossible in practice, and the bridge exclusively creates hardlinks rather than copies, so the check is functionally correct today. But if a future code path (e.g., an export/import tool) could place a different file at the same relative path, the repin would silently redirect a session to the wrong account's home — the exact bug being fixed. Comparing dev/ino between lstat(args.filePath) and lstat(candidatePath) would make the "same rollout" invariant explicit and match how dedupeCodexRolloutFileAliases itself identifies aliases.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Greptile SummaryThis PR fixes a multi-account Codex session resume bug: when two or more managed accounts exist, the AI Vault dedup step keeps the lexicographically-smallest hardlink alias, whose The fix adds a resume-time repin step: at preparation time the owning host checks whether the currently-selected account's home contains the same rollout at the same sessions-relative path, and if so substitutes that home into the resume command. Every uncertain branch (no account selected, unbridged rollout, stale layout, non-local host) declines gracefully, so the behavior degrades to the pre-fix state rather than failing.
Confidence Score: 5/5Safe to merge. All uncertain branches decline gracefully, the shared contract is backward-compatible, and the fix is guarded by real-hardlink integration tests that were verified red on origin/main. The repin logic is tightly scoped to local per-account sessions, every early-return path leaves resume behavior unchanged from before the fix, and the new substituteCodexHome field is optional so older hosts degrade cleanly. Test coverage is thorough: fail-first integration tests with real hardlinks, round-trip drag payload tests, mobile preparation tests, and renderer gating tests all pass. Files Needing Attention: mobile/src/session/ai-vault-resume-preparation.ts has a minor comment and fallback error message that still reference legacy in a code path now shared with per-account sessions.
|
| Filename | Overview |
|---|---|
| src/main/codex/codex-legacy-session-resume.ts | Core repin logic added via resolveSelectedAccountCodexHomeForResume; early-returns cleanly for all non-per-account sessions; isLegacyRolloutRelativePath renamed to isDatedRolloutRelativePath and shared with the new path. |
| src/shared/ai-vault-resume-preparation.ts | AiVaultPrepareSessionResumeResult extended with optional substituteCodexHome; new isPerAccountManagedCodexHome helper mirrors isLegacySharedCodexHome convention; backward-compatible (absent = keep own home). |
| src/renderer/src/lib/ai-vault-session-resume-preparation.ts | Renderer preparation now handles per-account homes via aiVaultSessionNeedsResumePreparation; applies substituteCodexHome when returned; correctly gates per-account repin to local sessions only. |
| src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx | Drop path updated to call aiVaultSessionNeedsResumePreparation and invoke buildAiVaultDropRepinStartup when host signals a substitute home; correctly errors loudly when payload is from an older serializer lacking sessionCwd. |
| src/renderer/src/lib/ai-vault-resume-command.ts | New buildAiVaultDropRepinStartup rebuilds a full startup from sessionCwd + substituteCodexHome; correctly declines (null) when sessionCwd is absent (older serializer), allowing the caller to surface a clear error. |
| src/renderer/src/lib/ai-vault-session-drag.ts | sessionCwd added to drag payload type; round-trip serialization correctly distinguishes null (no cwd) from absent (old serializer); validation guard added to isSerializedPayload. |
| mobile/src/session/ai-vault-resume-preparation.ts | New file splits prepareMobileAiVaultSessionResume out of the launch file; correctly handles both legacy and per-account sessions; minor inaccuracy in comment/fallback error message (see comment). |
| src/main/ai-vault/runtime-session-scanner.ts | aiVaultPrepareSessionResumeResultSchema extended with substituteCodexHome to prevent zod from silently stripping the new field on the runtime host path. |
| src/main/index.ts | Both prepareLegacySharedCodexSessionResume call sites wired with getSelectedHostAccountCodexHomePath; optional chaining ensures nil-safe fallback when codexRuntimeHome is absent. |
| src/renderer/src/components/right-sidebar/AiVaultSessionRow.tsx | sessionCwd always written to drag payload (null when absent), enabling drop targets to distinguish 'no cwd' from 'old serializer' for the repin rebuild path. |
Sequence Diagram
sequenceDiagram
participant U as User
participant R as Renderer
participant M as Main Process
participant FS as Filesystem
Note over U,FS: Direct resume (sidebar / Copy resume command)
U->>R: click Resume on peer-aliased session
R->>R: aiVaultSessionNeedsResumePreparation()
R->>M: "prepareSessionResume(agent, filePath, codexHome=peerHome, executionHostId)"
M->>M: resolveSelectedAccountCodexHomeForResume()
M->>FS: lstat(selectedHome/sessions/relativePath)
FS-->>M: stat (file exists, is regular file)
M-->>R: substituteCodexHome: selectedHome
R->>R: "Build resume command with CODEX_HOME=selectedHome"
Note over U,FS: Drag-drop resume
U->>R: drag session (payload includes sessionCwd)
U->>R: drop on pane
R->>M: prepareSessionResume(...)
M-->>R: substituteCodexHome: selectedHome
R->>R: buildAiVaultDropRepinStartup()
R->>R: Launch with rebuilt startup
Note over U,FS: Mobile resume
U->>R: tap Resume (mobile)
R->>M: RPC aiVault.prepareSessionResume(...)
M-->>R: substituteCodexHome: selectedHome
R->>R: "session with codexHome=selectedHome"
Reviews (2): Last reviewed commit: "fix(ai-vault): repin dropped sessions wi..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe change adds per-account Codex home detection and resume repinning across host, renderer, and mobile flows. Resume preparation results can now include a substitute Codex home, with runtime schema and shared types updated accordingly. Host logic validates compatible rollout files before selecting an account home. Renderer drag payloads preserve session working directories and use substituted homes during dropped-session startup. Mobile preparation moves into a dedicated module and handles legacy, per-account, unavailable, and error responses. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
…ng under the wrong account The drag payload only carried sessionCwd when session.cwd was truthy, so a null-cwd codex session dropped onto a pane silently fell back to the prebuilt command - which pins the wrong account's CODEX_HOME, the exact defect this PR eliminates on the other resume surfaces. - Serializer always sends sessionCwd (null when the session has no cwd), so absence now only means an older-serializer payload. - The repin rebuild accepts a null cwd (the builders already omit the cd prefix), matching the sidebar Resume/Copy paths which repin regardless of cwd. - An unrepinnable payload (absent sessionCwd) now fails loudly with guidance instead of silently resuming under the wrong account's home.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/lib/ai-vault-resume-command.drop-repin.test.ts (1)
84-93: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the missing
sessionFilePathbranch.The suite tests missing
sessionCwd, but not the separate!args.payload.sessionFilePathrejection. Add a case with a validsessionCwdand an absentsessionFilePath, asserting that the helper returnsnull.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b560788e-a021-4055-a7cc-ff7a6fa42320
📒 Files selected for processing (6)
src/renderer/src/components/right-sidebar/AiVaultSessionRow.tsxsrc/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsxsrc/renderer/src/lib/ai-vault-resume-command.drop-repin.test.tssrc/renderer/src/lib/ai-vault-resume-command.tssrc/renderer/src/lib/ai-vault-session-drag.test.tssrc/renderer/src/lib/ai-vault-session-drag.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/renderer/src/components/right-sidebar/AiVaultSessionRow.tsx
- src/renderer/src/lib/ai-vault-session-drag.test.ts
- src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
- src/renderer/src/lib/ai-vault-session-drag.ts
…unt's home (stablyai#11224) * fix(ai-vault): resume a bridged Codex session under the selected account's home The account session bridge hardlinks every rollout into each per-account CODEX_HOME, and vault dedup keeps the lexicographically-smallest alias, so Resume could pin an inline CODEX_HOME naming a peer account — running the session under that account's auth.json and quota. At resume time the owning host now substitutes the selected account's home when it holds the same rollout at the same sessions-relative path, declining on any uncertainty so resume degrades to today's behavior instead of failing. * fix(ai-vault): repin dropped sessions without a cwd instead of resuming under the wrong account The drag payload only carried sessionCwd when session.cwd was truthy, so a null-cwd codex session dropped onto a pane silently fell back to the prebuilt command - which pins the wrong account's CODEX_HOME, the exact defect this PR eliminates on the other resume surfaces. - Serializer always sends sessionCwd (null when the session has no cwd), so absence now only means an older-serializer payload. - The repin rebuild accepts a null cwd (the builders already omit the cd prefix), matching the sidebar Resume/Copy paths which repin regardless of cwd. - An unrepinnable payload (absent sessionCwd) now fails loudly with guidance instead of silently resuming under the wrong account's home.
…unt's home (stablyai#11224) * fix(ai-vault): resume a bridged Codex session under the selected account's home The account session bridge hardlinks every rollout into each per-account CODEX_HOME, and vault dedup keeps the lexicographically-smallest alias, so Resume could pin an inline CODEX_HOME naming a peer account — running the session under that account's auth.json and quota. At resume time the owning host now substitutes the selected account's home when it holds the same rollout at the same sessions-relative path, declining on any uncertainty so resume degrades to today's behavior instead of failing. * fix(ai-vault): repin dropped sessions without a cwd instead of resuming under the wrong account The drag payload only carried sessionCwd when session.cwd was truthy, so a null-cwd codex session dropped onto a pane silently fell back to the prebuilt command - which pins the wrong account's CODEX_HOME, the exact defect this PR eliminates on the other resume surfaces. - Serializer always sends sessionCwd (null when the session has no cwd), so absence now only means an older-serializer payload. - The repin rebuild accepts a null cwd (the builders already omit the cd prefix), matching the sidebar Resume/Copy paths which repin regardless of cwd. - An unrepinnable payload (absent sessionCwd) now fails loudly with guidance instead of silently resuming under the wrong account's home.
Problem
The Codex account session bridge (#10770) hardlinks every rollout into each per-account
CODEX_HOMEat the identical relative path, so the AI Vault sees the same physical rollout under severalcodex-accounts/<uuid>/homeroots. Pre-parse dedup collapses those aliases by hardlink identity and — with both roots ranked equally — keeps the lexicographically smallest path (codex-session-root-dedup.ts:103). The surviving row'scodexHomebecomes an inlineCODEX_HOME='…'prefix on the resume command, which overrides the pane's correctly-resolved env.Net effect: with two or more managed accounts, Resume / Copy resume command / drag-drop resume can run a session under a peer account's
auth.jsonand quota, decided by UUID sort order, silently. Nothing on the resume path corrected it — the existing preparation only covered the legacy shared home.Fix (resume-time repin, no dedup changes)
At resume time, the owning host substitutes the selected account's home when it verifiably holds the same rollout at the same sessions-relative path (
resolveSelectedAccountCodexHomeForResumeincodex-legacy-session-resume.ts). Selected-account-over-path-order is the same product decisionrankTrustedCodexHomesForRescanalready documents for the pane-restore path — once a rollout sits in several homes, the path no longer names an account, and the selected account is what the user asked for.Every uncertain branch declines and resume behaves exactly as today:
executionHostIdgate on both requester and host)The result contract grows an optional
substituteCodexHome; the runtime-RPC zod schema is extended so it is not silently stripped (zod drops unknown keys).Surfaces
sessionCwdpayload field; payloads without it (older windows) fall back to the prebuilt command.prepareMobileAiVaultSessionResumemoved tomobile/src/session/ai-vault-resume-preparation.ts(the launch file crossed the max-lines limit, which must not be bumped).codexSessionRootRank; the pane-restoreresolveVerifiedResumeHomepath; runtime-hosted and SSH sessions.Tests
Fail-first (verified red on origin/main
70c81c4b32, green here): two per-account homes with controlled UUIDs, a real rollout recorded under the larger UUID, a real hardlink bridged into the smaller at the identical relative path, run through the realdedupeCodexRolloutFileAliasesin both discovery orders — the dedup pick is asserted (peer alias wins), then prepare must repin to the selected home:Regression guards: selected == row home (single-account), system-default selection, unbridged rollout, non-local host, stray transcript layout, legacy materialization with a selection present, zod strip-catcher for the runtime result, renderer local/remote gating, drag payload round-trip, and 5 mobile preparation cases.
typecheck(fresh, tsbuildinfo removed),oxlint+ both code-quality configs, max-lines ratchet, reliability gates: all green. ai-vault + codex suites: 1155 passed (3 unrelated load flakes — a benchmark budget and two app-server deadline tests — pass clean at--maxWorkers=2, no overlap with this change). Mobile suite (own vitest config): 34 passed.