Skip to content

fix(babysit-pr): end every orphan of a bounded gh call under bash 3.2 - #74

Merged
chapati23 merged 1 commit into
mainfrom
fix-gh-timeout-bash32
Nov 26, 2026
Merged

chapati23 merged 1 commit into
mainfrom
fix-gh-timeout-bash32

Conversation

@chapati23

Copy link
Copy Markdown
Contributor

tl;dr

  • The PR watcher could stall for ten minutes on macOS's built-in older shell when a GitHub read left a stray background process behind. This change makes the watcher clean such processes up reliably, so its time limits hold on every shell. Nothing changes for you except that the timeout test now passes there.

The Problem

  • Under bash 3.2, a bounded gh call's leftover child could survive the one process-group kill and hold the $(...) pipe open, so the poller waited until it exited.
  • gh-timeout.test.sh's orphan case took 601 s against a 7 s margin under /bin/bash 3.2.

The Solution

  • bounded_run kills the command's process group again while it still has members, at most three rounds 20 ms apart, on the normal, alarm and signal paths.
  • An empty group costs nothing extra; a group of unreaped zombies costs at most 40 ms.
  • Decision: retry the kill rather than relay the output through perl, because the observed race is one in-progress fork, which the second round ends.

Risk

  • 🚪 Door: two-way. Revert the commit; no state changes.
  • 💥 Blast Radius: every gh call the babysit-pr poller makes, in every repo that uses the skill.

Validation

  • Gates at 0a589a9: validate-skills.mjs 27 skills ✓, pnpm test:scripts ✓, shellcheck ✓, pnpm check:shell ✓, Giskard pin preflight ✓ (no workflow change)
  • Regression: gh-timeout.test.sh under /bin/bash 3.2 fails on base 0b01f6c and on main (orphan case, 601 s), passes on head 3 of 3 runs (about 30 s each); also passes under bash 5.3
  • Not run locally: 5 eval-creator suites in test-skills.sh (this machine's python3 lacks psutil); the change does not touch them, CI installs it
  • Review: direct review plus codex review → 2 P2 findings, both declined (see Deferrals)

Deferrals

  • Declined (Codex P2), a miss on all three rounds: it needs a fork chain inside each 20 ms gap, which gh never makes.
  • Declined (Codex P2), group ID reuse within 40 ms: needs the PID space to wrap; the base already kills after reaping.

Ship Checklist

  • PR title is a Conventional Commits header, type: summary or type(scope): summary, as commitlint.config.mjs enforces for commits
  • Performed a self-review of my own changes
  • node scripts/validate-skills.mjs and the affected test suites pass
  • Nothing in the diff breaks the public-readership rules in AGENTS.md
  • Body is about 250 words, 400 at most, excluding this checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

bounded_run killed the command's process group once after it exited. Under
bash 3.2 a background list forks its last command instead of exec'ing it, so
a member that was forking when the signal arrived could leave a child the
kill missed. That child held the $(...) pipe, and the poller waited until it
exited: gh-timeout.test.sh's orphan case took 601 s against a 7 s margin.
Kill the group again while it still has members, at most three rounds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T14:20:27.150215Z 0a589a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Claude finished @chapati23's task in 2m 14s —— View job


Review complete

Verdict: LGTM

Analysis

The change replaces each single kill "KILL", -$pid with a new kill_group($pid) sub that retries the process-group kill up to 3 times, 20 ms apart, stopping early once kill() returns 0 (no members left to signal). Traced through all three call sites:

  1. Normal-exit path (gh-bound.sh:93): $status is saved into my $status = $?; before kill_group runs, so the retries can't clobber the exit status being propagated. In the common case (no orphan), the first kill() call returns 0 immediately and last fires — no sleep, matching the PR's "costs nothing extra" claim.
  2. ALRM path (gh-bound.sh:78-86): unchanged ordering (TERM → sleep 0.2 → kill_group → waitpid); alarm 0 already ran before this, so there's no race between a pending alarm and the retry sleeps.
  3. INT/TERM/HUP paths (gh-bound.sh:71-77): same kill_group + waitpid + exit pattern as before, just with retries.

The loop bound (3 rounds, 2× 20 ms sleeps = 40 ms worst case) matches the PR body exactly, and the "stop early when the group is empty" behavior via kill(...) or last is correct Perl (kill returns the count of processes signaled, 0 signals an empty/absent group).

Checked against AGENTS.md:

  • Shell modularity: bounded_run is 48 lines (49–96), under the 50-line function cap — no baseline row needed, none added.
  • No public-readership issues (no hostnames/paths/personal info introduced).
  • The new comment (gh-bound.sh:61-64) explains why (bash 3.2's extra fork for the last command of a backgrounded list racing the group kill), not what, consistent with the file's existing comment style and the repo's comment guidance.
  • Line-scoped shellcheck disable=SC2016 above the perl string already covered this block; nothing new needed.

Deferred items from the PR body (fork-chain-inside-20ms-gap, pgid-reuse-within-40ms) are reasonable to decline — both require conditions gh itself doesn't create, and the PR is explicit that these are accepted theoretical gaps, not overlooked ones.

No correctness, security, or style issues found worth flagging inline. The fix is minimal, well-reasoned, matches its own stated risk/validation, and the retry logic does exactly what the PR description says it does.

Findings roll-up

No findings — reviewed implementation matches the described fix with no bugs identified.

@chapati23

Copy link
Copy Markdown
Contributor Author

Thanks. Claude review: LGTM, no findings. Codex GitHub review: no findings. The local codex review raised two P2 findings, both declined with reasons in the PR body's Deferrals section: a miss on all three kill rounds needs a fork chain inside each 20 ms gap, and process-group ID reuse within 40 ms needs the PID space to wrap.

@chapati23
chapati23 merged commit 4080280 into main Nov 26, 2026
5 checks passed
@chapati23
chapati23 deleted the fix-gh-timeout-bash32 branch November 26, 2026 14:53
chapati23 added a commit that referenced this pull request Nov 26, 2026
…#75)

* fix(babysit-pr): treat a clean Claude review summary as informational

The watcher counted every claude-code-action summary as unanswered
top-level feedback, so a PR with an LGTM review stayed FEEDBACK_GATE_PENDING
until someone replied (agents #73 and #74). The summary is free-form model
text, so the review prompt now asks for one exact last line on a clean
review, and the watcher drops a github-actions[bot] summary only with the
action's header, that last line and no [P1]-[P3] tag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): require the whole clean shape of a Claude summary

The local Codex review found that a summary with an untagged finding and
the result line cleared the gate. A clean summary now holds only the
header, blank lines and checklist items before that line; anything else
stays actionable. Logins may carry a managed-user shortcode, and the watch
runbook states one rule for Claude summaries instead of two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): a clean Claude summary is the header and one line

The second local Codex review found that an open checklist item could
carry an unanswered request past the gate, and that the prompt did not
describe the whole accepted body. A clean summary is now the action's
header and rule plus the result line and nothing else, and both prompts
ask for exactly that body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): accept a Claude header without a duration

The pinned claude-code-action leaves out " in <time>" when it has no
timing, and writes the time only as "Ns" or "Nm Ns". The header match now
makes that clause optional and accepts only those two forms (third local
Codex review).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* style(babysit-pr): apply prettier to exact-feedback-formats.md

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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