Repository navigation
Description
Problem
A Python script whose SIGINT and SIGTERM handler follows CODESTYLE.md "Interrupts in Python" can die by the later signal instead of the first one.
CPython runs a Python signal handler from its pending-signal check, then checks again at that handler's first instruction. So a SIGTERM that trips after the check which 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 process then reports "interrupted by SIGTERM" and dies by SIGTERM, where the rule says the first signal decides. The input that reaches it is a SIGTERM sent within microseconds of a SIGINT, which is the SIGTERM uv run forwards to a process group a Ctrl-C already reached.
The prose gate had this defect (#4429). The pull request fixing it there guards the handler with frame is not None and frame.f_code is on_signal.__code__, and pins the order with a sys.setprofile test. It found the same handler body, if received: return, at these other sites, which it did not touch:
scripts/pr_review.py:2174scripts/canonical_review.py:1168scripts/backlog_metrics.py:1294scripts/docker_lint.py:377scripts/secrets_sync.py:1663catalog/snippets/hub_fetch_run.py:193host-setup/agent-safety/global_rules.py:319, which needs the maintainer's approval to changehost-setup/agent-safety/claude/install.py:2441, which needs the maintainer's approval to change
The rule text is the class's source. CODESTYLE.md "Interrupts in Python" (line 125) states only that the handler "returns at once on any later one", so a script written from it carries the race. The python-codestyle Skill carries that section as a generated include, so it changes when the rule does.
Evidence
On develop's gate, a sweep of the gap between SIGINT and SIGTERM from 0 to 400 microseconds ended 21 of 2,560 runs by SIGTERM. With the guard, 0 of 2,560 did. A copy of the handler that logs the frame each call interrupted showed the nested call running on the on_signal frame.
Done looks like
- The rule states the guard, or a shared primitive the scripts reach.
- Each site above takes it, with the two agent-safety sites only once the maintainer approves.
Activity
ptr727 commentedon Nov 25, 2026
Decision needed (away-mode backlog burndown, 2026-11-25, round 1 refill planner)
This issue's "Done looks like" names two forms without choosing one, and no committed rule chooses between them. So the away run holds it rather than guessing, and labels it
decision.Question 1: Where does the guard live?
CODESTYLE.md"Interrupts in Python" states the guard, and each site carries it inline (recommended). The handler returns at once when the frame it interrupted is the handler's own,frame is not None and frame.f_code is on_signal.__code__, as well as when a signal is already recorded. The sites share no module.catalog/snippets/hub_fetch_run.pyis carried byte-identical to downstream roots, and the agent-safety installers run standalone. A downstream script written from the carried rule can import nothing from the hub either. So only the rule reaches every site. Thepython-codestyleSkill's generated include follows the rule.scripts/. But it reaches onlyscripts/.hub_fetch_run.py, the two agent-safety sites, and every downstream script still need the inline form, so the fleet would hold two forms of one handler.Question 2: Do you approve the same guard at the two agent-safety sites,
host-setup/agent-safety/global_rules.pyandhost-setup/agent-safety/claude/install.py? An away run holds every edit there whatever the answer. An approval recorded here lets an attended run implement it, and the merge still waits on your go-ahead after reading that diff.Effect on the work: under either option, the part outside
host-setup/agent-safety/becomes ordinary work. It predicts more than four files, so it forms a group of its own. Two of its files are held now.CODESTYLE.mdis held by group C onburndown/codestyle-ps-suppress-pycheck(#4403, #4407).scripts/docker_lint.pyis held by the parked #1727 group onburndown/docker-lint-digest-pins.scripts/pr_review.pyis at 2196 lines against its size ceiling, so its edit has to stay within it.Pass Over a Signal Handled as the Prose Gate's First Handler Starts (#…
Pass Over a Signal Handled as the Hook Enabler's First Handler Starts (…
Promote Develop to Main: Python Line Selector, Docker Lint Digest Pin…
ptr727 commentedon Nov 26, 2026
Triage question, 2026-11-26.
Where does the nested-signal guard live, and do you approve it at the two agent-safety sites? A Python handler written from
CODESTYLE.md"Interrupts in Python" returns at once only when a signal is already recorded. CPython can run a second handler call at the first instruction of the first one, before it records anything. So a SIGTERM arriving microseconds after a SIGINT, the oneuv runforwards to a process group a Ctrl-C already reached, wins, and the script dies by the later signal. #4453 fixed the prose gate and #4500 fixedscripts/enable_hooks.py, each withif received or (frame is not None and frame.f_code is on_signal.__code__)and asys.setprofiletest. Both are onmain. The rule text still states only "returns at once on any later one", so every script written from it carries the race. Eight sites still carry the old body. Two are underhost-setup/agent-safety/, which needs your approval. No committed rule chooses between a rule-stated inline guard and a shared primitive.Options:
CODESTYLE.md"Interrupts in Python" adds the frame test beside the recorded-signal test. Thepython-codestyleSkill's generated include follows.scripts/pr_review.py,scripts/canonical_review.py,scripts/backlog_metrics.py,scripts/docker_lint.py,scripts/secrets_sync.py, andcatalog/snippets/hub_fetch_run.pytake it as ordinary work, each with the order test Pass Over a Signal Handled as the Prose Gate's First Handler Starts #4453 and Pass Over a Signal Handled as the Hook Enabler's First Handler Starts #4500 used.host-setup/agent-safety/global_rules.pyandhost-setup/agent-safety/claude/install.pytake it in an attended run, and that merge waits on your reading the diff. Only the rule reaches every site, since the snippet is carried byte-identical downstream, the agent-safety installers run standalone, and a downstream script can import nothing from the hub. The two earlier fixes already use this form.scripts/pr_review.pyis at 2196 of its 2200 lines, so its edit must fit the ceiling.host-setup/agent-safety/proceeds as in option 1. The two installers keep the race, which costs at most a wrong signal named on an interrupted install, and they then disagree with the rule they are written to.scripts/, which the rule names. One copy of the guard for the hub scripts. It reaches onlyscripts/. The snippet, the agent-safety installers, the prose gate, and every downstream script still need the inline form, so the fleet holds two forms of one handler.Evidence: #4452 body and the 2026-11-25 owner comment holding it. #4429, fixed by #4453 and closed on promotion by #4485. #4500. On
main,.github/actions/prose-gate/prose_lint.pyandscripts/enable_hooks.pycarry the guard and the eight sites above still readif received:.CODESTYLE.md"Interrupts in Python" onmain. The holds that comment named onCODESTYLE.mdandscripts/docker_lint.pyhave cleared, since #4403, #4407, and #1727 are closed and no open pull request touches either file.ptr727 commentedon Nov 26, 2026
Maintainer's answer, 2026-11-26 triage: option 1. CODESTYLE.md "Interrupts in Python" states the nested-signal guard, and every remaining site gets it inline. That includes the two installers under
host-setup/agent-safety/, which this answer approves as a design. Merging still waits on the maintainer's go-ahead after reading the diff, so an away run holds the agent-safety part.Guard Every Signal Handler Against a Nested Later Signal and Refuse a…