Skip to content

test(check): the zombie fixture's parent cannot miss its child's exit - #3605

Merged
devswha merged 1 commit into
mainfrom
test/check-zombie-fixture
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
test/check-zombie-fixture

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Why

scripts/check.test.ts "slots > takes over a marker whose run has exited but is not reaped yet" failed two local merge gates (#3281, #3570) after five seconds: the parent did not hear its child exit within 5000 ms PID 1506. It is not slow under load: it takes 25 to 80 ms when it passes, and when it fails it waits for a word that never comes.

The fixture is a perl parent that forks a child, lets it exit without reaping it, and prints ZOMBIE from its SIGCHLD handler; then it waits in pause(). Perl does not run a handler when the signal arrives: it notes the signal and runs the handler at its next look for signals, between statements. A SIGCHLD that lands after the last look and before pause() is noted and not acted on, and pause() then waits for a signal that has already come. The child exits about as long after the fork as the parent takes to print its pid and reach pause(), so the two meet.

What

The parent blocks SIGCHLD before the fork and waits with sigsuspend(), which lets the signal in and waits in one step: a signal that came early is still pending when the wait begins. Test-only, one line of perl. No assertion, wait or timeout changed.

Proof

Run Result
main's fixture, 3000 runs, 12 at once on 12 CPUs, unforced (CI runner image, perl 5.38.2) 5 printed the pid and never ZOMBIE; in all 5 the child was a zombie by then
the new fixture, the same 3000 runs 0
the new fixture, 12000 runs 0
main's test with the gap between the last look for signals and pause() made long (the same statement builds a 30-million-item list first; scratch patch) fails after 5 s, 0 pass, 1 fail
this branch's test with the same gap before sigsuspend() passes (200 ms)

In the forced run Bun's own five-second limit ended the test a moment before the fixture's (this test timed out after 5000ms); in the gate the fixture's limit came first. Both wait for the same missing word. That the gate's child had exited is not in its log (the test stops before it reads the child's state); in the unforced misses here it had.

Validation

  • bun run check fast: pass on this head (15146 unit tests pass, 0 fail).
  • bun test ./scripts/check.test.ts -t "takes over a marker whose run has exited": 3 of 3 on this PC (perl 5.40.1), 1 of 1 in the CI runner image.
  • Skipped: bun run check full, the integration and browser suites (one unit test changed, no product code). No changelog fragment: nothing a user notices.

🤖 Generated with Claude Code

The fixture's perl parent printed "ZOMBIE" from its SIGCHLD handler and waited in pause(). Perl
runs a handler at its next look for signals, between statements: a SIGCHLD that landed after the
last look and before pause() was noted and never acted on, and pause() then waited for a signal
that had already come. The test waited its five seconds for "ZOMBIE" and failed (two local merge
gates, "the parent did not hear its child exit within 5000 ms PID 1506").

SIGCHLD is now blocked until the parent waits, and the wait is sigsuspend(), which lets the
signal in and waits in one step.

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

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved reliability of the Linux zombie-process test by preventing a race condition while waiting for the child process.

The Linux zombie-process test now blocks SIGCHLD before forking and uses sigsuspend to wait for the child-exit signal.

Changes: Zombie-process test

Layer / File(s) Summary
Atomic SIGCHLD wait
scripts/check.test.ts
The Perl parent fixture blocks SIGCHLD before forking and uses sigsuspend instead of the POSIX::pause loop. This avoids a missed signal between checking and waiting.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other · Severity of issue fixed: Low

Merge Risk: Minimal · up to 846dc

The fixture now waits atomically for the child’s exit. No merge-blocking issue is identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the test change: preventing the zombie fixture’s parent from missing its child’s exit.
Description check Passed The description explains the problem, the SIGCHLD and sigsuspend fix, supporting test results, validation, and skipped checks. Its “Why” and “What” sections cover the template’s required “Change” info…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, the SIGCHLD and sigsuspend fix, supporting test results, validation, and skipped checks. Its “Why” and “What” sections cover the template’s required “Change” information.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6821c55 and 846dcce.

Files selected for processing: 1

  • scripts/check.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate: PASS

Local merge gate: PASS #3605 merge=e5d51803638a head=846dcce3e0bd main=64344a52aa17 on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 in 632s, reruns=1

The Linux suites of the required checks (Fast checks, Integration and browser), run on main 64344a5 with this PR's head 846dcce merged in (local merge e5d51803638a, not pushed), as groups side by side in the self-hosted CI runner image on herdr-ci-runner:local on devswha-ThinkStation-P620 CPUs 64-127 (38% busy before the start, host load 73.83; shards=4 unit_workers=8 browser_main_workers=2 browser_other_workers=16). Scope: full. Native Windows install and the macOS checks are not part of this gate.

Step Command Result Seconds Counts
fast-install bun install --frozen-lockfile pass 0 -
release-guards bun scripts/release-guards.ts --base 64344a52aa17 pass 0 -
fast bun run check fast pass 221 tests 15246 pass / 0 fail; check steps 6 ok / 0 failed
integration-install bun install --frozen-lockfile pass 0 -
integration bun run check integration pass 238 tests 1390 pass / 0 fail; check steps 3 ok / 0 failed
browser-main-install bun install --frozen-lockfile pass 0 -
browser-main-build bun run build pass 15 -
browser-main BROWSER_SCRIPTS=ui-regression,ui-contexts-regression bun run check run -- bun scripts/ci-browser-parallel.ts pass 402 browser scripts 2/2 passed
browser-other-install bun install --frozen-lockfile pass 0 -
browser-other-build bun run build && bun run build:shell pass 22 -
browser-other BROWSER_EXCLUDE=<those two> bun run check run -- bun scripts/ci-browser-parallel.ts pass 596 browser scripts 203/203 passed

Reruns:

  • browser scripts/palette-machines-demo-regression.ts failed, then passed on its automatic second run

Total 632s.

@devswha
devswha merged commit 4ba7810 into main Nov 10, 2026
12 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 846dcce3e0bd as 4ba7810a092f on the local merge gate, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

One reviewer: owner's test-only PR: one fixture line.

Test-only: one reviewer (Codex Terra), CLEAR. The fixture's perl parent could miss a SIGCHLD that landed just before pause(); 5 of 3000 runs on main, 0 of 12000 with the fix.

@devswha
devswha deleted the test/check-zombie-fixture branch November 10, 2026 19:24
devswha added a commit that referenced this pull request Nov 11, 2026
…prove a FIFO unread by who gets its text (#3630)

## Why

Two tests fail on a busy machine with their code untouched.

- `server/pty/host.test.ts`, "PtySession on the node PTY host > ends a
plain exit without waiting out the hold for a closed terminal": 151.99
and 213.5 ms against 150 in two local merge gates (#3585, #3354), 233.6
and 166.7 ms in two Integration jobs on GitHub (run 42827626297 attempt
1 of #3542, run 42831916527 attempt 1).
- `server/opencode.contract.test.ts`, "answers the catalog and a cold @
send within budget while opencode.json is a FIFO": 2047 ms against 2000
in the local gate of #3585.

Each measured mostly something else than what it guards.

- The PTY test's 150 ms ran from before the host's spawn. The Node
host's start is 37 of the 55 ms an idle run takes; the behaviour, an
exited command not being held for the host's 200 ms wait, is the last
17.
- The FIFO test's 2 s is the 1.5 s attach budget plus delivery. The
server never opens the FIFO, so none of it is the FIFO. On one CPU the
test fails every time (2009, 2023 ms).

## What

- PTY: the command leaves a file as it exits (`: > "$1"; exit 7`), and
the 150 ms run from that file's own time (its mtime, the system's word
for when the command wrote it) to the reported exit. What the test
process does late only makes the span longer, so a host that holds the
exit cannot pass on a busy machine. (The first head of this PR started
the clock when the test saw the file; the review showed that could hide
a hold.) Same number, same exit code. From there the exit is 18 to 23 ms
away on the Node host (the Rust host's whole test takes 4 to 5 ms); a
waited hold adds 200 ms. The marker is a file and not output because the
Node host ends a pty whose last byte comes with the hangup another way
(see "Not in this PR").
- FIFO: a writer waits at the FIFO from the start, and the test goes on
only once the writer has said it is about to open the FIFO and sleeps in
that open, so no read can come before it waits. Its open returns only
when something opens the FIFO to read, and that reader gets its text. At
the end the test opens the FIFO itself, without waiting, and must get
the text. No time is counted, and a server that reads the FIFO is not
held by it, so a regression fails in about 4 s instead of 7. The test is
renamed "answers the catalog and a cold @ send without opening an
opencode.json that is a FIFO".
- No product code changes.

Two things change in what the FIFO test catches:

- It now also fails when the server opens the FIFO without waiting on it
(`O_NONBLOCK`, refused by its descriptor). The old test passed there.
`openRegular` checks the path before any open, and the test now holds it
to that.
- It no longer bounds the catalog at 4 s or the first key at 2 s. A cold
send slowed past 2 s by something other than the FIFO failed before and
passes now. The attach budget has its own test, checked at its boundary
(#1741).

## Proof

In the CI runner image, one container at a time, commit ce11b34 plus
patch files.

| Product | Old tests | New tests |
|---|---|---|
| as is, 8 CPUs, whole files ×3 | pass | pass (41 pass / 26 pass, 0
fail) |
| as is, with a Rust host built from main, `host.test.ts` ×3 | pass |
pass on both hosts (64 pass, 0 fail) |
| Node host waits out the hold for an exited command | fail ×3 (322 to
371 ms) | fail ×3 (206 to 207 ms) |
| Rust host waits out the hold for an exited command | fail ×3 (404 ms)
| fail ×3 (200.4 ms) |
| the scan reads `opencode.json` with a plain open | fail ×3 (catalog
5.0 to 5.2 s) | fail ×3 (the text is gone) |
| the cold send reads `opencode.json` with a plain open | fail ×3 (first
key 6.2 to 6.4 s) | fail ×3 (the text is gone) |
| forced: the host starts 120 ms later, delivery is 600 ms slower | fail
×3 both (198 to 208 ms; 2115 to 2217 ms) | pass ×3 both |
| forced: one CPU, whole files ×2 | PTY pass, FIFO fail ×2 (2009, 2023
ms) | pass ×2 both |
| the server opens the FIFO without waiting and refuses it | pass ×2 |
fail ×2 (by design) |

## Validation

Ran:

- In the CI runner image (`herdr-ci-runner:local`), three times each, on
8 CPUs: `bun run check run -- env HERDR_TEST_MODE=integration bun test
--timeout 15000 ./server/pty/host.test.ts` (41 pass, 29 skip, 0 fail)
and `bun run check run -- env HERDR_TEST_MODE=integration bun test
--timeout 15000 ./server/opencode.contract.test.ts` (26 pass, 0 fail).
The same two commands twice on one CPU: pass.
- The first command three more times with `crates/pty-sidecar` built
from main (Rust 1.85, musl) in place: 64 pass, 4 skip, 0 fail.
- The mutation and forcing runs of the table above, each test alone
(`-t`).
- On the host: `bun run typecheck`; `bun test --timeout 15000
./scripts/conventions.test.ts ./server/conventions.test.ts
./server/catalog.conventions.test.ts ./src/conventions.test.ts` (63
pass).

- `bun run check fast`: pass on this head (15742 unit tests pass, 0
fail).
- On this head, in the CI runner image: both files three times (67 pass,
0 fail each), and the two changed tests with the Node host made to wait
out the hold and the scan made to read `opencode.json`: both fail, twice
(211.7 and 212.2 ms against 150; the text handed is `""`).
- Checked again on the final diff by the session that opens this PR, in
the CI runner image: both files twice (67 pass, 0 fail each), and the
two changed tests with the Node host made to wait out the hold and the
scan made to read `opencode.json` (both fail, twice: 208.4 and 206.9 ms;
the text handed is `""`). The independent review agent meant for this
change ended on the account's rate limit before it reported, so this
check and a reading of the diff stand in for it.

Skipped:

- `bun run check full`, the rest of the integration suite, the browser
lanes (no UI change).
- Native Windows and macOS: neither file is in those jobs.
- GitHub's "Rust PTY host" job, which runs `host.test.ts` on its own
build: it runs on the PR.

No changelog fragment: tests only, nothing a user notices, as in #3617,
#3604 and #3605.

## Not in this PR

- The Node PTY host holds a command 200 ms, or kills it, when its last
output is read together with the hangup: `printf X; exit 7` is reported
after 242 ms where `exit 7` takes 51 and the Rust host 2, and `printf X;
exec 0<&- 1>&- 2>&-; sleep 0.05; exit 3` is reported as 137 where the
Rust host says 3. The host takes the socket's end of stream for
node-pty's destroy after an exit. It needs its own fix and parity tests.
- The other tests that assert elapsed time under a fixed number. The
tightest are `server/prompt.test.ts:6651` (`< 1_790` over a 1.5 s wait),
the first-key gaps in `server/opencode.contract.test.ts:1102` (`<
1_000`, seen up to 774 ms) and `server/prompt.contract.test.ts:564` (`<
600`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[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