Skip to content

Implement max_events per run limit - #2986

Merged
shalabhc merged 15 commits into
mainfrom
shalabhc/event-limit-enforcement
Jul 22, 2026
Merged

Implement max_events per run limit#2986
shalabhc merged 15 commits into
mainfrom
shalabhc/event-limit-enforcement

Conversation

@shalabhc

@shalabhcshalabhc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enforces the published per-run events limit, which was previously not enforced. The server supplies the limit on the run_started response (separate change); once a run's event log reaches it, the runtime throws MaxEventsExceededError at the top of the replay loop, and the existing terminal-error path records it as run_failed with a new MAX_EVENTS_EXCEEDED code — instead of letting a runaway workflow (e.g. an unbounded step loop) grow the event log without bound.

  • Checked after the log is loaded and before runWorkflow schedules more work; deterministic, so it fails without retry/redelivery and is attributed to user code.
  • Enforced under both the Vercel World (server-supplied limit) and the Local World (WORKFLOW_MAX_EVENTS).
  • Additive and backwards-compatible: older servers/worlds omit the limit ⇒ no enforcement, in either direction.

Testing

  • classify-error.test.tsMaxEventsExceededError classifies as MAX_EVENTS_EXCEEDED.
  • describe-error.test.ts — user attribution + hint for the code.
  • world-testing E2E — a runaway workflow fails with MAX_EVENTS_EXCEEDED via the in-process Local World (WORKFLOW_MAX_EVENTS=10, turbo disabled), no Docker.

Pairs with the server change: vercel/workflow-server#638

@changeset-bot

changeset-botBot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f70fea4

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

This PR includes changesets to release 21 packages
NameType
@workflow/errorsPatch
@workflow/corePatch
@workflow/worldPatch
@workflow/world-vercelPatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-localPatch
@workflow/world-postgresPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/world-testingPatch
@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 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actionsBot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 81e9dcb · Tue, 21 Jul 2026 21:00:02 GMT · run logs

Backend: vercel · app: nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep129 (+16%) 🔻315 🔴 (+41%) 🔻373 🔴 (-8.1%)456 (-13%)30
TTFSstream124 (-8.8%)206 🔴 (-29%) 💚227 (-37%) 💚492 (-39%) 💚30
TTFShook + stream293 (-17%) 💚461 🔴 (-9.3%)586 🔴 (+1.7%)1378 🔴 (+123%) 🔻30
STSO1020 steps (1-20)196 (+15%)318 🔴 (+20%) 🔻364 🔴 (+13%)743 🔴 (+104%) 🔻19
STSO1020 steps (101-120)244 (+18%) 🔻356 🔴 (+17%) 🔻456 🔴 (+33%) 🔻596 🔴 (+26%) 🔻19
STSO1020 steps (1001-1020)599 (+2.2%)803 🔴 (+12%)1015 🔴 (+31%) 🔻1022 🔴 (+25%) 🔻19
WO1020 steps574390 (+9.0%)574390 (+9.0%)574390 (+9.0%)574390 (+9.0%)1
SLstream latency76 (±0%)117 🔴 (+13%)155 🔴 (-6.6%)228 🔴 (-5.8%)30
📜 Previous results (8)

f70fea4

Tue, 21 Jul 2026 18:44:53 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep155 (-85%) 💚300 🔴 (-74%) 💚383 🔴 (-70%) 💚431 (-72%) 💚30
TTFSstream154 (-38%) 💚386 🔴 (-66%) 💚509 🔴 (-58%) 💚2386 🔴 (+92%) 🔻30
TTFShook + stream300 (-76%) 💚507 🔴 (-65%) 💚731 🔴 (-51%) 💚2592 🔴 (+60%) 🔻30
STSO1020 steps (1-20)196 (+8.9%)325 🔴 (+1.6%)428 🔴 (+18%) 🔻453 🔴 (+3.9%)19
STSO1020 steps (101-120)240 (+16%) 🔻415 🔴 (+28%) 🔻525 🔴 (+38%) 🔻1034 🔴 (+106%) 🔻19
STSO1020 steps (1001-1020)620 (+24%) 🔻731 🔴 (+23%) 🔻869 🔴 (+35%) 🔻911 🔴 (+24%) 🔻19
WO1020 steps545430 (+24%) 🔻545430 (+24%) 🔻545430 (+24%) 🔻545430 (+24%) 🔻1
SLstream latency100 (+1.0%)156 🔴 (-7.1%)191 🔴 (+3.8%)2560 🔴 (+1091%) 🔻30

6d2ded2

Tue, 21 Jul 2026 04:23:07 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep443 (-38%) 💚1290 🔴 (+20%) 🔻1307 🔴 (+19%) 🔻1424 🔴 (-4.2%)30
TTFSstream1209 (+29%) 🔻1274 🔴 (+23%) 🔻1286 🔴 (+21%) 🔻1293 🔴 (+19%) 🔻30
TTFShook + stream1423 (+19%) 🔻1545 🔴 (+21%) 🔻1689 🔴 (+29%) 🔻3424 🔴 (+140%) 🔻30
STSO1020 steps (1-20)166 (-3.5%)278 🔴 (+14%)372 🔴 (+30%) 🔻435 🔴 (+26%) 🔻19
STSO1020 steps (101-120)180 (-6.3%)244 🔴 (-7.9%)323 🔴 (-53%) 💚360 🔴 (-68%) 💚19
STSO1020 steps (1001-1020)468 (+2.0%)592 🔴 (+17%) 🔻724 🔴 (+32%) 🔻3563 🔴 (+430%) 🔻19
WO1020 steps374542 (-1.1%)374542 (-1.1%)374542 (-1.1%)374542 (-1.1%)1
SLstream latency83 (+1.2%)142 🔴 (+15%)158 🔴 (-1.3%)246 🔴 (+12%)30

3a9ff12

Tue, 21 Jul 2026 01:06:57 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep233 (-67%) 💚1275 🔴 (+19%) 🔻1316 🔴 (+20%) 🔻1411 🔴 (-5.0%)30
TTFSstream213 (-77%) 💚1257 🔴 (+21%) 🔻1278 🔴 (+21%) 🔻1340 🔴 (+23%) 🔻30
TTFShook + stream540 (-55%) 💚1482 🔴 (+16%) 🔻1516 🔴 (+15%) 🔻1652 🔴 (+16%) 🔻30
STSO1020 steps (1-20)171 (-0.6%)283 🔴 (+16%) 🔻310 🔴 (+8.4%)316 🔴 (-8.4%)19
STSO1020 steps (101-120)175 (-8.9%)246 🔴 (-7.2%)317 🔴 (-54%) 💚543 🔴 (-52%) 💚19
STSO1020 steps (1001-1020)467 (+1.7%)571 🔴 (+12%)585 🔴 (+6.4%)882 🔴 (+31%) 🔻19
WO1020 steps390362 (+3.0%)390362 (+3.0%)390362 (+3.0%)390362 (+3.0%)1
SLstream latency90 (+9.8%)145 🔴 (+17%) 🔻209 🔴 (+31%) 🔻307 🔴 (+40%) 🔻30

3f073da

Mon, 20 Jul 2026 20:27:41 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1353 🔴1398 🔴1464 🔴30
TTFSstream1346 🔴1405 🔴1449 🔴30
TTFShook + stream1693 🔴1707 🔴1776 🔴30
STSO1020 steps (1-20)355 🔴450 🔴458 🔴19
STSO1020 steps (101-120)306 🔴366 🔴402 🔴19
STSO1020 steps (1001-1020)611 🔴701 🔴728 🔴19
WO1020 steps4341244341244341241
SLstream latency169 🔴206 🔴234 🔴30

8d92b85

