Skip to content

feat(core): resume hooks from stored resumeContext and seal to the run key - #3125

Merged
karthikscale3 merged 2 commits into
mainfrom
kk/hook-resume-context
Jul 28, 2026
Merged

feat(core): resume hooks from stored resumeContext and seal to the run key#3125
karthikscale3 merged 2 commits into
mainfrom
kk/hook-resume-context

Conversation

@karthikscale3

@karthikscale3karthikscale3 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What

Hooks can carry an optional resumeContext — the immutable slice of the owning run needed to route and decrypt a resume: deployment ID, workflow name, run spec version, core version, trace carrier, and (when the run publishes one) its X25519 encryptionPublicKey. resumeHook/resumeWebhook use it to resume a hook directly.

Why

Resuming a hook previously always fetched the full run to recover its routing and encryption context, adding a run round trip to every resume — including on the hot webhook path. Sealed payloads made this worse: a resume would additionally fetch the run's symmetric key (~350ms cross-deployment run-key hop) to write its payload.

How

  • When resumeContext is present, route the resume from the stored context and skip runs.get entirely.
  • When the context also carries encryptionPublicKey, seal the payload (encp) directly to that key — no symmetric-key material required. Building on the sealed-envelope work (feat(core): add encp sealed-box encryption primitive #3093feat(core): seal hook payloads to the target run's public key #3096), a default webhook resume then needs neither a run read nor a run-key lookup.
  • The symmetric key is resolved (and derived) only when the hook actually stores metadata that must be hydrated — the one case that genuinely needs it. Webhooks with stored metadata keep a single key lookup; the common metadata-less webhook pays none.
  • When the context is absent (older hook records), or when it carries no public key, transparently fall back to the previous runs.get + symmetric-key path — no behavior change for existing hooks.
  • Terminal-run resumes preserve the HookNotFoundError contract (error keyed to the hook token). On the fast path the terminal check happens on the receiving side and the backend-specific rejection is re-keyed to HookNotFoundError: current Vercel returns 404 (world-vercel maps it to HookNotFoundError), world-local / world-postgres reject with RunExpiredError, and EntityConflictError (HTTP 409) is caught for compatibility with older / conflict-shaped behavior.

Backwards compatible: resumeContext and its encryptionPublicKey are optional on both the schema and the resume path, so new clients interoperate with older records and vice versa.

Tests

  • The resume-hook suite is split into a control-flow suite (mocked serialization) and a real-serialization crypto suite, so the fast path is asserted to produce a genuine encp-sealed payload end-to-end and the default webhook is asserted to make zero key lookups while a metadata-bearing webhook makes exactly one.
  • world-vercel covers the getEncryptionKeyForRun(runId, { deploymentId }) overload the fast path relies on (derive locally for the current deployment, fetch for a different one).

Note

The world-postgres migration (0017_add_hook_resume_context) adds a resume_context column. Reads are safe (nullable); population of the column is a separate data-only change requiring no migration coordination. The journal numbering is clean — 0017 follows 0016 with no gap.

The web attribute panel gains a small renderer so a hook's resumeContext is inspectable in the UI.

@karthikscale3
karthikscale3 requested review from a team and ijjk as code ownersJuly 27, 2026 18:58
@changeset-bot

changeset-botBot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d52d089

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

This PR includes changesets to release 20 packages
NameType
@workflow/worldPatch
@workflow/world-postgresPatch
@workflow/corePatch
@workflow/web-sharedPatch
@workflow/cliPatch
@workflow/vitestPatch
@workflow/webPatch
@workflow/world-localPatch
@workflow/world-testingPatch
@workflow/world-vercelPatch
@workflow/buildersPatch
@workflow/nextPatch
@workflow/nitroPatch
workflowPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/nuxtPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch

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

vercelBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit d52d089 · Tue, 28 Jul 2026 05:35:08 GMT · run logs

Backend: vercel · app: nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep242 (-21%) 💚1344 🔴 (+34%) 🔻1358 🔴 (+25%) 🔻1463 🔴 (+15%) 🔻30
TTFSstream226 (-76%) 💚1338 🔴 (+36%) 🔻1377 🔴 (+39%) 🔻1524 🔴 (+31%) 🔻30
TTFShook + stream528 (-55%) 💚1508 🔴 (+17%) 🔻1568 🔴 (+15%)1619 🔴 (+14%)30
STSO1020 steps (1-20)189 (+20%) 🔻283 🔴 (+27%) 🔻546 🔴 (+120%) 🔻1340 🔴 (+396%) 🔻19
STSO1020 steps (101-120)183 (+2.2%)248 🔴 (-3.5%)305 🔴 (-18%) 💚647 🔴 (+71%) 🔻19
STSO1020 steps (1001-1020)490 (+3.8%)582 🔴 (+7.6%)605 🔴 (-11%)807 🔴 (+16%) 🔻19
WO1020 steps404916 (+7.9%)404916 (+7.9%)404916 (+7.9%)404916 (+7.9%)1
SLstream latency97 (+28%) 🔻167 🔴 (+23%) 🔻281 🔴 (+52%) 🔻517 🔴 (+81%) 🔻30
SOstream overhead (text)123 (+19%) 🔻303 🔴 (+66%) 🔻319 (+34%) 🔻3078 🔴 (+951%) 🔻30
SOstream overhead (structured)126 (+34%) 🔻200 (+2.0%)254 (+2.0%)301 (-57%) 💚30
📜 Previous results (5)

abb34dd

Tue, 28 Jul 2026 05:03:46 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep260 (-15%)1294 🔴 (+29%) 🔻1307 🔴 (+20%) 🔻1615 🔴 (+27%) 🔻30
TTFSstream246 (-74%) 💚1291 🔴 (+31%) 🔻1314 🔴 (+33%) 🔻1326 🔴 (+14%)30
TTFShook + stream334 (-72%) 💚1520 🔴 (+18%) 🔻1551 🔴 (+13%)1642 🔴 (+15%) 🔻30
STSO1020 steps (1-20)172 (+9.6%)278 🔴 (+25%) 🔻487 🔴 (+96%) 🔻551 🔴 (+104%) 🔻19
STSO1020 steps (101-120)185 (+3.4%)284 🔴 (+11%)439 🔴 (+18%) 🔻611 🔴 (+62%) 🔻19
STSO1020 steps (1001-1020)485 (+2.8%)570 🔴 (+5.4%)670 🔴 (-1.6%)699 🔴 (+0.9%)19
WO1020 steps407032 (+8.4%)407032 (+8.4%)407032 (+8.4%)407032 (+8.4%)1
SLstream latency99 (+30%) 🔻160 🔴 (+18%) 🔻184 🔴 (-0.5%)225 🔴 (-21%) 💚30
SOstream overhead (text)123 (+19%) 🔻197 (+7.7%)254 (+6.7%)624 (+113%) 🔻30
SOstream overhead (structured)117 (+24%) 🔻230 (+17%) 🔻281 (+13%)463 (-34%) 💚30

fd5b918

Tue, 28 Jul 2026 02:01:10 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1143 (+17%) 🔻1271 🔴 (+15%) 🔻1290 🔴 (+15%) 🔻1542 🔴 (+34%) 🔻30
TTFSstream1197 (+324%) 🔻1251 🔴 (+14%)1281 🔴 (+13%)1335 🔴 (+13%)30
TTFShook + stream490 (-46%) 💚1525 🔴 (+14%)1572 🔴 (+12%)1669 🔴 (+11%)30
STSO1020 steps (1-20)154 (-9.4%)245 🔴 (-13%)294 🔴 (-9.5%)351 🔴 (-4.4%)19
STSO1020 steps (101-120)173 (-0.6%)228 🔴 (-20%) 💚256 🔴 (-20%) 💚492 🔴 (-33%) 💚19
STSO1020 steps (1001-1020)456 (-7.5%)562 🔴 (-7.9%)742 🔴 (+15%)3371 🔴 (+316%) 🔻19
WO1020 steps375095 (-14%)375095 (-14%)375095 (-14%)375095 (-14%)1
SLstream latency72 (-23%) 💚139 🔴 (-17%) 💚157 🔴 (-12%)206 🔴 (-13%)30
SOstream overhead (text)97 (-27%) 💚136 (-46%) 💚144 (-63%) 💚507 (-12%)30
SOstream overhead (structured)93 (-24%) 💚134 (-68%) 💚157 (-80%) 💚174 (-95%) 💚30

677cd6d

Mon, 27 Jul 2026 23:49:23 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep304 (-59%) 💚1363 🔴 (+21%) 🔻1428 🔴 (+18%) 🔻1442 🔴 (+5.5%)30
TTFSstream218 (-31%) 💚1397 🔴 (+27%) 🔻1411 🔴 (+23%) 🔻1467 🔴 (+25%) 🔻30
TTFShook + stream408 (-68%) 💚1551 🔴 (+11%)1625 🔴 (+11%)1962 🔴 (+20%) 🔻30
STSO1020 steps (1-20)184 (+8.2%)325 🔴 (+7.6%)459 🔴 (+30%) 🔻618 🔴 (+63%) 🔻19
STSO1020 steps (101-120)196 (-0.5%)265 🔴 (-22%) 💚421 🔴 (+2.9%)424 🔴 (-15%) 💚19
STSO1020 steps (1001-1020)480 (-0.6%)582 🔴 (+1.4%)641 🔴 (-0.8%)878 🔴 (+34%) 🔻19
WO1020 steps424315 (-3.3%)424315 (-3.3%)424315 (-3.3%)424315 (-3.3%)1
SLstream latency96 (+3.2%)200 🔴 (+19%) 🔻217 🔴 (-7.3%)260 🔴 (+2.8%)30
SOstream overhead (text)125 (-4.6%)189 (-35%) 💚266 (-25%) 💚407 (-3.3%)30
SOstream overhead (structured)115 (-15%)227 (-13%)274 (-1.4%)511 (+24%) 🔻30

d85d03c

Mon, 27 Jul 2026 20:14:26 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep260 (-63%) 💚1344 🔴 (+30%) 🔻1369 🔴 (+26%) 🔻1407 🔴 (-0.8%)30
TTFSstream238 (-72%) 💚1323 🔴 (+39%) 🔻1383 🔴 (+42%) 🔻1755 🔴 (+76%) 🔻30
TTFShook + stream402 (-63%) 💚1568 🔴 (+28%) 🔻1593 🔴 (+26%) 🔻2161 🔴 (+47%) 🔻30
STSO1020 steps (1-20)190 (+5.0%)300 🔴 (+8.7%)426 🔴 (+40%) 🔻752 🔴 (+91%) 🔻19
STSO1020 steps (101-120)197 (+5.9%)280 🔴 (+4.9%)361 🔴 (+20%) 🔻437 🔴 (-82%) 💚19
STSO1020 steps (1001-1020)495 (+11%)594 🔴 (+15%) 🔻671 🔴 (+24%) 🔻982 🔴 (+49%) 🔻19
WO1020 steps426884 (+11%)426884 (+11%)426884 (+11%)426884 (+11%)1
SLstream latency107 (+39%) 🔻199 🔴 (+60%) 🔻216 🔴 (+50%) 🔻578 🔴 (+127%) 🔻30
SOstream overhead (text)121 (+25%) 🔻218 (+41%) 🔻330 (+89%) 🔻859 (+334%) 🔻30
SOstream overhead (structured)137 (+36%) 🔻215 (+28%) 🔻313 (+77%) 🔻452 (-70%) 💚30

906e26c

Mon, 27 Jul 2026 19:41:37 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1289 (+81%) 🔻1371 🔴 (+33%) 🔻1426 🔴 (+31%) 🔻1561 🔴 (+10%)30
TTFSstream385 (-55%) 💚1366 🔴 (+43%) 🔻1394 🔴 (+43%) 🔻1734 🔴 (+74%) 🔻30
TTFShook + stream1479 (+35%) 🔻1650 🔴 (+34%) 🔻1682 🔴 (+33%) 🔻1883 🔴 (+28%) 🔻30
STSO1020 steps (1-20)180 (-0.6%)292 🔴 (+5.8%)366 🔴 (+20%) 🔻371 🔴 (-5.8%)19
STSO1020 steps (101-120)197 (+5.9%)298 🔴 (+12%)442 🔴 (+47%) 🔻1199 🔴 (-51%) 💚19
STSO1020 steps (1001-1020)478 (+6.9%)572 🔴 (+11%)703 🔴 (+30%) 🔻1113 🔴 (+69%) 🔻19
WO1020 steps405737 (+5.5%)405737 (+5.5%)405737 (+5.5%)405737 (+5.5%)1
SLstream latency104 (+35%) 🔻157 🔴 (+27%) 🔻362 🔴 (+151%) 🔻3272 🔴 (+1183%) 🔻30
SOstream overhead (text)115 (+19%) 🔻184 (+19%) 🔻213 (+22%) 🔻303 (+53%) 🔻30
SOstream overhead (structured)120 (+19%) 🔻174 (+3.6%)223 (+26%) 🔻347 (-77%) 💚30
ℹ️ Metric definitions & methodology

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 · STSO (1-20) 20/30/60 · STSO (101-120) 30/45/90 · STSO (1001-1020) 40/60/120

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-actionsBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

E2E Test Summary

Summary
PassedFailedSkippedTotal
✅ ▲ Vercel Production145502391694
✅ 💻 Local Development162102271848
✅ 📦 Local Production162102271848
✅ 🐘 Local Postgres162102271848
✅ 🪟 Windows15400154
✅ 📋 Other102002121232
✅ vercel-multi-region270027
Total7519011328651
Details by Category

✅ ▲ Vercel Production

AppPassedFailedSkipped
✅ astro126028
✅ example126028
✅ express126028
✅ fastify126028
✅ hono126028
✅ nextjs-turbopack15103
✅ nextjs-webpack15103
✅ nitro126028
✅ nuxt126028
✅ sveltekit14509
✅ vite126028

✅ 💻 Local Development

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-canary135019
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
✅ nuxt-stable128026
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 📦 Local Production

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-canary135019
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
✅ nuxt-stable128026
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 🐘 Local Postgres

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-canary135019
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
✅ nuxt-stable128026
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 🪟 Windows

AppPassedFailedSkipped
✅ nextjs-turbopack15400

✅ 📋 Other

AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable128026
✅ e2e-local-dev-tanstack-start-128026
✅ e2e-local-postgres-nest-stable128026
✅ e2e-local-postgres-tanstack-start-128026
✅ e2e-local-prod-nest-stable128026
✅ e2e-local-prod-tanstack-start-128026
✅ e2e-vercel-prod-nest126028
✅ e2e-vercel-prod-tanstack-start126028

✅ vercel-multi-region

AppPassedFailedSkipped
✅ nextjs-turbopack2700

📋 View full workflow run

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

Additional Suggestion:

Adding optional resumeContext to HookSchema broke @workflow/world-postgres with TS1360 because the hooks table has no matching column to satisfy DrizzlishOfType<Cborized<Hook, 'metadata'>>.

Fix on Vercel

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

Additional Suggestion:

Docs still instruct users to import/call removed createLocalWorld() and createVercelWorld() exports, which now fail with a module import error.

Fix on Vercel

@TooTallNateTooTallNate left a comment

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.

The optimization is well-shaped — resumeContext is a good abstraction (immutable slice only, explicitly excluding mutable status/secrets), the fallback is transparent, and the refactor cleanly separates context resolution from key resolution so key work stays behind the terminal check. But the terminal-run error contract does not hold on the fast path, and I think it's worth fixing before this lands.

Blocking: the fast path's error re-keying targets the wrong error. The code assumes a terminal run makes hook_received fail with a 404 that the World maps to HookNotFoundError:

if(HookNotFoundError.is(err))thrownewHookNotFoundError(hook.token);throwerr;

That 404 mapping is real, but it means hook does not existworld-vercel's translation is gated on isHookEventRequiringExistence(...) && err.status === 404. A terminal run is a different rejection: the backend refuses non-allowed events on an ended run with a conflict (409), which http-core.ts maps to EntityConflictError — so it falls straight through the HookNotFoundError check and escapes as EntityConflictError. The self-hosted worlds are also not covered: both world-local (events-storage.ts, the hook_received terminal guard) and world-postgres (storage.ts, the FOR UPDATE status check) throw RunExpiredError for exactly this case.

Why it usually looks fine — and where it doesn't:

  • Hooks are deleted when a run finishes, so a token-based resume against a long-ended run 404s at getByToken before reaching either path. That's the common case and it keeps working.
  • It breaks where no getByToken happens or the hook still exists: resumeWebhook calls resumeHook(hook, request, encryptionKey) with the Hook object (so does any caller holding a retained hook), and the run can terminate between the lookup and the hook_received write. Pre-PR those all produced HookNotFoundError(token) from the local terminal check; on the fast path they now surface EntityConflictError (Vercel) or RunExpiredError (local/postgres).

The fix is small — widen the catch to the errors that actually represent "run already ended":

if(HookNotFoundError.is(err)||EntityConflictError.is(err)||RunExpiredError.is(err)){thrownewHookNotFoundError(hook.token);}

(or invert it: keep a terminal-status check on the fast path by including status in resumeContext — though that would break its nice immutability property, so I'd prefer widening the catch.) Please also correct the two code comments asserting the 404-on-terminal-run premise, and extend resume-hook.test.ts — the current fast-path test mocks HookNotFoundError from events.create, which bakes in the assumption; cases rejecting with EntityConflictError/RunExpiredError would have caught this.

Also worth resolving before merge: the world-postgres half-wiring. Migration 0017 adds resume_context and schema.ts types it, but nothing in world-postgres ever writes or reads the column — so postgres can't take the fast path today. That's fine as sequencing, but it's exactly the trap in the item above: the moment a follow-up populates it, postgres resumes go fast-path and terminal-run resumes start throwing RunExpiredError. Fixing the catch now makes that follow-up safe. Worth a line in the PR description saying the column is intentionally inert for now (the journal numbering is clean — 0017 follows 0016 with no gap).

Everything else checks out:

  • The getEncryptionKeyForRun(runId, { deploymentId }) overload already exists on the World interface, so the fast-path key resolution is contract-compliant, and encryptionKeyOverride still short-circuits it (the ?? ordering is right — no wasted lookup when a key is passed in, which resumeWebhook does).
  • Capability/compression selection now reads runSpecVersion/workflowCoreVersion from the context — same values the run entity provided, and resumeContextFromRun type-guards both when synthesizing from a run.
  • Naming runSpecVersion to avoid collision with the hook's own specVersion is a good call, as is routing world-vercel through the shared HookSchema so the new field flows without a world-side change.
  • The attribute-panel.tsx null renderer correctly keeps this internal plumbing out of the UI.
  • 7/7 resume-hook tests pass locally, and the fast-path assertions (runsGet not called, key resolved once) do pin the round-trip savings this PR is for.

Happy to re-review quickly once the catch is widened — the rest of this is ready.

@karthikscale3

Copy link
Copy Markdown
ContributorAuthor

Thanks for the thorough review — all four items addressed in fd5b918e4:

  • Widened the catch around world.events.create('hook_received') to re-key HookNotFoundErrorandEntityConflictError (world-vercel 409) andRunExpiredError (world-local / world-postgres) to HookNotFoundError(hook.token). Went with the catch over threading status into resumeContext, per your preference — keeps the context immutable.
  • Corrected the two comments that asserted the 404-on-terminal-run premise (both the fallback-path terminal note and the key-resolution comment).
  • Extended resume-hook.test.ts: the existing fast-path test comment no longer bakes in the 404 assumption, and there are now two new cases where events.create rejects with EntityConflictError and RunExpiredError respectively — each asserting the re-key to HookNotFoundError with .token === hook.token. 9/9 pass.
  • PR description now notes the world-postgresresume_context column (migration 0017) is intentionally inert for now, so a follow-up that populates it is a pure data change — and safe, because the catch is fixed.

Ready for another look when you have a moment.

@karthikscale3

Copy link
Copy Markdown
ContributorAuthor

Follow-up a4a5712ad — accuracy cleanup, no functional change: since workflow-server now returns 404 for hook_received against a terminal run (mapped to HookNotFoundError by world-vercel), the comments, test titles, and PR note now describe that as the current Vercel behavior, with EntityConflictError (409) kept purely as a compatibility catch for older / conflict-shaped behavior. Also reworded the postgres note to say storage "does not populate the column yet" (nullable Drizzle selects do read it). 9/9 tests + typecheck green.

@TooTallNateTooTallNate left a comment

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.

Re-reviewed fd5b918e4 — the blocking item is fully addressed. Approving.

  • The catch now re-keys all three real rejection shapes (HookNotFoundError for a genuinely missing hook, EntityConflictError for the Vercel 409, RunExpiredError for world-local / world-postgres), so resumeHook on an ended run throws HookNotFoundError(hook.token) on every world — including the resumeWebhook path that passes a Hook object and therefore has no getByToken 404 to fall back on.
  • Both misleading comments are corrected, and the new inline comment enumerating which World produces which error is exactly the context a future reader needs to not re-narrow this.
  • The two new tests pin the 409 and expired cases against the token contract and assert the queue isn't re-triggered — which is the part that would silently regress if someone later reshuffled the catch.

Verified locally on the updated head: 9/9 resume-hook tests and the full core suite at 1584 (+3 pre-existing expected-fails). CI is green (21 pass, 0 fail).

Two notes for later, neither blocking:

  1. Widening to EntityConflictError is the right trade today, but it's the loosest of the three — on world-local an events.create conflict can also mean a crashed-retry event-ID collision (the staging-path collision in events-storage.ts), which would now report as HookNotFoundError. That case is rare and its old surface (EntityConflictError) wasn't especially actionable either, so I'd leave it — but the clean long-term fix is for the worlds to agree on one error class for "terminal run rejected this event", after which the catch could drop the conflict arm.
  2. The world-postgresresume_context column is still inert (written/read by nothing). Now that the error mapping is correct, activating it later is safe — just worth a line in the description or a tracking issue so the follow-up that populates it isn't mistaken for dead-code cleanup.

karthikscale3and others added 2 commits July 27, 2026 21:41
…n key
Hooks can carry an optional `resumeContext` mirrored from the run at
creation time. When present, `resumeHook`/`resumeWebhook` resume directly
from it instead of fetching the full run, saving a round trip per resume.
When the context also carries the run's `encryptionPublicKey`, the resume
seals its payload (`encp`) directly to that key. Combined with the sealed
envelope work (#3093-#3096), a default webhook resume then needs neither a
run read nor a cross-deployment run-key lookup: the key is resolved only
when the hook actually stores metadata that must be hydrated symmetrically.
Everything falls back transparently to the full run fetch and symmetric
key when the context (or the public key within it) is absent, so new
clients interoperate with old servers and vice versa.
- world: optional `encryptionPublicKey` on `HookResumeContext`
- world-postgres: `resume_context` column migration
- core: combined fast-path + seal in resume-hook; fast-path control-flow
suite split from the real-serialization crypto suite
- world-vercel: cover the `getEncryptionKeyForRun(runId, { deploymentId })`
overload the fast path relies on
- web-shared: render `resumeContext` in the attribute panel
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
"@workflow/web-shared": patch
---

Hooks can carry an optional `resumeContext`; when present, `resumeHook`/`resumeWebhook` resume from it directly instead of fetching the full run, saving a round trip per resume. When the context also carries the run's `encryptionPublicKey`, the resume seals its payload (`encp`) directly to that key, so a default webhook resume needs neither a run read nor a run-key lookup. These two optimizations fall back independently: it fetches the full run when the context is absent, and uses symmetric encryption when no usable public key is available.

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.

Too long 😄

@github-actions

Copy link
Copy Markdown
Contributor

No backport to stable for d24c91c (AI decision).

This is a performance optimization and new API surface, not a defect fix: it adds an optional resumeContext field to HookSchema, a new world-postgres migration/column, and a fast path in resumeHook/resumeWebhook that skips the run read and run-key lookup. It also builds on main-only sealed-envelope work (#3093#3096) and the getEncryptionKeyForRun(runId, { deploymentId }) overload. Nothing here fixes broken behavior on stable — the existing runs.get + symmetric-key path remains correct, just slower.

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

d24c91cfde678e9a4935ee94b9597b5696d6792b

Sign up for freeto 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

@karthikscale3@TooTallNate