Skip to content

fix: a stalled stdout reader can't block signal wind-down - #162

Merged
natevick merged 3 commits into
mainfrom
natevick/sel-392-stalled-signal
Nov 22, 2026
Merged

natevick merged 3 commits into
mainfrom
natevick/sel-392-stalled-signal

Conversation

@natevick

Copy link
Copy Markdown
Contributor

After SIGTERM, SIGHUP or Ctrl-C, a stalled stdout reader can no longer leave sel test and the runner alive forever.

Linear: SEL-392.

What changed

  • With no --timeout, if a stdout write is still stuck about 12.25 seconds after the signal, sel kills the runner group and exits 130.
  • If stdout has recovered, wind-down continues normally and the reader gets its summary.
  • A hard limit of 24.25 seconds from the signal stops a reader that drips one byte at a time from holding sel open.

Checks

  • Reader that never reads, SIGTERM and SIGHUP: the base commit stays alive. Here it exits 130 at 12.28 s with the runner group gone, 20 of 20 each.
  • Reader that pauses 8 s while the runner ignores SIGINT: same exit code, bytes and summary as the base commit, 10 of 10. The first version of this fix lost the summary here, and a separate re-run of that reviewer's probe now passes 3 of 3.
  • Slow dripping reader: exits by the hard limit, 5 of 5.
  • Healthy reader, no signal, --watch and --timeout: match the base commit.
  • Removing the stuck-write check or the hard limit fails by assertion or timeout.
  • go vet on all three platforms, go test -race, and golangci-lint 1.64.8 pass.

Behavior to know

  • A reader still stuck at 12.25 s is cut off and doesn't get the summary.
  • A stall on stderr alone now ends at about 24.3 s. It used to hang.

Not established

  • The re-check that lets a finished wind-down beat the timer has no test.
  • Committed tests don't drive the stdout write wrapper directly. The real-binary probes do.
  • SIGINT was reproduced by hand and has no CI test.
  • A background child can survive when its group leader has already exited.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 3 commits November 22, 2026 14:13
With a stdout pipe that is open but never read and no --timeout, SIGTERM,
SIGHUP and SIGINT left sel and the runner group alive. Run's event loop was
parked in a blocking write(1) (readerWatch.Write -> format.EventLine ->
run.event), so it never saw the cancelled context and never reaped the
runner. Only a --timeout arms the backstop clock, so nothing bounded it.

Arm a hard exit when a signal is received and the context carries no
backstop clock: after ShutdownBudget + backstopGrace it kills running git
children and the runner group (the cleanups the backstop already runs) and
exits 130. The timer is released when the command's own wind-down finishes,
so a reader that keeps reading still gets its interrupted summary last.

Exit codes outside this path are unchanged: with --timeout the backstop still
decides (8 for TERM/HUP, as before), a closed reader exits before the timer,
and a wind-down that finishes inside the budget releases it. A runner that
needs the whole 12 s budget sits 0.25 s inside the bound; only a 5.7 s
wind-down is tested.

Limits: the bound is absolute, so a reader slower than the bound is cut off
like a stalled one; the cut-off run writes no final summary because stdout
is the thing that is stuck.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
The timer started at the signal and hard-exited 130 when it fired, but the run's own wind-down cannot start until a blocked stdout write returns. A reader that resumed after 8 s, with a runner that ignores SIGINT, was cut off with no summary; the base commit delivered it.

stdout writes are now counted (started, returned). At ShutdownBudget the timer samples the counters and, after backstopGrace, exits 130 only if a write is still in flight and none has returned since the signal. A recovered reader keeps winding down and gets its summary. A hard limit of 2*ShutdownBudget + backstopGrace from the signal still ends a reader that drips. wound is re-checked before any hard exit. A reader that never reads is cut at ShutdownBudget + backstopGrace, as before.

Known edges: a wedge that is not a tracked stdout write (stalled stderr, the watch-mode idle line) now waits for the hard limit instead of the first timer. The wound re-check cannot be tested deterministically: it matters only when the hard limit and the close of wound are ready in the same instant.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
@natevick
natevick marked this pull request as ready for review November 22, 2026 23:57
@natevick
natevick merged commit 9626b13 into main Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant