Skip to content
Merged
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
19 changes: 0 additions & 19 deletions src/main/agent-hooks/managed-agent-hook-controls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
installManagedAgentHooks,
removeManagedAgentHooksAsync,
resolveStartupManagedHookAction,
shouldInstallStartupManagedAgentHook,
shouldContinueManagedHookStartup
} from './managed-agent-hook-controls'

Expand Down Expand Up @@ -312,24 +311,6 @@ describe('startup managed hook reconciliation (STA-5679)', () => {
expect(resolveStartupManagedHookAction(null)).toBe('install')
})

it('only allows startup installs for globally enabled and agent-enabled hooks', () => {
expect(shouldInstallStartupManagedAgentHook({ agentStatusHooksEnabled: false }, 'codex')).toBe(
false
)
expect(
shouldInstallStartupManagedAgentHook(
{ agentStatusHooksEnabled: true, disabledTuiAgents: ['codex'] },
'codex'
)
).toBe(false)
expect(
shouldInstallStartupManagedAgentHook(
{ agentStatusHooksEnabled: true, disabledTuiAgents: ['claude'] },
'codex'
)
).toBe(true)
})

it('does not remove disabled agents during startup install reconciliation', async () => {
const settings = {
agentStatusHooksEnabled: true,
Expand Down
7 changes: 0 additions & 7 deletions src/main/agent-hooks/managed-agent-hook-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ export function resolveStartupManagedHookAction(
return isAgentStatusHooksEnabled(settings) ? 'install' : 'skip'
}

export function shouldInstallStartupManagedAgentHook(
settings: ManagedHookSettings,
agent: AgentHookTarget
): boolean {
return isAgentStatusHooksEnabledForAgent(settings, agent)
}

export function shouldContinueManagedHookStartup(
isQuitting: boolean,
settings: ManagedHookSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('CodexRuntimeHomeService', () => {
expect(store.updateSettings).not.toHaveBeenCalled()
expect(warnSpy).not.toHaveBeenCalled()

expect(service.isHostSystemDefaultRealHome()).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(false)
expect(service.prepareForRateLimitFetch()).toEqual({
kind: 'ready',
codexHomePath: managedHomePath1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('CodexRuntimeHomeService', () => {
const service = new CodexRuntimeHomeService(store as never)

// A host managed account's own home is its CODEX_HOME.
expect(service.isHostSystemDefaultRealHome()).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(false)
expect(service.isHostSystemDefaultSessionMigrationEligible()).toBe(false)
expect(service.prepareForCodexLaunch()).toBe(managedHomePath)
expect(
Expand Down Expand Up @@ -411,7 +411,7 @@ describe('CodexRuntimeHomeService', () => {

// Launching the account from its own home never populates the
// legacy shared mirror.
expect(service.isHostSystemDefaultRealHome()).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(false)
expect(service.prepareForCodexLaunch()).toBe(managedHomePath)

// A stale pre-E process writes matching, newer bytes to the shared mirror.
Expand All @@ -421,7 +421,7 @@ describe('CodexRuntimeHomeService', () => {
// syncForCurrentSelection), then Codex launches on the real home.
settings.activeCodexManagedAccountId = null
settings.activeCodexManagedAccountIdsByRuntime = { host: null, wsl: {} }
expect(service.isHostSystemDefaultRealHome()).toBe(true)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(true)
expect(service.prepareForCodexLaunch()).toBeNull()

// E owns refreshes in place, so takeover ignores later shared-mirror bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('CodexRuntimeHomeService', () => {
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)

expect(service.isHostSystemDefaultRealHome()).toBe(true)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(true)
expect(service.prepareForCodexLaunch()).toBeNull()
expect(service.getHostCodexHomePathsForSessionDiscovery()).toEqual([
getRuntimeCodexHomePath(),
Expand All @@ -67,7 +67,9 @@ describe('CodexRuntimeHomeService', () => {
mkdirSync(join(testState.userDataDir, 'codex-session-backfill'), { recursive: true })
const perSpawnCustomHome = join(testState.fakeHomeDir, 'per-spawn-custom-codex-home')
writeFileSync(markerPath, '{}\n', 'utf-8')
expect(service.isHostSystemDefaultRealHome({ CODEX_HOME: perSpawnCustomHome })).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected({ CODEX_HOME: perSpawnCustomHome })).toBe(
false
)
expect(service.prepareForCodexLaunch(undefined, { CODEX_HOME: perSpawnCustomHome })).toBe(
getRuntimeCodexHomePath()
)
Expand All @@ -86,7 +88,7 @@ describe('CodexRuntimeHomeService', () => {
'utf-8'
)
const shellLaunchEnv = { HOME: testState.fakeHomeDir, SHELL: '/bin/zsh' }
expect(service.isHostSystemDefaultRealHome(shellLaunchEnv)).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected(shellLaunchEnv)).toBe(false)
expect(service.prepareForCodexLaunch(undefined, shellLaunchEnv)).toBe(
getRuntimeCodexHomePath()
)
Expand All @@ -104,9 +106,9 @@ describe('CodexRuntimeHomeService', () => {
})
process.env.CODEX_HOME = getSystemCodexHomePath()
delete process.env.ORCA_CODEX_HOME
expect(service.isHostSystemDefaultRealHome()).toBe(true)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(true)
process.env.CODEX_HOME = join(testState.fakeHomeDir, 'user-owned-codex-home')
expect(service.isHostSystemDefaultRealHome()).toBe(false)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(false)
expect(service.prepareForRateLimitFetch()).toEqual({
kind: 'ready',
codexHomePath: getRuntimeCodexHomePath()
Expand Down Expand Up @@ -251,7 +253,6 @@ describe('CodexRuntimeHomeService', () => {

const service = new CodexRuntimeHomeService(store as never)

service.setRealHomeLaneGate(() => true)
expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(oldSystemAuth)
expect(readFileSync(join(getRuntimeCodexHomePath(), 'config.toml'), 'utf-8')).toContain(
'stale-provider'
Expand All @@ -273,7 +274,6 @@ describe('CodexRuntimeHomeService', () => {

setRealHomeRoutableForTest(true)
const restartedService = new CodexRuntimeHomeService(store as never)
restartedService.setRealHomeLaneGate(() => true)

expect(restartedService.prepareForCodexLaunch()).toBeNull()
expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(managedAuth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ describe('CodexRuntimeHomeService', () => {
}
)
const restartedService = new CodexRuntimeHomeService(store as never)
restartedService.setRealHomeLaneGate(() => true)

expect(existsSync(getRuntimeCodexAuthPath())).toBe(false)
writeFileSync(getSystemCodexAuthPath(), reloginAuth, 'utf-8')
Expand Down Expand Up @@ -525,7 +524,6 @@ describe('CodexRuntimeHomeService', () => {
}
)
const restartedService = new CodexRuntimeHomeService(store as never)
restartedService.setRealHomeLaneGate(() => true)
restartedService.reconcileLegacySharedHomeForRetainedPanes()

settings.activeCodexManagedAccountId = 'account-1'
Expand Down
23 changes: 3 additions & 20 deletions src/main/codex-accounts/runtime-home-service-home-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CodexRuntimeHomeManagedHome } from './runtime-home-service-managed-home
export abstract class CodexRuntimeHomeRouting extends CodexRuntimeHomeManagedHome {
getHostCodexHomePathsForSessionDiscovery(): string[] {
const homes = [this.getRuntimeHomePath()]
if (this.isHostSystemDefaultRealHome() || this.getSelfContainedManagedHostAccount()) {
if (this.isHostSystemDefaultRealHomeSelected() || this.getSelfContainedManagedHostAccount()) {
// Why: nested Orca processes can retain an ambient managed CODEX_HOME.
// Per-account lanes no longer bridge real-home history into the shared
// mirror, so include the real root for both directly-routed host lanes.
Expand Down Expand Up @@ -121,12 +121,6 @@ export abstract class CodexRuntimeHomeRouting extends CodexRuntimeHomeManagedHom
return [...homes.values()]
}

protected realHomeLaneGate: () => boolean = () => true

setRealHomeLaneGate(gate: () => boolean): void {
this.realHomeLaneGate = gate
}

// Why: real-home routing applies only to the host system-default selection.
// Managed accounts run in their own homes; custom CODEX_HOMEs stay on the
// mirror until cleanup can be tracked across old homes.
Expand All @@ -137,19 +131,8 @@ export abstract class CodexRuntimeHomeRouting extends CodexRuntimeHomeManagedHom
)
}

isHostSystemDefaultRealHome(launchEnv?: NodeJS.ProcessEnv): boolean {
return this.isHostSystemDefaultRealHomeSelected(launchEnv) && this.realHomeLaneGate()
}

// Why: launch prep evaluates the real-home lane AFTER clearing an unusable
// managed selection; read-only siblings need that same verdict with the
// selection ignored rather than cleared.
protected wouldSystemDefaultRouteToRealHome(launchEnv?: NodeJS.ProcessEnv): boolean {
return !hasCustomCodexHomeOverrideForLaunch(launchEnv) && this.realHomeLaneGate()
}

reconcileLegacySharedHomeForRetainedPanes(): void {
if (!this.isHostSystemDefaultRealHome() || !hasRecordedLegacySharedCodexPane()) {
if (!this.isHostSystemDefaultRealHomeSelected() || !hasRecordedLegacySharedCodexPane()) {
return
}
this.syncLegacySharedSystemDefaultAuthForRetainedPanes()
Expand Down Expand Up @@ -294,7 +277,7 @@ export abstract class CodexRuntimeHomeRouting extends CodexRuntimeHomeManagedHom
}
this.clearSelfContainedManagedSelection(selfContainedAccount)
}
if (this.isHostSystemDefaultRealHome()) {
if (this.isHostSystemDefaultRealHomeSelected()) {
this.copyMirrorLoginIntoEmptySystemHome()
if (hasRecordedLegacySharedCodexPane()) {
this.syncLegacySharedSystemDefaultAuthForRetainedPanes()
Expand Down
8 changes: 5 additions & 3 deletions src/main/codex-accounts/runtime-home-service-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class CodexRuntimeHomeLaunch extends CodexRuntimeHomeRouting {
// Why: only an untrusted home clears the selection; fall through to the
// system default without injecting a path Orca cannot prove it owns.
}
if (this.isHostSystemDefaultRealHome(launchEnv)) {
if (this.isHostSystemDefaultRealHomeSelected(launchEnv)) {
// Why: the system default runs Codex on the user's own ~/.codex.
// Returning null tells the PTY/env layer to inject no managed CODEX_HOME;
// the retired mirror is refreshed only for pre-rollout PTYs.
Expand Down Expand Up @@ -103,13 +103,15 @@ export abstract class CodexRuntimeHomeLaunch extends CodexRuntimeHomeRouting {
}
// Why: launch prep deselects an UNTRUSTED home before routing onward, so
// its next check sees no selection; predict that route, clearing nothing.
return this.wouldSystemDefaultRouteToRealHome(launchEnv)
return !hasCustomCodexHomeOverrideForLaunch(launchEnv)
? null
: resolveOrcaManagedCodexHomePath()
}
// Why the path-only resolver: getRuntimeHomePath() mkdirs the mirror, and
// this lookup must not create directories either.
return this.isHostSystemDefaultRealHome(launchEnv) ? null : resolveOrcaManagedCodexHomePath()
return this.isHostSystemDefaultRealHomeSelected(launchEnv)
? null
: resolveOrcaManagedCodexHomePath()
}

async prepareForCodexLaunchAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/main/codex-accounts/runtime-home-service-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class CodexRuntimeHomePaths extends CodexRuntimeHomeState {
}
return { kind: 'ready', homePath: resolved.kind === 'owned' ? resolved.homePath : null }
}
if (this.isHostSystemDefaultRealHome()) {
if (this.isHostSystemDefaultRealHomeSelected()) {
return { kind: 'ready', homePath: null }
}
return {
Expand Down
2 changes: 0 additions & 2 deletions src/main/codex-accounts/runtime-home-service-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export abstract class CodexRuntimeHomeState {
account: CodexManagedAccount
): { kind: 'ready'; homePath: string } | { kind: 'skip' }
abstract getRetainedHostCodexHookHomePaths(ptyIds: readonly string[]): string[]
abstract setRealHomeLaneGate(gate: () => boolean): void
abstract isHostSystemDefaultRealHomeSelected(launchEnv?: NodeJS.ProcessEnv): boolean
abstract isHostSystemDefaultRealHome(launchEnv?: NodeJS.ProcessEnv): boolean
abstract reconcileLegacySharedHomeForRetainedPanes(): void
abstract syncActiveWslSelectionsBeforeRestart(): Promise<void>

Expand Down
4 changes: 2 additions & 2 deletions src/main/codex-accounts/runtime-home-service-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export abstract class CodexRuntimeHomeSync extends CodexRuntimeHomeWsl {
this.lastHostAccountUsedSelfContainedHome = false
this.lastSyncedAccountId = null
this.lastWrittenAuthJson = null
if (this.isHostSystemDefaultRealHome(launchEnv)) {
if (this.isHostSystemDefaultRealHomeSelected(launchEnv)) {
return
}
}
if (this.isHostSystemDefaultRealHome(launchEnv)) {
if (this.isHostSystemDefaultRealHomeSelected(launchEnv)) {
// Why: retained daemon panes may own shared auth from a managed launch;
// compatibility reconciliation runs later with durable provenance.
if (this.lastSyncedAccountId !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('a status-hook problem never moves the system default off ~/.codex', ()
})
await _internals.settledForTesting()

expect(service.isHostSystemDefaultRealHome()).toBe(true)
expect(service.isHostSystemDefaultRealHomeSelected()).toBe(true)
// The resolver headless serve and the PTY launch both use: null keeps CODEX_HOME unset.
expect(service.resolveHostCodexHomePathForLaunchReadOnly()).toBeNull()
await expect(service.prepareForCodexLaunchAsync()).resolves.toBeNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ describe('CodexRuntimeHomeService', () => {
expect(existsSync(getRuntimeCodexAuthPath())).toBe(false)

setRealHomeRoutableForTest(true)
service.setRealHomeLaneGate(() => true)
writeFileSync(getSystemCodexAuthPath(), reloginAuth, 'utf-8')
service.reconcileLegacySharedHomeForRetainedPanes()

Expand Down
2 changes: 1 addition & 1 deletion src/main/codex/codex-ai-vault-session-resume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('prepareCodexAiVaultSessionResume', () => {
},
{
runtimeHome: {
isHostSystemDefaultRealHome: isSystemDefaultRealHome,
isHostSystemDefaultRealHomeSelected: isSystemDefaultRealHome,
resolveSelectedHostAccountCodexHomePathForResume: resolveSelectedHome
},
systemCodexHomePath: join(root, 'system-codex-home')
Expand Down
5 changes: 3 additions & 2 deletions src/main/codex/codex-ai-vault-session-resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { prepareLegacySharedCodexSessionResume } from './codex-legacy-session-re

type CodexAiVaultRuntimeHome = Pick<
CodexRuntimeHomeService,
'isHostSystemDefaultRealHome' | 'resolveSelectedHostAccountCodexHomePathForResume'
'isHostSystemDefaultRealHomeSelected' | 'resolveSelectedHostAccountCodexHomePathForResume'
>

/** Keeps window and serve AI Vault resumes behind the same refusing account-home gate. */
Expand All @@ -19,7 +19,8 @@ export function prepareCodexAiVaultSessionResume(
}
): Promise<AiVaultPrepareSessionResumeResult> {
return prepareLegacySharedCodexSessionResume(args, {
isHostSystemDefaultRealHome: () => options.runtimeHome?.isHostSystemDefaultRealHome() === true,
isHostSystemDefaultRealHomeSelected: () =>
options.runtimeHome?.isHostSystemDefaultRealHomeSelected() === true,
getSelectedHostAccountCodexHomePath: () =>
options.runtimeHome?.resolveSelectedHostAccountCodexHomePathForResume() ?? null,
systemCodexHomePath: options.systemCodexHomePath
Expand Down
Loading
Loading