Skip to content

fix(core): ensure async deserialization resolves promises in event log order#1246

Merged
TooTallNate merged 4 commits into
mainfrom
fix/async-deserialization-ordering
Mar 3, 2026
Merged

fix(core): ensure async deserialization resolves promises in event log order#1246
TooTallNate merged 4 commits into
mainfrom
fix/async-deserialization-ordering

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Mar 3, 2026

Summary

  • Fixes a latent determinism bug where async deserialization (in preparation for e2e encryption) could cause step/hook promises to resolve out of event log order when hydration takes variable time
  • Introduces a sequential promiseQueue on WorkflowOrchestratorContext through which all event-driven promise resolutions flow — steps, hooks, sleeps, failures, suspensions, and errors
  • Removes all setTimeout(0) calls from step.ts, hook.ts, and sleep.ts in favor of the unified queue
  • Adds 7 dedicated tests that simulate variable async delays during deserialization and verify ordering is preserved across diverse scenarios

Problem

The hydrateStepReturnValue function was made async in preparation for encryption/decryption support. Currently no real await happens so things work, but once actual async work begins (e.g. decrypting a larger payload takes longer), multiple in-flight hydrations would race and resolve out of order:

Step A (50ms deserialize) + Step B (5ms deserialize)
→ Without fix: B resolves before A → broken determinism
→ With fix:    A resolves before B → correct order

Changes

File Change
packages/core/src/private.ts Added promiseQueue: Promise<void> to context type
packages/core/src/workflow.ts Initialize queue as Promise.resolve()
packages/core/src/step.ts Route all resolve/reject/error paths through promiseQueue, remove all setTimeout(0)
packages/core/src/workflow/hook.ts Route all resolve/reject/error/suspension paths through promiseQueue, remove all setTimeout(0)
packages/core/src/workflow/sleep.ts Route resolve/error paths through promiseQueue, remove all setTimeout(0)
packages/core/src/async-deserialization-ordering.test.ts 7 new ordering tests
Test helpers Added promiseQueue to context in step.test.ts, hook.test.ts, sleep.test.ts

Test plan

All 145 tests pass (7 new + 138 existing):

New tests (async-deserialization-ordering.test.ts):

  1. Two step_completed events with variable async delays (50ms vs 5ms)
  2. Three sequential step_completed events with decreasing delays (60ms, 30ms, 5ms)
  3. Two hook_received payloads with variable async delays
  4. Mixed step_completed + step_failed with slow hydration on the completed step
  5. 10 concurrent steps with reverse-order delays (100ms→10ms)
  6. Sleep + step interleaving (step A slow → sleep B → step C fast)
  7. Interleaved concurrent steps (step_started events interleaved with step_completed)

Existing tests:

  • workflow.test.ts — 69 integration tests
  • step.test.ts — 15 tests
  • hook.test.ts — 23 tests
  • sleep.test.ts — 9 tests
  • events-consumer.test.ts — 22 tests

…g order

Add a sequential deserializationChain to WorkflowOrchestratorContext that
ensures step/hook hydration resolves in event log order even when individual
deserialization takes variable time (e.g. due to encryption/decryption).

Without this, concurrent async hydrations could resolve out of order,
breaking workflow replay determinism.
Copilot AI review requested due to automatic review settings March 3, 2026 20:51
@TooTallNate TooTallNate requested a review from a team as a code owner March 3, 2026 20:51
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 7def3db

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

This PR includes changesets to release 14 packages
Name Type
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/web-shared Patch
workflow Patch
@workflow/world-testing Patch
@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 Mar 3, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 538 0 67 605
✅ 💻 Local Development 576 0 84 660
✅ 📦 Local Production 576 0 84 660
✅ 🐘 Local Postgres 576 0 84 660
✅ 🪟 Windows 52 0 3 55
❌ 🌍 Community Worlds 117 48 15 180
✅ 📋 Other 138 0 27 165
Total 2573 48 364 2985

❌ Failed Tests

🌍 Community Worlds (48 failed)

turso (48 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • webhookWorkflow
  • sleepingWorkflow
  • parallelSleepWorkflow
  • nullByteWorkflow
  • workflowAndStepMetadataWorkflow
  • fetchWorkflow
  • promiseRaceStressTestWorkflow
  • 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 retry behavior workflow completes despite transient 5xx on step_completed
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • hookCleanupTestWorkflow - hook token reuse after workflow completion
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars)
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument
  • closureVariableWorkflow - nested step functions with closure variables
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly
  • Calculator.calculate - static workflow method using static step methods from another class
  • AllInOneService.processNumber - static workflow method using sibling static step methods
  • ChainableService.processWithThis - static step methods using this to reference the class
  • thisSerializationWorkflow - step function invoked with .call() and .apply()
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE
  • instanceMethodStepWorkflow - instance methods with "use step" directive
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument
  • cancelRun - cancelling a running workflow
  • cancelRun via CLI - cancelling a running workflow
  • pages router addTenWorkflow via pages router
  • pages router promiseAllWorkflow via pages router
  • pages router sleepingWorkflow via pages router

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 48 0 7
✅ example 48 0 7
✅ express 48 0 7
✅ fastify 48 0 7
✅ hono 48 0 7
✅ nextjs-turbopack 53 0 2
✅ nextjs-webpack 53 0 2
✅ nitro 48 0 7
✅ nuxt 48 0 7
✅ sveltekit 48 0 7
✅ vite 48 0 7
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 46 0 9
✅ express-stable 46 0 9
✅ fastify-stable 46 0 9
✅ hono-stable 46 0 9
✅ nextjs-turbopack-canary 52 0 3
✅ nextjs-turbopack-stable 52 0 3
✅ nextjs-webpack-canary 52 0 3
✅ nextjs-webpack-stable 52 0 3
✅ nitro-stable 46 0 9
✅ nuxt-stable 46 0 9
✅ sveltekit-stable 46 0 9
✅ vite-stable 46 0 9
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 46 0 9
✅ express-stable 46 0 9
✅ fastify-stable 46 0 9
✅ hono-stable 46 0 9
✅ nextjs-turbopack-canary 52 0 3
✅ nextjs-turbopack-stable 52 0 3
✅ nextjs-webpack-canary 52 0 3
✅ nextjs-webpack-stable 52 0 3
✅ nitro-stable 46 0 9
✅ nuxt-stable 46 0 9
✅ sveltekit-stable 46 0 9
✅ vite-stable 46 0 9
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 46 0 9
✅ express-stable 46 0 9
✅ fastify-stable 46 0 9
✅ hono-stable 46 0 9
✅ nextjs-turbopack-canary 52 0 3
✅ nextjs-turbopack-stable 52 0 3
✅ nextjs-webpack-canary 52 0 3
✅ nextjs-webpack-stable 52 0 3
✅ nitro-stable 46 0 9
✅ nuxt-stable 46 0 9
✅ sveltekit-stable 46 0 9
✅ vite-stable 46 0 9
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 52 0 3
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 3 0 2
✅ mongodb 52 0 3
✅ redis-dev 3 0 2
✅ redis 52 0 3
✅ turso-dev 3 0 2
❌ turso 4 48 3
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 46 0 9
✅ e2e-local-postgres-nest-stable 46 0 9
✅ e2e-local-prod-nest-stable 46 0 9

📋 View full workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

📊 Benchmark Results

📈 Comparing against baseline from main branch. Green 🟢 = faster, Red 🔺 = slower.

