Skip to content

[core] [world] PoC: run ahead past an awaited hook with strict speculative writes - #5660

Draft
benpankow wants to merge 7 commits into
poc/wait-due-horizonfrom
poc/conditional-run-ahead
Draft

benpankow wants to merge 7 commits into
poc/wait-due-horizonfrom
poc/conditional-run-ahead

Conversation

@benpankow

@benpankow benpankow commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Proof of concept, stacked on #5659 (and #5658, #5657). This shows one way to implement proposal 2 from the research note, so the trade-offs are concrete. It doesn't settle the API, which Worlds implement it, or the restart policy. Those choices are for the Workflow team.

What

On a World that declares the new capabilities.strictEventCount, spec 9 run-ahead can run ahead at a boundary whose only reason not to be inert is a hook that workflow code awaits. At such a "conditional" boundary:

  • Strict writes: every speculative write (outcomes and creations) is sent with strictEventCount: true and exactly the position it was decided at: its predicted slot - 1, never raised to the writer's completeThrough. The World commits it only at slot eventCount + 1, after checking the in-band fence. Otherwise it refuses with a new EventSlotTakenError (412, event-slot-taken) and allocates nothing.
  • Local refusal: the in-band writer also refuses a strict write itself if, since the boundary was classified, it learned of a position another writer took. That covers a live-feed or loaded event that isn't its own echo, and a gap below its own committed write.
  • Restart: either refusal becomes a RunAheadStopError. Decisions stop, as at a hazard stop. Refused outcomes of steps whose start committed are resent as ordinary writes, so no finished step runs again. Then the delivery restarts from a fresh load through the existing path.
  • No early bodies: the next step's body starts only once its creation has committed. To keep a gain anyway, the outcome write is held for up to 5ms until the next creation joins it, so both commit in one batch.
  • Unconsumed events: a boundary is never conditional while the log holds an event the workflow hasn't consumed.

Why

eve's session inbox always has a read pending on its hook, so every step boundary of an eve turn counts as having an awaited hook, and run-ahead never engages. Today a payload landing between speculative writes would commit around them and cause a hazard stop with possibleLogCorruption, which is why awaited hooks disable run-ahead. A conditional commit turns that case into a clean refusal before anything decided without the payload commits.

Review follow-ups

  • A strict write could commit past an unseen payload, confirmed and fixed. A non-strict write's answer, for example a bumped wait_created, could raise completeThrough past an unseen hook_received, and a strict write queued behind it then named a position covering it. Strict writes now name their decided position exactly, and the writer refuses them locally once it has learned of a foreign slot. A new test triggers this through a wait_created. It fails on the previous commit, where strict writes kept committing above the payload, and passes now.
  • Side effects after a refusal, fixed. Bodies started before their creation committed, so after a refusal a step the workflow never calls again could leave side effects with no event behind them. Bodies at a conditional boundary now wait for their creation to commit. The test checks that every body that ran has a committed step_started. The EventSlotTakenError doc no longer overstates the guarantee.
  • A refused outcome re-ran its step, confirmed and fixed. A refused group dropped its held outcome, so the restart re-ran a step that had already finished (9 steps, 10 bodies, two step_started for one step). The outcome doesn't depend on the payload, because the step's creation had already committed. So a refused group now resends those outcomes as ordinary writes, using the hazard-stop rule for what may still be written, and drops only the creations. Both tests now assert one step_started and one body per step. The hazard check stands down once a strict write was refused, because every speculative write before it went out at its exact slot.
  • An ordinary write could ride in a strict group, fixed. A non-strict creation queued into a held strict group went out at the strict position and was refused with it, and its body had already started. Strict and ordinary writes now never share a group, and a writer-level test fails without that rule. Behind strict writes in flight, an inert boundary is also treated as conditional (strict writes, bodies wait for their creation), because a refusal rejects every write decided after it.
  • Hazard check after a refusal: it now stands down only while no non-strict speculative write is in flight.
  • EventSlotTakenError doc: it now agrees with the World contract that a retried write may be refused after its first attempt committed. In that case the fence refuses the next write and the run is redelivered.
  • Not changed: slot gaps from this writer's own refused batch items still count as another writer's event. The writer knows how many slots a batch allocated, but not which refused item took them. Counting a hole as foreign costs a restart; counting a foreign event as its own would be unsafe.
  • Foreign-slot baseline taken too late, fixed (not reproduced). The baseline was read when the boundary was classified, so a slot another writer took between the start of the pass and classification could be counted as seen. It's now taken when the pass starts, and a boundary is conditional only if the writer learned nothing since. An inert boundary behind strict writes drains in that case.
  • Conformance: @workflow/world now ships strict-event-count-conformance.ts, in the shape of the fence conformance. It checks the exact slot, refusal without allocation, fence before slot, whole-batch refusal, and a slot taken out-of-band. It runs against the test World. world-vercel only maps the error and never sends strictEventCount, because it doesn't declare the capability.
  • World contract, specified. The fence is checked before the slot (the test World now does the same). A retried strict write that already committed may be refused or answered with its original result, but never committed twice. world-vercel maps 412 event-slot-taken to EventSlotTakenError.

Open for the team

  • No shipped World declares the capability. world-local, world-postgres and world-vercel (which needs workflow-server) don't, so nothing changes in practice.
  • A refusal turns run-ahead off for the rest of the delivery (MAX_RUN_AHEAD_RESTARTS), so a second refusal can't occur within it. There's no strict-specific test of the restart limit.
  • Conditional boundaries need a World with batch writes, so the strict path never goes through the lone non-batch writer.
  • The 5ms outcome hold is a guess. It trades latency on the last step of a turn for a single batch on each tool hop.
  • QuickJS has its own boundary classification, which this PoC doesn't change, so the strict tests are node:vm only: on QuickJS the conditional path never runs.

How did you test your changes?

  • run-ahead.runtime.test.ts (node:vm), on a World with strictEventCount:
    • Payload mid-batch: an outcome and the next creation go out in one batch while the hook is awaited. A payload appended mid-write gets a strict batch refused by the World. There's no possibleLogCorruption (now read from console.error, which the run logger prints through), each step has one step_started and ran one body, and a cold replay matches.
    • Payload learned through a non-strict write: a payload that reaches the writer through a non-strict wait_created is refused locally, instead of strict writes committing above it. This test fails on the first commit of this PR.
  • append-only-world.test.ts: the test World checks the fence before the slot, and a slot refusal moves neither the log nor the fence count. Before this, the test World advanced the fence before refusing, which the salvage exposed.
  • The existing "drains while the workflow waits on a hook" test still drains on a World without the capability.
  • src/runtime/spec9, test-support, the constants, abort and serialization tests (1366 tests), @workflow/world (301), @workflow/errors (67), and world-vercel's http-core and events-v4 tests (139) pass. world-local-coalescing.test.ts fails intermittently on the base branch too.
  • Not run: the full repo suites, e2e, world-sim, or a real World.

PR Checklist - Required to merge

  • 📦 pnpm changeset was run to create a changelog for this PR
  • 🔒 DCO sign-off passes (run git commit --signoff on your commits)
  • 📝 Ping @vercel/workflow in a comment once the PR is ready, and the above checklist is complete

Written by Claude Opus 5.5

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c567316

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

This PR includes changesets to release 22 packages
Name Type
@workflow/core Patch
@workflow/world Patch
@workflow/errors Patch
@workflow/world-vercel Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
workflow Patch
@workflow/world-cloudflare Patch
@workflow/world-testing Patch
@workflow/world-local Patch
@workflow/world-postgres Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt 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 Nov 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-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

⚠️ Results below are stale and not from the latest commit. This comment will be updated when CI completes on the latest run.

⏳ Tests are running...


_Started at: _


✅ All tests passed

⚠️ Flaky E2E Tests (passed on retry)

These tests failed at least once and passed on a retry. A recurring entry here is a real race worth investigating.

  • webhookWorkflow (nextjs-turbopack · local-dev / local / node / canary)

🛠 Infra Events (absorbed by the harness)

Platform anomalies the e2e harness detected and worked around (e.g. a run the queue never picked up, replaced by a fresh run). Clustered timestamps indicate a backend blip; a steady drip indicates a platform issue worth escalating.

  • run-pickup-stall · runs app-generated source against a registered step (tanstack-start) · at 21:50:42Z · abandoned wrun_01M801DPEGTKHCEGEK8ZYXY38C
  • cold-start-warmup · suite warmup (tanstack-start) · at 21:50:49Z · abandoned wrun_01M801DPFJ0RE880GXEGHXG3Q8

E2E Test Summary

Summary
Passed Failed Skipped Total
✅ 💻 Local Development 5272 0 731 6003
✅ 📦 Local Production 5272 0 731 6003
✅ 🐘 Local Postgres 5417 0 586 6003
✅ 🪟 Windows 401 0 13 414
✅ 🌐 Cross-language Conformance 68 0 114 182
✅ dynamic-runs 0 0 0 0
✅ local-postgres-spec9 0 0 364 364
✅ local-spec9 409 0 5 414
✅ vercel-http-transport 1054 0 188 1242
✅ vercel-spec9 395 0 19 414
✅ vercel-ws-transport 712 0 116 828
Total 19000 0 2867 21867
Details by Category

✅ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable-node 172 0 35
✅ astro-stable-quickjs 171 0 36
✅ express-stable-node 172 0 35
✅ express-stable-quickjs 171 0 36
✅ fastify-stable-node 172 0 35
✅ fastify-stable-quickjs 171 0 36
✅ hono-stable-node 172 0 35
✅ hono-stable-quickjs 171 0 36
✅ nest-stable-node 172 0 35
✅ nest-stable-quickjs 171 0 36
✅ nextjs-turbopack-canary-node 201 0 6
✅ nextjs-turbopack-canary-quickjs 200 0 7
✅ nextjs-turbopack-quickjs-snapshot 200 0 7
✅ nextjs-turbopack-stable-node 201 0 6
✅ nextjs-turbopack-stable-quickjs 200 0 7
✅ nextjs-webpack-canary-node 201 0 6
✅ nextjs-webpack-canary-quickjs 200 0 7
✅ nextjs-webpack-stable-node 201 0 6
✅ nextjs-webpack-stable-quickjs 200 0 7
✅ nitro-stable-node 172 0 35
✅ nitro-stable-quickjs 171 0 36
✅ nuxt-stable-node 172 0 35
✅ nuxt-stable-quickjs 171 0 36
✅ sveltekit-stable-node 191 0 16
✅ sveltekit-stable-quickjs 190 0 17
✅ tanstack-start-node 172 0 35
✅ tanstack-start-quickjs 171 0 36
✅ vite-stable-node 172 0 35
✅ vite-stable-quickjs 171 0 36

✅ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable-node 172 0 35
✅ astro-stable-quickjs 171 0 36
✅ express-stable-node 172 0 35
✅ express-stable-quickjs 171 0 36
✅ fastify-stable-node 172 0 35
✅ fastify-stable-quickjs 171 0 36
✅ hono-stable-node 172 0 35
✅ hono-stable-quickjs 171 0 36
✅ nest-stable-node 172 0 35
✅ nest-stable-quickjs 171 0 36
✅ nextjs-turbopack-canary-node 201 0 6
✅ nextjs-turbopack-canary-quickjs 200 0 7
✅ nextjs-turbopack-quickjs-snapshot 200 0 7
✅ nextjs-turbopack-stable-node 201 0 6
✅ nextjs-turbopack-stable-quickjs 200 0 7
✅ nextjs-webpack-canary-node 201 0 6
✅ nextjs-webpack-canary-quickjs 200 0 7
✅ nextjs-webpack-stable-node 201 0 6
✅ nextjs-webpack-stable-quickjs 200 0 7
✅ nitro-stable-node 172 0 35
✅ nitro-stable-quickjs 171 0 36
✅ nuxt-stable-node 172 0 35
✅ nuxt-stable-quickjs 171 0 36
✅ sveltekit-stable-node 191 0 16
✅ sveltekit-stable-quickjs 190 0 17
✅ tanstack-start-node 172 0 35
✅ tanstack-start-quickjs 171 0 36
✅ vite-stable-node 172 0 35
✅ vite-stable-quickjs 171 0 36

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable-node 177 0 30
✅ astro-stable-quickjs 176 0 31
✅ express-stable-node 177 0 30
✅ express-stable-quickjs 176 0 31
✅ fastify-stable-node 177 0 30
✅ fastify-stable-quickjs 176 0 31
✅ hono-stable-node 177 0 30
✅ hono-stable-quickjs 176 0 31
✅ nest-stable-node 177 0 30
✅ nest-stable-quickjs 176 0 31
✅ nextjs-turbopack-canary-node 206 0 1
✅ nextjs-turbopack-canary-quickjs 205 0 2
✅ nextjs-turbopack-quickjs-snapshot 205 0 2
✅ nextjs-turbopack-stable-node 206 0 1
✅ nextjs-turbopack-stable-quickjs 205 0 2
✅ nextjs-webpack-canary-node 206 0 1
✅ nextjs-webpack-canary-quickjs 205 0 2
✅ nextjs-webpack-stable-node 206 0 1
✅ nextjs-webpack-stable-quickjs 205 0 2
✅ nitro-stable-node 177 0 30
✅ nitro-stable-quickjs 176 0 31
✅ nuxt-stable-node 177 0 30
✅ nuxt-stable-quickjs 176 0 31
✅ sveltekit-stable-node 196 0 11
✅ sveltekit-stable-quickjs 195 0 12
✅ tanstack-start-node 177 0 30
✅ tanstack-start-quickjs 176 0 31
✅ vite-stable-node 177 0 30
✅ vite-stable-quickjs 176 0 31

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack-node 201 0 6
✅ nextjs-turbopack-quickjs 200 0 7

✅ 🌐 Cross-language Conformance

App Passed Failed Skipped
✅ python 68 0 114

✅ dynamic-runs

App Passed Failed Skipped
✅ example-vercel 0 0 0
✅ express-vercel 0 0 0
✅ hono-vercel 0 0 0
✅ nextjs-turbopack-vercel 0 0 0
✅ nitro-vercel 0 0 0
✅ vite-vercel 0 0 0

✅ local-postgres-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-stable-node 0 0 182
✅ nextjs-turbopack-stable-quickjs 0 0 182

✅ local-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-node 205 0 2
✅ nextjs-turbopack-quickjs 204 0 3

✅ vercel-http-transport

App Passed Failed Skipped
✅ example 171 0 36
✅ express 171 0 36
✅ hono 171 0 36
✅ nextjs-turbopack 199 0 8
✅ nitro 171 0 36
✅ vite 171 0 36

✅ vercel-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-node 198 0 9
✅ nextjs-turbopack-quickjs 197 0 10

✅ vercel-ws-transport

App Passed Failed Skipped
✅ example 171 0 36
✅ express 171 0 36
✅ nextjs-turbopack 199 0 8
✅ vite 171 0 36

📋 View full workflow run

@benpankow
benpankow force-pushed the poc/conditional-run-ahead branch from 5900ed2 to cbb3ad4 Compare November 20, 2026 23:27
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Sim World

Simulated world deterministic testing for races. Traces

🟢 world-sim scenario book — 0 fail of 45 total
scenario outcome events virt replay violations
✅ smoke-no-steps completed 3 0ms ok 0
✅ smoke-one-step completed 5 0ms ok 0
✅ hook-at-step-started completed 9 0ms ok 0
✅ hook-at-step-completed completed 9 0ms ok 0
✅ hook-at-hook-created completed 9 0ms ok 0
✅ claim-hook-at-registration completed 9 0ms ok 0
✅ claim-hook-at-step-started completed 9 0ms ok 0
✅ deadline-hook-wins completed 6 1.0h ok 0
✅ deadline-expires completed 6 1.0h ok 0
✅ step-vs-timer-early-settlement completed 6 1.0h ok 0
✅ long-sleep completed 9 30.0d ok 0
✅ hook-never-arrives stalled 3 0ms skipped 0
✅ step-retries-twice completed 9 2.0s ok 0
✅ parallel-steps completed 7 0ms ok 0
✅ hook-on-execution-state completed 9 0ms ok 0
✅ peek-hook-before-branch completed 9 0ms ok 0
✅ peek-hook-after-branch completed 9 0ms ok 0
✅ peek-hook-at-registration completed 9 0ms ok 0
✅ race-hook-before-probe completed 9 0ms ok 0
✅ race-hook-after-probe completed 9 0ms ok 0
✅ race-duplicate-delivery completed 10 0ms ok 0
✅ attr-hook-before-step completed 9 0ms ok 0
✅ attr-hook-after-step completed 9 0ms ok 0
✅ attr-from-step-body completed 10 0ms ok 0
✅ fork-hook-after-timeout completed 11 1.0m ok 0
✅ fork-hook-before-timeout completed 11 1.0m ok 0
✅ count-hook-after-timeout completed 13 1.0m ok 0
✅ count-hook-before-timeout completed 15 1.0m ok 0
✅ stale-read-step-count-fork completed 15 1.0m ok 0
✅ stale-read-equal-step-counts completed 11 1.0m ok 0
✅ step-vs-step-fork completed 9 0ms ok 0
✅ step-vs-step-fork-fenced completed 9 1.0s ok 0
✅ fence-catches-benign-direction completed 9 1.0s ok 0
✅ run-ahead-fenced-overlap completed 10 1.0s ok 0
✅ in-flight-before-decision completed 15 1.0m ok 0
✅ in-flight-before-decision-counted completed 13 1.0m ok 0
✅ in-flight-after-decision completed 15 2.0m ok 0
✅ stale-read-step-count-fork-fenced completed 15 1.0m ok 0
✅ fork-hook-wins completed 10 1.0m ok 0
✅ fork-timeout-wins completed 10 1.0m ok 0
✅ unclaimed-payload-under-fork completed 14 1.0m ok 0
✅ claimed-payload-under-fork completed 14 1.0m ok 0
✅ writers-independent-step-bodies completed 9 0ms ok 0
✅ writers-scripted-tempo completed 9 0ms ok 0
✅ cancel-mid-step cancelled 6 0ms skipped 0

Full trace: world-sim.txt

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
workflow-docs Ready Ready Preview, v0 Nov 23, 2026 6:09pm UTC

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

❌ The benchmark run for c567316 failed. See the run logs for details.

No benchmark results were produced.

ℹ️ Metric definitions & methodology

Metrics —

All timestamps are deployment-side; runs are triggered in-deployment, so the CI runner and api.vercel.com sit outside every measured window. TTFS = start() → first step body (includes dispatch + any cold start); Fan-out TTFS/TTLS = first/last step completion of one Promise.all from the same anchor (the gap is the runtime’s fan-out spread); STSO/WO between step bodies. Streaming delivery performance is measured in durabench.

Cold starts stay in the numbers (real bursty-workload latency, inflates P75+); Best is the warm floor.

@benpankow
benpankow force-pushed the poc/conditional-run-ahead branch from 422b76d to fe978ae Compare November 20, 2026 23:41
observedHookIds: suspension.observedHookIds,
selfStepIds,
});
if (conditionalBoundary) boundaryRunAhead.conditional = true;

@vercel vercel Bot Nov 20, 2026 •

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.

A hook payload flushed from the live feed before strict refusal still triggers a false possibleLogCorruption error when parallel steps have outcomes pending.

Fix on Vercel

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
Framework Flow route Step reg. Framework output
hono 306.7 KiB (+8 B) 126.0 KiB (-89 B) 2.42 MiB (-5.6 KiB)
nextjs-turbopack 398.2 KiB (+9 B) 491 B (±0) 1.14 MiB (-3.6 KiB)
About these numbers

Sizes are gzip; parentheses show the change against main.
Flow route and Step reg. gate this job, on raw bytes rather than the gzip shown, at max(2%, 50.0 KiB). Framework output is informational.

c567316 · run

…ative writes

Signed-off-by: benpankow <ben.pankow@vercel.com>
… after a learned foreign slot, and hold bodies until their creation commits

Signed-off-by: benpankow <ben.pankow@vercel.com>
…is held; map event-slot-taken in world-vercel

Signed-off-by: benpankow <ben.pankow@vercel.com>
…sts catch a step running twice

Signed-off-by: benpankow <ben.pankow@vercel.com>
…; assert which refusal stops each strict test

Signed-off-by: benpankow <ben.pankow@vercel.com>
…nd strict writes in flight; narrow the hazard stand-down; align the slot-taken docs

Signed-off-by: benpankow <ben.pankow@vercel.com>
… strictEventCount conformance and run it on the test World

Signed-off-by: benpankow <ben.pankow@vercel.com>

This branch was successfully deployed

1 active deployment
Preview – workflow-docs — c567316a Deployed Nov 23, 2026 by vercel[bot]
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.

1 participant