Skip to content

[world] Require a runId on listByCorrelationId - #3280

Merged
VaguelySerious merged 1 commit into
mainfrom
peter/correlation-id-run-scope
Aug 4, 2026
Merged

[world] Require a runId on listByCorrelationId#3280
VaguelySerious merged 1 commit into
mainfrom
peter/correlation-id-run-scope

Conversation

@VaguelySerious

@VaguelySerious VaguelySerious commented Aug 2, 2026

Copy link
Copy Markdown
Member

Why

A correlation id identifies a step, hook or wait within its run, not across runs. Nothing enforced that while every id carried a ULID, so the distinction never mattered. It matters as soon as a run numbers its own steps: step_…001 names the first step of every slot-numbered run.

Measured on the Local World before this change — two runs, each with one step, one unscoped lookup:

listByCorrelationId('step_…001') → 2 events, runIds [wrun_01KYTTGYF6…, wrun_01KYTTGYF9…]

Two consequences:

  • Foreign runs in the page. The observability search already post-filters on runId, so nothing wrong is displayed — but it pages against a bounded page cap, so the run it wants can sit past the cap and the search reports nothing found.
  • An ambiguous cursor. The Postgres query orders and resumes by eventId. Two runs can hold the same correlation id at the same slot, so eventId > cursor skips the sibling row at the equal id. Scoped, (run_id, id) is the primary key, so the cursor is a key again.

Nothing in the runtime reads this path — it is an observability read — so this is not a correctness regression in a run. It is a read that gets quietly wrong answers.

What

Breaking. ListEventsByCorrelationIdParams and AnalyticsListEventsByCorrelationIdParams gain a required runId. An unscoped lookup has no answer worth keeping: it means "every run that numbered one the same", which is never the question a caller is asking.

World How it scopes
Local Restricts the scan to the run's own event files
Postgres AND run_id = $n, which also disambiguates the cursor
Vercel — analytics Routes to the run-scoped endpoint that already takes a correlation-id filter
Vercel — runtime read Applies the scope to the returned page; the backend index is keyed by correlation id alone, so the pagination cursor and hasMore stay the backend's

The observability search passes the run it is already looking at, and keeps its post-filter as defence for a world that cannot scope.

This was previously the last commit of #3247, stacked behind the slot-identity SDK series. It stands alone: the bug it fixes predates slot identity, slot identity is only what makes it reachable.

Tests

  • Local: a scoped lookup returns the named run's events, and the sibling run's event is still reachable under its own run
  • Postgres: the same pair, plus paging a scoped query past a sibling run holding the same correlation id — the scope is what keeps the event-id cursor a key
  • 21 existing callsites across both suites now pass the run they created

Local 498 pass, Postgres 163 pass (real container), world-vercel 334, web 97, docs-typecheck 967. Root pnpm build and pnpm typecheck green.

Docs

docs/content/docs/v5/api-reference/workflow-runtime/world/{storage,analytics}.mdx document the requirement. The v5 migration table and the v4→v5 migration skill are updated in #3100.

Follow-up

The backend index behind the Vercel runtime read is keyed by correlation id alone, so a slot-mode step_…001 is a hot key across all runs and the scope is applied client-side. Taking a run scope there is a backend-side change, tracked separately.

Docs Preview

Base: https://workflow-docs-git-peter-correlation-id-run-scope.vercel.sh (Vercel SSO).

Page What changed
/docs/api-reference/workflow-runtime/world/storage#eventslistbycorrelationid runId documented as required, with why the scope is also what keeps the cursor a key; snippet and params table updated
/docs/api-reference/workflow-runtime/world/analytics#analyticssteps-analyticsevents-analyticshooks-analyticswaits analytics.events.listByCorrelationId snippet passes runId

A correlation id names a step, hook or wait within its run, not across
runs. Under slot event identity each run numbers its own steps, so
`step_...001` is the first step of every slot-numbered run and an
unscoped lookup answered with one event per such run. The scope is also
what keeps the pagination cursor a key: an event id alone cannot tell
two runs' rows apart.
@VaguelySerious
VaguelySerious requested review from a team and ijjk as code owners August 2, 2026 17:13
@changeset-bot

