Skip to content

A SIGINT at any instant of --install's placement ends the run and leaves no temporary, so test_a_run_killed_mid_placement_leaves_no_temporary[SIGINT-True-cp] stops failing about once in a hundred runs #250

Open

Description

@brettheap

Goal: a SIGINT that lands at any instant of a placement ends openRepoTools --install and leaves no .<name>.openrepotools.* temporary, so test_a_run_killed_mid_placement_leaves_no_temporary[SIGINT-True-cp] stops failing about once in a hundred runs. The test is at tests/test_openrepotools_command.py:877; it came with #172, for #167.

Where this comes from. Lane openRepoTools-3 filed this on Brett Heap's word, verbatim: "yes, file the SIGINT flake in v1.2.0" (2026-10-18).

Where it has failed

Measured outside pytest. The script below repeats the test's own steps:

  • a slow cp first on PATH;
  • a poll for a temporary every 50 ms;
  • then os.killpg(…, SIGINT) on the run's process group.

It adds one thing, a TMPDIR for each run. The machine runs bash 5.2.21, and /bin/sh is dash (Ubuntu on WSL2).

Installer Runs Ignored the SIGINT and kept installing Died of SIGINT but left the temporary Clean
main 87a5e9d 300 1 1 298
006-release-pypi at 2e4a633 (workdir and place_by_rename byte-identical to main) 190 2 1 187
T008's (#228, placement code unchanged) 190 0 2 188
main 87a5e9d, with an EXIT trap that logs each step using builtins 700 2 0 698

It needs the signal within a few milliseconds of mktemp making the file.

  • With 0 to 20 ms of random delay added before the signal, 100 runs each of 2e4a633 and T008's installer were all clean.
  • With the slow tool as mktemp instead (the signal lands while mktemp sleeps), 40 runs of each were all clean.
  • Only the cp case meets that window. Its mktemp is quick, and the test signals as soon as the file shows.

The two failure modes

  1. The run ignores the SIGINT and keeps installing. Then communicate(timeout=60) times out, because every later placement goes through the slow cp, 3 seconds each.
    • In both traced runs the EXIT trap never ran. Twenty seconds after the signal, the bin directory held 7 entries.
    • Likely cause: bash's rule for a non-interactive shell that receives SIGINT while it waits for a foreground command (bash manual, "Signals"). If that command does not die of the signal, bash assumes the command handled it, and goes on. A SIGINT that arrives after mktemp has exited 0, but before bash has reaped it, falls under that rule.
    • A person would see it too. A Ctrl-C at that instant does nothing, and the install goes on until a second Ctrl-C.
  2. The run dies of SIGINT but leaves the temporary. The file is 0 bytes, so it is mktemp's file, made before cp wrote anything. Run 268 of the 300 on main showed three things:
    • The run's workdir was gone, so the EXIT trap's first command, rm -rf -- "$WORKDIR" (openRepoTools:240), had run.
    • The real cp ran after the trap. The last line of stderr was /usr/bin/cp: cannot stat '…/tmp/tmp.ttxdmmFujp/…': the real cp could not find its source, which was in that workdir. So the slow cp, forked after mktemp, never received the signal, and ran on after the trap.
    • The temporary was still there. Its name carries the run's own $PLACING prefix, which the trap's second command, [ -z "$PLACING" ] || rm -f -- "$PLACING"*, removes.
    • Not yet known: whether that second command ran. The 700 traced runs did not reproduce this mode. A longer traced run is going, and lane 3 will add its result here.

What a fix has to settle (nothing here is decided):

  • Make SIGINT always end the run. One way is a trap … INT that does the EXIT trap's cleanup, then re-raises SIGINT with its default action. Bash runs a SIGINT trap even when the foreground command did not die of the signal, so this would close mode 1, for people as well as for the test. The run must still die of the signal (-2 or 130), which the test asserts.
  • Make the cleanup unable to stop halfway. Remove the temporary first, or remove the temporary and the workdir in one rm. Whether that closes mode 2 depends on mode 2's cause, which is still open.
  • Lane 3's recommendation: do not change only the test. Waiting until the slow tool is asleep before signalling would hide both modes, and re-sending the signal would hide mode 1. Both are real instants at which a person's Ctrl-C can land.

Done when:

  • a few hundred runs of the script below give none of either mode, on Linux;
  • the SIGINT and SIGTERM cases still fail against a trap that does not remove the temporary, as they do today;
  • CI's Linux jobs stay green.
The script: python3 -I repro7.py <installer tree> <runs> <scratch dir>, where the tree is git archive of the commit under test, extracted
import os, shutil, signal, subprocess, sys, tempfile, time
from pathlib import Path
src = Path(sys.argv[1]); runs = int(sys.argv[2]); base = sys.argv[3]
SLOW_CP = 'for arg in "$@"; do\n\tcase "$arg" in *.openrepotools.*) sleep 3 ;; esac\ndone\nexec {real} "$@"\n'
def temps(home):
    dirs = [home / ".local" / "bin", home / ".claude", home / ".claude" / "commands", home / ".claude-profiles" / "shared" / "commands"]
    for n in ("handoff", "lane-swap", "restart"):
        dirs += [home / ".claude" / "skills" / n, home / ".claude-profiles" / "shared" / "skills" / n]
    return sorted(str(p) for d in dirs if d.is_dir() for p in d.iterdir() if ".openrepotools." in p.name)
