Repository navigation
fix(github): bound and coalesce the Orca star check so gh children cannot pile up - #18239
Conversation
…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
📝 WalkthroughWalkthroughThe change routes GitHub CLI requests through Merge Risk: 🔵 Low · up to 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)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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 checkExplanation The changes satisfy issue Full details: Out of Scope Changes checkExplanation 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.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: ce724aa9-7dc1-4faa-bfdb-296df21c2630
📒 Files selected for processing (8)
src/main/git/command-runner/gh-exec-file-deadline.test.tssrc/main/git/command-runner/gh-spawn-boundary.test.tssrc/main/github/client-starred.test.tssrc/main/github/client.tssrc/main/github/client/fetch/authenticated-viewer.tssrc/main/github/client/fetch/orca-star.tssrc/renderer/src/components/Landing.tsxsrc/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() |
There was a problem hiding this comment.
🚀 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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
orca-star.ts—checkOrcaStarred/starOrcanow route throughghExecFileAsync(15s deadline + process-tree kill) instead of the unboundedexecFileAsync, andcheckOrcaStarredcoalesces concurrent callers onto one in-flight child cleared on settle.authenticated-viewer.ts—getAuthenticatedViewerswitched toghExecFileAsync(default 30s deadline).Landing.tsx/landing-github-star-state.ts— hoisted the star-state effect out of the conditionally-rendered footer soreposrewrites no longer remount it and re-forkgh.- Tests — kill-on-timeout + stdio/windowsHide intent, in-flight dedupe, fresh-check-after-settle, semaphore-release-on-failure, and a
gh-spawn-boundaryratchet 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…#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.
…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
…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.

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 theghhelper 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
ghspin 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.tsusedexecFileAsync, i.e.promisify(execFile)fromsrc/main/github/gh-utils.ts:10, with notimeoutoption: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 isbash shim → mise x → ghand killing only the direct child orphans the rest. That is precisely the reparenting tosystemd --userthe reporter observed.getAuthenticatedViewer(gh api user) had the identical defect. After this PR a repo-wide sweep finds zero files outside the command runner namingghas a spawned program, and a ratchet test keeps it that way.2. A hung child permanently exhausts the GitHub concurrency semaphore
acquire()/release()insrc/main/github/gh-utils.ts:44is a 4-wide semaphore over every GitHub operation in the app.checkOrcaStarredacquires before the spawn and releases infinally. With no deadline, aghthat never exits meansfinallynever 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 everysetIntervaland self-reschedulingsetTimeoutinsrc/mainandsrc/renderer/src; none reaches it. There are only four callers, all event-driven.The repeat comes from a remount.
Landing.tsxcomputed:and rendered
<GitHubStarButton>— whose mount effect fires the gh call — only inside that conditional footer.reposis rewritten wholesale on everyrepos:changedpush, andhasGitHubBackedProjectneeds a resolvedproviderIdentity.provider === 'github'. Any push whose intermediate state lacks that identity unmounts the footer; the next one remounts it and forks anothergh, with zero caching on the main side.Evidence
Mechanism demo. A
ghthat never exits (while :; do :; done), driven at the reporter's 12s cadence through both code shapes, with the realgh-utilssemaphore:Ruling out two of the reporter's structural clues, so nobody else spends time on them:
stdio: 'pipe'withsocketpair(AF_UNIX, SOCK_STREAM), notpipe(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 stateSat 0% CPU — consistent with the reporter's own observation that this isR, and with their conclusion that the child is not blocked on I/O.LD_LIBRARY_PATHpollution is real but is not the cause. I extracted the shippedAppRunfrom the real v1.4.195 AppImage. It exportsAPPDIR,PATH="$APPDIR:$APPDIR/usr/sbin:$PATH",LD_LIBRARY_PATH="$APPDIR/usr/lib",XDG_DATA_DIRSandGSETTINGS_SCHEMA_DIRinto every child Orca spawns, and defends against exactly this for its own helpers (LD_LIBRARY_PATH="" zenity …). But$APPDIR/usr/libholds onlylibappindicator.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'sexecFileon Ubuntu 24.04 with that exact directory on the loader path, 100 inherited descriptors andulimit -n 524288,ghcompleted in 279–328ms on every attempt. Negative result, reported so the hypothesis can be retired.Measurements
ghchildren after 45s at the reporting cadenceghchildrenSIGKILLto the treeChanges
orca-star.ts— route throughghExecFileAsync(15s deadline + tree kill); coalesce concurrentcheckOrcaStarredcalls onto one in-flight child, cleared on settle so the answer is never cached or stale.authenticated-viewer.ts— same routing forgh 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.windowsHideintent, plus agh-spawn-boundaryratchet with an empty allowlist.Negative user-facing trade-offs
One, and it is small. On a network where
gh apitakes longer than 15s the star check now reportsnullinstead of eventually reporting the true answer.nullis 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.
ghExecFileAsyncadds transient-5xx retry (2 attempts, 250ms/1s, bounded), the rate-limit breaker, and WSL/host fallback — all improvements. Windows.cmdargument encoding andwindowsHideare untouched;execFileCapturealready pinswindowsHide: trueand never usesshell. 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)
ghspins 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'sexecFilewith the AppImage environment, 100 inherited descriptors and the reporter'sRLIMIT_NOFILE— 280–350ms every time. It needs the reporter's Arch/Omarchy toolchain. I have posted the exactstrace -c -p,ls -l /proc/<pid>/fdandcat /proc/<pid>/stackcommands on the issue; the reporter offered to run them.O_CLOEXECrather than walking the fd table, and Chromium opensDawnWebGPUCache/DawnGraphiteCacheentries without it. Needs an upstream fix or a closing exec shim.reposbeing rewritten wholesale on everyrepos:changedpush. The hoist above makes the star check immune, but the remount storm itself is real churn for anything else mounted under arepos-derived condition. That is surgery on the publish path, so: follow-up, not this PR.