Fix stale Orca userData env on app relaunch (#4446)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-06-02 01:41:34 -04:00
committed by GitHub
co-authored by Orca
parent e86d094f4d
commit 02f24017f3
4 changed files with 75 additions and 3 deletions
@@ -361,6 +361,48 @@ describe('CodexRuntimeHomeService', () => {
)
})
it('uses the canonical Electron userData for legacy active host migration', async () => {
const staleUserDataDir = mkdtempSync(join(tmpdir(), 'orca-stale-runtime-home-'))
const staleRuntimeHomePath = join(staleUserDataDir, 'codex-runtime-home', 'home')
try {
mkdirSync(staleRuntimeHomePath, { recursive: true })
process.env.ORCA_USER_DATA_PATH = staleUserDataDir
const legacyLaunchHomePath = join(
testState.userDataDir,
'codex-runtime-home',
'launch',
'host',
'account-old',
'home'
)
const legacyActiveHomePath = getLegacyActiveHostCodexHomePath()
mkdirSync(legacyLaunchHomePath, { recursive: true })
mkdirSync(join(legacyActiveHomePath, '..'), { recursive: true })
symlinkSync(
legacyLaunchHomePath,
legacyActiveHomePath,
process.platform === 'win32' ? 'junction' : undefined
)
writeFileSync(getSystemCodexAuthPath(), '{"account":"system"}\n', 'utf-8')
const store = createStore(createSettings())
const { configureOrcaUserDataPathEnv } = await import('../startup/configure-process')
configureOrcaUserDataPathEnv()
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
new CodexRuntimeHomeService(store as never)
expect(process.env.ORCA_USER_DATA_PATH).toBe(testState.userDataDir)
expect(normalizeLinkTarget(readlinkSync(legacyActiveHomePath))).toBe(
normalizeLinkTarget(getRuntimeCodexHomePath())
)
expect(normalizeLinkTarget(readlinkSync(legacyActiveHomePath))).not.toBe(
normalizeLinkTarget(staleRuntimeHomePath)
)
} finally {
rmSync(staleUserDataDir, { recursive: true, force: true })
}
})
it('does not create a legacy active host pointer for fresh shared-home users', async () => {
writeFileSync(getSystemCodexAuthPath(), '{"account":"system"}\n', 'utf-8')
const store = createStore(createSettings())
+2 -3
View File
@@ -45,6 +45,7 @@ import {
import { checkForUpdatesFromMenu, isQuittingForUpdate } from './updater'
import {
configureDevUserDataPath,
configureOrcaUserDataPathEnv,
enableMainProcessGpuFeatures,
installDevParentDisconnectQuit,
installDevParentSignalQuit,
@@ -233,9 +234,7 @@ if (app.isPackaged && process.platform !== 'win32') {
})
}
configureDevUserDataPath(is.dev)
// Why: CLI-shared Codex helpers cannot import Electron. Seed the resolved
// app userData path once Electron has applied dev/e2e overrides.
process.env.ORCA_USER_DATA_PATH ??= app.getPath('userData')
configureOrcaUserDataPathEnv()
const startupDiagnosticsEnabled = isStartupDiagnosticsEnabled()
if (startupDiagnosticsEnabled) {
logStartupDiagnostic('before-single-instance-lock', {
@@ -151,6 +151,30 @@ describe('configureDevUserDataPath', () => {
})
})
describe('configureOrcaUserDataPathEnv', () => {
it('overwrites stale inherited ORCA_USER_DATA_PATH with Electron userData', async () => {
const { app } = await import('electron')
const { configureOrcaUserDataPathEnv } = await import('./configure-process')
const originalUserDataPath = process.env.ORCA_USER_DATA_PATH
process.env.ORCA_USER_DATA_PATH = '/tmp/stale-orca-user-data'
app.setPath('userData', '/tmp/current-orca-user-data')
let configuredUserDataPath: string | undefined
try {
configureOrcaUserDataPathEnv()
configuredUserDataPath = process.env.ORCA_USER_DATA_PATH
} finally {
if (originalUserDataPath === undefined) {
delete process.env.ORCA_USER_DATA_PATH
} else {
process.env.ORCA_USER_DATA_PATH = originalUserDataPath
}
}
expect(configuredUserDataPath).toBe('/tmp/current-orca-user-data')
})
})
describe('shouldInstallManagedHooks', () => {
it('keeps managed hook auto-install enabled for default dev runs', async () => {
const { shouldInstallManagedHooks } = await import('./configure-process')
+7
View File
@@ -145,6 +145,13 @@ export function configureDevUserDataPath(isDev: boolean): void {
app.setPath('userData', join(app.getPath('appData'), 'orca-dev'))
}
export function configureOrcaUserDataPathEnv(): void {
// Why: app relaunches can inherit an ORCA_USER_DATA_PATH from an older CLI or
// updater process. Main must canonicalize it before CLI-shared modules build
// runtime-home paths, or migrations can bridge two Orca app-data directories.
process.env.ORCA_USER_DATA_PATH = app.getPath('userData')
}
export function shouldInstallManagedHooks(isDev: boolean): boolean {
void isDev
// Why: managed hook installation now targets Orca-owned, environment-scoped