From 4f6d50a08c2b568003375b2e53dfd1f9179c8f0c Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:09:49 -0700 Subject: [PATCH] fix(codex): seed pane override fallbacks --- .../codex-accounts/runtime-home-service.test.ts | 14 ++++++++++++++ src/main/codex-accounts/runtime-home-service.ts | 11 +++++++---- src/main/codex/codex-pane-account-registry.ts | 4 +++- src/main/codex/codex-pane-launch-account.test.ts | 15 +++++++++++++++ src/main/codex/codex-pane-launch-account.ts | 5 ++++- src/main/codex/codex-stale-pane-accounts.test.ts | 6 ++++++ 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/main/codex-accounts/runtime-home-service.test.ts b/src/main/codex-accounts/runtime-home-service.test.ts index a63b9dee389..d1a8b1bed0d 100644 --- a/src/main/codex-accounts/runtime-home-service.test.ts +++ b/src/main/codex-accounts/runtime-home-service.test.ts @@ -1133,6 +1133,20 @@ describe('CodexRuntimeHomeService', () => { } }) + it('seeds shared auth for a pane-local custom home on the real-home lane', async () => { + const systemAuth = createCodexAuthJson('system@example.com', 'acct-system', 'system-token') + writeFileSync(getSystemCodexAuthPath(), systemAuth, 'utf-8') + const store = createStore(createSettings({ codexSystemDefaultRealHomeEnabled: true })) + const { CodexRuntimeHomeService } = await import('./runtime-home-service') + const service = new CodexRuntimeHomeService(store as never) + const customHome = join(testState.fakeHomeDir, 'pane-custom-codex-home') + + expect(service.prepareForCodexLaunch(undefined, { CODEX_HOME: customHome })).toBe( + getRuntimeCodexHomePath() + ) + expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(systemAuth) + }) + it('skips retired-home reconciliation when no retained host pane can use it', async () => { const syncLegacySharedCodexConfigForRetainedPanes = vi.fn() vi.doMock('./legacy-shared-config-compatibility', () => ({ diff --git a/src/main/codex-accounts/runtime-home-service.ts b/src/main/codex-accounts/runtime-home-service.ts index e68fafc8a6b..e9256145b77 100644 --- a/src/main/codex-accounts/runtime-home-service.ts +++ b/src/main/codex-accounts/runtime-home-service.ts @@ -240,7 +240,7 @@ export class CodexRuntimeHomeService { return null } this.invalidateBackfillAfterManagedSystemDefaultLaunch(launchEnv) - this.syncForCurrentSelection() + this.syncForCurrentSelection(target, launchEnv) syncSystemCodexResourcesIntoManagedHome() syncSystemConfigIntoManagedCodexHome() // Why: sessions can be large; bridge them after launch so starting a fresh TUI never waits on a full tree walk. @@ -615,7 +615,10 @@ export class CodexRuntimeHomeService { return this.getRuntimeHomePath() } - syncForCurrentSelection(target?: CodexAccountSelectionTarget): void { + syncForCurrentSelection( + target?: CodexAccountSelectionTarget, + launchEnv?: NodeJS.ProcessEnv + ): void { if (target?.runtime === 'wsl') { this.syncWslRuntimeForCurrentSelection(target) return @@ -636,11 +639,11 @@ export class CodexRuntimeHomeService { this.lastHostAccountUsedSelfContainedHome = false this.lastSyncedAccountId = null this.lastWrittenAuthJson = null - if (this.isHostSystemDefaultRealHome()) { + if (this.isHostSystemDefaultRealHome(launchEnv)) { return } } - if (this.isHostSystemDefaultRealHome()) { + if (this.isHostSystemDefaultRealHome(launchEnv)) { // Why: retained daemon panes may own shared auth from a managed launch; // compatibility reconciliation runs later with durable provenance. if (this.lastSyncedAccountId !== null) { diff --git a/src/main/codex/codex-pane-account-registry.ts b/src/main/codex/codex-pane-account-registry.ts index d74f09809b6..640dcd17506 100644 --- a/src/main/codex/codex-pane-account-registry.ts +++ b/src/main/codex/codex-pane-account-registry.ts @@ -250,7 +250,9 @@ export function hasRecordedLegacySharedCodexPane(): boolean { return Object.values(readRegistry().panes).some( (record) => record.selectionKey === 'host' && - (record.homeRoute === undefined || record.homeRoute === 'shared-home') + (record.homeRoute === undefined || + record.homeRoute === 'shared-home' || + record.homeRoute === 'custom-home') ) } diff --git a/src/main/codex/codex-pane-launch-account.test.ts b/src/main/codex/codex-pane-launch-account.test.ts index 76436b19ecb..51a9a47508d 100644 --- a/src/main/codex/codex-pane-launch-account.test.ts +++ b/src/main/codex/codex-pane-launch-account.test.ts @@ -87,6 +87,21 @@ describe('resolveCodexPaneLaunchAccount', () => { ).toEqual({ selectionKey: 'host', accountId: null, homeRoute: 'custom-home' }) }) + it('keeps an account-owned route comparable when a pane override is ignored', () => { + const accounts = [managedAccount({ id: 'account-a' })] + + expect( + resolveCodexPaneLaunchAccount({ + pinnedByResume: false, + launchCodexHomePath: '/data/codex-accounts/account-a/home', + recordComparableHomeRoute: false, + systemCodexHomePath: SYSTEM_HOME, + settings: settings({ host: 'account-a', accounts }), + target: { runtime: 'host' } + }) + ).toEqual({ selectionKey: 'host', accountId: 'account-a', homeRoute: 'account-home' }) + }) + it('records the same account a resume pinned to when it is already selected', () => { const accounts = [managedAccount({ id: 'account-a' })] diff --git a/src/main/codex/codex-pane-launch-account.ts b/src/main/codex/codex-pane-launch-account.ts index b52ba60dc43..1bb3cca9c28 100644 --- a/src/main/codex/codex-pane-launch-account.ts +++ b/src/main/codex/codex-pane-launch-account.ts @@ -40,8 +40,11 @@ export function resolveCodexPaneLaunchAccount(args: { target: CodexAccountSelectionTarget }): CodexPaneAccountRecord | null { const selectionKey = getCodexSelectionLaneKey(args.target) + const resolvedHomeRoute = resolveCodexPaneHomeRoute(args) const homeRoute = - args.recordComparableHomeRoute === false ? 'custom-home' : resolveCodexPaneHomeRoute(args) + args.recordComparableHomeRoute === false && resolvedHomeRoute === 'shared-home' + ? 'custom-home' + : resolvedHomeRoute if (!args.pinnedByResume) { return { selectionKey, diff --git a/src/main/codex/codex-stale-pane-accounts.test.ts b/src/main/codex/codex-stale-pane-accounts.test.ts index 1906d19f360..c5ee4802e5b 100644 --- a/src/main/codex/codex-stale-pane-accounts.test.ts +++ b/src/main/codex/codex-stale-pane-accounts.test.ts @@ -102,12 +102,18 @@ describe('codex pane account registry', () => { accountId: null, homeRoute: 'wsl-home' }) + + expect(hasRecordedLegacySharedCodexPane()).toBe(false) + recordCodexPaneAccount('pty-custom', { selectionKey: 'host', accountId: null, homeRoute: 'custom-home' }) + expect(hasRecordedLegacySharedCodexPane()).toBe(true) + + forgetCodexPaneAccount('pty-custom') expect(hasRecordedLegacySharedCodexPane()).toBe(false) recordCodexPaneAccount('pty-shared', {