Repository navigation
Description
Details
On Windows, every agent-detection pass blocks the Electron main process for about 1.1s. It runs synchronous statSync calls over the whole PATH a second time, after an async check has already searched it. Startup triggers it 2–3 times, so the main process is unresponsive for about 3s: no IPC is handled and no PTY data moves.
Evidence
I took a V8 CPU profile of the main process during the ACK-backpressured scenarios in artificial-opencode-terminal-load.spec.ts. This was an unminified e2e build on Windows, with 95 PATH dirs.
- Agent detection took 15–19% of main-thread time in all three scenarios. PTY ingestion and delivery combined took about 2–5%.
- Each pass was one continuous block of about 1.1s, and there were 2–3 passes in the first 7s.
- One missed command costs 95 dirs × 4 names × ~60µs per stat ≈ 23ms. About 45 of the ~55 probe commands miss, which comes to about 1.1s.
Cause
- detectAgentCommandsOnHost first checks every probe command asynchronously with isCommandOnPath:
orca/src/main/preflight/agent-command-detection.ts
Lines 24 to 29 in 5748d11
const pathChecks = await Promise.all( commands.map(async (cmd) => ({ cmd, installedOnPath: await isCommandOnPath(cmd) })) ) - That async check searches process PATH merged with the persisted Windows PATH (on POSIX and in WSL guests, the same PATH):
orca/src/main/ipc/preflight-command-exec.ts
Line 231 in 5748d11
return isCommandOnLocalPath(command, { env: buildLocalPreflightEnv() })
orca/src/main/ipc/preflight-local-env.ts
Lines 29 to 32 in 5748d11
const env = stringOnlyProcessEnv(process.env) // The running app must merge persisted Windows PATH to see newly installed CLIs. mergePersistedWindowsPath(env) return env - Every miss then goes to the install-dir fallback:
orca/src/main/preflight/agent-command-detection.ts
Lines 31 to 36 in 5748d11
// Resolve cold-GUI install dirs once; use the same WSL-filtered PATH while retaining process PATH elsewhere. const guestMounts = readGuestWindowsDriveMounts() const installDirCommands = detectCommandsInInstallDirs( missedCommands, guestMounts.length > 0 ? buildLocalPreflightEnv(guestMounts)?.PATH : undefined )
orca/src/shared/local-agent-install-dir-detection.ts
Lines 14 to 17 in 5748d11
const resolvedCommands = pathEnv === undefined ? resolveCliCommands(commands) : resolveCliCommands(commands, { pathEnv }) - That fallback, resolveCliCommands, re-scans all PATH dirs synchronously before it gets to the install dirs:
orca/src/shared/node-cli-command-resolution.ts
Lines 278 to 295 in 5748d11
export function resolveCliCommands( commandNames: readonly string[], options: ResolveCommandOptions = {} ): Map<string, string> { const platform = options.platform ?? process.platform const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null const pathDirectories = splitPath(pathEnv) const homePath = options.homePath ?? homedir() const installDirectories = getCliInstallDirectories(platform, homePath) const resolved = new Map<string, string>() for (const commandName of new Set(commandNames)) { const executableNames = getExecutableNames(platform, commandName) const pathCandidate = findFirstExecutable(platform, pathDirectories, executableNames) const installCandidate = pathCandidate ?? findFirstExecutable(platform, installDirectories, executableNames) resolved.set(commandName, installCandidate ?? commandName) }
orca/src/shared/node-cli-command-resolution.ts
Lines 76 to 91 in 5748d11
function isRunnableCommand(platform: NodeJS.Platform, candidate: string): boolean { try { const stats = statSync(candidate) if (!stats.isFile()) { return false } if (platform === 'win32') { return true } // Skip nonexecutables/placeholders now so GUI probing reaches a runnable CLI instead of later EACCES/EISDIR. accessSync(candidate, constants.X_OK) return true } catch { return false } } - The main process has no in-flight sharing for preflight:detectAgents:
orca/src/main/ipc/preflight.ts
Lines 38 to 40 in 5748d11
ipcMain.handle('preflight:detectAgents', async (_event, args?: AgentDetectionRequest) => detectAgentsOnHost({ kind: 'local', context: args }, detectionOptions(args)) )
The renderer de-duplicates per context key, but "enabled only" and "include disabled" use different keys, and the skills panel makes its own request:
orca/src/renderer/src/store/slices/local-detected-agent-state.ts
Lines 119 to 120 in 5748d11
const pending = window.api.preflight .detectAgents(includeDisabled ? context : { ...context, enabledOnly: true })
Mostly impacts Windows users with long PATHs (evidently, me). On macOS and Linux the extra scan is much cheaper (shorter PATH, faster stat), but the work is just as redundant there.
Activity
ctolkien commentedon Oct 29, 2026
Fixed upstream by #34636 (6af1ef0). Re-profiled the same scenarios on f5c84ea: agent-detection main-thread blocking dropped from ~3.3s to ~0.35s per window, and the longest block went from ~1.1s to ~250ms.