Skip to content

Contain plugin errors after reload without stopping the server - #5967

Closed
brsbl wants to merge 2 commits into
mainfrom
bb/keep-the-server-up-when-a-reloaded-plugin-errors-thr_csxw97jsa6
Closed

brsbl wants to merge 2 commits into
mainfrom
bb/keep-the-server-up-when-a-reloaded-plugin-errors-thr_csxw97jsa6

Conversation

@brsbl

@brsbl brsbl commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

A plugin CLI continuation could use its disposed API after reload and crash the server (#5964). Core only attributed uncaught errors from background services. The two production crash records both show PluginContextStaleError from host-care after a pending CLI continuation called realtime.publish.

What changed

  • Stale API errors are contained for exceptions and rejections, with one warning per disposed instance.
  • Existing async context now attributes detached route, CLI, RPC, and event failures; the owning live plugin becomes degraded.
  • Unattributed core failures remain fatal. No shipped plugin API or daemon protocol changes.
  • Deferred cancellation/settlement of pending callers to Settle pending plugin callers when their instance is disposed #5969, as requested.

How you verified

  • Remote baseline: seven targeted assertions failed on main plus regression tests.
  • Remote fixed CI: green, including eight regression tests, Linux/Windows server suites, lint, typecheck, and builds.
  • Full Slop Cop: PASS WITH FOLLOW-UPS, no P0/P1; two P2s below.
  • Isolated E2E: both reload races kept PID 3465033; warnings deduplicated, ordinary errors degraded only the fixture, reload recovered it.
Research baseline and reused implementation

Baseline was current main 06ae8f039a7198a6aad2b9b6e030efb88f8dd923. Read the requested source and both October 19/21 crash JSON files in full, without changing production files. Checked each relevant file's history, including the original service supervisor containment change.

Finding / reuse Source
Unclaimed exceptions exit with code 1. Main had no adjacent unhandledRejection listener; default Node behavior promoted rejections to uncaught exceptions. start-server.ts:526–532
The existing AsyncLocalStorage was entered only around service starts and otherwise declined containment. Extended this same store. plugin-runtime.ts:529–565
assertLive throws only after invalidation. The internal error now carries the plugin ID and is cached per handle for weak deduplication. plugin-api.ts:151–159, plugin-api.ts:640–642
Routes, RPC and CLI already use invokeWrapped; event dispatch does too. Attribution fits in the existing runtime, under 100 changed implementation lines. plugin-service.ts:2089–2160, plugin-service.ts:2208–2255, plugin-runtime.ts:895–921
Reused status reporting and instance identity; late failures from already-started old invocations cannot degrade the replacement. plugin-runtime.ts:581–599
Reused migrated DB, app harness and isolated plugin test project; no new test framework. plugin-uncaught.test.ts

Regression coverage: awaited CLI reload with native uncaught exception and unhandled rejection, repeated errors across two generations, stale handle without attribution after disable, detached CLI/route/RPC/event attribution, and rejecting unattributed core failures or a forged stale-error name. Real process survival is checked separately in isolated E2E.

Slop Cop scope and P2 follow-ups

Reviewed exact head e074fe4ec05eb39ea94d30fcfc2c09cfcbf69e43, base 06ae8f039a7198a6aad2b9b6e030efb88f8dd923, using git diff <base>..<head>. Independent security, architecture and code-quality reviewers; author's performance panel and isolated E2E. No P0/P1. Code quality and performance have no additional findings.

  • P2, security/performance: uncaughtExceptionMonitor still writes a diagnostic file before each contained stale exception. A surviving timer can grow diagnostic files despite warning deduplication. Follow up by deduplicating identical error objects in diagnostics.ts:173–185; distinct instances/core errors must still produce diagnostics.
  • P2, architecture: delayed old WebSocket onClose callbacks can begin after the replacement loads. invokeWrapped then captures the replacement, so an ordinary detached failure can degrade it. Follow up by retaining originating instance identity through routes/plugins.ts:357–366; verify a delayed old close leaves the new instance running. Source-confirmed; separate live WebSocket reproduction remains follow-up work.
Isolated end-to-end evidence and QA handoff

Exact head: e074fe4ec05eb39ea94d30fcfc2c09cfcbf69e43. Source pnpm start build, Linux. Fresh empty data directory, dedicated ports; managed temporary job. Every QA CLI write was preceded by a status --json preflight requiring that exact data directory and rejecting production. No production server or plugins changed.

Fixture uncaught5964 registers a CLI handler that writes a started marker, awaits a release file, then schedules two detached calls to its old bb.realtime.publish. Started each request through the real CLI, reloaded while awaiting, and only then released it.

Check Result
Awaiting CLI → reload → two uncaught stale publishes PASS: command settled; old generation 1792554612263 replaced by 1792554638411; server PID 3465033 persisted.
Awaiting CLI → reload → two rejected promises publishing stale handles PASS: replacement generation 1792554663371; same server PID.
Warning deduplication across generations PASS: exactly two stale warnings, one per disposed instance, both naming uncaught5964.
Ordinary detached CLI errors PASS: server survived; only fixture became degraded, detail cli uncaught5964 raised an uncaught error: fixture ordinary uncaught failure.
Recovery PASS: fixture reload restored running; same server PID.

Warning: [plugin:uncaught5964] plugin "uncaught5964" used a stale API handle — it was reloaded or disabled; re-entry happens via a fresh factory call.

The first launch failed before starting because the source checkout lacked generated profile-worker.js. Generated that existing Turbo prerequisite, then the bounded retry passed. This PR must not merge before QA passes.

Fixes #5964

BB-Thread-ID: thr_csxw97jsa6

AGENT GENERATED

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-21T03:53:13.676681Z e074fe4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot closed this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

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.

A plugin's error after reload crashes the whole server

1 participant