Skip to content

[core] Re-queue the workflow when a step's terminal write conflicts - #4824

Closed
VaguelySerious wants to merge 1 commit into
stablefrom
peter/stable-step-completed-409-requeue
Closed

VaguelySerious wants to merge 1 commit into
stablefrom
peter/stable-step-completed-409-requeue

Conversation

@VaguelySerious

Copy link
Copy Markdown
Member

On stable, a run can get stuck in running with its last event a step_completed, and nothing ever wakes it.

How it happens

  1. The step handler POSTs step_completed. The write lands, but the response never reaches the client before the 30s transport timeout.
  2. The world's in-process event retry re-POSTs step_completed, and the backend answers 409 because the step is already completed.
  3. On EntityConflictError the step handler logged "step has already finished" and returned without queuing the workflow continuation. It assumed another invocation had finished the step and would wake the workflow. Here the conflicting write was its own, so no one queued the continuation. The step message is acked, so nothing redelivers it.

This was seen in production on workflow@4.8.x: the step invocation ran for 30.5s, the retried step_completed got a 409, and no further invocation or event followed for the run.

Fix
On a 409 from step_completed or any step_failed write, fall through and queue the workflow continuation. This matches what the handler already does for a 409 on step_started, and what #4422 did for the max-deliveries step_failed path. A duplicate wake only costs one replay.

step_retrying is unchanged. It is not retried in-process, so a 409 there cannot come from its own write.

Tests
Updated the existing 409 unit tests in step-handler.test.ts to assert that the continuation is queued, covering step_completed, max-retries step_failed, the pre-execution guard step_failed, and the missing-function step_failed. All four fail on the previous handler.

🤖 Generated with Claude Code

The world retries step_completed/step_failed POSTs in-process when a
response is lost. If the first write landed, the retry gets a 409, and the
step handler treated that as "another invocation finished the step" and
returned without queuing the workflow continuation. Nothing else wakes the
workflow in that case, so the run stays `running` forever with its last
event a step_completed.

Fall through to the continuation enqueue on a 409 from step_completed and
every step_failed write, matching the step_started conflict path and the
max-deliveries path. A duplicate wake only costs one replay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VaguelySerious
VaguelySerious requested review from a team and ijjk as code owners October 9, 2026 22:32
@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
example-nextjs-workflow-turbopack Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
example-nextjs-workflow-webpack Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
example-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-astro-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-express-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-fastify-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-hono-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-nestjs-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-nitro-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-nuxt-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-python-workflow Error Error v0 Oct 9, 2026 10:36pm UTC
workbench-sveltekit-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-tanstack-start-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workbench-vite-workflow Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workflow-docs Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workflow-swc-playground Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workflow-tarballs Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC
workflow-web Ready Ready Preview, v0 Oct 9, 2026 10:36pm UTC

@changeset-bot

changeset-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 21c2b7d

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

This PR includes changesets to release 16 packages
Name Type
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
workflow Patch
@workflow/world-testing Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch

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

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

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

❌ Some tests failed

Summary

Passed Failed Skipped Total
❌ ▲ Vercel Production 1098 1 78 1177
✅ 💻 Local Development 1198 0 86 1284
✅ 📦 Local Production 1198 0 86 1284
✅ 🐘 Local Postgres 1198 0 86 1284
✅ 🪟 Windows 107 0 0 107
❌ 🌍 Community Worlds 83 105 9 197
✅ 📋 Other 606 0 36 642
Total 5488 106 381 5975

❌ Failed Tests

▲ Vercel Production (1 failed)

sveltekit (1 failed):

  • writableForwardedFromStepWorkflow | wrun_01M4HD45WKMR8PV2SSQVN6Y3V3 | 🔍 observability
🌍 Community Worlds (105 failed)

redis (20 failed):

  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M4HCYJYTBHTBTZH97YCWG4V8
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M4HCYZBEK68RRDZ0JG7VRMK6
  • sleepingWorkflow | wrun_01M4HD02XN3MC7JAXG6ZH2357X
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M4HD8EQQ6QXVYJ8YXFP5F6PY
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M4HD8V4K64CGCWD992BW0T3Y
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M4HD925M08ZM5SKPP5MK0JG2
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M4HD9F5Q63KPC5MPFKQE2MCR
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M4HDAAJZWF7WSDPVNXYCERX2
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M4HDAF8SHNM5KS8X5296HQ8F
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M4HDAMRXW4M4BN779V0TB0HN
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M4HDATV5DTAR7PD9QJYGYY19
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M4HDB4B7HFAQ72QPZNW9JECH
  • pages router sleepingWorkflow via pages router
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M4HDGYKYY5399FSFDQ4CF1BT

turso (85 failed):

  • addTenWorkflow | wrun_01M4HCX4CNCASAQQ8THJVR0H49
  • addTenWorkflow | wrun_01M4HCX4CNCASAQQ8THJVR0H49
  • deploymentId: 'latest' is a no-op in non-Vercel worlds
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01M4HCZ3WVXMC6PCGHD2ZYZ75W
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01M4HCXD8HP56EG0ACRW39RABJ
  • promiseRaceWorkflow | wrun_01M4HCXM1M5GJS3S87TK3GGC88
  • promiseAnyWorkflow | wrun_01M4HCXQEN8SE84YJTSSP13F52
  • importedStepOnlyWorkflow | wrun_01M4HCZF56E11M05W34QNXJBSA
  • readableStreamWorkflow | wrun_01M4HCXTN2NK56VTDPS0BBSDCR
  • hookWorkflow | wrun_01M4HCYBJ6ATEWHGFAKN8S5D3T
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M4HCYJYTBHTBTZH97YCWG4V8
  • webhookWorkflow | wrun_01M4HCYQTWSCVZNK3655AC7N2A
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M4HCYZBEK68RRDZ0JG7VRMK6
  • sleepingWorkflow | wrun_01M4HD02XN3MC7JAXG6ZH2357X
  • parallelSleepWorkflow | wrun_01M4HD0JP1E7FQ6XXPQ9SWQVN6
  • sleepWinsRaceWorkflow | wrun_01M4HD0R6CT1GDFSF43S39S3G3
  • stepWinsRaceWorkflow | wrun_01M4HD0VK7RTAXRDWCKP43PHNG
  • nullByteWorkflow | wrun_01M4HD0YRW2C80A5PX2Q1R9AEH
  • workflowAndStepMetadataWorkflow | wrun_01M4HD10WB5HPXWM9YCTCWN2XK
  • outputStreamWorkflow no startIndex (reads all chunks)
  • outputStreamWorkflow positive startIndex (skips first chunk)
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • outputStreamInsideStepWorkflow - getWritable() called inside step functions | wrun_01M4HD3KCZBQ00AEKA8C3GHJN8
  • writableForwardedFromWorkflowWorkflow | wrun_01M4HD4230XFWP1P2DFNF95GA3
  • writableForwardedFromStepWorkflow | wrun_01M4HD45WKMR8PV2SSQVN6Y3V3
  • fetchWorkflow | wrun_01M4HD48EMRKXSX5M1ZVYAH900
  • promiseRaceStressTestWorkflow | wrun_01M4HD4BJS41HF0GCAVMV7WJEK
  • 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()
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • error handling not registered WorkflowNotRegisteredError fails the run when workflow does not exist
  • error handling not registered StepNotRegisteredError fails the step but workflow can catch it
  • error handling not registered StepNotRegisteredError fails the run when not caught in workflow
  • hookCleanupTestWorkflow - hook token reuse after workflow completion | wrun_01M4HD83KZ0FFRCAKE9T445B05
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M4HD8EQQ6QXVYJ8YXFP5F6PY
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M4HD8V4K64CGCWD992BW0T3Y
  • 'hookGetConflictWithPriorStepWorkflow' - hook.getConflict() does not block step execution | wrun_01M4HD8XFP3A065K0X16TPYJAT
  • 'hookGetConflictWithParallelStepWorkfl…' - hook.getConflict() does not block step execution | wrun_01M4HD8ZY2NWR4P1BGWKH2TJZS
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M4HD925M08ZM5SKPP5MK0JG2
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M4HD9F5Q63KPC5MPFKQE2MCR
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M4HDAAJZWF7WSDPVNXYCERX2
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M4HDAF8SHNM5KS8X5296HQ8F
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M4HDAMRXW4M4BN779V0TB0HN
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M4HDATV5DTAR7PD9QJYGYY19
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M4HDB4B7HFAQ72QPZNW9JECH
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01M4HDBBNH52R3EQJND0WCMRZE
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01M4HDBTKHH04ETX3BQCE7VV50
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01M4HDC4G5MBVPBFNGW3YXC085
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01M4HDC9S8RA5BJ6VVJGYKYH3Y
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01M4HDCBVXA2JQP3N6ZQGGNSZJ
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • health check (CLI) - workflow health command reports healthy endpoints
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01M4HDD0CR9EGZSVDADR6ZS514
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01M4HDD5VPZDWN538KY4RKD0H0
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01M4HDDCW9T67M16KH2H28HH6X
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01M4HDDSA6BF98EKAVEVJ7RFXC
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01M4HDE03287M7A82F60Q021AH
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01M4HDE6T2T4BR5RFWNFAMZ1VX
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01M4HDEDJDYYEFR26P9H87MAFG
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01M4HDERWPRFDVED8P8DS61Q93
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01M4HDF0KWR06VQA3JD8PHT91D
  • cancelRun - cancelling a running workflow | wrun_01M4HDF775QDJVWKWV185E86N0
  • cancelRun via CLI - cancelling a running workflow | wrun_01M4HDFCC6GK9EZK0X2BS1Y49H
  • 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 | wrun_01M4HDFKTRP7WR1R1ASAC7NBVK
  • hookWithSleepFinalStepWorkflow - step only on final payload | wrun_01M4HDG0FAP7C2SCGXE0GGVE5V
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01M4HDG94PCDCXVCWKAEV7ZV75
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01M4HDGKBX6756VWNHR65ZN61N
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01M4HDGT5FJDBMNW3G2ZM66ZZT
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01M4HDGW9ZNVACS8ZDSSNDP9TB
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M4HDGYKYY5399FSFDQ4CF1BT

Details by Category

❌ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 99 0 8
✅ example 99 0 8
✅ express 99 0 8
✅ fastify 99 0 8
✅ hono 99 0 8
✅ nextjs-turbopack 104 0 3
✅ nextjs-webpack 104 0 3
✅ nitro 99 0 8
✅ nuxt 99 0 8
❌ sveltekit 98 1 8
✅ vite 99 0 8
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 107 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 4 0 3
✅ redis-dev 4 0 3
❌ redis 68 20 0
✅ turso-dev 4 0 3
❌ turso 3 85 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 101 0 6
✅ e2e-local-dev-tanstack-start-stable 101 0 6
✅ e2e-local-postgres-nest-stable 101 0 6
✅ e2e-local-postgres-tanstack-start-stable 101 0 6
✅ e2e-local-prod-nest-stable 101 0 6
✅ e2e-local-prod-tanstack-start-stable 101 0 6

📋 View full workflow run

@karthikscale3 karthikscale3 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.

Reviewed commit 21c2b7d. The change correctly publishes the workflow continuation after terminal step-write conflicts while preserving redelivery on other write or publication failures.

Validated 43 focused tests, including four additional regression checks covering lost-response retry, publication failure/redelivery, FatalError, and missing-startedAt. All four additional checks fail against the parent and pass against this commit.

Approving the code change. The remaining failed/pending CI checks should be resolved before merging. Missing source events and recovery of already-orphaned runs remain separate work.

@VaguelySerious

Copy link
Copy Markdown
Member Author

Superseeded by #5028

This branch was successfully deployed

1 active deployment
Preview – workflow-docs — 21c2b7d9 Deployed Oct 9, 2026 by vercel[bot]
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.

2 participants