Skip to content

fix(ci): make pre-push single-flight runner signal handling portable (Windows SIGHUP crash) - #10151

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
arhxam:fix/preflight-runner-windows-signals
Jul 27, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
arhxam:fix/preflight-runner-windows-signals

Conversation

@arhxam

@arhxam arhxam commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

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:

previous_handlers = {
    signum: signal.signal(signum, forward_signal)
    for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP)
}

signal.SIGHUP is POSIX-only and does not exist on Windows, so merely constructing that tuple raises:

AttributeError: module 'signal' has no attribute 'SIGHUP'
  at preflight_runner.py:183

The wrapper exits 1 and Git rejects the push before any pre-push check runs, forcing Windows contributors onto --no-verify. scripts/pre-push works directly — 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 rather 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 via getattr(signal, name, None), skipping absent signals instead of exploding. POSIX keeps 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 process group and the whole tree is reached — and falls back to child.send_signal() where process groups are unavailable. It now also swallows OSError alongside ProcessLookupError, since killpg can fail with other OS errors against a dying child.

run_owned() becomes:

previous_handlers = {signum: signal.signal(signum, forward_signal) for signum in forwardable_signals()}

Handler restoration and lock cleanup in the finally block are untouched.

Acceptance criteria (#9610)

  • Register only signal constants that exist on the current platform — forwardable_signals()
  • Keep os.killpg process-group forwarding on POSIX — preferred branch in signal_child()
  • Fall back to Popen.send_signal() when os.killpg is unavailable
  • Preserve handler restoration and lock cleanup — finally block unchanged
  • Tests simulate missing SIGHUP and missing os.killpg
  • No dependency changes

The two remaining boxes in #9610 (preflight_runner.py executing on Windows Python, and a real git push completing there) need a Windows host to sign off — I verified the logic by simulating both missing APIs on POSIX.

Tests

Added SignalPortabilityTests to .github/scripts/test_pr_preflight.py (already executed by repo-checks.yml), covering:

  • signal selection with SIGHUP removed — simulating Windows
  • SIGHUP present on POSIX
  • forwarding to the process group when os.killpg exists
  • send_signal fallback when os.killpg is absent
  • a dead child (ProcessLookupError) not raising

Verification

$ python -m unittest test_pr_preflight.SignalPortabilityTests
Ran 5 tests ... OK

# simulating Windows (SIGHUP deleted):
OLD expression      -> AttributeError: module 'signal' has no attribute 'SIGHUP'
forwardable_signals -> ['SIGINT', 'SIGTERM']

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.

@Git-on-my-level Git-on-my-level added workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior needs-maintainer-review Needs a human maintainer to sign off before merge labels Jul 21, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 via os.killpg and falls back to Popen.send_signal() when process groups are unavailable.
  • The new unit coverage exercises missing SIGHUP, missing os.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.py from .github/scripts in a clean environment on this head; all 26 tests passed. The focused SignalPortabilityTests also 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.

@tianmind-studio

tianmind-studio commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Native Windows follow-up: the signal-selection helper in this PR fixes the first SIGHUP exception, but a real hook-driven push still cannot complete on current Windows. After applying this layer I reproduced three subsequent host boundaries:

  • process_exists() uses os.kill(pid, 0); signal 0 is CTRL_C_EVENT on Windows and interrupted the shared console.
  • The extensionless scripts/pre-push cannot be passed directly to native CreateProcess.
  • A bare bash launched from native Python can resolve to C:\Windows\System32\bash.exe instead of the Git Bash already running the hook.

The direct-child send_signal() fallback also cannot contain descendants.

The signal seam itself is useful, but the current Fixes #9610/#9724 scope overstates end-to-end Windows readiness. #10574 carries the host-tested full chain (supported signals, non-destructive PID identity, Git Bash/Python binding, Job Object descendant cleanup, UTF-8 paths, and a native Windows workflow), with all CI green and a positive collaborator review.

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]>
@undivisible
undivisible force-pushed the fix/preflight-runner-windows-signals branch from e405d60 to de1eda4 Compare July 27, 2026 05:06

@tianmind-studio tianmind-studio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) reaches child.send_signal(signal.SIGINT) when os.killpg is unavailable. Native Windows Popen.send_signal() does not provide POSIX SIGINT semantics 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 mocked send_signal(signal.SIGTERM) call, so it does not cover the failing SIGINT path or real Windows Popen behavior. 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 uses os.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/#9724 fix.

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.

@kodjima33 kodjima33 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.

Verified against #9724/#9610: preflight_runner.py still hard-codes signal.SIGHUP on main, which does not exist on Windows and crashes the pre-push hook; the fix filters to the signals the platform actually has.

@kodjima33
kodjima33 merged commit f630fe2 into BasedHardware:main Jul 27, 2026
27 checks passed
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-push single-flight runner crashes on Windows without SIGHUP fix(ci): make pre-push preflight portable on Windows

4 participants