Skip to content

fix(github): bound and coalesce the Orca star check so gh children cannot pile up - #18239

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-18234-star-check-spin
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-18234-star-check-spin

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​274 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​264
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​96 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63

Fixes #18234

ELI5

Orca asks GitHub "has this user starred the Orca repo?" by shelling out to gh. It asked that question with no time limit, no way to kill the helper if it wedged, and no memory that it had already asked. On the reporter's Linux box the gh helper never finished — it spun a CPU core at 100% — and Orca kept starting new ones without cleaning up the old ones. Four of them were still running after 1h48m each.

There is a second, quieter half the reporter did not see: every stuck helper also holds one of only four slots Orca has for talking to GitHub at all. Four stuck helpers means the user's entire GitHub integration — PR status, checks, issues, reviews — was silently dead for the rest of the session, not just burning CPU.

This PR does not fix whatever makes gh spin on that machine (see "What is still open"). It makes the spin survivable: the helper now gets a deadline and a kill, Orca only ever asks once at a time, and the UI stops re-asking every few seconds.

Root cause

Three separate defects stack up. Only the first is speculative-free-standing; all three are proven below.

1. The star check was the only gh call site with no deadline and no kill

src/main/github/client/fetch/orca-star.ts used execFileAsync, i.e. promisify(execFile) from src/main/github/gh-utils.ts:10, with no timeout option:

const { stdout, stderr } = await execFileAsync(
  'gh',
  ['api', '--include', `user/starred/${ORCA_REPO}`],
  { encoding: 'utf-8' }        // ← no timeout, no kill, no tree termination
)

Every other gh call in the app goes through ghExecFileAsync (src/main/git/command-runner/gh-exec-file.ts), which supplies a 30s deadline and, on expiry, killSpawnedCommandTree(child) — a real process-tree kill, which matters here because the chain is bash shim → mise x → gh and killing only the direct child orphans the rest. That is precisely the reparenting to systemd --user the reporter observed.

getAuthenticatedViewer (gh api user) had the identical defect. After this PR a repo-wide sweep finds zero files outside the command runner naming gh as a spawned program, and a ratchet test keeps it that way.

2. A hung child permanently exhausts the GitHub concurrency semaphore

acquire() / release() in src/main/github/gh-utils.ts:44 is a 4-wide semaphore over every GitHub operation in the app. checkOrcaStarred acquires before the spawn and releases in finally. With no deadline, a gh that never exits means finally never runs and the slot is leaked forever.

This is what explains the reporter finding exactly four stuck children and no more. It is not a coincidence — it is MAX_CONCURRENT = 4. It also means their PR/checks/issues polling had been queued behind a permanently full semaphore.

3. The ~12s respawn is a remount, not a poll

There is no timer anywhere that calls checkOrcaStarred. I checked every setInterval and self-rescheduling setTimeout in src/main and src/renderer/src; none reaches it. There are only four callers, all event-driven.

The repeat comes from a remount. Landing.tsx computed:

const showGitHubSupportFooter = repos.length === 0 || hasGitHubProject

and rendered <GitHubStarButton> — whose mount effect fires the gh call — only inside that conditional footer. repos is rewritten wholesale on every repos:changed push, and hasGitHubBackedProject needs a resolved providerIdentity.provider === 'github'. Any push whose intermediate state lacks that identity unmounts the footer; the next one remounts it and forks another gh, with zero caching on the main side.

Evidence

Mechanism demo. A gh that never exits (while :; do :; done), driven at the reporter's 12s cadence through both code shapes, with the real gh-utils semaphore:

=== BEFORE ===                              === AFTER ===
t= 0s  live gh children=0  sem=1/4          t= 0s  live gh children=0  sem=1/4
t= 5s  live gh children=1  sem=1/4          t= 5s  live gh children=1  sem=1/4
t=10s  live gh children=1  sem=1/4          t=10s  live gh children=1  sem=1/4
t=15s  live gh children=2  sem=2/4          t=15s  live gh children=1  sem=0/4
t=20s  live gh children=2  sem=2/4          t=20s  live gh children=0  sem=0/4
t=25s  live gh children=3  sem=3/4          t=25s  live gh children=1  sem=1/4
t=30s  live gh children=3  sem=3/4          t=30s  live gh children=1  sem=1/4
t=35s  live gh children=3  sem=3/4          t=35s  live gh children=1  sem=1/4
t=40s  live gh children=4  sem=4/4          t=40s  live gh children=0  sem=0/4
t=45s  live gh children=4  sem=4/4          t=45s  live gh children=0  sem=0/4
final: 4 live children, semaphore 4/4       final: 1 live child, semaphore 1/4
       — never recovers                            — drains every cycle

Ruling out two of the reporter's structural clues, so nobody else spends time on them:

  • stdin/stdout being sockets is normal, not a symptom. libuv implements stdio: 'pipe' with socketpair(AF_UNIX, SOCK_STREAM), not pipe(2). Every Node and Electron child on Linux shows sockets on fd 0/1/2. It confirms a Node spawn; it is not evidence of a defect. The child's end is left blocking, so a parent that stopped reading would show state S at 0% CPU — consistent with the reporter's own observation that this is R, and with their conclusion that the child is not blocked on I/O.
  • LD_LIBRARY_PATH pollution is real but is not the cause. I extracted the shipped AppRun from the real v1.4.195 AppImage. It exports APPDIR, PATH="$APPDIR:$APPDIR/usr/sbin:$PATH", LD_LIBRARY_PATH="$APPDIR/usr/lib", XDG_DATA_DIRS and GSETTINGS_SCHEMA_DIR into every child Orca spawns, and defends against exactly this for its own helpers (LD_LIBRARY_PATH="" zenity …). But $APPDIR/usr/lib holds only libappindicator.so.1, libgconf-2.so.4, libindicator.so.7, libnotify.so.4, libXss.so.1, libXtst.so.6 — no libc, libstdc++, libssl or libz to shadow. Driving the mise shim from Node's execFile on Ubuntu 24.04 with that exact directory on the loader path, 100 inherited descriptors and ulimit -n 524288, gh completed in 279–328ms on every attempt. Negative result, reported so the hypothesis can be retired.

Measurements

before after
Live gh children after 45s at the reporting cadence 4 0–1
Peak concurrent gh children 4 (unbounded by time) 1
Max lifetime of a wedged child unbounded (1h48m observed) 15s, then SIGKILL to the tree
GitHub semaphore after 4 hangs 4/4, permanent 0/4, drains every cycle
CPU burned by wedged children 4 cores, indefinitely ≤1 core, ≤15s per cycle
gh spawns per star check, 3 concurrent callers 3 1

Changes

  • orca-star.ts — route through ghExecFileAsync (15s deadline + tree kill); coalesce concurrent checkOrcaStarred calls onto one in-flight child, cleared on settle so the answer is never cached or stale.
  • authenticated-viewer.ts — same routing for gh api user.
  • landing-github-star-state.ts (new) + Landing.tsx — hoist the star-state effect above the conditionally rendered footer, so a repo-catalog rewrite no longer remounts it and re-forks gh. Landing itself only mounts on navigation, so the check runs once per visit.
  • Tests — bounded spawn, kill-on-timeout, in-flight dedupe, semaphore release on failure, stdio/windowsHide intent, plus a gh-spawn-boundary ratchet with an empty allowlist.

Negative user-facing trade-offs

One, and it is small. On a network where gh api takes longer than 15s the star check now reports null instead of eventually reporting the true answer. null is already a first-class outcome — it routes the prompt to the browser-star fallback, which is a working path, not a dead button. The previous behaviour was not "a correct answer later": the UI had long since resolved, so the late answer was discarded anyway while the child kept running. Everything else is unchanged: the same argv, the same 200/204 → starred, 404 → not starred, anything-else → null mapping, and the same prompt behaviour.

Nothing else regresses. ghExecFileAsync adds transient-5xx retry (2 attempts, 250ms/1s, bounded), the rate-limit breaker, and WSL/host fallback — all improvements. Windows .cmd argument encoding and windowsHide are untouched; execFileCapture already pins windowsHide: true and never uses shell. Nothing changes for SSH/remote: the star check is a local-host, main-process concern and is not exposed over runtime RPC.

What is still open (not fixed here, deliberately)

  1. Why gh spins on that machine. I could not reproduce it. I set up mise 2026.x + gh 2.98.0 + the same bash shim on Ubuntu 24.04 and drove it from Node's execFile with the AppImage environment, 100 inherited descriptors and the reporter's RLIMIT_NOFILE — 280–350ms every time. It needs the reporter's Arch/Omarchy toolchain. I have posted the exact strace -c -p, ls -l /proc/<pid>/fd and cat /proc/<pid>/stack commands on the issue; the reporter offered to run them.
  2. ~100 descriptors inherited from Electron. Real, and a genuine second defect, but not fixable at Orca's spawn layer: libuv relies on O_CLOEXEC rather than walking the fd table, and Chromium opens DawnWebGPUCache/DawnGraphiteCache entries without it. Needs an upstream fix or a closing exec shim.
  3. Updating does not terminate the previous instance. The reporter had 1.4.190 and 1.4.195 running side by side with both squashfs mounts active, which doubles every background cost. Worth its own issue.
  4. repos being rewritten wholesale on every repos:changed push. The hoist above makes the star check immune, but the remount storm itself is real churn for anything else mounted under a repos-derived condition. That is surgery on the publish path, so: follow-up, not this PR.

…nnot pile up

`checkOrcaStarred`, `starOrca` and `getAuthenticatedViewer` were the only gh
call sites that reached for the legacy `execFileAsync` instead of
`ghExecFileAsync`, so they ran with no deadline, no process-tree kill and no
coalescing. A `gh` that never exits therefore ran forever and never released
its slot in the 4-wide GitHub semaphore in gh-utils.

Route all three through `ghExecFileAsync`, coalesce concurrent star checks onto
one child, and hoist the Landing star-state effect out of the conditionally
rendered footer so a repo-catalog rewrite no longer remounts it and re-forks gh.

Adds a ratchet test asserting no file outside the command runner names `gh` as
a spawned program.

Fixes #18234
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change routes GitHub CLI requests through ghExecFileAsync with timeout handling. Orca star checks coalesce concurrent requests and release concurrency slots after failures or timeouts. New tests verify process termination, invocation boundaries, request coalescing, and star actions. Landing page star state now comes from useLandingOrcaStarState and is passed to GitHubStarButton.

Merge Risk: 🔵 Low · up to 8357e

The change bounds and coalesces GitHub star checks, but the check can still run for up to 15 seconds when the GitHub footer is not visible, temporarily using shared GitHub capacity without user benefit; the PR is otherwise mergeable with this bounded follow-up.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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. Analyzed 12 functions across 8 files. 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 primary change: bounding and coalescing the Orca GitHub star check to prevent accumulating gh child processes.
Description check ✅ Passed The description is detailed and covers the problem, root cause, changes, rationale, linked issue, testing evidence, trade-offs, and remaining scope. It does not include the template's explicit Visual …
Linked Issues check ✅ Passed The changes satisfy issue #18234 by adding a timeout and process-tree termination, releasing semaphore slots after failures, coalescing concurrent star checks, and preventing remount-triggered respawn…
Out of Scope Changes check ✅ Passed The production and test changes remain focused on the linked issue. The authenticated viewer update, Landing hook extraction, spawn-boundary test, and reset helper directly support preventing unbounde…
Full details: Description check

Explanation

The description is detailed and covers the problem, root cause, changes, rationale, linked issue, testing evidence, trade-offs, and remaining scope. It does not include the template's explicit Visual Proof section or checklist, but the required information is mostly present and the change is clearly documented.

Full details: Linked Issues check

Explanation

The changes satisfy issue #18234 by adding a timeout and process-tree termination, releasing semaphore slots after failures, coalescing concurrent star checks, and preventing remount-triggered respawns. The existing star-check behavior remains intact, and tests cover the required protections.

Full details: Out of Scope Changes check

Explanation

The production and test changes remain focused on the linked issue. The authenticated viewer update, Landing hook extraction, spawn-boundary test, and reset helper directly support preventing unbounded gh processes and related semaphore exhaustion.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: ce724aa9-7dc1-4faa-bfdb-296df21c2630

📥 Commits

Reviewing files that changed from the base of the PR and between 698584f and 8357ef2.

📒 Files selected for processing (8)
  • src/main/git/command-runner/gh-exec-file-deadline.test.ts
  • src/main/git/command-runner/gh-spawn-boundary.test.ts
  • src/main/github/client-starred.test.ts
  • src/main/github/client.ts
  • src/main/github/client/fetch/authenticated-viewer.ts
  • src/main/github/client/fetch/orca-star.ts
  • src/renderer/src/components/Landing.tsx
  • src/renderer/src/components/landing-github-star-state.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


// Why: the runtime-aware slice probes the active remote host instead of the renderer host.
const { preflightIssues } = useLandingPreflightRuntime()
const [starState, setStarState] = useLandingOrcaStarState()

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Do not start the star check when the GitHub footer is hidden.

Line 231 runs useLandingOrcaStarState() for every Landing mount. When showGitHubSupportFooter is false, the footer does not render, but the hook still starts gh. A stuck request can occupy a GitHub concurrency slot for 15 seconds without visible UI. Pass the footer condition into the hook and skip its effect when it is false.

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

✅ No new issues found.

Reviewed changes

  • orca-star.ts — checkOrcaStarred/starOrca now route through ghExecFileAsync (15s deadline + process-tree kill) instead of the unbounded execFileAsync, and checkOrcaStarred coalesces concurrent callers onto one in-flight child cleared on settle.
  • authenticated-viewer.ts — getAuthenticatedViewer switched to ghExecFileAsync (default 30s deadline).
  • Landing.tsx / landing-github-star-state.ts — hoisted the star-state effect out of the conditionally-rendered footer so repos rewrites no longer remount it and re-fork gh.
  • Tests — kill-on-timeout + stdio/windowsHide intent, in-flight dedupe, fresh-check-after-settle, semaphore-release-on-failure, and a gh-spawn-boundary ratchet with an empty allowlist.

I read the full diff end-to-end and traced the surrounding seams (gh-utils semaphore, exec-file-capture deadline/tree-kill, gh-idempotency, gh-retry-policy, the IPC handlers, and the test-mock wiring). I verified the ratchet's claim independently (no gh spawns outside command-runner/) and ran the three changed test files — all 13 tests pass. The coalescing is sound (release() runs before the outer .finally clears inFlightStarCheck, and the no-signal acquire() never rejects, so the slot is always released), and starOrca's -X PUT is correctly classified non-idempotent so the new retry path cannot double-star. The 404→false mapping is preserved in both old and new error shapes.

The one deliberate trade-off — the star check now fires once per Landing mount even when the footer is hidden — is small, bounded, and clearly documented, and matches the fix's goal of killing the remount storm.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 1910ab9 into main Sep 2, 2026
29 checks passed
nwparker added a commit that referenced this pull request Sep 2, 2026
…#18258)

`gh` and `glab` on PATH are routinely shims — mise, asdf, volta, or a
hand-written wrapper — so a timed-out invocation has a chain to stop, not
one process. `execFileCapture`'s POSIX kill path signals only the direct
child; the descendants are orphaned to init and keep running. #18234 is
exactly that shape: `bash ~/.local/bin/gh` -> `mise x gh` -> `gh`, where
the reporter found the tail reparented to `systemd --user` and still at
100% CPU nearly two hours later. The 15s deadline #18239 added bounds
Orca's semaphore slot and its promise; it does not bound the CPU burn.

Route both CLIs through `execFileCaptureToTermination`, the primitive
git's barrier path already uses: POSIX children spawn `detached`, the
deadline signals `-pgid` and escalates to SIGKILL, and the promise waits
for verified termination. Windows behaviour is unchanged (`taskkill /t`
either way).

Switching primitives also swapped execFile's hard maxBuffer failure for
`runProcess`'s silent clipping, which would have turned an oversized gh
response into a shorter valid-looking one. `ProcessResult` now reports
truncation and the capture rejects on it, restoring the old contract and
closing the same latent gap on git's barrier path.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…nnot pile up (stablyai#18239)

`checkOrcaStarred`, `starOrca` and `getAuthenticatedViewer` were the only gh
call sites that reached for the legacy `execFileAsync` instead of
`ghExecFileAsync`, so they ran with no deadline, no process-tree kill and no
coalescing. A `gh` that never exits therefore ran forever and never released
its slot in the 4-wide GitHub semaphore in gh-utils.

Route all three through `ghExecFileAsync`, coalesce concurrent star checks onto
one child, and hoist the Landing star-state effect out of the conditionally
rendered footer so a repo-catalog rewrite no longer remounts it and re-forks gh.

Adds a ratchet test asserting no file outside the command runner names `gh` as
a spawned program.

Fixes stablyai#18234
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#18258)

`gh` and `glab` on PATH are routinely shims — mise, asdf, volta, or a
hand-written wrapper — so a timed-out invocation has a chain to stop, not
one process. `execFileCapture`'s POSIX kill path signals only the direct
child; the descendants are orphaned to init and keep running. stablyai#18234 is
exactly that shape: `bash ~/.local/bin/gh` -> `mise x gh` -> `gh`, where
the reporter found the tail reparented to `systemd --user` and still at
100% CPU nearly two hours later. The 15s deadline stablyai#18239 added bounds
Orca's semaphore slot and its promise; it does not bound the CPU burn.

Route both CLIs through `execFileCaptureToTermination`, the primitive
git's barrier path already uses: POSIX children spawn `detached`, the
deadline signals `-pgid` and escalates to SIGKILL, and the promise waits
for verified termination. Windows behaviour is unchanged (`taskkill /t`
either way).

Switching primitives also swapped execFile's hard maxBuffer failure for
`runProcess`'s silent clipping, which would have turned an oversized gh
response into a shorter valid-looking one. `ProcessResult` now reports
truncation and the capture rejects on it, restoring the old contract and
closing the same latent gap on git's barrier path.
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.

[Bug]: gh api user/starred child processes spin at 100% CPU indefinitely and are respawned continuously

1 participant