Repository navigation
test(check): the zombie fixture's parent cannot miss its child's exit - #3605
Conversation
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]>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Local merge gate: PASS
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
Reruns:
Total 632s. |
Merge passMerged head
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. |
…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]>
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
ZOMBIEfrom itsSIGCHLDhandler; then it waits inpause(). 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. ASIGCHLDthat lands after the last look and beforepause()is noted and not acted on, andpause()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 reachpause(), so the two meet.What
The parent blocks
SIGCHLDbefore the fork and waits withsigsuspend(), 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
main's fixture, 3000 runs, 12 at once on 12 CPUs, unforced (CI runner image, perl 5.38.2)ZOMBIE; in all 5 the child was a zombie by thenmain's test with the gap between the last look for signals andpause()made long (the same statement builds a 30-million-item list first; scratch patch)0 pass, 1 failsigsuspend()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.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