Skip to content

perf(codex): throttle spawn-time hook rechecks and resolve Codex once per run - #35622

Closed
ctolkien wants to merge 2 commits into
stablyai:mainfrom
ctolkien:perf/codex-spawn-lookup-35565
Closed

ctolkien wants to merge 2 commits into
stablyai:mainfrom
ctolkien:perf/codex-spawn-lookup-35565

Conversation

@ctolkien

Copy link
Copy Markdown
Contributor

ELI5

Every time you opened a terminal, Orca briefly froze its main process (~50ms) while it searched your whole PATH for the Codex CLI, twice, even if you don't use Codex. Opening or restoring many terminals stacked those freezes. Now a burst of terminals triggers one check (plus a catch-up check 10s later), and each check searches once.

What Changed

  • scheduleCodexHookReconcile() (called on every native PTY spawn) now runs at most once per 10s. A trailing run covers spawns inside the window, so every spawn is still rechecked within 10s. Explicit Codex launches (reconcileCodexHooksForLaunch), the startup run and reconcileCodexHooks() are unthrottled.
  • reconcileOnce resolves the Codex path once and passes it to resolveCodexHookAnswer(codexPath) and readKnownCodexHookAnswer(codexPath). Both still default to resolving it themselves for their other callers.

Why

Each resolution is a synchronous statSync scan of PATH plus install dirs. On Windows with a 95-dir PATH and no Codex installed, that's ~25ms per scan, ×2 per run, ×1 run per terminal. On default settings (agentStatusHooksEnabled: true, no agents disabled) every user pays it.

Memoizing the resolution or reusing agent detection's batched lookup (#34636) was considered and left out of this PR: the resolved path feeds the hook-trust fingerprint, and detection's PATH and extension order differ from the path panes actually run. Making resolveCodexCommand cheap for every caller is better done separately.

Linked Issue

Fixes #35565

Visual Proof

N/A: no UI change. Before/after main-process CPU profiles instead:

Scenario (~26s window) Codex lookup bursts Main-thread time in Codex lookup Main-thread idle
Background PTYs ACK-backpressured 18 → 3 1,103ms → 101ms 79.5% → 82.9%
Hidden real PTYs ACK-backpressured 18 → 3 1,095ms → 93ms 77.2% → 80.0%
Rich hidden model output 18 → 3 1,073ms → 101ms 80.4% → 82.0%

Before: f5c84eae583 (main). After: this branch. Method: V8 sampling profiler (200µs) inside the main process during the three ACK-backpressured scenarios of tests/e2e/artificial-opencode-terminal-load.spec.ts; unminified e2e build (ORCA_UNMINIFIED_MAIN=1), ORCA_BACKGROUND_LAUNCH=1, Windows 11, 95 PATH dirs, Codex not installed.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Profiled locally on Windows (above).

  • Added a test: a burst of pane spawns rechecks once, then once more after the throttle window. Existing spawn-coalescing and ride-along tests pass.

  • pnpm check:changed --base=upstream/main: all checks pass except 14 unit tests in 3 runtime files that fail with EPERM on C:\WINDOWS\TEMP cleanup; they fail identically on unmodified main (environment). codex-hook-reconcile.test.ts › keeps the approval main's grant recorded for Orca's entry also fails identically on unmodified main on this machine.

  • Not tested on macOS/Linux; the change is platform-neutral, with a smaller gain there (shorter PATH, faster stat).

AI Disclosure

Investigation, profiling and implementation done with Claude (Opus 5.5) in Claude Code, reviewed by me.

… per run

Every native pane spawn scheduled a Codex hook reconcile, and each run
resolved the codex binary twice with a synchronous PATH + install-dir
scan (~25ms each on a 95-dir Windows PATH, worst when Codex is not
installed). A session restore of 18 panes blocked main ~1.1s in 18 bursts.

Spawn-triggered rechecks now run at most once per 10s with a trailing
run, so a spawn inside the window is still rechecked. Explicit Codex
launches and the startup run are unchanged. Each run resolves the path
once and passes it to both lookups.

Fixes stablyai#35565
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This PR limits spawn-triggered Codex hook checks and reuses the resolved Codex path within each run.

  • Pane spawns now share Codex hook checks across ten-second bursts.
  • Each hook check now looks up Codex only once.

Reviews (2) · Last reviewed commit: "fix(codex): rerun a trailing spawn reche..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Reconciliation now resolves the Codex executable once and passes its path to both hook-answer lookups. Spawn-triggered reconciliations start immediately or schedule a trailing run within a 10-second interval. The test suite adds coverage for repeated pane spawns and the trailing run.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 9666a

Occasional long reconciliations can allow closely spaced Codex lookups and a brief performance stall. The impact is bounded, but the throttle should be corrected.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary changes: throttling spawn-time Codex hook rechecks and resolving Codex once per run.
Description check Passed The description is mostly complete. It explains the user impact, changes, rationale, linked issue, profiling evidence, testing, and AI usage. The Review, Agent skill upstream boundary, Notes, and Chec…
Linked Issues check Passed Issue #35565 requires reducing synchronous Codex PATH scans during terminal-spawn reconciliation. scheduleCodexHookReconcile() coalesces spawn requests and schedules a trailing run after the 10-seco…
Out of Scope Changes check Passed The changes are limited to Codex hook reconciliation, Codex path reuse, and focused reconciliation tests. These changes directly support issue #35565. No unrelated product behavior or files are shown …
Full details: Description check

Explanation

The description is mostly complete. It explains the user impact, changes, rationale, linked issue, profiling evidence, testing, and AI usage. The Review, Agent skill upstream boundary, Notes, and Checklist sections are not included, but the missing sections do not prevent understanding the change.

Full details: Linked Issues check

Explanation

Issue #35565 requires reducing synchronous Codex PATH scans during terminal-spawn reconciliation. scheduleCodexHookReconcile() coalesces spawn requests and schedules a trailing run after the 10-second interval. reconcileOnce() resolves the Codex path once and passes it to both hook-answer lookups. Tests cover burst coalescing and a trailing run, including a busy-reconcile case.

Full details: Out of Scope Changes check

Explanation

The changes are limited to Codex hook reconciliation, Codex path reuse, and focused reconciliation tests. These changes directly support issue #35565. No unrelated product behavior or files are shown in the reviewed changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59b0bc1a-cbf5-4168-bb53-895cd0ac7f52
Commits

Reviewing files that changed from the base of the PR and between 79ba74d and 2c53637.

Files selected for processing: 3
  • src/main/codex/codex-hook-hash-lookup.ts
  • src/main/codex/codex-hook-reconcile.test.ts
  • src/main/codex/codex-hook-reconcile.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/main/codex/codex-hook-reconcile.ts Resolved
…cile

A trailing spawn recheck that fired while another reconcile was running
returned early, and that run may have resolved Codex before the throttled
spawn. Request a rerun instead so the spawn is always rechecked.

Refs stablyai#35565

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a1e189d-1f69-49f7-b4ac-e905f5acb6c4
Commits

Reviewing files that changed from the base of the PR and between 2c53637 and 9666acb.

Files selected for processing: 2
  • src/main/codex/codex-hook-reconcile.test.ts
  • src/main/codex/codex-hook-reconcile.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread src/main/codex/codex-hook-reconcile.ts Resolved
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @ctolkien — this landed in #35967 with you as co-author. We kept resolving the Codex path once per reconcile, made the spawn recheck async on Windows only (macOS/Linux keep the fast sync scan, now halved), dropped the 10s throttle so hook rechecks stay immediate, and queue one trailing recheck for spawns that arrive while the async answer is in flight. Fixes #35565.

@nwparker nwparker closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants