Skip to content

[SEL-389] Exit 130 when Ctrl-C lands before --timeout and the backstop fires - #153

Merged
natevick merged 12 commits into
mainfrom
natevick/sel-389-ctrl-c-deadline
Nov 22, 2026
Merged

natevick merged 12 commits into
mainfrom
natevick/sel-389-ctrl-c-deadline

Conversation

@natevick

@natevick natevick commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SEL-389: a Ctrl-C before --timeout now exits 130 even when clock.fire (the backstop) ends the process. Before, a stuck sel 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 --json Ctrl-C exits 130 with no final line. Base wrote the timeout object and exited 8. #154 fixes this.

What changed

  • interruptContext tells the clock about SIGINT only, and the clock counts it only before the deadline. SIGTERM and SIGHUP are untouched.
  • fire then exits 130, prints at most one Interrupted line (none when stderr is the stalled pipe), and writes no timeout object or Error: line.
  • The normal path's exit code needed no change. sel test reads ctx.Err(), which keeps its first cancel.

Checks on 6901bbf

The 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.

  • G1/G1b: Ctrl-C before the deadline, wind-down crosses it. 130, 20/20 each.
  • G2: stdout never read, Ctrl-C before the deadline. 130, one Interrupted, no expired, runner gone. 20/20. Base exits 8.
  • G3: hung run, no Ctrl-C: 8, stdout read or stalled, within the Bound plus a 500 ms test allowance. 20/20 each.
  • G4/G4b: Ctrl-C after the deadline: 8, with the timeout object (read) or Error: line (stalled). 20/20 each.
  • G6: SIGTERM and SIGHUP before the deadline, stdout stalled: 8, 20/20 each.
  • Four mutants fail by assertion: fire always 130, Ctrl-C never recorded, no deadline check (unit test only), SIGTERM counted as Ctrl-C.
  • CI commands: vet for linux, darwin and windows, golangci-lint 1.64.8, go test -race ./... (21 packages).
  • Union with [SEL-391] Cap JSON error objects at 512 bytes under an explicit --timeout #149 (badd67ac): one conflict in clock.fire, keeping format.BoundedError with && !ctrlC. cmd/sel passes under -race.
  • Stress: 300 of 300 under -race, 8 busy loops on 32 CPUs.

Not established

  • No row pins the !ctrlC guard on the JSON write. [SEL-389] Keep the final summary when stderr is stalled on Ctrl-C #154 adds one.
  • All 150 stalled samples exited 22 to 62 ms past the Bound, measured from before exec.
  • Read, not run: a Ctrl-C at the deadline before launch can exit 8, and a Ctrl-C after an earlier SIGTERM isn't recorded.
  • macOS and Windows were built, not run.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 9 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
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
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-388-finished-run to main November 22, 2026 20:51
@natevick
natevick merged commit d239405 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