Skip to content

Backport #2059: feat(core): support passing parent WritableStream to child workflow via start()#2070

Open
github-actions[bot] wants to merge 2 commits into
stablefrom
backport/pr-2059-to-stable
Open

Backport #2059: feat(core): support passing parent WritableStream to child workflow via start()#2070
github-actions[bot] wants to merge 2 commits into
stablefrom
backport/pr-2059-to-stable

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Automated backport of #2059 to stable (backport job run).

AI recommendation: This commit fixes two real bugs in existing functionality that exists on stable — forwarding a parent's WritableStream (from getWritable()) to a child workflow via start(). On stable this pattern silently drops child writes after the parent step process exits (notably on Vercel after ~15 minutes) and double-frames every chunk so external consumers see the inner devalue frame instead of raw bytes. The affected files (encryption.ts, serialization.ts, step/writable-stream.ts, symbols.ts, 99_e2e.ts) all exist on stable, and the change is self-contained without dependencies on main-only APIs.

Merge conflicts were resolved by AI (opencode with anthropic/claude-opus-4.7). Please review the conflict resolution carefully before merging.

…ia start() (#2059)

* test(e2e): cover WritableStream passed as start() argument

Adds an e2e workflow + test where a parent workflow gets a WritableStream
via getWritable(), forwards it through start() to a child workflow, and
the child step writes raw bytes to it. Asserts the external reader on
the parent's stream observes the exact bytes the child wrote.

* fix(core): avoid double-framing when WritableStream is forwarded via start()

When a workflow's getWritable() handle is passed across start() to a
child workflow, the parent step's reviver wraps it in a serialize
transform that pipes into a workflow server stream. Until now,
getExternalReducers.WritableStream then installed a second serialize
transform on top of that — so every chunk the child step wrote got
devalue-framed twice but only deframed once on the reader side, and
external consumers saw the inner frame instead of the original bytes.

Fix: tag every user-visible writable that's already backed by a
workflow server stream with its (runId, name). When the external
reducer recognizes those tags during dehydration, it bridges bytes
straight from the new child-side server stream to the original server
stream instead of piping through the user's writable. That leaves the
producer-side serialize transform (installed once by the child's step
reviver) as the only framing layer in the chain.

* fix(core): forward (runId, name) when a tagged WritableStream crosses start()

Replaces the previous in-process bridge with first-class writable
forwarding at the descriptor level. When a parent workflow's
getWritable() handle is passed as an argument to a child workflow,
the dehydrated descriptor now carries the original (runId, name).
The child run's step-side reviver opens the writable against the
parent's server stream directly and resolves the parent run's
encryption key (encrypt-only) via getEncryptionKeyForRun.

This removes the architectural limitation that the bridge could
only stay alive for the duration of the parent step process — on
Vercel that capped forwarding at ~15 minutes regardless of the
child run's lifetime, dropping any writes the child made after the
parent step process exited.

importKey() now accepts a usages parameter, defaulting to
['encrypt', 'decrypt']. The cross-run forwarding path imports with
['encrypt'] only so a compromised child run cannot decrypt any
existing data on the parent's stream — only contribute new writes.

* test: rename writable-forwarded workflows and cover step-context getWritable()

Addresses PR review:

- Rename writableForwardedToChildChildWorkflow → writableForwardedChildWorkflow
  (drops the duplicated 'Child' segment).
- Split writableForwardedToChildWorkflow into two variants covered by a
  test.each: writableForwardedFromWorkflowWorkflow (workflow-context
  getWritable, the original test) and writableForwardedFromStepWorkflow
  (step-context getWritable passed directly into start() from the same
  step that called getWritable()).
- Terser changeset description.

Signed-off-by: Nathan Rajlich <n@n8.io>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: 75cdb77

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

This PR includes changesets to release 17 packages
Name Type
@workflow/core Minor
workflow Minor
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
@workflow/world-testing Patch
@workflow/ai Major
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite 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 May 22, 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 May 25, 2026 5:32pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment May 25, 2026 5:32pm
example-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-astro-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-express-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-fastify-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-hono-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-nitro-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-nuxt-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-sveltekit-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment May 25, 2026 5:32pm
workbench-vite-workflow Building Building Preview, Comment May 25, 2026 5:32pm
workflow-docs Ready Ready Preview, Comment, Open in v0 May 25, 2026 5:32pm
workflow-swc-playground Ready Ready Preview, Comment May 25, 2026 5:32pm
workflow-tarballs Ready Ready Preview, Comment May 25, 2026 5:32pm
workflow-web Ready Ready Preview, Comment May 25, 2026 5:32pm

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 25, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ ▲ Vercel Production 838 2 60 900
✅ 💻 Local Development 994 0 86 1080
✅ 📦 Local Production 994 0 86 1080
✅ 🐘 Local Postgres 994 0 86 1080
✅ 🪟 Windows 90 0 0 90
❌ 🌍 Community Worlds 15 71 0 86
✅ 📋 Other 504 0 36 540
Total 4429 73 354 4856

❌ Failed Tests

▲ Vercel Production (2 failed)

astro (1 failed):

example (1 failed):

🌍 Community Worlds (71 failed)

mongodb-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

redis-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

turso-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

turso (68 failed):

  • addTenWorkflow | wrun_01KSG30CBRT35MR32MC7D2Q56R
  • addTenWorkflow | wrun_01KSG30CBRT35MR32MC7D2Q56R
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01KSG3290F70PEDWM8QYYF401T
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01KSG30KC39KY62NSA9YVG3PAE
  • promiseRaceWorkflow | wrun_01KSG30TG3MS5NMFRNZCTGPK18
  • promiseAnyWorkflow | wrun_01KSG30WTTNKQJSGQV58G0CV1Z
  • importedStepOnlyWorkflow | wrun_01KSG32N7AADQ8DXBAWNMQ6XY7
  • readableStreamWorkflow | wrun_01KSG30YRC99AMZG0Y8HHDRD37
  • hookWorkflow | wrun_01KSG31BBJXB1MG8N5W5SB03VH
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KSG31HK5KB6ZDX8CP0NGZR2E
  • webhookWorkflow | wrun_01KSG31NWDB0E36ADEVN1243RQ
  • sleepingWorkflow | wrun_01KSG31WYHK1JQ07DJV88KE8F6
  • parallelSleepWorkflow | wrun_01KSG32B283XFVZQKPZF055V1C
  • nullByteWorkflow | wrun_01KSG32E61H0CCJ5GW1PJS0C6E
  • workflowAndStepMetadataWorkflow | wrun_01KSG32G42ZM3Z5N9H11FRKK6T
  • outputStreamWorkflow no startIndex (reads all chunks)
  • outputStreamWorkflow positive startIndex (skips first chunk)
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • outputStreamInsideStepWorkflow - getWritable() called inside step functions | wrun_01KSG34SXVS8RN4KN7B0TXF4T0
  • writableForwardedFromWorkflowWorkflow | wrun_01KSG357AZYHN72HZWSWWDC21Q
  • writableForwardedFromStepWorkflow | wrun_01KSG35BX6K85A09PVD718QEA5
  • fetchWorkflow | wrun_01KSG35F9CFVFA9NE0M9PJJP8X
  • promiseRaceStressTestWorkflow | wrun_01KSG35JC5EDYQ5J8E64K4SQGX
  • 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 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_01KSG38M3QPNXTJ03N00QWSBCF
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KSG38Z2S3Q9ED5TW00YV5FK3
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01KSG39D6VEGTPR0823ST4B7KV
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01KSG39V3ZB0YS404004GTAYVV
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01KSG3A33GGD9QD8KKE0V96KRF
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01KSG3A7ZSR3S1BAQW1DCRX988
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01KSG3AA0CFGR86W1SWARH1NAG
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • health check (CLI) - workflow health command reports healthy endpoints
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01KSG3AQFH7C03YQG41JF7N3YY
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01KSG3AW785TKH4A5VQ3ZMD8VP
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01KSG3B25KQ4VQW8MXN428DR42
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01KSG3B82JM8FJ86HZ2BKQ7FD5
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01KSG3BE2WEVQVC564V99R9HKD
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01KSG3BKXQGE1EQYY0V814E12E
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01KSG3BSTWK7S6BRA2D4N3318R
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01KSG3C51D8SVYFDYJKN012SQC
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01KSG3CDBX06X4EWCYCKKZDBBY
  • cancelRun - cancelling a running workflow | wrun_01KSG3CKASNPH6VS1Z07MHHXY0
  • cancelRun via CLI - cancelling a running workflow | wrun_01KSG3CVSSM7W16VM4E0KM7Y90
  • 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_01KSG3D77222BTXE1TK6PXXMMJ
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01KSG3DPEFYN7BT95WX2FNYC9P
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01KSG3E0MA8XQX1FJ6DMS8HMZD
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01KSG3E7KQ15Q8D1W9AVD20YDG
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01KSG3E9KHB9F4TBS7HE5441ZZ
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01KSG3EBH81453X065DXQH11YT

Details by Category

❌ ▲ Vercel Production
App Passed Failed Skipped
❌ astro 82 1 7
❌ example 82 1 7
✅ express 83 0 7
✅ fastify 83 0 7
✅ hono 83 0 7
✅ nextjs-turbopack 88 0 2
✅ nextjs-webpack 88 0 2
✅ nitro 83 0 7
✅ nuxt 83 0 7
✅ sveltekit 83 0 7
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 84 0 6
✅ express-stable 84 0 6
✅ fastify-stable 84 0 6
✅ hono-stable 84 0 6
✅ nextjs-turbopack-canary 71 0 19
✅ nextjs-turbopack-stable 90 0 0
✅ nextjs-webpack-canary 71 0 19
✅ nextjs-webpack-stable 90 0 0
✅ nitro-stable 84 0 6
✅ nuxt-stable 84 0 6
✅ sveltekit-stable 84 0 6
✅ vite-stable 84 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 84 0 6
✅ express-stable 84 0 6
✅ fastify-stable 84 0 6
✅ hono-stable 84 0 6
✅ nextjs-turbopack-canary 71 0 19
✅ nextjs-turbopack-stable 90 0 0
✅ nextjs-webpack-canary 71 0 19
✅ nextjs-webpack-stable 90 0 0
✅ nitro-stable 84 0 6
✅ nuxt-stable 84 0 6
✅ sveltekit-stable 84 0 6
✅ vite-stable 84 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 84 0 6
✅ express-stable 84 0 6
✅ fastify-stable 84 0 6
✅ hono-stable 84 0 6
✅ nextjs-turbopack-canary 71 0 19
✅ nextjs-turbopack-stable 90 0 0
✅ nextjs-webpack-canary 71 0 19
✅ nextjs-webpack-stable 90 0 0
✅ nitro-stable 84 0 6
✅ nuxt-stable 84 0 6
✅ sveltekit-stable 84 0 6
✅ vite-stable 84 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 90 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
❌ mongodb-dev 4 1 0
❌ redis-dev 4 1 0
❌ turso-dev 4 1 0
❌ turso 3 68 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 84 0 6
✅ e2e-local-dev-tanstack-start-stable 84 0 6
✅ e2e-local-postgres-nest-stable 84 0 6
✅ e2e-local-postgres-tanstack-start-stable 84 0 6
✅ e2e-local-prod-nest-stable 84 0 6
✅ e2e-local-prod-tanstack-start-stable 84 0 6

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant