Skip to content

[core] PoC: spec 9 run-ahead counts a wait as due only within the skew allowance - #5659

Draft
benpankow wants to merge 5 commits into
poc/in-band-only-abort-controllerfrom
poc/wait-due-horizon
Draft

benpankow wants to merge 5 commits into
poc/in-band-only-abort-controllerfrom
poc/wait-due-horizon

Conversation

@benpankow

@benpankow benpankow commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Proof of concept, stacked on #5658 (and #5657). This shows one way to implement proposal 3(b) from the research note, so the trade-off is concrete. Whether the full inline window is needed is for the Workflow team to decide: there may be a reason for it that we're missing.

What

At each spec 9 run-ahead boundary, an open wait now counts as due (path-changing) only if its resumeAt is at or before getRunAheadWaitWindowEndMs: min(now, inline deadline) plus the allowance, where the allowance is WORKFLOW_OPEN_WAIT_CLOCK_SKEW_MS (30s) floored at 1s (MIN_RUN_AHEAD_WAIT_ALLOWANCE_MS). In other words, now plus the allowance, capped at where the check used to end. Before, a wait counted if it fell anywhere in the invocation's inline window plus 30s. On Vercel, with maxDuration: "max", that window is 5 minutes from the invocation's start. The same change applies on node:vm and QuickJS.

Why

eve arms a 5-minute sandbox idle sleep() after a session goes idle. sleep() can't be cancelled, so the wait stays open into the next turn, and because it falls inside the inline window it blocks run-ahead at every step boundary for up to 5 minutes. Any app with a long timer open beside its steps hits the same thing.

On spec 9 only the orchestrator writes wait_completed, in-band, at the top of a pass. A wait that comes due after the writes in flight have committed is completed at a later pass, after them, so nothing out-of-band can land between speculative writes. The existing comment says a wait due within the window counts because "its completion is the orchestrator's own decision taken at the top of a pass, which run-ahead does not pipeline". This PoC reads that as requiring the wait to come due before the in-flight writes commit (milliseconds, so the 30s allowance is generous), not before the invocation ends. That reading is the thing to confirm.

The alternative, proposal 3(a), is a cancellable sleep(). It isn't prototyped, because it needs a new event type in every World and in workflow-server.

Review follow-ups

  • A wait coming due mid-run-ahead is now tested on both engines. A 1.3s unawaited sleep runs beside a 120-step loop. Run-ahead runs before the wait is due. Once it's due, the next boundary is classified as path-changing and drains. The orchestrator completes the wait in-band partway through the loop, and run-ahead resumes afterwards. There are no run-ahead stops and no possibleLogCorruption, and a cold replay matches. This is the empirical answer to the "top of a pass" concern. Whether it holds in every case is still for the team to confirm.
  • The comments match the code now. One helper computes the window for both engines, and its doc states the formula. The waitDue docs in out-of-band-observation.ts and the README no longer describe the old window.
  • Unit test for the window and its floor: getRunAheadWaitWindowEndMs is unit-tested without the real clock, so exact-boundary behavior no longer depends on timing. The OPEN_WAIT_CLOCK_SKEW_MS doc describes the new window. The mid-run-ahead test now reads corruption logs from console.error, which the run logger prints through. The <= comparison itself is still inline at the two call sites.
  • Flaky on loaded QuickJS: the mid-run-ahead test used a 1.3s wait, which left only 300ms of run-ahead before the wait counted as due. It now uses a 2.5s wait (1.5s of run-ahead) and loops until the wait completes, then 20 more steps, so a slow engine can't outrun it. I couldn't reproduce the flake on a 15-core machine with every core busy (old or new test), so this widens the margin rather than proving a fix.
  • Docs: the window doc now says that past the inline deadline the window stops moving, so a wait due after its end isn't counted, as before. The skew constant and observation docs say spec 8 still uses the old window. The changeset mentions the 1s floor and the cap.
  • Safety argument, made consistent: on spec 9 only an orchestrator writes wait_completed, in-band. A wait coming due mid-run-ahead is completed after the writes in flight, or by its timer's delivery, which the fence orders against this one. So the window, the 1s floor included, decides cost (a fenced redelivery or a late completion), not correctness. The constant, floor and observation docs now all say that.
  • Biome: fixed the import order in spec9/delivery.ts.
  • Not changed: this changes the default for all spec 9 runs, with no flag. Putting it behind an opt-in is easy if the team prefers that.
  • The allowance now has a lower bound. With the old window, a skew of 0 still left minutes; with the new one it would have meant "now". The allowance is floored at 1s.

How did you test your changes?

  • run-ahead.runtime.test.ts: a new test with a wait due in 90s, which is inside the inline window but past the skew allowance. It now runs ahead on both engines. It fails without the change, and passes with it.
  • The existing "drains with a wait due within the invocation (1s)" test still drains.
  • src/runtime/spec9 and out-of-band-observation.test.ts all pass (971 tests).
  • The spec 9 README and the out-of-band-observation.ts comment are updated.

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

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

This PR includes changesets to release 18 packages
Name Type
@workflow/core 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/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch
@workflow/world-vercel 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

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

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

  • awaitChildReturnValueWorkflow - parent waits on the child-run completion hook (fail: true) (nextjs-webpack · local-postgres / postgres / quickjs / 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:49:42Z · abandoned wrun_01M801BVV88KV6J14539DJHM60
  • cold-start-warmup · suite warmup (tanstack-start) · at 21:49:54Z · abandoned wrun_01M801BVXD43PSF02HKZSYNRQR

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

@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

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

❌ The benchmark run for 2193965 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.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
Framework Flow route Step reg. Framework output
hono 306.6 KiB (±0) 126.0 KiB (-89 B) 2.41 MiB (-8.0 KiB)
nextjs-turbopack 398.2 KiB (±0) 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.

2193965 · run

…w allowance

Signed-off-by: benpankow <ben.pankow@vercel.com>
…test a wait coming due mid-run-ahead

Signed-off-by: benpankow <ben.pankow@vercel.com>
…t the skew doc; catch corruption logs in the mid-run-ahead wait test

Signed-off-by: benpankow <ben.pankow@vercel.com>
… correct the wait window docs and changeset

Signed-off-by: benpankow <ben.pankow@vercel.com>
…decides cost, not correctness

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

This branch was successfully deployed

1 active deployment
Preview – workflow-docs — 2193965f 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