Skip to content

tools: an ended gate run takes its binary's timeout with it - #319

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-gate-timeout-group
Oct 16, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-gate-timeout-group

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes #201.

What and why

Closes #171.

Release notes: internal: a gate or timing runner that is stopped with TERM, INT or HUP now ends the binary it started, so the binary's gate locks, output and timing lease go with the runner instead of staying held until the binary's own bound.

GNU timeout puts its command in a process group of its own, and the gate runners start their binary under timeout in the foreground. A TERM, INT or HUP sent to a runner's process group never reaches the binary or its timeout, and a TERM sent to the runner's pid ends the runner alone. Either way the binary runs on until its own bound and keeps what it holds:

  • tools/gpu-gate.sh: the gate lock descriptors and the writers of the run's output, up to 900 s when BLOOMERY_GATE_BOUND is unset.
  • tools/ref/time-gate.sh: the machine-wide lease, up to 600 s.
  • tools/host-gate.sh and tools/gate.sh: the binary, or cargo test, still writing to the run's output.
  • tools/ref/lease.sh's lease_bounded, which bounds the children the timing runners start under the lease: the lease (descriptor 9), up to LEASE_ARM_BOUND (900 s by default). Most timing runners also call it inside a command substitution or a pipeline (out=$(lease_bounded …)), where even a fix inside lease_bounded would not see a TERM sent to the runner's pid. The DS41 and Qwen3-MoE depth runners start their arms under a timeout of their own, piped into a fault marker. The DS41 and GLM5Next preheats and tools/ref/cstate-ab.sh's arms start theirs inside a command substitution (out=$(timeout … 2>&1)).
  • tools/ref/perf-decode.sh and tools/ref/load-groups.sh, which start the decoder or the load under a timeout of their own in the background and give the runner no way to stop it: the lease, up to that timeout's bound.

The gpu-gate self-test meets this when gate()'s bound ends a held run. The bound returns 124, but the stub binary and its timeout stay alive, and a later blocking flock on the same lock, or a relay() reading that output, waits for them.

