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

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

WorldHow it scopes
LocalRestricts the scan to the run's own event files
PostgresAND run_id = $n, which also disambiguates the cursor
Vercel — analyticsRoutes to the run-scoped endpoint that already takes a correlation-id filter
Vercel — runtime readApplies 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).

PageWhat changed
/docs/api-reference/workflow-runtime/world/storage#eventslistbycorrelationidrunId 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-analyticswaitsanalytics.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 ownersAugust 2, 2026 17:13
@changeset-bot

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
NameType
@workflow/worldMajor
@workflow/world-localMajor
@workflow/world-postgresMajor
@workflow/world-vercelMajor
@workflow/webMinor
@workflow/cliPatch
@workflow/corePatch
@workflow/vitestPatch
@workflow/web-sharedMinor
@workflow/world-testingPatch
@workflow/nitroPatch
workflowPatch
@workflow/buildersPatch
@workflow/nextPatch
@workflow/nuxtPatch
@workflow/astroPatch
@workflow/nestPatch
@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 Aug 2, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

E2E Test Summary

Summary
PassedFailedSkippedTotal
✅ ▲ Vercel Production146602391705
✅ 💻 Local Development163302271860
✅ 📦 Local Production163302271860
✅ 🐘 Local Postgres163302271860
✅ 🪟 Windows15500155
✅ 📋 Other102802121240
✅ vercel-multi-region270027
Total7575011328707
Details by Category

✅ ▲ Vercel Production

AppPassedFailedSkipped
✅ astro127028
✅ example127028
✅ express127028
✅ fastify127028
✅ hono127028
✅ nextjs-turbopack15203
✅ nextjs-webpack15203
✅ nitro127028
✅ nuxt127028
✅ sveltekit14609
✅ vite127028

✅ 💻 Local Development

AppPassedFailedSkipped
✅ astro-stable129026
✅ express-stable129026
✅ fastify-stable129026
✅ hono-stable129026
✅ nextjs-turbopack-canary136019
✅ nextjs-turbopack-stable15500
✅ nextjs-webpack-canary136019
✅ nextjs-webpack-stable15500
✅ nitro-stable129026
✅ nuxt-stable129026
✅ sveltekit-stable14807
✅ vite-stable129026

✅ 📦 Local Production

AppPassedFailedSkipped
✅ astro-stable129026
✅ express-stable129026
✅ fastify-stable129026
✅ hono-stable129026
✅ nextjs-turbopack-canary136019
✅ nextjs-turbopack-stable15500
✅ nextjs-webpack-canary136019
✅ nextjs-webpack-stable15500
✅ nitro-stable129026
✅ nuxt-stable129026
✅ sveltekit-stable14807
✅ vite-stable129026

✅ 🐘 Local Postgres

AppPassedFailedSkipped
✅ astro-stable129026
✅ express-stable129026
✅ fastify-stable129026
✅ hono-stable129026
✅ nextjs-turbopack-canary136019
✅ nextjs-turbopack-stable15500
✅ nextjs-webpack-canary136019
✅ nextjs-webpack-stable15500
✅ nitro-stable129026
✅ nuxt-stable129026
✅ sveltekit-stable14807
✅ vite-stable129026

✅ 🪟 Windows

AppPassedFailedSkipped
✅ nextjs-turbopack15500

✅ 📋 Other

AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable129026
✅ e2e-local-dev-tanstack-start-129026
✅ e2e-local-postgres-nest-stable129026
✅ e2e-local-postgres-tanstack-start-129026
✅ e2e-local-prod-nest-stable129026
✅ e2e-local-prod-tanstack-start-129026
✅ e2e-vercel-prod-nest127028
✅ e2e-vercel-prod-tanstack-start127028

✅ vercel-multi-region

AppPassedFailedSkipped
✅ nextjs-turbopack2700

📋 View full workflow run

@github-actions

github-actionsBot 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

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep274 (-65%) 💚1397 🔴 (+28%) 🔻1433 🔴 (+25%) 🔻1680 🔴 (+10%)30
TTFSstream253 (+6.3%)1344 🔴 (+24%) 🔻1377 🔴 (+24%) 🔻1459 🔴 (+25%) 🔻30
TTFShook + stream512 (-59%) 💚1597 🔴 (+16%) 🔻1644 🔴 (+14%)1672 🔴 (-9.1%)30
STSO1020 steps (inline)179 (+3.5%)485 (-6.4%)550 (-6.0%)761 (-13%)1016
STSO1020 steps (queue-hop)1677 (-15%) 💚3122 (-5.6%)3122 (-5.6%)3122 (-5.6%)3
WO1020 steps428735 (-4.1%)428735 (-4.1%)428735 (-4.1%)428735 (-4.1%)1
SLstream latency105 (+14%)171 🔴 (-5.0%)201 🔴 (-17%) 💚277 🔴 (-36%) 💚30
SOstream overhead (text)122 (-10%)212 (-2.8%)298 (+9.6%)420 (+12%)30
SOstream 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.

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

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 mainAug 4, 2026
161 of 179 checks passed
@VaguelySerious
VaguelySerious deleted the peter/correlation-id-run-scope branch August 4, 2026 20:09
@github-actions

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

@VaguelySerious@TooTallNate