Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Phase 4: SerializationError + user-facing serialization hints by pranaygp · Pull Request #1836 · vercel/workflow · GitHub
Skip to content

Phase 4: SerializationError + user-facing serialization hints - #1836

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization
Closed

Phase 4: SerializationError + user-facing serialization hints#1836
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-3-loggerfrom
pranaygp/friendlier-errors-phase-4-serialization

Conversation

@pranaygp

@pranaygppranaygp commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the friendlier-errors stack. Introduces SerializationError and adopts it at every user-facing serialization boundary in @workflow/core, while normalizing bare throw new Error(...) internal invariants to WorkflowRuntimeError.

What changes

  • New class SerializationError in @workflow/errors:

    • Extends WorkflowError with slug: 'serialization-failed' so the docs link (https://workflow-sdk.dev/err/serialization-failed) appears in every message.
    • Optional hint option — an actionable "how to fix" line rendered above the docs link.
    • SerializationError.is(value) for runtime discrimination.
  • User-facing sites throw SerializationError with a hint:

    • Locked ReadableStream passed across a workflow boundary
    • Class without classId / unregistered classId / missing WORKFLOW_DESERIALIZE
    • StepFunction returned to client / WorkflowFunction called directly / respondWith() outside a step
    • All four dehydrate* paths (workflow arguments, workflow return value, step arguments, step return value) and stream-chunk transform errors
    • formatSerializationError now returns { message, hint } so the hint renders through the standard framing instead of being baked into the message string.
  • Internal invariants converted to WorkflowRuntimeError: format prefix length checks, unknown serialization format bytes, missing STREAM_NAME_SYMBOL, encryption key / ciphertext size guards, Stream aborted default reason, Writable stream closed prematurely, Failed to get reader, and the WORKFLOW_USE_STEP / closure-var context checks.

Manual test plan

Using workbench/nextjs-turbopackpnpm dev and watch the terminal. Each test should produce a SerializationError with a hint: line and the docs URL https://workflow-sdk.dev/err/serialization-failed.

  • Unregistered class across step boundary:

    classMyThing{constructor(publicx: number){}}asyncfunctionmyStep(thing: MyThing){'use step';returnthing.x;}exportasyncfunctionwf(){'use workflow';awaitmyStep(newMyThing(1));}

    Expect SerializationError naming "MyThing" and a hint: explaining how to register via registerClass / serde.

  • Non-serializable value (function):

    asyncfunctionecho<T>(v: T){'use step';returnv;}exportasyncfunctionwf(){'use workflow';awaitecho(()=>123);// function is not serializable}

    Expect SerializationError with hint: naming the offending value path (e.g. at .args[0]).

  • Non-serializable value (symbol) — same shape as above but pass Symbol('x').

  • Locked ReadableStream — deliberately lock a ReadableStream (call .getReader()) before passing it across a step boundary. Expect SerializationError: locked ReadableStream with a hint describing the stream-lock constraint.

  • StepFunction returned to client — have a workflow return a bare step reference directly (not a result). Expect a clear message that you can't surface step functions to the caller.

  • WorkflowFunction called directly — call a "use workflow"-tagged function from regular app code (not through start()). Expect a clear message pointing at start().

  • respondWith() outside a step — call respondWith(new Response()) from workflow or application code. Expect a SerializationError explaining that respondWith only works inside step functions.

  • Stream chunk transform error — pipe a non-serializable value through getWritable(). Expect a SerializationError identifying the offending chunk.

  • Internal invariant now attributed to SDK — harder to induce, but if you can corrupt a serialization prefix byte or strip STREAM_NAME_SYMBOL, confirm the thrown error is WorkflowRuntimeError (not bare Error) so Phase 5's describeError attributes it to sdk.

  • Attribution in step-failed log — confirm the [workflow-sdk] log at step-failure time carries errorAttribution: 'user' for all the above, plus hint: 'A value passed across a workflow/step boundary…' (Phase 5 wiring).

Unit tests

  • pnpm --filter @workflow/errors test — 15 pass (10 Ansi + 5 new SerializationError)
  • pnpm --filter @workflow/core exec vitest run src/serialization.test.ts — 116 pass; 7 pre-existing DOMException failures unrelated (confirmed on stash baseline)
  • Updated "should throw error when reviver cannot find registered step function" for the new hint text
  • Typecheck clean for Phase 4 changes

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

#PRPhaseSummary
1#1831Phase 1 + 2Ansi rendering primitives + context-violation errors
2#1832Phase 3Structured logger metadata; folds in #1812
3→ this PR (#1836)Phase 4SerializationError at serialization / stream / encryption boundaries
4#1837Phase 5Presentation-only user vs SDK attribution (describeError)
5#1838Phase 6Consistency pass on remaining bare throw new Error(...) sites
6#1839Phase 7 foundationData-driven describeRunError + public subpath
7#1840Phase 8WorkflowBuildError + applications in @workflow/builders
8#1849FollowupsDrop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

CopilotAI review requested due to automatic review settings April 23, 2026 16:34
@changeset-bot

changeset-botBot commented Apr 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 351d330

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

This PR includes changesets to release 21 packages
NameType
@workflow/corePatch
@workflow/errorsPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/world-vercelPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch
@workflow/aiPatch

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

vercelBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
❌ 💻 Local Development10522861140
✅ 📦 Local Production10540861140
❌ 🐘 Local Postgres10504861140
✅ 📋 Other267018285
Total342362763705

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • 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
🐘 Local Postgres (4 failed)

express-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

nitro-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
❌ vite-stable8726
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable8906
✅ express-stable8906
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
✅ nitro-stable8906
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
❌ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable8906
❌ express-stable8726
✅ fastify-stable8906
✅ hono-stable8906
✅ nextjs-turbopack-canary76019
✅ nextjs-turbopack-stable9500
✅ nextjs-webpack-canary76019
✅ nextjs-webpack-stable9500
❌ nitro-stable8726
✅ nuxt-stable8906
✅ sveltekit-stable8906
✅ vite-stable8906
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable8906
✅ e2e-local-postgres-nest-stable8906
✅ e2e-local-prod-nest-stable8906

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Stacked: #1837 — Phase 5, presentation-only user vs SDK attribution

pranaygpand others added 2 commits April 23, 2026 18:15
Phase 4 of friendlier errors: introduce a `SerializationError` class with
an optional `hint` and a docs link (workflow-sdk.dev/err/serialization-failed),
and adopt it at every user-facing serialization boundary in @workflow/core:
- Locked ReadableStream at a workflow boundary
- Unregistered class / missing `classId` / missing `WORKFLOW_DESERIALIZE`
- Attempting to return step functions to clients or call workflow functions
directly
- Webhook `respondWith()` called outside a step
- `dehydrate*` / `getSerializeStream` failures (workflow args/return, step
args/return, stream chunks)
Internal invariants (format prefix length checks, unknown format bytes,
missing `STREAM_NAME_SYMBOL`, encryption key/size guards, etc.) now throw
`WorkflowRuntimeError` instead of plain `Error` so the classifier and logger
treat them consistently.
`formatSerializationError` now returns `{ message, hint }` so the hint
fragment can be rendered with the standard SerializationError framing
instead of being baked into the message string.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

Sign up for freeto 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

@pranaygp