Skip to content

Stop killing a working test run as stalled when its workers run in their own session - #4477

Closed
dtoelke wants to merge 1 commit into
garrytan:mainfrom
dtoelke:stall-guard-counts-worker-sessions
Closed

dtoelke wants to merge 1 commit into
garrytan:mainfrom
dtoelke:stall-guard-counts-worker-sessions

Conversation

@dtoelke

@dtoelke dtoelke commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

/ship no longer kills a working test run as stalled when the test command starts its workers in their own session.

Why: the stall check measured CPU in the command's process group only, so under pnpm 11 a busy but quiet Vitest run read as idle and was killed.

Nothing to do: a command whose workers stay in its process group is measured and killed exactly as before.

Why (in your own words)

Our monorepo runs its tests through pnpm exec vitest run. With pnpm 11, pnpm exec starts Vitest in a new session, so the workers are outside the process group gstack creates for the command. One of our suites prints nothing for longer than the stall timeout while it works. /ship ended PREGATE_STALLED three times in a row at the same tree, and the same suite was green when run by hand. The stall check was reading CPU time from the process group alone, where only the idle pnpm wrapper was left.

This change sums CPU over the command's process tree: its group plus every descendant reached by parent links, whatever session it started. A stall or timeout kill now signals the group of each such descendant too, so the worker is not left running after the command is killed. After a normal exit only the command's own group is cleaned up, as today.

Live evidence

repro.sh builds a throwaway repo whose test command starts one worker in a new session (a detached spawn, which is what pnpm exec does). The worker is busy and silent for 8 seconds, then the command prints its result and exits 0. It runs gstack-pregate --base main --allow-repo-commands --stage tests --only lanes --stall-timeout 3. Temp paths are shortened to <tmp>.

Before, on main at dd4266d:

PREGATE: tests incomplete in 3.3s — lanes: no test output for 3 s and its process group used under a tenth of one CPU; process group killed; last file started: test/util.test.js
tests      lanes     incomplete         3349 ms  no test output for 3 s and its process group used under a tenth of one CPU; process group killed; last file started: test/util.test.js (PREGATE_STALLED)
    lanes: ran: node run-tests.js 'test/util.test.js'
PREGATE: incomplete tree=fd2289dee249 head=8e052a07c1ae checks=1 of 8
exit=1

After, on this branch:

PREGATE_TEST: 1/1 test/util.test.js start
PREGATE_TEST: 1/1 test/util.test.js pass 8.1
PREGATE: tests pass in 8.4s — lanes: count unavailable tests ran in 1 file(s), exit 0
tests      lanes     pass               8357 ms  count unavailable tests ran in 1 file(s), exit 0
    lanes: ran: node run-tests.js 'test/util.test.js'
    lanes:   1 pass, 0 fail
PREGATE: pass tree=fd2289dee249 head=73f81a72a9a6 checks=1 of 8

The two new tests in test/pregate-supervise.test.ts fail on main's lib/pregate/supervise.ts and pass here:

# main's supervise.ts with the new tests
(fail) supervise: process group, log file, stall and deadline > a worker the runner starts in its own session counts toward CPU: busy and silent runs to the end, never-ending is killed with the runner at the deadline
(fail) supervise: process group, log file, stall and deadline > a tree whose runner and own-session worker both sit idle is killed as stalled, worker included

# this branch: both pass

The reproduction script:

#!/usr/bin/env bash
# repro.sh <gstack checkout>
set -eu
GSTACK=$1
T=$(mktemp -d)
git init -q --bare "$T/origin.git"
git init -q -b main "$T/work" && cd "$T/work"
git config user.email [email protected] && git config user.name repro && git config commit.gpgsign false
git remote add origin "$T/origin.git"
mkdir -p .gstack lib test
echo '{ "runner": "node run-tests.js {files}", "dependencies": { "README.md": [], "run-tests.js": [] } }' > .gstack/pregate.json
echo '# repro' > README.md
cat > run-tests.js <<'JS'
const { spawn } = require('node:child_process');
const busy = 'const end = Date.now() + 8000; while (Date.now() < end) {}';
const worker = spawn(process.execPath, ['-e', busy], { detached: true, stdio: 'ignore' });
worker.on('exit', code => { console.log('1 pass, 0 fail'); process.exit(code ?? 1); });
JS
echo 'exports.add = (a, b) => a + b;' > lib/util.js
echo "require('../lib/util.js');" > test/util.test.js
git add -A && git commit -q -m base && git push -q -u origin main
git checkout -q -b change
echo 'exports.add = (a, b) => b + a;' > lib/util.js
git commit -q -am 'edit util'
GSTACK_HOME="$T/home" "$GSTACK/bin/gstack-pregate" --base main --allow-repo-commands --stage tests --only lanes --stall-timeout 3 2>&1 || echo "exit=$?"

Scope

  • Changed: lib/pregate/supervise.ts (a process table with parent links, processTree, treeCpuMs in place of groupCpuMs, killTree for stall and timeout kills), two tests, the wording "process group" to "process tree" where the stall is described (bin/gstack-pregate help and cancel line, lib/result-codes.ts, lib/pregate/config.ts, the guard and stall detail lines, docs/pregate.md, docs/troubleshooting.md), a changelog fragment.
  • Verified live by: the reproduction above on macOS with Bun 1.3.13 (the ps -S path); bun run typecheck; test/pregate-supervise.test.ts, where five other tests fail here and fail the same way on main. It has also run in a private pnpm 11 monorepo's /ship since 2026-11-12.
  • Did NOT test: Linux (the /proc path is changed the same way but I ran it only on macOS); Windows (no CPU reading there, unchanged); a worker reparented away from the tree by a double fork, which is still not measured; the full free suite (bun run test).

Liveness proof (required for external contributors)

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above

…eir own session

The stall check read CPU time from the test command's process group alone.
A launcher such as pnpm exec (pnpm 11) starts Vitest in a new session, so a
quiet suite that was busy looked idle and was killed at the stall timeout.
The check now sums CPU over the process tree: the command's group plus
every descendant by parent links. Stall and timeout kills signal the group
of each such descendant as well.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 18, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Thank you, @dtoelke. This is a real problem with good evidence: the before/after run, the throwaway repo and two tests that fail on main make the cause clear, and pnpm 11's pnpm exec starting Vitest in its own session is exactly the kind of thing the stall check missed.

What happens next: because this changes how gstack finds and signals processes outside the command's own group, we won't merge the branch as-is. We'll rebuild the change on current main with you credited, and give the signal fan-out a careful safety read first (for example, making sure a reused pid can never get a kill meant for a test worker). We'll link the new PR here and close this one when it lands. Until then, --stall-timeout 0 (or stall_timeout_s: 0) turns the stall check off for that suite.

@capy-ai capy-ai Bot added bug Something isn't working S3 Severity 3: everything else labels Nov 18, 2026
@capy-ai

capy-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Thanks @dtoelke. The stall fix from this PR landed in #4533, rewritten on current main, and you're credited as a co-author.

/ship's test check now counts CPU from every process descended from the test command, whatever session it starts in. So a quiet Vitest run under pnpm 11's pnpm exec that is still working is no longer killed as stalled. Stall and timeout kills now reach those workers too. A truly hung run is still killed at the same stall timeout.

#4533 carries only the stall fix from this PR.

@capy-ai capy-ai Bot closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working S3 Severity 3: everything else

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants