Skip to content

Make the shell suite's wrapper stop the suite's process group on a timeout, interrupt, TERM or hangup, pin the launcher precedence of lane <name> with launchers the suite names, and say what the pty driver comment counts - #217

Merged
brettheap merged 13 commits into
mainfrom
fix/suite-hygiene-142-143-147
Oct 19, 2026

Conversation

@brettheap

@brettheap brettheap commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Three test-suite hygiene fixes, none of them touching a shipped command.

What was wrong

What changed

file lines (on this branch) change
tests/test_lane_helpers_suite.py 30, 34, 36-37, 158-284, 315-316 run_in_own_group(): the suite runs under Popen(start_new_session=True), and the timeout, a Ctrl-C, and a TERM or hangup to pytest stop its process group (stop_group: TERM, up to 5 s for the suite's own TERM trap to remove its sandbox, then KILL)
tests/test_lane_helpers_suite_timeout.py new, 373 lines twelve tests, below
tests/test_lane_helpers.sh 6073-6153 five precedence cases (lclaude, pclaude, claude-profile, no launcher, $PCLAUDE), in the lane <name> section straight after CASE 2
tests/test_lane_helpers.sh 10655-10658 the comment reword only

A session of its own is not the group tests/run.sh stops, so a group TERM and a hangup now reach pytest alone, and pytest has no handler for either (the independent review reproduced the orphaned sleep on the first head of this PR). run_in_own_group installs one for as long as it waits, only where the disposition is still the default, so a nohup'd run keeps ignoring a hangup. The handler only NOTES the signal and the wait is made in half-second slices that look for it, because a handler that raised would also raise inside Popen(), after the fork and before the child is bound; a signal that arrives as the suite finishes is not swallowed; and after the group is stopped the signal is sent again with its default action restored, so the process ends as it would have. stop_group ignores Ctrl-C until it is done (a Ctrl-C during the grace used to skip the KILL and orphan a suite that ignores TERM) and sends the KILL from a finally. The grace is 5 s, not the 10 tests/run.sh gives its own group (really about 10.7 s: fifty polls of 0.2 s and a ps each), so this stop finishes inside run.sh's and run.sh never KILLs pytest mid-stop. A timeout is raised again with the bound that was passed and the output gathered so far, so a CI log reads "timed out after 5400 seconds" and not the last half-second slice's. The pty driver's children are session leaders of their own and are outside the group; each is bounded by that driver's own silence limit.

The lane cases use fake launchers in directories of their own: with both lclaude and pclaude on PATH and the pclaude directory FIRST, lclaude runs (so the rule is shown to prefer a name, not a PATH position); with every directory holding an lclaude taken out of PATH (the a17 section's own idiom), pclaude runs; with neither, claude-profile; with none of the three, lane refuses with 2 and runs nothing; and with $PCLAUDE set and an lclaude on PATH, $PCLAUDE wins. Each asserts the whole logged line, so it also proves exactly one launcher ran.

Other writers may add cases to tests/test_lane_helpers.sh in other sections; this PR inserts only at the two ranges above.

Tests

  • tests/test_lane_helpers_suite_timeout.py points the wrapper's SUITE at a stand-in script that starts a sleep 600, answers TERM with a trap as the suite does, and hangs. The timeout and the interrupt: the sleep must be gone (a zombie does not count) and the trap must have run. A stand-in that ignores TERM must be KILLed after the grace. The signal tests run run_in_own_group in a process of their own, in a group of its own, as tests/run.sh runs pytest, and signal that group with TERM and with HUP the way stop_group does: no sleep survives, the trap ran, and the runner ends by the signal it was sent. A hangup the run was ignoring stays ignored. A TERM, or a Ctrl-C, followed by a Ctrl-C inside the grace of a suite that ignores TERM must not orphan it. A timeout reports the bound it was given, and the partial transcript comes with it. A Ctrl-C inside the grace lets a suite whose TERM trap takes a second finish writing its marker (a one-second trap in a three-second grace, so a loaded bench has about two seconds of margin). A green stand-in and a red one pin that the footer check and the printed transcript are unchanged. The tests' own cleanup does not depend on the wrapper working: a fixture kills a leaked sleep, the SIGINT sender is gated on an event, and the module is skipped where ps -o stat= -p cannot answer.
  • The test module imports where signal has no SIGHUP (tests-windows once died collecting it, run 38465043600, because a decorator named it; no Windows job remains in CI, ci: run the test suite on Linux only #227, so this was checked by deleting SIGHUP from signal and importing).
  • Under the shared lock, with every LANES_* and TMUX* unset (trap 16), at d798d70 (the branch merged with main at a41adb6): python3 -m pytest tests/test_lane_helpers_suite_timeout.py tests/test_repo_hygiene.py -q gives 201 passed in 25.55 s. The two newest tests (the timeout bound, and the slow-trap test, whose stand-in trap takes one second inside the three-second grace) passed 10 runs in a row. With the SIGINT ignore removed from stop_group the slow-trap test is red (1 failed, 11 passed), and against the previous round's wrapper (06a2cd6) the timeout-bound test is red (1 failed, 11 passed). Earlier rounds, at 799dbc6: 162 passed; the Ctrl-C-in-the-grace test red against 97a1e16; and against mutants of the wrapper (no handlers installed, 4 failed; a handler installed even over an ignored hangup, 1 failed; no TERM stage before the KILL, 4 failed; no stop of the group when a signal was noted, 4 failed).
  • The five lane cases were run in a throwaway slice of tests/test_lane_helpers.sh (the suite's header and fakes, the repoA11 fixtures, the lane section through the new cases; about 30 s) on a host that has the real /usr/local/bin/lclaude: 10 new assertions pass. Each goes red under its matching mutation of launcher(): order swapped, $PCLAUDE ignored, pclaude fallback dropped, claude-profile fallback dropped, claude itself let in. The full 45-minute shell suite was not run locally; CI's Linux tests and tests-no-submodule jobs are its record.
  • CI: run 39067800623 at 97a1e16 and run 39094913000 at 06a2cd6 were green (tests and tests-no-submodule). The run at the current head d798d70 is run 39113489411.

Closes #143
Closes #147
Refs #142 (item 3)

🤖 Generated with Claude Code

Summary by Sourcery

Prevent shell-suite process leaks and lock down launcher precedence while correcting the related CI-run documentation.

New Features:

  • Add coverage that pins launcher selection precedence for lane <name> across environment overrides and fallback launchers.

Bug Fixes:

  • Ensure timed-out or interrupted shell-suite runs terminate their entire process group, preventing orphaned fixtures and preserving cleanup traps.
  • Ensure TERM and hangup signals stop the suite process group while retaining default signal behavior and honoring ignored hangups.

Enhancements:

  • Correct the pty driver comment to accurately describe the CI runs referenced by the issue.

Tests:

  • Add focused tests covering timeout, signal, process-group cleanup, launcher precedence, transcript preservation, and suite success or failure behavior.

brettheap and others added 4 commits October 11, 2026 16:49
…darwin and one on Linux whose two jobs both went red, not seven

Copilot read "five on darwin, then both Linux jobs of #61's `ready` run" as
seven runs. #107 names six: five `tests-macos` runs and one Linux run,
37124906535, in which both the `tests` and `tests-no-submodule` jobs failed.
The count was right and the wording was ambiguous; this changes a comment only.

Closes #147

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… names itself, so no host's lclaude can be picked

#143's eight false reds were already gone: c1bac0d exports PCLAUDE before the
`lane` cases, which pins the launcher seam to the suite's fake. What was never
added is a case for the rule that applies when the seam is unset, which is
`lclaude`, else `pclaude`. Three cases now, each on a PATH of its own:

* both launchers present, the pclaude directory FIRST, so the rule is shown to
  prefer a name and not a position: lclaude runs, once;
* every directory holding an lclaude taken out of PATH (the a17 section's way
  of making a word absent, and on a workstation the directory the real one is
  in): pclaude runs with the same argv;
* PCLAUDE set explicitly, with an lclaude on PATH: PCLAUDE wins.

Each was checked against a throwaway slice of the suite on a host that has
workBenches' /usr/local/bin/lclaude, and each goes red under the matching
mutation of `lane`'s launcher() (order swapped, seam ignored, fallback dropped).

Closes #143

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…launcher-precedence cases (harness + mutation checked), #142 item 3 test file written; left: apply the start_new_session/killpg fix in tests/test_lane_helpers_suite.py, run the new pytest file red-then-green under the lock, push CI watch, open the PR

The new tests/test_lane_helpers_suite_timeout.py is unrun: its first run was queued behind other lanes on the pytest lock and was stopped before it started. The wrapper in tests/test_lane_helpers_suite.py is still the unfixed subprocess.run.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ess group when the wrapper gives up, so a timeout leaves no orphan `sleep`

subprocess.run(timeout=) killed the bash it started and nothing under it, and
the suite's EXIT trap does not run on a SIGKILL, so the liveness fixture's
`sleep` (longer than TIMEOUT_SECONDS on purpose, #83) and every later
fixture's were orphaned for up to 70 minutes. The suite now runs under
Popen(start_new_session=True), and any exception out of communicate() - the
timeout, and a Ctrl-C, which a session of its own no longer receives from the
terminal - kills the group with os.killpg before it propagates.

tests/test_lane_helpers_suite_timeout.py drives the wrapper's own test function
against a stand-in suite that starts a `sleep 600` and hangs: on the old
wrapper the timeout and interrupt tests fail with that sleep still running
(2 failed, 2 passed); the green-suite and red-suite tests pin that the
footer check and the transcript on failure are unchanged.

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 22 hours and 51 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR hardens the shell-suite wrapper against orphaned descendants by killing a dedicated process group, adds regression tests for timeout/interruption and output handling, pins the lane launcher precedence with host-independent shell cases, and corrects the related CI-run comment.

File-Level Changes

Change Details Files
Run the shell suite in its own process session and terminate the entire process group whenever execution exits exceptionally.
  • Replace timeout-based subprocess.run with Popen and communicate.
  • Use start_new_session=True so the suite leads its process group.
  • Kill the group on timeout, interruption, or other propagated exceptions while preserving output and return-code handling.
tests/test_lane_helpers_suite.py
Add focused regression coverage for descendant cleanup and unchanged wrapper reporting behavior.
  • Exercise timeout and KeyboardInterrupt paths with a stand-in suite that starts a long-lived sleep.
  • Verify the child is gone, excluding zombie processes.
  • Retain coverage for successful footer parsing and complete failure transcript reporting.
tests/test_lane_helpers_suite_timeout.py
Pin launcher selection behavior with isolated fake executables and exact invocation assertions.
  • Verify unset PCLAUDE prefers lclaude even when pclaude appears earlier in PATH.
  • Verify pclaude is selected when all lclaude locations are removed from PATH.
  • Verify an explicit PCLAUDE overrides an available lclaude.
  • Assert exit status, working directory, arguments, and exactly one launcher invocation.
tests/test_lane_helpers.sh
Correct the pty-driver incident-count comment to distinguish CI runs from jobs.
  • Describe five Darwin runs and one Linux run whose two jobs failed, rather than counting the jobs as separate runs.
tests/test_lane_helpers.sh

Assessment against linked issues

Issue Objective Addressed Explanation
#143 Keep the lane shell-suite cases independent of a host-installed lclaude, so workstations do not get false failures from launcher selection. ✅
#143 Add controlled tests for launcher precedence: $PCLAUDE overrides PATH launchers; otherwise lclaude wins over pclaude; and pclaude is used when lclaude is unavailable. ✅
#147 Reword the pty driver comment so it clearly counts five macOS runs and one Linux run, whose two jobs both went red. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Brett Heap and others added 2 commits October 13, 2026 20:38
… on the timeout, TERM before KILL, and clean up in the tests that watch it

Review of the session change found that moving the suite out of tests/run.sh's
process group opened a new way to orphan the fixture `sleep`: run.sh's
`kill -TERM -- -<pgid>` and a terminal's hangup now reach pytest alone, pytest
has no handler for either, and the suite's bash dies on its dead pipe with its
TERM trap never run. On main the suite shared the group and its trap cleaned up.

The wrapper's call is now run_in_own_group(): for as long as it waits it
installs a TERM and a HUP handler, where the disposition is still the default
(a nohup'd run keeps ignoring a hangup), which stops the suite's group and then
lets the signal take pytest as it would have. The timeout and a Ctrl-C stop the
group the same way. stop_group sends TERM first and waits up to ten seconds
(run.sh's own grace) for the suite's trap to remove its sandbox, then KILLs
what is left. The comment no longer claims the group is everything the suite
started: the pty driver's children are session leaders of their own.

The new tests signal the runner's own group the way run.sh does (TERM and HUP)
and assert no `sleep` survives, that the TERM trap ran, that a TERM-deaf group
is killed after the grace, and that an ignored hangup stays ignored. The
tests' own cleanup no longer depends on the wrapper working: a fixture kills a
leaked `sleep`, and the SIGINT sender is gated on an Event so it cannot fire
after the wrapper has returned.

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…er-precedence cases, and check the exit code of the PCLAUDE case

The `lane` launcher is `$PCLAUDE`, else lclaude, else pclaude, else
claude-profile, else a refusal with 2. The cases covered the first three; two
more now cover the last two, on a PATH where the suite's own pclaude (in
fakebin, beside the fake tmux, ps and pgrep) is replaced by links to everything
else in that directory, and where every directory holding one of the three
words is taken out. The PCLAUDE case also asserts the exit code.

Checked in the throwaway slice of the suite, on a host with the real
/usr/local/bin/lclaude: dropping the claude-profile fallback, and letting
`claude` itself be found, each turn the matching cases red.

Refs #143

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@brettheap brettheap changed the title Make the shell suite's wrapper kill everything it started on a timeout, pin the launcher precedence of lane <name> with launchers the suite names, and say what the pty driver comment counts Make the shell suite's wrapper stop the suite's process group on a timeout, interrupt, TERM or hangup, pin the launcher precedence of lane <name> with launchers the suite names, and say what the pty driver comment counts Oct 13, 2026
The Windows job collected tests/test_lane_helpers_suite_timeout.py and died with
`AttributeError: module 'signal' has no attribute 'SIGHUP'`: the parametrize
decorator names the signal at import, before the module-wide Windows skip can
apply. SIGHUP is now read with getattr, and the module imports with the
attribute removed (checked by deleting it from `signal` and importing).

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brett Heap and others added 5 commits October 18, 2026 02:28
… finish inside run.sh's own, and note a TERM or hangup instead of raising from its handler

The delta check of the signal handling found two edges and a window.

* A SIGINT during the grace left child.wait() with a KeyboardInterrupt before
  the KILL stage, so a suite that ignores TERM was orphaned: TERM then Ctrl-C,
  and Ctrl-C twice, both ended the runner with the suite's `sleep` still
  running. stop_group now ignores SIGINT until it is done, and the KILL is in a
  `finally` as well.
* GROUP_TERM_GRACE equalled the ten seconds tests/run.sh's stop_group gives its
  own group, which is really about 10.7 (fifty polls of 0.2 s and a `ps` each),
  so a delay on pytest's side let run.sh KILL pytest mid-stop. It is five now,
  and the comment says why.
* A handler that raised also raised inside Popen(), after the fork and before
  `child` was bound, leaving the suite with nobody to stop it. The handlers now
  only note the signal; the wait is made in half-second slices that look for
  one, a signal that comes as the suite finishes is not swallowed, and the
  signal is sent again with its default action after the group is stopped.

The new test sends a deaf suite's runner a TERM, or a Ctrl-C, and a Ctrl-C
inside the grace, and asserts no `sleep` survives. The tests' `ps` check is now
a probe that skips the module where `ps -o stat= -p` cannot answer, rather than
one that passes by finding nothing.

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…during the TERM grace lets a slow trap finish

The wrapper now waits in half-second slices, and the TimeoutExpired it re-raised
was the last slice's, so a 5400 s CI timeout would have read "timed out after
0.4 seconds". It is raised again with the bound that was passed and the output
and stderr gathered so far, and a test asserts the bound, the message and the
partial transcript.

Nothing pinned stop_group's SIGINT ignore: with it removed the KILL in the
`finally` still prevents an orphan, but a Ctrl-C in the grace cuts short the
cleanup of a suite that does answer TERM, slowly. A stand-in whose TERM trap
takes two seconds now has to finish writing its marker through a Ctrl-C.

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…second trap inside the three-second grace

The stand-in's TERM trap took two seconds against a three-second grace, and the
marker landed 2.1 to 2.5 s after the TERM, so about a second of scheduler delay
would have failed it. The trap now takes one second, which roughly doubles the
margin and still leaves the Ctrl-C landing mid-trap, and the comment says where
the Ctrl-C lands rather than where the trap is.

Refs #142 (item 3)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap merged commit 55b26e3 into main Oct 19, 2026
5 checks passed
@brettheap
brettheap deleted the fix/suite-hygiene-142-143-147 branch October 19, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant