Repository navigation
Description
Summary
A plugin background service can terminate the entire bb server process, and with it every host daemon connection. plugin-runtime.ts already supervises services well, but that supervision only observes the promise chain. Errors raised out-of-band — an EventEmitter 'error' with no listener, a detached promise rejection, a throw inside a timer callback — bypass it entirely and reach uncaughtExceptionMonitor, which by design observes and lets the process die.
This is a feature request, so per CONTRIBUTING.md I am opening an issue before any pull request.
Production evidence
On bb 0.35.1, Ubuntu 22.04, 4 cores / 4.9 GiB:
- 1321 identical crash dumps over five days, in
~/.bb/logs/process-server-uncaughtException-*.json - Steady cadence of one every ~5m11s: 278, 278, 276, 279 crashes per day
- Every dump identical:
Error: Socket timeout, thrown fromimapflow - Each crash dropped the host daemon's connection. The database recorded 1613
host_daemon_sessionsclosed asreplacedagainst only 7 asdaemon-disconnect - User-visible symptom was
Thread interrupted because the host daemon disconnected
The cause was a bug in my own plugin: an ImapFlow client constructed without an 'error' listener. That part is entirely my fault and is fixed. The issue I am raising is that a plugin-level mistake of this kind can take down the host.
Mechanism
runService at apps/server/src/services/plugins/plugin-runtime.ts:427 wraps the service's start() and routes rejections to onServiceSettled, which restarts with capped exponential backoff. That is a good supervisor, and for promise-chain failures it works exactly as intended.
But the failure above never enters that chain. imapflow raises its socket timeout from a timer callback on a later tick:
Error: Socket timeout
at TLSSocket.<anonymous> (imapflow/lib/imap-flow.js:1263:29)
at TLSSocket.emit (node:events:509:28)
at Socket._onTimeout (node:net:740:8)
at Timeout.onStreamTimeout (node:internal/stream_base_commons:237:10)
ImapFlow is an EventEmitter, and Node rethrows an 'error' event with no listener as an uncaught exception. There is no promise linking that throw back to start(), so:
- the
try/finallyinside the plugin's own IMAP wrapper cannot see it - the
.catch()the plugin had around its poll cycle cannot see it runService's rejection handler cannot see it
It goes straight to installSafeProcessDiagnostics (packages/process-utils/src/index.ts:257), which registers uncaughtExceptionMonitor. The monitor variant deliberately does not intervene, so Node's default behavior applies and the process exits. The comment at line 271 makes clear this is intentional, and for server-owned code it is the right call.
The same hole applies to any detached promise rejection or raw setTimeout/setInterval throw originating in plugin code.
Why the attribution gap is the real cost
All 1321 dumps name imapflow. Not one names the plugin that owns it. Nothing in bb records which plugin's async context the throw came from.
From an operator's seat, a misbehaving plugin is indistinguishable from bb itself being broken. I spent five days assuming I had a host daemon connectivity problem, because that is what the symptom looks like from the UI. The daemon had 7 days of uptime the entire time.
Proposed direction
- Run each plugin background service inside its own
AsyncResource(orAsyncLocalStoragecontext) so out-of-band throws can be attributed to the owning plugin. - Route attributed failures into the backoff-and-restart path that
onServiceSettledalready implements. - Auto-disable a plugin that crash-loops, surfacing it the same way
reportNeedsConfigurationsurfaces configuration failures. - Include the owning plugin id in the crash diagnostic when attribution succeeds.
Known tradeoff
Point 2 requires switching from uncaughtExceptionMonitor to uncaughtException so the handler can actually intervene. Node's documentation is explicit that resuming after an uncaught exception can leave corrupt state, and the current choice looks deliberate rather than accidental. I do not want to hand-wave that.
The fully robust alternative is out-of-process plugin hosting: run each plugin in a worker thread or child process so a crash is structurally unable to reach the server. That is a much larger change. BbPluginApi currently hands plugins live objects (bb.sdk, bb.log, bb.slots) and callbacks that do not serialize across a process boundary, every existing plugin would need rewriting or shimming, and each plugin process carries its own ~40-80 MB Node runtime. On a 4.9 GiB host running 17 plugins that overhead is significant.
I would happily take the cheaper in-process boundary if out-of-process hosting is not on the roadmap. Step 4 alone (attribution in the crash dump) would have saved me most of those five days, and carries none of the uncaughtException risk.
Related
- Provider processes need one host-daemon lease owner tied to active turns #1363 — same shape of ownership gap for provider processes
- Host lacks global admission control across work sources #1393 — records the identical
Thread interrupted because the host daemon disconnectedsymptom
Happy to work on this once there is agreement on which direction is wanted.
Activity
SawyerHood commentedon Aug 18, 2026
Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1746.html
The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at
16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).Route plugin service uncaught exceptions to the service supervisor (#…