Skip to content

[Other]: (perf) Every terminal spawn blocks the main process ~50ms resolving the Codex CLI path (sync PATH scan, twice) #35565

Closed

Description

@ctolkien

Details

Opening any local (non-WSL) terminal schedules a Codex hook reconcile. That happens whether or not the terminal runs Codex. The reconcile resolves the codex binary twice, and each resolution is a full synchronous statSync scan of PATH and the install dirs. On Windows with a long PATH, that blocks the Electron main process for ~50ms per terminal spawned. Restoring or opening N terminals costs N × 50ms.

It's worst for users who don't have Codex installed, because every scan misses and walks every directory. This is the same sync-scan pattern as #35562.

Evidence

I profiled the main process with V8 sampling during the ACK-backpressured scenarios in artificial-opencode-terminal-load.spec.ts. The build was an unminified e2e build on Windows, with 95 PATH dirs and Codex not installed.

  • There were 18–19 blocking bursts per profile window, each about 45–65ms. That's one burst per spawned pane, roughly once a second while panes were opening.
  • In total it was about 0.8s of main-thread time per window (about 3%).

Cause

  1. Every non-WSL PTY spawn schedules a reconcile:
    if (!opts.isWsl) {
    // Native panes may run Codex later by typing it; recheck hooks against any updated Codex install.
    scheduleCodexHookReconcile()
    }

    export function scheduleCodexHookReconcile(): void {
    // One run already reads after the spawn; coalesce calls from its multiple env builders.
    if (config && !running) {
    void reconcileCodexHooks()
    }
    }
  2. reconcileOnce resolves Codex twice: once through resolveCodexHookAnswer() and again through readKnownCodexHookAnswer():
    async function reconcileOnce(realHomeLaunch: boolean): Promise<void> {
    const current = config
    if (!current?.isEnabled() || !(realHomeLaunch || resolveHome(current).kind === 'real')) {
    return
    }
    const lookup = resolveCodexHookAnswer()
    const live = await withTimeout<CodexHookAnswer | null>(lookup, ANSWER_WAIT_MS, null)
    if (!live) {
    // Replace stopgap approvals once Codex's answer arrives.
    void lookup.then(() => reconcileCodexHooks({ realHomeLaunch }))
    }
    // Reuse Codex's saved answer so a slow startup probe does not disturb existing hooks.
    const answer = live && live.kind !== 'pending' ? live : readKnownCodexHookAnswer()
  3. Each of those calls resolveCodexCommand() synchronously:
    export async function resolveCodexHookAnswer(): Promise<CodexHookAnswer> {
    // Resolve the same hydrated PATH that panes use.
    await appPathReady
    return lookupCodexHookAnswer(resolveCodexCommand(), getManagedCommand(getManagedScriptPath()))
    }
    /** Read status from memory or disk without spawning Codex. */
    export function readKnownCodexHookAnswer(): CodexHookAnswer | null {
    const codexPath = resolveCodexCommand()
    const fingerprint = fingerprintCodex(codexPath)

    export function resolveGuestNativeAgentCommand(
    name: string,
    options: ResolveCommandOptions = {},
    mounts?: readonly string[]
    ): string {
    return (
    resolveGuestNativeProgram(name, options, resolveCliCommand, mounts) ??
    `${WINDOWS_ONLY_AGENT_CLI_DIR}/${name}`
    )
    }
    export function resolveCodexCommand(options: ResolveCommandOptions = {}): string {
    return resolveGuestNativeAgentCommand('codex', options)
    }
  4. resolveCodexCommand() ends up in resolveCliCommand, which runs statSync over every PATH dir × 4 names and then every install dir:
    export function resolveCliCommand(
    commandName: string,
    options: ResolveCommandOptions = {}
    ): string {
    const platform = options.platform ?? process.platform
    const executableNames = getExecutableNames(platform, commandName)
    const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null
    const pathCandidate = findFirstExecutable(platform, splitPath(pathEnv), executableNames)
    if (pathCandidate) {
    return pathCandidate
    }
    const homePath = options.homePath ?? homedir()
    const installCandidate = findFirstExecutable(
    platform,
    getCliInstallDirectories(platform, homePath),
    executableNames
    )
    return installCandidate ?? commandName

    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
    }
    }

Activity

  1. added a commit that references this issue on Oct 29, 2026
    2c53637
  2. ctolkien commented on Oct 29, 2026

    @ctolkien
    ContributorAuthor

    My 2c, is that making a user restart Orca to pickup new agents is a better option that constantly checking every time we open a terminal. That is a product decision however.

  3. added a commit that references this issue on Oct 29, 2026
    b95b11c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions