fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

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

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

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

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

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

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

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

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

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

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

@TooTallNate@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

fix(swc-plugin): closure variable detection for new expressions and module-level declarations - #1368

Merged
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs
Mar 16, 2026
Merged

fix(swc-plugin): closure variable detection for new expressions and module-level declarations#1368
TooTallNate merged 10 commits into
mainfrom
fix/swc-closure-variable-bugs

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

Fixes all four SWC compiler plugin bugs from #1365 related to closure variables:

  • Bug 1: new expressions (e.g. new MockLanguageModelV3(...args)) were not analyzed for closure variables because ClosureVariableCollector::collect_from_expr had no Expr::New case. Arguments and callee identifiers were silently missed.
  • Bug 2: Nested step functions in the step bundle were replaced with bare references to the hoisted copy, breaking direct (non-workflow) calls because __private_getClosureVars() has no values outside workflow context. Now the original function body is preserved inline (directive stripped) so JavaScript's normal closure semantics work for direct calls.
  • Bug 3: Module-level declarations (functions, variables, classes) were incorrectly captured as closure variables, since only import bindings were excluded. This caused runtime failures (serializing functions) and prevented DCE from removing step-only helpers and their imports from the workflow bundle.
  • Bug 4: Closure variables used deeply inside nested function/method bodies (e.g., inside a ReadableStream's start() method) were not detected because the collector skipped nested function/arrow/method bodies entirely. Now it walks into them while properly tracking inner parameters as local vars.

Additionally, the closure variable collector was expanded to handle many more AST patterns that were previously falling through silently (Prop::Shorthand, OptChain, Seq, Yield, Throw, Try/Catch/Finally, Switch, ForIn, ForOf, DoWhile, Labeled, computed property keys). Common Web API globals (ReadableStream, WritableStream, TransformStream, etc.) were added to the known globals list.

Changes

  • packages/swc-plugin-workflow/transform/src/lib.rs:
    • Add Expr::New arm to closure variable collector
    • Pass declared_identifiers to collect_from_function/collect_from_arrow_expr so module-level declarations are excluded
    • Preserve original step function bodies in enclosing functions (step mode) instead of replacing with bare hoisted references
    • Walk into nested function/arrow/method/getter/setter bodies for closure variable detection
    • Add handling for Prop::Shorthand, OptChain, Seq, Yield, computed keys, Throw, Try, Switch, ForIn, ForOf, DoWhile, Labeled
    • Add ReadableStream, WritableStream, TransformStream, and other Web API globals to known globals list
  • packages/swc-plugin-workflow/spec.md: Document all new behaviors
  • New test fixture closure-new-expr-and-module-declarations with 15 test cases
  • Updated fixture expectations across 10+ existing fixtures

All 172 tests pass with no regressions.

Fixes#1365
Fixes#1369

… module-level declarations
Fix two SWC compiler plugin bugs related to closure variable detection:
1. Add Expr::New handling to ClosureVariableCollector so `new Class(...args)`
properly captures both the callee and arguments as closure variables.
2. Exclude module-level declarations (functions, variables, classes) from
closure variable detection, preventing over-capturing of identifiers
that are already available in all bundles. This also allows DCE to
properly remove step-only helpers and their imports from the workflow
bundle.
Fixes#1365
@TooTallNate
TooTallNate requested a review from a team as a code ownerMarch 13, 2026 06:11
CopilotAI review requested due to automatic review settings March 13, 2026 06:11
@changeset-bot

changeset-botBot commented Mar 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85dc525

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

This PR includes changesets to release 17 packages
NameType
@workflow/swc-pluginPatch
@workflow/astroPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nestPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/vitePatch
@workflow/vitestPatch
@workflow/world-testingPatch
@workflow/nuxtPatch
@workflow/aiPatch
@workflow/corePatch
@workflow/web-sharedPatch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercelBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-nextjs-workflow-webpackReadyReadyPreview, CommentMar 16, 2026 10:54pm
example-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-astro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-express-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-fastify-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-hono-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nitro-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-nuxt-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-sveltekit-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workbench-vite-workflowReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-docsReadyReadyPreview, Comment, Open in v0Mar 16, 2026 10:54pm
workflow-nestReadyReadyPreview, CommentMar 16, 2026 10:54pm
workflow-swc-playgroundReadyReadyPreview, CommentMar 16, 2026 10:54pm

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

PassedFailedSkippedTotal
✅ ▲ Vercel Production560067627
✅ 💻 Local Development600084684
✅ 📦 Local Production600084684
✅ 🐘 Local Postgres600084684
✅ 🪟 Windows540357
❌ 🌍 Community Worlds1165515186
✅ 📋 Other144027171
Total2674553643093

❌ Failed Tests

🌍 Community Worlds (55 failed)

mongodb (3 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • webhookWorkflow
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

redis (2 failed):

  • hookWorkflow is not resumable via public webhook endpoint
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously

turso (50 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • importedStepOnlyWorkflow
  • hookWorkflow
  • hookWorkflow is not resumable via public webhook endpoint
  • 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 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
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
AppPassedFailedSkipped
✅ astro5007
✅ example5007
✅ express5007
✅ fastify5007
✅ hono5007
✅ nextjs-turbopack5502
✅ nextjs-webpack5502
✅ nitro5007
✅ nuxt5007
✅ sveltekit5007
✅ vite5007
✅ 💻 Local Development
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 📦 Local Production
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🐘 Local Postgres
AppPassedFailedSkipped
✅ astro-stable4809
✅ express-stable4809
✅ fastify-stable4809
✅ hono-stable4809
✅ nextjs-turbopack-canary5403
✅ nextjs-turbopack-stable5403
✅ nextjs-webpack-canary5403
✅ nextjs-webpack-stable5403
✅ nitro-stable4809
✅ nuxt-stable4809
✅ sveltekit-stable4809
✅ vite-stable4809
✅ 🪟 Windows
AppPassedFailedSkipped
✅ nextjs-turbopack5403
❌ 🌍 Community Worlds
AppPassedFailedSkipped
✅ mongodb-dev302
❌ mongodb5133
✅ redis-dev302
❌ redis5223
✅ turso-dev302
❌ turso4503
✅ 📋 Other
AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable4809
✅ e2e-local-postgres-nest-stable4809
✅ e2e-local-prod-nest-stable4809

📋 View full workflow run

@github-actions

github-actionsBot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

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

workflow with no steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Nitro0.042s (-2.1%)1.006s (~)0.964s101.00x
💻 LocalExpress0.042s (+3.7%)1.006s (~)0.964s101.00x
💻 LocalNext.js (Turbopack)0.047s1.005s0.958s101.12x
🌐 RedisNext.js (Turbopack)0.052s1.005s0.953s101.26x
🐘 PostgresNext.js (Turbopack)0.059s1.011s0.952s101.42x
🐘 PostgresExpress0.061s (-3.3%)1.012s (~)0.951s101.46x
🌐 MongoDBNext.js (Turbopack)0.113s1.008s0.895s102.70x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express0.503s (-2.0%)2.704s (+12.0% 🔺)2.201s101.00x
▲ VercelNitro0.518s (+12.7% 🔺)2.302s (-11.1% 🟢)1.784s101.03x
▲ VercelNext.js (Turbopack)0.584s (+22.0% 🔺)2.442s (+0.5%)1.858s101.16x

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

workflow with 1 step

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)1.116s2.006s0.890s101.00x
💻 LocalNitro1.120s (~)2.006s (~)0.886s101.00x
💻 LocalExpress1.124s (~)2.006s (~)0.882s101.01x
🌐 RedisNext.js (Turbopack)1.128s2.007s0.879s101.01x
🐘 PostgresExpress1.140s (-0.9%)2.014s (~)0.873s101.02x
🐘 PostgresNext.js (Turbopack)1.141s2.014s0.873s101.02x
🌐 MongoDBNext.js (Turbopack)1.319s2.008s0.689s101.18x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)1.990s (-1.2%)3.376s (-4.6%)1.386s101.00x
▲ VercelNitro2.021s (-0.9%)3.512s (-8.6% 🟢)1.490s101.02x
▲ VercelExpress2.093s (+0.7%)3.788s (-1.0%)1.695s101.05x

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

workflow with 10 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)10.757s11.023s0.266s31.00x
💻 LocalNext.js (Turbopack)10.844s11.023s0.180s31.01x
🐘 PostgresNext.js (Turbopack)10.855s11.043s0.188s31.01x
💻 LocalExpress10.891s (~)11.023s (~)0.132s31.01x
💻 LocalNitro10.892s (~)11.022s (~)0.130s31.01x
🐘 PostgresExpress10.961s (~)11.044s (~)0.083s31.02x
🌐 MongoDBNext.js (Turbopack)12.241s13.020s0.779s31.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro16.633s (+0.8%)18.580s (+3.3%)1.947s21.00x
▲ VercelExpress16.813s (-3.9%)18.598s (-8.6% 🟢)1.785s21.01x
▲ VercelNext.js (Turbopack)16.954s (+1.9%)18.335s (~)1.381s21.02x

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