changeset-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c7792d

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

This PR includes changesets to release 20 packages
Name Type
@workflow/world Major
@workflow/world-local Major
@workflow/world-postgres Major
@workflow/world-vercel Major
@workflow/web Minor
@workflow/cli Patch
@workflow/core Patch
@workflow/vitest Patch
@workflow/web-shared Minor
@workflow/world-testing Patch
@workflow/nitro Patch
workflow Patch
@workflow/builders Patch
@workflow/next Patch
@workflow/nuxt Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite 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 Aug 2, 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 2, 2026 5:16pm
example-nextjs-workflow-webpack Ready Ready Preview Aug 2, 2026 5:16pm
example-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-astro-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-express-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-fastify-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-hono-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-nestjs-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-nitro-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-nuxt-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-sveltekit-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-tanstack-start-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workbench-vite-workflow Ready Ready Preview Aug 2, 2026 5:16pm
workflow-docs Ready Ready Preview, v0 Aug 2, 2026 5:16pm
workflow-swc-playground Ready Ready Preview Aug 2, 2026 5:16pm
workflow-tarballs Ready Ready Preview Aug 2, 2026 5:16pm
workflow-web Ready Ready Preview Aug 2, 2026 5:16pm

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

E2E Test Summary

Summary
Passed Failed Skipped Total
✅ ▲ Vercel Production 1466 0 239 1705
✅ 💻 Local Development 1633 0 227 1860
✅ 📦 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 7575 0 1132 8707
Details by Category

✅ ▲ Vercel Production

App Passed Failed Skipped
✅ astro 127 0 28
✅ example 127 0 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
✅ 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 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 Aug 2, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 7c7792d · Sun, 02 Aug 2026 17:35:54 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 274 (-65%) 💚 1397 🔴 (+28%) 🔻 1433 🔴 (+25%) 🔻 1680 🔴 (+10%) 30
TTFS stream 253 (+6.3%) 1344 🔴 (+24%) 🔻 1377 🔴 (+24%) 🔻 1459 🔴 (+25%) 🔻 30
TTFS hook + stream 512 (-59%) 💚 1597 🔴 (+16%) 🔻 1644 🔴 (+14%) 1672 🔴 (-9.1%) 30
STSO 1020 steps (inline) 179 (+3.5%) 485 (-6.4%) 550 (-6.0%) 761 (-13%) 1016
STSO 1020 steps (queue-hop) 1677 (-15%) 💚 3122 (-5.6%) 3122 (-5.6%) 3122 (-5.6%) 3
WO 1020 steps 428735 (-4.1%) 428735 (-4.1%) 428735 (-4.1%) 428735 (-4.1%) 1
SL stream latency 105 (+14%) 171 🔴 (-5.0%) 201 🔴 (-17%) 💚 277 🔴 (-36%) 💚 30
SO stream overhead (text) 122 (-10%) 212 (-2.8%) 298 (+9.6%) 420 (+12%) 30
SO stream overhead (structured) 108 (-8.5%) 209 (-13%) 307 (-3.8%) 507 (+13%) 30
📈 STSO distribution vs main (inline / queue-hop histograms)

1020 steps (inline)

Cumulative STSO time: main 437759ms → this run 419570ms (Δ -18189ms, -4%)

  150-200 ms  ┃                         main  10  this   7    -3
  200-250 ms  ██████████┃██             main  86  this  72   -14
  250-300 ms  ████████████████┃         main 104  this 116   +12
  300-350 ms  ███████████████░░░░░┃     main  98  this 140   +42
  350-400 ms  ████████████████████░░┃   main 136  this 151   +15
  400-450 ms  ████████████████████░░░┃  main 132  this 161   +29
  450-500 ms  █████████████████████░┃   main 140  this 151   +11
  500-550 ms  ████████████████┃███      main 135  this 116   -19
  550-600 ms  ███████┃██████            main  93  this  52   -41
  600-650 ms  ██┃███                    main  38  this  22   -16
  650-700 ms  ┃██                       main  18  this   5   -13
  700-750 ms  ┃                         main   8  this  10    +2
  750-800 ms  ┃                         main   3  this   6    +3
  800-850 ms  ┃                         main   2  this   2    +0
  850-900 ms  ┃                         main   3  this   0    -3
  900-950 ms  ┃                         main   5  this   0    -5
1050-1100 ms  ┃                         main   1  this   0    -1
1100-1150 ms  ┃                         main   0  this   2    +2
1200-1250 ms  ┃                         main   2  this   0    -2
1250-1300 ms  ┃                         main   1  this   1    +0
1300-1350 ms  ┃                         main   1  this   0    -1
1750-1800 ms  ┃                         main   0  this   1    +1
1850-1900 ms  ┃                         main   0  this   1    +1

1020 steps (queue-hop)

Cumulative STSO time: main 8262ms → this run 7676ms (Δ -586ms, -7%)

1500-2000 ms  ███████████████████████┃  main 1  this 1  +0
2500-3000 ms  ███████████████████████┃  main 1  this 1  +0
3000-3500 ms  ███████████████████████┃  main 1  this 1  +0
ℹ️ 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.

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

Reviewed at 7c7792d (base 3 days / 23 commits behind main — merges clean, no semantic overlap with the interim work).

Verified locally:

  • Root pnpm build + pnpm typecheck green; world-local 498, world-vercel 334, web 97 all pass. (No docker on this machine for the Postgres container suite — reviewed those tests statically and CI's run is green.)
  • Callsite sweep is complete: the only remaining listByCorrelationId references outside the four world implementations and the web callers are the interface declaration and the docs-typecheck ambient stub ((...args: any[])), which tolerates the new field.
  • Changeset semver is exactly right: major across @workflow/world/world-local/world-postgres/world-vercel for a breaking required param, minor on web. External world implementations get the correct signal.

Design points that held up under scrutiny:

  • The Postgres cursor argument is real, not decorative: the query orders and resumes by eventId alone, and two runs genuinely can hold the same correlation id at the same slot — scoping restores (run_id, id) as the key. The limit-1 paging test past a sibling run is precisely the regression trap.
  • Local world: the filePrefix: ${runId}-`` scope matches the established file-naming convention used by the other four run-scoped queries in the same file, and the new assertSafeEntityId('runId', …) guard is a nice catch — runId now feeds a path prefix, so it needs the same injection defense correlationId already had.
  • Vercel analytics: the run-scoped endpoint is an established route family in this client, and I confirmed the backend's run-scoped events listing accepts the same correlationId filter — so the reroute is a strict improvement (server-side scope instead of none).
  • Vercel runtime read: the client-side filter keeps the backend's hasMore/cursor untouched, so a page that filters to empty is still followed — and the web hook's paging loop keys on the cursor, not page contents (do … while (nextCursor)), so it can't terminate early on an all-foreign page. The retained event.runId === runId post-filter as defense-in-depth for worlds that can't scope is the right belt-and-suspenders, and the MAX_CORRELATION_SEARCH_PAGES + truncated handling bounds the hot-key cost until the backend-side scope lands (good that the follow-up is called out honestly).
  • The 'correlationId' in params discriminator in getWorkflowRunEvents is sound against the params union — ListEventsParams never carries correlationId, and both variants now carry runId.

Docs updates are accurate (required param documented with the cursor rationale, snippets updated), and the measured two-run repro in the PR description matches what the code change prevents.

CI green (only the standard permission-gated skips). Ship it.

@VaguelySerious
VaguelySerious merged commit de1905f into main Aug 4, 2026
161 of 179 checks passed
@VaguelySerious
VaguelySerious deleted the peter/correlation-id-run-scope branch August 4, 2026 20:09
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

No backport to stable for de1905f (AI decision).

This is a breaking API change (major changesets for @workflow/world, -local, -postgres, -vercel) that adds a required runId to events.listByCorrelationId and analytics.events.listByCorrelationId, so it belongs to the next major rather than a maintenance line. The underlying issue is an observability read returning cross-run events, which the PR itself notes is not a runtime correctness regression and is only made reachable by the main-only slot-identity work; a scoping fix for stable would need to be non-breaking (e.g. an optional runId) rather than this signature change.

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

de1905f15c0a31f272966ac518ebf272864ea5c6

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