Skip to content

Add additional tests for event consumer fixes for hook/sleep/step race conditions#1528

Open
pranaygp wants to merge 7 commits intomainfrom
fix/unconsumed-event-false-positive-hook-step
Open

Add additional tests for event consumer fixes for hook/sleep/step race conditions#1528
pranaygp wants to merge 7 commits intomainfrom
fix/unconsumed-event-false-positive-hook-step

Conversation

@pranaygp
Copy link
Copy Markdown
Contributor

@pranaygp pranaygp commented Mar 26, 2026

Fix shipped in #1778, so this PR now only adds tests, see old description below


Summary

  • Fixes a race condition in EventsConsumer where a step_created event could be falsely flagged as unconsumed during replay of for await (const payload of hook) { await step(payload); } patterns
  • After the promise queue drains (e.g., step result deserialization), yields to the event loop before re-checking, allowing microtask chains to propagate and append a second round of async work (hook payload deserialization)
  • Adds a unit test reproducing the exact event log pattern from the CI failure (alternating hook_received + step lifecycle events)

Root Cause

During replay, the EventsConsumer advances through events via process.nextTick. When it reaches a step_created event for the second loop iteration, no step consumer exists yet because:

  1. The preceding step_completed deserialization resolves processPayload() → triggers for-await loop continuation
  2. The loop calls createHookPromise() → chains hook payload deserialization onto the promise queue
  3. After hook deserialization → for-await yields → processPayload() called → step consumer registered

The existing deferred check only chained onto the promise queue once, missing the second round of async work added in step 2. The fix adds a setTimeout(0) yield between queue drains to let microtask chains propagate.

CI Failure

Test plan

  • All 22 events-consumer.test.ts tests pass
  • All 16 hook-sleep-interaction.test.ts tests pass (including new test)
  • All 71 workflow.test.ts tests pass
  • All other related test files pass (166 tests total)

🤖 Generated with Claude Code

During replay of a `for await (const payload of hook) { await step() }`
pattern, the EventsConsumer could advance to a step_created event before
the workflow code registered the step consumer. The existing deferred
unconsumed check chained onto the promise queue once and waited 100ms,
but this missed a second round of async work (hook payload deserialization)
triggered by the first drain's resolve().

Fix: after the initial queue drain, yield to the event loop (setTimeout(0))
so microtask chains propagate (e.g., step resolve → for-await resumes →
createHookPromise → new deserialization), then re-chain onto the latest
queue before starting the 100ms timeout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 26, 2026 23:03
@pranaygp pranaygp requested a review from a team as a code owner March 26, 2026 23:03
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 26, 2026

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

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 26, 2026

⚠️ No Changeset found