The issue offers two fixes. This PR takes the first: the runner passes the signal on to the inner timeout and its process group, and waits for them.

  • run_bounded now lives in tools/gate-bound.sh, which gpu-gate.sh, host-gate.sh and gate.sh already source. It sets its trap first, then starts the bounded command in the background and waits for it. A signal that comes before the child's pid is known is recorded and passed on as soon as the pid is, so no signal falls between the start and the trap. BIN_SENT records that the trap has passed the signal on already, so the child gets it once. The trap ignores nothing before the child starts, because a child started with signals ignored would keep them. On TERM or HUP it stops that child with lease_stop, ignores further signals and waits until the child ends; the runner then goes on with the child's code. If lease_stop cannot clear the child's group, run_bounded returns that failure when the child itself ended with 0, and the child's own nonzero code otherwise. Stopping a child that has already ended is no error, under set -e too (time-gate.sh and the timing runners run under it), and the pid is cleared once the child is reaped, so a late signal reaches no other process. INT works the same way unless the runner itself was started with & by a shell, because bash leaves INT ignored in that case. The child keeps the runner's stdin (<&0), because a background command in a non-interactive shell reads /dev/null otherwise.
  • lease_stop <pid>, also in tools/gate-bound.sh, sends TERM to timeout and to its process group, waits for the group's live members (a zombie counts as ended), then sends KILL and reaps timeout, all within one cleanup budget (9 s by default, the TERM wait ending 2 s before it). A group still alive at the end of the budget is reported ([bound] <pid> or its process group still alive after its <n> s cleanup budget) and lease_stop returns 70, as it does when it cannot read the process table. The TERM goes to the group too because GNU timeout that receives a TERM before it has returned from fork exits without signalling its command, and the command then keeps the lease or the lock in timeout's group.
  • All the gate runners go through run_bounded: gpu-gate.sh's three start paths (plain, BLOOMERY_GATE_STACKS and BLOOMERY_GATE_GDB; the stacks path now sources stack-watch.sh into the runner's shell and puts the runner's own traps back after the watch), host-gate.sh, gate.sh, time-gate.sh and lease.sh's lease_bounded. lease.sh now sources gate-bound.sh beside lease-probe.sh, and time-gate.sh gets run_bounded through lease.sh and keeps its own 600 s bound.
  • A gate runner ends right after its binary, but a timing runner has more arms to run. So after the child has ended, lease_bounded sends the signal it passed on to the runner again (kill -s <signal> $$), and the runner stops, by its own trap where it set one, instead of starting its next arm. For that, run_bounded records the signal it passed on in BIN_SIGNAL and puts back the caller's own TERM, INT and HUP traps when it returns, instead of resetting them. dump.sh and dump-mtp.sh set exit 143 and exit 130 traps before they call lease_bounded, and a reset would drop them. The gate runners other than gate.sh set no such traps and ignore BIN_SIGNAL, so for them nothing changes.
  • A timing runner that needs a bounded command's output now calls it in its own shell and reads the output from a file, so the signal reaches run_bounded. lease.sh has three helpers for this:
    • lease_capture <seconds> <command…> runs lease_bounded with stdout and stderr in a temp file and puts them in LEASE_OUT, as $(… 2>&1) gave them.
    • lease_filter <seconds> <stdout|stderr> <file> <filter…> -- <command…> runs a live filter (the depth runners' majflt_mark, dma-dram-share.sh's stamp) on the command's output through a FIFO: stdout filters the combined output, stderr filters stderr and leaves stdout in LEASE_OUT_FILE. The filter runs with descriptor 9 closed, so it never holds the lease. The bound and the arguments are checked before the filter starts. Like run_bounded, lease_filter sets its trap before it starts the filter, and a signal that comes before the filter's pid is known is acted on as soon as it is: the trap ends and reaps the filter, puts back the caller's traps and sends the signal on to the runner. Without that, a filter still waiting to open the FIFO would outlive the runner and hold the runner's stderr open. A signal that comes after the filter is reaped but before the caller's traps are back is held and sent to the runner once they are, so the caller's trap, or the default action, ends the runner and its next arm does not start. When the command succeeds and the filter fails, lease_filter returns the filter's code.
    • lease_out_init makes the temp dir with that file and FIFO, and adds lease_out_clean to the runner's EXIT trap without replacing what is there. lease_bounded also takes LEASE_BOUNDED_OUT and LEASE_BOUNDED_ERR, for a caller that names its own files.
  • The timing runners use them. ab-decode.sh, depth-decode.sh, depth-gpu.sh, decode-measure.sh's two sweeps, governor-ab.sh and depth-glm5next.sh's other arms take their output through lease_capture; perf-decode.sh's three readers and governor-ab.sh's ik arm, whose stderr was dropped, write to files through LEASE_BOUNDED_OUT. depth-glm5next.sh's ours arms, depth-ds41.sh's and depth-qwen3moe.sh's reference arms, depth-ds41.sh's ours arm and dma-dram-share.sh's bench go through lease_filter, and depth-qwen3moe.sh's ours arms through lease_capture. The DS41 and Qwen3-MoE arms keep their $BOUND. The DS41 and GLM5Next preheats and cstate-ab.sh's arms take their output through lease_capture with the bound they had ($BOUND, and 600 s in cstate-ab.sh). qdot-rate.sh runs its rounds in its own shell into the sitting file and prints the file after them, and expert-union-dump.sh reads its prompts from a process substitution instead of a pipe into its loop.
  • The timing runners that started a bounded command of their own now use lease_bounded as well: the build steps of build-dump-draft.sh, build-dump-mtp.sh, build-ik-cand.sh and build-ik-mimo2.sh, and host-rate.sh, ik-draft.sh, ik-greedy.sh, ik-ppl.sh, router-trace.sh, r8-sidecar.sh, ncu-gpu.sh, nsys-ds41.sh and nsys-gpu.sh (its profiled arms and its analyze step). ik-ppl.sh and router-trace.sh used to start the command in the background to publish its pid. They now set LEASE_BOUNDED_PIDFILE, and lease_bounded writes timeout's pid there before the binary starts. lease-hold.sh runs its command through run_bounded timeout --kill-after=10 0, where the 0 means no bound, so the command gets a group that lease_stop can reach.
  • perf-decode.sh now owns its background decoder. An EXIT trap stops the decoder's timeout and its group with lease_stop, and a TERM, INT or HUP that comes before the decoder's pid is known is held and acted on as soon as it is (exit 143, 130 or 129). Before, a TERM during perf record ended the profiler and then the runner, and the decoder and its timeout kept the lease. After a normal run the runner reaps the decoder and clears its pid, so the later perf script, annotate and report calls keep their usual signal handling. A decoder that fails now fails the run with its code, a reason (cut off at its <n> s bound for 124) and the last 20 lines of its log. The EXIT trap keeps the runner's exit code, removes the capture files with lease_out_clean, and exits with the cleanup failure when lease_stop fails. Its symbol table's awk now writes to ("sort -rn | head -n " top) in parentheses, which BSD awk on the Mac needs.
  • load-groups.sh's lg_process runs a load of arms under one timeout in the background. It now sets a TERM, INT and HUP trap before it starts that timeout: the trap stops the load with lease_stop, puts back the caller's traps and sends the signal on to the runner, and a signal that comes before the load's pid is known is acted on as soon as it is. A signal that comes after the load is reaped but before the caller's traps are back is sent to the runner once they are, so the runner stops instead of starting the next load. Its own stops (no line within the bound, a line past the last arm) also go through lease_stop, and a stop that fails ends the run with its code unless the load itself exited nonzero. depth-qwen3moe.sh's memory scope (MEM_SCOPE_SCRIPT) passes a TERM, INT or HUP on to its command once, ignores further ones and waits again, so it returns the command's code; it used to stop waiting at the first signal.
  • With this, a failed filter now fails the arm when the command itself succeeded; the old pipelines kept only PIPESTATUS[0]. expert-union-dump.sh now stops with code 1 at the first failed prompt; its exit 1 used to end only the pipeline's subshell, and the script went on. dma-dram-share.sh now refuses a value with a leading zero (0600) with 64, as lease_bounded refuses such a bound; it used to refuse only 0. Its EXIT cleanup now stops the copy's group with lease_stop, removes the capture files and exits with the cleanup failure, and a TERM, INT or HUP that comes while the copy is starting ends the run once the copy's pid is known.
  • The card tests and the three depth-*-stub.sh tests build temp trees with a copy of lease.sh; those trees now get tools/gate-bound.sh too. The lease self-test reads depth-qwen3moe.sh's arms through a variable path, so check-recipes' walk of the timing scripts does not count lease.sh as a caller of that lease-taking runner.
  • gate.sh with a test filter used to pipe cargo test into tee. In a pipeline, run_bounded would run in a subshell that a TERM to the runner does not reach. The output now reaches tee through a FIFO beside the log, and the runner waits for tee before it counts the passed tests. A FIFO that cannot be made ends the runner with 70 before cargo starts, and a tee that fails after a passing run ends the runner with tee's code (cargo's own failure wins). tee starts before run_bounded sets its trap, so gate.sh sets a TERM, INT and HUP trap of its own before it starts tee: once tee's pid is known the trap exits (143, 130 or 129), and a signal that comes before that pid is known is acted on as soon as it is. The EXIT trap then ignores further signals, sends tee a KILL and reaps it before it removes the log and the FIFO, because the reader may still be the shell opening the FIFO, before tee has its default signal handlers. Without this, a TERM in that window ended the runner, and tee, still waiting to open the FIFO, held the runner's output open.
  • tools/ref/stack-watch.sh passes a TERM or HUP on to its command and to a gdb dump under way. It now sources gate-bound.sh and runs both the command and the dump through run_bounded. The command starts as (set -m; run_bounded "$@"), so it has a process group of its own and a background descendant of the command gets the TERM too. gpu-gate.sh now sources stack-watch.sh into the runner's shell instead of starting it with run_bounded bash, and puts back its own TERM, INT and HUP traps after the watch. A cancelled watch waits for each timeout's group, and a lock either child inherited is free when the watch returns. The dump runs in the background and is waited for. Before, a TERM that came during a dump was handled only after the dump, and an outer KILL in that window left the inner timeout and the binary behind. Once it has passed a signal on, the trap ignores further ones, because under GNU timeout the watch gets the bound's TERM twice (from the outer timeout's group signal and from the runner). The first signal still cuts short the wait it arrives in, so the watch makes each wait, for the dump and for the command, twice, as run_bounded does: it goes on only after the child has ended, and returns the command's code. The first wait of each pair is written wait ... || true, and each TERM the watch sends to a child that may have ended is written || :, so a watch run under bash -e still reaches its last waits. The trap also sets $stop. A signal that comes outside a wait (during the loop's one-second sleep) ends the loop at its next turn, and the watch then waits for the command and starts no dump. Without it, a command that took longer than QUIET to end after its TERM was dumped with a gdb that no signal would reach. As in run_bounded, the trap is set before the command starts: a signal before the command's pid is known sets $stop, and the command gets its TERM as soon as the pid is known, unless the trap has sent it one already ($told). The trap also ignores nothing from the last $stop check before a dump until the dump's pid is known ($spawning), because a dump started with TERM ignored can lose the TERM the watch sends it before timeout sets its own handler. A signal in that window goes on to the command, and the dump gets its TERM as soon as its pid is known. The dump writes to a file beside the watch's log, and the watch passes that file to stderr, prefixed, once the dump has ended, so no child of the dump outlives it. The dump's timeout sends a TERM at 120 s and, with --kill-after=10, a KILL ten seconds later. After a dump the watch gives the quiet process ten seconds to end before a KILL. It reads the process state with ps -o stat= and counts a zombie as ended; kill -0 succeeds on a zombie, so a process whose parent, or the subreaper it was reparented to, does not reap it held the watch for the full ten seconds. When ps cannot read the state, alive checks with kill -0 that the pid exists; an existing pid is reported on stderr (stack-watch: cannot read state of existing pid <pid>) and counted as alive, so a command that ignores the TERM still gets its KILL when ps fails. An INT reaches the watch's trap only when the watch runs in the foreground.
  • tools/ref/stub-timeout.py stands in for timeout on hosts without coreutils (the Mac). It now keeps coreutils' timing and exit codes. It sends TERM at its bound or when it receives a TERM. It sends KILL --kill-after seconds after the first of the two, and --kill-after=0 means no KILL. It exits 124 when the bound ran out and 137 when the KILL ended the command. It sets its TERM handler before it starts the command, so a TERM that comes right after the runner starts it reaches the command's group. Like coreutils, it now leads a process group of its own and sends its TERM and KILL to the group, ignoring its own TERM while it forwards it. A bound of 0 means no bound, and the command inherits the monitor's open descriptors, including a lease held on descriptor 9. Before, it sent KILL at once at its bound and signalled only its direct child, so a run that left a grandchild behind could not fail on the Mac. The card tests copy it onto PATH as timeout when the host has none. tools/ref/cancel-stubs.sh holds the two fixtures the lease and stack-watch self-tests share: a timeout that makes its own group and exits on a TERM without passing it on, and a readiness check that waits until the stub's timeout is asleep.

The second option in the issue keeps both bounds in one process group. The simplest way to do that is timeout --foreground on the inner bound, and in that mode timeout does not end the command's own children when the bound expires. So I did not use it.

The tests:

  • gpu-gate self-test, part 1. gate() takes GB=<s> for its own bound (the default stays 60 s). The stub writes its pid and its parent's pid (the binary's timeout) to STUB_PID. With STUB_TERM=7 it ends with code 7 one second after a TERM. The case holds the stub and lets gate()'s bound end the run with GB=10, once plain and once under the watch. Right after the bound returns 124 it checks that the stub and its timeout are gone and the card lock is free. Then it checks that the output pipe reached EOF and that the runner's own exit line says exit 7. The processes are checked before the wait for EOF, so a runner that passes the TERM on and exits without waiting does not pass. The exit line catches a runner that returns the status of its interrupted wait (143) instead of the child's.
  • gpu-gate self-test, part 2. A held command that ignores TERM runs under the real watch (BLOOMERY_GATE_STACKS), with a timeout stand-in that makes its own group and exits on a TERM without passing it on, and a sleep stand-in that holds the watch's one-second sleep until the case lets go. The case sends the runner's pid a TERM while the watch sleeps. The runner must end with 143, the command and its timeout must be gone, the output must reach EOF and the gate and v41-load locks must be free. Two more cases make ps fail while run_bounded stops a child that exits with 0 or 7. The run must end with 70 for the child that exited with 0 and with 7 for the other, and print cannot read processes while stopping.
  • stack-watch self-test. In the first, a stub gdb on PATH holds, so the watch (QUIET 1) stays in its dump, and the stub ends only six seconds after its TERM; it sets its TERM trap before it writes the pid the case waits for. The case sends a TERM to the watch and a second one 1.5 s later. The watch must end within 20 s with the command's code (7, two seconds after its TERM), and neither the gdb nor the command may be left. In the second, the command goes on after the watch has ended its quiet sleep, and the case sends a TERM while the watch waits for the command. The watch must end with the command's 7, not 143, and the command must be gone. In the third, the command prints every 0.2 s until its TERM and then takes five seconds to end, longer than the quiet time (2 s), and the case sends the TERM a second after the command's pid is there. Its printing, not the TERM's timing, keeps the quiet time from running out before the TERM. No dump may start (the stub gdb writes its pid when it starts), the watch must return 4 to 7 s after the TERM with the command's 7, and the command must be gone. In the fourth, the command sets its TERM trap, starts a background sleep and writes its pid and its parent's pid. The case waits until the command's timeout is asleep and the descendant is there, then sends the TERM. It runs twice: once after the watch has read the command's pid, and once on a copy of the watch with a wait planted right after the command starts, so the TERM comes before the pid is read. Each time the watch must end with the command's 7 and both the command and its background descendant must be gone; in the planted run the watch must have recorded the TERM before it had a pid. The fifth and sixth put a timeout stand-in on PATH that makes its own group and exits on a TERM without passing it on, as GNU timeout can before fork returns, once for the command and once for the dump, with a lock the held child inherited. The case waits until the child and its timeout are there with the lock held, sends the watch a TERM, and the child must be gone and the lock free. A further case puts a ps stand-in that exits 2 first on PATH and calls alive with the pid of the running self-test: alive must succeed and print stack-watch: cannot read state of existing pid <pid>. The checks that a child has gone use the same alive (five places), so a zombie is not counted as left behind. A failed case prints the last line of what it read (for example dumping: yes, ended in N s, left: none) on its FAIL line, so a log that keeps only FAIL lines shows why.
  • card tests. gate.sh with a test filter passes cargo's output through and ends 78 when no test passed, which covers the FIFO path. A call whose FIFO cannot be made, because a link already holds its path, must end 70 before cargo runs and leave the linked file as it was. Four more cases plant a TERM or a HUP right after tee starts, before and after its pid is recorded: the runner must end with 143 or 129, cargo must never start, and tee must end. Two cases give gate.sh a tee that exits 9 after it has copied the output: after a passing summary the runner must end with 9 (GATE RED (exit 9)), and when cargo ends with 3 it must end with 3.
  • lease self-test, signal cases. A runner holds a temp lease, runs a stub through the call under test, then prints next arm. The stub sets a trap that ends it with 7 one second after a TERM, then writes its pid and its parent's pid (its timeout) and holds. The case waits until that pid file is there and the stub's timeout is asleep waiting for it (polled every 0.1 s), checks that it got there, and sends a TERM to the runner's pid, once with no runner trap and once with a runner trap that prints trap ran and exits 143. Each time the runner must end with 143 before the call's 20 s bound, the stub and its timeout must be gone, the lease must be free and next arm must not appear; with the trap, trap ran must appear. The call is lease_bounded in the runner's shell, lease_capture (whose temp dir must be gone too), a lease_bounded whose copy of run_bounded waits between starting the child and reading its pid, so the TERM lands in that window, a lease_bounded under the timeout stand-in that exits without passing the TERM on, lg_process with a stub load (also under that stand-in; skipped where bash is older than 4.1, as /bin/bash 3.2 on a Mac is), a profiler arm (the profiled-arm lines of nsys-gpu.sh run with a stub profiler that ignores TERM, and LEASE_BOUNDED_PIDFILE must name its timeout), and nine arms taken from depth-ds41.sh, depth-glm5next.sh, depth-qwen3moe.sh and cstate-ab.sh: the DS41 and Qwen3-MoE ours and reference arms, the DS41 pp arm, the Qwen3-MoE memory-capped arm, the DS41 and GLM5Next preheats (with a held stub in place of the preheat script) and cstate-ab.sh's arm loop.
  • lease self-test, memory scope. The real MEM_SCOPE_SCRIPT runs the held stub and gets two TERMs 0.1 s apart; it must return the stub's 7, and the stub must be gone.
  • lease self-test, perf cancellation. A copy of perf-decode.sh runs with a stub decoder and a stub perf, and the case sends the runner a TERM during perf record (also under the timeout stand-in), before the decoder's pid is assigned, and during annotate and during the callers report. Each time the runner must end with 143 before the 20 s bound, with the decoder, the profiler and their timeouts gone and the lease free; before the pid, no perf command may run. A decoder that ends with 23, and one that ends with 124, must fail the run with that code, the decode exited <code>: line and the last 20 lines of its log. The EXIT trap is also run alone, for a runner that ends with 0 or 23 and a lease_stop that returns 0 or 70: the code must be the runner's own unless the stop failed, in which case it is 70, and lease_out_clean must run each time.
  • load-groups self-test, cleanup status. lease_stop is replaced by a stub that fails with 70 (71 in the second pair). A load that stalls and exits with 0 must end the run with 70, and one that exits with 7 with 7. A load that prints a line past the last arm gives 71 and 7 the same way.
  • lease self-test, filter start. A copy of lease_filter waits between starting the filter and reading its pid, and the case sends the runner a TERM there, with no runner trap, with one that exits and with one that returns. The filter must be gone and the runner's stderr must reach EOF before the case cleans up, the lease must be free, and a trap that returns must find its own trap back afterwards. The case never signals the filter itself.
  • lease self-test, filter reaped. A DEBUG trap sends the runner a TERM or a HUP right after lease_filter has reaped its filter and before it puts the caller's traps back, once with set -e off and once with it on. The runner must end with 143 for the TERM and 129 for the HUP, and the marker of the next arm (NEXT_ARM_STARTED) must not appear.
  • load-groups self-test, load reaped. The same four cases run lg_run_unit with a stub load. The stub's command builder prints NEXT_ARM_STARTED when a further load starts, and it must not appear.
  • lease self-test, the rest. lease_capture's output and code; the EXIT trap it extends (a quoted one and one with a trailing comment, both still run), read in the runner's own shell with its positional arguments untouched; a mktemp that fails (code 70, empty output); lease_filter's two streams; a failed filter's code; a refused bound that starts no filter; dma-dram-share.sh refusing 0600; expert-union-dump.sh stopping at a failed prompt; and a command that reads the runner's stdin.

