Skip to content

[SEL-389] Keep the final summary when stderr is stalled on Ctrl-C - #154

Merged
natevick merged 15 commits into
mainfrom
natevick/sel-389-stderr-stalled
Nov 22, 2026
Merged

natevick merged 15 commits into
mainfrom
natevick/sel-389-stderr-stalled

Conversation

@natevick

@natevick natevick commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SEL-389 follow-up: with stderr stalled and stdout read, a --json Ctrl-C under --timeout now still writes its final summary. On #153 it exits 130 with no final line, which breaks the exit 130 row in contract §3.

Stacked on #153 (6901bbf), which is stacked on #152. Merge them together with #156, which fixes a Ctrl-C during a stuck launch.

What changed

  • After a recorded Ctrl-C, announceInterrupt waits at most 125 ms for the Interrupted notice when stderr is a different file from stdout, then lets the summary go out. The wait ends before the backstop can take stdout.
  • If stderr drains later than that, the notice is lost. The summary still lands.
  • When both are the same file, it keeps waiting, so a 2>&1 reader still gets the summary last.
  • SIGTERM and SIGHUP are unchanged from [SEL-389] Exit 130 when Ctrl-C lands before --timeout and the backstop fires #153: exit 8 with the timeout object when stderr is stalled.

Checks on 39300b0

Each row ran 20 times under -race. The Bound is timeout + 12 s wind-down + 0.5 s.

  • S1: stderr stalled, stdout read. 130, one interrupted summary last, no timeout object, runner gone. Fails on 6901bbf.
  • S2, S3: one read pipe keeps the notice first. One stalled pipe exits 130 within the Bound plus 500 ms.
  • S4: SIGTERM and SIGHUP on a stalled stderr stay at exit 8. Passes on 6901bbf, fails on the first fix attempt.
  • H1: a Ctrl-C just before the deadline still writes the summary. Fails on the first fix attempt.
  • U1 to U3: no timeout object after a Ctrl-C, the bounded wait applies only to different files, and one Interrupted across both paths.
  • Every [SEL-389] Exit 130 when Ctrl-C lands before --timeout and the backstop fires #153 row (G1 to G6, unit) passes 20/20.
  • Ten mutants fail by assertion.
  • CI commands pass (21 packages).
  • Union with [SEL-391] Cap JSON error objects at 512 bytes under an explicit --timeout #149 (badd67ac): one conflict in clock.fire, every row 3/3.
  • Stress: 380 of 380 under -race and load.

Not established

  • Run on 223af62 and 6901bbf: without --timeout, or with --watch --timeout, a stalled stderr still blocks a Ctrl-C indefinitely.
  • 165 timed samples exited past the Bound: 164 by 26 to 73 ms, one by 254 ms under load.
  • Read, not run: on Windows, sameFile treats any two pipes as the same file, so the bounded wait never applies. sel test refuses Windows at launch.
  • macOS and Windows were built, not run.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 11 commits November 21, 2026 15:03
…it (SEL-391)

With an explicit --timeout a hard exit fires if the command is stuck. If
stdout is stalled and an error object is larger than the pipe's atomic
write size, the kernel takes part of it, the write blocks, and the hard
exit leaves an unterminated line on stdout. Any error object can be that
large, not only timeout errors: a network_error with a long hostname was
cut 5 of 5.