workflow with no steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Express 0.033s (-4.4%) 1.006s (~) 0.973s 10 1.00x
💻 Local Nitro 0.033s (-7.1% 🟢) 1.005s (~) 0.973s 10 1.00x
🌐 Redis Next.js (Turbopack) 0.042s 1.005s 0.963s 10 1.27x
💻 Local Next.js (Turbopack) 0.048s 1.006s 0.958s 10 1.47x
🐘 Postgres Nitro 0.056s (-18.1% 🟢) 1.011s (~) 0.956s 10 1.70x
🐘 Postgres Next.js (Turbopack) 0.056s 1.012s 0.956s 10 1.71x
🐘 Postgres Express 0.057s (~) 1.011s (~) 0.955s 10 1.73x
🌐 MongoDB Next.js (Turbopack) 0.086s 1.007s 0.921s 10 2.61x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 0.416s (-24.0% 🟢) 1.748s (-24.3% 🟢) 1.332s 10 1.00x
▲ Vercel Next.js (Turbopack) 0.503s (-52.7% 🟢) 2.046s (-30.4% 🟢) 1.543s 10 1.21x
▲ Vercel Nitro 0.914s (+50.1% 🔺) 2.445s (-11.8% 🟢) 1.530s 10 2.20x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

workflow with 1 step

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Express 1.101s (-1.1%) 2.006s (~) 0.905s 10 1.00x
💻 Local Nitro 1.102s (~) 2.006s (~) 0.904s 10 1.00x
🌐 Redis Next.js (Turbopack) 1.108s 2.006s 0.898s 10 1.01x
💻 Local Next.js (Turbopack) 1.112s 2.007s 0.894s 10 1.01x
🐘 Postgres Express 1.124s (-1.4%) 2.013s (~) 0.889s 10 1.02x
🐘 Postgres Next.js (Turbopack) 1.126s 2.011s 0.885s 10 1.02x
🐘 Postgres Nitro 1.129s (-1.2%) 2.012s (~) 0.883s 10 1.03x
🌐 MongoDB Next.js (Turbopack) 1.289s 2.008s 0.718s 10 1.17x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Nitro 2.046s (-8.2% 🟢) 3.320s (-3.8%) 1.274s 10 1.00x
▲ Vercel Express 2.124s (+1.6%) 2.986s (-5.4% 🟢) 0.862s 10 1.04x
▲ Vercel Next.js (Turbopack) 2.446s (+12.0% 🔺) 3.511s (+5.9% 🔺) 1.065s 10 1.20x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

workflow with 10 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 10.647s 11.021s 0.374s 3 1.00x
💻 Local Express 10.766s (-1.2%) 11.023s (~) 0.257s 3 1.01x
💻 Local Nitro 10.774s (-0.5%) 11.023s (~) 0.249s 3 1.01x
💻 Local Next.js (Turbopack) 10.800s 11.025s 0.224s 3 1.01x
🐘 Postgres Next.js (Turbopack) 10.804s 11.048s 0.244s 3 1.01x
🐘 Postgres Nitro 10.854s (-0.7%) 11.043s (~) 0.189s 3 1.02x
🐘 Postgres Express 10.868s (~) 11.047s (~) 0.180s 3 1.02x
🌐 MongoDB Next.js (Turbopack) 12.222s 13.020s 0.797s 3 1.15x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 16.602s (-3.4%) 17.847s (-2.3%) 1.245s 2 1.00x
▲ Vercel Nitro 16.813s (-2.4%) 17.600s (-4.9%) 0.788s 2 1.01x
▲ Vercel Next.js (Turbopack) 17.402s (-3.3%) 18.503s (-2.5%) 1.100s 2 1.05x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

workflow with 25 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 26.508s 27.048s 0.540s 3 1.00x
🐘 Postgres Next.js (Turbopack) 26.929s 27.062s 0.134s 3 1.02x
🐘 Postgres Express 26.974s (-1.2%) 27.066s (-3.6%) 0.092s 3 1.02x
🐘 Postgres Nitro 26.991s (-1.5%) 27.065s (-3.6%) 0.075s 3 1.02x
💻 Local Next.js (Turbopack) 27.098s 27.720s 0.623s 3 1.02x
💻 Local Nitro 27.165s (-1.2%) 28.052s (~) 0.887s 3 1.02x
💻 Local Express 27.217s (-1.6%) 28.052s (~) 0.835s 3 1.03x
🌐 MongoDB Next.js (Turbopack) 30.338s 31.032s 0.694s 2 1.14x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Nitro 47.367s (+6.2% 🔺) 48.816s (+7.0% 🔺) 1.448s 2 1.00x
▲ Vercel Next.js (Turbopack) 48.266s (~) 49.688s (-0.8%) 1.422s 2 1.02x
▲ Vercel Express 48.455s (+3.7%) 49.491s (+3.7%) 1.036s 2 1.02x

🔍 Observability: Nitro | Next.js (Turbopack) | Express

workflow with 50 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 52.873s 53.088s 0.215s 2 1.00x
🐘 Postgres Next.js (Turbopack) 53.696s 54.100s 0.404s 2 1.02x
🐘 Postgres Nitro 53.938s (-2.6%) 54.110s (-3.6%) 0.171s 2 1.02x
🐘 Postgres Express 54.008s (-2.1%) 54.105s (-3.6%) 0.098s 2 1.02x
💻 Local Next.js (Turbopack) 55.901s 56.106s 0.205s 2 1.06x
💻 Local Nitro 56.066s (-2.1%) 56.099s (-3.4%) 0.033s 2 1.06x
💻 Local Express 56.115s (-2.4%) 56.600s (-2.6%) 0.485s 2 1.06x
🌐 MongoDB Next.js (Turbopack) 60.662s 61.046s 0.384s 2 1.15x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 93.781s (-6.8% 🟢) 95.174s (-7.3% 🟢) 1.393s 1 1.00x
▲ Vercel Next.js (Turbopack) 94.214s (-12.7% 🟢) 94.924s (-13.4% 🟢) 0.710s 1 1.00x
▲ Vercel Nitro 98.124s (-12.4% 🟢) 98.945s (-13.2% 🟢) 0.821s 1 1.05x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

Promise.all with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 1.254s 2.006s 0.752s 15 1.00x
🐘 Postgres Nitro 1.386s (~) 2.011s (~) 0.626s 15 1.11x
🐘 Postgres Express 1.390s (+1.6%) 2.012s (~) 0.622s 15 1.11x
🐘 Postgres Next.js (Turbopack) 1.397s 2.011s 0.613s 15 1.11x
💻 Local Nitro 1.413s (+1.0%) 2.006s (~) 0.592s 15 1.13x
💻 Local Express 1.431s (-1.9%) 2.005s (-3.2%) 0.575s 15 1.14x
💻 Local Next.js (Turbopack) 1.455s 2.006s 0.551s 15 1.16x
🌐 MongoDB Next.js (Turbopack) 2.121s 3.007s 0.886s 10 1.69x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 2.393s (+5.9% 🔺) 3.268s (+3.8%) 0.875s 10 1.00x
▲ Vercel Next.js (Turbopack) 2.549s (+1.2%) 3.547s (+1.7%) 0.998s 9 1.07x
▲ Vercel Nitro 2.668s (+15.9% 🔺) 3.631s (+10.2% 🔺) 0.963s 9 1.12x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

Promise.all with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 2.039s (+5.9% 🔺) 2.597s (+3.3%) 0.559s 12 1.00x
🐘 Postgres Nitro 2.050s (-3.3%) 2.598s (-3.2%) 0.548s 12 1.01x
🐘 Postgres Next.js (Turbopack) 2.122s 2.599s 0.477s 12 1.04x
🌐 Redis Next.js (Turbopack) 2.499s 3.007s 0.509s 10 1.23x
💻 Local Nitro 2.591s (~) 3.008s (~) 0.417s 10 1.27x
💻 Local Express 2.686s (+7.8% 🔺) 3.007s (~) 0.321s 10 1.32x
💻 Local Next.js (Turbopack) 2.729s 3.008s 0.279s 10 1.34x
🌐 MongoDB Next.js (Turbopack) 4.687s 5.177s 0.491s 6 2.30x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Nitro 2.520s (+8.5% 🔺) 3.543s (+6.8% 🔺) 1.024s 9 1.00x
▲ Vercel Express 2.669s (+7.7% 🔺) 4.112s (+26.8% 🔺) 1.443s 8 1.06x
▲ Vercel Next.js (Turbopack) 3.097s (+13.5% 🔺) 4.075s (+11.6% 🔺) 0.977s 8 1.23x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 4.026s 4.732s 0.705s 7 1.00x
🐘 Postgres Express 4.196s (+18.4% 🔺) 4.885s (+14.4% 🔺) 0.689s 7 1.04x
🌐 Redis Next.js (Turbopack) 4.253s 5.010s 0.757s 6 1.06x
🐘 Postgres Nitro 4.460s (+14.0% 🔺) 5.191s (+12.8% 🔺) 0.731s 6 1.11x
💻 Local Nitro 7.644s (+2.8%) 8.018s (~) 0.373s 4 1.90x
💻 Local Express 7.735s (+8.0% 🔺) 8.017s (~) 0.282s 4 1.92x
💻 Local Next.js (Turbopack) 7.819s 8.517s 0.698s 4 1.94x
🌐 MongoDB Next.js (Turbopack) 9.910s 10.350s 0.440s 3 2.46x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Nitro 2.955s (-15.0% 🟢) 3.976s (-14.0% 🟢) 1.021s 8 1.00x
▲ Vercel Express 3.205s (-0.7%) 4.391s (+7.8% 🔺) 1.186s 7 1.08x
▲ Vercel Next.js (Turbopack) 3.299s (-0.9%) 4.458s (+3.0%) 1.159s 7 1.12x

