Skip to content

Fix race conditions in webhook response handling#672

Merged
TooTallNate merged 1 commit intomainfrom
12-22-fix_race_conditions_in_webhook_response_handling
Dec 22, 2025
Merged

Fix race conditions in webhook response handling#672
TooTallNate merged 1 commit intomainfrom
12-22-fix_race_conditions_in_webhook_response_handling

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Dec 22, 2025

Fixed a race condition in the streamer where close events could arrive during disk reads, causing premature controller closure. This fixes the flakiness in the webhookWorkflow E2E test on "local" test suites.

What changed?

  • Added a pendingClose flag to buffer close events that arrive during disk reading
  • Modified the closeListener function to set this flag instead of immediately closing the controller when disk reads are in progress
  • Added logic to process any pending close events after disk reads complete

Why make this change?

There was a race condition in the streamer where close events arriving during disk reads would close the controller before all data was enqueued. This could lead to incomplete data streams and potential data loss. This fix ensures that all data is properly processed before the stream is closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 22, 2025

🦋 Changeset detected

Latest commit: e764695

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

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

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

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

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Dec 22, 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 22, 2025 8:22am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Dec 22, 2025 8:22am
example-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-astro-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-express-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-fastify-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-hono-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-nitro-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-nuxt-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-sveltekit-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workbench-vite-workflow Ready Ready Preview, Comment Dec 22, 2025 8:22am
workflow-docs Ready Ready Preview, Comment Dec 22, 2025 8:22am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 22, 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 110 10 0 120
Total 1209 10 35 1254

❌ Failed Tests

🌍 Community Worlds (10 failed)

mongodb (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 27 0 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
Member Author

TooTallNate commented Dec 22, 2025

@TooTallNate TooTallNate force-pushed the 12-22-fix_race_conditions_in_webhook_response_handling branch from 74ec92d to 2f9461f Compare December 22, 2025 08:20
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 fixes a race condition in the streamer's readFromStream method where close events arriving during disk reads would immediately close the ReadableStream controller before all data was enqueued, potentially causing data loss.

Key changes:

  • Added a pendingClose flag to buffer close events that arrive while reading from disk
  • Modified closeListener to set the flag instead of closing immediately when disk reads are in progress
  • Added logic to process buffered close events after disk reads and buffered event chunks are processed

Reviewed changes

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

File Description
packages/world-local/src/streamer.ts Implements the race condition fix by buffering close events during disk reads and processing them after disk reading completes
.changeset/webhook-response-body-fix.md Documents the fix for the changeset

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

@TooTallNate TooTallNate merged commit c3464bf into main Dec 22, 2025
79 checks passed
@TooTallNate TooTallNate deleted the 12-22-fix_race_conditions_in_webhook_response_handling branch December 22, 2025 18:41
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