Skip to content

Detect installed GitHub CLI behind hung launchers - #25183

Merged
OrcaWin merged 5 commits into
mainfrom
fix/omarchy-gh-launcher-detection
Oct 8, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
fix/omarchy-gh-launcher-detection

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​226 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​192
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​87

ELI5

Orca should recognize an installed GitHub CLI even when the first gh launcher it finds gets stuck. A fresh Omarchy install currently reports “CLI not installed” in that situation.

What Changed

Local CLI detection keeps its original five-second allowance for healthy copies. After a timeout, one additional five-second recovery budget is shared across the remaining executable copies, with the existing four-copy limit. The shared process runner stops a timed-out launcher's children before detection continues. Authentication and subsequent GitHub/GitLab commands keep using the copy that passed the version check. On Windows, process cleanup now resolves taskkill.exe through the existing absolute System32 resolver; a sparse or shadowed PATH can no longer prevent child cleanup.

On Linux and macOS, preflight now waits for the existing shell PATH resolver before checking tools. Re-check refreshes that PATH, so an early check or a newly installed CLI cannot leave a stale missing-CLI result. WSL continues to check tools inside its own distro.

Why

Reproduced with AUR stably-orca-bin 1.4.220 on Omarchy. ~/.local/bin/gh runs mise x gh -- gh; in Orca's environment, the inner gh resolves back to that launcher and loops. The actual mise shim and installed binary both run successfully, but detection previously stopped at the first timeout. There is also a startup race between the asynchronous shell PATH probe and the cached preflight result.

Extending the existing executable search covers mise and other launchers without hardcoding install directories or overriding the user's PATH order. A single recovery budget avoids paying another five seconds for every failed copy. Healthy and explicitly selected binaries retain their original five-second allowance. A regression test protects slow but healthy first copies. The absolute System32 lookup also keeps Windows child cleanup working when PATH is limited to tool directories. Only actual hangs can add the recovery budget and bounded process cleanup time.

Linked Issue

None — maintainer fix for a reproduced installation problem.

Visual Proof

Before/after backend evidence with the same hanging gh fixture placed ahead of the real Omarchy mise shim:

Before: timeout; subsequent commands still resolve bare gh
After:  available; selected ~/.local/share/mise/shims/gh

The installed app separately returned gh: { installed: false, authenticated: false } before a local launcher repair and gh: { installed: true, authenticated: true } afterward. That local workaround is outside this diff.

Rendered screenshots were not collected because the $electron skill required by AGENTS.md is unavailable in this session. There are no renderer code changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Linux: focused preflight and process-termination tests passed, including real hung launchers, candidate limits, healthy-first-copy timeout preservation, explicit paths, shell PATH ordering, forced refresh, and runtime preflight. The latest production detection selected and pinned the actual Omarchy mise shim behind a hanging fixture: baseline timed out after 5.0 seconds; this revision recovered after 7.1 seconds including process cleanup. The installed app separately confirms installed: true and authenticated: true after the local wrapper repair.

A broader preflight and shared-child-process run passed 316 tests and skipped 53. It also found one pre-existing failure in bounded-output-sink.test.ts: the backing allocation is 65,599 bytes against a 65,536-byte assertion. The isolated test fails too, and replaying the base revision's identical test dependencies reproduces it. Those files are unchanged in this PR.

pnpm tc:node and pnpm run check:code-quality:changed passed. Native platform CI is green on final commit 42fb4cbabc:

  • Ubuntu 22.04: 179 passed, 3 platform-specific cases skipped.
  • macOS 15: 179 passed, 3 platform-specific cases skipped.
  • Windows Server 2022: 148 passed, 34 platform-specific cases skipped. The real batch-launcher timeout recovery and Node-child termination test passed.

The workflow keeps these native CLI and shell-PATH checks running for future changes. WSL routing remains covered by existing mocks; no live WSL or SSH host was tested. Rendered UI was not exercised. Full builds and remaining suites are left to CI; the main static-analysis job is still queued.

Review

The Omarchy wrapper generator still needs its own upstream correction to remove recursion for every application. This PR fixes Orca's PATH race and its failure to recover a usable installed CLI; the local launcher repair removes the recursion on the reported machine.

The RPC shape and status meanings are unchanged. SSH runtimes apply the fix on their execution host; client-side remote agent detection is unchanged. No repository/worktree assumption is added, and GitLab uses the same launcher recovery.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No credentials or machine-specific install paths are added to Orca. Only version probes are retried; authentication and other operations are not replayed against alternate copies.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47c98d38-d0ea-423f-a520-8e9606f11e44
📥 Commits

Reviewing files that changed from the base of the PR and between 07cf3c2 and 42fb4cb.

📒 Files selected for processing (6)
  • .github/workflows/preflight-cli-platforms.yml
  • src/main/ipc/preflight-command-exec.test.ts
  • src/main/ipc/preflight-command-exec.ts
  • src/main/ipc/preflight-runnable-local-cli.test.ts
  • src/shared/child-process/process-tree-termination.test.ts
  • src/shared/child-process/process-tree-termination.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.


📝 Walkthrough

Walkthrough

Preflight detection now hydrates shell PATH on non-Windows platforms, with an option to force refresh. Local command probes divide the remaining timeout across candidates and continue after individual timeouts. If no candidate succeeds, the result reports a timed-out binary. Windows process-tree termination resolves taskkill.exe through the System32 path. Tests and a new workflow cover PATH hydration, candidate recovery, timeout reporting, and process termination across operating systems.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 42fb4

Recovery behind a hung launcher is improved, but with several candidates and another timeout, detection can report the wrong launcher. This is a bounded issue to address or accept before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 42fb4

The changes remain within existing local tool-execution permissions and improve cleanup. However, recovery can proceed when cleanup could not confirm that the previous launcher's children stopped, potentially overlapping executable activity.

Retained concerns

  • Low · reliability · observed: Timeout recovery can start another executable after the termination barrier settles without verified descendant cleanup. The runner's escape deadline is preexisting, but the new recovery loop treats this outcome like an ordinary timeout and has no cleanup-failure state that prevents the handoff. Residual descendants are conditional, not demonstrated; this is a bounded failure-containment concern rather than a verified privilege escalation.
Security review details

Security Blast Radius

  • inferred — The evidenced authority path is local executable discovery followed by provider authentication and commands under the caller's existing environment. Exploiting executable substitution would require control of a searched executable, PATH, or shell configuration; such attacker control and cross-tenant reachability were not established.

Trust Boundaries and Controls

  • observed — Multi-candidate POSIX probes are placed in detached process groups for tree termination. Native execution uses argument arrays with shell execution disabled, and Windows tree cleanup retains exited-PID and kill-admission checks.

Resilience and Maintainability Implications

  • observed — The barrier attempts tree termination and defers settlement while cleanup is pending. If verification fails, its existing last-resort deadline eventually settles without proving descendant exit. Recovery inherits this limitation rather than receiving an explicit cleanup-verification outcome.

Hardening Proposals

  • proposed — Expose cleanup verification separately from timeout status and stop candidate handoff when termination remains unverified, while still allowing preflight to return a bounded timeout result.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 8 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: detecting an installed GitHub CLI when an earlier launcher hangs.
Description check ✅ Passed The description covers the change, motivation, implementation, testing, platform impact, and review notes. It identifies the linked-issue exception as a maintainer fix and explains why rendered screen…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 8 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72e5be21-af84-43ab-a69f-4fbc282dff97
📥 Commits

Reviewing files that changed from the base of the PR and between 2b3b692 and 07cf3c2.

📒 Files selected for processing (6)
  • src/main/ipc/agent-detection-shell-path.ts
  • src/main/ipc/preflight-command-exec.test.ts
  • src/main/ipc/preflight-command-exec.ts
  • src/main/ipc/preflight-host-cli-status.test.ts
  • src/main/ipc/preflight-runnable-local-cli.test.ts
  • src/main/preflight/agent-detection.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.

}
)

it('refreshes the POSIX shell PATH on Re-check after a CLI install', async () => {

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
ast-grep outline src/main/ipc/preflight-host-cli-status.test.ts --items all --match 'beforeEach|afterEach'
rg -n -C 5 'beforeEach|afterEach|restoreAllMocks|stubGlobal|Object\.defineProperty\(process|spyOn\(process, .platform.' src/main/ipc/preflight-host-cli-status.test.ts

Repository: stablyai/orca

Length of output: 4595


🏁 Script executed:

printf '%s\n' '--- test source ---'
sed -n '690,755p' src/main/ipc/preflight-host-cli-status.test.ts | cat -n
printf '%s\n' '--- relevant base-to-head diff ---'
git diff --unified=5 2b3b692d29102b87389042a5614d80b93956d5e0 07cf3c24848eff6073db5d53e0a05058ac7ecc13 -- src/main/ipc/preflight-host-cli-status.test.ts | sed -n '/waits for the %s shell PATH/,/awaits the persisted Windows Path refresh/p'

Repository: stablyai/orca

Length of output: 6238


🏁 Script executed:

printf '%s\n' '--- test harness and imports ---'
sed -n '1,160p' src/main/ipc/preflight-host-cli-status.test.ts | cat -n
printf '%s\n' '--- runPreflightCheck definitions and platform branches ---'
rg -n -C 5 'runPreflightCheck|process\.platform|hydrateShellPath|mergePersistedWindowsPath' src/main/ipc

Repository: stablyai/orca

Length of output: 45659


🏁 Script executed:

printf '%s\n' '--- agent-detection outline ---'
ast-grep outline src/main/preflight/agent-detection.ts
printf '%s\n' '--- platform-dependent preflight implementation ---'
rg -n -C 8 'export (async )?function runPreflightCheck|runPreflightCheck|process\.platform|hydrateShellPath|mergePathSegments|buildLocalPreflightEnv|refreshShellPathAndDetectAgents' src/main/preflight/agent-detection.ts src/main/ipc/preflight-local-env.ts

Repository: stablyai/orca

Length of output: 14475


Set a POSIX platform in both tests.

On Windows, the refresh test skips shell hydration. Its merge mock therefore does not change execFileAsyncMock from rejection to success, and the forced check can still report gh as not installed. The hydration-failure test can pass without exercising the hydration-failure path.

🐛 Suggested fix
   it('refreshes the POSIX shell PATH on Re-check after a CLI install', async () => {
+    Object.defineProperty(process, 'platform', { configurable: true, value: 'linux' })
     execFileAsyncMock.mockRejectedValue(
@@
   it('uses the inherited PATH when POSIX shell hydration fails', async () => {
+    Object.defineProperty(process, 'platform', { configurable: true, value: 'linux' })
     hydrateShellPathMock.mockResolvedValue({ ok: false, segments: [], failureReason: 'timeout' })

@OrcaWin
OrcaWin marked this pull request as draft October 4, 2026 08:52

@pullfrog pullfrog 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.

Important

The budget that is supposed to "leave time for a working copy behind a launcher that never returns" is measured against the wall clock, but a timed-out candidate's terminationBarrier charges a mandatory ~2s POSIX teardown before runProcess resolves — so the working copy's slice can shrink to a few hundred milliseconds, which can reproduce the "not installed" result this PR fixes. Details inline.

Reviewed changes

  • Recover after a timed-out candidate — probeRunnableLocalCommand now continues past a timed-out copy instead of returning at the first one, and shares the 5s PREFLIGHT_COMMAND_TIMEOUT_MS budget across candidates (preflight-command-exec.ts).
  • Stop the hung launcher's tree — multi-candidate probes pass terminationBarrier: true through execLocalPreflightCommandOrThrow into runProcess, so a timed-out launcher's descendants are terminated before probing continues.
  • Hydrate shell PATH before POSIX preflight — executePreflightCheck awaits hydrateShellPathForAgentDetection(context, force) on non-win32, and force re-probes the login shell (agent-detection-shell-path.ts, agent-detection.ts), closing the startup race between the async PATH probe and the cached missing-CLI result.
  • Tests — unit coverage for recovery/timeout accounting/explicit paths plus a real-process integration case whose hung launcher traps TERM and proves its descendant was killed.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/ipc/preflight-command-exec.ts Outdated
return { status: 'timeout', binary }
}
// Leave time for a working copy behind a launcher that never returns.
const timeoutMs = Math.max(1, Math.floor(remainingMs / (probes.length - index)))

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.

The shared budget is wall-clock (deadline = Date.now() + PREFLIGHT_COMMAND_TIMEOUT_MS), but a timed-out candidate's terminationBarrier adds a mandatory ~2s POSIX grace before runProcess resolves. That teardown is charged against remainingMs, so the working copy behind a hung launcher gets far less than its nominal share — with 4 candidates it lands at ~583ms, which many version-manager shims exceed on a cold cache, reintroducing the installed: false result this PR targets.

Technical details
# Termination-barrier teardown consumes the probe budget

## Affected sites
- `src/main/ipc/preflight-command-exec.ts:183` — `remainingMs` is wall-clock, so the ~2s barrier grace spent on each timed-out candidate shrinks every later candidate's slice.
- `src/main/ipc/preflight-command-exec.ts:179` — once the deadline is exhausted mid-loop, the early return reports `binary` (the current, never-probed candidate) rather than `timedOutBinary`; in practice only reachable because of the overrun above.
- `src/shared/child-process/run-process.ts:205-269` — on POSIX the barrier only settles inside the `PROCESS_EXIT_GRACE_MS` (2000ms) timer, so every timed-out barrier probe costs `timeoutMs + ~2s` even when SIGTERM killed the tree immediately.

## Required outcome
- A working copy behind a hung launcher should keep a meaningful slice of the 5s budget, not the residual after teardown overhead.
- When the deadline is exhausted, the reported `binary` should be the candidate that actually timed out.

## Suggested approach (optional)
- Track elapsed *child* time rather than pure wall clock (e.g. add `PROCESS_EXIT_GRACE_MS` back to the deadline per timed-out candidate), or reserve the barrier grace when sizing the initial share.
- Return `{ status: 'timeout', binary: timedOutBinary ?? binary }` (or classify as `exec_failed` when no candidate timed out) at the `remainingMs <= 0` branch.

## Open questions for the human (optional)
- In the Omarchy reproduction, how many candidates were ahead of the working mise shim, and what did the winning copy's share work out to?

@OrcaWin
OrcaWin marked this pull request as ready for review October 4, 2026 09:29

@pullfrog pullfrog 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.

Important

The recovery budget's per-candidate division still does not account for the termination barrier's fixed ~2s POSIX teardown. A working copy behind two timed-out launchers gets a sub-second slice, and behind three it is never probed — which can reproduce the installed: false result this PR fixes. Details inline.

Reviewed changes

  • Recover past a timed-out launcher — probeRunnableLocalCommand now continues to the next executable copy instead of returning at the first; the first candidate keeps the full 5s and a second 5s recovery budget is shared across the rest (preflight-command-exec.ts).
  • Stop the hung launcher's tree before continuing — multi-candidate probes pass terminationBarrier: true into runProcess, and execLocalPreflightCommandOrThrow awaits the runner directly when set and treats outputTruncated as failure.
  • Hydrate the shell PATH before POSIX preflight — executePreflightCheck awaits hydrateShellPathForAgentDetection(context, force) on non-win32 and force re-probes the login shell (agent-detection.ts, agent-detection-shell-path.ts), closing the startup race behind a cached missing-CLI result.
  • Absolute Windows taskkill — forceTerminateProcessTree resolves taskkill.exe through windowsSystem32Binary, so a pruned or shadowed PATH can no longer block tree cleanup (process-tree-termination.ts).
  • Tests and native-platform CI — new unit and real-process coverage for recovery, timeout accounting, explicit paths, and tree termination, plus a new preflight-cli-platforms workflow running the CLI/PATH suites on Ubuntu, macOS, and Windows.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +184 to +186
const timeoutMs = recoveryDeadline
? Math.max(1, Math.floor(remainingMs / (probes.length - index)))
: remainingMs

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.

The recovery budget is divided evenly by remaining candidate count, but each timed-out candidate also pays the termination barrier's fixed ~2s POSIX grace (run-process.ts only settles a POSIX barrier inside the PROCESS_EXIT_GRACE_MS timer). That overhead is charged against remainingMs, so the division fronts more time per candidate than the budget can pay: with the fourth of four candidates healthy and the first three hung, the loop exhausts recoveryDeadline and returns before probing it, and with two hung ahead the working copy gets ~0.7s. Commit db62b17 fixed the healthy-first-copy case (it now keeps the full 5s), but this recovery-phase interaction is unchanged.

Technical details
# Termination-barrier grace is not reserved in the recovery budget

## Affected sites
- `src/main/ipc/preflight-command-exec.ts:184-186` — `Math.floor(remainingMs / (probes.length - index))` sizes each share as if a failed probe consumed only `timeoutMs`, ignoring the ~2s grace every timed-out barrier probe also spends.
- `src/main/ipc/preflight-command-exec.ts:180-182` — when the overrun exhausts `recoveryDeadline`, the early return reports the current, never-probed `binary` (not `timedOutBinary`) and can classify ordinary-failure exhaustion as `timeout`.
- `src/shared/child-process/run-process.ts:205-269` — on POSIX the barrier resolves only inside the `PROCESS_EXIT_GRACE_MS` (2000ms) timer, so a timed-out barrier probe costs `timeoutMs + ~2s` even when SIGTERM killed the tree immediately.

## Required outcome
- A working copy behind one or more timed-out launchers should still be probed with a meaningful slice (the reported Omarchy case has a single hung launcher, which the current code handles).
- Exhaustion should report the candidate that actually timed out.

## Suggested approach (optional)
- Reserve the barrier grace when dividing (e.g. `remainingMs - PROCESS_EXIT_GRACE_MS * remaining`), or measure recovery against child time rather than wall clock.
- Return `{ status: 'timeout', binary: timedOutBinary ?? binary }` at the `remainingMs <= 0` branch.

## Open questions for the human (optional)
- Is a multi-hung-launcher PATH (two or more wrappers before the working shim) in scope, or is the single-hung case the acceptance bar?

@OrcaWin
OrcaWin force-pushed the fix/omarchy-gh-launcher-detection branch from 42fb4cb to d2c827f Compare October 8, 2026 22:03
@OrcaWin
OrcaWin merged commit 4d1a3dd into main Oct 8, 2026
64 of 66 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
…cs (#30897)

The daily full E2E run on main fails these specs every time because the
product moved on and PR CI only runs specs a PR touches:
- editor header menu renamed to File actions (#30129)
- terminal attention: an on-screen bell leaves no unread marker (#28637)
- terminal file drops carry their source host (#26830)
- single-choice questions auto-submit (#26288)
- phone terminal rows carry customTitle (#30037)
- gh/git preflight re-reads the login shell PATH (#25183)
- board drag starts after the target column is in view
- chat history anchor read after scroll settles
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.

1 participant