Skip to content

Clean up POSIX verification subprocesses on SIGTERM - #4975

Merged
Mister-Meeseeks merged 3 commits into
CrocSwap:mainfrom
JoyboyBrian:brian/posix-sigterm-cleanup
Oct 23, 2026
Merged

Mister-Meeseeks merged 3 commits into
CrocSwap:mainfrom
JoyboyBrian:brian/posix-sigterm-cleanup

Conversation

@JoyboyBrian

@JoyboyBrian JoyboyBrian commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

SIGTERM sent to either POSIX verification owner can terminate the owner while its separately grouped module and solver keep running. A readiness-controlled baseline fixture observes both descendants still alive after owner exit -15. Existing timeout and KeyboardInterrupt cleanup do not run for default SIGTERM.

This change temporarily handles default SIGTERM during main-thread calls to research_package.run_command and run_isolated_tests.run_modules, then uses their existing process-group cleanup. A normal handled termination exits 143, restores the previous handler and never reports verification success. The registered path covers Python replay and optional dependency-install commands; the isolated path retains result order and queued-work cancellation. Custom/ignored handlers, worker-thread invocation and Windows ownership retain their existing behavior.

Launch/assignment and cleanup only record pending termination. Asynchronous cancellation is permitted only inside a wait protected by an inner finally. A signal before Popen returns therefore cannot lose its spawned handle; the isolated workers retain the existing launch/registration lock. Repeated SIGTERM cannot interrupt cleanup. If an ordinary exception has already entered cleanup, the first SIGTERM is deferred and the original exception remains the failure. This closes a distinct cancellation boundary beyond #2625/#2676, #2906, #4683 and #4779. Detached sessions and SIGKILL remain outside scope.

Validation on macOS 27 arm64 / CPython 3.12.2:

  • Eleven new methods / twenty real-process fixtures pass normally and with the actual owner interpreter optimized (13.742 s / 13.660 s). Native kqueue exit observations precede independent fixture teardown. Coverage includes both entry points, launch races, queue cancellation, repeated signals, ordinary completion and exceptional cleanup, handler preservation/restoration, and worker-thread calls.
  • The exception-cleanup fixture holds two isolated process groups/four observed processes, injects an ordinary failure, then sends the first SIGTERM from the first cleanup call. Every group exits and the original failure survives. A parent-only cleanup mutation is rejected for both owners.
  • Five existing focused unittest groups: 71 passes / 30 platform skips (101 total). Optimized isolated/registered-bytecode/onboarding compatibility: 61 passes / 23 skips (84 total).
  • Complete unchanged isolated-test-bytecode and isolated-descendant-bytecode registered hooks pass in 7.995 s / 24.085 s. The standalone copied-runner boundary remains supported; no new helper import is required.
  • git diff --check passes. Three meaningful commits retain the regression, root repair and scope/evidence note; every author and committer is JoyboyBrian.

The new test_research_posix_sigterm.py is included by existing Ubuntu onboarding CI. At exact head 7cffe39596aae05003391f22a4a9c452501b27ae, Ubuntu onboarding job120251366422 passed on Ubuntu 24.04.5 / CPython 3.12.15: all eleven new SIGTERM methods passed with native pidfd lifetime observations, and the complete onboarding suite passed 373 tests with eleven platform skips. The downstream full archive CI remains unverified. Changing shared scripts/research_package.py makes the actual planner select all 2,851 opted-in packages at this base; those historical/scientific packages were not replayed locally. The separately inspected isolated-runner-successor metadata still rejects its unchanged historical certificates/selected-result.json pin before replay. No frozen pin, acceptance list, selected record or mathematical claim is changed, and full archive CI is not claimed green.

Base: canonical b91956876e5b4122fd89179f1b57557ff8378f15, priority revision 7. Exact commands, source hashes, signal/exit-status contract and open obligations are in docs/research/posix-sigterm-cleanup.md. Canonical claim and investigation.

Entry overlap checkpoint: complete 317 open PRs at 2026-10-23 04:46:31 UTC, 4,064 Discussion records at 04:47:21 UTC, and all 6,636 local notes. The portable-replay card and explicit runner/export/SIGTERM/cancellation terms found credited predecessors, but no matching default-SIGTERM repair in this coverage. Offline-staleness and unreviewed-discussion limitations remain; final submission refresh is recorded separately.

Credit Paul Romeo, yssite, ywz65, Nick Petalas, Mihir Srivastava, Douglas Colkitt and retained lifecycle/source contributors. Prepared by JoyboyBrian with substantial OpenAI Codex assistance; author-process agent review is not independent human/formal verification. Apache-2.0. No new kappa or selected-frontier change.

Final submission checkpoint: canonical main refreshed at 04:59 UTC remains b91956876e5b4122fd89179f1b57557ff8378f15; governing guidance and affected inputs are unchanged. Complete refreshed overlap covers 318 open PRs (04:59:29 UTC), 4,077 discussion records (05:00:22 UTC) and 6,636 current-base notes. The scoped SIGTERM query finds only this claim and its index; live Discussion1472 was read again before submission. This coverage does not prove novelty. A separate coordinating Codex review checked the production diff and documentation, including an exceptional-cleanup race which is covered by the final regression.

CI follow-up for exact head 7cffe39596aae05003391f22a4a9c452501b27ae: archive CI is failing and unfinished. The frozen 2026-10-23 05:35:17 UTC snapshot contained 257 currently emitted checks: 38 successful, 11 failed, 208 pending. This is not completion of all 2,851 selected packages. The Ubuntu plan job passed all eleven new SIGTERM methods; its full onboarding group ran 373 tests with 11 skips on Ubuntu 24.04.5 / CPython 3.12.15.

Each of the eleven failed logs in that frozen snapshot was inspected and compared with exact canonical base b91956876e5b4122fd89179f1b57557ff8378f15:

Inspected failed job Actual failure Limited baseline evidence
archive-2979-receipt docs/research/pr-intake-decisions.json Exact-base and head --check-only: same rejection
alternation-lemma certificates/selected-result.json Exact-base and head --check-only: same rejection
alternating-shear-exchange certificates/selected-result.json Exact-base and head --check-only: same rejection
affine-mixed-four-targets-seed5638 certificates/selected-result.json Exact-base and head --check-only: same rejection
address-operator-composition certificates/selected-result.json Exact-base and head --check-only: same rejection
adaptive-witness-retune package-local selected-result hash guard Metadata passes both; exact-base source-only guard reproduces CI exception
a5-conjugate-any-registers package-local selected-result hash guard Metadata passes both; exact-base source-only guard reproduces CI exception
a5-conjugate-5cycle-seedd316f8 certificates/selected-result.json Exact-base and head --check-only: same rejection
archive-2980-2981-receipt docs/research/pr-intake-decisions.json Exact-base and head --check-only: same rejection
bidirectional-connector package-local selected-result hash guard Metadata passes both; exact-base source-only guard reproduces CI exception
basis-gap-minimum certificates/selected-result.json Exact-base and head --check-only: same rejection

The eight metadata failures reproduce with the original base scripts/research_package.py, base package metadata and base source bytes, using --check-only. For adaptive-witness-retune, a5-conjugate-any-registers and bidirectional-connector, --check-only passes at both revisions; their own unchanged verifier/caller separately treats historical selected-result provenance as a live hash. Executing only those exact source-authentication guards from the base reproduces their logged exceptions. Their scientific routines were not rerun locally. All eleven relevant verifier/caller and metadata files, and both mismatched source targets, are byte-identical between base and this PR. These eleven inspected causes therefore predate this change; pending or subsequently completed archive jobs have not been triaged. No full archive success or baseline scientific replay is claimed. Frozen pins remain unchanged.

@jwr404

jwr404 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Independent review at head 7cffe39596aae05003391f22a4a9c452501b27ae

Linux run. The package was validated on macOS. On Linux (CPython 3.12.14), tests.test_research_posix_sigterm and tests.test_research_onboarding pass together, 38 tests in 14.3 s. They pass with this PR merged onto #4973, which also edits run_command: the merge is automatic and conflict-free. #4973 changes only the child-environment lines above the POSIX branch.

run_command logic. I checked these interleavings:

  • During handler installation or Popen. A signal sets terminating, because waiting is False. Popen completes, process is assigned, and the explicit if terminating: raise SystemExit(143) then runs the group cleanup. The handle cannot be lost.
  • Between Popen and waiting = True. The signal is deferred and caught by the check inside the inner try, so cleanup runs.
  • During process.wait. The handler raises SystemExit(143). The inner finally resets waiting, and the outer finally kills the group, waits, and restores SIG_DFL.
  • After wait returns, before waiting = False. The handler raises SystemExit(143) from that point and cleanup still runs. Exit is 143 even if the child had succeeded, which matches "never reports verification success".
  • During cleanup. A repeated signal does nothing, since terminating is already set. A first signal during exceptional cleanup is deferred, so the original exception propagates.
  • Not affected. A custom or ignored handler, or a call from a worker thread, leaves the handler untouched, as stated.

I found no defect. This is an author-independent check, not maintainer acceptance. No κ effect.

Reviewed by James Reed with substantial Anthropic Claude (Claude Code) assistance.

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.

3 participants