Repository navigation
fix(gh): reap the whole gh/glab process tree at the deadline on POSIX - #18258
Conversation
`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.
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (13)
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.
Important
One regression in the outputTruncated path: the new overrun error no longer matches isMaxBufferOverflowError, so oversized PR files lose their tooLarge signal. See the inline comment.
Reviewed changes
- gh/glab route through
execFileCaptureToTermination— the two CLIs now reuse git'sterminationBarrierprimitive, spawningdetachedon POSIX so the deadline signals-pgid, escalates toSIGKILL, and waits for verified quiescence instead of orphaning a shim chain to init (#18234). outputTruncatedplumbed throughrunProcess—bounded-output-sinkexposestruncated(),ProcessResultgainsoutputTruncated?, andexecFileCaptureToTerminationrejects on it so gh/glab fail rather than returning a clipped JSON/JSONL answer.- Churn-probe coverage restored —
execFileCaptureToTerminationnow recordsrecordSubprocessSpawn, keeping gh coverage and adding the git barrier path. - Test re-mock to
spawn+ shared fixture — four gh/glab suites swapped theirexecFilestubs forspawn, backed by a new__fixtures__/fake-spawned-child.tsand new deadline/truncation assertions (detached,-pid, exact-cap clip).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| ? // Why fail instead of returning the clipped text: callers parse this | ||
| // as JSON or JSONL, where a clipped answer reads as a shorter valid | ||
| // one. execFile's own maxBuffer overrun errored for the same reason. | ||
| `${command} produced more than ${options.maxBuffer ?? DEFAULT_GIT_MAX_BUFFER} bytes of output.` |
There was a problem hiding this comment.
This error drops the ENOBUFS/maxBuffer signal that getPRFileContents keys on. pull-request-file-contents.ts catches gh overruns with isMaxBufferOverflowError, which matches code === 'ENOBUFS' or a /maxBuffer/i message; here code becomes result.code (0 for a clip) and the message says produced more than N bytes, so an oversized PR file now falls through to { isBinary: false } with no tooLarge — rendering >8 MiB files as empty content instead of "too large".
Technical details
# Preserve the maxBuffer-overflow classification on the truncation error
## Affected sites
- src/main/git/command-runner/exec-file-capture.ts:62-73 — the `outputTruncated` branch builds a plain `Error` and `Object.assign`s `code: result.code` (0), losing the maxBuffer shape
- src/main/git/max-buffer-overflow.ts:7-11 — `isMaxBufferOverflowError` only matches `code === 'ENOBUFS'` or `/\bmaxBuffer\b/i`
- src/main/github/pull-request-file-contents.ts:53-56 — calls `ghExecFileAsync(..., { maxBuffer: 8 MiB })` and relies on `isMaxBufferOverflowError` to return `{ tooLarge: true }`; `githubHostExecOptions` raw-content fetch
- src/renderer `pr-file-diff-mapping.ts` / `pr-file-content-size.ts` — consume `originalTooLarge`/`modifiedTooLarge` to cap rendering and show the overflow message
## Required outcome
- A gh/glab output-overrun must remain classifiable as "too large" by existing `isMaxBufferOverflowError` consumers (or those consumers updated), so the PR-file-diff view continues to flag oversized files instead of showing empty content.
## Suggested approach
- Tag the truncation error with `code: 'ENOBUFS'` (or a message containing `maxBuffer`) instead of `code: result.code`, OR add an `outputTruncated`/`tooLarge` check to `pull-request-file-contents.ts`. Prefer the first: it keeps every `isMaxBufferOverflowError` call site working with no consumer edits.
…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.

Follow-up to #18239 for #18234.
The gap
ghandglabon 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 tree kill is Windows-only:On POSIX the child is not
detached, so there is no group to signal even if we wanted to. Everything below the direct child is orphaned to init and keeps running.#18234 is exactly that shape. The reporter's chain is
/bin/bash ~/.local/bin/gh→mise x gh -- gh→gh, and they found the tail reparented tosystemd --user, still in stateRat ~99% CPU, 1h48m after its spawner was gone. The 15s deadline #18239 added bounds Orca's semaphore slot and its promise. It does not bound the CPU burn: we SIGTERM the wrapper and the rest of the chain outlives us.I said "process-tree kill" in the #18234 thread. That was true on Windows and wrong on Linux and macOS.
The fix
Route both CLIs through
execFileCaptureToTermination— the primitive git'sterminationBarrierpath already uses. On POSIX that spawnsdetached, so the child leads its own process group; the deadline then signals-pgid, escalates toSIGKILL, and waits for verified quiescence before settling. Windows behaviour is unchanged:taskkill /pid <pid> /t /feither way.One thing the switch would have broken, and does not
execFileCaptureused execFile'smaxBuffer, which errors on overrun.runProcessclips silently. Forgh api --paginatethat difference is not cosmetic — a clipped JSONL response parses as a shorter valid answer, so an oversized list would have quietly lost entries instead of failing.ProcessResultnow carriesoutputTruncated, andexecFileCaptureToTerminationrejects on it. That restores gh's previous contract and closes the same latent gap on git's barrier path.Also
execFileCaptureToTerminationnow recordsrecordSubprocessSpawn, which it never did — so the churn probe keeps its gh coverage, and gains the git barrier path it was missing.__fixtures__/fake-spawned-child.ts: the four suites that drove gh/glab by mockingexecFilenow mockspawn, and they were each rolling their own child stub.What this does not fix
Why
mise x ghspins on that machine at all. That is upstream and still under investigation on the issue — this PR only makes sure that when it happens, the thing we started dies when we say so instead of running until reboot.Git's own non-barrier
execFileCapturepath keeps the POSIX orphan gap.gitis far less often a shim, and changing it touches every git call in the app; left deliberately out of scope.Verification
pnpm tcclean.pnpm test src/main/git src/main/github src/main/gitlab src/shared/child-process src/main/star-nag src/main/source-control src/relay— 4201 passed, 33 skipped.pnpm run check:code-quality:changed— 0 new findings across 12 files.-pid(and asserts the child was spawneddetached, since without that the signal would go to Orca's own group); gh rejects rather than returning a clipped answer on overrun;runProcessreports truncation, and does not report it for output that exactly fills the cap.