Skip to content

Default WORKFLOW_PRECONDITION_GUARD on#2946

Merged
VaguelySerious merged 6 commits into
mainfrom
peter/precondition-guard-followup
Jul 21, 2026
Merged

Default WORKFLOW_PRECONDITION_GUARD on#2946
VaguelySerious merged 6 commits into
mainfrom
peter/precondition-guard-followup

Conversation

@VaguelySerious

@VaguelySerious VaguelySerious commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #2266. Two things:

  1. WORKFLOW_PRECONDITION_GUARD is now on by default. The event-creation guard was opt-in; it now runs unless explicitly disabled with WORKFLOW_PRECONDITION_GUARD=0. Backends that don't support the guard ignore the stateUpdatedAt snapshot, so this is backward-compatible and fails open. Validated by the Add stateUpdatedAt precondition guard to event creation #2266 race-repro (2000 runs guard-on: 0 CORRUPTED_EVENT_LOG, 13.8% of runs hit a 412 and recovered).

  2. Addresses the non-blocking feedback from this review

Review items addressed

  • Env-var parsing footgundeferred to a separate PR. Accepting the common truthy/falsy spellings (1/true/yes/on, 0/false/no/off) instead of only 1 will ship on its own, so this PR leaves the flag parsing (and @workflow/builders / @workflow/world-vercel) untouched.
  • run_failed asymmetry — added a comment documenting why the terminal run_failed is intentionally not guarded like run_completed (fail-open: a spurious failure is re-runnable, a spurious completion commits a wrong result; and the loaded event log isn't in scope on that catch path). Guarding it symmetrically would be a larger change — happy to do it as its own follow-up if preferred.
  • World-authoring docs gapCreateEventParams.stateUpdatedAt JSDoc now documents the backend contract (which events advance the per-run marker, strictly-older rejects, equal-passes anti-livelock) so custom-World authors have something to implement against.
  • Concurrent-reload cursor — comment on the benign last-write-wins cursor in withPreconditionRetry.
  • Silent disarm diagnosticsruntimeLogger.debug when a non-decodable event id disarms the guard for a create.
  • retryAfter nit — JSDoc noting it's forward-compat and currently unread by the runtime.

Follow-up to #2266 (review pullrequestreview-4699625704).

- **Guard on by default:** `isPreconditionGuardEnabled()` now returns true
  unless `WORKFLOW_PRECONDITION_GUARD` is explicitly falsy. Validated by the
  #2266 race-repro (2000 runs guard-on: 0 corruptions).
- **Env-var footgun:** boolean flags accept `1`/`true`/`yes`/`on` (and
  `0`/`false`/`no`/`off` for the guard's opt-out) case-insensitively instead of
  only `1`, so `=true` no longer silently reads as off. Mirrored across
  `isPreconditionGuardEnabled` (core) and `isSequentialReplaysEnabled`
  (builders + world-vercel).
- **run_failed asymmetry:** comment documenting why the terminal `run_failed`
  is intentionally not guarded (fail-open, re-runnable) unlike `run_completed`.
- **Concurrent-reload cursor:** comment on the benign last-write-wins cursor in
  withPreconditionRetry.
- **World-authoring docs:** CreateEventParams.stateUpdatedAt JSDoc now documents
  the backend marker/reject/equal-passes contract for custom-world authors.
- **Diagnostics:** debug log when a non-decodable event id disarms the guard.
- **retryAfter:** JSDoc noting it is forward-compat and currently unused.
- Docs: runtime-tuning guard entry updated to "Default: enabled" + opt-out.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VaguelySerious
VaguelySerious requested review from a team and ijjk as code owners July 15, 2026 19:36
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 17ec74f

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

This PR includes changesets to release 21 packages
Name Type
workflow Minor
@workflow/core Minor
@workflow/world Patch
@workflow/errors Patch
@workflow/world-testing Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
@workflow/world-local Patch
@workflow/world-postgres Patch
@workflow/world-vercel Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/nuxt 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 Jul 15, 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, Comment Jul 21, 2026 4:14pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment Jul 21, 2026 4:14pm
example-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-astro-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-express-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-fastify-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-hono-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-nestjs-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-nitro-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-nuxt-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-sveltekit-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workbench-vite-workflow Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workflow-docs Building Building Preview, Comment, Open in v0 Jul 21, 2026 4:14pm
workflow-swc-playground Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workflow-tarballs Ready Ready Preview, Comment Jul 21, 2026 4:14pm
workflow-web Ready Ready Preview, Comment Jul 21, 2026 4:14pm

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 17ec74f · Tue, 21 Jul 2026 16:25:15 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 303 (+21%) 🔻 1284 🔴 (-5.7%) 1293 🔴 (-7.8%) 1418 🔴 (-5.2%) 30
TTFS stream 1197 (+360%) 🔻 1249 🔴 (-7.6%) 1273 🔴 (-7.4%) 1316 🔴 (-10%) 30
TTFS hook + stream 468 (+33%) 🔻 1541 🔴 (±0%) 1587 🔴 (+0.6%) 1639 🔴 (-6.9%) 30
STSO 1020 steps (1-20) 177 (-3.3%) 283 🔴 (-17%) 💚 310 🔴 (-20%) 💚 504 🔴 (-29%) 💚 19
STSO 1020 steps (101-120) 187 (-5.6%) 238 🔴 (-19%) 💚 289 🔴 (-21%) 💚 381 🔴 (-20%) 💚 19
STSO 1020 steps (1001-1020) 462 (-13%) 539 🔴 (-15%) 680 🔴 (-4.1%) 3375 🔴 (+307%) 🔻 19
WO 1020 steps 373253 (-8.1%) 373253 (-8.1%) 373253 (-8.1%) 373253 (-8.1%) 1
SL stream latency 89 (-3.3%) 146 🔴 (-16%) 💚 153 🔴 (-27%) 💚 331 🔴 (+34%) 🔻 30
📜 Previous results (4)

cf4bdba

Mon, 20 Jul 2026 21:10:52 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1265 (+19%) 🔻 1389 🔴 (+15%) 🔻 1441 🔴 (+16%) 🔻 1554 🔴 (-9.1%) 30
TTFS stream 360 (+1.1%) 1335 🔴 (+24%) 🔻 1388 🔴 (+22%) 🔻 1552 🔴 (+25%) 🔻 30
TTFS hook + stream 1532 (+211%) 🔻 1690 🔴 (+19%) 🔻 1776 🔴 (+10%) 1911 🔴 (-38%) 💚 30
STSO 1020 steps (1-20) 183 (-13%) 312 🔴 (-1.3%) 362 🔴 (-12%) 445 🔴 (-6.7%) 19
STSO 1020 steps (101-120) 222 (+1.8%) 275 🔴 (-10%) 343 🔴 (-1.7%) 908 🔴 (+149%) 🔻 19
STSO 1020 steps (1001-1020) 463 (-6.1%) 551 🔴 (-12%) 586 🔴 (-18%) 💚 592 🔴 (-26%) 💚 19
WO 1020 steps 428613 (-6.2%) 428613 (-6.2%) 428613 (-6.2%) 428613 (-6.2%) 1
SL stream latency 105 (+15%) 🔻 188 🔴 (+4.4%) 223 🔴 (-9.0%) 351 🔴 (-33%) 💚 30

ae65171

Sat, 18 Jul 2026 00:21:01 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1334 🔴 1366 🔴 1442 🔴 30
TTFS stream 1330 🔴 1358 🔴 1384 🔴 30
TTFS hook + stream 1593 🔴 1626 🔴 1943 🔴 30
STSO 1020 steps (1-20) 275 🔴 303 🔴 426 🔴 19
STSO 1020 steps (101-120) 293 🔴 353 🔴 2119 🔴 19
STSO 1020 steps (1001-1020) 585 🔴 620 🔴 677 🔴 19
WO 1020 steps 411512 411512 411512 1
SL stream latency 192 🔴 244 🔴 378 🔴 30

304f594

Wed, 15 Jul 2026 20:54:37 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1647 🔴 1663 🔴 1801 🔴 30
TTFS hook + stream 1956 🔴 2031 🔴 2137 🔴 30
STSO 1020 steps (1-20) 377 🔴 515 🔴 678 🔴 19
STSO 1020 steps (101-120) 577 🔴 625 🔴 630 🔴 19
STSO 1020 steps (1001-1020) 1123 🔴 1217 🔴 4432 🔴 19
WO stream 1647 1663 1801 30
WO hook + stream 1956 2031 2137 30
SL stream 5513 🔴 5554 🔴 5825 🔴 30
SL hook + stream 5333 🔴 5581 🔴 6739 🔴 30

45a9425

Wed, 15 Jul 2026 19:57:19 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1708 🔴 1745 🔴 1945 🔴 30
TTFS hook + stream 1944 🔴 1998 🔴 2086 🔴 30
STSO 1020 steps (1-20) 353 🔴 439 🔴 653 🔴 19
STSO 1020 steps (101-120) 461 🔴 620 🔴 658 🔴 19
STSO 1020 steps (1001-1020) 1059 🔴 1077 🔴 1413 🔴 19
WO stream 1708 1745 1945 30
WO hook + stream 1944 1998 2086 30
SL stream 4754 🔴 5673 🔴 5755 🔴 30
SL hook + stream 5232 🔴 5478 🔴 5871 🔴 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-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 1455 0 239 1694
✅ 💻 Local Development 1621 0 227 1848
✅ 📦 Local Production 1621 0 227 1848
✅ 🐘 Local Postgres 1621 0 227 1848
✅ 🪟 Windows 154 0 0 154
✅ 📋 Other 1020 0 212 1232
✅ vercel-multi-region 27 0 0 27
Total 7519 0 1132 8651

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 126 0 28
✅ example 126 0 28
✅ express 126 0 28
✅ fastify 126 0 28
✅ hono 126 0 28
✅ nextjs-turbopack 151 0 3
✅ nextjs-webpack 151 0 3
✅ nitro 126 0 28
✅ nuxt 126 0 28
✅ sveltekit 145 0 9
✅ vite 126 0 28
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 154 0 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 128 0 26
✅ e2e-local-dev-tanstack-start- 128 0 26
✅ e2e-local-postgres-nest-stable 128 0 26
✅ e2e-local-postgres-tanstack-start- 128 0 26
✅ e2e-local-prod-nest-stable 128 0 26
✅ e2e-local-prod-tanstack-start- 128 0 26
✅ e2e-vercel-prod-nest 126 0 28
✅ e2e-vercel-prod-tanstack-start 126 0 28
✅ vercel-multi-region
App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

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

Documentation incorrectly states the precondition guard requires opt-in via WORKFLOW_PRECONDITION_GUARD=1, when it is now enabled by default.

Fix on Vercel

@VaguelySerious VaguelySerious changed the title Default WORKFLOW_PRECONDITION_GUARD on; address #2266 review feedback Default WORKFLOW_PRECONDITION_GUARD on Jul 15, 2026

@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 both shapes of this PR — the original (default-flip + env-var spelling hardening) and the narrowed head after 304f594bd split the spelling changes out. Approving the narrowed version.

The flip itself is sound and consistent with the merged #2266 state. I re-verified the post-approval history: the WORKFLOW_SAFE_MODE umbrella was removed from #2266 before merge ("configure WORKFLOW_SEQUENTIAL_REPLAYS directly"), so isPreconditionGuardEnabled() collapsing to a single !== '0' check has no orphaned umbrella semantics to worry about. Fail-open properties hold in every direction: unsupporting backends ignore the snapshot (no-op, today's behavior), a non-decodable event id disarms the guard for that create (now with the debug log so a fleet-wide silent disarm is diagnosable), and an unrecognized env value fails toward the guard — the correct direction for an opt-out safety flag.

The review-feedback items are all well executed:

  • The run_failed asymmetry comment captures both the principled reason (spurious failure is re-runnable; spurious completion commits a wrong result) and the practical one (the event log isn't in scope in that catch) — exactly what a future reader needs to not "fix" it naively.
  • The stateUpdatedAt backend-contract JSDoc is the most valuable addition here: the externally-originated-events-advance-the-marker / replay-origin-events-must-not distinction is the crux of the whole design, and it was previously only implemented, not specified. Custom-World authors now have something to build against, including the equal-passes anti-livelock rule.
  • The concurrent-reload cursor comment (benign last-write-wins, refetch-only consequence) and the retryAfter forward-compat note close out the remaining items.

Verified locally on the narrowed head: guard + replay + runtime suites 66/66; full core suite was 1482 green on the pre-narrowing head and the narrowing only removed code. Docs were correctly narrowed along with the code ("Set 0 to disable" — no spelling promises the code doesn't keep). Changeset properly trimmed to workflow/@workflow/core minor + world/errors patch. The one CI failure is the nextjs-webpack HMR rebuild-count test — the same flake family that's hit at least four unrelated PRs recently, and it watches dev-server rebuild logs, mechanistically untouched by event-creation guarding.

Two follow-through asks, non-blocking:

  1. With the spelling hardening split out, WORKFLOW_PRECONDITION_GUARD=false currently leaves the guard on silently — the exact footgun class the split-out PR fixes, now pointed in the opposite direction. The docs only promise 0, so nothing is inconsistent — but please land the spelling PR promptly behind this one so the window where =false misleads is short.
  2. For the record on rollout sequencing: the Slack plan was a few days of internal-project soak before the opt-out flip. The 2000-run race-repro (0 corrupted, 13.8% recovered 412s) plus the fully-green forced-ON e2e round from #2266 are strong evidence, and the failure mode on unsupporting backends is a no-op — so I'm comfortable approving. Just confirm the backend guard support is fully rolled out in production before this reaches a published beta, since default-ON makes the 412-recovery path production-hot immediately.

…ard-followup

# Conflicts:
#	docs/content/docs/v5/configuration/runtime-tuning.mdx
@github-actions

Copy link
Copy Markdown
Contributor

No backport to stable for eb8fdb9 (AI decision).

This commit is a follow-up to #2266's WORKFLOW_PRECONDITION_GUARD feature, which exists only on main: verified via git grep on origin/stable that WORKFLOW_PRECONDITION_GUARD, withPreconditionRetry, PreconditionFailedError, and stateUpdatedAt do not exist anywhere in packages/, and the touched v5 docs page docs/content/docs/v5/configuration/runtime-tuning.mdx is also absent there. Every changed file builds on main-only behavior, so there is nothing to backport.

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

eb8fdb979748f54a94289530ee7ac155feddddcc

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