Repository navigation
Description
Problem
A plugin that touches a stale API handle after it's reloaded crashes the whole production server. On a production server this happened twice:
| When (UTC) | Crash record (<data-dir>/logs/) |
|---|---|
| 2026-10-19 23:48:32 | process-server-uncaughtException-2026-10-19T23-48-32-306Z-….json |
| 2026-10-21 03:32:57 | process-server-uncaughtException-2026-10-21T03-32-57-744Z-….json |
Both records show the same error: PluginContextStaleError: plugin "host-care" used a stale API handle — it was reloaded or disabled. In each case the launcher restarted the server about 30 s later.
How it happens: a host-care CLI request (a heavy start waiting in its queue) was still pending in the old plugin instance when the plugin reloaded. When that request finished, the plugin called bb.realtime.publish(...) through the old handle. assertLive threw PluginContextStaleError, nothing caught it, and the server exited.
Stack: assertLive → realtime.publish → plugin changed() → finish (from the request's continuation), processTicksAndRejections.
Cause (at ab04f04)
apps/server/src/start-server.ts:526-531: the server'suncaughtExceptionhandler askspluginService.handleUncaughtException(error)and callsprocess.exit(1)when that returns false.apps/server/src/services/plugins/plugin-runtime.ts:562-564:handleUncaughtExceptioncontains an error only whenserviceContext.getStore()finds a plugin service run. A continuation of a plugin route or CLI handler (or any plugin async work outside a service run) has no store, so the handler returns false and the server exits.PluginContextStaleErrornames its plugin and means by definition "a disposed instance did something". It is always safe to contain, yet it can still bring the server down.
Expected
A plugin's error after reload or disable is contained and logged against that plugin, and the server keeps running:
- Always contain
PluginContextStaleError(and its rejection form) in the server'suncaughtException/unhandledRejectionhandling. Log it once per plugin and instance, and never exit. - Carry plugin attribution into route, CLI, RPC and event-handler invocations (not only service runs), so other uncaught errors from a plugin are attributed and contained too. That plugin can go degraded instead of the process exiting.
- Optional: when a plugin instance is disposed, settle or reject its in-flight request continuations so stale work doesn't keep running.
Tests
- A server test that reloads a plugin while one of its CLI or route handlers is awaiting, then has that handler call
bb.realtime.publishafter reload. It fails today (the process exits); afterwards the server stays up and a warning names the plugin. - Same for a rejected promise (
unhandledRejection).
Context
The host-care plugin is also being fixed on its side (drain waiting starts before a reload, guard publishes after dispose). But any plugin with long-lived requests can hit this core path.
Activity
bb-slop-cop commentedon Oct 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotplugins.confirmed-repro.Tie each loaded plugin copy's work to that copy across reload, disabl…