Skip to content

[SEL-391] Cap JSON error objects at 512 bytes under an explicit --timeout - #149

Merged
natevick merged 3 commits into
mainfrom
natevick/sel-391-cut-json
Nov 22, 2026
Merged

natevick merged 3 commits into
mainfrom
natevick/sel-391-cut-json

Conversation

@natevick

@natevick natevick commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SEL-391. With an explicit --timeout, a JSON error object larger than the pipe's atomic write could be cut by the hard exit when stdout is stalled. Now, once the command has started, each JSON error object on stdout is at most 512 bytes including its newline, in one Write.

Do not merge without #155, which keeps approval and other fields this PR drops under --timeout.

Changes (explicit --timeout only)

  • format.BoundedError keeps v, error, message, shortens message on a UTF-8 boundary, keeps other fields only while they fit.
  • sel doctor: stdout carries failed_check instead of doctor; the full document goes to stderr as one {"v":1,"doctor":{...}} line after the stdout object.
  • Without --timeout, error and run output match v0.4.0. The only change is four new lines in sel doctor's help.

One exit code change. When a pipe had room for only part of an oversized error, it was cut and exited 8. The smaller object now lands and exits with its real code (4 for network_error, 5 for a 422). A completely full pipe still exits 8.

Choices the decision did not cover

  • Keyed on the hard exit being armed: an error before the command starts (extra argument, 682 bytes) keeps the old output; so does --watch, not measured.
  • A long message can crowd out failed_check. A field that does not fit is skipped.
  • Success and pending-approval documents are not capped.

Needs a decision

  • A non-doctor error whose server echoes the token prints it, with or without --timeout, on v0.4.0 too. Doctor redacts. Fixing it changes output without --timeout, so untouched.

Checks (lanes/lane-3/evidence/sel391/, v041/second-opinion-2.md)

  • The PR's stalled-stdout tests, including network_error and 2>&1: red on 8bb9d50b, green here, 20 of 20 in an independent rerun. Cap bypassed: red by assertion.
  • Gate harness on head: 135 slow, 49 fast runs, 0 flagged. No-guard control under 24 busy loops: 2 of 108 spliced on 8bb9d50b, 0 of 135 on head.
  • CI commands (vet and builds on three OSes, golangci-lint 1.64.8, go test -race, 21 of 21) pass on this head. The 57 clock, backstop, reader and hangup tests ran 20x under -race on 1edcf3e; on this head only the 3 new ones.

Not run or not established

  • macOS, Windows at runtime, a socket as stdout.
  • A success document over the atomic limit can still be cut, as can the doctor stderr line under 2>&1.
  • No unit test of BoundedError.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 3 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
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
@natevick
natevick marked this pull request as ready for review November 22, 2026 20:51
@natevick
natevick merged commit 426c59d 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