Skip to content

fix(worker): preload the Workflow bundle only when an inspector is active - #2695

Open
burrows99 wants to merge 2 commits into
temporalio:mainfrom
burrows99:fix/worker-preload-abort-on-uncaught-exception
Open

burrows99 wants to merge 2 commits into
temporalio:mainfrom
burrows99:fix/worker-preload-abort-on-uncaught-exception

Conversation

@burrows99

@burrows99 burrows99 commented Nov 15, 2026 •

Copy link
Copy Markdown

What was changed

parseWorkflowCode now preloads the Workflow bundle only when an inspector is active (inspector.url() !== undefined). Without an inspector it skips the preload.

A regression test in test-bundler.local.ts runs parseWorkflowCode in a child process started with --abort-on-uncaught-exception and expects exit status 0. A changelog fragment is added under fixed.

Why?

The preload evaluates the bundle in an empty vm context so that debuggers resolve breakpoints reliably. That evaluation throws a TypeError (globalThis.__webpack_module_cache__ is undefined), which the surrounding try/catch ignores. Under --abort-on-uncaught-exception V8 does not see a handler across the vm context boundary, so it aborts the process before the Worker starts.

The issue suggests making the preload conditional on the presence of a debugger, since it is expensive and only useful to one. This PR does that and nothing more.

flowchart TD
    A[Worker parses the Workflow bundle] --> B{Node runs with abort on uncaught exception}
    B -->|Before| C[Preload throws in vm context and V8 aborts]
    B -->|After| D[No inspector so no preload and Worker starts]
Loading

Narrated and captioned recording, before then after:

evidence.mp4

Commands shown in the recording, with the fix reverted and then restored (output trimmed to the test result):

git checkout upstream/main -- packages/worker/src/worker.ts
pnpm -s -F @temporalio/worker run build
pnpm -s ava lib/test-bundler.local.js -m "*abort*"
  parseWorkflowCode does not abort a process started with --abort-on-uncaught-exception (#1578)

  Uncaught TypeError: Cannot read properties of undefined (reading '../workflow/lib/worker-interface.js')
  ...
  Difference (- actual, + expected):

    {
  -   signal: 'SIGTRAP',
  +   signal: null,
  -   status: null,
  +   status: 0,
    }

  1 test failed
git checkout HEAD -- packages/worker/src/worker.ts
pnpm -s -F @temporalio/worker run build
pnpm -s ava lib/test-bundler.local.js -m "*abort*"
  ✔ parseWorkflowCode does not abort a process started with --abort-on-uncaught-exception (#1578) (654ms)

  1 test passed

Checklist

  1. Closes [Bug] Worker fails to start if Node option --abort-on-uncaught-exception is set #1578

  2. How was this tested:

    • The new test fails on main (child killed by SIGTRAP) and passes with the change, as shown above.
    • pnpm ava lib/test-bundler.local.js lib/test-worker-lazy-bundler.js: 16 tests passed.
    • With --inspect=0 the preload still runs once; without an inspector it does not run.
    • tsc --build for the worker and test packages, oxlint, oxfmt --check, pnpm changelog:check and commitlint pass.
    • I ran this on macOS arm64 with Node 22, using the prebuilt 1.25.0 core bridge rather than one built from this tree. I did not run the integration suite or the Bun tests.

    Two things reviewers should know:

    • A debugger attached after the bundle was parsed (for example through SIGUSR1) no longer gets the preload. Starting Node with --inspect keeps today's behavior.
    • This fixes startup only. With the same guard applied to the published 1.25.0 packages, a Worker under --abort-on-uncaught-exception starts and completes Workflows against a local dev server, but the process still aborts at worker.shutdown() with Uncaught ShutdownError: Worker has been shutdown, raised from the native bridge. That is a separate abort site and is not addressed here. An inspector combined with this flag also still aborts in the preload. Say if you would rather keep the issue open for those.
  3. Any docs updates needed?

    No.

AI assistance (Claude Code) was used to prepare this change.

🤖 Generated with Claude Code

…tive

parseWorkflowCode evaluates the bundle in an unconfigured vm context so that
debuggers resolve breakpoints reliably, and ignores the TypeError this throws.
Under --abort-on-uncaught-exception V8 treats that error as uncaught, because
it does not see the handler outside of the vm context, and aborts the process
before the Worker starts.

Skip the preload unless an inspector is active. It only benefits a debugger.

Fixes temporalio#1578
@burrows99
burrows99 requested a review from a team as a code owner November 15, 2026 00:00
@CLAassistant

CLAassistant commented Nov 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

[Bug] Worker fails to start if Node option --abort-on-uncaught-exception is set

2 participants