Skip to content

golive: un-flake rehearse's "server dying mid R4" test - #1181

Merged
scuttletoby merged 1 commit into
mainfrom
fork/unflake-rehearse-die-r4
Nov 28, 2026
Merged

scuttletoby merged 1 commit into
mainfrom
fork/unflake-rehearse-die-r4

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

The flake

fork-kit/golive/tests/rehearse.test.py Rehearse.test_a_server_dying_mid_r4_fails failed on main (Fork tests run 46087858969, "Fork kit tests 1") with AssertionError: Failed not raised. That commit changed nothing under fork-kit/golive/.

Root cause

In dieInReport mode the stub t3's __fork-report sends SIGKILL to the server and returns immediately. rehearse.py then calls server.poll() right after reading the report. A kill is only queued. On a busy runner the server can still be exiting at that point, so poll() returns None, rehearse sees a live server, and no R4 problem is raised.

Fix (test fixture only)

The stub now returns only after the killed server is a zombie or gone (it reads /proc/<pid>/stat, with a 30 s cap). That matches what the test means: "a server that died during the checks". rehearse.py is unchanged.

Proof

I ran the single test 20 times, pinned to one core with 3 busy loops on that core:

  • before: 5/20 failed
  • after: 0/20 failed

The whole file passes locally: 100 tests, ~57 s. Its runtime is unchanged, so .github/fork-ci-tests.txt needs no update. I also ran the schema, upstream-files and seam checks locally, and all three pass.

🤖 Generated with Claude Code

The stub's __fork-report SIGKILLed the server and returned at once. A kill
is only queued: on a busy runner the server was still exiting when
rehearse polled it right after the report, so poll() said "running" and
the test saw no failure ("Failed not raised", seen on main).

The stub now returns only once the server is a zombie or gone, as a
server that died during the checks is. Under single-core contention the
test failed 5 of 20 runs before and 0 of 20 after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 (lens sub-agent) · read at: 26c25c5

blocker: none
major: none
minor: the wait could use os.pidfd_open + select (Linux 5.3+, Python 3.9+) and drop the /proc text parsing and the 10 ms loop. Optional; the current loop is correct.

What I checked

  • Can the wait hang? No. It stops after 30 s at most. live.fork_report gives the report 120 s (REPORT_TIMEOUT), so even a kill that never lands ends as a normal test failure, not a hang or a timeout error. On a system without /proc, the first open raises FileNotFoundError, so the loop breaks at once (the old behaviour). CI is ubuntu-24.04, and rehearse needs Linux anyway (PR_SET_PDEATHSIG).
  • Does the loop really end? Yes. The server is a Popen child of the rehearse process, and nothing in fork-kit/golive reaps it early: no waitpid(-1), no SIGCHLD handler, and subprocess._cleanup only touches Popen objects that were garbage-collected. While _report blocks, the killed server stays a zombie, so /proc/<pid>/stat shows Z. The pid can't be reused while the zombie is unreaped, so the loop can't watch a different process. The parse rsplit(')', 1)[1].split()[0] is safe for a comm that contains ). A process that disappears mid-read raises ProcessLookupError (ESRCH), and that case is caught.
  • Does it hide a rehearse.py bug? No. run_rehearse checks server.poll() right after _r4(cfg, before, _report(p)). In the test, "died during the checks" means "dead when the report returns". The old stub returned while the SIGKILL was only queued, and that does not match a server that has died. A real t3 __fork-report never kills the server. A real crash shows the same race only when it happens at the very moment the report returns, and then it really did happen after the checks.
  • Should rehearse.py tolerate a server that is still exiting? No. It would need a guessed sleep after the report, which slows every rehearsal and only moves the race. One possible later step, not needed for this PR: also flag a server whose _stop exit is not the clean SIGTERM exit, to catch a death between poll() and terminate(). That needs the real t3's SIGTERM exit code pinned first, so I am not raising it as a finding.
  • Tests: the change is the test fixture itself. The PR body's 5/20 failures before vs 0/20 after, under CPU pinning with busy loops, is the right kind of proof for a race. I did not rerun it, because I had no suspected bug to prove.

State question. Runs again: each test has its own temp root, and the wait only reads /proc, so a rerun behaves the same. Stops half-way: if the stub is killed during the wait, rehearse gets a failed or partial report and raises Failed, and the finally still runs _stop on the server. Existing, old or empty state: a server that has already gone makes os.kill raise, which is unchanged from before. A missing /proc entry ends the wait at once.

🤖 Generated with Claude Code

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Nov 28, 2026
@scuttletoby
scuttletoby merged commit 8912ebd into main Nov 28, 2026
27 checks passed
scuttletoby added a commit that referenced this pull request Nov 28, 2026
The stub's __fork-report SIGKILLed the server and returned at once. A kill
is only queued: on a busy runner the server was still exiting when
rehearse polled it right after the report, so poll() said "running" and
the test saw no failure ("Failed not raised", seen on main).

The stub now returns only once the server is a zombie or gone, as a
server that died during the checks is. Under single-core contention the
test failed 5 of 20 runs before and 0 of 20 after.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@scuttletoby
scuttletoby deleted the fork/unflake-rehearse-die-r4 branch November 29, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant