Skip to content

A plugin's error after reload crashes the whole server #5964

Closed

Description

@brsbl

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's uncaughtException handler asks pluginService.handleUncaughtException(error) and calls process.exit(1) when that returns false.
  • apps/server/src/services/plugins/plugin-runtime.ts:562-564: handleUncaughtException contains an error only when serviceContext.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.
  • PluginContextStaleError names 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:

  1. Always contain PluginContextStaleError (and its rejection form) in the server's uncaughtException / unhandledRejection handling. Log it once per plugin and instance, and never exit.
  2. 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.
  3. 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.publish after 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

  1. added theissue type on Oct 21, 2026
  2. added
    plugins
    confirmed-repro
    on Oct 21, 2026
  3. bb-slop-cop commented on Oct 21, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · High priority · Medium effort · plugins.
    • Report: Reproduction and root-cause report — REPRODUCED, high confidence.
    • Evidence: The regression fails on trusted main and again in a second clean checkout: stale CLI exceptions and rejected promises both exit with code 1. Reproduction label: confirmed-repro.
    • Root cause: Process-level containment recognizes background-service contexts only; stale API errors and detached handler failures lack attribution and fall through to the fatal server handler.
    • No new PR: #5967 is already open and linked, so a duplicate fix was not pushed. Its diff was reviewed statically, not executed.

    AGENT GENERATED

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

    confirmed-reproplugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions