Repository navigation
[SEL-389] Exit 130 when Ctrl-C lands before --timeout and the backstop fires - #153
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
…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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
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: a Ctrl-C before
--timeoutnow exits 130 even whenclock.fire(the backstop) ends the process. Before, a stucksel test(stdout never read) exited 8 with the timeout error.Stacked on #152 (SEL-388,
85ba618).Known regression, do not merge alone
With stderr stalled and stdout read, a
--jsonCtrl-C exits 130 with no final line. Base wrote the timeout object and exited 8. #154 fixes this.What changed
interruptContexttells the clock about SIGINT only, and the clock counts it only before the deadline. SIGTERM and SIGHUP are untouched.firethen exits 130, prints at most oneInterruptedline (none when stderr is the stalled pipe), and writes no timeout object orError:line.sel testreadsctx.Err(), which keeps its first cancel.Checks on
6901bbfThe Bound is timeout + 12 s wind-down + 0.5 s. Only G2 fails on base. The other rows are guards, run once each on base without
-race.Interrupted, noexpired, runner gone. 20/20. Base exits 8.Error:line (stalled). 20/20 each.firealways 130, Ctrl-C never recorded, no deadline check (unit test only), SIGTERM counted as Ctrl-C.go test -race ./...(21 packages).badd67ac): one conflict inclock.fire, keepingformat.BoundedErrorwith&& !ctrlC.cmd/selpasses under-race.-race, 8 busy loops on 32 CPUs.Not established
!ctrlCguard on the JSON write. [SEL-389] Keep the final summary when stderr is stalled on Ctrl-C #154 adds one.exec.🤖 Generated with Claude Code
https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp