Skip to content

Slot event identity (SDK 1/4): per-kind correlation ids and run-scoped idempotency keys - #3228

Closed
VaguelySerious wants to merge 5 commits into
mainfrom
peter/slot-event-ids
Closed

Slot event identity (SDK 1/4): per-kind correlation ids and run-scoped idempotency keys#3228
VaguelySerious wants to merge 5 commits into
mainfrom
peter/slot-event-ids

Conversation

@VaguelySerious

@VaguelySerious VaguelySerious commented Jul 30, 2026

Copy link
Copy Markdown
Member

First of four SDK PRs for slot-based event identity. Client half of the groundwork; dormant — nothing stamps spec version 6 yet, so every run still takes the ULID path byte-for-byte.

What

@workflow/world

  • slot-identity.ts: slotIdBody(slot) / slotFromId(id) / isSlotId(id), FIRST_SLOT = 1, SLOT_ID_WIDTH = 26. A slot body is a 26-char zero-padded decimal, which is a valid Crockford base32 (ULID) body — so every existing schema, sort key, range fence and eid: cursor keeps working unchanged. Slots start at 1 because slot 0 is the inclusive lower fence for range queries.
  • SPEC_VERSION_SLOT_IDENTITY = 6 and usesSlotIdentity(). Deliberately not SPEC_VERSION_CURRENT: requiresNewerWorld() is what makes a world reject runs it can't read, so bumping current before the worlds can allocate slots would have them reject their own new runs. That bump lands last.
  • The package had 10 test files but no test script, so none of them ran in CI. Added one.

@workflow/core

  • nextCorrelationId(kind) on the orchestrator context is now the only place step and wait correlation ids are minted (step.ts, workflow/sleep.ts). In slot mode each kind counts independently from 1; otherwise it delegates to the same seeded ULID generator, in the same call order, as today.
  • Mode comes from the run's persisted specVersion, never from the build. A run whose log holds step_01K… must keep proposing ULIDs however new the code replaying it is, or it would propose step_…001 and match no existing entity.
  • Nothing seeds the counters. The VM is rebuilt per replay and the body issues its operations in the same order — the same argument that licenses today's seeded-ULID sequence. Recovering them from the loaded log would make the n-th step's id depend on how much log was loaded.
  • Independent per-kind counters also fix a latent coupling that exists today: all four kinds draw from one shared generator, so inserting a hook renumbers every later step and wait.

Run-scoped queue idempotency keysrunScopedKey(runId, …parts), threaded through backstopIdempotencyKey, getWaitContinuationDispatch, and the step-dispatch and delayed-retry sends.

Queues dedupe on (queue, idempotencyKey), and a queue is per workflow, not per run. Once correlation ids are slot-numbered, the first step of every run of a workflow is step_…001, so two concurrent runs would submit the same key. The failure is total and silent: the send is answered normally with a fresh message id, the duplicate is excluded from notifications, no callback is ever dispatched, the orchestrator acks — and the inline-ownership backstop can't recover it because it needs a step_started that never happened. There is no error to find afterwards, so a source-scan test asserts that no site in packages/core builds an idempotencyKey any other way.

This is a prerequisite, not a live bug fix: the VM's ULID seed already includes the run id, so today's correlation ids are run-unique.

Tests

  • world: slot bodies pad to ULID width and parse as ULIDs, order lexicographically by slot, reject 0/-1/1.5; slotFromId round-trips prefixed and bare bodies and reads nothing out of a ULID, the all-zero fence, or a wrong-width body.
  • core: dense per-kind numbering; two fresh invocations issue identical sequences; interleaved allocations of other kinds don't renumber steps or waits; ULID mode still draws one shared sequence across kinds.
  • core: the idempotency-key source scan (verified to fail when an unscoped site is introduced), plus per-run isolation tests for the backstop and wait-continuation keys.

Full packages/core (1666), packages/world (87) and packages/world-vercel (309) unit suites pass; turbo typecheck green across 41 tasks.

Note for review

WORKFLOW_SERVER_URL_OVERRIDE is set in its own commit (bb04d1c) and points at the top of the paired backend stack, so e2e runs against a backend that can accept and allocate slots. Reverting that one commit is all that's needed before merge. The follow-up commit making the last three v4 mock tests honor the override is a permanent fix and should stay.


Stack: #3228#3234#3246#3247

Paired backend stack (world-vercel side): 6 PRs, all rebased on main and stacked; WORKFLOW_SERVER_URL_OVERRIDE points at the top of it and must be reverted before merge.

… keys

Adds the client half of slot-based event identity, dormant until a run is
stamped at spec version 6.

- `@workflow/world` gains `slot-identity.ts` (26-char zero-padded decimal
  bodies, so a slot is a valid ULID body everywhere a ULID is accepted),
  `SPEC_VERSION_SLOT_IDENTITY` and `usesSlotIdentity()`.
- `nextCorrelationId(kind)` on the orchestrator context is now the only place
  step and wait correlation ids are minted. In slot mode each kind counts
  independently from 1; otherwise it delegates to the same seeded ULID
  generator as before, so existing runs are byte-identical.
- Every queue idempotency key is scoped to the run. Queues dedupe per queue,
  which is per workflow, so slot-numbered correlation ids would otherwise
  collide across concurrent runs of one workflow — silently, because a
  deduped send is answered normally and never dispatched. A source-scan test
  asserts no site builds a key any other way.
- `packages/world` had test files but no `test` script, so 10 files never ran
  in CI. Added one.
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c55dc1e

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

This PR includes changesets to release 20 packages
Name Type
@workflow/core Patch
@workflow/world 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/world-local Patch
@workflow/world-postgres Patch
@workflow/world-vercel 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 30, 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 1, 2026 8:04pm
example-nextjs-workflow-webpack Ready Ready Preview Aug 1, 2026 8:04pm
example-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-astro-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-express-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-fastify-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-hono-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-nestjs-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-nitro-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-nuxt-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-sveltekit-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-tanstack-start-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workbench-vite-workflow Ready Ready Preview Aug 1, 2026 8:04pm
workflow-docs Ready Ready Preview, v0 Aug 1, 2026 8:04pm
workflow-swc-playground Ready Ready Preview Aug 1, 2026 8:04pm
workflow-tarballs Ready Ready Preview Aug 1, 2026 8:04pm
workflow-web Ready Ready Preview Aug 1, 2026 8:04pm

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

❌ Failed E2E Tests

▲ Vercel Production (1 failed)

example (1 failed):

E2E Test Summary

Summary
Passed Failed Skipped Total
❌ ▲ Vercel Production 1465 1 239 1705
✅ 💻 Local Development 1478 0 227 1705
✅ 📦 Local Production 1633 0 227 1860
✅ 🐘 Local Postgres 1633 0 227 1860
✅ 🪟 Windows 155 0 0 155
✅ 📋 Other 1028 0 212 1240
✅ vercel-multi-region 27 0 0 27
Total 7419 1 1132 8552
Details by Category

❌ ▲ Vercel Production

App Passed Failed Skipped
✅ astro 127 0 28
❌ example 126 1 28
✅ express 127 0 28
✅ fastify 127 0 28
✅ hono 127 0 28
✅ nextjs-turbopack 152 0 3
✅ nextjs-webpack 152 0 3
✅ nitro 127 0 28
✅ nuxt 127 0 28
✅ sveltekit 146 0 9
✅ vite 127 0 28

✅ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nextjs-webpack-stable 155 0 0
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nextjs-webpack-stable 155 0 0
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack 155 0 0

✅ 📋 Other

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

✅ vercel-multi-region

App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit c55dc1e · Sat, 01 Aug 2026 20:24:18 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 269 (-66%) 💚 1341 🔴 (+22%) 🔻 1376 🔴 (+20%) 🔻 1394 🔴 (-8.5%) 30
TTFS stream 229 (-3.8%) 1334 🔴 (+23%) 🔻 1345 🔴 (+21%) 🔻 1374 🔴 (+18%) 🔻 30
TTFS hook + stream 521 (-58%) 💚 1597 🔴 (+16%) 🔻 1641 🔴 (+14%) 2007 🔴 (+9.1%) 30
STSO 1020 steps (inline) 161 (-6.9%) 510 (-1.5%) 582 (-0.5%) 759 (-14%) 1016
STSO 1020 steps (queue-hop) 1458 (-26%) 💚 2623 (-21%) 💚 2623 (-21%) 💚 2623 (-21%) 💚 3
WO 1020 steps 433005 (-3.1%) 433005 (-3.1%) 433005 (-3.1%) 433005 (-3.1%) 1
SL stream latency 107 (+16%) 🔻 167 🔴 (-7.2%) 191 🔴 (-21%) 💚 276 🔴 (-36%) 💚 30
SO stream overhead (text) 126 (-7.4%) 213 (-2.3%) 272 (±0%) 480 (+28%) 🔻 30
SO stream overhead (structured) 112 (-5.1%) 202 (-16%) 💚 268 (-16%) 💚 409 (-8.7%) 30
📈 STSO distribution vs main (inline / queue-hop histograms)

