Skip to content

Pass Over a Signal Handled as the Prose Gate's First Handler Starts - #4453

Merged
ptr727 merged 2 commits into
developfrom
burndown/prose-gate-signal-order
Nov 25, 2026
Merged

ptr727 merged 2 commits into
developfrom
burndown/prose-gate-signal-order

Conversation

@ptr727

@ptr727 ptr727 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

The prose gate's interrupt test once saw the gate exit by SIGTERM after a back-to-back SIGINT and SIGTERM (#4429). The cause is in the gate's handler, not the test's delivery.

Cause

CPython runs a Python signal handler from its pending-signal check, and checks again at that handler's own first instruction. So a SIGTERM whose C-level trip lands after the check that started on_signal(SIGINT) runs on_signal(SIGTERM) nested inside it, before the SIGINT is recorded. The nested call receives the outer handler's frame as frame. It finds received empty, records SIGTERM, and raises. The SIGINT handler never reaches its own line. Where both signals are pending at one check, CPython takes them in signal-number order, so SIGINT wins. That is why the failure needs the narrow window above and shows only now and then.

Fix

  • on_signal returns when the frame it interrupted is its own (frame.f_code is on_signal.__code__), so the handler already running records its signal. The first signal decides, as CODESTYLE.md "Interrupts in Python" states.
  • A new test, test_a_signal_handled_as_the_first_handler_starts_is_passed_over, makes the nested call at the same point with a sys.setprofile hook, so the order is fixed rather than raced. It fails on develop's gate ([SIGTERM] != [SIGINT]) and passes with this fix.
  • The test's stubbed git call now sleeps in 0.05-second steps instead of one 60-second sleep. A signal tripped after the interpreter's last check but before a long sleep starts waits that sleep out. Under load that ran the stub into the test's own 60-second timeout. This is a second, test-only flake the stress runs below found.

Evidence

All runs were local, on CPython 3.13 on Linux, each under setsid --wait timeout, with pgrep confirming that no process survived.

  • A mirror of the handler logged the frame each call interrupted. Under 64 busy loops it reproduced the CI signature 2 times in 1,440 trials. Each time the SIGINT handler was called first, interrupting <module>. The SIGTERM handler then ran on the on_signal frame and recorded itself.
  • The real gate, run through the test's own launcher, was swept over a 0 to 400 microsecond gap between SIGINT and SIGTERM. On develop's gate, 21 of 2,560 runs died by SIGTERM. With this fix, 0 of 2,560 did.
  • In the mirror, 3 of 1,440 runs held a signal until the 60-second sleep ended. A stack dump showed the child still in time.sleep, with neither handler called yet.
  • With both commits, the interrupt test class passed 640 of 640 runs under 64 busy loops. The full test_prose_lint module passes.

Pre-existing findings, filed

Closes on promotion: #4429

🤖 Generated with Claude Code

ptr727 and others added 2 commits November 25, 2026 14:25
Python checks for pending signals as a function starts. A SIGTERM landing just after the
SIGINT's handler was called therefore ran its own handler on that handler's frame, before the
SIGINT was recorded, and the gate reported SIGTERM. The handler now returns when the frame it
interrupted is its own, so the first signal decides. A profile-hook test pins the order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A signal tripped after the interpreter's last check but before a long sleep starts waits for that
sleep to end. Under load that left the stub sleeping out its 60 seconds into the test's own
timeout. Short sleeps bound that wait to one of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings November 25, 2026 22:32
@ptr727

ptr727 commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 8b75779f46fddf7c5f3bee7efa64487fa11ab8d8, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e5573a9 and 8b75779.

Files selected for processing: 2

  • .github/actions/prose-gate/prose_lint.py
  • tests/test_prose_lint.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI 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.

🟢 Approval recommended

The changes address the signal-ordering issue with a guard and add deterministic regression coverage, with no active review issues identified.

No open issues 🎉

What changed in this PR

This PR fixes signal ordering in the prose gate so the first signal remains authoritative when a later handler starts during its execution, and makes the interrupt test less timing-sensitive.

Changes:

  • Guard nested signal-handler calls using the interrupted frame.
  • Add deterministic regression coverage for nested signal delivery.
  • Replace the test stub's single long sleep with short intervals.
File Description
tests/​test_prose_lint.py Adds deterministic nested-handler coverage and replaces the long stub sleep with interruptible intervals.
.github/​actions/​prose-gate/​prose_lint.py Prevents nested signal handling from replacing the first recorded signal.

Review effort: Lite

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.62%. Comparing base (b38e084) to head (8b75779).
⚠️ Report is 347 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4453      +/-   ##
===========================================
- Coverage    81.60%   79.62%   -1.99%     
===========================================
  Files           26       47      +21     
  Lines         9070    16398    +7328     
===========================================
+ Hits          7402    13057    +5655     
- Misses        1668     3341    +1673     
Flag Coverage Δ
python-3.13 79.62% <ø> (-1.99%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit e9cf79a into develop Nov 25, 2026
15 checks passed
@ptr727
ptr727 deleted the burndown/prose-gate-signal-order branch November 25, 2026 22:53
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