Skip to content

An agent that stops reading its input is a closed connection, not a crash - #270

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/sigpipe
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
fix/sigpipe

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Full test runs crashed about 1 in 16 with swiftpm-testing-helper ... exited with unexpected signal code 13. ACPProcessTransport checked the agent was running, then wrote to its stdin. If the agent exited in between, SIGPIPE ended the whole process. The running app had the same crash.

  • The app, the heed CLI and the test process ignore SIGPIPE at startup (BrokenPipe.ignore(), and a C constructor in a test-only HeedTestProcess target for the test bundle, because Swift Testing has no hook that runs before every test).
  • ACPProcessTransport.send throws ACPError.closed when the write fails.
  • The CLI sets SO_NOSIGPIPE on its hook socket and writes stdout/stderr with write(contentsOf:), so heed watch | head ends quietly.
  • The other writers needed no change: Control, ClaudeInbox and TelemetryServer already set SO_NOSIGPIPE, HookSpool writes to a file, and ProcessRunner and HostEventStream give their child no stdin pipe.

Tests: one agent closes its stdin and keeps running, so the write after the running check is always the one that fails. Another agent exits without reading. A third test checks that the test process ignores SIGPIPE.

Testing the tests:

  • With the constructor's signal call removed, the closed-stdin test kills the run with unexpected signal code 13, the same failure CI showed.
  • With the EPIPE catch removed, both send tests fail on NSCocoaErrorDomain 512 / POSIX 32 Broken pipe.

16 full-suite runs in a row: no signal 13. The only failures were the known theHookStaysFast, plus wall-clock checks under a loaded machine (removalWaitsForTheSummaryButNotForever 3/16, manyAsksAtOnceAreEachAnswered… 1/16). This change does not touch the code those two test.

🤖 Generated with Claude Code

…rash

heed, the heed CLI and the test process now ignore SIGPIPE at startup, so a write to
a pipe or socket whose reader has gone fails with EPIPE instead of ending the process.
That was the 1-in-16 "unexpected signal code 13" in full test runs: ACPProcessTransport
checked the agent was running, then wrote to its stdin, and an agent that exited in
between killed the test run (or the app).

- ACPProcessTransport.send throws ACPError.closed when the write fails.
- The CLI sets SO_NOSIGPIPE on its hook socket, and writes stdout and stderr with
  write(contentsOf:), so `heed watch | head` ends quietly rather than raising.
- The other writers already set SO_NOSIGPIPE (Control, ClaudeInbox, TelemetryServer),
  write to a file (HookSpool) or give their child no stdin pipe (ProcessRunner,
  HostEventStream).

The test process ignores SIGPIPE from a C constructor in a small test-only target,
HeedTestProcess: Swift Testing has no hook that runs before every test, and a trait
or shared helper covers only the tests that opt in. The constructor runs when the
bundle loads, before any test; theTestProcessIgnoresBrokenPipes checks it did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@Mpdreamz
Mpdreamz merged commit d94fb98 into main Nov 16, 2026
5 checks passed
@Mpdreamz
Mpdreamz deleted the fix/sigpipe branch November 16, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant