Skip to content

Contain stack-less uncaught errors from work a plugin started - #7849

Merged
ymichael merged 1 commit into
get-bb:mainfrom
lanjak:fix-7509-frameless-abort-error
Nov 20, 2026
Merged

ymichael merged 1 commit into
get-bb:mainfrom
lanjak:fix-7509-frameless-abort-error

Conversation

@lanjak

@lanjak lanjak commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

The server's uncaughtException handler exits unless the plugin runtime claims the error (start-server.ts#L606-L612). Outside a service run, the runtime claims an error only when a loaded plugin's code file appears in its stack (plugin-runtime.ts#L610-L645).

The error in #7509 is what an aborted fetch rejects with. undici re-captures the stack after an await. The result is AbortError: This operation was aborted with no frames on Node 24, which the desktop app runs, and with only an node:internal/deps/undici frame on Node 22. undici also rewrites the stack of the shared signal.reason, so anything else that later throws that reason has the same stack. When plugin code leaves such a rejection unhandled, the stack names no plugin and the server exits. This is how one plugin's floating aborted fetch can restart the whole server several times a day.

What changed

  • apps/server/src/services/plugins/plugin-runtime.ts:
    • A new AsyncLocalStorage, pluginCodeContext, names the plugin. It is set around the plugin's module import, its factory and invokeWrapped, which every handler, hook, provider, RPC, route, CLI and event call goes through.
    • Node runs the uncaughtException handler in the async context of the throwing callback or the rejected promise, so the handler can read it.
    • containPluginError still decides by stack location first. Only when the stack names no code outside node: internals does it fall back to that context.
    • A claimed error is logged as [plugin:<id>] uncaught error from work this plugin started (its stack names no code): ..., and the plugin's status detail is set as before.
  • Deviation from the issue's ask: the server still exits for core errors. A core error with frames is never claimed by context, including core work started during a plugin call (Tie each loaded plugin copy's work to that copy across reload, disable and removal #6464's test is unchanged and passes).
  • Accepted risk: a stack-less error from core work that a plugin call started is attributed to that plugin and contained. Such an error carries no evidence either way, and before this change it took the server down.
  • Not identified: which plugin aborted the fetch in the reporter's crashes. With this change the log names it.
  • No wire, schema, CLI, SDK or plugin API changes.

How you verified

  • New test in apps/server/test/services/plugins/plugin-instance-lifecycle.test.ts, "contains an aborted fetch's frameless error from work a plugin started". The fixture plugin aborts a real fetch to a local server that never answers and rethrows the rejection from a detached callback. On main it fails: 0 errors claimed. With the change, 1 is claimed and the plugin stays running with the message in its status detail.
  • New test "does not claim a frameless error from work no plugin started": the same error from test code is not claimed.
  • A standalone script on Node 22.23.5 and Node 24.22.1 confirms what the tests depend on: the aborted-fetch error names no code outside node:, and the handler sees the plugin's context. The server test suite itself only runs on the Node 24 build here.
  • pnpm exec turbo run test --filter=@bb/server -- test/services/plugins test/plugins passes (61 files, 603 tests).
  • pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/server passes, and oxfmt is clean.

Fixes #7509

AGENT GENERATED

An aborted fetch rejects with an AbortError whose stack names no code:
no frames at all on Node 24 (the desktop runtime) and only an undici
frame on Node 22, because undici re-captures the stack after an await.
When a plugin left such a rejection unhandled, the server could not find
a plugin location in the stack and exited (get-bb#7509).

Run the plugin's module import, factory and every wrapped invocation in
an AsyncLocalStorage context that names the plugin. The uncaught handler
still decides by stack location first. Only when the stack names no code
outside node: internals does it fall back to that context, so a core
error with frames, including core work started during a plugin call,
still exits the server.
@lanjak
lanjak force-pushed the fix-7509-frameless-abort-error branch from 69a3cc4 to 2906be1 Compare November 19, 2026 19:01
@ymichael
ymichael merged commit 906220b into get-bb:main Nov 20, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server exits on an uncaught AbortError with no stack frames, which plugin containment cannot attribute

2 participants