🔍 Observability: Nitro | Express | Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 1.228s 2.006s 0.778s 15 1.00x
🐘 Postgres Next.js (Turbopack) 1.350s 2.011s 0.661s 15 1.10x
🐘 Postgres Nitro 1.383s (-2.2%) 2.010s (~) 0.628s 15 1.13x
🐘 Postgres Express 1.383s (-2.7%) 2.011s (~) 0.628s 15 1.13x
💻 Local Express 1.429s (-1.0%) 2.004s (~) 0.575s 15 1.16x
💻 Local Nitro 1.439s (-0.6%) 2.005s (~) 0.566s 15 1.17x
💻 Local Next.js (Turbopack) 1.464s 2.006s 0.542s 15 1.19x
🌐 MongoDB Next.js (Turbopack) 2.142s 3.008s 0.865s 10 1.74x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 2.122s (-24.8% 🟢) 2.926s (-24.0% 🟢) 0.804s 11 1.00x
▲ Vercel Next.js (Turbopack) 2.264s (-5.2% 🟢) 3.393s (-3.4%) 1.129s 9 1.07x
▲ Vercel Nitro 2.396s (+10.9% 🔺) 3.498s (+3.7%) 1.101s 9 1.13x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

Promise.race with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 2.005s 2.597s 0.592s 12 1.00x
🐘 Postgres Nitro 2.040s (-0.9%) 2.598s (~) 0.558s 12 1.02x
🐘 Postgres Express 2.090s (-3.8%) 2.515s (-6.2% 🟢) 0.425s 12 1.04x
🌐 Redis Next.js (Turbopack) 2.496s 3.007s 0.512s 10 1.24x
💻 Local Nitro 2.707s (-2.1%) 3.008s (~) 0.301s 10 1.35x
💻 Local Express 2.746s (+1.4%) 3.008s (~) 0.262s 10 1.37x
💻 Local Next.js (Turbopack) 2.973s 3.208s 0.235s 10 1.48x
🌐 MongoDB Next.js (Turbopack) 4.632s 5.176s 0.544s 6 2.31x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 2.347s (-4.8%) 3.139s (-4.1%) 0.792s 10 1.00x
▲ Vercel Nitro 2.703s (+14.4% 🔺) 3.666s (+13.0% 🔺) 0.964s 9 1.15x
▲ Vercel Next.js (Turbopack) 2.868s (+21.0% 🔺) 3.862s (+17.9% 🔺) 0.994s 9 1.22x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 3.953s (+8.4% 🔺) 4.602s (+4.6%) 0.649s 7 1.00x
🐘 Postgres Nitro 4.066s (+8.9% 🔺) 4.744s (+3.3%) 0.678s 7 1.03x
🌐 Redis Next.js (Turbopack) 4.213s 5.011s 0.798s 6 1.07x
🐘 Postgres Next.js (Turbopack) 4.388s 5.354s 0.965s 6 1.11x
💻 Local Next.js (Turbopack) 8.015s 8.519s 0.503s 4 2.03x
💻 Local Nitro 8.194s (+5.0%) 9.022s (+12.5% 🔺) 0.828s 4 2.07x
💻 Local Express 8.272s (+6.4% 🔺) 9.020s (+9.1% 🔺) 0.748s 4 2.09x
🌐 MongoDB Next.js (Turbopack) 9.835s 10.349s 0.514s 3 2.49x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 3.382s (-7.3% 🟢) 4.395s (-1.7%) 1.013s 7 1.00x
▲ Vercel Nitro 3.399s (+6.2% 🔺) 4.432s (-1.6%) 1.033s 7 1.00x
▲ Vercel Next.js (Turbopack) 3.635s (+8.9% 🔺) 4.581s (~) 0.946s 7 1.07x

🔍 Observability: Express | Nitro | Next.js (Turbopack)

Stream Benchmarks (includes TTFB metrics)
workflow with stream

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🌐 Redis 🥇 Next.js (Turbopack) 0.145s 1.000s 0.001s 1.007s 0.862s 10 1.00x
💻 Local Next.js (Turbopack) 0.160s 1.001s 0.011s 1.017s 0.858s 10 1.10x
💻 Local Nitro 0.168s (-4.3%) 1.002s (~) 0.011s (+0.9%) 1.017s (~) 0.849s 10 1.16x
💻 Local Express 0.172s (-6.9% 🟢) 1.002s (~) 0.011s (+0.9%) 1.016s (~) 0.845s 10 1.18x
🐘 Postgres Next.js (Turbopack) 0.174s 1.001s 0.002s 1.013s 0.839s 10 1.20x
🐘 Postgres Nitro 0.204s (-3.2%) 0.995s (~) 0.001s (-7.7% 🟢) 1.011s (~) 0.808s 10 1.41x
🐘 Postgres Express 0.211s (+3.4%) 0.992s (~) 0.002s (+13.3% 🔺) 1.012s (~) 0.801s 10 1.46x
🌐 MongoDB Next.js (Turbopack) 0.486s 0.949s 0.001s 1.008s 0.521s 10 3.36x

▲ Production (Vercel)

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Express 1.476s (-20.4% 🟢) 2.747s (+3.1%) 0.597s (+5.1% 🔺) 33.621s (+825.2% 🔺) 32.144s 10 1.00x
▲ Vercel Next.js (Turbopack) 1.625s (-13.1% 🟢) 2.085s (-10.2% 🟢) 0.129s (-20.3% 🟢) 2.648s (-10.3% 🟢) 1.024s 10 1.10x
▲ Vercel Nitro 1.768s (+8.1% 🔺) 2.386s (+8.3% 🔺) 0.112s (-73.6% 🟢) 33.067s (+967.9% 🔺) 31.300s 10 1.20x

🔍 Observability: Express | Next.js (Turbopack) | Nitro

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World 🥇 Fastest Framework Wins
💻 Local Express 4/12
🐘 Postgres Next.js (Turbopack) 7/12
▲ Vercel Express 8/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework 🥇 Fastest World Wins
Express 🐘 Postgres 6/12
Next.js (Turbopack) 🌐 Redis 8/12
Nitro 🐘 Postgres 6/12
Column Definitions
  • Workflow Time: Runtime reported by workflow (completedAt - createdAt) - primary metric
  • TTFB: Time to First Byte - time from workflow start until first stream byte received (stream benchmarks only)
  • Slurp: Time from first byte to complete stream consumption (stream benchmarks only)
  • Wall Time: Total testbench time (trigger workflow + poll for result)
  • Overhead: Testbench overhead (Wall Time - Workflow Time)
  • Samples: Number of benchmark iterations run
  • vs Fastest: How much slower compared to the fastest configuration for this benchmark

Worlds:

  • 💻 Local: In-memory filesystem world (local development)
  • 🐘 Postgres: PostgreSQL database world (local development)
  • ▲ Vercel: Vercel production/preview deployment
  • 🌐 Turso: Community world (local development)
  • 🌐 MongoDB: Community world (local development)
  • 🌐 Redis: Community world (local development)
  • 🌐 Jazz: Community world (local development)

📋 View full workflow run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a determinism hazard in the core workflow replay engine by enforcing sequential async deserialization so step/hook promises resolve in the same order as the event log, even when hydration time varies (e.g., future decryption).

Changes:

  • Introduces deserializationChain: Promise<void> on WorkflowOrchestratorContext and initializes it for workflow runs and test contexts.
  • Chains step (step_completed) and hook (hook_received) hydration + promise resolution through deserializationChain to preserve event-log ordering.
  • Adds a new test file intended to validate ordering under simulated variable async deserialization delays.

Reviewed changes

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

Show a summary per file
File Description
packages/core/src/private.ts Adds deserializationChain to the orchestrator context type (with doc comment).
packages/core/src/workflow.ts Initializes deserializationChain for real workflow runs.
packages/core/src/step.ts Routes step completion hydration/resolve through deserializationChain.
packages/core/src/workflow/hook.ts Routes hook payload hydration/resolve through deserializationChain in both immediate and queued cases.
packages/core/src/async-deserialization-ordering.test.ts New tests meant to simulate variable async hydration delays and assert deterministic resolution ordering.
packages/core/src/workflow/sleep.test.ts Updates test context helper to include deserializationChain.
packages/core/src/workflow/hook.test.ts Updates test context helper to include deserializationChain.
packages/core/src/step.test.ts Updates test context helper to include deserializationChain.
.changeset/fix-deserialization-ordering.md Publishes the fix as a patch changeset for @workflow/core.

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

Comment thread packages/core/src/step.ts
Comment thread packages/core/src/workflow/hook.ts Outdated
Comment thread packages/core/src/async-deserialization-ordering.test.ts
Comment thread packages/core/src/async-deserialization-ordering.test.ts
Address review feedback:
- Add hook-specific deserialization ordering test
- Add afterEach(vi.restoreAllMocks) to prevent spy leaks
- Remove manual mockRestore calls
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread packages/core/src/async-deserialization-ordering.test.ts
Comment thread packages/core/src/workflow/hook.ts
Comment thread packages/core/src/workflow/sleep.test.ts
- The hasConflict path in createHookPromise() was rejecting immediately,
  bypassing the promiseQueue and potentially settling out of event-log
  order relative to prior queued resolutions.
- Add missing runId and encryptionKey to sleep.test.ts context stub.
Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious left a comment

Choose a reason for hiding this comment

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

Great solution to the problem

@TooTallNate TooTallNate merged commit 860531d into main Mar 3, 2026
104 checks passed
@TooTallNate TooTallNate deleted the fix/async-deserialization-ordering branch March 3, 2026 22:42
@TooTallNate TooTallNate restored the fix/async-deserialization-ordering branch March 3, 2026 22:46
@TooTallNate TooTallNate deleted the fix/async-deserialization-ordering branch March 3, 2026 22:47
pranaygp added a commit that referenced this pull request Mar 7, 2026
Add failing tests that reproduce a regression from #1246 where the
sleep's WorkflowSuspension fires before all hook payloads are delivered
when a hook and sleep run concurrently.

Root cause: when the null event fires, the sleep queues a suspension
through promiseQueue. After the first hook payload resolves, subsequent
hook payload resolutions are queued AFTER the sleep suspension, causing
the workflow to terminate prematurely via Promise.race.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TooTallNate added a commit that referenced this pull request Mar 7, 2026
…romiseQueue