Left open:

  • run_bounded, lease_filter, gate.sh and the watch each set their trap before they start their child. The lease self-test reaches the first two windows with a planted wait, the card tests reach gate.sh's with a signal planted right after tee starts, and the stack-watch self-test reaches the watch's window before the command's pid is read with a wait planted in a copy of the watch. The watch's window before a dump's pid is read is reached only by a mutant under "Fail first".
  • A binary that ignores the TERM gets a KILL 7 s later by default. One that the KILL does not end within the rest of the budget, for example a process stuck in the driver, is reported, and the lease or lock it holds stays held until it ends.
  • The watch checks $stop in two places. The loop's condition ends the loop at its next turn, so no new round starts after the signal; the round under way when the signal came may still scan with ps and print "nothing dumped". The check before a dump keeps that round from starting a dump.
  • The dump's output reaches stderr only once the dump has ended, so a KILL to the watch during a dump, with no TERM before it, leaves no stacks in the log.
  • Cancelling and cleaning up the runners this PR does not touch is out of scope, tracked in tools: bounding, stopping and cleaning up a child process is written again in each shell runner, so a fix in one leaves its siblings #313.
  • qdot-rate.sh prints its rounds only after they have ended, not while they run. A signal that stops it partway leaves none of the finished rounds on screen or in the log, because its EXIT trap removes the sitting file.

What I ran into

This does not block the PR.

The head is rebased onto main 85511826. After the review on ba4aee3d, lease_stop sends TERM to the monitor first and to the rest of its group only after the monitor exits, with one deadline and the KILL step kept. A new case in tools/gpu-gate.sh --self-test uses a child that drains on the first TERM and aborts on a second: the old lease_stop fails it (49 of 50 ok), and the head passes the whole self-test (111 of 111 ok). tools/recipes.py --self-test now names the Clefvis reference tree as the never-skip reason of the cancellation fixture (174 gate recipes, 0 failures).

After the review on e078e390, the Clefvis wrapper's three inner timeout calls (chat, tower, hidden) go through lease_bounded, and tools/ref/lease.sh --self-test gains twelve cases: each call, with the child ending TERM at 0 and at 7, with and without an outer TERM trap. Each case checks that the child and its timeout end, the lock is free, the output reaches EOF, the runner returns 143 and no next arm starts. With the old clefvis.sh those cases fail (24 failures); at the head the self-test reports ok (0 failures). This ran on an Apple Silicon Mac with bash 5.3, through the self-test's timeout stub.

After the review on b15f54a2, two more changes:

  • run_bounded no longer resets TERM, INT and HUP before it puts back the caller's traps. It saves an explicit reset only for a signal the caller had no handler for and restores each handler directly, so a TERM that arrives at that point still runs the caller's handler. A lease self-test case sends the TERM there and checks that the server ends, the caller's handler runs, the lease is free, the output reaches EOF and no next arm starts.
  • Nested supervisors now split one cleanup budget instead of each taking 10 seconds. lease_stop uses a single deadline for the TERM wait, the KILL and the reap: 9 seconds by default, 7 for TERM and up to 2 for KILL and reap, so it finishes before an enclosing timeout --kill-after=10. run_bounded passes half of its budget to its command (LEASE_STOP_GRACE, 9, 4, 2, 1), lease_bounded uses the inherited budget for its timeout --kill-after, and a budget of 0 refuses to start the next bounded command with a named error and status 70. A lease self-test case runs a child that ignores TERM, INT and HUP under an outer timeout, an outer TERM trap and the inner lease_bounded, and checks the lock and EOF right after the outer bound returns. Before the change it returned 137 with the lease held; now it returns 124 with the lease free.

