Skip to content

Add first-class serialization for FatalError and RetryableError#1513

Open
TooTallNate wants to merge 2 commits intomainfrom
nrajlich/error-class-serde
Open

Add first-class serialization for FatalError and RetryableError#1513
TooTallNate wants to merge 2 commits intomainfrom
nrajlich/error-class-serde

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Mar 24, 2026

Summary

  • Add WORKFLOW_SERIALIZE / WORKFLOW_DESERIALIZE static methods to FatalError and RetryableError in @workflow/errors
  • Add @workflow/serde as a dependency of @workflow/errors
  • This enables the SWC plugin to discover and register these classes through the standard class serialization pipeline — no manual registration or explicit serialization entries needed
  • Add unit tests verifying Instance-based round-trip serialization
  • Add e2e workflow tests verifying class identity preservation end-to-end (instanceof FatalError, instanceof RetryableError)

Context

This is PR 3 of 5 in a series to improve error handling in Workflow DevKit. Stacked on top of #1512.

  1. Add first-class serialization for built-in Error subclasses #1511 — First-class serde for built-in Error subclasses
  2. Add DOMException to VM context and first-class serialization support #1512DOMException serde support
  3. This PRFatalError and RetryableError serde
  4. Serialize thrown step errors through the devalue pipeline (event log format change)
  5. Serialize thrown workflow errors through the devalue pipeline

Design

Rather than adding explicit reducer/reviver entries to the serialization pipeline (the approach in PRs 1-2 for built-in JS types), FatalError and RetryableError use the custom class serialization flow — the same mechanism user-defined classes use:

  1. The classes declare static [WORKFLOW_SERIALIZE]() and static [WORKFLOW_DESERIALIZE]() methods
  2. The SWC plugin discovers these during build and generates classId + registration IIFEs in each bundle context (step, workflow, client)
  3. The existing Instance reducer/reviver handles serialization and deserialization automatically
  4. Cross-VM behavior is correct: each bundle context registers its own class reference, so instanceof works in all contexts

This is the right approach because:

  • FatalError and RetryableError are not global constructors (unlike TypeError, DOMException) — they're named exports from @workflow/errors
  • The SWC plugin already handles discovery of serde symbols on imported classes
  • No changes needed to @workflow/core's serialization pipeline — the Instance flow handles everything

Test plan

  • 6 new unit tests in serialization.test.ts verifying round-trip serialization for both classes (type preservation, stack, retryAfter, Instance serialization key)
  • 2 new e2e workflow tests in 99_e2e.ts + e2e.test.ts verifying class identity preservation (instanceof, FatalError.is(), custom properties) through the full step → workflow error boundary
  • All 525 core package unit tests pass
  • Both packages build cleanly with tsc

Note: The e2e tests require a running dev server with the SWC plugin active to validate the full discovery → registration → serialization → deserialization pipeline.

@TooTallNate TooTallNate requested a review from a team as a code owner March 24, 2026 21:57
Copilot AI review requested due to automatic review settings March 24, 2026 21:57
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 728d056

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@workflow/errors Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/core Patch
workflow Patch
@workflow/world-local Patch
@workflow/world-postgres Patch
@workflow/world-vercel Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/vitest Patch
@workflow/world-testing Patch
@workflow/web-shared Patch
@workflow/ai Patch
@workflow/nuxt Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Apr 6, 2026 6:03am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Apr 6, 2026 6:03am
example-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-astro-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-express-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-fastify-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-hono-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-nitro-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-nuxt-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-sveltekit-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workbench-vite-workflow Ready Ready Preview, Comment Apr 6, 2026 6:03am
workflow-docs Ready Ready Preview, Comment, Open in v0 Apr 6, 2026 6:03am
workflow-swc-playground Ready Ready Preview, Comment Apr 6, 2026 6:03am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 24, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ ▲ Vercel Production 868 22 67 957
❌ 💻 Local Development 782 22 153 957
❌ 📦 Local Production 842 24 178 1044
❌ 🐘 Local Postgres 842 24 178 1044
❌ 🪟 Windows 77 2 8 87
❌ 🌍 Community Worlds 134 67 24 225
❌ 📋 Other 213 6 42 261
Total 3758 167 650 4575

❌ Failed Tests

▲ Vercel Production (22 failed)

astro (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

example (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

express (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

fastify (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

hono (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nitro (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nuxt (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

sveltekit (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

vite (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
💻 Local Development (22 failed)

astro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

express-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

fastify-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

hono-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-canary (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nitro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nuxt-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

sveltekit-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

vite-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
📦 Local Production (24 failed)

astro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

express-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

fastify-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

hono-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-canary (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack-canary (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nitro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nuxt-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

sveltekit-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

vite-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
🐘 Local Postgres (24 failed)

astro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

express-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

fastify-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

hono-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-canary (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-turbopack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack-canary (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nextjs-webpack-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nitro-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

nuxt-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

sveltekit-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

vite-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
🪟 Windows (2 failed)

nextjs-turbopack (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
🌍 Community Worlds (67 failed)

mongodb (5 failed):

  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KNGP643DPJ3CMCR2Q53BCQBG
  • webhookWorkflow | wrun_01KNGP6D6VQQGGZEVAY7MF0QKA
  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KNGPFPZYJ1CKYB76CP39WTD0

redis (4 failed):

  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KNGP643DPJ3CMCR2Q53BCQBG
  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KNGPFPZYJ1CKYB76CP39WTD0

turso (58 failed):

  • addTenWorkflow | wrun_01KNGP51680JYGAFY0D055VGE1
  • addTenWorkflow | wrun_01KNGP51680JYGAFY0D055VGE1
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01KNGP76SAMT0Y4K2SGS6DCP0B
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01KNGP57BZH2D25K3VAF2JJYVA
  • promiseRaceWorkflow | wrun_01KNGP5BNGXR2EHJEB0X7ZHQFT
  • promiseAnyWorkflow | wrun_01KNGP5DTCNCRCQ24KX3TEHFSH
  • importedStepOnlyWorkflow | wrun_01KNGP7K72V9RT3MWJXXRZZZYV
  • hookWorkflow | wrun_01KNGP5SW2SKHB3QWRJBY31K7X
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KNGP643DPJ3CMCR2Q53BCQBG
  • webhookWorkflow | wrun_01KNGP6D6VQQGGZEVAY7MF0QKA
  • sleepingWorkflow | wrun_01KNGP6KKJE5QX15SE9MBSVQKA
  • parallelSleepWorkflow | wrun_01KNGP6ZY8RVK7VXF5PD6MDP2M
  • nullByteWorkflow | wrun_01KNGP733G9X30PGAJV2VR8MKN
  • workflowAndStepMetadataWorkflow | wrun_01KNGP7548A4CCE173P8CSYF6N
  • fetchWorkflow | wrun_01KNGP9Q2FPHBD6CNF6BD28PWX
  • promiseRaceStressTestWorkflow | wrun_01KNGP9T7GDA3JMHQFAYTADTD8
  • error handling error propagation workflow errors nested function calls preserve message and stack trace
  • error handling error propagation workflow errors cross-file imports preserve message and stack trace
  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
  • error handling retry behavior regular Error retries until success
  • error handling retry behavior FatalError fails immediately without retries
  • error handling retry behavior RetryableError respects custom retryAfter delay
  • error handling retry behavior maxRetries=0 disables retries
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization
  • error handling not registered WorkflowNotRegisteredError fails the run when workflow does not exist
  • error handling not registered StepNotRegisteredError fails the step but workflow can catch it
  • error handling not registered StepNotRegisteredError fails the run when not caught in workflow
  • hookCleanupTestWorkflow - hook token reuse after workflow completion | wrun_01KNGPF3KHPNDHV9EPGYDJ9ZVT
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KNGPFPZYJ1CKYB76CP39WTD0
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01KNGPGAXRCQ26RY23K637688D
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01KNGPGXK21KVKJ9M10RWCBFT9
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01KNGPH5Y4R55DR69DKMF61XVK
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01KNGPHB1PKQYG1XGW5NNGD6ZZ
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01KNGPHD6A0T5A4CTDYG7FGZ8S
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01KNGPHV802XZH88XMZ1W1QR45
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01KNGPJ08J1BE3VQ2WWK1JW3TD
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01KNGPJ5CKYNQ8ME49545P2BJJ
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01KNGPJCJNFXP4N9RXFN5HPEB8
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01KNGPJHNZ027S5BGA91G51P9R
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01KNGPJS2AKVSJVJQRTRR5DD65
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01KNGPJZ5ZJAGHEN233Z12HYZN
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01KNGPK9KYZJ1F0VQH686B3QRF
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01KNGPKH4AK532YHCXP9GYP1PV
  • cancelRun - cancelling a running workflow | wrun_01KNGPKQA6JDJTSDKPF5A2CFQV
  • cancelRun via CLI - cancelling a running workflow | wrun_01KNGPM0CFA2SYDCVQH461CQHJ
  • pages router addTenWorkflow via pages router
  • pages router promiseAllWorkflow via pages router
  • pages router sleepingWorkflow via pages router
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep | wrun_01KNGPMBV1PPN1GTT87BRNPQFT
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01KNGPMZ64S88DCWHR8TZAHJBZ
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01KNGPN95C7JAN3TTB3E1B4ETB
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01KNGPNFG3HV8TKQKZYB4FNZTZ
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01KNGPNHHZKJCV399VXKAV9ZRC
📋 Other (6 failed)

e2e-local-dev-nest-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

e2e-local-postgres-nest-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

e2e-local-prod-nest-stable (2 failed):

  • error handling catchability FatalError preserves class identity through serialization
  • error handling catchability RetryableError preserves class identity through serialization

Details by Category

❌ ▲ Vercel Production
App Passed Failed Skipped
❌ astro 78 2 7
❌ example 78 2 7
❌ express 78 2 7
❌ fastify 78 2 7
❌ hono 78 2 7
❌ nextjs-turbopack 83 2 2
❌ nextjs-webpack 83 2 2
❌ nitro 78 2 7
❌ nuxt 78 2 7
❌ sveltekit 78 2 7
❌ vite 78 2 7
❌ 💻 Local Development
App Passed Failed Skipped
❌ astro-stable 71 2 14
❌ express-stable 71 2 14
❌ fastify-stable 71 2 14
❌ hono-stable 71 2 14
❌ nextjs-turbopack-canary 60 2 25
❌ nextjs-turbopack-stable 77 2 8
❌ nextjs-webpack-stable 77 2 8
❌ nitro-stable 71 2 14
❌ nuxt-stable 71 2 14
❌ sveltekit-stable 71 2 14
❌ vite-stable 71 2 14
❌ 📦 Local Production
App Passed Failed Skipped
❌ astro-stable 71 2 14
❌ express-stable 71 2 14
❌ fastify-stable 71 2 14
❌ hono-stable 71 2 14
❌ nextjs-turbopack-canary 60 2 25
❌ nextjs-turbopack-stable 77 2 8
❌ nextjs-webpack-canary 60 2 25
❌ nextjs-webpack-stable 77 2 8
❌ nitro-stable 71 2 14
❌ nuxt-stable 71 2 14
❌ sveltekit-stable 71 2 14
❌ vite-stable 71 2 14
❌ 🐘 Local Postgres
App Passed Failed Skipped
❌ astro-stable 71 2 14
❌ express-stable 71 2 14
❌ fastify-stable 71 2 14
❌ hono-stable 71 2 14
❌ nextjs-turbopack-canary 60 2 25
❌ nextjs-turbopack-stable 77 2 8
❌ nextjs-webpack-canary 60 2 25
❌ nextjs-webpack-stable 77 2 8
❌ nitro-stable 71 2 14
❌ nuxt-stable 71 2 14
❌ sveltekit-stable 71 2 14
❌ vite-stable 71 2 14
❌ 🪟 Windows
App Passed Failed Skipped
❌ nextjs-turbopack 77 2 8
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 5 0 0
❌ mongodb 57 5 8
✅ redis-dev 5 0 0
❌ redis 58 4 8
✅ turso-dev 5 0 0
❌ turso 4 58 8
❌ 📋 Other
App Passed Failed Skipped
❌ e2e-local-dev-nest-stable 71 2 14
❌ e2e-local-postgres-nest-stable 71 2 14
❌ e2e-local-prod-nest-stable 71 2 14

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: failure
  • Local Prod: failure
  • Local Postgres: failure
  • Windows: failure

Check the workflow run for details.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class devalue serialization support for Workflow DevKit error types FatalError and RetryableError, improving type preservation across serialization boundaries.

Changes:

  • Add FatalError / RetryableError reducers and revivers to the common devalue pipeline.
  • Extend serialization tests with new round-trip coverage for both error types and adjust cross-VM FatalError expectations.
  • Add a changeset to release the update as a patch to @workflow/core.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/serialization.ts Introduces new special reducers/revivers for FatalError and RetryableError in the common serialization pipeline.
packages/core/src/serialization.test.ts Updates cross-VM FatalError assertions and adds new round-trip tests for Fatal/Retryable errors.
.changeset/fatal-retryable-error-serialization.md Declares a patch release note for the new serialization behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/serialization.ts Outdated
if (!FatalError.is(value)) return false;
return {
message: value.message,
stack: value.stack,
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FatalError currently serializes only {message, stack}. Since this reducer runs before the generic Error reducer, any FatalError with an assigned cause will now lose its cause chain during serialization/deserialization. Consider including cause in the serialized payload and restoring it on the revived error (e.g., assign error.cause when present).

Suggested change
stack: value.stack,
stack: value.stack,
// Preserve the error cause chain when present
cause: (value as any).cause,

Copilot uses AI. Check for mistakes.
Comment thread packages/core/src/serialization.ts Outdated
Comment on lines +773 to +776
return {
message: value.message,
stack: value.stack,
retryAfter: (value as RetryableError).retryAfter,
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RetryableError reducer assumes retryAfter exists and is a Date from the same realm. Since RetryableError.is() only checks value.name, any Error named 'RetryableError' without a valid date-like retryAfter can be captured and cause hydration to throw. Additionally, when serializing across VM realms, retryAfter may be a host-realm Date that fails the Date reducer’s instanceof global.Date check, so it won’t be revived as a Date. Add validation that retryAfter is date-like and normalize it to a global.Date (or serialize it as an ISO string) before returning it; otherwise return false to fall back to the generic Error reducer. Also consider serializing/restoring cause here to avoid regressing from the generic Error reducer’s cause preservation.

Suggested change
return {
message: value.message,
stack: value.stack,
retryAfter: (value as RetryableError).retryAfter,
const retryAfterRaw = (value as RetryableError).retryAfter as unknown;
let timestamp: number | null = null;
if (
retryAfterRaw &&
typeof retryAfterRaw === 'object' &&
typeof (retryAfterRaw as { getTime?: unknown }).getTime === 'function'
) {
const t = (retryAfterRaw as Date).getTime();
if (!Number.isNaN(t)) timestamp = t;
} else if (
typeof retryAfterRaw === 'string' ||
typeof retryAfterRaw === 'number'
) {
const t = new Date(retryAfterRaw).getTime();
if (!Number.isNaN(t)) timestamp = t;
}
if (timestamp === null) {
// Not a valid date-like retryAfter; fall back to generic Error reducer.
return false;
}
const retryAfter = new Date(timestamp);
const cause =
'cause' in (value as Error) ? (value as Error & { cause?: unknown }).cause : undefined;
return {
message: value.message,
stack: value.stack,
retryAfter,
...(cause !== undefined ? { cause } : {}),

Copilot uses AI. Check for mistakes.
Comment thread packages/core/src/serialization.ts Outdated
Comment on lines +1180 to +1182
// Use the context-specific FatalError if available (e.g. workflow VM),
// otherwise fall back to a plain Error with the FatalError name.
// This ensures the deserialized error is instanceof the correct context's Error.
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FatalError reviver comment says it falls back to a plain Error and that this guarantees instanceof the context's Error. The implementation actually falls back to the imported host FatalError class, which may be from a different realm than global.Error. Please update the comment to match the behavior (context ctor if provided; otherwise host ctor, and rely on FatalError.is() for cross-realm checks).

Suggested change
// Use the context-specific FatalError if available (e.g. workflow VM),
// otherwise fall back to a plain Error with the FatalError name.
// This ensures the deserialized error is instanceof the correct context's Error.
// Prefer the context-specific FatalError constructor if available (e.g. workflow VM),
// otherwise fall back to the imported host FatalError constructor.
// Cross-realm identification should rely on FatalError.is() rather than instanceof.

Copilot uses AI. Check for mistakes.
@TooTallNate TooTallNate force-pushed the nrajlich/error-class-serde branch from 7b08980 to b27fa71 Compare April 2, 2026 00:11
@TooTallNate TooTallNate force-pushed the nrajlich/domexception-serialization branch from 7a43bf9 to 909f31f Compare April 2, 2026 00:17
@TooTallNate TooTallNate force-pushed the nrajlich/error-class-serde branch from b27fa71 to 1c8650d Compare April 2, 2026 00:17
/** Test: RetryableError preserves class identity through step error serialization */
async function throwRetryableErrorStep() {
'use step';
throw new RetryableError('retryable serde test', {
Copy link
Copy Markdown
Contributor

@vercel vercel Bot Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errorRetryableSerdeRoundTrip e2e test will always time out because it throws a RetryableError with retryAfter set to year 2099 (causing ~74-year retry delay), and even if retries were exhausted, the step_failed path always reconstructs the error as FatalError (not RetryableError), causing all test assertions to fail.

Fix on Vercel

- Pass DOMException through to the workflow VM context alongside other
  Web APIs (Headers, URL, TextEncoder, etc.)
- Add DOMException reducer/reviver to the serialization pipeline,
  preserving message, name, derived code, and cause when present
- Add DOMException to the Serializable type union
- 8 new tests: round-trip for AbortError, NotFoundError, default name,
  cause preservation, cause absence, serialization key, cross-VM
  boundaries, and VM context availability
…leError

Add custom serialization methods to FatalError and RetryableError in
@workflow/errors, enabling the SWC plugin to discover and register them
through the standard class serialization pipeline. This preserves class
identity (instanceof), the fatal flag, and the retryAfter date when
these errors cross serialization boundaries.

- Add @workflow/serde dependency to @workflow/errors
- Add WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE static methods to both classes
- Add unit tests verifying Instance-based round-trip serialization
- Add e2e workflow tests verifying class identity preservation end-to-end
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.

2 participants