When --timeout is given explicitly, an error object on stdout is now at
most 512 bytes including its newline, measured after JSON encoding, and
written in one Write. v, error and message are kept, message shortened
on a UTF-8 boundary if needed. Other fields are kept only while the
object still fits, never partially. sel doctor's object carries
failed_check (the first failing check's name) in place of the doctor
field, and the full document goes to stderr as one {"v":1,"doctor":{...}}
line after the stdout object.

Choices the decision did not cover: a server-supplied error code that
alone cannot fit is shortened to fit, with an empty message; extra
fields are tried in key order and a field that does not fit is skipped,
later smaller ones are still kept. Pending-approval documents are not
error objects and are unchanged.

Without an explicit --timeout, and with --watch (no hard exit), output
is unchanged.

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

When the stdout reader left just as the runner's report_at_finish was
handled, the failed summary write cancelled the run context and drive()
reported the run as interrupted, so a red run exited 130 instead of 1.

runTest now keeps the real exit code when the run was finished
(Summary.Reported), the first cause was the reader leaving, and this is
not --watch. The runner is still stopped and cleaned up as before. Ctrl-C,
SIGTERM and SIGHUP, any reader leaving before report_at_finish, and
--watch still exit 130. The check sits after the runner_error and
reader-gone reclassification so a finished run whose runner lingers
after the reader left also keeps its real code.

Under --watch Watch numbers iterations from 1 and Reported is only set
for iteration 0, so Reported is already false there; the !f.watch
condition is a guard, not something the tests can distinguish.

The fake runner gains FAKE_FINISH_GATE and FAKE_FINISHED_FILE so the
tests force the reader to leave before the runner reports its finish.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
They need no pipe stall, only a child process and a server, so they use
runBinaryIn instead of the Linux-only runCapped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
sel stops the runner as soon as it handles report_at_finish, so a runner
that wrote its finished marker after sending the report could be killed
before writing it. Under load that made the new tests time out waiting
for a marker of a run that had in fact finished (reproduced with
-race, 5 parallel processes and 8 busy-loop hogs).

The marker now precedes the report, and the tests assert it after sel
exits instead of waiting for it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Watch.Run numbers iterations from 1 and Summary.Reported is only set for
iteration 0, so Reported is never true under --watch and the !f.watch
condition could not change any outcome (a mutant dropping it survived
the --watch tests). The --watch tests stay as the pin: a reader leaving
right after an iteration still exits 130.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
A list is not a finished test run, so it keeps the interrupted exit even after the runner reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
When sel test was stuck after a Ctrl-C (stdout never read, so the
interrupt summary could not be written) and the deadline plus wind-down
passed, clock.fire exited 8 and printed the timeout error, although the
user interrupted first.

interruptContext now tells the clock about SIGINT only, and only if it
arrives before the deadline. fire then exits 130 with one Interrupted
line and no timeout object. SIGTERM and SIGHUP keep exit 8, and a Ctrl-C
after the deadline keeps exit 8. The normal path was already correct:
ctx.Err() keeps its first cancel, so a wind-down that crosses the
deadline still ends in 130 (guard rows G1 and G1b).

The Interrupted notice goes through one once-only gate shared by the
normal path and fire, so a stalled run prints it exactly once whichever
gets there first.

Tests force the timing with the fake runner (SIGINT receipt time and a
stop gate) rather than sleeps, and prove each row's ordering. fullPipe
is extracted from the existing stalled-stdout test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
The binary tests cannot force this race, so test the clock directly. Print Interrupted through a sync.Once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
A stalled stderr blocked the Interrupted notice, so a --json run exited
130 with no final line. Wait a bounded time for the notice when stderr
is not stdout. On one shared pipe, keep waiting so the summary stays last.

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

The wait matched the backstop grace, so a Ctrl-C right at the deadline
could still lose the summary. Halve it. Apply it only after a recorded
Ctrl-C, so SIGTERM and SIGHUP keep their existing exit code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Nate Vick and others added 2 commits November 22, 2026 07:02
…under --timeout (SEL-391)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
…or objects (SEL-391)

Under an explicit --timeout the 512-byte error object lost three things the
contract says an agent can rely on, and doctor's stderr document could change
the exit code.

- approval was dropped from every exit 6 and 7 error, including the second
  202's new approval. It is now compacted to id, url, status and expires_at
  (the write object's shape, CONTRACT 5.5) before it is sized. Compaction
  round-trips through JSON because the field is a *api.Approval from the wait
  path and a json.RawMessage from the re-send path.
- message was sized before the other fields, so a long server message evicted
  retry_after_s, attempts, scope and failed_check. Fields are now placed first,
  keeping room for the first 128 written bytes of the message (rounded up to a
  rune boundary), and the message takes what remains. A field that does not fit
  is still dropped whole. The 512-byte cap wins over the 128-byte floor when
  the error code or control-character escapes leave no room.
- doctor ... 2>&1: the stderr document is skipped when stderr is the file
  stdout is written to, so the last JSON line is the error object.
- doctor with a stalled stderr: the document write is bounded by
  backstopExit/2 and, when it lapses, the Error: line (which would block
  behind the partial document) is skipped so the real exit code is returned
  instead of 8.

Not fixed: a 422 whose fields value alone exceeds 512 bytes is still dropped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Nate Vick added 2 commits November 22, 2026 12:22
Co-Authored-By: Claude Opus 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 20:51
@natevick
natevick changed the base branch from natevick/sel-389-ctrl-c-deadline to main November 22, 2026 20:51
@natevick
natevick merged commit 31642fd 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