Skip to content

perf: parallelize suspension handler for high-concurrency#544

Merged
pranaygp merged 1 commit into
mainfrom
pranaygp/12-04-perf_parallelize_suspension_handler_for_high-concurrency
Dec 18, 2025
Merged

perf: parallelize suspension handler for high-concurrency#544
pranaygp merged 1 commit into
mainfrom
pranaygp/12-04-perf_parallelize_suspension_handler_for_high-concurrency

Conversation

@pranaygp
Copy link
Copy Markdown
Contributor

@pranaygp pranaygp commented Dec 5, 2025

The current implementation of suspension handler processes the invocation queue sequentially which is really slow. Now we process is in parallel:

  • Process hooks first, then steps and waits in parallel to prevent race conditions
  • Refactor runtime.ts into modular files: suspension-handler.ts, step-handler.ts, helpers.ts
  • nit: Add otel attributes for hooks created (workflow.hooks.created) and waits created (workflow.waits.created)
  • nit: Update suspension status from pending_steps to workflow_suspended

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 5, 2025

🦋 Changeset detected

Latest commit: 886548c

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

This PR includes changesets to release 12 packages
Name Type
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/web-shared Patch
workflow Patch
@workflow/astro Patch
@workflow/sveltekit Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch

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

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

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Dec 5, 2025

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

Project Deployment Review Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Dec 18, 2025 2:28am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Dec 18, 2025 2:28am
example-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-astro-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-express-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-fastify-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-hono-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-nitro-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-nuxt-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-sveltekit-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workbench-vite-workflow Ready Ready Preview, Comment Dec 18, 2025 2:28am
workflow-docs Ready Ready Preview, Comment Dec 18, 2025 2:28am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 5, 2025

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 286 0 11 297
✅ 💻 Local Development 262 0 8 270
✅ 📦 Local Production 262 0 8 270
✅ 🐘 Local Postgres 262 0 8 270
✅ 🪟 Windows 27 0 0 27
❌ 🌍 Community Worlds 109 11 0 120
Total 1208 11 35 1254

❌ Failed Tests

🌍 Community Worlds (11 failed)

mongodb (1 failed):

  • webhookWorkflow

redis (1 failed):

  • webhookWorkflow

starter (8 failed):

  • addTenWorkflow
  • addTenWorkflow
  • retryAttemptCounterWorkflow
  • crossFileErrorWorkflow - stack traces work across imported modules
  • hookCleanupTestWorkflow - hook token reuse after workflow completion
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars)
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step

turso (1 failed):

  • webhookWorkflow

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 26 0 1
✅ example 26 0 1
✅ express 26 0 1
✅ fastify 26 0 1
✅ hono 26 0 1
✅ nextjs-turbopack 26 0 1
✅ nextjs-webpack 26 0 1
✅ nitro 26 0 1
✅ nuxt 26 0 1
✅ sveltekit 26 0 1
✅ vite 26 0 1
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 26 0 1
✅ express-stable 26 0 1
✅ fastify-stable 26 0 1
✅ hono-stable 26 0 1
✅ nextjs-turbopack-stable 27 0 0
✅ nextjs-webpack-stable 27 0 0
✅ nitro-stable 26 0 1
✅ nuxt-stable 26 0 1
✅ sveltekit-stable 26 0 1
✅ vite-stable 26 0 1
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 26 0 1
✅ express-stable 26 0 1
✅ fastify-stable 26 0 1
✅ hono-stable 26 0 1
✅ nextjs-turbopack-stable 27 0 0
✅ nextjs-webpack-stable 27 0 0
✅ nitro-stable 26 0 1
✅ nuxt-stable 26 0 1
✅ sveltekit-stable 26 0 1
✅ vite-stable 26 0 1
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 26 0 1
✅ express-stable 26 0 1
✅ fastify-stable 26 0 1
✅ hono-stable 26 0 1
✅ nextjs-turbopack-stable 27 0 0
✅ nextjs-webpack-stable 27 0 0
✅ nitro-stable 26 0 1
✅ nuxt-stable 26 0 1
✅ sveltekit-stable 26 0 1
✅ vite-stable 26 0 1
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 3 0 0
❌ mongodb 26 1 0
✅ redis-dev 3 0 0
❌ redis 26 1 0
✅ starter-dev 3 0 0
❌ starter 19 8 0
✅ turso-dev 3 0 0
❌ turso 26 1 0

📋 View full workflow run

Copy link
Copy Markdown
Contributor Author

pranaygp commented Dec 5, 2025

@pranaygp pranaygp force-pushed the pranaygp/12-04-perf_use_map_for_invocationsqueue_o_1_lookup_delete_ branch 2 times, most recently from 61edd56 to bdefce0 Compare December 5, 2025 22:20
@pranaygp pranaygp force-pushed the pranaygp/12-04-perf_parallelize_suspension_handler_for_high-concurrency branch from c4a92e0 to 4d36770 Compare December 5, 2025 22:20
@pranaygp pranaygp force-pushed the pranaygp/12-04-perf_parallelize_suspension_handler_for_high-concurrency branch from 4210576 to 30e3e2c Compare December 7, 2025 03:28
@pranaygp pranaygp force-pushed the pranaygp/12-04-perf_parallelize_suspension_handler_for_high-concurrency branch from 30e3e2c to a9f53cb Compare December 16, 2025 01:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the workflow suspension handler to improve performance through parallelization and better code organization. The main runtime.ts file is split into modular components (suspension-handler.ts, step-handler.ts, helpers.ts) to improve maintainability, and the suspension processing is optimized to handle hooks, steps, and waits more efficiently.

Key Changes

  • Parallelization: Hooks are now processed sequentially first to prevent race conditions, followed by parallel processing of steps and waits for better performance
  • Code organization: Large runtime.ts file is refactored into focused, modular files that separate concerns
  • Enhanced telemetry: New OpenTelemetry attributes track hooks created (workflow.hooks.created) and waits created (workflow.waits.created) for better observability

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/core/src/telemetry/semantic-conventions.ts Adds new telemetry attributes for hooks and waits, updates suspension status naming from pending_steps to workflow_suspended
packages/core/src/runtime/suspension-handler.ts New module handling workflow suspensions with parallel processing of hooks, steps, and waits
packages/core/src/runtime/step-handler.ts Extracted step handler logic from runtime.ts with no functional changes
packages/core/src/runtime/helpers.ts New helper module containing shared utility functions (event loading, health checks, queue operations)
packages/core/src/runtime.ts Refactored to import and use modular components, removes large inline implementations
.changeset/fast-owls-flow.md Documents the performance improvement and refactoring changes

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

Comment on lines +143 to +151
} catch (err) {
if (WorkflowAPIError.is(err) && err.status === 409) {
// Step already exists, so we can skip it
console.warn(
`Step "${queueItem.stepName}" with correlation ID "${queueItem.correlationId}" already exists, skipping: ${err.message}`
);
return;
}
throw err;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error handling in processStep only checks for 409 (conflict) errors but not 410 (workflow completed) errors. This is inconsistent with processHook which handles both 409 and 410 status codes. When a workflow has already completed, attempting to create a step should be handled gracefully like hooks do, otherwise the error will bubble up and potentially cause issues.

Copilot uses AI. Check for mistakes.
- Process hooks first, then steps and waits in parallel to prevent race conditions
- Refactor runtime.ts into modular files: suspension-handler.ts, step-handler.ts, helpers.ts
- Add otel attributes for hooks created (workflow.hooks.created) and waits created (workflow.waits.created)
- Update suspension status from pending_steps to workflow_suspended
- Add retry logic to benchmark for unexpected content type errors
- Refactor stress test benchmarks to use shared config (10, 25 steps enabled; 100+ skipped)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants