Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,38 @@ describe('CodexRuntimeHomeService', () => {
}
})

it('bridges managed-account history into the real home when launching system default', async () => {
const accountBridge = vi.fn(async () => {})
vi.doMock('../codex/codex-account-session-bridge', () => ({
startCodexAccountSessionBridgeInBackground: accountBridge
}))
const managedHomePath = createManagedAuth(
testState.userDataDir,
'account-1',
createCodexAuthJson('user@example.com', 'acct-1', 'refresh-1')
)
const store = createStore(
createSettings({
realHomeRoutable: true,
codexManagedAccounts: [
createCodexAccountRecord('account-1', 'user@example.com', 'acct-1', managedHomePath)
]
})
)
try {
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)

expect(service.prepareForCodexLaunch()).toBeNull()
expect(accountBridge).toHaveBeenCalledWith({
targetCodexHomePath: getSystemCodexHomePath(),
sourceCodexHomePaths: [managedHomePath]
})
} finally {
vi.doUnmock('../codex/codex-account-session-bridge')
}
})

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')
Expand Down
1 change: 1 addition & 0 deletions src/main/codex-accounts/runtime-home-service-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export abstract class CodexRuntimeHomeLaunch extends CodexRuntimeHomeRouting {
// Null leaves CODEX_HOME uninjected; refresh the retired mirror only for retained panes.
this.copyMirrorLoginIntoEmptySystemHome()
this.reconcileLegacySharedHomeForRetainedPanes()
this.startSystemDefaultSessionBridgeForLaunch()
return null
}
this.invalidateBackfillAfterManagedSystemDefaultLaunch(launchEnv)
Expand Down
42 changes: 34 additions & 8 deletions src/main/codex-accounts/runtime-home-service-managed-home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ export abstract class CodexRuntimeHomeManagedHome extends CodexRuntimeHomeSync {
]
}

// Real-home launches see managed-account history too, or switching back to system default hides it (#25000).
protected startSystemDefaultSessionBridgeForLaunch(): void {
const sourceCodexHomePaths = this.getManagedHostAccountHomesForSessionDiscovery()
if (sourceCodexHomePaths.length === 0) {
return
}
void startCodexAccountSessionBridgeInBackground({
targetCodexHomePath:
resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),
Comment on lines +158 to +159

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.

Major · Data Integrity & Integration · Quick win

🔎 Supported by static analysis

Script executed:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --find-renames c074ec50da641241e79867cf520cea93e45a919d0 a3cacfb26556809d29235e16982373b82a74b6d0 -- src/main/codex-accounts/runtime-home-service-managed-home.ts src/main/codex-accounts
printf '%s\n' '--- target implementation and related symbols ---'
rg -n -F --glob '*.ts' -e 'resolveHostCodexSessionSourceHome' -e 'isHostSystemDefaultRealHomeSelected' -e 'prepareForCodexLaunch' -e 'targetCodexHomePath' -e 'codexSessionSourceHome' src/main/codex-accounts src | head -240
printf '%s\n' '--- relevant file excerpts ---'
nl -ba src/main/codex-accounts/runtime-home-service-managed-home.ts | sed -n '1,240p'
printf '%s\n' '--- selection/launch definitions ---'
rg -l -F --glob '*.ts' -e 'isHostSystemDefaultRealHomeSelected' -e 'resolveHostCodexSessionSourceHome' -e 'codexSessionSourceHome' src/main | while read -r f; do echo "### $f"; nl -ba "$f" | sed -n '1,280p'; done
printf '%s\n' '--- focused tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'resolveHostCodexSessionSourceHome' -e 'isHostSystemDefaultRealHomeSelected' -e 'startSystemDefaultSessionBridgeForLaunch' -e 'configured source' -e 'session source' src/main/codex-accounts src | head -240

Repository: stablyai/orca

Length of output: 45667


Script executed:

printf '%s\n' '--- launch ---'
nl -ba src/main/codex-accounts/runtime-home-service-launch.ts | sed -n '1,190p'
printf '%s\n' '--- home routing ---'
nl -ba src/main/codex-accounts/runtime-home-service-home-routing.ts | sed -n '1,150p'
printf '%s\n' '--- session source resolver ---'
nl -ba src/main/codex/codex-session-source-home.ts
printf '%s\n' '--- direct consumers of source home ---'
nl -ba src/main/startup/main-process-runtime-service.ts | sed -n '95,140p'
nl -ba src/main/startup/main-process-account-services.ts | sed -n '35,65p'
nl -ba src/main/startup/main-window-core-services.ts | sed -n '75,105p'
printf '%s\n' '--- configured source tests ---'
nl -ba src/main/codex-accounts/runtime-home-session-migration-pass.test.ts | sed -n '1,180p'
nl -ba src/main/codex-accounts/runtime-home-real-home-lane-routing.test.ts | sed -n '1,230p'
printf '%s\n' '--- relevant settings declarations ---'
rg -n -F --glob '*.{ts,tsx}' -e 'codexSessionSourceHome' -e 'realHomeRoutable' src/shared src/main | head -160

Repository: stablyai/orca

Length of output: 42129


Target the real Codex home for real-home launches.

When the real-home lane is selected, prepareForCodexLaunch() returns null, so CODEX_HOME remains unset and Codex reads the system home. The bridge currently targets the configured history source instead, so managed sessions can remain unavailable from the real home.

🐛 Suggested fix
--- "a/src/main/codex-accounts/runtime-home-service-managed-home.ts"
+++ "b/src/main/codex-accounts/runtime-home-service-managed-home.ts"
@@ -155,8 +155,7 @@
       return
     }
     void startCodexAccountSessionBridgeInBackground({
-      targetCodexHomePath:
-        resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),
+      targetCodexHomePath: getSystemCodexHomePath(),
       sourceCodexHomePaths
     })
   }

