Repository navigation
[SEL-389] Leave a final JSON line after Ctrl-C during a stuck launch - #156
Merged
Merged
Conversation
…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
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
…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
--json with --timeout, launch stuck in a read it cannot cancel, Ctrl-C before the deadline: exit 130 with empty stdout. The backstop skipped its JSON write after a recorded Ctrl-C, expecting sel test's interrupted summary, which a stuck launch never reaches. Base 85ba618 exited 8 with a timeout object. After a recorded Ctrl-C the final line has one owner, decided atomically under clock.mu: - The interrupted closure in sel test claims first thing, before the Reported check. The backstop then writes nothing to stdout and does not take the guard, whose TryLock is never released and would block the summary. - If the backstop reaches a clean stdout first, it writes one {"error":"interrupted"} object and exits 130, never a timeout object. The closure then writes no summary. With no recorded Ctrl-C (SIGTERM, SIGHUP, no signal, Ctrl-C after the deadline) the claim is a no-op and the backstop runs the same statements as at 39300b0. The write is still one format.Error call. test.go is the only caller of interruptContext. Tests: real process with a FIFO as the client, proven blocked via /proc wchan before the signal (Ctrl-C, no signal, SIGTERM); unit rows for each claim order and the no-Ctrl-C claim. Two #154 tests that pinned empty stdout are updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
added 3 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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
natevick
marked this pull request as ready for review
November 22, 2026 20:51
natevick
changed the base branch from
natevick/sel-389-stderr-stalled
to
main
November 22, 2026 20:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SEL-389 follow-up: with
--json --timeout, a Ctrl-C while launch was stuck in a read it can't cancel exited 130 with empty stdout. It now leaves oneinterruptedobject.Stacked on #154 (
39300b0). Merge #152, #153, #154 and this together.What changed
sel testsummary claim the final line atomically, so only one of them writes it.interruptederror object and exits 130.Checks on
796186839300b0exits 130 with empty stdout. This exits 130 with oneinterruptedobject.-race, and 3/3 with 8 busy loops running.interruptedobject with no Ctrl-C, and a claim with no Ctrl-C.clock.fire, resolved toBoundedError(c.guard.w, c.finalError(ctrlC)). Vet, lint andgo test -racepass (21 packages). The launch, [SEL-391] Keep approval and small fields in --timeout errors #155 and SEL-389 rows pass 3/3.Accepted limit
If a stdout write is in flight at the moment the backstop fires after a Ctrl-C, the backstop spends the claim without writing, so the summary is lost. The exit stays 130.
39300b0wrote the summary in that case (run in a probe). It needs a run still winding down at the 12 s backstop, so it is accepted for v0.4.1.Not established
cmd/seltook 579 s locally on the full candidate, againstgo test's 600 s default. Splitting CI across runners is separate work.🤖 Generated with Claude Code
https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp