Repository navigation
fix(ci): make pre-push single-flight runner signal handling portable (Windows SIGHUP crash) - #10151
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the focused fix — this looks like the right shape for the Windows SIGHUP crash in the pre-push single-flight runner.
What I checked:
forwardable_signals()avoids importing/registering signal constants that the host Python does not define, so Windows should no longer fail before the pre-push checks start.signal_child()keeps POSIX process-group forwarding viaos.killpgand falls back toPopen.send_signal()when process groups are unavailable.- The new unit coverage exercises missing
SIGHUP, missingos.killpg, POSIX process-group forwarding, and dead-child handling without sending real signals to the test process. - I ran
python -m unittest test_pr_preflight.pyfrom.github/scriptsin a clean environment on this head; all 26 tests passed. The focusedSignalPortabilityTestsalso passed separately.
I’m leaving this as a positive maintainer signal rather than a formal approval because it changes repo hook/CI tooling under .github/scripts, so a human maintainer should make the final call before merge. I did not find a blocker in the code itself.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Native Windows follow-up: the signal-selection helper in this PR fixes the first
The direct-child The signal seam itself is useful, but the current I recommend either narrowing this PR to the helper-only layer or coordinating it with that complete integration so maintainers do not merge two conflicting partial implementations. |
Fixes BasedHardware#9724. run_owned() built its signal handler map from a hard-coded tuple: previous_handlers = { signum: signal.signal(signum, forward_signal) for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP) } signal.SIGHUP is POSIX-only and simply does not exist on Windows, so merely constructing that tuple raises AttributeError: module 'signal' has no attribute 'SIGHUP' The wrapper exits 1 and git rejects the push before any pre-push check runs. Running scripts/pre-push directly works; only the single-flight wrapper fails. The forwarding callback had the same class of problem: os.killpg is POSIX-only, so a signal arriving on Windows would raise AttributeError instead of stopping the child. Fix: - forwardable_signals() resolves the forward set against the host with getattr(signal, name, None), so absent signals are skipped instead of exploding. POSIX still gets SIGINT/SIGTERM/SIGHUP; Windows gets SIGINT/SIGTERM. - signal_child() prefers os.killpg (the child is started with start_new_session=True, so it leads its own group and the whole tree is reached) and falls back to child.send_signal() where process groups are unavailable. It now swallows OSError as well as ProcessLookupError, since killpg can fail with other OS errors on a dying child. Both seams are module-level so they can be tested without sending a real signal to the test process, as the issue requested. Tests (.github/scripts/test_pr_preflight.py, already run by repo-checks.yml): new SignalPortabilityTests covering signal selection with SIGHUP removed (simulating Windows), SIGHUP present on POSIX, process-group forwarding, send_signal fallback when os.killpg is absent, and a dead child not raising. Verification: the 5 new tests pass; simulating Windows shows the old expression raising "module 'signal' has no attribute 'SIGHUP'" while forwardable_signals() returns ['SIGINT', 'SIGTERM']. The 2 remaining failures in the file are pre-existing and identical before and after this change (they need a full clone). black --check --line-length 120: clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
e405d60 to
de1eda4
Compare
tianmind-studio
left a comment
There was a problem hiding this comment.
Native Windows review on CPython 3.12 found two reproducible blockers in the portability path. A real child passed through signal_child(..., signal.SIGINT) raises ValueError: Unsupported signal: 2, and the focused test class currently reports FAILED (errors=1, skipped=2) on Windows. I included the exact failure sites and focused fixes inline. The SIGHUP selection change itself is sound.
| if killpg is not None: | ||
| killpg(child.pid, signum) | ||
| else: | ||
| child.send_signal(signum) |
There was a problem hiding this comment.
forwardable_signals() registers SIGINT on Windows, but Windows Popen.send_signal() does not accept signal.SIGINT (2); it accepts SIGTERM or the Windows console-control events. On a native Windows Python 3.12 checkout I reproduced this with a real start_new_session=True child: signal_child(child, signal.SIGINT) raises ValueError: Unsupported signal: 2. ValueError escapes this handler, and run_owned()'s finally does not stop the still-running child. Please map interruption to a supported Windows mechanism (and create the needed process group if using a console-control event), or use a deliberate termination fallback, then cover the real Windows signal value rather than only mocked SIGTERM.
|
|
||
| def test_forwarding_swallows_dead_child(self) -> None: | ||
| child = Mock(pid=4321) | ||
| with patch.object(os, "killpg", side_effect=ProcessLookupError): |
There was a problem hiding this comment.
This new portability suite does not pass on the platform it targets. Native Windows has no os.killpg, so patch.object(os, "killpg", ...) raises AttributeError before signal_child() runs. Repro from .github/scripts: py -3 -m unittest test_pr_preflight.SignalPortabilityTests -> 5 tests, 1 error, 2 skipped. Please create/inject the missing callable explicitly (for example create=True) or exercise the platform-neutral seam without assuming the POSIX attribute exists.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for continuing to narrow this. The SIGHUP registration seam is useful, but I think the current head still needs changes before this can be treated as a Windows pre-push fix.
Blocking points I see:
- In the Windows fallback path,
signal_child(child, signal.SIGINT)reacheschild.send_signal(signal.SIGINT)whenos.killpgis unavailable. Native WindowsPopen.send_signal()does not provide POSIXSIGINTsemantics for a child process the way the test mock assumes, so an interrupted hook can still fail instead of cleanly stopping/forwarding. The current test only checks a mockedsend_signal(signal.SIGTERM)call, so it does not cover the failingSIGINTpath or real WindowsPopenbehavior. Please either avoid forwarding unsupported signals in the direct-child fallback, map to a Windows-supported console-control/termination behavior with the right process creation constraints, or otherwise make interruption safe on Windows, with coverage that exercises that path. - The PR still presents this as fixing the end-to-end Windows pre-push hook, but the runner has other native-Windows boundaries that this patch does not address. For example,
process_exists()still usesos.kill(pid, 0), and the actual hook command path still needs to be valid when launched by native Windows Python. If this PR is intended to be a small first layer, please narrow the claims/acceptance wording so maintainers do not merge it as the complete#9610/#9724fix.
I ran the focused SignalPortabilityTests and the full .github/scripts/test_pr_preflight.py suite on Linux at de1eda489f882b2b2a1bce0c912e5db437b32888; both pass locally (5 focused tests, 26 full tests). So the POSIX side looks okay, but the Windows-specific behavior the PR is meant to fix is still under-covered and appears incomplete.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…asedHardware#10151) Fixes BasedHardware#9724. run_owned() built its signal handler map from a hard-coded tuple: previous_handlers = { signum: signal.signal(signum, forward_signal) for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP) } signal.SIGHUP is POSIX-only and simply does not exist on Windows, so merely constructing that tuple raises AttributeError: module 'signal' has no attribute 'SIGHUP' The wrapper exits 1 and git rejects the push before any pre-push check runs. Running scripts/pre-push directly works; only the single-flight wrapper fails. The forwarding callback had the same class of problem: os.killpg is POSIX-only, so a signal arriving on Windows would raise AttributeError instead of stopping the child. Fix: - forwardable_signals() resolves the forward set against the host with getattr(signal, name, None), so absent signals are skipped instead of exploding. POSIX still gets SIGINT/SIGTERM/SIGHUP; Windows gets SIGINT/SIGTERM. - signal_child() prefers os.killpg (the child is started with start_new_session=True, so it leads its own group and the whole tree is reached) and falls back to child.send_signal() where process groups are unavailable. It now swallows OSError as well as ProcessLookupError, since killpg can fail with other OS errors on a dying child. Both seams are module-level so they can be tested without sending a real signal to the test process, as the issue requested. Tests (.github/scripts/test_pr_preflight.py, already run by repo-checks.yml): new SignalPortabilityTests covering signal selection with SIGHUP removed (simulating Windows), SIGHUP present on POSIX, process-group forwarding, send_signal fallback when os.killpg is absent, and a dead child not raising. Verification: the 5 new tests pass; simulating Windows shows the old expression raising "module 'signal' has no attribute 'SIGHUP'" while forwardable_signals() returns ['SIGINT', 'SIGTERM']. The 2 remaining failures in the file are pre-existing and identical before and after this change (they need a full clone). black --check --line-length 120: clean. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Fixes #9724.
Fixes #9610.
Problem
The installed pre-push hook routes through
.github/scripts/preflight_runner.py.run_owned()builds its signal handler map from a hard-coded tuple:signal.SIGHUPis POSIX-only and does not exist on Windows, so merely constructing that tuple raises:The wrapper exits 1 and Git rejects the push before any pre-push check runs, forcing Windows contributors onto
--no-verify.scripts/pre-pushworks directly — only the single-flight wrapper fails.The forwarding callback had the same class of problem:
os.killpgis POSIX-only, so a signal arriving on Windows would raiseAttributeErrorrather than stopping the child.Fix
Two module-level seams, so both are testable without sending a real signal to the test process:
forwardable_signals()resolves the forward set against the host viagetattr(signal, name, None), skipping absent signals instead of exploding. POSIX keepsSIGINT/SIGTERM/SIGHUP; Windows getsSIGINT/SIGTERM.signal_child()prefersos.killpg— the child is started withstart_new_session=True, so it leads its own process group and the whole tree is reached — and falls back tochild.send_signal()where process groups are unavailable. It now also swallowsOSErroralongsideProcessLookupError, sincekillpgcan fail with other OS errors against a dying child.run_owned()becomes:Handler restoration and lock cleanup in the
finallyblock are untouched.Acceptance criteria (#9610)
forwardable_signals()os.killpgprocess-group forwarding on POSIX — preferred branch insignal_child()Popen.send_signal()whenos.killpgis unavailablefinallyblock unchangedSIGHUPand missingos.killpgThe two remaining boxes in #9610 (
preflight_runner.pyexecuting on Windows Python, and a realgit pushcompleting there) need a Windows host to sign off — I verified the logic by simulating both missing APIs on POSIX.Tests
Added
SignalPortabilityTeststo.github/scripts/test_pr_preflight.py(already executed byrepo-checks.yml), covering:SIGHUPremoved — simulating WindowsSIGHUPpresent on POSIXos.killpgexistssend_signalfallback whenos.killpgis absentProcessLookupError) not raisingVerification
Full file: 26 tests, with 2 pre-existing failures that are identical before and after this change (they require a full clone; my sandbox used a shallow sparse checkout).
black --check --line-length 120→ clean, matching the pinned CI formatter.🤖 Generated with Claude Code
Failure class
Failure-Class: none
Windows-only signal API portability in a repo tooling script; no registered class covers host-API availability in the pre-push runner.