workflow with 25 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)26.755s27.050s0.295s31.00x
💻 LocalNext.js (Turbopack)27.098s27.718s0.620s31.01x
🐘 PostgresExpress27.286s (~)28.067s (~)0.780s31.02x
🐘 PostgresNext.js (Turbopack)27.293s28.066s0.773s31.02x
💻 LocalExpress27.427s (~)28.051s (~)0.625s31.03x
💻 LocalNitro27.461s (~)28.051s (~)0.591s31.03x
🌐 MongoDBNext.js (Turbopack)30.437s31.039s0.602s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro43.937s (-6.9% 🟢)45.751s (-7.9% 🟢)1.814s21.00x
▲ VercelExpress44.547s (+1.2%)46.384s (+1.9%)1.838s21.01x
▲ VercelNext.js (Turbopack)46.044s (+4.2%)47.363s (+2.4%)1.320s21.05x

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

workflow with 50 sequential steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)53.410s54.098s0.688s21.00x
🐘 PostgresNext.js (Turbopack)54.011s54.106s0.095s21.01x
🐘 PostgresExpress54.354s (~)55.114s (~)0.760s21.02x
💻 LocalNext.js (Turbopack)55.809s56.099s0.289s21.04x
💻 LocalNitro56.584s (~)57.098s (~)0.513s21.06x
💻 LocalExpress56.614s (~)57.102s (~)0.488s21.06x
🌐 MongoDBNext.js (Turbopack)60.803s61.071s0.268s21.14x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)94.174s (-7.5% 🟢)96.390s (-6.1% 🟢)2.216s11.00x
▲ VercelNitro97.506s (-11.5% 🟢)98.716s (-12.4% 🟢)1.210s11.04x
▲ VercelExpress104.206s (~)106.460s (~)2.254s11.11x

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

Promise.all with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.335s2.006s0.672s151.00x
🐘 PostgresExpress1.435s (~)2.011s (~)0.577s151.08x
💻 LocalExpress1.511s (~)2.006s (~)0.495s151.13x
🐘 PostgresNext.js (Turbopack)1.522s2.012s0.490s151.14x
💻 LocalNitro1.526s (+1.8%)2.005s (~)0.479s151.14x
💻 LocalNext.js (Turbopack)1.540s2.006s0.466s151.15x
🌐 MongoDBNext.js (Turbopack)2.175s3.008s0.833s101.63x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.432s (-0.5%)3.962s (+2.1%)1.530s81.00x
▲ VercelExpress2.537s (-5.3% 🟢)4.009s (-9.9% 🟢)1.473s81.04x
▲ VercelNitro2.645s (-6.1% 🟢)3.965s (-7.5% 🟢)1.319s81.09x

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

Promise.all with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.529s3.008s0.479s101.00x
🐘 PostgresExpress2.647s (+5.3% 🔺)3.014s (~)0.366s101.05x
🐘 PostgresNext.js (Turbopack)2.709s3.114s0.405s101.07x
💻 LocalNext.js (Turbopack)2.753s3.107s0.355s101.09x
💻 LocalNitro2.859s (+1.9%)3.007s (~)0.148s101.13x
💻 LocalExpress2.879s (-3.1%)3.007s (-12.9% 🟢)0.128s101.14x
🌐 MongoDBNext.js (Turbopack)4.750s5.176s0.426s61.88x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.654s (-3.2%)3.878s (-12.5% 🟢)1.224s81.00x
▲ VercelNext.js (Turbopack)2.939s (-25.7% 🟢)4.106s (-19.6% 🟢)1.168s81.11x
▲ VercelExpress3.491s (+38.5% 🔺)5.529s (+39.2% 🔺)2.038s61.32x

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

Promise.all with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express3.972s (-4.3%)4.306s (-3.2%)0.335s71.00x
🌐 RedisNext.js (Turbopack)4.109s5.011s0.902s61.03x
🐘 PostgresNext.js (Turbopack)4.394s5.017s0.623s61.11x
💻 LocalNext.js (Turbopack)7.700s8.516s0.816s41.94x
💻 LocalNitro7.991s (~)8.519s (~)0.528s42.01x
💻 LocalExpress8.448s (+7.0% 🔺)9.019s (+9.1% 🔺)0.571s42.13x
🌐 MongoDBNext.js (Turbopack)9.884s10.349s0.465s32.49x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro4.766s (-29.9% 🟢)6.512s (-24.9% 🟢)1.746s61.00x
▲ VercelExpress5.771s (-13.8% 🟢)7.514s (-9.7% 🟢)1.743s41.21x
▲ VercelNext.js (Turbopack)6.504s (+39.0% 🔺)7.876s (+29.9% 🔺)1.372s41.36x

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

