Skip to content

world-local: converge redelivered hook_received re-ensure on its committed resumeId claim - #3297

Merged
TooTallNate merged 2 commits into
mainfrom
fix-world-local-resume-redelivery-converge
Aug 3, 2026
Merged

world-local: converge redelivered hook_received re-ensure on its committed resumeId claim#3297
TooTallNate merged 2 commits into
mainfrom
fix-world-local-resume-redelivery-converge

Conversation

@TooTallNate

Copy link
Copy Markdown
Member

Problem

world-local's events.create('hook_received', …) runs its disposal-committed and hook-existence rejections before the (runId, resumeId) claim convergence added for lazy hook resumption (#3230). A queue redelivery of the consumer's re-ensure — after the workflow has disposed the hook (e.g. the using hook = createHook(…) → dispose → sleep() pattern, which releases the token while the run continues) — therefore gets HookNotFoundError even though this exact resume is already committed.

The consumer contract (runtime.ts lazy-resume prologue) treats HookNotFoundError as "the run went terminal / nothing left to resume" and acks the delivery. Any continuation the redelivered message was carrying is silently dropped and the run wedges. Natural triggers include a consumer crash after the re-ensure but before ack, a queue retry racing the dispose, or an engine that reschedules via visibility-timeout redelivery of the resume message (where this was found: the QuickJS engine branch, #3048).

Fix

Check the (runId, resumeId) claim first: a committed claim whose pinned event is journaled proves this exact resume was accepted while the hook was alive — return that event as success (idempotent convergence, matching the documented server behavior). Everything else is unchanged:

  • claims with a mismatched hookId or payload digest still fall through to full validation and are rejected as before
  • genuinely new resumes of a disposed hook are still rejected with HookNotFoundError
  • a claim whose pinned event is not yet visible (crash between claim write and append) still goes through the disposal/existence checks

Notes

  • world-postgres is unaffected: it deliberately does not advertise lazy hook-resume dedup (no resumeId column) and stays on the sequential single-writer path, so the re-ensure redelivery shape never occurs there.
  • New regression test in hook-resume-dedup.test.ts covers converge-after-dispose plus the still-rejected new-resume case.
  • Backport candidate: correctness/wedge fix to existing functionality.

…itted resumeId claim

A redelivered re-ensure of an already-committed resume (same runId +
resumeId + digest) was rejected with HookNotFoundError when the hook had
since been disposed by the workflow (dispose -> sleep releases the
token while the run continues). The queue consumer treats HookNotFound
as 'nothing left to resume' and acks the delivery — silently dropping
whatever continuation the redelivered message carried and wedging the
run.

Check the (runId, resumeId) claim BEFORE the disposal/existence
rejections: a committed claim whose pinned event is journaled proves
this exact resume was accepted while the hook was alive, so return that
event as success. Claims with a mismatched hookId or payload digest
still fall through to full validation and are rejected as before, as
are genuinely new resumes of a disposed hook.
Copilot AI review requested due to automatic review settings August 3, 2026 18:50
@TooTallNate
TooTallNate requested review from a team and ijjk as code owners August 3, 2026 18:50
@vercel

vercel Bot commented Aug 3, 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 Aug 3, 2026 7:05pm
example-nextjs-workflow-webpack Ready Ready Preview Aug 3, 2026 7:05pm
example-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-astro-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-express-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-fastify-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-hono-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-nestjs-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-nitro-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-nuxt-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-sveltekit-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-tanstack-start-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workbench-vite-workflow Ready Ready Preview Aug 3, 2026 7:05pm
workflow-docs Ready Ready Preview, v0 Aug 3, 2026 7:05pm
workflow-swc-playground Ready Ready Preview Aug 3, 2026 7:05pm
workflow-tarballs Ready Ready Preview Aug 3, 2026 7:05pm
workflow-web Ready Ready Preview Aug 3, 2026 7:05pm

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ee823c7

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

This PR includes changesets to release 18 packages
Name Type
@workflow/world-local Patch
@workflow/cli Patch
@workflow/core Patch
@workflow/vitest Patch
@workflow/web 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/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 Aug 3, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit ee823c7 · Mon, 03 Aug 2026 19:23:41 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1251 (+190%) 🔻 1300 🔴 (+26%) 🔻 1310 🔴 (+25%) 🔻 1358 🔴 (-12%) 30
TTFS stream 1264 (+33%) 🔻 1338 🔴 (+34%) 🔻 1347 🔴 (+34%) 🔻 1472 🔴 (+40%) 🔻 30
TTFS hook + stream 1507 (+27%) 🔻 1565 🔴 (+22%) 🔻 1616 🔴 (+24%) 🔻 1763 🔴 (+29%) 🔻 30
STSO 1020 steps (inline) 137 (-16%) 💚 469 (±0%) 530 (±0%) 735 (+3.7%) 1016
STSO 1020 steps (queue-hop) 2257 (+7.1%) 3317 (+6.0%) 3317 (+6.0%) 3317 (+6.0%) 3
WO 1020 steps 400242 (±0%) 400242 (±0%) 400242 (±0%) 400242 (±0%) 1
SL stream latency 95 (+17%) 🔻 177 🔴 (+46%) 🔻 179 🔴 (+30%) 🔻 298 🔴 (+61%) 🔻 30
SO stream overhead (text) 90 (-14%) 150 (-18%) 💚 194 (-6.7%) 253 (-66%) 💚 30
SO stream overhead (structured) 99 (-4.8%) 129 (-22%) 💚 148 (-28%) 💚 194 (-24%) 💚 30
📈 STSO distribution vs main (inline / queue-hop histograms)

1020 steps (inline)

Cumulative STSO time: main 393223ms → this run 390119ms (Δ -3104ms, -1%)

  100-150 ms  ┃                         main   0  this   1    +1
  150-200 ms  ████┃                     main  32  this  43   +11
  200-250 ms  ████████████┃             main  98  this 105    +7
  250-300 ms  ██████████████┃███        main 144  this 122   -22
  300-350 ms  ████████████████┃         main 138  this 138    +0
  350-400 ms  ████████████████░░░░░░░┃  main 132  this 193   +61
  400-450 ms  ██████████████┃██████     main 167  this 122   -45
  450-500 ms  ██████████████┃█          main 131  this 120   -11
  500-550 ms  ███████████┃█             main 103  this  96    -7
  550-600 ms  ███┃                      main  34  this  35    +1
  600-650 ms  █┃                        main  16  this  16    +0
  650-700 ms  ┃                         main  10  this   8    -2
  700-750 ms  ┃                         main   3  this   8    +5
  750-800 ms  ┃                         main   4  this   2    -2
  800-850 ms  ┃                         main   3  this   3    +0
  850-900 ms  ┃                         main   1  this   0    -1
  900-950 ms  ┃                         main   0  this   1    +1
1050-1100 ms  ┃                         main   0  this   2    +2
1200-1250 ms  ┃                         main   0  this   1    +1

1020 steps (queue-hop)

Cumulative STSO time: main 7422ms → this run 8760ms (Δ +1338ms, +18%)

2000-2500 ms  ███████████┃████████████  main 2  this 1  -1
3000-3500 ms  ████████████░░░░░░░░░░░┃  main 1  this 2  +1
ℹ️ Metric definitions & methodology

The collapsed STSO distribution section above buckets every step gap of the sequential-steps run (not a sampled window), split by whether the step ending the gap ran inline — in the same warm process as the step before it, so the gap is pure framework overhead — or after a queue-hop — the first step of a fresh process, which pays queue dispatch, client reinit and event-log replay. Bars overlay the two runs: is main, marks where this run lands, bridges the gap when this run has more samples in a bucket.

Best/P75/P90/P99 deltas compare against the most recent benchmark run on main at the time of this run. 🔻 flags a delta worse than +15%, 💚 one better than −15%.

Metrics — TTFS: time to first step body (in-deployment start() → first step body, deployment clocks) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored) · SL: stream latency (in-deployment write → read propagation, readAt - writtenAt) · SO: stream overhead (end-to-end write+consume time beyond the modelled generation window)

Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · stream latency: parallel reader/writer steps on a dedicated stream; SL is the in-deployment write->read propagation (readAt - writtenAt) · stream overhead (text): writer streams 300 variable-length text token deltas paced at 100/s for 3s (a haiku-size LLM's token throughput) while a parallel reader drains the whole stream; SO is the end-to-end write+consume time beyond the 3s generation window (overhead/backpressure) · stream overhead (structured): same workload as stream overhead (text), but each delta is an AI-SDK-style structured object ({ type: 'text-delta', id, text }) instead of a raw string, so the SO gap vs the text scenario is the added serialization cost

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · SO 250/500/1000

All metrics are measured from deployment-side timestamps only. Runs are triggered by an in-deployment route that stamps the anchor (clientStart) right before start(), so the CI runner’s request and its path through api.vercel.com sit outside every measured window. TTFS = in-deployment start() → first step body (turbo uses the in-process fast path, non-turbo the dispatch path), and includes the VQS dispatch hop plus any /flow cold start. STSO/WO are measured between step bodies on the deployment. SL is measured inside the workflow (parallel reader/writer steps), so it no longer includes the api.vercel.com read path.

Cold starts are kept in the numbers on purpose — they are part of real bursty-workload latency. The workbench deployment cold-starts the /flow invocation for a large fraction of runs, inflating P75+; the Best column shows the fastest (warm-start) sample for comparison.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

❌ Failed E2E Tests

📦 Local Production (1 failed)

hono-stable (1 failed):

  • webhookWorkflow | wrun_41KZ4H91NT0GW21QHEYR3J97N6

E2E Test Summary

Summary
Passed Failed Skipped Total
✅ ▲ Vercel Production 1455 0 239 1694
✅ 💻 Local Development 1621 0 227 1848
❌ 📦 Local Production 1620 1 227 1848
✅ 🐘 Local Postgres 1621 0 227 1848
✅ 🪟 Windows 154 0 0 154
✅ 📋 Other 1020 0 212 1232
✅ vercel-multi-region 27 0 0 27
Total 7518 1 1132 8651
Details by Category

✅ ▲ Vercel Production

App Passed Failed Skipped
✅ astro 126 0 28
✅ example 126 0 28
✅ express 126 0 28
✅ fastify 126 0 28
✅ hono 126 0 28
✅ nextjs-turbopack 151 0 3
✅ nextjs-webpack 151 0 3
✅ nitro 126 0 28
✅ nuxt 126 0 28
✅ sveltekit 145 0 9
✅ vite 126 0 28

✅ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

❌ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
❌ hono-stable 127 1 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack 154 0 0

✅ 📋 Other

App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 128 0 26
✅ e2e-local-dev-tanstack-start- 128 0 26
✅ e2e-local-postgres-nest-stable 128 0 26
✅ e2e-local-postgres-tanstack-start- 128 0 26
✅ e2e-local-prod-nest-stable 128 0 26
✅ e2e-local-prod-tanstack-start- 128 0 26
✅ e2e-vercel-prod-nest 126 0 28
✅ e2e-vercel-prod-tanstack-start 126 0 28

✅ vercel-multi-region

App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

Copilot AI 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.

Pull request overview

Fixes a correctness edge case in @workflow/world-local’s lazy hook resumption dedup: when a hook_received re-ensure message is redelivered after the workflow has disposed the hook, the consumer should converge on the already-committed (runId, resumeId) claim (and return the already-journaled event) instead of rejecting with HookNotFoundError, which can otherwise cause the consumer to ack and drop a continuation.

Changes:

  • Check the (runId, resumeId) resume-claim convergence path before hook disposal/existence rejection for hook_received, returning the committed event when it’s already journaled.
  • Add a regression test covering “converge-after-dispose” redelivery plus the still-rejected “new resume after disposal” case.
  • Add a patch changeset for @workflow/world-local.

Reviewed changes

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

File Description
packages/world-local/src/storage/events-storage.ts Reorders hook_received validation to converge redeliveries on an existing committed resume claim/event even if the hook has since been disposed.
packages/world-local/src/storage/hook-resume-dedup.test.ts Adds regression coverage for redelivery convergence after hook disposal and confirms new resumes post-disposal still reject.
.changeset/world-local-resume-redelivery-converge.md Publishes the fix as a patch release note for @workflow/world-local.

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

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

Looks good to me.

@TooTallNate
TooTallNate enabled auto-merge (squash) August 3, 2026 19:01
@TooTallNate
TooTallNate disabled auto-merge August 3, 2026 19:35
@TooTallNate
TooTallNate merged commit aa78a7e into main Aug 3, 2026
158 of 179 checks passed
@TooTallNate
TooTallNate deleted the fix-world-local-resume-redelivery-converge branch August 3, 2026 19:43
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

No backport to stable for aa78a7e (AI decision).

This is a correctness/wedge fix, but it is built entirely on the (runId, resumeId) claim infrastructure from the main-only lazy hook-resume dedup work (#3230): origin/stable's packages/world-local/src/storage/events-storage.ts has no resumeId, hookResumeClaimPath, or HookResumeClaimSchema at all (git grep resumeId origin/stable -- packages/world-local returns nothing), and hook-resume-dedup.test.ts does not exist there. The bug shape it fixes (a redelivered consumer re-ensure carrying a resumeId) therefore cannot occur on stable, and the patch has no code to apply against.

To override, re-run the Backport to stable workflow manually via workflow_dispatch and paste this commit SHA into the ref input:

aa78a7e63c73e170f32143b22e01e796a537c405

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