Revert "Isolate managed Codex launch homes"

This reverts commit 826a6c4773.
This commit is contained in:
Jinwoo-H
2026-05-10 20:14:36 -04:00
parent ef92abfd33
commit 7b78b6544a
4 changed files with 12 additions and 58 deletions
@@ -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')
@@ -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,
+5 -4
View File
@@ -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
}
+5 -4
View File
@@ -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