Skip to content

State how a test's held process ends, and refuse SIGKILL in the suite - #1798

Merged
max-sixty merged 5 commits into
mainfrom
test-loop-provenance
Oct 5, 2026
Merged

max-sixty merged 5 commits into
mainfrom
test-loop-provenance

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

#1774 removed the polling loop that held under_codex's fake Codex task, and every SIGKILL in tests/. This change tells the next author the rule that loop broke, and adds a test so the suite rejects SIGKILL again.

The loop came from a tend-ci-fix run that opened #1104. The section "A process the suite starts ends with the run" in tests/AGENTS.md only said which fixture owns each resource. The change did take its process from spawn, and two reviews read that as proof of cleanup: "the fixture closes surviving processes on failure". spawn only ended the runner, though, so its shell survived.

  • tests/AGENTS.md now states the property itself, as checks you can run:
    • Many suite runs share one machine, so a process a test starts ends on every way out of the test. spawn's teardown ends a child and its group on a pass, failure or interrupt. A worker that dies runs no teardown, so a process that would otherwise run on carries its own link to the worker: the session claim for a page server, the worker's pipe for a held process.
    • A held process blocks on a pipe the worker holds, as session_process does. It never polls for a file the test body has yet to write.
    • A test ends a process with SIGTERM or by closing that pipe, never SIGKILL.
    • To check a new held process: make the test fail right after starting it, then run pgrep -fl <tmp_path>. On the pre-End held test processes with their test, and shorten Claude Code title requests #1774 tree that finds the leaked shell; on End held test processes with their test, and shorten Claude Code title requests #1774 it finds nothing.
  • test_no_test_ends_a_process_with_sigkill reads tests/*.py and fails on Popen.kill(), signal.SIGKILL, signal 9 passed to kill, killpg or send_signal, or a shell kill -9 / kill -KILL. Each form planted in a scratch test made it fail, naming the line, and os.kill(pid, 0) still passes.

I scored the guidance with and without the new text:

Scenario Without With
Codex reviewing #1104 in a checkout at its base: flags the leak 4/6 4/6
Those reviews: ask for a pipe hold that ends with the worker (instead of a finally that keeps the poll) 0/4 4/4
Writing a crashed-lease-holder test: avoids SIGKILL 0/3 3/3
Writing a session stand-in: blocks on a worker-held pipe 1/3 3/3
Reviewing a correct pipe-held test: no false process findings clean clean

The guidance doesn't make a reviewer notice the leak more often. What stops it now is #1774's change to spawn; the guidance shapes how the fix is written.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 4 commits October 4, 2026 17:02
PR #1104 held `under_codex`'s fake Codex task with a shell loop polling
every 10 ms for a release file only the test body wrote. A test that
failed first, or a worker that died, left the loop running for good; on
2026-10-04, 154–170 of them ran at once on one Mac at load 200–440.

"A process the suite starts ends with the run" said only which fixture
owns each resource, and the change took its process from `spawn`. Two
reviewers then read that ownership as a guarantee, and one approved the
merge. The section now states the property itself: a process ends on
every way out of its test, including a worker that dies before teardown,
because many runs share one machine. A held process blocks on a pipe the
worker holds, as `session_process` does, never on a file the test has
yet to write, and a test ends a process with SIGTERM or by closing that
pipe, not SIGKILL. It names the check that catches a violation: fail the
test right after the start and look for survivors.

In an A/B on Codex reviewing #1104 in a checkout at its base, the rule
didn't change how often a review caught the leak (4/6 each), but every
review that caught it with the rule asked for a pipe hold (4/4), and
none without it did (0/4; they asked for a `finally` release that keeps
the poll). On Opus, writing a crash-holder test went from SIGKILL in 3/3
runs to SIGTERM in 3/3, and a session stand-in from blocking on a signal
in 2/3 to a pipe in 3/3. A review of a correct pipe-held test drew no
false findings in either arm.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
#1774 took the suite's last three `.kill()` calls out. Nothing stopped
the next one, and nothing at runtime can see which signal a test sent,
so `test_no_test_ends_a_process_with_sigkill` reads `tests/*.py` for
`Popen.kill()`, `signal.SIGKILL`, and a shell `kill -9` or `kill -KILL`.
It passes on the current tree and names the line for each of the three
forms planted in a scratch test. The process-lifetime section of
tests/AGENTS.md cites it beside the rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worker-death guarantee in tests/AGENTS.md is broader than the fixture it recommends. spawn calls _retire only after its yield, during fixture teardown. If a worker exits before teardown, a child such as the sleep 600 process used by test_a_spawned_process_ends_with_what_it_started has no worker-held pipe or other exit link and can keep running. Because the new guidance tells authors to use spawn for child processes, it preserves the cleanup assumption this PR aims to correct. Please either make spawned children end on worker death or scope the guarantee to processes that have a worker-held exit mechanism, and say which kind future tests need.

Comment thread tests/test_interact_layer.py Resolved
…gnal 9

Review on #1798 found two gaps:

- The guidance said a test's process ends when its worker dies, but
  `spawn` ends children only at teardown, which a dead worker never runs.
  The section now says what covers each case: teardown ends a child and
  its group on a pass, failure or interrupt, and a process that would
  otherwise run on after a worker dies carries its own link to the worker,
  the session claim for a page server and the worker's pipe for a held
  process.
- The SIGKILL guard passed `os.kill(pid, 9)`, `os.killpg(group, 9)` and
  `send_signal(9)`. It now flags signal 9 passed to any of them, and still
  passes a liveness probe such as `os.kill(pid, 0)`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit f2faba5 into main Oct 5, 2026
5 checks passed
@max-sixty
max-sixty deleted the test-loop-provenance branch October 5, 2026 06:54
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.

2 participants