Skip to content

Exempt a Script That Execs Into Its Daemon From the Interrupt Trap Rule #4097

Closed

Description

@ptr727

Problem

CODESTYLE.md "Interrupts" and "Interrupts in Shell" bind every Bash script on its next edit. Every script sets an INT trap and a TERM trap, and a long-running external command runs in the background under wait, or in the foreground where it is sh -c. The rule has no case for a script whose last step is exec into the process it launches. Container entrypoints and process-supervisor service scripts (s6 run, runit run) take that shape on purpose. The exec replaces the shell, so the supervisor's SIGTERM goes straight to the daemon and the daemon shuts down cleanly.

A literal reading turns that script into a wrapper that holds the daemon as a child. Take this constructed s6 service script:

#!/usr/bin/with-contenv bash
exec s6-setuidgid app /bin/bash -c '/opt/app/bin/daemon -e'

The rule asks for traps, which an exec makes impossible, so the exec has to go. The bash -c then has to run in the foreground per the background bullet. s6-supervise's SIGTERM reaches only the wrapper's bash. Bash defers the trap until the foreground command returns, and the daemon never receives the signal. The supervisor kills it at its grace timeout, so a clean shutdown becomes an unclean one. For an entrypoint script, docker stop gets the trap's forced exit 143 in place of the daemon's own status.

Expected

An exec into the long-running process is a sanctioned shape. The script no longer exists when the signal arrives, so it owes no trap and no signal test. Anything it held before the exec is released before the exec. A script that keeps running after it starts a child still takes the full rule.

Found by

A local strict review during a resync of ptr727/NxWitness, from audit run 2026-11-12T16:56:31Z | hub 2d0f8901. NxWitness has an entrypoint and s6 service scripts of this exact shape. Those scripts are untouched today, and the rule would apply on their next edit.

Done when

  • CODESTYLE.md "Interrupts" (or "Interrupts in Shell") exempts a script that ends by exec-ing the process it launches, and states that anything held before the exec is released before it.
  • shell-codestyle is regenerated through scripts/build_dist.py.

🤖 Generated with Claude Code

Activity

  1. ptr727 commented on Nov 12, 2026

    @ptr727
    OwnerAuthor

    Correction and one more shape, both from a later local review pass of the same resync.

    Correction to the s6 example above. A bash -c given a single simple command execs that command in place. So $! still names the daemon, and the rule's own reasoning puts it in the background rather than the foreground. The grace-timeout kill described above is therefore not what follows from the rule for that form. The cost of dropping an exec that stands is the extra bash between the supervisor and the daemon, plus the trap's fixed 143 replacing the daemon's own exit status. Neither has been confirmed in a running container. A probe would build an image with the exec removed, then run ps -o pid,args and an s6-svc -r against the service inside it.

    A second handover the rule cannot express. A constructed entrypoint:

    #!/bin/bash
    sudo /opt/app/bin/helper &
    exec /opt/app/bin/daemon -e

    The helper is a long-running background child that is meant to outlive the script across the exec. "Interrupts in Shell" requires wait "$pid" on such a child, which blocks before the exec, so the daemon never starts. "Interrupts" also owes a mid-run signal test for a script holding a child. Here the only window for that test is the moment before the exec. So the exemption needs to cover a background child handed across the exec, not only the exec line.

    🤖 Generated with Claude Code

  2. ptr727 commented on Nov 13, 2026

    @ptr727
    OwnerAuthor

    Backlog burndown claim, round 1 (2026-11-13), away run, scope develop. Branch burndown/interrupts-reraise, group: #4084, #4097. Tier: frontier (carried CODESTYLE.md and codestyle skills).

    Predicted files:

    • CODESTYLE.md ("Interrupts", "Interrupts in Python", "Interrupts in Shell")
    • .agents/skills/python-codestyle/SKILL.md
    • .agents/skills/shell-codestyle/SKILL.md
    • .github/skills/python-codestyle/SKILL.md
    • .github/skills/shell-codestyle/SKILL.md
    • .claude-plugin/fleet-skills/skills/python-codestyle/SKILL.md
    • .claude-plugin/fleet-skills/skills/shell-codestyle/SKILL.md
    • .claude-plugin/fleet-skills/.source-digests/python-codestyle
    • .claude-plugin/fleet-skills/.source-digests/shell-codestyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions