Skip to content

[world-vercel] Bound HTTP timeouts and retry transport timeouts - #3169

Merged
VaguelySerious merged 1 commit into
stablefrom
peter/world-vercel-undici-timeouts
Jul 28, 2026
Merged

[world-vercel] Bound HTTP timeouts and retry transport timeouts#3169
VaguelySerious merged 1 commit into
stablefrom
peter/world-vercel-undici-timeouts

Conversation

@VaguelySerious

Copy link
Copy Markdown
Member

Problem

The shared undici Agent in world-vercel sets no headersTimeout/bodyTimeout, so undici's 5-minute defaults apply. That is longer than the queue's 300s visibility timeout, so a connection that accepts a request and then goes quiet outlives the lease the invocation is holding: the message redelivers, the run replays, and the whole thing is invisible — no step_retrying, no errorCode, just a ~305s gap between two consecutive workflow events.

This was found on a production customer on 4.5.0: 56 of 33,822 runs over 4 days (0.17%) each contain exactly one gap of 302.9–308.3s. The tightness of that distribution is what identifies it as a fixed timeout rather than workload variance. Two contributing signatures showed up in the outgoing-fetch logs for the invocations that went silent:

  • UND_ERR_HEADERS_TIMEOUT at ~300,300ms against the queue host — undici's default headersTimeout, on a path that has no other deadline (the queue client gets this dispatcher but does not go through makeRequest).
  • A POST /api/v3/runs/<wrun>/events aborted at 60,003ms — REQUEST_TIMEOUT_MS in utils.ts — with zero retries, because RetryAgent never retries a POST.

In both cases the invocation returned HTTP 200 having renewed its queue lease but never acked it.

Change

Timeouts (http-client.ts): headersTimeout and bodyTimeout are set to 30s. That is under both the queue's 60s visibility-extension interval and makeRequest's 60s deadline, so a stalled socket surfaces as a typed, retryable UND_ERR_*_TIMEOUT while callers can still react — instead of as an opaque outer abort, or (off the makeRequest path) not until the lease is already gone. Overridable via WORKFLOW_VERCEL_HEADERS_TIMEOUT_MS / WORKFLOW_VERCEL_BODY_TIMEOUT_MS; 0 disables.

Retries for timeouts: UND_ERR_HEADERS_TIMEOUT / UND_ERR_BODY_TIMEOUT are added to the RetryAgent's errorCodes (undici's defaults omit them, so a stalled socket was never retried at all), and maxRetries drops from undici's 5 to 2. These codes are ambiguous — the request may have been processed — so they stay scoped to RetryAgent's default methods, which never includes POST. The PUTs that go through this dispatcher are the legacy v1/v2 entity updates (cancel run, update step), idempotent in outcome; stream appends bypass the dispatcher entirely.

The retry budget is bounded deliberately: 3 attempts × 30s ≈ 92s with backoff, and the queue client wraps its acknowledge call in its own 3 attempts, so the product stays under the 300s visibility window. A test asserts that arithmetic so raising either constant fails.

POST event writes: since RetryAgent can't cover them, this backports the type-aware in-process retry from #2675 (event-retry.ts), whose transient set already includes the timeout codes. attr_set is dropped — it doesn't exist on this line. step_started, step_retrying, and hook_received stay at one attempt.

Validation

packages/world-vercel: 200 unit tests pass; workspace typecheck clean. New tests cover the env parsing (including the 0 and unparseable cases), the presence of the timeout codes, the retry-budget arithmetic, and — against a real socket that accepts and never responds — that the request fails with UND_ERR_HEADERS_TIMEOUT rather than hanging.

Two out-of-band probes against a hung local server, using the built dist and the real createWorkflowRunEvent (not committed):

event attempts outcome
step_completed 3 UND_ERR_HEADERS_TIMEOUT at 3× the configured timeout
step_started 1 UND_ERR_HEADERS_TIMEOUT, no attempt-counter double-increment

A raw POST through the dispatcher fails at the configured timeout with exactly one request reaching the server, confirming the dispatcher itself does not re-issue POSTs.

🤖 Generated with Claude Code

The shared undici Agent set no headersTimeout/bodyTimeout, so undici's
5-minute defaults applied. That is longer than the queue's 300s visibility
timeout, so one connection that accepted a request and then went quiet
outlived the lease the invocation was holding: the message redelivered, the
run replayed, and it surfaced as a ~305s gap between two consecutive workflow
events with no error recorded anywhere.

Set headersTimeout/bodyTimeout to 30s — under both the queue's 60s
visibility-extension interval and makeRequest's 60s deadline — so a stalled
socket fails fast as a typed UND_ERR_*_TIMEOUT while callers can still react.
Add those two codes to the RetryAgent's errorCodes (undici's defaults omit
them, so a stalled socket was never retried) and cap maxRetries at 2 so the
worst case stays inside the visibility window even when a caller wraps the
call in its own retries.

POST is never retried by the RetryAgent, so event writes get the type-aware
in-process retry from #2675, backported here (minus attr_set, which does not
exist on this line).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 187ab97

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

This PR includes changesets to release 17 packages
Name Type
@workflow/world-vercel Patch
@workflow/cli Patch
@workflow/core Patch
@workflow/web Patch
workflow Patch
@workflow/world-testing Patch
@workflow/builders Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared 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

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Jul 28, 2026 9:31pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment Jul 28, 2026 9:31pm
example-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-astro-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-express-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-fastify-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-hono-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-nestjs-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-nitro-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-nuxt-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-sveltekit-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workbench-vite-workflow Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workflow-docs Ready Ready Preview, Comment, Open in v0 Jul 28, 2026 9:31pm
workflow-swc-playground Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workflow-tarballs Ready Ready Preview, Comment Jul 28, 2026 9:31pm
workflow-web Ready Ready Preview, Comment Jul 28, 2026 9:31pm

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 1077 0 78 1155
✅ 💻 Local Development 1174 0 86 1260
✅ 📦 Local Production 1174 0 86 1260
✅ 🐘 Local Postgres 1174 0 86 1260
✅ 🪟 Windows 105 0 0 105
❌ 🌍 Community Worlds 82 102 9 193
✅ 📋 Other 594 0 36 630
Total 5380 102 381 5863

❌ Failed Tests

🌍 Community Worlds (102 failed)

redis (19 failed):

  • hookWorkflow | wrun_01KYNA44S6QPF8FGGYVK0VC10C
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KYNA4CY3QBBSWR8Y0GP3A81Z
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01KYNA4Q8XM9D536B1NHN03MTF
  • sleepingWorkflow | wrun_01KYNA5QT01W5TTTTN3HK8YHDM
  • 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
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KYNADWDT90JV3KTG2R7M9R65
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01KYNAE95CHCR2299V6PFVWTRT
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01KYNAEHCFF6NEBKTRVW3F4S12
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01KYNAEYYKNS1DWHQ4WNMT1S71
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01KYNAFVYQNX8JYAPHPNGN7JYG
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01KYNAG0TD7HF6SQDW1Y1B0K0Q
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01KYNAG6J45WRKB8D5S84W9TYB
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01KYNAGBTQH46PCQKHXVXK7KX7
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01KYNAGNJATQMYHH6GJ9KPXZHW
  • pages router sleepingWorkflow via pages router
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01KYNAPPYDK2AJ01QE1S9DHWES

turso (83 failed):

  • addTenWorkflow | wrun_01KYNA36XB54A64QQ0VESNATA3
  • addTenWorkflow | wrun_01KYNA36XB54A64QQ0VESNATA3
  • deploymentId: 'latest' is a no-op in non-Vercel worlds
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01KYNA58J9KEQNPFBRZPCA91P6
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01KYNA3ECYM4R4Z9RQP270MQ85
  • promiseRaceWorkflow | wrun_01KYNA3K529DF184525YYB8DJ1
  • promiseAnyWorkflow | wrun_01KYNA3NMPNPT6JARNZ7EG7FJA
  • importedStepOnlyWorkflow | wrun_01KYNA5M8WJM7RR8Y086Q09BRE
  • readableStreamWorkflow | wrun_01KYNA3R6S3GFGMPJ13F9A480Q
  • hookWorkflow | wrun_01KYNA44S6QPF8FGGYVK0VC10C
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KYNA4CY3QBBSWR8Y0GP3A81Z
  • webhookWorkflow | wrun_01KYNA4H7JMCTX2K086B4F8A6Z
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01KYNA4Q8XM9D536B1NHN03MTF
  • sleepingWorkflow | wrun_01KYNA5QT01W5TTTTN3HK8YHDM
  • parallelSleepWorkflow | wrun_01KYNA68800136G0CFJMBNX9RK
  • sleepWinsRaceWorkflow | wrun_01KYNA6BYZAZQ71F1EHN3TRJQ1
  • stepWinsRaceWorkflow | wrun_01KYNA6FNFR6EPFDKF5BTYTF5Y
  • nullByteWorkflow | wrun_01KYNA6KBQE0RJ2YEV6FS0NW83
  • workflowAndStepMetadataWorkflow | wrun_01KYNA6NSV54GF7KN634VM4SMZ
  • 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_01KYNA9196HCQBY6REKBM74TXK
  • writableForwardedFromWorkflowWorkflow | wrun_01KYNA9F7R14MFNW9ARXVF5AVQ
  • writableForwardedFromStepWorkflow | wrun_01KYNA9KK0039D56X4FH9M6FWF
  • fetchWorkflow | wrun_01KYNA9Q6X6C95NQH2MNXMMMSB
  • promiseRaceStressTestWorkflow | wrun_01KYNA9TQNBJCDKEQXYJTYR6VS
  • 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 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_01KYNADF4TVVJV995YDG4TMP7P
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KYNADWDT90JV3KTG2R7M9R65
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01KYNAE95CHCR2299V6PFVWTRT
  • 'hookGetConflictWithPriorStepWorkflow' - hook.getConflict() does not block step execution | wrun_01KYNAEBY1WB922GWTHVP6KE6B
  • 'hookGetConflictWithParallelStepWorkfl…' - hook.getConflict() does not block step execution | wrun_01KYNAEEFTK0AGXR2Q1HRTDCXV
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01KYNAEHCFF6NEBKTRVW3F4S12
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01KYNAEYYKNS1DWHQ4WNMT1S71
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01KYNAFVYQNX8JYAPHPNGN7JYG
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01KYNAG0TD7HF6SQDW1Y1B0K0Q
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01KYNAG6J45WRKB8D5S84W9TYB
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01KYNAGBTQH46PCQKHXVXK7KX7
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01KYNAGNJATQMYHH6GJ9KPXZHW
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01KYNAGWSHMXFDNAN3VRVGJ9NY
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01KYNAHD89AXEQPJ0PB1PCQCFK
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01KYNAHQKX45Q5AN5767EWSQJG
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01KYNAHXQA9XCJRAZQK827Y29R
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01KYNAJ03SENXPZ4M0ZV69DP6V
  • 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_01KYNAJGQEQEEXDS5D04K18G4T
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01KYNAJQ0Y6R25MJYQ369C764E
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01KYNAJYAQEQBPYCBHSDCGWETN
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01KYNAK5RR3KNFQS1JSQF6VFQK
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01KYNAKD3V3ZKK6R1V8X5VVVWD
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01KYNAKNVB2H4NE3BC8RAX3TVK
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01KYNAKX4CCTGHVXQ2Q6NDQX9A
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01KYNAMAT54QD97D2AAVZWF06V
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01KYNAMK8VZXC5BH0JA0780CZY
  • cancelRun - cancelling a running workflow | wrun_01KYNAMTT3C17BJ07ZKEBB0WF3
  • cancelRun via CLI - cancelling a running workflow | wrun_01KYNAN0ANTPH2VPT75E3330VM
  • 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_01KYNAN8R2RT98HDAYAPC8FVFE
  • hookWithSleepFinalStepWorkflow - step only on final payload | wrun_01KYNANP3JVC70KSJNR19EFYQK
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01KYNANZWNEQ8DMW986YGYMDN8
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01KYNAPAPSZ0PZY6VZHF5SQYQ7
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01KYNAPJ1KQGJ9KZJ0R6PYHK8K
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01KYNAPMGXW1V7J23F4NTBYV6T
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01KYNAPPYDK2AJ01QE1S9DHWES

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 97 0 8
✅ example 97 0 8
✅ express 97 0 8
✅ fastify 97 0 8
✅ hono 97 0 8
✅ nextjs-turbopack 102 0 3
✅ nextjs-webpack 102 0 3
✅ nitro 97 0 8
✅ nuxt 97 0 8
✅ sveltekit 97 0 8
✅ vite 97 0 8
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 99 0 6
✅ express-stable 99 0 6
✅ fastify-stable 99 0 6
✅ hono-stable 99 0 6
✅ nextjs-turbopack-canary 86 0 19
✅ nextjs-turbopack-stable 105 0 0
✅ nextjs-webpack-canary 86 0 19
✅ nextjs-webpack-stable 105 0 0
✅ nitro-stable 99 0 6
✅ nuxt-stable 99 0 6
✅ sveltekit-stable 99 0 6
✅ vite-stable 99 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 99 0 6
✅ express-stable 99 0 6
✅ fastify-stable 99 0 6
✅ hono-stable 99 0 6
✅ nextjs-turbopack-canary 86 0 19
✅ nextjs-turbopack-stable 105 0 0
✅ nextjs-webpack-canary 86 0 19
✅ nextjs-webpack-stable 105 0 0
✅ nitro-stable 99 0 6
✅ nuxt-stable 99 0 6
✅ sveltekit-stable 99 0 6
✅ vite-stable 99 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 99 0 6
✅ express-stable 99 0 6
✅ fastify-stable 99 0 6
✅ hono-stable 99 0 6
✅ nextjs-turbopack-canary 86 0 19
✅ nextjs-turbopack-stable 105 0 0
✅ nextjs-webpack-canary 86 0 19
✅ nextjs-webpack-stable 105 0 0
✅ nitro-stable 99 0 6
✅ nuxt-stable 99 0 6
✅ sveltekit-stable 99 0 6
✅ vite-stable 99 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 105 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 4 0 3
✅ redis-dev 4 0 3
❌ redis 67 19 0
✅ turso-dev 4 0 3
❌ turso 3 83 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 99 0 6
✅ e2e-local-dev-tanstack-start-stable 99 0 6
✅ e2e-local-postgres-nest-stable 99 0 6
✅ e2e-local-postgres-tanstack-start-stable 99 0 6
✅ e2e-local-prod-nest-stable 99 0 6
✅ e2e-local-prod-tanstack-start-stable 99 0 6

📋 View full workflow run

@VaguelySerious
VaguelySerious marked this pull request as ready for review July 28, 2026 21:38
@VaguelySerious
VaguelySerious requested review from a team and ijjk as code owners July 28, 2026 21:38

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

One documentation nit; I did not find a blocking correctness issue or regression in the implementation.

* `UND_ERR_HEADERS_TIMEOUT` while callers still have time to react — rather than
* as an opaque outer abort, or not at all.
*
* Override with `WORKFLOW_VERCEL_HEADERS_TIMEOUT_MS`; `0` disables the timeout.

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.

nit: These are new user-configurable environment variables, but the repo guidelines require every such variable to be documented. Could we add both WORKFLOW_VERCEL_HEADERS_TIMEOUT_MS and WORKFLOW_VERCEL_BODY_TIMEOUT_MS to docs/content/docs/deploying/world/vercel-world.mdx (and ideally the package README), including the 30s defaults and that 0 disables each timeout?

@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 the timeout bounds and event retry behavior. The world-vercel build and all 200 package tests pass locally; no blocking correctness issues found.

@pranaygp pranaygp 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 with the claims checked against their sources rather than taken on faith: I read every retryable: true handler in workflow-server's event-create path, undici 7.28.0's RetryHandler source, and @vercel/queue 0.3.1, and ran the package suite locally (200 tests pass, typecheck clean).