Mon, 20 Jul 2026 19:32:09 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1409 🔴1428 🔴1586 🔴30
TTFSstream1401 🔴1438 🔴1978 🔴30
TTFShook + stream1694 🔴1726 🔴2009 🔴30
STSO1020 steps (1-20)268 🔴307 🔴309 🔴19
STSO1020 steps (101-120)344 🔴417 🔴521 🔴19
STSO1020 steps (1001-1020)564 🔴613 🔴696 🔴19
WO1020 steps4148964148964148961
SLstream latency192 🔴231 🔴300 🔴30

5062c00

Mon, 20 Jul 2026 18:46:24 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1266 🔴1279 🔴1333 🔴30
TTFSstream1280 🔴1290 🔴1316 🔴30
TTFShook + stream1479 🔴1522 🔴1606 🔴30
STSO1020 steps (1-20)311 🔴488 🔴524 🔴19
STSO1020 steps (101-120)332 🔴429 🔴638 🔴19
STSO1020 steps (1001-1020)561 🔴669 🔴674 🔴19
WO1020 steps4165044165044165041
SLstream latency175 🔴213 🔴402 🔴30

310f227

Fri, 17 Jul 2026 19:14:49 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstream1699 🔴1733 🔴3652 🔴30
TTFShook + stream1943 🔴2031 🔴3686 🔴30
STSO1020 steps (1-20)356 🔴398 🔴470 🔴19
STSO1020 steps (101-120)308 🔴405 🔴555 🔴19
STSO1020 steps (1001-1020)764 🔴773 🔴808 🔴19
WOstream16991733365230
WOhook + stream19432031368630
SLstream5806 🔴5933 🔴6050 🔴30
SLhook + stream5648 🔴5729 🔴6639 🔴30

330a548

Fri, 17 Jul 2026 16:29:55 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstream1721 🔴1783 🔴1905 🔴30
TTFShook + stream2064 🔴2121 🔴2384 🔴30
STSO1020 steps (1-20)333 🔴436 🔴521 🔴19
STSO1020 steps (101-120)491 🔴581 🔴616 🔴19
STSO1020 steps (1001-1020)938 🔴999 🔴1100 🔴19
WOstream17211783190530
WOhook + stream20642121238430
SLstream5877 🔴6059 🔴6309 🔴30
SLhook + stream5761 🔴5825 🔴7096 🔴30

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)

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)

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · 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 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

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

@shalabhc
shalabhcforce-pushed the shalabhc/event-limit-enforcement branch from 4d4aefc to d4ddf7eCompareJuly 17, 2026 16:07
@shalabhc
shalabhcforce-pushed the shalabhc/event-limit-enforcement branch from d4ddf7e to 330a548CompareJuly 17, 2026 16:10
@vercel
vercelBottemporarily deployed to Preview – workflow-docs July 17, 2026 16:10 Inactive
Comment threadworkbench/nextjs-turbopack/workflows/test_blob_violation.ts Outdated
@shalabhc

Copy link
Copy Markdown
CollaboratorAuthor

Made change to use server provided limit.
Refactored to raise a new max events exceeded error that gets caught and fails run via a prexisting catch.

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

Let's wait with merge until other PRs merge first

Comment threadpackages/world/src/events.ts Outdated
Comment threadpackages/world-testing/workflows/event-limit.ts Outdated

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

workbench/nest's vercel-build script invokes packages/nest/dist/cli.js without first compiling the @workflow/nest workspace dependency, so the file is missing and the build aborts with MODULE_NOT_FOUND.

Fix on Vercel

@vercel

vercelBot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

You must have Developer access to commit code to Vercel Labs on Vercel. If you contact an administrator and receive Developer access, commit again to see your changes.

Learn more: https://vercel.com/docs/accounts/team-members-and-roles/access-roles#team-level-roles

@github-actionsgithub-actionsBot mentioned this pull request Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #3042. Merge conflicts were resolved by AI — please review carefully. (backport job run)

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

@shalabhc@VaguelySerious