Skip to content

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

Open
github-actions[bot] wants to merge 1 commit 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 1 commit 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: 02134ae

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 22, 2026 12:11am
example-nextjs-workflow-webpack Ready Ready Preview, Comment May 22, 2026 12:11am
example-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-astro-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-express-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-fastify-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-hono-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-nitro-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-nuxt-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-sveltekit-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-tanstack-start-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workbench-vite-workflow Ready Ready Preview, Comment May 22, 2026 12:11am
workflow-docs Ready Ready Preview, Comment, Open in v0 May 22, 2026 12:11am
workflow-swc-playground Ready Ready Preview, Comment May 22, 2026 12:11am
workflow-tarballs Ready Ready Preview, Comment May 22, 2026 12:11am
workflow-web Ready Ready Preview, Comment May 22, 2026 12:11am

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.

0 participants