def dflt():
    signal.signal(signal.SIGINT, signal.SIG_DFL); signal.signal(signal.SIGTERM, signal.SIG_DFL)
stats = {"runs": 0, "died": 0, "left": 0, "left_workdir_gone": 0, "left_workdir_kept": 0, "hung": 0, "survived": 0}
for i in range(runs):
    home = Path(tempfile.mkdtemp(dir=base)).resolve()
    shim = home / "shim"; shim.mkdir()
    tmpdir = home / "tmp"; tmpdir.mkdir()
    (shim / "cp").write_text("#!/bin/sh\n" + SLOW_CP.format(real=shutil.which("cp"))); (shim / "cp").chmod(0o755)
    env = {k: v for k, v in os.environ.items() if not k.startswith(("OPENREPOTOOLS_", "LANES_", "TMUX", "XDG_DATA_HOME", "CLAUDE_", "AGENT_PROTOCOL_ROOT", "PROJECTS_DIR"))}
    env.update(HOME=str(home), TMPDIR=str(tmpdir), CLAUDE_PROFILES_HOME=str(home / ".claude-profiles"), CLAUDE_USER_DIR=str(home / ".claude"), AGENT_PROTOCOL_ROOT=str(home / ".agents"), PATH=f"{shim}:{os.environ['PATH']}")
    run = subprocess.Popen(["bash", str(src / "openRepoTools"), "--install"], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env, start_new_session=True, preexec_fn=dflt)
    deadline = time.monotonic() + 60
    while time.monotonic() < deadline and not temps(home): time.sleep(0.05)
    seen = temps(home)
    workdirs_before = sorted(os.listdir(tmpdir))
    os.killpg(run.pid, signal.SIGINT)
    stats["runs"] += 1
    try:
        out, err = run.communicate(timeout=20)
    except subprocess.TimeoutExpired:
        stats["hung"] += 1
        print("HUNG", i, "signalled beside", [p.split("/")[-1] for p in seen], "bin now holds", len(os.listdir(home / ".local" / "bin")), flush=True)
        os.killpg(run.pid, signal.SIGKILL); out, err = run.communicate()
    rc = run.returncode
    if rc in (-signal.SIGINT, 128 + signal.SIGINT): stats["died"] += 1
    elif rc != -9: stats["survived"] += 1; print("SURVIVED", i, "exit", rc, flush=True)
    t = temps(home)
    if t and rc != -9:
        stats["left"] += 1
        kept = sorted(os.listdir(tmpdir))
        stats["left_workdir_kept" if kept else "left_workdir_gone"] += 1
        print("LEFT", i, "exit", rc, t[0].split("/")[-1], os.path.getsize(t[0]), "bytes; signalled beside", [p.split("/")[-1] for p in seen],
              "; TMPDIR before the signal", workdirs_before, "after", kept, "; last stderr line", (err.strip().splitlines() or [""])[-1][:160], flush=True)
    shutil.rmtree(home, ignore_errors=True)
    if (i + 1) % 25 == 0: print("progress", i + 1, stats, flush=True)
print("FINAL", stats, flush=True)

Lane: openRepoTools-3

Activity

  1. added this to the v1.2.0 milestone on Oct 18, 2026
  2. brettheap commented on Oct 18, 2026

    @brettheap
    ContributorAuthor

    The longer traced run, 2026-10-18T14:5xZ, against main 87a5e9d. The copy logs each step of the EXIT trap with builtins only, as in the issue's last table row. A further 1,500 runs went out in three parallel workers, so the traced runs now total 2,200.

    Runs Ignored the SIGINT and kept installing Died of SIGINT but left the temporary Clean
    2,200 4 0 2,196
    • Mode 1, all four runs: the trap never ran, and the bin directory held 7 entries 20 seconds after the signal. That is the shape the issue describes.
    • Mode 2 has not come back under the trace. Untraced code that is byte-identical in workdir and place_by_rename gave 4 such runs in 680. The traced copy gave none in 2,200.
      • The trace runs only after the signal. So its builtins seem to change how the trap races whatever else is running then. In run 268, that was the slow cp, forked after mktemp, which ran on after the trap.
      • This is inference, not a measurement. Mode 2's cause is still open. A tracer that does not touch the trap (strace -f -tt -e trace=execve,unlink,unlinkat,kill, or bpftrace on unlinkat) is the next step.

    Lane: openRepoTools-3

  3. brettheap commented on Oct 20, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoTools-5, session 0d83dca2-c18c-4bb0-99ce-896e6cafea02@Eagle, 2026-10-20T23:02:39Z, for #250

    Logged in lanes/log/openRepoTools-5.md at ac78b0be71fbd9657740459786902b7edef3af00.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoTools#250:
       none
    2. `gh pr list --repo opensoft/openRepoTools --state all --search "#250"`, kept where the row or its body names `#250`:
    262	openRepoTools becomes the openrepotools package: pipx installs the wheel with the whole payload, --install leaves pipx's link to pipx, --version names the release, and every count line says where the other commands come from (#228, PR 1 of 4)	006-release-pypi	MERGED
    3. `git ls-remote --heads [email protected]:opensoft/openRepoTools` branches naming `250` as a whole token:
       none
    
  4. modified the milestones: v1.2.0, v1.2.1 on Nov 8, 2026
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions