Skip to content

Default WORKFLOW_PRECONDITION_GUARD on#2946

Open
VaguelySerious wants to merge 3 commits into
mainfrom
peter/precondition-guard-followup
Open

Default WORKFLOW_PRECONDITION_GUARD on#2946
VaguelySerious wants to merge 3 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: 304f594

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 15, 2026 8:37pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment Jul 15, 2026 8:37pm
example-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-astro-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-express-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-fastify-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-hono-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-nitro-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-nuxt-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-sveltekit-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workbench-vite-workflow Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workflow-docs Ready Ready Preview, Comment, Open in v0 Jul 15, 2026 8:37pm
workflow-swc-playground Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workflow-tarballs Ready Ready Preview, Comment Jul 15, 2026 8:37pm
workflow-web Ready Ready Preview, Comment Jul 15, 2026 8:37pm

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

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

Backend: vercel · app: nextjs-turbopack

Metric Scenario Avg (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1149 (-3.6%) 1647 🔴 1663 🔴 1801 🔴 30
TTFS hook + stream 1663 (+16%) 1956 🔴 2031 🔴 2137 🔴 30
STSO 1020 steps (1-20) 338 (+7.4%) 377 🔴 515 🔴 678 🔴 19
STSO 1020 steps (101-120) 496 (+3.9%) 577 🔴 625 🔴 630 🔴 19
STSO 1020 steps (1001-1020) 1151 (+12%) 1123 🔴 1217 🔴 4432 🔴 19
WO stream 1149 (-3.6%) 1647 1663 1801 30
WO hook + stream 1663 (+16%) 1956 2031 2137 30
SL stream 4534 (+8.8%) 5513 🔴 5554 🔴 5825 🔴 30
SL hook + stream 4779 (±0%) 5333 🔴 5581 🔴 6739 🔴 30
📜 Previous results (1)

45a9425

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

vercel / nextjs-turbopack

Metric Scenario Avg (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1253 (-2.7%) 1708 🔴 1745 🔴 1945 🔴 30
TTFS hook + stream 1555 (+8.4%) 1944 🔴 1998 🔴 2086 🔴 30
STSO 1020 steps (1-20) 310 (+13%) 353 🔴 439 🔴 653 🔴 19
STSO 1020 steps (101-120) 450 (+7.3%) 461 🔴 620 🔴 658 🔴 19
STSO 1020 steps (1001-1020) 969 (+16%) 1059 🔴 1077 🔴 1413 🔴 19
WO stream 1253 (-2.7%) 1708 1745 1945 30
WO hook + stream 1555 (+8.4%) 1944 1998 2086 30
SL stream 4159 (-15%) 4754 🔴 5673 🔴 5755 🔴 30
SL hook + stream 4729 (-7.8%) 5232 🔴 5478 🔴 5871 🔴 30

Avg deltas compare against the most recent benchmark run on main at the time of this run.

Metrics — TTFS: time to first step body execution · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (time outside step bodies, client start → last step body exit) · SL: stream latency (first chunk write → visible to the reader)

Scenarios — stream: one step that streams chunks back to the client; no hooks, so the run stays in turbo mode · hook + stream: registers a hook before the same streaming step, which exits turbo mode · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges

🟢/🔴 mark percentiles within/above target. 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

TTFS/WO compare client vs deployment clocks and SL compares the step runner’s clock vs the client’s (NTP-synced in CI). WO ends at the last step body exit, the closest observable proxy for the final step-completion request.

@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 1453 0 230 1683
✅ 💻 Local Development 1464 0 219 1683
✅ 📦 Local Production 1617 0 219 1836
✅ 🐘 Local Postgres 1617 0 219 1836
✅ 🪟 Windows 153 0 0 153
✅ 📋 Other 894 0 177 1071
✅ vercel-multi-region 27 0 0 27
Total 7225 0 1064 8289

Details by Category

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

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: success
  • Local Dev: failure
  • Local Prod: success
  • Local Postgres: success
  • Windows: success

Check the workflow run for details.

@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
Per follow-up direction, remove the "accept common truthy/falsy spellings"
change from this PR; it will ship on its own later. The guard's default-on
behavior stays (opt out with WORKFLOW_PRECONDITION_GUARD=0), and
WORKFLOW_SEQUENTIAL_REPLAYS reverts to `=== '1'` (back to main), so
@workflow/builders and @workflow/world-vercel are no longer touched by this PR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

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