Skip to content

[stable] Harden event pagination responses#2179

Merged
VaguelySerious merged 1 commit into
stablefrom
pranaygp/codex/harden-event-pagination-stable
May 31, 2026
Merged

[stable] Harden event pagination responses#2179
VaguelySerious merged 1 commit into
stablefrom
pranaygp/codex/harden-event-pagination-stable

Conversation

@pranaygp
Copy link
Copy Markdown
Contributor

Summary

  • deduplicate overlapping event-log pages returned during cursor pagination
  • retry a rejected continuation cursor once by reloading the event log from the beginning
  • fail with a world contract error when pagination returns no usable progress
  • deduplicate events before appending the stable runtime's wait-completion delta

Why

This is client-side defense in depth for the cursor compatibility issue addressed by vercel/workflow-server#454. On stable, the optimized wait-completion replay path appends the cursor delta directly. If a server ignores the cursor and restarts the read at the beginning, previously committed events can be appended again and corrupt replay.

The server still needs to preserve legacy cursor compatibility for already deployed clients. This backport also makes the stable client tolerant of overlapping or rejected cursor reads and fails cleanly for non-progressing pagination.

Validation

  • pnpm --filter '@workflow/core...' build
  • Node v24.15.0: pnpm --filter @workflow/core typecheck
  • Node v24.15.0: pnpm --filter @workflow/core test (639 tests passed)
  • pnpm exec biome check packages/core/src/runtime/helpers.ts packages/core/src/runtime/helpers.test.ts packages/core/src/runtime/wait-completion-replay.test.ts .changeset/calm-events-guard.md
  • git diff --check

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 30, 2026

🦋 Changeset detected

Latest commit: e4da7eb

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

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 30, 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 May 30, 2026 9:41pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment May 30, 2026 9:41pm
example-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-astro-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-express-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-fastify-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-hono-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-nitro-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-nuxt-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-sveltekit-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workbench-vite-workflow Ready Ready Preview, Comment May 30, 2026 9:41pm
workflow-docs Ready Ready Preview, Comment, Open in v0 May 30, 2026 9:41pm
workflow-swc-playground Ready Ready Preview, Comment May 30, 2026 9:41pm
workflow-tarballs Ready Ready Preview, Comment May 30, 2026 9:41pm
workflow-web Ready Ready Preview, Comment May 30, 2026 9:41pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 901 0 67 968
✅ 💻 Local Development 970 0 86 1056
✅ 📦 Local Production 970 0 86 1056
✅ 🐘 Local Postgres 970 0 86 1056
❌ 🌍 Community Worlds 15 69 0 84
✅ 📋 Other 492 0 36 528
Total 4318 69 361 4748

❌ Failed Tests

🌍 Community Worlds (69 failed)

mongodb-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

redis-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

turso-dev (1 failed):

  • dev e2e should rebuild on imported step dependency change

turso (66 failed):

  • addTenWorkflow | wrun_01KSXD83HBJY4QM0X3FTE6WESW
  • addTenWorkflow | wrun_01KSXD83HBJY4QM0X3FTE6WESW
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01KSXDA47MS2BDPF2N0Y9SMXS0
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01KSXD8AWB5D33J9ANCXBPH6MJ
  • promiseRaceWorkflow | wrun_01KSXD8F4JG81STT12GWHG2C2N
  • promiseAnyWorkflow | wrun_01KSXD8J707E9EFMPEGN3CJNDE
  • importedStepOnlyWorkflow | wrun_01KSXDAHMES033R52SPZN36A6G
  • readableStreamWorkflow | wrun_01KSXD8N9A233AHG5PVABSB91W
  • hookWorkflow | wrun_01KSXD95RK5BZRK9WGG7T1T0A6
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KSXD9BER11J34J4CH7YMXND2
  • webhookWorkflow | wrun_01KSXD9GJ2A9AZXHZ2PC1H8ASQ
  • sleepingWorkflow | wrun_01KSXD9QPKV9H8HQ6N46RWDPN3
  • parallelSleepWorkflow | wrun_01KSXDA70PW5ZWHVG4RQ7FPB74
  • nullByteWorkflow | wrun_01KSXDAA45EYKDRSR98JPBCX40
  • workflowAndStepMetadataWorkflow | wrun_01KSXDAC387Z3V8FHEG322TBJT
  • 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_01KSXDCPFFCPH5VH2QA3QD6P27
  • fetchWorkflow | wrun_01KSXDD4MDJRP5ADD4AXK6NFYW
  • promiseRaceStressTestWorkflow | wrun_01KSXDD7NYGW5AMR0TGQ7NPREH
  • 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_01KSXDGD1FXGB75FRMQN20H5GD
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KSXDGRPVMQX0RVWJ9Z7DXQAY
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01KSXDH9MXARBJTENXBSSXX2VS
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01KSXDHR7S49N1SVYXB68Q1CG6
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01KSXDJ0HKGKE2W69AP98D9P45
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01KSXDJ5G8YYTAH8JEECH0BBJD
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01KSXDJ7CH33DBHVWAHQZFDXQB
  • 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_01KSXDJNPVMKQSGWKH4TB41312
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01KSXDJTXJKV72NB6QP69SMCVX
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01KSXDK1VW9ZFN8E1JP2CXZDPY
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01KSXDK889AMYNVE1QE87F3BFM
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01KSXDKENRM7QTGZJV4YT6V349
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01KSXDKNWFM9S38W9VN2YXKHYN
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01KSXDKVZR7VV0KTTQMD3QD1AQ
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01KSXDM7MN57YXN7190WFBX3Z6
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01KSXDMG6K99RSQK4HA345YNV9
  • cancelRun - cancelling a running workflow | wrun_01KSXDMQDZRCS0YMDA6HC501G5
  • cancelRun via CLI - cancelling a running workflow | wrun_01KSXDN03GE6PF7AV5JP8GKNAM
  • 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_01KSXDNBJVCHK59KM1C2T3Y98X
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01KSXDNW4RP0TNEZEFZTJDEEN0
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01KSXDP6HKPKJ92P8DK020SDCX
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01KSXDPCNDNHKX9RWRYTZ2P9HS
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01KSXDPER5QZJFNP318R8K31K8
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01KSXDPGX84RXX5JHNMXSSEMKE

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 81 0 7
✅ example 81 0 7
✅ express 81 0 7
✅ fastify 81 0 7
✅ hono 81 0 7
✅ nextjs-turbopack 86 0 2
✅ nextjs-webpack 86 0 2
✅ nitro 81 0 7
✅ nuxt 81 0 7
✅ sveltekit 81 0 7
✅ vite 81 0 7
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 82 0 6
✅ express-stable 82 0 6
✅ fastify-stable 82 0 6
✅ hono-stable 82 0 6
✅ nextjs-turbopack-canary 69 0 19
✅ nextjs-turbopack-stable 88 0 0
✅ nextjs-webpack-canary 69 0 19
✅ nextjs-webpack-stable 88 0 0
✅ nitro-stable 82 0 6
✅ nuxt-stable 82 0 6
✅ sveltekit-stable 82 0 6
✅ vite-stable 82 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 82 0 6
✅ express-stable 82 0 6
✅ fastify-stable 82 0 6
✅ hono-stable 82 0 6
✅ nextjs-turbopack-canary 69 0 19
✅ nextjs-turbopack-stable 88 0 0
✅ nextjs-webpack-canary 69 0 19
✅ nextjs-webpack-stable 88 0 0
✅ nitro-stable 82 0 6
✅ nuxt-stable 82 0 6
✅ sveltekit-stable 82 0 6
✅ vite-stable 82 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 82 0 6
✅ express-stable 82 0 6
✅ fastify-stable 82 0 6
✅ hono-stable 82 0 6
✅ nextjs-turbopack-canary 69 0 19
✅ nextjs-turbopack-stable 88 0 0
✅ nextjs-webpack-canary 69 0 19
✅ nextjs-webpack-stable 88 0 0
✅ nitro-stable 82 0 6
✅ nuxt-stable 82 0 6
✅ sveltekit-stable 82 0 6
✅ vite-stable 82 0 6
❌ 🌍 Community Worlds
App Passed Failed Skipped
❌ mongodb-dev 4 1 0
❌ redis-dev 4 1 0
❌ turso-dev 4 1 0
❌ turso 3 66 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 82 0 6
✅ e2e-local-dev-tanstack-start-stable 82 0 6
✅ e2e-local-postgres-nest-stable 82 0 6
✅ e2e-local-postgres-tanstack-start-stable 82 0 6
✅ e2e-local-prod-nest-stable 82 0 6
✅ e2e-local-prod-tanstack-start-stable 82 0 6

📋 View full workflow run


Some E2E test jobs failed:

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

Check the workflow run for details.

@pranaygp pranaygp marked this pull request as ready for review May 31, 2026 01:51
@pranaygp pranaygp requested a review from a team as a code owner May 31, 2026 01:51
Copilot AI review requested due to automatic review settings May 31, 2026 01:51
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

Client-side defense in depth for cursor pagination in the stable runtime. Hardens getWorkflowRunEvents() against overlapping pages, rejected continuation cursors, and non-progressing pagination, and deduplicates events in the wait-completion replay append path.

Changes:

  • Add dedup, cursor-rejection retry (once), and progress assertions to getWorkflowRunEvents().
  • Deduplicate newEvents.events before appending in the wait-completion replay optimized path.
  • Add helper and replay tests plus a patch changeset.

Reviewed changes

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

Show a summary per file
File Description
packages/core/src/runtime/helpers.ts Adds pagination dedup, contract-error assertions, and one-shot retry on 400 cursor rejection
packages/core/src/runtime.ts Dedupes wait-completion delta events before appending
packages/core/src/runtime/helpers.test.ts Tests for overlap dedup, 400 retry, cursor-repeat, and missing-cursor failures
packages/core/src/runtime/wait-completion-replay.test.ts Test for delta that restarts at the beginning
.changeset/calm-events-guard.md Patch changeset for @workflow/core

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

Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious left a comment

Choose a reason for hiding this comment

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

AI review: no blocking issues

);
}
if (requestedCursors.has(cursor)) {
throw eventPaginationContractError(runId, 'repeated a cursor');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI Review: Nit

The repeated-cursor guard terminates the common failure mode this PR targets (a backend that restarts the read at the beginning re-issues cursors we've already requested). It does not bound the loop against a backend that returns an endless stream of fresh cursors with hasMore: trueappendUniqueEvents keeps the result flat, but the while (hasMore) loop never exits. Since pagesLoaded is already tracked, a sanity cap (throwing the same contract error past, say, N pages) would fully close the non-progression hole rather than just the repeated-cursor case.

return (
cursor !== null &&
!alreadyRetried &&
WorkflowWorldError.is(error) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI Review: Note

The full-reload fallback only engages on error.status === 400. If a backend ever signals a rejected/expired cursor with a different 4xx (404/410/422), the retry won't trigger and the error propagates straight to run_failed. If the contract guarantees 400 for cursor rejection this is fine; otherwise consider matching the set of statuses the backend can use. (Also worth noting: a 400 surfaced on the cursorless initial load classifies as USER_ERROR via classifyRunError, since isWorldContractError bails when status is set — pre-existing, just flagging the interaction.)

Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious left a comment

Choose a reason for hiding this comment

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

AI review: no blocking issues

Human: please address the nits and forward-port those in the other PR

@VaguelySerious VaguelySerious merged commit e256858 into stable May 31, 2026
154 of 164 checks passed
@VaguelySerious VaguelySerious deleted the pranaygp/codex/harden-event-pagination-stable branch May 31, 2026 08:47
VaguelySerious added a commit that referenced this pull request May 31, 2026
Co-authored-by: Peter Wielander <mittgfu@gmail.com>
@github-actions github-actions Bot mentioned this pull request May 31, 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