The promiseQueue refactor (#1246) moved ALL promise resolutions through
the queue, including WorkflowSuspension calls. This caused premature
termination when hooks had buffered payloads and a concurrent entity
(sleep or incomplete step) was pending:

1. Null event fires → all subscribers run
2. Sleep/step queues WorkflowSuspension via promiseQueue.then()
3. Hook's next payload resolution is also queued via promiseQueue.then()
4. Suspension fires first → Promise.race terminates workflow
5. Hook payload never delivered → infinite retry loop

Fix: move WorkflowSuspension calls back to setTimeout(0) (macrotask).
Suspensions fire AFTER all microtask-based deliveries (promiseQueue
resolve/reject for step results and hook payloads) have completed.
Non-suspension resolve/reject calls remain on promiseQueue for
deterministic ordering of data delivery.

Affected paths:
- step.ts: null event handler
- sleep.ts: null event handler
- hook.ts: null event handler, eventLogEmpty suspension, dispose suspension
TooTallNate added a commit that referenced this pull request Mar 7, 2026
…h concurrent pending entities (#1294)

* test: reproduce hook+sleep promiseQueue regression

Add failing tests that reproduce a regression from #1246 where the
sleep's WorkflowSuspension fires before all hook payloads are delivered
when a hook and sleep run concurrently.

Root cause: when the null event fires, the sleep queues a suspension
through promiseQueue. After the first hook payload resolves, subsequent
hook payload resolutions are queued AFTER the sleep suspension, causing
the workflow to terminate prematurely via Promise.race.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: expand tests to isolate bug to hook + pending entity pattern

Add control tests proving sequential steps are NOT affected by the
promiseQueue regression, isolating the bug to hooks specifically:

Failing (hook-based):
- hook + sleep: all 3 payloads → step invocation
- hook + sleep: 2 payloads → return
- hook + incomplete step: 2 payloads → return

Passing (step-based controls):
- sleep + sequential steps: both step events exist
- sleep + sequential steps: only 1st step completed
- incomplete step + sequential steps: all step events exist
- hook only (no concurrent entity): payloads + step

The bug is: any entity that queues a suspension through promiseQueue
at null-event time preempts hook payload delivery, because hooks
buffer payloads in payloadsQueue and only resolve them one-at-a-time
as the workflow code iterates. Steps are unaffected because each step
has its own events consumed before null fires.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(core): move WorkflowSuspension calls back to setTimeout(0) from promiseQueue

The promiseQueue refactor (#1246) moved ALL promise resolutions through
the queue, including WorkflowSuspension calls. This caused premature
termination when hooks had buffered payloads and a concurrent entity
(sleep or incomplete step) was pending:

1. Null event fires → all subscribers run
2. Sleep/step queues WorkflowSuspension via promiseQueue.then()
3. Hook's next payload resolution is also queued via promiseQueue.then()
4. Suspension fires first → Promise.race terminates workflow
5. Hook payload never delivered → infinite retry loop

Fix: move WorkflowSuspension calls back to setTimeout(0) (macrotask).
Suspensions fire AFTER all microtask-based deliveries (promiseQueue
resolve/reject for step results and hook payloads) have completed.
Non-suspension resolve/reject calls remain on promiseQueue for
deterministic ordering of data delivery.

Affected paths:
- step.ts: null event handler
- sleep.ts: null event handler
- hook.ts: null event handler, eventLogEmpty suspension, dispose suspension

* fix(core): use pendingDeliveries counter + scheduleWhenIdle for suspensions

Replace all nested setTimeout/promiseQueue suspension patterns with a
clean idle-polling mechanism:

1. pendingDeliveries counter: incremented before async hydration (step
   results, hook payloads), decremented in finally block after delivery
2. scheduleWhenIdle(ctx, fn): polls via setTimeout(0) → check counter →
   if > 0, wait for promiseQueue.then() → repeat. Only fires fn when
   pendingDeliveries reaches 0.

This correctly handles:
- Sync deserialization (no encryption): counter is 0, fires immediately
  after first setTimeout(0)
- Async deserialization (with encryption): waits for decryption to
  complete before firing
- Multi-round hook payload delivery: each createHookPromise() call
  increments the counter, preventing premature suspension between
  delivery rounds

Also adds payloadsQueue.length check to hook null handler — don't
trigger suspension if buffered payloads can satisfy pending awaits.

Tests now run in both sync and async modes (14 total = 7 scenarios x 2).
All 164 tests pass.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Nathan Rajlich <n@n8.io>
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.

3 participants