diff --git a/src/main/browser/agent-browser/helper-process/agent-browser-process-environment.ts b/src/main/browser/agent-browser/helper-process/agent-browser-process-environment.ts index ebacfddf2ce..e77a0d25d2c 100644 --- a/src/main/browser/agent-browser/helper-process/agent-browser-process-environment.ts +++ b/src/main/browser/agent-browser/helper-process/agent-browser-process-environment.ts @@ -46,7 +46,7 @@ export function createAgentBrowserProcessEnvironment(options: { return { env, ownsSocketDirectory: true } } -/** Until this lands, agent-browser reads the user's config files; a missing file would fail every command. */ +/** Until this lands, agent-browser reads the user's ~/.agent-browser/config.json and ./agent-browser.json. */ export async function pointAtEmptyAgentBrowserConfig( env: NodeJS.ProcessEnv, userDataPath: string diff --git a/src/main/browser/agent-browser/session-lifecycle/agent-browser-bridge-shutdown.ts b/src/main/browser/agent-browser/session-lifecycle/agent-browser-bridge-shutdown.ts index 71cea05b84b..98e91769511 100644 --- a/src/main/browser/agent-browser/session-lifecycle/agent-browser-bridge-shutdown.ts +++ b/src/main/browser/agent-browser/session-lifecycle/agent-browser-bridge-shutdown.ts @@ -5,6 +5,7 @@ import type { AgentBrowserCleanupOptions } from './agent-browser-cleanup-options export abstract class AgentBrowserBridgeShutdown extends AgentBrowserBridgeLifecycle { async sweepOrphanedSessions(): Promise { + await this.agentBrowserConfigReady return sweepOrphanedAgentBrowserSessions({ binaryPath: this.agentBrowserBin, env: this.agentBrowserEnv, diff --git a/src/main/browser/agent-browser/session-routing/agent-browser-bridge-state.ts b/src/main/browser/agent-browser/session-routing/agent-browser-bridge-state.ts index 9832eca790a..664ce842af8 100644 --- a/src/main/browser/agent-browser/session-routing/agent-browser-bridge-state.ts +++ b/src/main/browser/agent-browser/session-routing/agent-browser-bridge-state.ts @@ -25,6 +25,8 @@ export abstract class AgentBrowserBridgeState { protected readonly processingQueues = new Set() protected readonly agentBrowserBin: string protected readonly agentBrowserEnv: NodeJS.ProcessEnv + // Startup spawns await it; agent commands come long after it lands. + protected readonly agentBrowserConfigReady: Promise protected readonly ownsAgentBrowserSocketDirectory: boolean // Null disables idle-replacement detection when daemon lifetime is unbounded. protected readonly agentBrowserIdleTimeoutMs: number | null @@ -48,8 +50,11 @@ export abstract class AgentBrowserBridgeState { userDataPath }) this.agentBrowserEnv = processEnvironment.env - // Lands long before an agent's first command; a failed write keeps agent-browser's own lookup. - void pointAtEmptyAgentBrowserConfig(this.agentBrowserEnv, userDataPath).catch(() => {}) + // A failed write keeps agent-browser's own lookup; a missing file would fail every command. + this.agentBrowserConfigReady = pointAtEmptyAgentBrowserConfig( + this.agentBrowserEnv, + userDataPath + ).catch(() => {}) this.ownsAgentBrowserSocketDirectory = processEnvironment.ownsSocketDirectory const idleTimeoutMs = Number(this.agentBrowserEnv.AGENT_BROWSER_IDLE_TIMEOUT_MS) this.agentBrowserIdleTimeoutMs = idleTimeoutMs > 0 ? idleTimeoutMs : null