Skip to content

[SEL-391] Keep approval and small fields in --timeout errors - #155

Merged
natevick merged 5 commits into
mainfrom
natevick/sel-391-keep-fields
Nov 22, 2026
Merged

natevick merged 5 commits into
mainfrom
natevick/sel-391-keep-fields

Conversation

@natevick

Copy link
Copy Markdown
Contributor

SEL-391 follow-up: under --timeout, #149 dropped fields agents act on and could change doctor's exit code. This keeps them and returns the real code.

Stacked on #149 (badd67a). Merge the two together.

What changed

  • Exit 6 and 7 errors keep a compact approval: id, url, status, expires_at.
  • retry_after_s, attempts, scope and failed_check no longer lose to a long message. The message keeps at least its first 128 written bytes unless the line cap leaves less. The line stays at most 512 bytes.
  • doctor ... 2>&1: the error stays the last JSON line. The full document is skipped when stderr is the file stdout writes to.
  • A stalled stderr no longer turns doctor's exit code into 8. The document write waits at most 125 ms, then the real code returns and the Error: line is skipped.

Checks on 1fe02ec

Not established

  • An approval with a very long URL is still dropped whole.
  • Fields are placed in sorted key order, so a mid-size field could evict a later one. Not seen with the contract's fields.
  • A 422 whose fields alone exceeds 512 bytes still loses fields.
  • Read, not run: a slow stderr can receive a partial doctor document once the 125 ms wait ends.
  • A stalled terminal (Ctrl-S) was not tested. macOS and Windows were vetted, not run.
  • CONTRACT.md is not updated here.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp

Nate Vick and others added 5 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
…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
@natevick
natevick marked this pull request as ready for review November 22, 2026 20:51
@natevick
natevick changed the base branch from natevick/sel-391-cut-json to main November 22, 2026 20:51
@natevick
natevick merged commit 0f66305 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