If the configured history home must also contribute existing sessions, include it as a source instead of using it as the target.

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
targetCodexHomePath:
resolveHostCodexSessionSourceHome(this.store.getSettings()) ?? getSystemCodexHomePath(),
targetCodexHomePath: getSystemCodexHomePath(),

sourceCodexHomePaths
})
}

// Per-account homes own auth refreshes in place; selection needs no shared-mirror read-back.
protected syncSelfContainedManagedSelection(account: CodexManagedAccount): void {
const resolved = this.resolveSelfContainedManagedHome(account)
Expand Down Expand Up @@ -259,13 +272,26 @@ export abstract class CodexRuntimeHomeManagedHome extends CodexRuntimeHomeSync {
const systemCodexHomePath =
resolveWslCodexSessionSourceHome(this.store.getSettings(), distro) ??
this.getWslSystemCodexHomePath({ runtime: 'wsl', wslDistro: distro })
if (systemCodexHomePath && systemCodexHomePath !== runtimeHomePath) {
// Create history links inside the distro so Codex can see them in /resume.
void startWslCodexSessionBridgeInBackground({
distro,
systemCodexHomePath,
managedCodexHomePath: runtimeHomePath
})
}
const targetLinuxPath = parseWslUncPath(runtimeHomePath)?.linuxPath ?? runtimeHomePath
// Sibling account homes are sources too, or a switch hides the previous account's sessions (#18486).
const sourceHomes = [
systemCodexHomePath,
...this.store
.getSettings()
.codexManagedAccounts.map((account) => this.getWslLaunchCodexHomePath(account, distro))
].filter(
(home): home is string =>
!!home && (parseWslUncPath(home)?.linuxPath ?? home) !== targetLinuxPath
)
// Create history links inside the distro so Codex can see them in /resume; one wsl.exe at a time.
void (async () => {
for (const sourceHome of new Set(sourceHomes)) {
await startWslCodexSessionBridgeInBackground({
distro,
systemCodexHomePath: sourceHome,
managedCodexHomePath: runtimeHomePath
})
}
})()
}
}
74 changes: 73 additions & 1 deletion src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,79 @@ describe('CodexRuntimeHomeService', () => {
}
})

it('bridges sibling WSL account homes into the selected account home', async () => {
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
const startWslCodexSessionBridgeInBackground = vi.fn(() => Promise.resolve())
vi.doMock('../codex/wsl-codex-session-bridge', () => ({
startWslCodexSessionBridgeInBackground
}))
const wslHome = join(testState.userDataDir, 'ubuntu-home')
vi.doMock('../wsl', () => ({
getDefaultWslDistro: () => 'Ubuntu',
getWslHome: () => wslHome
}))
const accountsRoot = join(wslHome, '.local', 'share', 'orca', 'codex-accounts')
const wslAccount = (id: string, distro: string) => ({
id,
email: `${id}@example.com`,
managedHomePath: join(accountsRoot, id, 'home'),
managedHomeRuntime: 'wsl' as const,
wslDistro: distro,
wslLinuxHomePath: join(accountsRoot, id, 'home'),
providerAccountId: null,
workspaceLabel: null,
workspaceAccountId: null,
createdAt: 1,
updatedAt: 1,
lastAuthenticatedAt: 1
})
const store = createStore(
createSettings({
codexManagedAccounts: [
wslAccount('a', 'Ubuntu'),
wslAccount('b', 'Ubuntu'),
wslAccount('other-distro', 'Debian')
],
activeCodexManagedAccountIdsByRuntime: { host: null, wsl: { Ubuntu: 'b' } }
})
)

try {
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
const selectedHome = join(accountsRoot, 'b', 'home')

expect(service.prepareForCodexLaunch({ runtime: 'wsl', wslDistro: 'Ubuntu' })).toBe(
selectedHome
)
await vi.waitFor(() =>
expect(startWslCodexSessionBridgeInBackground.mock.calls).toEqual([
[
{
distro: 'Ubuntu',
systemCodexHomePath: join(wslHome, '.codex'),
managedCodexHomePath: selectedHome
}
],
[
{
distro: 'Ubuntu',
systemCodexHomePath: join(accountsRoot, 'a', 'home'),
managedCodexHomePath: selectedHome
}
]
])
)
} finally {
vi.doUnmock('../codex/wsl-codex-session-bridge')
vi.doUnmock('../wsl')
if (originalPlatform) {
Object.defineProperty(process, 'platform', originalPlatform)
}
}
})

it('does not rescan retired sessions after the launch drain bridges them', async () => {
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
Expand Down Expand Up @@ -487,7 +560,6 @@ describe('CodexRuntimeHomeService', () => {
await Promise.all(drainTasks)
expect(readFileSync(linkedSessionPath, 'utf-8')).toBe('{"session":"retired"}\n')
expect(statSync(linkedSessionPath).ino).toBe(statSync(retiredSessionPath).ino)
expect(existsSync(join(selectedHome, relativeSessionPath))).toBe(false)

rmSync(linkedSessionPath)
rmSync(retiredHome, { recursive: true })
Expand Down
Loading