Promise.race with 10 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)1.297s2.006s0.709s151.00x
🐘 PostgresExpress1.411s (+1.0%)2.012s (~)0.601s151.09x
🐘 PostgresNext.js (Turbopack)1.430s2.011s0.581s151.10x
💻 LocalNitro1.495s (-2.5%)2.006s (~)0.511s151.15x
💻 LocalExpress1.509s (+0.9%)2.006s (~)0.497s151.16x
💻 LocalNext.js (Turbopack)1.514s2.006s0.491s151.17x
🌐 MongoDBNext.js (Turbopack)2.177s3.008s0.831s101.68x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Next.js (Turbopack)2.521s (-14.7% 🟢)3.814s (-18.6% 🟢)1.294s81.00x
▲ VercelExpress2.668s (+25.6% 🔺)4.613s (+3.9%)1.945s71.06x
▲ VercelNitro3.026s (+31.7% 🔺)4.402s (+10.6% 🔺)1.375s71.20x

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

Promise.race with 25 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🌐 Redis🥇 Next.js (Turbopack)2.574s3.008s0.434s101.00x
🐘 PostgresExpress2.579s (~)3.013s (~)0.434s101.00x
🐘 PostgresNext.js (Turbopack)2.682s3.013s0.331s101.04x
💻 LocalNext.js (Turbopack)2.905s3.309s0.404s101.13x
💻 LocalNitro2.958s (-4.3%)3.566s (-3.0%)0.607s91.15x
💻 LocalExpress2.994s (~)3.676s (-2.2%)0.682s91.16x
🌐 MongoDBNext.js (Turbopack)4.726s5.343s0.617s61.84x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro2.330s (-45.0% 🟢)3.833s (-37.2% 🟢)1.503s81.00x
▲ VercelNext.js (Turbopack)3.648s (+12.1% 🔺)5.166s (+14.6% 🔺)1.518s61.57x
▲ VercelExpress33.476s (+1159.9% 🔺)35.478s (+809.8% 🔺)2.002s214.37x

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

Promise.race with 50 concurrent steps

💻 Local Development

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
🐘 Postgres🥇 Express4.151s (+5.8% 🔺)4.589s (+3.2%)0.438s71.00x
🌐 RedisNext.js (Turbopack)4.171s5.012s0.840s61.00x
🐘 PostgresNext.js (Turbopack)4.303s5.017s0.714s61.04x
💻 LocalNext.js (Turbopack)7.977s8.268s0.292s41.92x
💻 LocalNitro8.452s (+3.3%)9.022s (~)0.570s42.04x
💻 LocalExpress9.014s (+2.2%)9.524s (~)0.510s42.17x
🌐 MongoDBNext.js (Turbopack)10.250s10.683s0.433s32.47x
🐘 PostgresNitro⚠️missing----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Nitro3.160s (-19.7% 🟢)4.650s (-20.3% 🟢)1.490s71.00x
▲ VercelNext.js (Turbopack)3.833s (+19.7% 🔺)5.031s (+1.3%)1.198s71.21x
▲ VercelExpress20.153s (+522.2% 🔺)22.122s (+338.7% 🔺)1.969s26.38x

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

Stream Benchmarks(includes TTFB metrics)
workflow with stream

💻 Local Development

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
💻 Local🥇 Next.js (Turbopack)0.166s1.002s0.011s1.018s0.852s101.00x
🌐 RedisNext.js (Turbopack)0.170s1.000s0.001s1.008s0.837s101.03x
💻 LocalNitro0.193s (-0.9%)1.003s (~)0.011s (-0.9%)1.017s (~)0.824s101.16x
🐘 PostgresNext.js (Turbopack)0.198s1.001s0.002s1.013s0.814s101.19x
💻 LocalExpress0.199s (~)1.003s (~)0.012s (+11.8% 🔺)1.018s (~)0.819s101.20x
🐘 PostgresExpress0.215s (-5.8% 🟢)1.000s (~)0.001s (-12.5% 🟢)1.013s (~)0.798s101.29x
🌐 MongoDBNext.js (Turbopack)0.517s0.935s0.002s1.009s0.492s103.11x
🐘 PostgresNitro⚠️missing-----

▲ Production (Vercel)

WorldFrameworkWorkflow TimeTTFBSlurpWall TimeOverheadSamplesvs Fastest
▲ Vercel🥇 Express1.844s (+20.6% 🔺)2.625s (+13.8% 🔺)0.005s (-9.3% 🟢)3.296s (+14.8% 🔺)1.452s101.00x
▲ VercelNitro2.447s (+55.7% 🔺)3.255s (+37.2% 🔺)0.005s (-5.3% 🟢)3.776s (+26.8% 🔺)1.329s101.33x
▲ VercelNext.js (Turbopack)2.496s (+40.6% 🔺)3.552s (+22.2% 🔺)0.339s (+6298.1% 🔺)4.461s (+31.9% 🔺)1.966s101.35x

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

Summary

Fastest Framework by World

Winner determined by most benchmark wins

World🥇 Fastest FrameworkWins
💻 LocalNext.js (Turbopack)9/12
🐘 PostgresExpress8/12
▲ VercelNitro6/12
Fastest World by Framework

Winner determined by most benchmark wins

Framework🥇 Fastest WorldWins
Express🐘 Postgres8/12
Next.js (Turbopack)🌐 Redis8/12
Nitro💻 Local8/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


Some benchmark jobs failed:

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

Check the workflow run for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWC plugin closure-variable analysis so step extraction correctly captures identifiers used in new expressions, and avoids over-capturing module-scope declarations (which can lead to attempting to serialize functions and can block DCE of step-only helpers).

Changes:

  • Add Expr::New handling in ClosureVariableCollector to analyze constructor callee + args.
  • Exclude module-level declarations (in addition to imports) from closure-variable detection by seeding collector locals with declared_identifiers.
  • Add a new fixture covering both scenarios and update the plugin spec + changelog entry.

Reviewed changes

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

Show a summary per file
FileDescription
packages/swc-plugin-workflow/transform/src/lib.rsImplements Expr::New traversal and passes module-level declared identifiers into closure var collection to prevent over-capture.
packages/swc-plugin-workflow/spec.mdDocuments the updated closure-variable detection behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/input.jsNew fixture input reproducing both reported bugs.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-workflow.jsExpected workflow-mode output validating closure capture and DCE-friendly behavior.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-step.jsExpected step-mode output validating rehydration + direct access to module-level helpers.
packages/swc-plugin-workflow/transform/tests/fixture/closure-new-expr-and-module-declarations/output-client.jsExpected client-mode output validating closure capture in non-step bundle.
.changeset/fix-swc-closure-variable-bugs.mdChangeset for patch release of @workflow/swc-plugin.

💡 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 threadpackages/swc-plugin-workflow/spec.md Outdated
Comment threadpackages/swc-plugin-workflow/spec.md Outdated
…ure variable collector
Expand closure variable detection to cover more AST patterns:
Expressions: Seq (comma), Yield, OptChain, Prop::Shorthand,
computed property keys, Prop::Assign defaults, Class (skip bodies)
Statements: Throw, Try/Catch/Finally, Switch, ForIn, ForOf,
DoWhile, Labeled
Also fix existing Prop::Shorthand bug where object shorthand
properties like { url } were not being collected as closure vars.
Extend test fixture with cases for all newly handled patterns.
Fix spec.md wording per review feedback.
…od bodies
The closure variable collector was skipping nested function expressions,
arrow functions, and method bodies entirely. This meant closure
variables used deep inside inner functions (e.g., a variable used inside
a ReadableStream's start() method) were not captured.
Now the collector walks into nested function/arrow/method/getter/setter
bodies while adding their parameters to the local var set, so only
truly free variables from the outer step scope are captured.
Also add ReadableStream, WritableStream, TransformStream, and other
common Web API globals to the known globals list.
…es in closure detection
After comparing with Next.js's SWC plugin closure detection approach,
identified and fixed remaining gaps:
- TypeScript expression wrappers (as, satisfies, !, type assertions,
const assertions, instantiation expressions) now traverse to the
inner expression instead of being silently skipped
- Class expressions and declarations now walk their body members
(methods, properties, constructors, static blocks) to detect
closure variables used inside them
- Document all remaining safe-to-skip Expr variants (This, Lit,
SuperProp, MetaProp, PrivateName, Invalid, JSX)
…ion wrappers
Add a proper input.ts fixture that tests closure variable detection
through real TypeScript syntax: `as`, `satisfies`, `!` (non-null),
angle-bracket type assertions, `as const`, and generic function calls.
Update test harness to support input.ts files by adding swc_ecma_parser
dev-dependency and auto-detecting TypeScript syntax from file extension.
Remove the incorrectly placed TypeScript-related test cases from the JS
fixture (they were using plain JS syntax, not actual TS wrappers).
@ghostghost mentioned this pull request Mar 16, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure variables break steps from being reused as normal functions outside workflow context 3 compiler bugs related to closure variables

3 participants

@TooTallNate@VaguelySerious