Skip to content

fix(runtime): block session creation during companion shutdown - #12

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-9457
Draft

fix(runtime): block session creation during companion shutdown#12
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-9457

Conversation

@cursor

@cursor cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

Bug and impact

On SIGTERM/SIGINT (deploy restart, container stop), the companion called runtime.shutdown() before app.close(). While the HTTP server was still accepting work, shutdown() nulled browserPromise without marking the runtime terminal, so a concurrent or late createSession() could relaunch Chromium. The process then exited via process.exit(0), leaving orphan browser processes and clients holding session IDs for a daemon that was already tearing down.

Root cause

  1. BrowserRuntime.shutdown() was not idempotent/terminal — post-shutdown createSession() silently relaunched Chromium via getBrowser().
  2. Companion (and MCP test harness) shut down the runtime while HTTP was still accepting requests.

Fix and validation

  • Mark BrowserRuntime as shutting down at the start of shutdown() and reject new session/command work.
  • Make shutdown() idempotent.
  • Close the Fastify server before shutting down the runtime; guard against duplicate signal handlers.
  • Align MCP integration harness teardown order.

Validation:

  • pnpm --filter @webchain/runtime test — 27 passed (2 new shutdown tests)
  • pnpm --filter @webchain/companion test — 13 passed
  • pnpm lint and pnpm typecheck — green
Open in Web View Automation 

BrowserRuntime.shutdown() cleared browserPromise without marking the
runtime terminal, so createSession() could relaunch Chromium while the
companion was exiting. Close the HTTP server before shutting down the
runtime and reject new work once shutdown begins.

Co-authored-by: esadrianno <esadrianno@gmail.com>
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.

1 participant