Skip to content

Host daemon crashes on unhandled EPIPE from the watcher child ping, killing every thread on the host #1505

Closed

Description

@AndrewSB

Summary

An unhandled write EPIPE in the host daemon's parcel watcher channel crashes the entire daemon. Every thread running on that host dies with "Thread interrupted because the host daemon disconnected", losing whatever work was in flight.

This has fired 5 times on my host (bb-app 0.36.0, Linux, node v22.22.3). Two of those crashes killed 8 threads outright, including three recovery threads that had each been working for ~1h20m.

Root cause

packages/host-watcher/src/parcel-subprocess/fork-channel.ts:37-41

send(message: ParentToChildMessage) {
  if (child.connected) {
    child.send(message);
  }
},

child.connected is not a sufficient guard: it stays true while the IPC channel is tearing down, so child.send() can still fail with EPIPE. There is no try/catch, no send callback, and no 'error' listener on the child.

The proxy pings the child from a bare setInterval (parcel-watcher-proxy.ts:129-155), so the throw has nothing above it to catch — it escapes as an uncaughtException and takes down the daemon:

Error: write EPIPE
    at target._send (node:internal/child_process:877:20)
    at target.send (node:internal/child_process:751:19)
    at Object.send (bb-app/host-daemon/dist/daemon-bundle.mjs:44:827)
    at Timeout._onTimeout (bb-app/host-daemon/dist/daemon-bundle.mjs:44:1550)
    at listOnTimeout (node:internal/timers:585:17)

Why the race opens

The window is widest exactly when the daemon is already unhealthy. Both of my recent crashes were preceded by severe event-loop starvation:

"msg":"Host daemon event loop stalled","maxDelayMs":11542.7,"meanDelayMs":11538.5
"msg":"Host daemon heartbeat timer delayed","gapMs":403139,"heartbeatIntervalMs":5000
"msg":"Watcher child unresponsive; killing","sinceLastPongMs":21436

A stalled event loop delays the ping timer well past a child's exit — so when the timer finally fires, the child is gone but its exit event has not been processed and connected is still true. The ping goes into a dead pipe and the daemon dies.

Timeline from my host (all UTC, 2026-08-12):

Time Event
21:03:52 last log line, gapMs: 317452
21:03–21:17 daemon logs nothing (stalled)
21:17:18 write EPIPE uncaughtException, daemon dies
21:17:53 daemon restarts; 3 threads already lost

The irony is that createParcelWatcherProxy is explicitly built to survive a dying child — it kills, respawns, and replays every subscription. The one path it doesn't survive is the send that discovers the child is dead.

Impact

The blast radius is the whole host, not the watcher. A file-watcher IPC hiccup terminates every running agent thread, and long-running threads are the most expensive ones to lose. The failure also isn't provider-specific — my crashes took out codex and claude-code threads together.

Fix

PR incoming: make the channel's send non-throwing and treat a send failure as "this child is gone", reporting it through the exit path the proxy already recovers from — plus an 'error' listener, since an unhandled 'error' event on the ChildProcess is the same fatal outcome by another route.

Note this only addresses the crash. The underlying event-loop stalls are a separate issue; after the fix the watcher recycles cleanly instead of taking the daemon with it.

AGENT GENERATED: by Claude Opus 5

Activity

  1. AndrewSB commented on Aug 13, 2026

    @AndrewSB
    ContributorAuthor

    Fix up in #1506 — makes the channel's send non-throwing and routes a failed send through the exit path the proxy already self-heals from, plus an 'error' listener for the other unhandled route.

    Regression-tested by reverting the guard: 4 of the 5 new cases fail with exactly the EPIPE escape.

    AGENT GENERATED: by Claude Opus 5

  2. added theissue type on Aug 13, 2026
  3. added a commit that references this issue on Aug 14, 2026
    5ecdd69
  4. added a commit that references this issue on Aug 22, 2026
    995c1ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions