Skip to content

refactor: replace HTTP status code checks with semantic error types#1342

Open
pranaygp wants to merge 1 commit intopgp/run-failed-schema-vailidation-errorfrom
pgp/semantic-world-errors
Open

refactor: replace HTTP status code checks with semantic error types#1342
pranaygp wants to merge 1 commit intopgp/run-failed-schema-vailidation-errorfrom
pgp/semantic-world-errors

Conversation

@pranaygp
Copy link
Collaborator

Summary

Replaces the pattern of catching WorkflowAPIError with HTTP status codes (409, 410, 429) in the runtime with semantic error types that each world implementation throws directly. This removes the coupling between the runtime and HTTP transport semantics.

Stacked on #1340#1339

Problem

The runtime had ~18 places doing this:

if (WorkflowAPIError.is(err) && err.status === 409) {
  // entity already in terminal state, skip
}

This is wrong because:

  • HTTP status codes are a world-vercel implementation detail leaking into the runtime
  • world-local and world-postgres had to fake HTTP status codes (new WorkflowAPIError('...', { status: 409 })) to match
  • The runtime shouldn't know about HTTP — it should handle semantic states

Solution

New semantic error types (@workflow/errors)

Error Replaces Meaning
EntityConflictError status === 409 Entity already in terminal state (run/step/wait finished)
RunExpiredError status === 410 Run has been cleaned up or expired
ThrottleError status === 429 Rate limited, carries retryAfter

All follow the existing HookNotFoundError / WorkflowRunNotFoundError pattern with .is() static method.

World implementations updated

  • world-vercel: makeRequest() maps HTTP 409 → EntityConflictError, 410 → RunExpiredError, 429 → ThrottleError at the throw site
  • world-local: All WorkflowAPIError({ status: 409 })EntityConflictError, etc.
  • world-postgres: Same pattern

Runtime updated

All ~18 catch sites now use semantic checks:

// Before
if (WorkflowAPIError.is(err) && err.status === 409) { ... }

// After
if (EntityConflictError.is(err)) { ... }

Files touched: runtime.ts, step-handler.ts, suspension-handler.ts, helpers.ts, runs.ts

WorkflowAPIError retained as catch-all

WorkflowAPIError remains for genuinely unexpected HTTP errors. The runtime no longer inspects .status on it.

Test plan

  • Build passes (all 27 packages)
  • Typecheck passes
  • All 478 core unit tests pass
  • All 220 world-local tests pass
  • Updated test files: helpers.test.ts, step-handler.test.ts, runs.test.ts
  • E2E tests (to be run on CI)

🤖 Generated with Claude Code

@vercel
Copy link
Contributor

vercel bot commented Mar 12, 2026

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 Mar 18, 2026 2:10am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Mar 18, 2026 2:10am
example-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-astro-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-express-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-fastify-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-hono-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-nitro-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-nuxt-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-sveltekit-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workbench-vite-workflow Ready Ready Preview, Comment Mar 18, 2026 2:10am
workflow-docs Ready Ready Preview, Comment, Open in v0 Mar 18, 2026 2:10am
workflow-nest Ready Ready Preview, Comment Mar 18, 2026 2:10am
workflow-swc-playground Ready Ready Preview, Comment Mar 18, 2026 2:10am

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 758 0 67 825
✅ 💻 Local Development 782 0 118 900
✅ 📦 Local Production 782 0 118 900
❌ 🐘 Local Postgres 781 1 118 900
✅ 🪟 Windows 72 0 3 75
❌ 🌍 Community Worlds 118 56 15 189
✅ 📋 Other 198 0 27 225
Total 3491 57 466 4014

❌ Failed Tests

🐘 Local Postgres (1 failed)

fastify-stable (1 failed):

  • webhookWorkflow
🌍 Community Worlds (56 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 (51 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
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control)

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 68 0 7
✅ example 68 0 7
✅ express 68 0 7
✅ fastify 68 0 7
✅ hono 68 0 7
✅ nextjs-turbopack 73 0 2
✅ nextjs-webpack 73 0 2
✅ nitro 68 0 7
✅ nuxt 68 0 7
✅ sveltekit 68 0 7
✅ vite 68 0 7
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 66 0 9
✅ express-stable 66 0 9
✅ fastify-stable 66 0 9
✅ hono-stable 66 0 9
✅ nextjs-turbopack-canary 55 0 20
✅ nextjs-turbopack-stable 72 0 3
✅ nextjs-webpack-canary 55 0 20
✅ nextjs-webpack-stable 72 0 3
✅ nitro-stable 66 0 9
✅ nuxt-stable 66 0 9
✅ sveltekit-stable 66 0 9
✅ vite-stable 66 0 9
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 66 0 9
✅ express-stable 66 0 9
✅ fastify-stable 66 0 9
✅ hono-stable 66 0 9
✅ nextjs-turbopack-canary 55 0 20
✅ nextjs-turbopack-stable 72 0 3
✅ nextjs-webpack-canary 55 0 20
✅ nextjs-webpack-stable 72 0 3
✅ nitro-stable 66 0 9
✅ nuxt-stable 66 0 9
✅ sveltekit-stable 66 0 9
✅ vite-stable 66 0 9
❌ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 66 0 9
✅ express-stable 66 0 9
❌ fastify-stable 65 1 9
✅ hono-stable 66 0 9
✅ nextjs-turbopack-canary 55 0 20
✅ nextjs-turbopack-stable 72 0 3
✅ nextjs-webpack-canary 55 0 20
✅ nextjs-webpack-stable 72 0 3
✅ nitro-stable 66 0 9
✅ nuxt-stable 66 0 9
✅ sveltekit-stable 66 0 9
✅ vite-stable 66 0 9
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 72 0 3
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 3 0 2
❌ mongodb 52 3 3
✅ redis-dev 3 0 2
❌ redis 53 2 3
✅ turso-dev 3 0 2
❌ turso 4 51 3
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 66 0 9
✅ e2e-local-postgres-nest-stable 66 0 9
✅ e2e-local-prod-nest-stable 66 0 9

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: success
  • Local Dev: success
  • Local Prod: success
  • Local Postgres: failure
  • Windows: success

Check the workflow run for details.

Copy link
Collaborator Author

pranaygp commented Mar 12, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: cb18ce3

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

This PR includes changesets to release 20 packages
Name Type
@workflow/errors Patch
@workflow/core Patch
@workflow/world-local Patch
@workflow/world-vercel Patch
@workflow/world-postgres Patch
@workflow/builders Patch
@workflow/cli Patch
workflow Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/world-testing Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/ai 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

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 2841381

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

This PR includes changesets to release 20 packages
Name Type
@workflow/errors Patch
@workflow/core Patch
@workflow/world-local Patch
@workflow/world-vercel Patch
@workflow/world-postgres Patch
@workflow/builders Patch
@workflow/cli Patch
workflow Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/world-testing Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/ai 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

@pranaygp pranaygp force-pushed the pgp/run-failed-schema-vailidation-error branch from e7068bf to e019085 Compare March 17, 2026 19:35
@pranaygp pranaygp force-pushed the pgp/semantic-world-errors branch from 90bd273 to 0a9c6f7 Compare March 17, 2026 19:35
@pranaygp pranaygp force-pushed the pgp/run-failed-schema-vailidation-error branch 6 times, most recently from 256bb01 to 1f26e4e Compare March 18, 2026 01:59
…runtime

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
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

Refactors error handling across the core runtime and world implementations to replace runtime-side HTTP status code branching (409/410/429) with semantic error types emitted by worlds, reducing coupling to HTTP transport details.

Changes:

  • Add new semantic error classes in @workflow/errors: EntityConflictError, RunExpiredError, ThrottleError.
  • Update world-vercel to map HTTP 409/410/429 to those semantic errors at the request boundary.
  • Update world-local, world-postgres, and @workflow/core runtime call sites to throw/catch semantic errors instead of WorkflowAPIError.status.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/world-vercel/src/utils.ts Map HTTP 409/410/429 responses to semantic errors in makeRequest()
packages/world-postgres/src/storage.ts Replace storage-layer WorkflowAPIError({status:409/410}) with semantic errors
packages/world-local/src/storage/events-storage.ts Replace local storage WorkflowAPIError({status:409/410}) with semantic errors
packages/world-local/src/fs.ts Use EntityConflictError for write conflicts instead of HTTP-encoded errors
packages/errors/src/index.ts Introduce semantic error classes for conflict/expired/throttle cases
packages/core/src/runtime/suspension-handler.ts Replace runtime checks for 409/410 with semantic errors in suspension flow
packages/core/src/runtime/step-handler.ts Replace runtime checks for 409/410/429 with semantic errors in step processing
packages/core/src/runtime/step-handler.test.ts Update tests to throw EntityConflictError instead of WorkflowAPIError(409)
packages/core/src/runtime/runs.ts Use EntityConflictError for wake-up conflict handling
packages/core/src/runtime/runs.test.ts Update tests to use EntityConflictError
packages/core/src/runtime.ts Replace runtime status checks (409/410) with semantic error guards
.changeset/semantic-world-errors.md Publish patch bumps for affected packages

💡 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 on lines +261 to +262
* Thrown when attempting to operate on a run that has been cleaned up or expired.
* Replaces WorkflowAPIError with status 410.
Comment on lines +188 to +191
// 425 Too Early: retryAfter timestamp not reached yet
// Return timeout to queue so it retries later
if (WorkflowAPIError.is(err) && err.status === 425) {
// Parse retryAfter from error response meta
Comment on lines +177 to +183
} else if (WorkflowAPIError.is(err) && err.status === 404) {
// Hook may have already been disposed or never created
runtimeLogger.info('Hook not found for disposal, continuing', {
workflowRunId: runId,
correlationId: queueItem.correlationId,
message: err.message,
});
}

/**
* Thrown when attempting to modify an entity that is already in a terminal state.
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