The new regressions fail on the previous head (11 failures) and pass at babd6b99. The head is rebased onto main 98a513fc; the five commits are unchanged by the rebase.

  • On an x86_64 machine with Ubuntu 26.04.1, timeout is uutils coreutils 0.8.0. When timeout itself receives a TERM from outside, GNU coreutils returns the child's code and uutils returns 143: timeout 900 bash -c 'trap "sleep 1; exit 7" TERM; sleep 30 & wait' & p=$!; sleep 1; kill -TERM $p; wait $p; echo $? prints 143 there and 7 with GNU coreutils 9.4 on a DGX Spark. run_bounded returns timeout's code (the comment above run_bounded states that it expects GNU's), so on such a machine an ended runner reports 143 instead of the binary's code, and the two gpu-gate self-test cases that look for exit 7 expect GNU's behavior. Options: take the binary's code from somewhere other than timeout's status; or require GNU timeout for the gate runners and say so in the tools' requirements.
  • just contrib-check --tier t1 on that Ubuntu machine, with its own timeout, ended total=104 red=1 at d4d899b1 and at main, with check-recipes red. There the load-groups self-test got 15 at d4d899b1 and 124 at main where it expects 143, which is the timeout difference above, and the two gpu-gate cases that look for exit 7 failed at d4d899b1. I ran it once more with GNU timeout 9.7 first on PATH. Those failures were gone and both trees still ended red=1, on the gate-batch self-test's checks that two items sharing a lock never run at overlapping times. Main failed pool: two pool items never overlap in the second run and chain: a big-host item never overlaps a member in the first. d4d899b1 failed chain: no two members overlap (the mutex) in both runs and pool: two pool items never overlap in the second. I did not find why that chain case fails. The same t1 on a DGX Spark ended red=0 at d4d899b1.
  • Red at main too: the DS41 and Qwen3-MoE stub tests on the RTX 5090 machine below, and the gates counted below as "same as base". On the Mac, shellcheck is not installed, at main too.

Code shape

  • No second copy. run_bounded and lease_stop have one owner, tools/gate-bound.sh, which the gate runners already source and lease.sh and stack-watch.sh now source too; the four gate runners, lease_bounded and stack-watch.sh run their bounded children through run_bounded, and perf-decode.sh and load-groups.sh stop their background timeout with lease_stop. The timing runners' bounded children go through lease_bounded, lease_capture or lease_filter. The DS41 and Qwen3-MoE arms, the two preheats and cstate-ab.sh's arms no longer start a timeout of their own. stack-watch.sh keeps its own trap for its loop and its dump.
  • Model code holds only architecture facts. No model code is touched.
  • Dead code is gone. Nothing became unused.
  • No silent failure. lease_filter refuses by name a stream other than stdout or stderr and a call without a filter or a -- command, and checks its bound as lease_bounded does, all with 64 and before the filter starts. A temp dir or FIFO it cannot make returns 70, and so does gate.sh when it cannot make its FIFO. lease_stop reports a group that outlives its KILL and returns 70. dma-dram-share.sh now refuses a leading zero. A runner that is ended still exits with a status, now the binary's, a failed filter fails the arm, and a failed decoder fails perf-decode.sh with its code and the end of its log.
  • Comments state what is true now. tools/check-comments.sh passes at the head on the Mac (mac-static: check-comments rc 0). It also passed on an RTX 5090 machine at d4d899b1, and d4d899b1 differs from the head only in tools/ref/stack-watch.sh.
  • No relaxed gate. gate()'s default bound is still 60 s. One window is wider: the stack-watch dump case allowed [0-7] s and now allows 1?[0-9] s, because its stub gdb now ends six seconds after its TERM. Without the signal passed on, the stub holds until the dump's TERM at 120 s, so the window still tells the two apart. The case carries a PIN(2026-10-15): comment with this reason. No other case changed its expectation.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. No Rust file is touched.

Duplication found or removed (path:line, at main 55acee0b): the same foreground timeout start was in tools/host-gate.sh:25, tools/gate.sh:74, tools/gate.sh:79, tools/gpu-gate.sh:1779, :1794 and :1799, tools/ref/time-gate.sh:38 and tools/ref/lease.sh:461. All of them now go through run_bounded. The DS41 and Qwen3-MoE arms started their own at tools/ref/depth-ds41.sh:1619, :1621, :1730 and :1732 and tools/ref/depth-qwen3moe.sh:2223, :2372 and :2378, the preheats at tools/ref/depth-ds41.sh:1588 and tools/ref/depth-glm5next.sh:820, and cstate-ab.sh at tools/ref/cstate-ab.sh:65. lease_bounded ran inside a substitution or a pipeline in ab-decode.sh (for example tools/ref/ab-decode.sh:58), decode-measure.sh, depth-decode.sh, depth-glm5next.sh, depth-gpu.sh, dma-dram-share.sh, governor-ab.sh, perf-decode.sh, qdot-rate.sh (tools/ref/qdot-rate.sh:49) and expert-union-dump.sh (tools/ref/expert-union-dump.sh:16). All of these now run in the runner's shell through lease_bounded, lease_capture or lease_filter. The background timeouts at tools/ref/perf-decode.sh:31 and tools/ref/load-groups.sh:152 had no stop of their own and now stop through lease_stop. Other runners under tools/ref/ still start some commands under a foreground timeout of their own (for example tools/ref/depth-ds41.sh:1355); they are not changed here. Cancelling and cleaning up the runners that remain is out of scope and tracked in #313.

What I ran

The head, babd6b99, has five commits, one per contract. Against fdff9218 it changes tools/ref/lcpp-warm.sh: the shared llama-server arm that the DS41 and Qwen depth runners use stops its server and timeout group through lease_stop on TERM, INT or HUP, before or after the pid is known and during a request, so the lease is released; its self-test covers those cases, failed with 13 failures before the change and passes after it. It also changes one line of tools/ref/card-tests/run.sh: the tee cleanup check now keeps an existing pid alive when ps cannot read it, and the card tests ran again at the head (card-tests: 735 tests, 0 failed). Both sit on main 55acee0b and were not rebased. Every result below comes from fdff9218, except contrib-check t1, which ran at d4d899b1, and the gates and the two GPU gates marked "at a0776ff3". d4d899b1 differs from the head only in tools/ref/stack-watch.sh (alive and its self-test), 3148d735 differs from d4d899b1 only in tools/ref/lease.sh and tools/ref/load-groups.sh, and a0776ff3 differs from 3148d735 only inside self_test() in tools/ref/stack-watch.sh. At the last check main was d0e8a8e1; the head merges with it without conflicts (git merge-tree).

On a Mac

  • ./tools/mac-static.sh 55acee0b…, with a local edit to tools/check-recipes.sh that starts its blocks two at a time: mac-static: ok.
  • Inside it, check-recipes ran the tool self-tests, among them card-tests: 735 tests, 0 failed, gpu-gate self-test: 109 of 109 ok, stack-watch self-test: ok and gate-batch self-test: 639 of 639 ok, with check-recipes: 57 tool self-tests ok.
  • The shell self-tests, each under Homebrew bash 5.3.20 and under /bin/bash 3.2.57, with LC_ALL=C:
Command bash 5.3.20 /bin/bash 3.2.57
bash tools/ref/stack-watch.sh --self-test stack-watch self-test: ok stack-watch self-test: ok
bash tools/ref/lease.sh --self-test self-test: ok (0 failures) self-test: ok (0 failures), with skip bounded-ds41-load: the runner's bash has no exec {fd}<> and skip bounded-ds41-load-fork: the runner's bash has no exec {fd}<>
bash tools/gpu-gate.sh --self-test gpu-gate self-test: 109 of 109 ok gpu-gate self-test: 109 of 109 ok
bash tools/ref/card-tests/run.sh card-tests: 735 tests, 0 failed card-tests: 735 tests, 0 failed
bash tools/ref/card-tests/cpu-guard.sh cpu-guard: 9 tests, 0 failed cpu-guard: 9 tests, 0 failed
bash tools/ref/load-groups.sh --self-test self-test: ok (0 failures) self-test: ok (0 failures), with skip stall: bash 3.2.57(1)-release has no exec {fd}<>

shellcheck on the changed timing scripts did not run: shellcheck: command not found on that Mac at d4d899b1, the same at main 55acee0b. tools/check-comments.sh ran inside mac-static above.

On a DGX Spark

just contrib-check --tier t1, which runs the t0 units and the host-nightly units, ran at d4d899b1 three times in the bloomery-dev CUDA 13.3.1 container (NVIDIA GB10, driver 595.84). Each run ended DONE tier=t1 total=104 red=0, in 408 s, 298 s and 297 s. The head differs from d4d899b1 only in tools/ref/stack-watch.sh, and t1 was not run again on it. The head's stack-watch self-test passed on a Mac and on an RTX 5090 machine (see their sections). t0 was not run on its own.

On an RTX 5090 machine

The machine runs Ubuntu on x86_64 with GNU bash 5.3.9 and LC_ALL=C. Its own timeout is uutils coreutils 0.8.0, which reports a cancelled run's status differently (see "What I ran into"). The suites therefore ran with GNU timeout 9.7 first on PATH.

Command Result
bash tools/ref/stack-watch.sh --self-test stack-watch self-test: ok
bash tools/ref/lease.sh --self-test self-test: ok (0 failures)
bash tools/gpu-gate.sh --self-test gpu-gate self-test: 110 of 110 ok
bash tools/ref/card-tests/run.sh card-tests: 735 tests, 0 failed
bash tools/ref/card-tests/cpu-guard.sh cpu-guard: 9 tests, 0 failed
bash tools/ref/load-groups.sh --self-test self-test: ok (0 failures)
bash tools/ref/depth-glm5next-stub.sh depth-glm5next-stub: 49 checks, 0 failed
bash tools/ref/depth-ds41-stub.sh depth-ds41-stub: 84 checks, 2 failed, the same line and failures as main 55acee0b on that machine, so not from this change
bash tools/ref/depth-qwen3moe-stub.sh depth-qwen3moe-stub: 86 checks, 1 failed, the same line and failure as main 55acee0b on that machine, so not from this change

The failures are the warm cases: FAIL warm and FAIL warm-fail in the DS41 test, and FAIL warm: rc 0, want 1 in the Qwen3-MoE test. At d4d899b1, with the machine's own timeout, gpu-gate ended 108 of 110 ok and load-groups failed stall-term.

stack-watch's self-test under a child subreaper that does not reap orphans, so an ended child stays a zombie, three runs on CPUs 0 to 3: stack-watch self-test: ok each time, with the dump case dumping: yes, ended in 6 s, left: none in two runs and dumping: yes, ended in 10 s, left: none in the other. In the same setup, 3 of 20 runs of the full self-test at a0776ff3 failed with left: gdb on a DGX Spark, and the process caught each time was an ended gdb in state Z ([gdb] <defunct>). The self-test's checks for a leftover now use alive, which counts a zombie as ended.

Gates at a0776ff3

The gates ran at a0776ff3, before the two helper scripts that differ at the head. tools/affected-gates.sh on those two files selects no gate (0 of 166 gate-recipes selected), so I did not repeat them.

  • tools/affected-gates.sh 55acee0b --no-box at a0776ff3 selects 166 of 166 gate-recipes. Each ran as BLOOMERY_BOX_LOCAL=1 just <recipe>. A gate that failed ran again on main 55acee0b on the same machine, and the two failure lists were compared: gates-affected: 175 gates, ok 32, same as base 143, differs 0, unproven 0. The other gates counted as "same as base" fail at the head and at main with the same failure lines, so they are failures on this machine, not passes. Nine of the 175 are fixture variants (<recipe>@BLOOMERY_FIXTURE_VARIANT=<variant>) that ended with head 64 base 64 same.

GPU gates through run_bounded

tools/gpu-gate.sh starts every GPU gate's binary through run_bounded. One gate ran on each card at a0776ff3, on base 55acee0b. Neither gate reads a model file; both build their inputs from fixed shapes.

  • DGX Spark, nvidia-smi line NVIDIA GB10, 595.84, [N/A]: BLOOMERY_BOX_LOCAL=1 BLOOMERY_ARCH=sm_121 just gate-gpu-kquant printed PASSED: gate_kquant q5k_gemv_sel within 1e-5 of the f64 dequant_row reference at 8 shapes and gpu-gate.sh: gate_kquant ran 1 s (exit 0).
  • RTX 5090 machine, nvidia-smi line NVIDIA GeForce RTX 5090, 595.99.02, 32607 MiB: BLOOMERY_BOX_LOCAL=1 BLOOMERY_ARCH=sm_120 just gate-gpu-p1 printed PASSED: gate_p1 K-quant gemvs within 0.00001 of the q8_1 reference and gpu-gate.sh: gate_p1 ran 7 s (exit 0).

Fail first

I planted each of 28 candidate mutants in a copy of the head's tree on the RTX 5090 machine. The check ran on the mutant, then on the restored copy, and the restored source was compared with the head. 26 of the 28 were caught there at this head. The failure lines in the table are from the run at d4d899b1, except those of the new alive mutant and the ones the run at the head also recorded. The 27 earlier mutants ran again at the head, and each restored copy ended green. One is excluded and one is caught only by BSD awk on a Mac; both are explained below the table. Every row ran with GNU timeout 9.7 first on PATH, because that machine's own timeout ended the restored copy red in three of them at d4d899b1 (the two cleanup-status mutants and the one that sends tee a single TERM). Four rows use a probe outside this PR that sends the TERM inside a delay the mutant plants. On every restored copy the check ended green.

Mutant Check With the mutant
lease_filter sends no signal on after it has reaped the filter lease self-test FAIL bounded-filter-reaped-TERM-off-rc: got [0], want [143], with the same in all four cases of each signal and set -e state, and self-test: FAIL (8 failures)
lg_process sends no signal on after it has reaped the load load-groups self-test FAIL reaped-TERM-off-rc: got [0], want [143], with the same in all four cases, and self-test: FAIL (8 failures)
lease_filter sets no trap of its own and acts on no signal held from before the filter's pid lease self-test reader=alive stderr=open in bounded-filter-open-term-none-reader
run_bounded starts the child before it sets its trap lease self-test left: stub timeout, lease: held in bounded-startup-term
lease_capture takes the output with $(lease_bounded … 2>&1) lease self-test self-test: FAIL (12 failures), among them the preheat and cstate-ab.sh arms
the watch ignores signals while a dump starts probe, TERM before the dump watch still waiting 25 s after the TERM, gdb started: yes, left: gdb
the TERM to an ended dump fails under bash -e probe, watch under bash -e rc 1, ended in 3 s, gdb started: yes, left: command
gate.sh sets no trap before tee probe, TERM before run_bounded runner gone: yes, output ended: no
gate.sh does not act on a signal from before tee's pid probe, TERM before the pid runner gone: no, output ended: no
lease_filter's trap does not end and reap the filter lease self-test reader=alive stderr=open in bounded-filter-open-term-none-reader
perf-decode.sh as it was before the decoder fix lease self-test left: decoder decoder-timeout, lease: held in bounded-perf-record-term
lease_stop sends one TERM to timeout only lease self-test left: stub, lease: held in bounded-fork-term, left: decoder record, lease: held in bounded-perf-fork-term
lg_process sets no signal trap lease self-test left: stub timeout, lease: held in bounded-ds41-load-term
perf-decode.sh's failed decoder exits with its code alone lease self-test no line matches /^decode exited 23: / in bounded-perf-fail-reason
the watch runs its command without run_bounded stack-watch self-test stack-watch self-test: 4 failed
the watch starts its command without a process group of its own stack-watch self-test stack-watch self-test: 2 failed
the watch runs its dump without run_bounded stack-watch self-test left: child, lock after: held in the dump case
lease_stop reads the ps rows without its own IFS lease self-test left: stub, lease: held in bounded-ds41-load-fork-term
alive returns false when ps cannot read the state of a pid that exists stack-watch self-test FAIL a failed state read of an existing pid: alive, with a diagnostic (rc 1, want 0
a stop that fails inside run_bounded no longer changes the runner's exit code gpu-gate self-test rc 0 (want 70) in the case "a failed process read after TERM keeps cleanup failure"
load-groups.sh ignores a failed lease_stop when it stops a load load-groups self-test stall-cleanup-0-rc: got [post 0 rc=0], want [post 0 rc=70]
gate.sh sets no trap before tee and acts on no held signal the card tests' cases that signal right after tee starts tee-four-cases: total=12 failed=2
gate.sh's EXIT trap sends tee one TERM and does not reap it the same cases, 20 runs 7 of the 20 runs red
the readiness check of the signal cases always succeeds lease and stack-watch self-tests bounded-startup-ready: got [no], want [yes]
stub-timeout.py without its own process group, on a PATH with no timeout lease self-test self-test: FAIL (31 failures)
the lease self-test names depth-qwen3moe.sh by its literal path python3 tools/recipes.py --self-test self-test: FAIL (166 gate recipes, 1 failures)

ff-term-ready is not counted. It changes only the lease self-test's own readiness wait and deletes its assertion, so no product behavior differs, and the self-test ends with rc 0 with it.

The awk mutant removes the parentheses around ("sort -rn | head -n " top) in perf-decode.sh. GNU awk accepts that, so the Linux run does not catch it (red=0 restored=0). BSD awk on a Mac does: the lease self-test ended with FAIL bounded-perf-annotate-term-rc: got [2], want [143] there, and ended with rc 0 on the restored copy.

No mutant covers the case where gate.sh cannot make its FIFO.

Hardware (if the change is for a machine)

Not a machine-specific change. The runs used a Mac, one DGX Spark (NVIDIA GB10, driver 595.84) and an RTX 5090 machine (NVIDIA GeForce RTX 5090, driver 595.99.02).

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 16, 2026

@github-actions github-actions Bot 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.

Verdict: MUST_FIX: A cancellation signal can be discarded before the next grouped load starts.

Must fix

1. Replay cancellation recorded after the load is reaped

tools/ref/load-groups.sh:231: TERM or HUP arriving after pid='' on line 229 and before trap reset on line 230 sets lg_sig, but skips lg_stop because the PID is empty. Trap restoration never checks that flag. With another unit queued, the DS41 round loop and Qwen3-MoE round loop continue into another load while holding the timing lease.

Replaying the recorded signal prevents a cancelled run from consuming another load. Replace line 231 with:

  eval "$lg_traps"
  [ -z "$lg_sig" ] || kill -s "$lg_sig" $$

Add a cancellation case immediately after PID clearing. A probe using the trap and reap excerpts prints NEXT_ARM_STARTED and exits 0 for either signal; the replacement prevents that marker and terminates with 143 for TERM or 129 for HUP, with and without set -e.

Checked

Evidence: signal traps, PID clearing, trap restoration, both callers' round loops and lease ownership confirmed. The finding meets kind A; no review exclusion or ledger lesson applies.
Tests: cancellation probes and Bash syntax checks of the suggested replacement passed. Existing load cancellation tests signal a running child and do not cover this post-reap window.
Inline suggestion: line 231 is added by the diff and the replacement is valid Bash.

Notes

Full shell self-tests were not rerun during validation.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Comment thread tools/ref/load-groups.sh
wait "$pid" || rc=$?
pid=''
trap - TERM INT HUP
eval "$lg_traps"

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.

After PID clearing, the trap records cancellation without stopping the runner. Replay that signal after restoring the caller's traps, before another load starts.

Suggested change
eval "$lg_traps"
eval "$lg_traps"
[ -z "$lg_sig" ] || kill -s "$lg_sig" $$

@juliankang4
juliankang4 force-pushed the dgx-spark-gate-timeout-group branch from 3148d73 to e078e39 Compare October 16, 2026 10:22

@github-actions github-actions Bot 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.

Verdict: MUST_FIX: Cancelling a GPU gate leaves a nested Clefvis dump running with inherited lock and output descriptors.

Must fix

1. Forward cancellation through the Clefvis gate wrapper

tools/gpu-gate.sh:1947 runs the Clefvis shell wrapper through an outer timeout. The wrapper starts a second timeout group at tools/ref/clefvis/clefvis.sh:227, without a forwarding trap. On TERM, tools/gate-bound.sh:35 stops the outer timeout and its group; the inner dump survives in its separate group and keeps the inherited card lock and output descriptors until its own bound.

A validator probe returned 143 while the nested command remained alive, its inherited descriptor lock stayed held, and output had no EOF. This is a remaining sibling path in the cancellation fix.
Cost: Fix this caller before relying on cancellation to release card locks.

Reuse lease_bounded for these calls. It also re-raises the signal after cleanup, preventing another arm from starting when the child exits successfully.

--- a/tools/ref/clefvis/clefvis.sh
+++ b/tools/ref/clefvis/clefvis.sh
@@ -61,2 +61,4 @@
 fi
+# shellcheck source=tools/ref/lease.sh
+source "$HERE/tools/ref/lease.sh"
 # shellcheck source=tools/ref/ref-paths.sh
@@ -145,3 +147,3 @@
   SECONDS=0
-  if env CUDA_VISIBLE_DEVICES= timeout --kill-after=10 "$BOUND" "$BIN" chat --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
+  if lease_bounded "$BOUND" env CUDA_VISIBLE_DEVICES= "$BIN" chat --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
       --card cpu --requests "$REQUESTS" "${img_args[@]}" "${seat_args[@]}" --out "$stage" -t "$THREADS"; then
@@ -226,3 +228,3 @@
   SECONDS=0
-  if "${run[@]}" timeout --kill-after=10 "$BOUND" "$BIN" tower --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
+  if lease_bounded "$BOUND" "${run[@]}" "$BIN" tower --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
       --card "$device" "${img_args[@]}" "${pre_args[@]}" "${tap_args[@]}" "${tower_seat_args[@]}" --out-taps "$taps.staging" "${where[@]}"; then
@@ -269,3 +271,3 @@
     SECONDS=0
-    if "${run[@]}" timeout --kill-after=10 "$BOUND" "$BIN" hidden --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
+    if lease_bounded "$BOUND" "${run[@]}" "$BIN" hidden --mmproj "$MMPROJ" -m "$TEXT" --mmproj-sha256 "$MMPROJ_SHA256" \
         --card "$device" --ids "$ids" "${img_args[@]}" --rows "$rows" "${extra[@]}" --out "$dir.staging" \

Extend the cancellation fixture with a shell wrapper containing an inner timeout. Assert that its command ends, the lock is free, output reaches EOF, and no next arm starts. Validator probes using the proposed owner with child TERM statuses 0 and 7 ended the child, reached EOF, and started no next arm. All four patch hunks match the current file, and the patched shell passes syntax checking.

Checked

Duplicates: the proposed fix reuses the existing lease_bounded owner.
Complexity: no Rust functions changed.
Silent failure: followed cancellation through lease_stop, run_bounded and the GPU runner's exit status.
Tests: reproduced the nested-group failure and checked the proposed owner; all 43 changed shell files pass syntax checks, and the changed Python file compiles.
Gates: the stack-watch timing allowance has a dated PIN and reason.
Escape catalog: this finding matches none of C1–C4. No ledger lessons are in force.

Notes

Full self-tests and hardware gates were not rerun by the validator.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot 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.

Verdict: MUST_FIX: One cancellation can force immediate server termination before requests drain.

Must fix

1. Send group TERM only after the monitor exits

tools/gate-bound.sh:35 sends TERM to timeout, which forwards it, then sends TERM to its group. The command can receive two signals from one cancellation. When tools/ref/lease-hold.sh:81 wraps a running server, this can reach its second-interrupt _exit(1) in crates/serve/src/api.rs:822 before pending answers drain.

A shutdown probe completed draining with status 0 in all five monitor-only runs. The current implementation returned 1 after two signals without draining in all five runs. Fixing the shared stop protects its callers together.

Signal the monitor first. Signal surviving group members after the monitor exits; retain the shared deadline and KILL escalation. Add a regression whose first TERM drains and whose second aborts. The replacement below passed that probe and the nonforwarding-monitor case.

lease_stop() {
  local pid=$1 sig target err table p pg state live monitor failed=0 deadline
  for sig in TERM KILL; do
    deadline=$((SECONDS + 10))
    for target in "$pid" "-$pid"; do
      if err=$(LC_ALL=C kill -s "$sig" -- "$target" 2>&1); then :; else
        case $err in
          *'No such process'*) ;;
          *) printf '[bound] cannot send %s to %s: %s\n' "$sig" "$target" "$err" >&2; failed=70 ;;
        esac
      fi
      if [ "$sig" = KILL ] && [ "$target" = "$pid" ]; then continue; fi
      while :; do
        if ! table=$(ps -eo pid=,pgid=,stat=); then
          echo "[bound] cannot read processes while stopping $pid" >&2
          failed=70
          break 2
        fi
        live='' monitor=''
        while IFS=$' \t\n' read -r p pg state; do
          if { [ "$p" = "$pid" ] || [ "$pg" = "$pid" ]; } && [[ $state != Z* ]]; then
            live=1
            [ "$p" != "$pid" ] || monitor=1
          fi
        done <<< "$table"
        [ -n "$live" ] || break 3
        if [ "$sig" = TERM ] && [ "$target" = "$pid" ] && [ -z "$monitor" ]; then break; fi
        if [ "$SECONDS" -ge "$deadline" ]; then
          if [ "$sig" = KILL ]; then
            echo "[bound] $pid or its process group still alive 10 s after KILL" >&2
            return 70
          fi
          break 2
        fi
        sleep 0.1 9>&-
      done
    done
  done
  [ "$failed" = 0 ] || return "$failed"
  wait "$pid" 2> /dev/null || :
  return "$failed"
}

