Skip to content

fix(gh): reap the whole gh/glab process tree at the deadline on POSIX - #18258

Merged
nwparker merged 1 commit into
mainfrom
nwparker/mise-gh-followup
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/mise-gh-followup

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​436 $\color{#cf222e}{\Huge{\mathbf{−}}}$​446 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​50

Follow-up to #18239 for #18234.

The gap

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 tree kill is Windows-only:

export function killSpawnedCommandTree(child: ChildProcess): Promise<void> {
  const pid = child.pid
  if (!pid || process.platform !== 'win32') {
    child.kill()          // <- SIGTERM to the direct child, and nothing else
    return Promise.resolve()
  }
  return /* taskkill /pid <pid> /t /f */
}

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 to systemd --user, still in state R at ~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's terminationBarrier path already uses. On POSIX that spawns detached, so the child leads its own process group; the deadline then signals -pgid, escalates to SIGKILL, and waits for verified quiescence before settling. Windows behaviour is unchanged: taskkill /pid <pid> /t /f either way.

One thing the switch would have broken, and does not

execFileCapture used execFile's maxBuffer, which errors on overrun. runProcess clips silently. For gh api --paginate that 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.

ProcessResult now carries outputTruncated, and execFileCaptureToTermination rejects on it. That restores gh's previous contract and closes the same latent gap on git's barrier path.

Also

  • execFileCaptureToTermination now records recordSubprocessSpawn, which it never did — so the churn probe keeps its gh coverage, and gains the git barrier path it was missing.
  • New __fixtures__/fake-spawned-child.ts: the four suites that drove gh/glab by mocking execFile now mock spawn, and they were each rolling their own child stub.

What this does not fix

Why mise x gh spins 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 execFileCapture path keeps the POSIX orphan gap. git is far less often a shim, and changing it touches every git call in the app; left deliberately out of scope.

Verification

  • pnpm tc clean.
  • 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.
  • New coverage: gh's deadline signals -pid (and asserts the child was spawned detached, since without that the signal would go to Orca's own group); gh rejects rather than returning a clipped answer on overrun; runProcess reports truncation, and does not report it for output that exactly fills the cap.

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

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 4f9d4710-780c-4d64-ba3a-c751738396b3

📥 Commits

Reviewing files that changed from the base of the PR and between 4376154 and 06fda78.

📒 Files selected for processing (13)
  • src/main/git/command-runner/exec-file-capture.ts
  • src/main/git/command-runner/gh-exec-file-deadline.test.ts
  • src/main/git/command-runner/gh-exec-file.ts
  • src/main/git/command-runner/glab-exec-file.ts
  • src/main/git/runner-command-exec.test.ts
  • src/main/git/runner-gh-rate-limit-breaker.test.ts
  • src/main/git/runner-wsl-gh-fallback.test.ts
  • src/main/gitlab/gitlab-known-host-probe-wsl-fallback.test.ts
  • src/shared/child-process/__fixtures__/fake-spawned-child.ts
  • src/shared/child-process/bounded-output-sink.ts
  • src/shared/child-process/process-spec.ts
  • src/shared/child-process/run-process.test.ts
  • src/shared/child-process/run-process.ts

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.

@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

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's terminationBarrier primitive, spawning detached on POSIX so the deadline signals -pgid, escalates to SIGKILL, and waits for verified quiescence instead of orphaning a shim chain to init (#18234).
  • outputTruncated plumbed through runProcess — bounded-output-sink exposes truncated(), ProcessResult gains outputTruncated?, and execFileCaptureToTermination rejects on it so gh/glab fail rather than returning a clipped JSON/JSONL answer.
  • Churn-probe coverage restored — execFileCaptureToTermination now records recordSubprocessSpawn, keeping gh coverage and adding the git barrier path.
  • Test re-mock to spawn + shared fixture — four gh/glab suites swapped their execFile stubs for spawn, backed by a new __fixtures__/fake-spawned-child.ts and new deadline/truncation assertions (detached, -pid, exact-cap clip).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.`

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.

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.

@nwparker
nwparker merged commit fb48a97 into main Sep 2, 2026
29 checks passed
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.

1 participant