Latest commit: 365a4df

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 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 🥇 Nitro 0.044s (+2.1%) 1.005s (~) 0.961s 10 1.00x
💻 Local Express 0.045s (+1.6%) 1.006s (~) 0.961s 10 1.02x
💻 Local Next.js (Turbopack) 0.047s 1.005s 0.958s 10 1.07x
🐘 Postgres Next.js (Turbopack) 0.058s 1.010s 0.952s 10 1.31x
🐘 Postgres Express 0.059s (+2.1%) 1.010s (~) 0.951s 10 1.35x
🐘 Postgres Nitro 0.060s (-37.1% 🟢) 1.009s (-3.2%) 0.950s 10 1.36x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 0.250s (-0.7%) 2.110s (-9.6% 🟢) 1.860s 10 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 1 step

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Next.js (Turbopack) 1.113s 2.006s 0.893s 10 1.00x
💻 Local Nitro 1.128s (~) 2.006s (~) 0.878s 10 1.01x
💻 Local Express 1.132s (+0.6%) 2.006s (~) 0.874s 10 1.02x
🐘 Postgres Express 1.143s (~) 2.008s (~) 0.865s 10 1.03x
🐘 Postgres Next.js (Turbopack) 1.153s 2.011s 0.857s 10 1.04x
🐘 Postgres Nitro 1.155s (+1.3%) 2.009s (~) 0.854s 10 1.04x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.028s (~) 3.634s (-5.1% 🟢) 1.606s 10 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 10 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
💻 Local 🥇 Next.js (Turbopack) 10.793s 11.023s 0.230s 3 1.00x
🐘 Postgres Nitro 10.904s (~) 11.023s (~) 0.119s 3 1.01x
🐘 Postgres Express 10.917s (~) 11.020s (~) 0.103s 3 1.01x
💻 Local Express 10.948s (~) 11.024s (~) 0.076s 3 1.01x
💻 Local Nitro 10.966s (~) 11.021s (~) 0.056s 3 1.02x
🐘 Postgres Next.js (Turbopack) 10.980s 11.687s 0.708s 3 1.02x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 19.703s (+13.8% 🔺) 21.262s (+9.6% 🔺) 1.559s 2 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 25 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 14.471s (-0.8%) 15.021s (~) 0.550s 4 1.00x
🐘 Postgres Next.js (Turbopack) 14.480s 15.026s 0.545s 4 1.00x
🐘 Postgres Nitro 14.584s (~) 15.020s (~) 0.436s 4 1.01x
💻 Local Next.js (Turbopack) 14.636s 15.030s 0.395s 4 1.01x
💻 Local Express 14.998s (~) 15.279s (+1.7%) 0.282s 4 1.04x
💻 Local Nitro 15.032s (~) 15.530s (-3.1%) 0.498s 4 1.04x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 37.409s (-28.8% 🟢) 39.353s (-27.9% 🟢) 1.944s 2 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 50 sequential steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 13.817s 14.023s 0.206s 7 1.00x
🐘 Postgres Nitro 13.859s (-0.8%) 14.023s (-2.0%) 0.165s 7 1.00x
🐘 Postgres Express 14.090s (+0.6%) 14.881s (+2.0%) 0.791s 7 1.02x
💻 Local Next.js (Turbopack) 16.360s 17.031s 0.670s 6 1.18x
💻 Local Nitro 16.474s (-1.8%) 17.032s (~) 0.558s 6 1.19x
💻 Local Express 16.887s (+1.7%) 17.032s (~) 0.144s 6 1.22x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 57.559s (-85.4% 🟢) 58.911s (-85.1% 🟢) 1.352s 2 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.all with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 1.231s 2.009s 0.778s 15 1.00x
🐘 Postgres Nitro 1.259s (-1.2%) 2.010s (~) 0.751s 15 1.02x
🐘 Postgres Express 1.267s (+0.6%) 2.010s (~) 0.743s 15 1.03x
💻 Local Nitro 1.506s (-7.7% 🟢) 2.005s (-3.3%) 0.499s 15 1.22x
💻 Local Next.js (Turbopack) 1.529s 2.005s 0.476s 15 1.24x
💻 Local Express 1.598s (+7.3% 🔺) 2.006s (~) 0.409s 15 1.30x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 3.013s (-11.3% 🟢) 4.430s (-10.2% 🟢) 1.416s 7 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.all with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 2.318s (-1.8%) 3.009s (~) 0.691s 10 1.00x
🐘 Postgres Nitro 2.336s (-0.6%) 3.009s (~) 0.672s 10 1.01x
🐘 Postgres Next.js (Turbopack) 2.399s 3.008s 0.610s 10 1.03x
💻 Local Nitro 2.825s (-10.1% 🟢) 3.007s (-22.6% 🟢) 0.183s 10 1.22x
💻 Local Next.js (Turbopack) 2.839s 3.209s 0.370s 10 1.22x
💻 Local Express 2.994s (+1.4%) 3.760s (+8.9% 🔺) 0.766s 8 1.29x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.616s (-63.2% 🟢) 4.239s (-52.4% 🟢) 1.623s 8 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.all with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 3.472s (~) 4.009s (~) 0.537s 8 1.00x
🐘 Postgres Nitro 3.483s (~) 4.011s (~) 0.528s 8 1.00x
🐘 Postgres Next.js (Turbopack) 3.676s 4.009s 0.332s 8 1.06x
💻 Local Nitro 7.534s (-9.8% 🟢) 8.018s (-11.1% 🟢) 0.484s 4 2.17x
💻 Local Next.js (Turbopack) 7.708s 8.266s 0.558s 4 2.22x
💻 Local Express 8.517s (+2.1%) 9.271s (+2.7%) 0.755s 4 2.45x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 4.570s (-48.7% 🟢) 6.201s (-43.4% 🟢) 1.630s 5 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.race with 10 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 1.217s 2.009s 0.793s 15 1.00x
🐘 Postgres Express 1.252s (~) 2.008s (~) 0.756s 15 1.03x
🐘 Postgres Nitro 1.270s (+1.1%) 2.008s (~) 0.737s 15 1.04x
💻 Local Next.js (Turbopack) 1.499s 2.006s 0.506s 15 1.23x
💻 Local Nitro 1.584s (-15.1% 🟢) 2.006s (-14.3% 🟢) 0.422s 15 1.30x
💻 Local Express 1.607s (-15.2% 🟢) 2.006s (-15.1% 🟢) 0.399s 15 1.32x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.420s (-17.5% 🟢) 4.124s (-11.2% 🟢) 1.705s 8 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.race with 25 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 2.320s (-0.8%) 3.009s (~) 0.689s 10 1.00x
🐘 Postgres Express 2.361s (+0.8%) 3.009s (~) 0.648s 10 1.02x
🐘 Postgres Next.js (Turbopack) 2.378s 3.009s 0.630s 10 1.03x
💻 Local Next.js (Turbopack) 2.983s 3.760s 0.777s 8 1.29x
💻 Local Nitro 3.018s (-1.5%) 3.676s (-5.4% 🟢) 0.658s 9 1.30x
💻 Local Express 3.233s (+3.2%) 4.009s (+6.6% 🔺) 0.776s 8 1.39x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.797s (-11.0% 🟢) 4.301s (-4.9%) 1.504s 7 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

Promise.race with 50 concurrent steps

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 3.468s (~) 4.009s (~) 0.541s 8 1.00x
🐘 Postgres Express 3.546s (+1.3%) 4.012s (~) 0.467s 8 1.02x
🐘 Postgres Next.js (Turbopack) 3.635s 4.012s 0.376s 8 1.05x
💻 Local Next.js (Turbopack) 8.502s 9.020s 0.519s 4 2.45x
💻 Local Nitro 8.563s (-6.3% 🟢) 9.024s (-10.0% 🟢) 0.460s 4 2.47x
💻 Local Express 9.046s (+2.8%) 9.772s (+5.4% 🔺) 0.726s 4 2.61x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 4.787s (-29.2% 🟢) 6.953s (-18.6% 🟢) 2.166s 6 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 10 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.789s 1.023s 0.235s 59 1.00x
🐘 Postgres Nitro 0.800s (-2.5%) 1.006s (~) 0.206s 60 1.01x
🐘 Postgres Express 0.846s (+0.8%) 1.023s (~) 0.178s 59 1.07x
💻 Local Next.js (Turbopack) 0.862s 1.039s 0.177s 58 1.09x
💻 Local Express 0.995s (+1.1%) 1.276s (+18.6% 🔺) 0.281s 48 1.26x
💻 Local Nitro 1.021s (+4.1%) 1.748s (+59.9% 🔺) 0.727s 35 1.30x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 10.142s (-30.1% 🟢) 12.043s (-25.1% 🟢) 1.902s 6 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 25 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 1.925s (-2.6%) 2.076s (-8.1% 🟢) 0.150s 44 1.00x
🐘 Postgres Next.js (Turbopack) 1.929s 2.124s 0.195s 43 1.00x
🐘 Postgres Nitro 2.004s (+4.0%) 2.402s (+14.4% 🔺) 0.398s 38 1.04x
💻 Local Next.js (Turbopack) 2.667s 3.008s 0.341s 30 1.39x
💻 Local Nitro 3.028s (~) 3.689s (-1.8%) 0.661s 25 1.57x
💻 Local Express 3.063s (+1.6%) 4.010s (+11.9% 🔺) 0.947s 23 1.59x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 31.407s (-36.9% 🟢) 33.514s (-35.2% 🟢) 2.107s 3 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 50 sequential data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 3.914s 4.218s 0.304s 29 1.00x
🐘 Postgres Nitro 4.042s (-1.5%) 4.296s (-6.7% 🟢) 0.254s 28 1.03x
🐘 Postgres Express 4.212s (+5.6% 🔺) 4.812s (+10.1% 🔺) 0.600s 25 1.08x
💻 Local Next.js (Turbopack) 8.595s 9.018s 0.423s 14 2.20x
💻 Local Nitro 8.969s (-3.5%) 9.479s (-5.4% 🟢) 0.511s 13 2.29x
💻 Local Express 9.246s (~) 9.942s (-0.8%) 0.696s 13 2.36x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 79.499s (-25.8% 🟢) 81.232s (-25.4% 🟢) 1.733s 2 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 10 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.252s 1.007s 0.755s 60 1.00x
🐘 Postgres Nitro 0.290s (+2.3%) 1.007s (~) 0.717s 60 1.15x
🐘 Postgres Express 0.299s (+5.8% 🔺) 1.008s (~) 0.709s 60 1.19x
💻 Local Next.js (Turbopack) 0.557s 1.004s 0.448s 60 2.21x
💻 Local Nitro 0.568s (-6.1% 🟢) 1.004s (-1.7%) 0.436s 60 2.25x
💻 Local Express 0.594s (+6.1% 🔺) 1.005s (~) 0.410s 60 2.36x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.039s (+0.8%) 3.958s (+4.3%) 1.919s 17 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 25 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 0.501s (+0.9%) 1.007s (~) 0.506s 90 1.00x
🐘 Postgres Next.js (Turbopack) 0.510s 1.018s 0.508s 89 1.02x
🐘 Postgres Express 0.510s (~) 1.007s (~) 0.496s 90 1.02x
💻 Local Nitro 2.387s (-5.9% 🟢) 3.010s (~) 0.622s 30 4.77x
💻 Local Next.js (Turbopack) 2.564s 3.009s 0.445s 30 5.12x
💻 Local Express 2.612s (+3.9%) 3.009s (~) 0.397s 30 5.22x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 3.407s (-3.6%) 4.969s (-4.3%) 1.562s 19 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: Next.js (Turbopack)

workflow with 50 concurrent data payload steps (10KB)

💻 Local Development

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 0.782s (-4.5%) 1.007s (-1.0%) 0.226s 120 1.00x
🐘 Postgres Nitro 0.784s (-0.8%) 1.007s (~) 0.223s 120 1.00x
🐘 Postgres Next.js (Turbopack) 0.791s 1.007s 0.216s 120 1.01x
💻 Local Nitro 10.511s (-6.1% 🟢) 11.117s (-4.7%) 0.606s 11 13.45x
💻 Local Next.js (Turbopack) 11.010s 11.663s 0.654s 11 14.09x
💻 Local Express 11.419s (+2.0%) 12.028s (+0.7%) 0.609s 10 14.61x

▲ Production (Vercel)

World Framework Workflow Time Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 6.529s (-36.8% 🟢) 8.123s (-33.9% 🟢) 1.594s 15 1.00x
▲ Vercel Express ⚠️ missing - - - -
▲ Vercel Nitro ⚠️ missing - - - -

🔍 Observability: 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
💻 Local 🥇 Next.js (Turbopack) 0.172s 1.003s 0.012s 1.017s 0.846s 10 1.00x
🐘 Postgres Next.js (Turbopack) 0.190s 1.001s 0.001s 1.011s 0.821s 10 1.10x
🐘 Postgres Express 0.201s (-2.0%) 0.996s (~) 0.001s (-12.5% 🟢) 1.010s (~) 0.809s 10 1.17x
🐘 Postgres Nitro 0.207s (+0.8%) 0.993s (-0.7%) 0.001s (-20.0% 🟢) 1.010s (~) 0.803s 10 1.20x
💻 Local Express 0.207s (+3.9%) 1.004s (~) 0.013s (+3.3%) 1.019s (~) 0.812s 10 1.20x
💻 Local Nitro 0.209s (-2.3%) 1.004s (~) 0.010s (-20.0% 🟢) 1.016s (~) 0.807s 10 1.22x

▲ Production (Vercel)

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 2.194s (-68.0% 🟢) 3.590s (-58.5% 🟢) 1.019s (+61.2% 🔺) 5.041s (-48.5% 🟢) 2.847s 10 1.00x
▲ Vercel Express ⚠️ missing - - - - -
▲ Vercel Nitro ⚠️ missing - - - - -

🔍 Observability: Next.js (Turbopack)

stream pipeline with 5 transform steps (1MB)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Express 0.611s (-3.0%) 1.021s (+1.4%) 0.004s (+17.0% 🔺) 1.039s (+1.6%) 0.428s 58 1.00x
🐘 Postgres Next.js (Turbopack) 0.622s 1.026s 0.004s 1.039s 0.417s 58 1.02x
🐘 Postgres Nitro 0.635s (+1.7%) 1.022s (+1.6%) 0.004s (-6.2% 🟢) 1.045s (+2.2%) 0.410s 58 1.04x
💻 Local Next.js (Turbopack) 0.676s 1.012s 0.010s 1.024s 0.348s 59 1.11x
💻 Local Express 0.753s (-0.5%) 1.012s (-1.6%) 0.010s (+3.2%) 1.024s (-1.6%) 0.271s 59 1.23x
💻 Local Nitro 0.868s (+3.5%) 1.012s (~) 0.010s (+4.0%) 1.117s (~) 0.249s 54 1.42x

▲ Production (Vercel)

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 4.664s (-72.4% 🟢) 6.153s (-66.3% 🟢) 0.174s (-17.8% 🟢) 6.773s (-64.2% 🟢) 2.110s 9 1.00x
▲ Vercel Express ⚠️ missing - - - - -
▲ Vercel Nitro ⚠️ missing - - - - -

🔍 Observability: Next.js (Turbopack)

10 parallel streams (1MB each)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Next.js (Turbopack) 0.938s 1.201s 0.000s 1.208s 0.269s 50 1.00x
🐘 Postgres Express 0.946s (-1.6%) 1.082s (-15.3% 🟢) 0.000s (+25.5% 🔺) 1.098s (-16.0% 🟢) 0.152s 55 1.01x
🐘 Postgres Nitro 0.975s (+0.6%) 1.271s (+1.9%) 0.000s (-48.9% 🟢) 1.285s (+2.1%) 0.310s 47 1.04x
💻 Local Nitro 1.236s (+1.1%) 2.021s (~) 0.000s (+300.0% 🔺) 2.023s (~) 0.787s 30 1.32x
💻 Local Express 1.258s (+2.7%) 2.023s (~) 0.001s (+50.0% 🔺) 2.025s (~) 0.767s 30 1.34x
💻 Local Next.js (Turbopack) 1.285s 2.021s 0.000s 2.024s 0.739s 30 1.37x

▲ Production (Vercel)

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 3.414s (-66.5% 🟢) 4.676s (-59.4% 🟢) 0.000s (NaN%) 5.127s (-57.5% 🟢) 1.713s 12 1.00x
▲ Vercel Express ⚠️ missing - - - - -
▲ Vercel Nitro ⚠️ missing - - - - -

🔍 Observability: Next.js (Turbopack)

fan-out fan-in 10 streams (1MB each)

💻 Local Development

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
🐘 Postgres 🥇 Nitro 1.769s (-1.3%) 2.139s (~) 0.000s (-100.0% 🟢) 2.162s (-0.6%) 0.393s 28 1.00x
🐘 Postgres Express 1.816s (+2.5%) 2.139s (-1.8%) 0.000s (NaN%) 2.157s (-1.9%) 0.341s 28 1.03x
🐘 Postgres Next.js (Turbopack) 1.847s 2.072s 0.000s 2.113s 0.265s 29 1.04x
💻 Local Nitro 3.553s (+4.9%) 4.168s (+3.4%) 0.000s (-12.5% 🟢) 4.170s (+3.3%) 0.617s 15 2.01x
💻 Local Next.js (Turbopack) 3.701s 4.300s 0.001s 4.305s 0.604s 15 2.09x
💻 Local Express 3.702s (+6.8% 🔺) 4.100s (+1.6%) 0.001s (-25.0% 🟢) 4.103s (+1.6%) 0.401s 15 2.09x

▲ Production (Vercel)

World Framework Workflow Time TTFB Slurp Wall Time Overhead Samples vs Fastest
▲ Vercel 🥇 Next.js (Turbopack) 4.082s (-27.3% 🟢) 5.128s (-26.6% 🟢) 0.000s (-100.0% 🟢) 5.552s (-26.4% 🟢) 1.470s 11 1.00x
▲ Vercel Express ⚠️ missing - - - - -
▲ Vercel Nitro ⚠️ missing - - - - -

🔍 Observability: Next.js (Turbopack)

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World 🥇 Fastest Framework Wins
💻 Local Next.js (Turbopack) 13/21
🐘 Postgres Next.js (Turbopack) 9/21
▲ Vercel Next.js (Turbopack) 21/21
Fastest World by Framework

Winner determined by most benchmark wins

Framework 🥇 Fastest World Wins
Express 🐘 Postgres 19/21
Next.js (Turbopack) 🐘 Postgres 17/21
Nitro 🐘 Postgres 19/21
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


Some benchmark jobs failed:

  • Local: success
  • Postgres: success
  • Vercel: failure

Check the workflow run for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ ▲ Vercel Production 849 1 60 910
✅ 💻 Local Development 1006 0 86 1092
✅ 📦 Local Production 1006 0 86 1092
✅ 🐘 Local Postgres 1006 0 86 1092
✅ 🪟 Windows 91 0 0 91
✅ 📋 Other 255 0 18 273
Total 4213 1 336 4550

❌ Failed Tests

▲ Vercel Production (1 failed)

vite (1 failed):

Details by Category

❌ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 84 0 7
✅ example 84 0 7
✅ express 84 0 7
✅ fastify 84 0 7
✅ hono 84 0 7
✅ nextjs-turbopack 89 0 2
✅ nextjs-webpack 89 0 2
✅ nitro 84 0 7
✅ nuxt 84 0 7
❌ vite 83 1 7
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 85 0 6
✅ express-stable 85 0 6
✅ fastify-stable 85 0 6
✅ hono-stable 85 0 6
✅ nextjs-turbopack-canary 72 0 19
✅ nextjs-turbopack-stable 91 0 0
✅ nextjs-webpack-canary 72 0 19
✅ nextjs-webpack-stable 91 0 0
✅ nitro-stable 85 0 6
✅ nuxt-stable 85 0 6
✅ sveltekit-stable 85 0 6
✅ vite-stable 85 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 85 0 6
✅ express-stable 85 0 6
✅ fastify-stable 85 0 6
✅ hono-stable 85 0 6
✅ nextjs-turbopack-canary 72 0 19
✅ nextjs-turbopack-stable 91 0 0
✅ nextjs-webpack-canary 72 0 19
✅ nextjs-webpack-stable 91 0 0
✅ nitro-stable 85 0 6
✅ nuxt-stable 85 0 6
✅ sveltekit-stable 85 0 6
✅ vite-stable 85 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 85 0 6
✅ express-stable 85 0 6
✅ fastify-stable 85 0 6
✅ hono-stable 85 0 6
✅ nextjs-turbopack-canary 72 0 19
✅ nextjs-turbopack-stable 91 0 0
✅ nextjs-webpack-canary 72 0 19
✅ nextjs-webpack-stable 91 0 0
✅ nitro-stable 85 0 6
✅ nuxt-stable 85 0 6
✅ sveltekit-stable 85 0 6
✅ vite-stable 85 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 91 0 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 85 0 6
✅ e2e-local-postgres-nest-stable 85 0 6
✅ e2e-local-prod-nest-stable 85 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.

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 replay-time race in EventsConsumer where step_created could be incorrectly treated as orphaned in for await (const payload of hook) { await step(payload) } patterns, by adding an additional event-loop yield + promise-queue re-check before triggering the deferred “unconsumed event” failure path.

Changes:

  • Update EventsConsumer’s deferred unconsumed-event check to drain the promise queue, yield to the event loop, then drain again before scheduling the final delayed check.
  • Add a unit test reproducing the CI event-log pattern (alternating hook_received and step lifecycle events) for the hook + sleep + per-payload step scenario.
  • Add a patch changeset for @workflow/core.

Reviewed changes

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

File Description
packages/core/src/events-consumer.ts Adds a second promise-queue drain after a setTimeout(0) yield to avoid false-positive unconsumed events during replay.
packages/core/src/hook-sleep-interaction.test.ts Adds regression coverage for for await hook loops that call a step per payload while a sleep is pending.
.changeset/fix-unconsumed-event-hook-step-loop.md Declares a patch release for the core fix.

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