1020 steps (inline)

Cumulative STSO time: main 437759ms → this run 425313ms (Δ -12446ms, -3%)

  150-200 ms  █┃                        main  10  this  14    +4
  200-250 ms  ████████████┃██           main  86  this  74   -12
  250-300 ms  ██████████████████░░░░┃   main 104  this 133   +29
  300-350 ms  █████████████████░░░░┃    main  98  this 131   +33
  350-400 ms  ██████████████████████┃   main 136  this 136    +0
  400-450 ms  ████████████████████┃██   main 132  this 122   -10
  450-500 ms  ██████████████████┃█████  main 140  this 108   -32
  500-550 ms  █████████████████████┃█   main 135  this 129    -6
  550-600 ms  ██████████████┃█          main  93  this  90    -3
  600-650 ms  █████┃█                   main  38  this  36    -2
  650-700 ms  ██┃                       main  18  this  20    +2
  700-750 ms  ┃                         main   8  this   7    -1
  750-800 ms  ┃                         main   3  this   8    +5
  800-850 ms  ┃                         main   2  this   6    +4
  850-900 ms  ┃                         main   3  this   1    -2
  900-950 ms  ┃                         main   5  this   0    -5
1050-1100 ms  ┃                         main   1  this   1    +0
1200-1250 ms  ┃                         main   2  this   0    -2
1250-1300 ms  ┃                         main   1  this   0    -1
1300-1350 ms  ┃                         main   1  this   0    -1

1020 steps (queue-hop)

Cumulative STSO time: main 8262ms → this run 6341ms (Δ -1921ms, -23%)

1000-1500 ms  ░░░░░░░░░░░░░░░░░░░░░░░┃  main 0  this 1  +1
1500-2000 ms  ┃███████████████████████  main 1  this 0  -1
2000-2500 ms  ░░░░░░░░░░░░░░░░░░░░░░░┃  main 0  this 1  +1
2500-3000 ms  ███████████████████████┃  main 1  this 1  +0
3000-3500 ms  ┃███████████████████████  main 1  this 0  -1
📜 Previous results (1)

3ae14e7

Thu, 30 Jul 2026 21:39:47 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 238 (+13%) 1337 🔴 (+26%) 🔻 1353 🔴 (+25%) 🔻 1424 🔴 (+17%) 🔻 30
TTFS stream 203 (-25%) 💚 1321 🔴 (+23%) 🔻 1350 🔴 (+23%) 🔻 1410 🔴 (+20%) 🔻 30
TTFS hook + stream 444 (+17%) 🔻 1582 🔴 (+26%) 🔻 1634 🔴 (+27%) 🔻 1703 🔴 (+8.1%) 30
STSO 1020 steps (inline) 152 (-15%) 497 (+3.3%) 561 (+4.9%) 883 (+29%) 🔻 1019
WO 1020 steps 429379 (+3.2%) 429379 (+3.2%) 429379 (+3.2%) 429379 (+3.2%) 1
SL stream latency 97 (+20%) 🔻 185 🔴 (+26%) 🔻 199 🔴 (+8.7%) 263 🔴 (-27%) 💚 30
SO stream overhead (text) 105 (-16%) 💚 249 (+14%) 343 (+37%) 🔻 441 (+2.8%) 30
SO stream overhead (structured) 112 (-3.4%) 187 (-19%) 💚 247 (-18%) 💚 593 (+59%) 🔻 30
ℹ️ 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.

@VaguelySerious VaguelySerious changed the title Slot event identity (SDK 1/3): per-kind correlation ids and run-scoped idempotency keys Slot event identity (SDK 1/4): per-kind correlation ids and run-scoped idempotency keys Aug 2, 2026
@VaguelySerious

Copy link
Copy Markdown
Member Author

(AI) Superseded by #3305, which combines this stack into a single PR. The correlation-id renumbering that this stack carried is dropped: it was separable from slot event identity, and it dragged in prerequisites of its own (run-scoped queue idempotency keys, run-scoped step keys). Correlation ids stay ULIDs.

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.

1 participant