Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Problem
Fleet Python and shell scripts do not handle an interrupt. A Ctrl-C (SIGINT) or a SIGTERM partway through a run aborts it where it stands:
- Python prints a
KeyboardInterrupttraceback, and a SIGTERM kills the process with no unwinding at all. - Temporary files, partial outputs, lock files, and child processes stay behind.
- A multi-step write can stop between steps, leaving state that is neither the old nor the new.
Nothing in CODESTYLE.md asks for interrupt handling, so each script gets whatever its default is.
A constructed example of the failure:
$ ./scripts/rebuild_index.py --root ./data
Scanning 4,000 files...
^CTraceback (most recent call last):
File "./scripts/rebuild_index.py", line 88, in <module>
main()
...
KeyboardInterrupt
$ ls ./data
index.db index.db.tmp .rebuild.lock
The .tmp and .lock files stay, and the next run refuses to start or reads a half-written index.
Proposed standing rule
Every fleet shell and Python script handles SIGINT and SIGTERM as an orderly stop. As far as can be helped, it never leaves things undefined mid-run:
- Unwind and clean up. Remove temporary files, release locks, and stop the child processes the script started. Leave persistent state either unchanged or fully committed, never half-written. A write that must be atomic writes to a temporary path and renames it.
- Report briefly, with no traceback. Print one line naming the interruption and what was or was not completed, then exit with the conventional status: 130 for SIGINT, 143 for SIGTERM.
- Python: route both signals into one shutdown path, for example by converting SIGTERM into the same exception as
KeyboardInterrupt. Clean up infinallyblocks or context managers rather than at each call site. Catch the interrupt once, at the entry point, and don't swallow it deeper down. - Shell:
trapcleanup onEXITtogether withINTandTERM, consistent with theset -Eeuo pipefailheader the shell rules already require. The trap kills the children the script started and exits with the signal's status. - One shared helper, per GOVERNANCE.md "Design Before Code". Where more than one script needs the same handling, it lives in one helper rather than in each script.
Where it lives
CODESTYLE.md: a General subsection, next to "Operations and Failure Messages", stating the language-neutral rule. The Python and Shell sections then state each language's mechanics.- The
python-codestyleandshell-codestyleSkills pick it up through their generated includes. Rebuild withscripts/build_dist.py. - The hub's own
scripts/are the first adopters, and downstream repositories get it on their next resync.
Scope
Bash and Python utility scripts only. The fleet has no .NET scripts, and its .NET console apps already handle termination (maintainer, 2026-11-09).
Open question for the maintainer
- Should a test prove it, by sending a script a signal mid-run and asserting a clean exit and no leftovers, or is the review checklist enough?
Raised by the maintainer on 2026-11-08.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
ptr727 commentedon Nov 10, 2026
Researched question (decision triage, 2026-11-10).
Should fleet shell and Python scripts handle SIGINT and SIGTERM in an orderly way? If so, what does the rule say, and where does it live?
CODESTYLE.mdGeneral (recommended). Add an "Interrupts" subsection after "Operations and Failure Messages", with the mechanics in the Python and Shell sections. On SIGINT or SIGTERM a script releases what it holds: temp paths, locks, and children it started. It leaves persistent state either old or new, by temp path plus rename. It prints one line naming the signal, with no traceback, and exits 130 or 143. Shell does cleanup in theEXITtrap the fleet already uses, addingINTandTERMtraps only to stop children and keep the status. Python catches the interrupt once at the entry point and maps SIGTERM onto the same path. A script takes the rule when created or next edited, with no retrofit sweep. Only a script holding a lock, temp state, or children owes a signal-mid-run test. The interrupt line makes no claim about what completed, sinceCODESTYLE.md:36already forbids a failure message claiming the state it left.Evidence:
CODESTYLE.md:32-36and:101,host-setup/menu.sh:357and:724,host-setup/bootstrap.sh:507, thetrap ... EXITpattern inhost-setup/linux/*.sh, andscripts/docker_lint.py:559, the only Python SIGTERM handler. No 130 or 143 exit appears onmain.Blocks: none.
ptr727 commentedon Nov 10, 2026
Answered by the maintainer, 2026-11-10: option 1, a narrowed rule.
CODESTYLE.mdGeneral, after "Operations and Failure Messages", with the mechanics in the Python and Shell sections.EXITtrap.INTandTERMtraps are added only to stop children and keep the status.This is now work.
build_dist.pyregenerates thepython-codestyleandshell-codestyleskills from the change.ptr727 commentedon Nov 11, 2026
Backlog burndown claim, round 3 (2026-11-11). Branch
feature/codestyle-interrupts, group: #3947.Predicted files:
CODESTYLE.md.agents/skills/python-codestyle/SKILL.md.github/skills/python-codestyle/SKILL.md.claude-plugin/fleet-skills/skills/python-codestyle/SKILL.md.claude-plugin/fleet-skills/.source-digests/python-codestyle.agents/skills/shell-codestyle/SKILL.md.github/skills/shell-codestyle/SKILL.md.claude-plugin/fleet-skills/skills/shell-codestyle/SKILL.md.claude-plugin/fleet-skills/.source-digests/shell-codestyleGrown by adjudication, 2026-11-11 (the Shell subsection is the file's last heading, and the generator carries trailing link definitions into its include):
scripts/build_dist.pytests/test_build_dist.pyRequire Orderly SIGINT and SIGTERM Handling in Shell and Python Scrip…
ptr727 commentedon Nov 11, 2026
Released (2026-11-11): #4086 merged and its branch is deleted, so this claim holds no files.
Backlog burndown claim, round 3 promotion fix (2026-11-11). Branch
feature/promotion-4083-review-fixes, fixing review findings on promotion #4083.Predicted files:
CODESTYLE.mddocs/repo-config.mdrepo-config/README.mdrepo-config/configure.shtests/test_configure_archived.pySTANDUP.mdGOVERNANCE.mdscripts/build_dist.pytests/test_build_dist.pyspec/audit.pytests/test_audit_helpers.py.agents/skills/python-codestyle/SKILL.md.github/skills/python-codestyle/SKILL.md.claude-plugin/fleet-skills/skills/python-codestyle/SKILL.md.claude-plugin/fleet-skills/.source-digests/python-codestyle.agents/skills/shell-codestyle/SKILL.md.github/skills/shell-codestyle/SKILL.md.claude-plugin/fleet-skills/skills/shell-codestyle/SKILL.md.claude-plugin/fleet-skills/.source-digests/shell-codestyleGrown by adjudication, 2026-11-11:
spec/fidelity_text.pytests/test_fidelity_text.py.agents/skills/branching-and-release-model/references/branch-protection-and-promotion.md.github/skills/branching-and-release-model/references/branch-protection-and-promotion.md.claude-plugin/fleet-skills/skills/branching-and-release-model/references/branch-protection-and-promotion.md.claude-plugin/fleet-skills/.source-digests/branching-and-release-model