Comment on lines +118 to +127
.then(
// Yield to the event loop after the first queue drain. This allows
// microtask chains triggered by the preceding resolve() (e.g., a
// step result delivery that resumes a for-await loop, which then
// calls createHookPromise and appends a second round of async work
// to the promise queue) to propagate before we re-check the queue.
() => new Promise<void>((resolve) => setTimeout(resolve, 0))
)
.then(() => this.getPromiseQueue())
.then(() => {
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The deferred check promise chain always schedules the extra timer(s) even if a later subscribe() has already invalidated checkVersion. This can leave behind unnecessary timers (including the new setTimeout(0) yield) under high churn, keeping the event loop alive and doing extra work even though the check can never fire. Consider short‑circuiting before scheduling the setTimeout (and/or before the second getPromiseQueue() call) when this.unconsumedCheckVersion !== checkVersion so cancellation is cheap and no timers are created for stale checks.

Suggested change
.then(
// Yield to the event loop after the first queue drain. This allows
// microtask chains triggered by the preceding resolve() (e.g., a
// step result delivery that resumes a for-await loop, which then
// calls createHookPromise and appends a second round of async work
// to the promise queue) to propagate before we re-check the queue.
() => new Promise<void>((resolve) => setTimeout(resolve, 0))
)
.then(() => this.getPromiseQueue())
.then(() => {
.then(() => {
// If a newer subscribe() has already invalidated this check, bail out
// before scheduling the extra yield timer.
if (this.unconsumedCheckVersion !== checkVersion) {
return;
}
// Yield to the event loop after the first queue drain. This allows
// microtask chains triggered by the preceding resolve() (e.g., a
// step result delivery that resumes a for-await loop, which then
// calls createHookPromise and appends a second round of async work
// to the promise queue) to propagate before we re-check the queue.
return new Promise<void>((resolve) => setTimeout(resolve, 0));
})
.then(() => {
// Short-circuit stale checks before performing a second queue drain.
if (this.unconsumedCheckVersion !== checkVersion) {
return;
}
return this.getPromiseQueue();
})
.then(() => {
// If a later subscribe() has invalidated this check by the time both
// queue drains (and the yield) have completed, do not schedule the
// final timeout at all.
if (this.unconsumedCheckVersion !== checkVersion) {
return;
}

Copilot uses AI. Check for mistakes.
Comment on lines +639 to +646
const ctx = setupWorkflowContext([
{
eventId: 'evnt_0',
runId: 'wrun_test',
eventType: 'hook_created',
correlationId: `hook_${CORR_IDS[0]}`,
eventData: { token: 'test-token', isWebhook: false },
createdAt: new Date(),
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This test is intended to ensure an "unconsumed event" error does not occur, but setupWorkflowContext() configures EventsConsumer with onUnconsumedEvent: () => {}. That means the regression would manifest as a hang until the test times out (and it won’t surface the same error the real runtime throws). To make the regression signal deterministic and match production, consider letting the test pass an onUnconsumedEvent handler that rejects via ctx.onWorkflowError (or throws) so a failure is immediate and clearly attributed to the unconsumed-event path.

Copilot uses AI. Check for mistakes.
@pranaygp pranaygp marked this pull request as draft March 27, 2026 18:19
@VaguelySerious
Copy link
Copy Markdown
Member

Double checked this with an agent. I'm adding another e2e test to this PR and then will attempt to ship

Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Review

Good intent — adding multiple angles of regression coverage for the fix from #1778. The e2e test and the test-harness fix in hook-sleep-interaction.test.ts are particularly valuable. I have one blocking issue and some observations.

Blocking

The new test in workflow.test.ts imports DEFERRED_CHECK_DELAY_MS from ./events-consumer.js, but that export doesn't exist (neither on main nor on this branch). The "add more tests" commit (4701796) introduced this export, but the "WIP undo" commit (06a3f42) reverted the events-consumer.ts changes and left the test dangling.

At runtime, DEFERRED_CHECK_DELAY_MS is undefined, so DEFERRED_CHECK_DELAY_MS + 50 is NaN, and setTimeout(r, NaN) coerces to setTimeout(r, 0). The test passes, but it's not actually exercising the case it claims to — "hydrate latency exceeds the deferred-check window." It's running the happy path with near-zero hydrate delay.

See inline comment for fix options.

Non-blocking observations

  1. hook-sleep-interaction.test.ts harness fix is the most valuable change in this PR. The prior onUnconsumedEvent: () => {} silently swallowed errors, meaning any existing test in that file that triggered this error would have silently passed. Wiring it through ctx.onWorkflowError means existing tests now actually catch false-positive unconsumed events. This is a meaningful test infrastructure improvement.

  2. e2e test is good — verifies the fix through real queue/world infrastructure, not just unit-level mocks. The 5s + 3s sleeps between operations are necessary for the replay timing but slightly fragile; worth monitoring for flakes.

  3. Overlap with #1778's test: the existing test in #1778 already covers the alternating hook_received + step-lifecycle pattern with 150ms hydrate delay on call #3. The new hook-sleep-interaction.test.ts test covers similar territory but at the orchestrator-context level rather than runWorkflow level — a useful lower-level variant. Not duplicative.

Comment thread packages/core/src/workflow.test.ts Outdated
// production this corresponds to slower-than-expected encrypted payload
// decryption (cold cache, contended CPU, etc.); the fix must not rely on
// hydrate completing within the timer window.
const hydrateDelayMs = DEFERRED_CHECK_DELAY_MS + 50;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking: DEFERRED_CHECK_DELAY_MS is imported but doesn't exist, so this test isn't actually exercising slow hydrate.

  • Line 6 imports DEFERRED_CHECK_DELAY_MS from ./events-consumer.js
  • events-consumer.ts on this branch (and on main) does not export DEFERRED_CHECK_DELAY_MS — the 100ms value is an inline magic number at events-consumer.ts:141
  • At runtime: DEFERRED_CHECK_DELAY_MS is undefined, undefined + 50 = NaN, setTimeout(r, NaN) behaves as setTimeout(r, 0)
  • Net effect: the test claims to mock hydrate with > 100ms delay but actually mocks it with 0ms delay

So this test runs, passes, but isn't testing what the comment claims. The "WIP undo" commit removed the DEFERRED_CHECK_DELAY_MS export from events-consumer.ts (added in the "add more tests" commit) but left the import here.

Fix options:

  1. Re-export DEFERRED_CHECK_DELAY_MS from events-consumer.ts — this is the cleanest and also improves the production code by replacing the magic 100 at events-consumer.ts:141 with a named constant. Since the fix already shipped in fix false-positive unconsumed event in hook loop replay #1778, this would be a small follow-up enhancement worth including in this test-only PR.

  2. Hardcode the delay — e.g. const hydrateDelayMs = 150. Simplest, but couples the test to an implementation constant.

Option 1 is better. Recommend adding back:

// packages/core/src/events-consumer.ts
export const DEFERRED_CHECK_DELAY_MS = 100;
// ...
this.pendingUnconsumedTimeout = setTimeout(() => {
  // ...
}, DEFERRED_CHECK_DELAY_MS);

Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Blocking issue from prior review is resolved. The 'fix test' commit (5279e839) replaces the phantom DEFERRED_CHECK_DELAY_MS import with local constants:

const DEFFERED_CHECK_DELAY_MS = 100;
const BUFFER_FOR_TEST = 50;
const hydrateDelayMs = DEFFERED_CHECK_DELAY_MS + BUFFER_FOR_TEST;  // 150ms

hydrateDelayMs is now a real 150, which exceeds the actual 100ms deferred-check window hardcoded in events-consumer.ts:141. The test genuinely exercises the slow-hydrate race condition now.

Minor nit (non-blocking): DEFFERED is misspelled twice — should be DEFERRED. Worth fixing while you're in there. If/when the constant is eventually promoted to a proper export in events-consumer.ts (my earlier preferred option), the test can swap these locals out.

Otherwise LGTM — the test harness improvement in hook-sleep-interaction.test.ts remains the most valuable piece here, and the e2e test plus the additional workflow.test.ts case give good coverage of the race from multiple angles.

Signed-off-by: Peter Wielander <mittgfu@gmail.com>
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.

4 participants