From 7b78b6544a8231ddc828cfda50fd81a096ecfec7 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Sun, 10 May 2026 18:29:45 -0400 Subject: [PATCH] Revert "Isolate managed Codex launch homes" This reverts commit 826a6c4773ce9bf12e3dafa7cab8271eab0f26c1. --- .../runtime-home-service.test.ts | 32 ------------------- .../codex-accounts/runtime-home-service.ts | 20 ++---------- src/main/ipc/pty.ts | 9 +++--- src/shared/types.ts | 9 +++--- 4 files changed, 12 insertions(+), 58 deletions(-) diff --git a/src/main/codex-accounts/runtime-home-service.test.ts b/src/main/codex-accounts/runtime-home-service.test.ts index 466e3f9d2..adbc1a644 100644 --- a/src/main/codex-accounts/runtime-home-service.test.ts +++ b/src/main/codex-accounts/runtime-home-service.test.ts @@ -395,38 +395,6 @@ describe('CodexRuntimeHomeService', () => { expect(existsSync(join(testState.fakeHomeDir, '.codex'))).toBe(true) }) - it('returns the managed home for managed Codex launch and rate-limit preparation', async () => { - const managedHomePath = createManagedAuth( - testState.userDataDir, - 'account-1', - '{"account":"managed"}\n' - ) - const store = createStore( - createSettings({ - codexManagedAccounts: [ - { - id: 'account-1', - email: 'user@example.com', - managedHomePath, - providerAccountId: null, - workspaceLabel: null, - workspaceAccountId: null, - createdAt: 1, - updatedAt: 1, - lastAuthenticatedAt: 1 - } - ], - activeCodexManagedAccountId: 'account-1' - }) - ) - - const { CodexRuntimeHomeService } = await import('./runtime-home-service') - const service = new CodexRuntimeHomeService(store as never) - - expect(service.prepareForCodexLaunch()).toBe(managedHomePath) - expect(service.prepareForRateLimitFetch()).toBe(managedHomePath) - }) - it('does not overwrite auth.json when no managed account was ever active', async () => { const runtimeAuthPath = join(testState.fakeHomeDir, '.codex', 'auth.json') writeFileSync(runtimeAuthPath, '{"account":"original"}\n', 'utf-8') diff --git a/src/main/codex-accounts/runtime-home-service.ts b/src/main/codex-accounts/runtime-home-service.ts index 753ae6320..029f5e2c4 100644 --- a/src/main/codex-accounts/runtime-home-service.ts +++ b/src/main/codex-accounts/runtime-home-service.ts @@ -59,12 +59,12 @@ export class CodexRuntimeHomeService { prepareForCodexLaunch(): string { this.syncForCurrentSelection() - return this.getPreparedCodexHomePath() + return this.getRuntimeHomePath() } prepareForRateLimitFetch(): string { this.syncForCurrentSelection() - return this.getPreparedCodexHomePath() + return this.getRuntimeHomePath() } syncForCurrentSelection(): void { @@ -220,22 +220,6 @@ export class CodexRuntimeHomeService { return accounts.find((account) => account.id === activeAccountId) ?? null } - private getPreparedCodexHomePath(): string { - const settings = this.store.getSettings() - const activeAccount = this.getActiveAccount( - settings.codexManagedAccounts, - settings.activeCodexManagedAccountId - ) - if (!activeAccount) { - return this.getRuntimeHomePath() - } - // Why: live Codex processes mutate CODEX_HOME/auth.json during OAuth - // refresh. Managed sessions must run from their account-owned home so old - // PTYs on account B cannot race a newly launched account A process through - // the shared ~/.codex runtime file. - return activeAccount.managedHomePath - } - private runtimeAuthMatchesAccount( runtimeAuthContents: string, activeAccount: CodexManagedAccount, diff --git a/src/main/ipc/pty.ts b/src/main/ipc/pty.ts index 87e791205..cbbe63a4d 100644 --- a/src/main/ipc/pty.ts +++ b/src/main/ipc/pty.ts @@ -219,10 +219,11 @@ export function buildPtyHostEnv( baseEnv.ORCA_PI_CODING_AGENT_DIR = baseEnv.PI_CODING_AGENT_DIR } - // Why: managed Codex accounts use account-owned homes so live Codex PTYs on - // different accounts cannot race on one shared auth.json during OAuth - // refresh. Keep the override PTY-scoped so Orca does not mutate the app - // process environment or the user's unrelated external shells. + // Why: Codex account switching now materializes auth into one shared + // runtime home (~/.codex), and Codex launched inside Orca terminals must + // use that same prepared home as quota fetches and other entry points. + // Keep the override PTY-scoped so Orca does not mutate the app process + // environment or the user's unrelated external shells. if (opts.selectedCodexHomePath) { baseEnv.CODEX_HOME = opts.selectedCodexHomePath } diff --git a/src/shared/types.ts b/src/shared/types.ts index 16e461474..5224e898d 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -1179,10 +1179,11 @@ export type GlobalSettings = { * 300 000 (5 min, the standard Anthropic API / Bedrock TTL) and * 3 600 000 (1 hr, for extended-TTL plans). */ promptCacheTtlMs: number - /** Why: Codex account routing is a durable app preference owned by the main - * process, not transient UI state. Persisting managed homes here lets Orca - * resolve the correct `CODEX_HOME` before the renderer hydrates, while - * keeping this scope explicitly separate from Codex usage analytics. */ + /** Why: Codex rate-limit account routing is a durable app preference owned by + * the main process, not transient UI state. Persisting the selected managed + * homes here lets Orca resolve the correct `CODEX_HOME` before the renderer + * hydrates, while keeping this scope explicitly separate from Codex usage + * analytics and external terminal sessions. */ codexManagedAccounts: CodexManagedAccount[] activeCodexManagedAccountId: string | null /** Why: Claude Code keeps conversations under one shared config root. Orca