Checked

Evidence: followed lease-hold through run_bounded and lease_stop to the server's signal handler and orderly shutdown wait. The finding is kind A and is outside the exclusion and escape-catalog patterns. No ledger lessons are in force.

Tests: syntax passed for all 44 changed shell files and the changed Python file. The replacement passed syntax and all five draining probes. With a nonforwarding monitor, it also stopped the surviving child group, completed draining and closed output.

Notes

No Rust file changed. Full shell suites and GPU gates were not rerun during validation.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Share bounded process-group cleanup across the gate and lease runners.
Forward signals before PID publication, wait for commands and stack dumps,
and reap filtered-output readers before releasing locks and output.

Cover startup windows, orphaned timeout groups, cleanup failures and FIFO
setup failures with the gate and watcher fixtures.
Capture bounded output in the runner's shell instead of substitutions and
pipelines. Share live FIFO filtering, preserve caller traps and argument
frames, and stop on failed prompts or invalid bounds before starting work.

Use the same owner in depth arms, preheats and C-state runs. Exercise
cancellation, startup gaps, filter cleanup and capture trap ownership.
Hold signals until the load monitor is known, stop its group, and restore
the caller's traps only after reaping it. Keep cleanup failures unless
the command already failed, including extra-arm and idle-timeout paths.

Have memory scopes wait through repeated signals and keep the child's
status. Cover grouped loads, fork-exit monitors and scope cancellation.
Own the background decoder through startup and EXIT cleanup, then leave
later profiling commands under the shared bounded owner. Preserve decoder
failures with a diagnostic log tail and keep the symbol table BSD-awk compatible.

Exercise cancellation before PID publication and during record, annotate
and caller reports, plus decoder and cleanup failure statuses.
Run the remaining profiling, reference, conversion and build commands
through the shared signal owner without an extra timeout supervisor.
Publish monitor PIDs from the bounded child when a runner needs them.

Stop and reap concurrent copy groups on exit, supervise generic lease
holders, and cover a TERM-ignoring profiler through KILL escalation.
@juliankang4
juliankang4 force-pushed the dgx-spark-gate-timeout-group branch from ba4aee3 to babd6b9 Compare October 16, 2026 12:57

@github-actions github-actions Bot 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.

Verdict: CLEAN: The changed runners forward cancellation, wait for owned processes, and preserve failure statuses.

Checked

Duplicates: 15 new helpers checked, including shared test fixtures; no duplicate owner found. Test doubles have distinct fixture roles.
Complexity: no Rust functions changed; the shell cleanup and signal-state branches were reviewed for correctness.
Silent failure: 9 shell status and cleanup paths followed through their consumers; child, reader and cleanup failures remain visible.
Tests: assertions cover signal forwarding, startup traps, cleanup-error propagation, reader-error propagation and next-arm suppression. All 44 changed shell files pass bash -n; both Python files parse. Runtime self-tests and process probes were not rerun during validation.
Gates: the widened stack-watch test window has a dated PIN, a reason and a delayed-gdb fixture that explains the change.
Escape catalog: C1–C4 checked; no matching defect remains in the changed code.
Performance: tools only; no inference hot path changed.

Notes

Dryer and crapper did not run because no Rust file changed.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 438bc48 into midagedev:main Oct 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gpu-gate self-test: the outer timeout leaves the inner gate alive

1 participant