Skip to content

fix(install): end a gh shim's lingering child with the Windows star check - #1073

Merged
devswha merged 2 commits into
mainfrom
fix/install-ps1-gh-job-object
Oct 14, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/install-ps1-gh-job-object

Conversation

@devswha

@devswha devswha commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Fixes #558

Root cause

install.ps1 Invoke-GhApi (origin/main L123-154): when gh is a .cmd/.bat shim run through cmd.exe, the shim can start a child that inherits the stdout pipe and then exit. WaitForExit succeeds, $said.Wait(2000) times out, and the timeout branch (L148) runs taskkill /T /F on the launcher PID, which has already exited and has no tree left. The child lives on. The finally (L154) only called Process.Dispose(), which on Windows PowerShell's .NET Framework leaves the StandardOutput/StandardError readers open.

What changed

  • install.ps1: before gh starts, Invoke-GhApi creates a job object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE through Add-Type P/Invoke (PowerShell 5.1 compatible, compiled once per session, only when gh is present). It assigns the launched process to the job right after Process.Start. On a timeout, closing the job ends gh and every process it started, even one whose parent has exited. The job is also closed in finally. Both pipe readers are closed explicitly, and the close is guarded against a pending ReadToEndAsync. If Add-Type, job creation or assignment fails, the previous taskkill /T path runs unchanged.
  • scripts/windows-install.test.ps1: adds a lingering mode to the gh stand-in. It answers, then leaves a ping child holding its output and writes that child's PID. The new case extracts only Invoke-GhApi from the installer through a PowerShell AST parse, calls it, and asserts the child is gone. Assertions are labelled control (the stand-in named its child; the call returned nothing within 15 s) or regression (fails on main) (the child does not outlive the call).
  • changelog.d/install-ps1-gh-job-object.md: Fixed entry.

Not covered: the two Low notes in the issue about install.sh's gh watcher (a briefly orphaned sleep 1 and PID-only identification). Neither is part of this Windows fix.

Residual: a process gh starts in the instant between Process.Start and AssignProcessToJobObject is not in the job, because Process.Start cannot start suspended. The taskkill fallback still covers a live launcher.

Evidence

On the Windows QA PC (Windows 11, PowerShell 5.1), in a fresh clone of this branch:

  • After (this branch): scripts\windows-install.test.ps1 exits 0 with PASS gh deadline: a child of gh that holds its output ends with the call (PID …, 3 s). The existing native installer, star and herdr installer cases still pass.
  • Before (install.ps1 from origin/main, same test): exits 1 with regression (fails on main): the child gh left holding its output (PID …) must not outlive the call. Both controls pass. The surviving child was confirmed alive until the test killed it.
  • Cleanup: no leftover ping, no stand-in temp directories, clone removed.

Checks run

  • bun run typecheck: exit 0
  • HERDR_TEST_MODE=unit bun test ./scripts/changelog-fold.test.ts ./scripts/install-star.test.ts ./scripts/conventions.test.ts: 43 pass, 0 fail
  • bun run test:unit: 3515 pass, 0 fail, 8 skipped
  • git diff --check: clean
  • powershell -File scripts\windows-install.test.ps1 on Windows: pass on the branch, regression failure with main's installer (above)

…heck

Invoke-GhApi killed only the launcher PID on its deadline. A gh .cmd shim's
launcher has often exited by then, and taskkill /T finds no tree under an
exited PID, so a child that kept gh's output open lived on, and on .NET
Framework Dispose left the pipe readers open.

gh now runs in a job object with KILL_ON_JOB_CLOSE (Add-Type P/Invoke, works
on Windows PowerShell 5.1), created before gh starts and closed on the
deadline and in finally; the output and error readers are closed there too.
Without a job the old taskkill path still runs.

scripts/windows-install.test.ps1 extracts Invoke-GhApi by AST and runs it
against a gh.cmd stand-in that leaves a ping holding its output; the child's
PID must be gone after the call (regression, fails on main).

Closes #558
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51ea154e-4be7-47b9-9b13-9db298beb433
📥 Commits

Reviewing files that changed from the base of the PR and between b8cd639 and 8cecf3f.

📒 Files selected for processing: 3
  • changelog.d/install-ps1-gh-job-object.md
  • install.ps1
  • scripts/windows-install.test.ps1
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Fix the blocking PR #1073 start-before-assignment finding by creating gh suspended with redirected pipes, assigning its job, then resuming it. Pin the race with an immediate-child Windows shim and a forced runnable-launch negative control.
@devswha
devswha merged commit e2bab55 into main Oct 14, 2026
10 checks passed
@devswha
devswha deleted the fix/install-ps1-gh-job-object branch October 14, 2026 11:46
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.

install.ps1: a shim gh's child that keeps the output pipe can outlive the 10-second deadline

1 participant