What verified cleanly:

  • Every event-sourced (v3/v4) classification in EVENT_RETRY_ELIGIBILITY matches the server: conditional creates → 409 for run/step/wait/hook_created; terminal-state .where() guards on run/step transitions (InvalidOperationStateError is HTTP 409); run_started early-returns the running run without a duplicate row; hook_disposed is a conditional delete; and the three exclusions are right (startStepPatch does .add({attempt: 1}), step_retrying's pending→pending patch passes its non-terminal guard and would append a duplicate row, hook_received has no guard). Entity handlers do run before the event-row insert, as the module doc claims.
  • undici's RetryHandler applies its methods gate to both errorCodes and statusCodes retries, so POSTs are truly never retried by the dispatcher — the in-process and dispatcher budgets don't stack. A POST 5xx surfaces as UND_ERR_REQ_RETRY, which TRANSIENT_CODES covers. RETRY_ERROR_CODES = undici defaults + the two timeout codes, exactly as documented. Firewall-challenge 429s land in the classifier as status 429 → not retried in-process, consistent with the dispatcher's 429 policy.
  • @vercel/queue 0.3.1's DIRECTIVE_CALL_ATTEMPTS is indeed 3, so the budget test's * 3 factor matches reality.

One real issue (inline on events.ts): the retry wrapper also covers the v1Compat legacy branch, whose endpoints don't have the guards the classification relies on — most notably v1 run_created mints the runId server-side, so a retry whose original landed creates a duplicate run. One-line guard suggested. main has the same shape from #2675, so the guard wants forward-porting too.

Forward-port note: main already has event-retry.ts (#2675) but not the http-client.ts half of this PR — 5.x still runs undici's 5-minute defaults with no timeout codes in errorCodes. This PR should get a companion on main so the actual production fix isn't stable-only.

E2E: Vercel Prod / Local / Postgres / Windows all green; the Community Worlds failures are the known non-blocking redis/turso set that also fails on main.

// queue delivery. Non-retryable types (step_started, step_retrying,
// hook_received) run once. See ./event-retry for the validated per-event
// classification.
return await withEventPostRetry(

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.

The retry wrapper also covers createWorkflowRunEventInner's v1Compat branch, but EVENT_RETRY_ELIGIBILITY was validated against the event-sourced handlers only — the legacy endpoints don't share those guards:

  • run_created + v1Compat (a start()/recreateRun of a specVersion-1 run) goes to POST /v1/runs/create, which mints the runId server-side (RunsService.createRunId.make(); CreateWorkflowRunRequest carries no client key). A retry whose original landed creates a second run — there's nothing to 409 on.
  • wait_completed + v1Compat (wakeUpRun on a legacy run) hits the server's handleLegacyEvent, which is a bare event.create with a fresh EventId.make() and no duplicate guard — a retry appends a duplicate event row. (Benign for legacy runs in practice, but it breaks the "no duplicate row" invariant the classification promises.)
  • run_cancelled + v1Compat goes through cancelWorkflowRunV1, a PUT via makeRequest — which the dispatcher's RetryAgent already retries, so this stacks up to 3×3 attempts. Idempotent in outcome; just noting the amplification.

Suggest bypassing the in-process retry for the legacy branch:

return params?.v1Compat
  ? await createWorkflowRunEventInner(id, data, params, config)
  : await withEventPostRetry(
      () => createWorkflowRunEventInner(id, data, params, config),
      data.eventType
    );

(main's events.ts has the identical shape from #2675, so the guard would want forward-porting as well.)

* Declared `satisfies Record<WorkflowEventType, …>` so adding or removing a
* world event type without classifying it is a compile error.
*/
export const EVENT_RETRY_ELIGIBILITY = {

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.

Worth stating in this docstring that the classification is derived from (and only valid for) the event-sourced create path — the v1Compat legacy endpoints (/v1/runs/create, /v1/runs/:id/events) don't share these guards; see the comment on events.ts for the concrete divergence.

For the event-sourced path itself I cross-checked every entry against workflow-server's handlers and they all hold (conditional creates → 409; terminal-state .where() guards with InvalidOperationStateError = 409; run_started early-return; hook_disposed conditional delete; and the three exclusions match startStepPatch's .add({attempt: 1}), step_retrying's pending→pending patch, and the unguarded hook_received).

// Each attempt can burn a full headers timeout. The queue client wraps its
// acknowledge call in its own 3 attempts, so the product must stay under
// the 300s visibility timeout or a hung ack still loses the lease.
expect(attempts * headersTimeout * 3).toBeLessThan(300_000);

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.

Nit: this worst-case product excludes both backoff layers — the RetryAgent sleeps 500ms + 1s between its 3 attempts (~1.5s per cycle), and the queue client adds 250ms × attempt between its 3 DIRECTIVE_CALL_ATTEMPTS — so the true worst case is ~275s, not 270s. Still comfortably under 300s today, but the assertion as written would accept WORKFLOW_VERCEL_HEADERS_TIMEOUT_MS-class changes up to 33s (3 × 33 × 3 = 297 < 300) while the real budget crosses the window. Consider adding the backoff terms to the arithmetic, or asserting against a smaller bound to preserve headroom.

*
* Exported so a test can assert the timeout codes stay in the list.
*/
export const RETRY_ERROR_CODES = [

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.

Optional/question: was leaving UND_ERR_CONNECT_TIMEOUT out deliberate? A connect timeout fires before the request is written, so it's the safest retry of the lot — safer than the two timeout codes this PR adds. Today it's only covered by the bespoke single-attempt retryConnectTimeout path in makeRequest (#3013) for flagged GETs; event POSTs get it via TRANSIENT_CODES, but a plain GET/PUT through this dispatcher never retries it. Fine to keep the backport diff minimal — just checking it was considered.

@VaguelySerious
VaguelySerious merged commit 9d8b293 into stable Jul 28, 2026
95 of 98 checks passed
@VaguelySerious
VaguelySerious deleted the peter/world-vercel-undici-timeouts branch July 28, 2026 23:50
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
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