Commit Graph

1667 Commits

Author SHA1 Message Date
Cursor Agent e105c6e168 docs: add Cursor Cloud environment setup notes to AGENTS.md 2026-08-18 21:47:16 +00:00
Peter Wielander 04e060a0ec [world] Add WORKFLOW_NODE_HTTP to run the HTTP Worlds on node:http (#3461) 2026-08-18 14:31:08 -07:00
Peter Wielander 707dfe6a06 [core] Pin draw order to event-log order: retire delivery barriers through one ordered dispenser (#3554) 2026-08-18 14:07:21 -07:00
Alex Langenfeld 09c51d8a16 [e2e] Shrink fibonacciWorkflow's run tree from fib(6) to fib(5) (#3619)
fib(6) spawns a 25-run tree whose ~24 concurrent parent polls saturate
the workflow scheduler past the test's 180s budget under a concurrent
suite (#2083 measured this as one of the three flake classes blocking
e2e concurrency re-enablement). fib(5)'s 15-run tree still exercises
the test's actual subject - recursive start() composition with parallel
children at every level - with 40% less peak load.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-18 15:47:39 -05:00
Alex Langenfeld fb6f2654ac [e2e] Assert only the positive direction of step source maps (#3620)
Where hasStepSourceMaps() reports maps unsupported, the tests asserted
their absence - but on some lanes (nuxt, nextjs-webpack) source maps
apply nondeterministically, so the negative assertion pinned that
nondeterminism as a flake (#2083 measured this as one of the three
flake classes blocking e2e concurrency re-enablement). A stack that
resolves to source where none was promised is an improvement, not a
failure; hasStepSourceMaps() remains the record to update when a lane
starts mapping reliably, verified by the positive assertions on the
lanes it does promise.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-18 15:47:27 -05:00
Alex Langenfeld 916fcf0833 [next] Let HMR log readers tell quiet from rebuild-in-flight (#3589)
The dev HMR log line for a rebuild is written at classification time,
before the (potentially multi-second) rebuild runs. A reader counting
lines in a window has no way to tell 'quiet' from 'rebuild in flight
with queued events behind it', and the e2e HMR tests count lines in
exact windows: on CI, where rebuilds take 5-12s, a write from a
previous test case (or a teardown restore) can still be rebuilding when
the next window opens, and its legitimate rebuild lines land inside
that window - observed on main as the fuzz test failing both retry
attempts with 'expected 2 to be 1'.

The dev server now also logs 'workflow dev hmr: rebuild complete' when
a rebuild finishes processing (in a finally, so an erroring rebuild
cannot wedge readers; behind WORKFLOW_DEV_HMR_LOGS like every hmr
line). The e2e suite uses it to drain to quiescence - every started
rebuild completed, plus a short quiet window covering watcher latency
and the flush debounce - before taking a log cursor. Every cursor call
site writes only after taking its cursor, so draining there cannot
swallow lines a test means to count.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-18 15:07:40 -05:00
Alex Langenfeld 880801bd45 Stamp request provenance on step starts (#3567)
## Summary & Motivation

`step_started` now carries the invocation's request ID alongside the
compute instance ID, so observability can show both dimensions of where
an attempt ran. The two stay independent fields — world-vercel maps
`requestId` onto its analytics `vercelId`, which the compute instance ID
doesn't stand in for.

## Test Plan

Unit tests added for the stamping on all three step-start paths,
including when no request ID is available.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-18 13:21:36 -05:00
Shalabh Chaturvedi ac51658d39 [core] Record step execution duration metric (#3526)
## Summary
- record `workflow.step.execute.duration` as an OpenTelemetry histogram
around the inner user-code step span
- rely on resource `service.name` for the service dimension and add only
a bounded status attribute
- cover the histogram name, unit, and attributes with a focused unit
test

## Validation
- `pnpm exec vitest run packages/core/src/telemetry-metrics.test.ts`
- `pnpm --filter @workflow/core typecheck`

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-08-17 14:49:39 -07:00
Alex Langenfeld df0103bc3c Document stream reader request cancellation (#3581)
## Summary & Motivation

The earlier timeout-docs attempt in #534 was closed without merging.
Without `supportsCancellation`, a browser disconnect leaves the stream
reader reconnecting until the function hits
`FUNCTION_INVOCATION_TIMEOUT`, so the streaming guide now documents the
`vercel.json` opt-in, with a warning that it terminates everything
matching the configured path, and the resumable-streams guide points at
it.

## Test Plan

Docs only; no tests.


## Docs Preview

| Page | v4 | v5 |
| --- | --- | --- |
| Streaming |
[Preview](https://workflow-docs-git-alangenfeld-timeout-docs.vercel.sh/docs/foundations/streaming#avoiding-function-timeouts-after-client-disconnects)
|
[Preview](https://workflow-docs-git-alangenfeld-timeout-docs.vercel.sh/v5/docs/foundations/streaming#avoiding-function-timeouts-after-client-disconnects)
|
| Resumable Streams |
[Preview](https://workflow-docs-git-alangenfeld-timeout-docs.vercel.sh/docs/ai/resumable-streams)
|
[Preview](https://workflow-docs-git-alangenfeld-timeout-docs.vercel.sh/v5/docs/ai/resumable-streams)
|

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-17 13:04:11 -05:00
Alex Langenfeld c5f9177be3 Verify stream completion on clean EOF in the reconnecting framed reader (#3564)
## Summary & Motivation

Long live reads were ending silently at the server's 2-minute connection
cap: the max-duration abort reaches the client as a clean EOF on some
transport paths, and the reader read that as end-of-stream. On EOF it
now consults `streams.getInfo` and reconnects from the next chunk unless
the stream is done and every chunk up to the tail was delivered. A
failed metadata read trusts the EOF, so a transient blip can't fail a
healthy completion.

## Test Plan

Tests added for the reconnect, verified-completion, metadata-failure,
and reconnect-budget paths.

---------

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-17 12:58:27 -05:00
Pranay Prakash 64b8866140 [ci] Bump Next.js canary e2e pin to 16.3.1-canary.17 (#3559)
## Summary & Motivation

The canary e2e lanes (E2E Local Dev / Local Prod / Local Postgres for
`nextjs-turbopack` and `nextjs-webpack`, × node/quickjs) were pinned to
`16.3.0-canary.2`. This bumps the pin to the current canary,
`16.3.1-canary.17`, in all six spots in `tests.yml`.

Bumping the pin alone is not enough: fresh Next canaries are younger
than the repo's 48h `minimumReleaseAge` gate, so the "Setup canary"
`pnpm install --no-frozen-lockfile` fails with
`ERR_PNPM_NO_MATURE_MATCHING_VERSION` (reproduced locally with this
exact version). This adds `next` and its lockstep-published `@next/*`
companion packages (`@next/env`, `@next/swc-*`) to
`minimumReleaseAgeExclude` — both are Vercel-published, matching the
trust model of the existing exclusions (`@vercel/*`, `turbo`,
`esbuild`).

## Validation

The full e2e suite was run locally against `next@16.3.1-canary.17` on
all three worlds (staged tarball workbenches, same as CI's
`prepare-workbench-path`):

| World | App / mode | Result |
| --- | --- | --- |
| `world-local` | nextjs-webpack, dev server, node vm | `dev.test.ts` 5
passed / 4 skipped (incl. the HMR fuzz test) · `test:e2e` 137 passed /
19 skipped |
| `world-postgres` | nextjs-turbopack, prod build, node vm |
`local-build.test.ts` 13 passed · `test:e2e` 137 passed / 19 skipped¹ |
| `world-vercel` | nextjs-turbopack, preview deployment
(`dpl_3siALD2WyrsrdPFjmRY3ymwEHZiJ`), node vm | `test:e2e` 134 passed /
22 skipped |

¹ First pass failed the 3 `pages router` tests because the local harness
ran `local-build.test.ts` without `CI=true`, which deletes the
`workflow-sourcemap-warning-fixture` package the built output still
references (the test preserves it only when `CI=true`, exactly as its
comment warns). With the fixture preserved, all 3 pass. Not a canary
issue.

Note: the vercel world has no canary lane in CI (deployments build from
the committed stable pin), so the preview-deployment run above is the
only canary coverage it got.

## Context on current `main` CI

Recent `main` runs are red, but not because of the canary pin: the
dominant failure is the nextjs-webpack local-dev HMR fuzz race
(SDK-side, fix in flight in #3529), which hits the stable and canary
lanes alike; the rest are the known rotating vercel-prod flakes. The
latest completed `main` run (with #3530's e2e retry) passed every canary
lane and failed only the *stable* webpack dev lane.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 10:37:05 -07:00
Shalabh Chaturvedi ec709ba533 [world-sim] Remove mint-ordered log (#3544)
Since we're moving to server side serialized ids, we dont need to
simulate the prior model.

## Summary
- remove the mint-ordered simulation mode and reservation API
- make commit-time log positions and lagging-prefix reads the only
simulator behavior
- simplify CI, scenarios, tests, and documentation to the single log
model

## Testing
- node --check on changed TypeScript files
- pnpm --filter @workflow/world-sim test (blocked: node_modules is
absent; vitest unavailable)

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-08-17 10:35:41 -07:00
Pranay Prakash b0adb50bce feat(world,world-vercel): createBatch — ordered batch event write with per-event results (#3025)
## createBatch: the client half of the v4 batch event write (per-event
results, no fence)

> **Note:** this PR was rebuilt from scratch. The previous revision
implemented the retired "v2 suspension fence" design
(`expectedRunVersion` / `batchId` / `logicalCreatedAt`, a
grammar-validated collect mode, world-postgres migration 0016,
world-local claim machinery). The server redesigned its endpoint in
place (vercel/workflow-server#646, merged and deployed) and this branch
now targets that contract on top of current `main` (specVersion 6 slot
identity). The old head is tagged `batch-client-v2-fence-design`; prior
review threads reference deleted code.

### The server contract this targets

`POST /api/v4/runs/:runId/events/batch` (workflow-server#646): an
**ordered** list of v4 frames — byte-identical to single-event POST
frames, **no batch-level meta** — committed in one DynamoDB transaction
per attempt, answered with HTTP 200 + `{ results }`: one entry per
frame, in request order. Each event reports what its own single POST
would have returned: `200` + the materialized entity, or the single-path
status/code (e.g. `409`/`conflict` for an event an earlier delivery
already applied). A transport retry of a committed batch converges to
all-409s with nothing written twice — idempotency comes from per-entity
conditions, not batch bookkeeping. Slot-identity runs only (specVersion
≥ 6 — what `world-vercel` stamps on every new run since #3389).

### What this revision ships

1. **`@workflow/world` — the spec addition.** `Storage['events']` gains
one optional method; **method presence is the capability declaration**
(no capability flag, no stub required):

```ts
createBatch?(
  runId: string,
  events: BatchEventRequest[],
  params?: CreateEventBatchParams
): Promise<EventBatchResult>;

interface BatchEventRequest {
  event: CreateEventRequest;   // same discriminated union as the single create
  occurredAt?: Date;           // under slot identity: the source of the durable createdAt
}

type BatchEventItemResult =    // one per submitted event, in request order
  | { status: 200; event: Event; run?: WorkflowRun; step?: Step; wait?: Wait }
  | { status: number; error: string; message: string };

interface EventBatchResult { results: BatchEventItemResult[] }
```

Contract: **ordered** (events land in the log in request order),
**per-event outcomes** (each event reports what its own single `create`
would have returned — success discriminated by `error === undefined`),
**idempotent on retry** (per-entity conditions make a retried committed
batch converge to per-event 409s). Worlds that don't implement it keep
the single-event path. `world-local` and `world-postgres` deliberately
do NOT implement it — batching a local/in-process write buys nothing
(this deletes the old revision's riskiest surface: the hand-written
postgres migration and the world-local claim machinery).
2. **`@workflow/world-vercel`** — the wire adapter: per-event frames
concatenated in order (reusing the single-frame encoder; each frame
carries its own `occurredAt`, which under slot identity is the source of
the durable `createdAt` — this natively closes the replay-clock question
the old `logicalCreatedAt` field existed for), CBOR `{ results }`
decoded against the **same per-type zod schemas as the single POST**,
loud `SCHEMA_VALIDATION` on any malformed response (wrong length,
invalid item), and the standard typed error mapping for request-level
failures.
3. **Retry policy** — a `batchIdempotent` override in the event-retry
eligibility machinery: the whole batch POST retries transient transport
failures/5xx (and waits out 429 `Retry-After` per #3504) regardless of
the contained event types, because per-event entity conditions make the
retry converge; the per-type non-retryability matrix guards *single*
posts (where e.g. a retried bare `step_started` would increment
`attempt`) and doesn't apply inside a batch.

Tests: 7 wire tests — frame encoding/ordering + **no fence fields on the
wire**, per-event result mapping (successes typed, failures passed
through), malformed-response failures (length mismatch, invalid item
body with index), typed request-level 400s, in-process 5xx retry,
empty-batch guard — plus 9 suspension-handler tests for the runtime
fold: ordering (steps then waits), per-event 409 tolerance, non-409
failure propagation, every gate exclusion (flag off / no `createBatch` /
pre-slot run / hook writes), 32-cap chunking, and lazy-inline exclusion.
Full `world-vercel` suite: 508 passed; full `@workflow/core` suite: 2126
passed.

### The runtime integration: batched suspension fan-out (ON by default)

The suspension handler folds a **clean fan-out** — the suspension's
eager `step_created` + `wait_created` writes — into `createBatch` calls
of at most **32 events**, and uses the batch endpoint **exactly when two
or more batchable eager events exist**: a lone eager event takes the
ordinary single write (same round trip, and it keeps the slot-snapshot +
bump-and-report the single path provides) (mirroring the server's
transaction budgets: 2 items/event against the 100-item cap, 768 KB
inline-byte budget; larger fan-outs commit in successive batches). The
gate requires: World implements `createBatch` ∧ run on slot identity
(specVersion ≥ 6) ∧ no attribute writes ∧ no hook writes ∧ no resilient
step dispatch. **Everything outside the gate keeps the single-event path
byte-for-byte**, and lazy-inline steps keep deferring their
`step_created` to the lazy start exactly as before.

Per-event semantics mirror the single path: a `409` is the same
already-exists tolerance as `EntityConflictError` (the conflicted step
is not marked owned); any other per-event failure fails the suspension
write the way a single-path rejection would. Slot bumps (the batch
endpoint has no bump-and-report) are tolerated and logged — the same
accepted exposure as a dropped truncated skipped-slot report on the
single path.

**On by default**, with the `WORKFLOW_TURBO`-shaped kill switch as the
operator escape hatch: **`WORKFLOW_BATCH_TRANSITIONS=0`** (or `false`)
disables batching and restores the exact prior one-write-per-event path.
Documented in the worlds configuration reference and the changelog
entry. Burn-in watch: the `event_batch`-tagged slot-conflict metrics and
DynamoDB throttle monitors on the server side.

### Docs

- New v5 changelog entry **`changelog/batched-event-writes`**
documenting the World spec addition (full `createBatch` signature +
contract — the signature block is compile-checked against
`@workflow/world` by the docs code-sample checker), the runtime fold,
and the follow-up.
- `configuration/worlds` gains the **`WORKFLOW_BATCH_TRANSITIONS`**
reference entry: default on, `=0`/`false` as the documented escape
hatch.

### Staged follow-up: the deferred sequential transition (the STSO win)

Hold `step_completed(N)` across the replay turn and commit
`[step_completed(N), step_created(N+1), step_started(N+1)]` as one batch
at the next lazy start (the server folds the pair born-running). This
needs the synthetic-completion replay machinery rebuilt against today's
runtime (parallel inline batches, turbo's run-ready barrier, optimistic
starts, slot bookkeeping) — it stays a separate PR so the SDK's most
sensitive replay path gets its own focused review. Its acceptance
criteria are already agreed: the runtime eligibility matrix as unit
tests, and an e2e that asserts ≥1 POST to `/events/batch` and **zero**
single-event POSTs for the batched transitions.

### Compatibility

- Old servers: no `/batch` route → 404/405 → callers fall back to
single-event posts (the runtime PRs will latch this per run).
- Pre-slot runs: request-level 400 (`batch-requires-slot-identity`) →
same fallback.
- No `WORKFLOW_SERVER_URL_OVERRIDE` pin this time — the server endpoint
is merged and deployed to production.

Refs: vercel/workflow-server#646 (endpoint), vercel/workflow-server#780
(unbatchable-types design space), #3389 (slot identity), #3504 (429
retry).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-14 17:42:33 -07:00
Peter Wielander 1321570464 [docs] Document duplicate-event handling, and describe webhook token generation accurately (#3497) 2026-08-14 16:00:21 -07:00
Alex Langenfeld ae1637502b [next] Fix dev HMR dropping edits that race a full rediscovery rebuild (#3529)
## Summary & Motivation

A full rebuild reads sources twice — once when the bundler consumes
them, once when the classifier baseline is refreshed from disk
afterwards — so an edit landing in between was absorbed into the
baseline without being built, and its queued watcher event classified as
a no-op. `pinBaselinesAcrossFullRebuild` pins baselines across the
rebuild instead: pre-build values for files present in both maps, and
the snapshots `classifyRebuild` read for the files that triggered the
rebuild, so routine duplicate watcher events still diff equal rather
than cascading into another full rebuild.

This is the largest ongoing CI flake — the nextjs-webpack local-dev e2e
HMR fuzz test writes a step definition right after triggering a
rediscovery and times out at 300s when the write lands mid-rebuild (~60
attempt-1 job failures in 10 days). For files the in-flight rebuild
discovered for the first time this narrows a create-then-edit race
rather than closing it; the initial-build startup window has the same
shape and is out of scope, documented at the call site.

## Test Plan

Unit tests cover the absorb race and the duplicate-event no-op; the
previously-flaky HMR fuzz e2e passed 3/3 locally against nextjs-webpack
where main reproduced the manifest drop, and a mid-rediscovery edit rig
went from 2/6 dropped on base to 0/6.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-14 17:55:39 -05:00
Alex Langenfeld 234d3dd7b8 [core] Replace never-picked-up e2e runs instead of failing whole tests (#3560)
## Summary & Motivation

The e2e `start()` wrappers now poll the new run until it leaves
`pending`. A run still pending after `WORKFLOW_E2E_PICKUP_BUDGET_MS`
(default 15s) has executed no workflow code, so it is abandoned and
replaced in place and the test continues — one replacement, with the
CI-level retry still the backstop if that one stalls too.

Each replacement is recorded to an `e2e-infra-*.json` sidecar that every
e2e job uploads, and the aggregation script renders it as an "Infra
Events" section in the step summary and PR comment, so clustered
timestamps read as a backend blip rather than as unrelated flaky tests.

## Test Plan

Unit tests cover the pickup watchdog; a local nextjs-turbopack run
exercised both the clean path and, with a forced 1ms budget, the
replacement path end to end, and the aggregation script was smoke-tested
against synthetic sidecars in both modes.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-14 16:48:08 -05:00
Fantix King 09b299a03e [e2e] Add Python e2e Test (#3369)
Turns `packages/core/e2e/e2e.test.ts` into a cross-language conformance
suite and adds `workbench/python` as its first non-JavaScript subject.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 16:56:05 -04:00
Alex Langenfeld af91cc2582 bench: per-chunk stream latency (CRTT/CDV) and replay-driven stream scenarios (#3393)
## Summary & Motivation

- **CRTT (chunk round-trip time)** — per-chunk write→read latency for a
paced stream, aggregated inside the reader step on the deployment (one
clock domain) into a fixed log-bin histogram plus index buckets and
mean-RTT profiles over stream progress and chunk size. Fills the gap
between SL (first chunk only) and SO (whole-stream throughput), where a
mid-stream delivery regression was invisible. It is deliberately a
*round*-trip name: the future production one-way write→read metric is
CTT, with its own skew caveats.
- **CDV (chunk delay variation)** — inter-arrival gap minus inter-write
gap per seq-adjacent pair, so each gap subtracts same-clock stamps and
the stat stays skew-free and measurable in production later. Reported as
each run's max positive value, since a 1-in-300 delivery stall dilutes
out of pooled percentiles.
- **Replay scenarios** — two real captured cadences (eve envelope
protocol via gpt-5.6-sol; raw gateway SSE via gpt-5.4-nano) replayed
through the same rig on an absolute open-loop schedule, so the workload
is measured rather than invented; the 2x speed multiplier is the only
chosen number, and matches how real fast-tier models behave (same chunk
sizes, compressed time). Each capture carries a semantic sha256 over
canonical `(offsetMs, bytes)` tuples so durabench's independent copy can
be checked for drift.
- **Streams table** — stream scenarios render in their own table with
writer/reader sustained rates, CRTT percentiles, and median worst stall.
No pass/fail targets yet: numbers and vs-main deltas only.
- **SL/SO report rows retired** — CRTT's seq-0 slice reproduces SL and
its aggregate reproduces SO's signal at ~100x the samples; write slip
stays as artifact-only data, the only guard for producer stalls that
neither CRTT nor CDV can see.

## Test Plan

- [x] Unit tests for the bucketing/merge/CDV helpers and the renderer;
the full benchmarks job ran green against real preview deployments, and
the first Streams numbers separated workload strain (eve 2x: read 173 <
write 181 c/s, CRTT p75 1278ms) from the transport floor (the paced
control and the 1x reality row both clean).

---------

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-14 15:53:11 -05:00
github-actions[bot] df1c7f1969 Version Packages (beta) (#3466) workflow@5.0.0-beta.42 2026-08-14 11:42:17 -07:00
Peter Wielander f5591aa278 [e2e] Fix event-log-race-repro for local/postgres (#3558) 2026-08-14 11:34:29 -07:00
Shalabh Chaturvedi 63cc09e24f feat(world-vercel): enrich STSO event spans (#3536)
Enrich the existing v4 event-write `http POST` **CLIENT** span. No new
span is created.

The modified span is emitted by HTTP event writes through `fetchV4` /
`instrumentedFetch` and WebSocket event writes through the existing
synthetic parity span in `postEventFrameOverWs` / `withHttpClientSpan`.

## Added attributes

- `workflow.client.version` on every v4 event write, formatted as
`@workflow/world-vercel/<version>`
- `step.stso_ms` when the event input carries step-to-step overhead
telemetry
- `step.latency_optimizations` when the event input carries the active
runtime optimization list, such as `lazyStepStart`, `turbo`, and
`optimisticStart`

The span already inherits the client application OTEL `service.name` and
carries the event type, transport, URL, and status. The added fields
allow sampled STSO analysis by client service, Workflow SDK version, and
runtime mode on one span.

## Validation

- Dependency-aware `@workflow/world-vercel` build
- `ws-transport-spans.test.ts`: 13 tests passed
- `@workflow/world-vercel` typecheck
- Biome and `git diff --check`

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-08-14 11:33:51 -07:00
Alex Langenfeld 60dd2065f3 [core] Fix flaky timing-sensitive tests: events-consumer deferred-check budgets and TTL-expiration e2e timeout (#3531)
* [core] Give events-consumer deferred-check tests a stall-proof budget

The 'duplicate event classes' tests reach their outcome through the
deferred check's multi-stage timer chain (promise queue -> setTimeout(0)
-> idle poll -> delay timer), which a loaded CI runner with coarse
timers can starve for whole seconds. The afterDeferredCheck poll capped
that at 2s and two follow-up assertions used vi.waitFor's 1s default,
inside the 5s default test timeout - regularly starved through on
Windows runners ('does not track hook deliveries' and 'leaves a
duplicate run_cancelled' flaked ~1.5x/day over the last 10 days,
failing with strandedEvent/parkedSummary still undefined).

The polls return as soon as their assertions hold, so raising the poll
timeout to 15s and the suite budget to 30s costs healthy runs nothing
while bounding only genuinely stalled runners.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>

* [core] Match the TTL-expiration abort e2e test budget to its siblings

The other distributedAbortController tests run with a 60s budget; the
TTL-expiration one got 30s. Its 3s TTL is trivial, but on a fresh prod
deployment cold starts plus queue backlog routinely push run start +
first stream delivery past 30s - it timed out on two apps
simultaneously in a single Tests run over the last week.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>

* Add changeset

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>

---------

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-14 13:24:26 -05:00
Peter Wielander 0c5a6495bc [ci] Report all three event-log-race-repro lanes in one small PR comment (#3556) 2026-08-14 10:59:00 -07:00
Andrew Barba 3560218937 fix(core): preserve order across adjacent hook deliveries (#3552)
Signed-off-by: Andrew Barba <barba@hey.com>
2026-08-14 10:51:22 -07:00
Peter Wielander de2a86c61c [world] Make spec version 6 the current version (#3542) 2026-08-14 10:22:21 -07:00
Alex Langenfeld c041d3d231 [ci] Retry e2e tests once in CI, keeping retried tests visible (#3530)
* [ci] Retry e2e tests once in CI, keeping retried tests visible

Over the last 10 days ~93 Tests runs were manually re-run until green,
some taking 6 attempts: the e2e suites drive real deployments, and a
single test losing a timing race fails a whole 20+ minute matrix job.
A CI-only vitest retry (retry: 1) absorbs those single-test races.
beforeEach/afterEach hooks run per attempt, so suites with file-restore
hooks (dev.test.ts) retry cleanly.

Retries must not hide real races, so a retried-then-passed test stays
visible everywhere a failure would have been: the github-reporter emits
::warning annotations and an e2e-flaky-*.json sidecar, every e2e job
uploads it, and aggregate-e2e-results.js renders a 'Flaky E2E Tests
(passed on retry)' section in both the per-job step summary and the PR
comment, with per-app occurrence counts.

Harnesses whose failures are themselves the signal pin retry: 0:
event-log-race-repro (a pass runs the full configured budget) and
benchmarks (a regression should not be papered over by a luckier
second sample). Local runs keep retry at 0 so races reproduce while
debugging.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>

* Add changeset

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>

---------

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-14 12:08:41 -05:00
Peter Wielander dc85865718 [core] Drop pre-slot event ID support and preconditionGuard capability (#3519) 2026-08-13 15:57:28 -07:00
Peter Wielander 834d1f945f [web-shared] Mark ignored duplicate events in the observability UI (#3467) 2026-08-13 12:07:13 -07:00
Nathan Rajlich 8d8b7b3845 [world-vercel] Retry throttled (429) event writes in-process, honoring Retry-After (#3504) 2026-08-13 18:33:36 +00:00
Peter Wielander 0b7c9671ee [bench] Add a Promise.all fan-out scenario with Fan-out TTFS/TTLS rows (#3522) 2026-08-13 11:00:50 -07:00
Peter Wielander 3450c867f6 [core] Poll for the deferred check instead of sleeping past it (#3507) 2026-08-13 08:58:58 -07:00
Shalabh Chaturvedi 01991edeeb feat(world-vercel): synthesize per-event client spans on the WS transport (#3452)
* feat(world-vercel): synthesize per-event client spans on the WS transport

PR #3084 added the opt-in `WORKFLOW_EVENTS_TRANSPORT=ws` path and listed
"no client-side span on the WS path" as a known limitation. Because event
writes become multiplexed frames on one long-lived socket rather than
individual `fetch` calls, the per-event `http POST` CLIENT span that the
HTTP transport produced simply disappeared — traces went from one span
per event to nothing between the invocation and the server.

Restore it by synthesizing a request-shaped span around each frame, and
give the upgrade its own span:

- Extract `withHttpClientSpan` / `recordClientSpanStatus` from
  `instrumentedFetch` in `http-core.ts` so the synthetic span is emitted
  by the same envelope as the real one and cannot drift from it.
  `InstrumentedFetchOptions` now extends `HttpClientSpanOptions`.
- `postEventFrameOverWs` opens `http POST` with `url.full` pointing at the
  v4 REST endpoint the frame is forwarded into, so per-event traces and
  latency dashboards keep working across the flag. Extract `eventsV4Url`
  so that URL cannot drift from the one the HTTP path actually requests.
- Tag both transports with `workflow.events.transport` (`http` | `ws`) and
  `workflow.event.type`; the WS path additionally sets
  `network.protocol.name=websocket`, `workflow.events.ws.url` (the real
  wire destination) and `workflow.events.ws.req_id` (join key to the
  server's log line for the frame), so the span is never mistaken for a
  real HTTP request.
- Add a `workflow.events.ws.connect` span around the upgrade — the one
  genuinely-HTTP request here, previously the invisible half of every WS
  write's latency — carrying `workflow.events.ws.reconnect_attempt`. This
  also puts `resolveUpgradeHeaders`' trace-context injection inside a
  client span, as AGENTS.md requires.
- Fix `parseServer` to treat `wss:` as TLS (port 443, not 80).

Out of scope, deliberately: per-frame `traceparent` (needs a frame-meta
field plus a server change) and Vercel's outgoing-requests view (that
instruments global `fetch`, so a frame structurally cannot appear there).

Covered by `ws-transport-spans.test.ts`, which drives the real selection +
transport + adapter stack over a fake socket and asserts span shape,
failure reporting, retry behaviour and HTTP/WS parity.

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

Co-Authored-By: shalabhchaturvedi-7802 <shalabh.chaturvedi@vercel.com>

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* chore: trim WS spans changeset to the user-facing summary

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

Co-Authored-By: shalabhchaturvedi-7802 <shalabh.chaturvedi@vercel.com>

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* fix(world-vercel): only tag event-write spans with transport

Signed-off-by: Shalabh Chaturvedi <shalabh.chaturvedi@vercel.com>

Co-Authored-By: shalabhchaturvedi-7802 <shalabh.chaturvedi@vercel.com>

* fix(world-vercel): format WS transport span regression test

Signed-off-by: Shalabh Chaturvedi <shalabh.chaturvedi@vercel.com>

Co-Authored-By: Shalabh Chaturvedi <shalabh.chaturvedi@vercel.com>

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-08-13 00:06:59 -07:00
Karthik Kalyan f1ef0cbf03 Deprecate world.runs.list for observability (#3404)
* Deprecate storage run listing for observability

* Document analytics run listing guidance
2026-08-12 14:36:21 -07:00
Peter Wielander 0f4b35f629 [world-local] Fix CORRUPTED_EVENT_LOG from hook-resume staging slot holes (#3492) 2026-08-12 13:16:42 -07:00
Peter Wielander 8931bee41b [world-local] Give the complete-preload test a budget the Windows runner can meet (#3503) 2026-08-12 13:09:35 -07:00
Peter Wielander b589460ce8 [core] Report the replay position on every event write (#3479) 2026-08-12 13:08:18 -07:00
Mitul Shah 14b52ac04b [1/4] Replace shared observability component styles with Tailwind (#3295)
* Replace hard-coded UI styles with Tailwind

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

* Update Tailwind migration verification

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

* Remove documentation changes from style migration

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

* Split trace, graph, and workbench style changes

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

---------

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mitul-s <19615826+mitul-s@users.noreply.github.com>
2026-08-12 19:13:39 +00:00
Karthik Kalyan a0ccfe0f50 feat(core): measure hook-triggered time to resume (#3437)
Report end-to-end TTR for a hook resumption — entry into the public resume
API through to the first line of the next durable step — on that step's
`step.execute` span, decomposed into non-overlapping phases that sum
exactly to the total:

  workflow.resume.total_ms
  workflow.resume.phase.{producer_prep,queue_delivery,resume_setup,
                         replay,step_dispatch,step_claim,step_prepare}_ms

dimensioned by trigger, dispatch strategy, setup source, and whether the
step ran inline or was dispatched to another invocation.

T0 is stamped by whichever public entry point the caller used, so
`resumeWebhook` — which does its own by-token lookup and key resolution
before reaching the shared implementation — measures the same window as
`resumeHook` rather than a systematically shorter one. T7 is taken inside
`contextStorage.run`, immediately before `stepFn.apply()`, so the
`step_prepare` phase covers the step-context setup it is defined to cover.

`resumeHook()` puts the producer boundaries on an optional
`hookResumeTiming` field on the queue message (both dispatch paths); the
consuming invocation adds its own and hands them to the execution that
will actually ATTEMPT the next durable step. That decision is made against
the dispatch loop's own classification, so an owned-recovery step keeps
the measurement here instead of it riding off on a queued sibling, and a
step converted into a delayed backstop wake — which this delivery does not
attempt — never takes it. Within an inline batch the tracking is shared
and a one-shot latch picks the single step that reaches user code, so the
sample survives the batch's first step losing its create-claim. A
deployment-affinity re-route forwards the timing untouched, keeping the
wasted hop inside `queue_delivery`.

The field is optional in every direction (new producer/old consumer, new
consumer/old message, no workflow-server change) and parses with
`.catch(undefined)` so a malformed value can never fail a delivery. A
sample is emitted only when every required boundary is present, finite,
and monotonic — a skewed or incomplete set is dropped rather than
reported as a negative phase.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 11:14:03 -07:00
Peter Wielander efbc408c4e [core] Ignore duplicate events per event class instead of failing the run (#3381) 2026-08-12 09:16:59 -07:00
Alex Langenfeld 600b096d2f feat(world): batch analytics event lookups (#3390)
## Summary & Motivation

Adds `events.getMany` to the analytics API, letting dashboard consumers
enrich canonical event pages with ClickHouse provenance in one bounded,
deduplicated batch request instead of N point lookups. Coordinated with
a workflow-server batch endpoint.

## Test Plan

Added unit tests for the client and schema; also ran Biome checks, `git
diff --check`, and world-vercel typecheck.

Signed-off-by: Alex Langenfeld <alex.langenfeld@vercel.com>
2026-08-12 08:56:54 -05:00
Nathan Colosimo 9add9d782d Bound decoded sparse-array lengths (#3462)
## Summary

- reject compact sparse arrays above the supported logical length at the
main devalue hydration boundary
- delegate accepted sparse-array construction to devalue
- cover both current binary payloads and legacy flattened payloads

## Why

Compact sparse-array encodings can represent a logical length that is
disproportionate to the stored payload. Applying one codec-level bound
keeps hydration predictable before downstream consumers process the
decoded value.

## Impact

Compact sparse arrays with logical lengths above 100,000 now fail
hydration with a `RangeError`. Other payloads are unchanged.

## Verification

- `pnpm --filter @workflow/core test` — 2,023 passed, 3 expected
failures
- `pnpm --filter @workflow/core typecheck`
- `pnpm --filter @workflow/core build`
- focused serialization suite — 154 passed
- direct root-argument, bound-step, and aggregate-error payload checks
- reuse, quality, and efficiency review
2026-08-11 13:27:12 -07:00
Alex Langenfeld c1a5c74edb fix(streams): surface typed retention expiry errors (#3410)
## Summary & Motivation

Adds `StreamExpiredError` to `@workflow/errors`, carrying the run, stream, and server-reported expiry timestamp from workflow-server's 410 `stream-expired` envelope. The reconnect loop rethrows it instead of retrying, since retention expiry is terminal and a retry budget would only convert it into a generic exhaustion error.

## Test Plan

Unit tests added for the 410 decoding path and the reconnect rethrow; typechecks pass across the touched packages.
2026-08-11 14:52:38 -05:00
Nathan Rajlich 7683130461 Resilient step dispatch: parallelize step_created writes with queue publishes (#3365)
* feat(world,world-vercel,core): resilient step dispatch (parallel step_created + queue publish)

Newly created steps are handed to the queue in parallel with their
step_created event write, with the serialized input carried on the
message (stepInput) so the queue consumer can idempotently re-ensure
the event when the direct write failed transiently — mirroring
resilient start (runInput) and resilient hook resume (hookInput).

- @workflow/world: stepInput on WorkflowInvokePayload,
  CreateEventParams.viaStepDispatch, WorldCapabilities.resilientStepDispatch
- core (node:vm): suspension handler publishes eligible steps alongside
  their create; the dispatch pass skips them (queuedStepCorrelationIds)
- core (quickjs): dispatchPendingOps does the same for overflow steps;
  the ineligible fallback is now published in parallel too (removes the
  serial per-step enqueue loop)
- consumer: on a redelivery, a stepInput-carrying message re-ensures
  step_created (marked viaStepDispatch) before executing
- under an enforced precondition guard the parallel path requires
  backend cooperation (capabilities.resilientStepDispatch, declared by
  world-vercel): a 412-rejected step's in-flight dispatch is revoked
  server-side and its re-ensure refused
- step dispatch/retry idempotency keys are step-identity-scoped
  (cid + hashed step name) so a revoked message for a reassigned
  correlation id cannot absorb the corrected schedule's dispatch
- kill switch: WORKFLOW_RESILIENT_STEP_DISPATCH=0

* Validate stepInput.input as Uint8Array at the schema boundary

Review feedback: producers only attach stepInput when the dehydrated
input is binary and the queue transport preserves bytes (CBOR), so a
non-binary value means the payload was mangled in transit. Enforcing
Uint8Array in StepDispatchInputSchema fails the message parse instead
of silently writing non-binary data into a step_created, and types the
consumer's re-ensure so the unchecked 'as SerializedData' cast goes
away.

* Keep sequential dispatch under an enforced precondition guard (drop the resilientStepDispatch capability lift)

Review feedback (two P1s): backend-side revocation bookkeeping cannot
carry the guard's correctness property across the queue side-channel —

- nothing orders a slow guarded create's eventual 412 (the moment the
  backend learns the dispatch is poisoned and records the revocation
  marker) before the consumer's redelivery re-ensure, so attempt > 1
  is a probabilistic mitigation, not a happens-before; and
- a best-effort marker that fails open (Redis loss) cannot back a
  capability the SDK treats as a correctness attestation.

Only sequencing the publish after the create gives the message a
happens-after edge over the create's guard verdict, so the guard gate
is now unconditional: worlds that enforce the precondition guard keep
the sequential create-then-publish dispatch. The parallel resilient
path remains for unguarded writes (the quickjs engine everywhere, and
worlds without the guard). Removes WorldCapabilities.resilientStepDispatch
and world-vercel's declaration; the viaStepDispatch flag is kept and
re-documented as advisory (server-side defense-in-depth only).

This also dissolves the reviewed dedupe hazard on the step-identity-
scoped dispatch keys: with no 410-ack path in any real SDK flow, a
message for a never-created step keeps redelivering until an entity
exists, execution always hydrates input from the committed entity
(never the message), and a name-mismatched stale start is skipped by
the server's stepName fence.

* Correct the MAX_RESILIENT_STEP_INPUT_BYTES rationale: VQS has no hard message-size cap

256 KB is the queue's inline-vs-S3 threshold, not a rejection limit
(payloads above it spill to S3-backed storage transparently). The
128 KiB bound is a cost/latency choice — keep step messages on the
inline path rather than paying an S3 double-hop for bytes that already
live in the event log.

* Recover a missing step in-band when a stepInput-carrying delivery beats its create

Durabench parallel sweeps (guard-off, node engine) caught ~4-8% of
fan-out runs stalling one branch for ~306s on the resilient dispatch
path. Root cause: the consumer's step_created re-ensure was gated on
metadata.attempt > 1, but world-vercel's failure-retry path re-enqueues
a FRESH message whose attempt resets to 1 — so when a delivery beat the
producer's parallel step_created write, every fast retry hit the same
'step not found' rejection with attempt 1, and the step only recovered
when the ORIGINAL message's ~300s visibility-timeout redelivery finally
arrived with attempt 2.

The recovery is now in-band and attempt-independent: when a
stepInput-carrying execution rejects with the step-missing signature
(WorkflowWorldError, 404 or the local worlds' message shape), the
consumer materializes the step_created from the message payload and
retries the execution once within the same delivery. The eager
attempt>1 ensure is kept as a round-trip saver on genuine redeliveries.

Sweep effect expected: the 305-306s TTLS outliers disappear while the
resilient path keeps its p50 win (1054ms vs 1425ms at 64 branches).
2026-08-11 19:34:15 +00:00
github-actions[bot] 9f5015b805 Version Packages (beta) (#3378) workflow@5.0.0-beta.41 2026-08-11 12:30:28 -07:00
Peter Wielander 6786db9953 World-side incrementing event ID (specVersion 6) (#3389) 2026-08-11 09:06:53 -07:00
Shalabh Chaturvedi b7591fbf21 sim-world - deterministic scenario testing for race conditions (#3328)
* Add world-sim: a deterministic simulation World for concurrency scenarios

`@workflow/world-sim` is an in-process World implementation whose point is
that nothing in it races. Every world call is a stoppable point with
`before`/`positioned`/`after` phases, every call is attributed to a writer
(orchestrator, a named step body, or an out-of-band external client), and
the clock is virtual — a thirty-day sleep costs no wall time. A scenario
script says "stop this writer here, do that, let it go", so an interleaving
that a real deployment leaves to chance becomes something you can name.

The model follows workflow-server where it matters:

- Event ids are minted at the handler boundary, not at storage append.
  DynamoDB does not generate ids, so the server does, in the request
  handler — and that id is the log's sort key. This is what makes "earlier
  log position, later commit" expressible, and it is the hazard the fence
  scenarios are about.
- The out-of-band write marker is keyed on the event's own ULID time and is
  forward-only, over `hook_received`, `step_completed` and `step_failed`.
- Both halves of the staleness fence are modelled behind flags: the
  watermark (`preconditionGuard`) that clients send today, and the count
  (`countGuard`) that they do not. The count is synthesized on the caller's
  behalf and keyed by run rather than by writer, since an orchestrator and
  its inline step bodies are one process sharing one loaded log.

`workbench/sim-world` is the scenario book — 39 of them, each a workflow
plus a script. Several are pinned corruptions rather than passing
assertions: they record what the runtime does today, so that a change in
behaviour shows up as a diff. The doc-29/30/31 trio is the argument for the
count guard, one flag apart: (B, A, C) corrupts under the watermark alone,
is fenced once the count is on, and (B, C, A) corrupts with both on. That
last one suspends mid-run on purpose. The fence is a conditional append
evaluated inside the storage write, so there is no checked-but-uncommitted
moment to slip past; the window nothing can close is the quiescent gap
between deliveries, where the run makes no writes and so meets no checks.

Both packages are private and unpublished, so no changeset.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Add the new sim-world workspaces to the lockfile

Kept separate from the source commit because it is not a clean diff. The
two new importers are the part that belongs to this branch; the rest is
re-resolution churn from running `pnpm install` at a later date than
whoever last touched the file — `latest` specifiers like docs' `radix-ui`
move on their own. Drop or regenerate this commit if the churn is
unwelcome; the source commit stands on its own.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Make a consistency violation fail the scenario that tripped it

`expect.violations` let a scenario declare the corruption it reproduced and
pass for reproducing it. That is a green suite describing a broken system,
and it goes red on the day someone *fixes* the bug — backwards, and the
opposite of what a test is for.

The field is gone. A scenario now states the outcome the run should have
reached, which for a corruption means the branch its own durable log
implies, and stays red until the runtime gets there. Any violation fails the
scenario. The six reproductions read as ordinary failures now:

  expected output "afterSlow:doc-26", got "afterFast:doc-26"

Six scenarios are therefore red, and `run.ts` exits non-zero. The count is
the signal: seven is a regression, five means something was fixed and a
scenario is ready to retire. Five of the six have known fixes — four predate
the count guard, and doc-29 goes green the moment a client sends
`stateEventCount`. doc-31 has none, which is the point of it.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Document the world-sim implementation in DESIGN.md

Folds the working notes into a checked-in design doc: module map, the
runtime model the simulator has to match, the interception model and its
three call phases, the determinism machinery, the store's guards and
fault injection, the writer vocabulary, the termination budgets, both
consistency checkers, and current test status.

Links it from both READMEs, and updates the workbench's doc-31 note now
that the append-tail fence it needs exists as a proposal.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Say which fix closes each red scenario, and which are demonstrated

The fix column read "predates the count guard" on three rows, which scans as
"the count guard is involved" when it meant the opposite. It was also wrong on
one: `two racing STEPS, no hook anywhere` cannot be fixed by anything predating
the count guard, since the row below it is that same fault with
`preconditionGuard` on and failing identically.

The column now names the specific change, and a second column separates a fix
that is argued for from one that is shown — a passing scenario that is the red
one with the fix armed, same tempo, one flag apart. Two of the six have that;
three name a fix with no paired scenario yet; doc-31 has none.

Also states the thing the column could imply but does not mean: `countGuard`
requires `stateEventCount`, which no client sends, so three of the five
identified fixes are dark in production.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Give scenarios stable ids, refer to events by log position, add colour

Four changes to make a rendered scenario something you can cite and read.

Scenario ids. Every scenario gets a hyphenated `id` next to its prose name —
`in-flight-after-decision`, `stale-read-step-count-fork`. The name is a
sentence and will be reworded; the id is what a commit message, a bug report
or `pnpm sim <id>` refers to. The runner matches the id first and falls back
to the name, so existing invocations keep working, and the table of the six
red scenarios in DESIGN.md now cites ids.

One reference scheme. Events were referred to three ways at once: the trace
printed raw correlation ULIDs, violation messages carried `evnt_<ulid>` event
ids, and the docs spoke of "position 7". Now there is only log position. `#12`
is the twelfth event in the durable log sorted the way `events.list` sorts it,
`@7` is the resource created at position 7, and ids inside violation messages
are rewritten on the way out.

That numbering is deliberately in *log* order while the trace prints in
*commit* order, which makes the subject of the red scenarios visible on the
page: a run whose log disagrees with the order its writers committed in shows
positions counting backwards.

Colour, by event family, and only when the destination is a terminal. Off
under `NO_COLOR` or `--no-color`, forced on with `--color`. With colour off
the output is the same plain ASCII, so it stays usable as a golden file.

The workflows under test are now one file. Nothing imported across them and
scenarios read them alongside the tempo that steers them, so five modules were
a two-file hop for no benefit.

Unit tests 61/61. Scenario book unchanged at 33 passed, 6 failed.

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Add an append-only log world, and split the book into one file per scenario

Three things the book could not do before.

`appendOnlyLog` gives an event its log position at *commit* instead of when
its handler minted one. That is the single change that makes a stale read
impossible — the log can be behind, never wrong — so playing the same 39
scenarios with and without it is how you tell which of the six reds the change
would actually close. All six: 33 pass / 6 violations mint-ordered, 39 pass /
0 violations append-only. It bundles two effects that have to move together:
an overtaken write re-mints at the tail, and a withheld read returns a prefix
rather than a hole, which is why `onStaleRead` now carries `{eventId, hidden,
truncated}` and the trace distinguishes a lagging read from a stale one.

`preconditionGuard` on `RunScenarioOptions` forces the fence off across the
book, asking whether anything relies on it. Violations 6 -> 8 mint-ordered, so
it is load-bearing there; 0 -> 0 append-only, so it is dead weight once
positions are assigned at commit. Both flags are tri-state: `undefined` leaves
it to the spec, which is not the same as `false`.

The scenario book was a 1020-line file; it is now 39 files and an index that
only decides reading order. Same 39 ids. This is the whole answer to "how do I
add a scenario" — copy the file next door — and it is why the README can be
short. Three `in-flight-*` scenarios are reworded so that no expectation is
restated per world: a scenario is one sequence of movements, the only thing a
world changes is what a read returns, and what catches the fault in both is
the invariant that a run's log must replay back into that run.

Also: `loadFlowHandler` moves out of `build.ts` into `load.ts`, so playing
scenarios no longer drags SWC and esbuild into the module graph; the CLI gains
`--report-only`, `--summary-file` and `--detail-file` for CI, with the default
still exiting non-zero; and the workbench's `test` script points at
`--report-only` so a recursive `pnpm -r test` does not go red for the six.

Docs are split by task: the workbench README is how to add a scenario, and the
package README plus DESIGN.md are how to change the simulator.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Publish the scenario book from CI, without blocking a merge

Plays the book on every pull request, once per log world, and posts both
summaries as one sticky comment.

It never gates. Six scenarios are red on purpose — each is a reproduction of a
corruption the runtime can still produce, stating the outcome its own durable
log implies and staying red until the runtime gets there — so a lane that
failed on them would be red on every PR and read as broken rather than as
informative. What it publishes is the pair of counts, and the thing to look at
is whether they still say 33/6 and 39/0. A seventh red is a regression; five
means something got fixed and a scenario is ready to retire. The append-only
column is the measurement the pair exists for: it says which of the six would
close if positions were assigned at commit.

Non-blocking at the job level rather than only on the two sim steps, so that a
failed install or a PR comment the token cannot write does not turn this into
a red X either. The steps themselves keep their real exit codes, so the run
still says which world was clean.

`--title` is new on the CLI: two summaries land in one comment, and two
headings reading "world-sim scenario book" would leave the chips line as the
only way to tell them apart.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* Make the Sim World comment four lines until you open it

Two collapsed folds, one per world, each with its count and a green or orange
dot on the visible line; the table is behind them. Nothing else above the fold.

The failures list is gone. Six scenarios are red on purpose, so a comment that
led with them led with the part that was not news, and grew a wall of text on
exactly the PRs that changed nothing. The count is the signal — and anyone who
wants the names can open the table, which has always had them.

`renderMarkdownSummary` now renders no heading of its own, since it is built
to be stacked under one; the workflow supplies the heading and the one-line
description. `mdCell`, `clip` and `dedupe` existed only for the failures table
and go with it.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(sim-world): drop the six-red list, add an API reference

The "six red scenarios" section was a second copy of something `pnpm sim`
already prints exactly, and the copy that goes stale. What replaces it says how
to read a red — an open bug stating the outcome its own durable log implies,
green when fixed rather than when seen again — and points at DESIGN.md for the
part that is not re-derivable from a run.

The reference has three tables. Writers: what a concurrent thread of execution
is here, and the four ids one can have. Movements: the instruction that moves a
writer to a place and holds it, described against the world boundary, the
position in the event log, and the commit to storage — three moments, which is
why there are three stops rather than one. Withholdings: the two ways to change
what a reader sees without holding anybody.

Terminology unified on hold/held (the word `Held` and the trace already use)
and on "assigned a position in the event log" / "committed to storage", which
also fixes the `runToEventProduced` docstring: the event has crossed the world
boundary there, so "submitted" was the misleading half.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(sim-world): move the API reference into the package, uniform vocabulary

The reference documents `@workflow/world-sim`, so it belongs beside the API and
not in the workbench that happens to be its first caller. It replaces the old
`## Writers` section, which said most of the same things in a different order
and a different vocabulary.

Three nouns, one meaning each. A *writer* is a thread of execution — the table
lists all three kinds with the handle that names each and the events each one
writes. An *advance* moves one writer to a named place and holds it; the three
`runTo*` stops are the three moments a write has (crossed the world boundary,
assigned a position in the event log, committed to storage), which is why there
are three rather than one, and the table says which way a concurrent commit
sorts at each. A *withholding* hides something from readers without holding
anybody, which is what `withholdNextEvent` and `beginHookDelivery` have in
common and why the latter is not an advance.

"Movements" is gone in favour of "advances", which the code and the older prose
already used. "Held" replaces "stopped"/"paused" throughout, matching `Held` and
`isHeld()`.

The workbench README loses the duplicate tables and keeps the four rules that
bite on a first scenario, so it is a guide to adding one and links out for the
rest.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(world-sim): rename "Two logs" to "World behaviors", one-line motivations

The section described two logs, but there are four world behaviors a scenario
can pick between: the two log orderings and the two guards. Renamed and
regrouped so each one is described by what it does rather than by which of the
current reds it closes.

Measured counts and "production" / "what happens today" framing are out of this
README throughout — they belong to a run of the book, and a doc that carries
them is stale the first time a scenario changes colour. The workbench README
and the CI lane still print them, where they read as measurements.

Every section's motivation is one line; the file-top motivation is unchanged.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(world-sim): Usage shows both halves — the workflow and the script

The example was a script with no workflow beside it, which hid the fact that
you write both. Replaced with the smallest pair that has something to control:
two steps in flight at once, and a script that decides which of them reaches
the log first.

The scenario in it was run before it was written down — `prepare` held before
it takes a position, `finalize` committed into the earlier slot, #6 then #7 —
so the positions the prose cites are the ones the trace prints.

Link to the workbench moved to the end of the section, where it reads as
"where to go next" rather than as an aside mid-example.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(world-sim): say what "arm" meant instead of using the word

The READMEs told a reader to arm a wait without ever saying that calling an
advance and awaiting it are two separate things. That is the whole mechanism —
`runTo` registers its watch synchronously when called, and the returned promise
only reports arrival — so it is stated plainly once in Advances and the jargon
is dropped everywhere it stood in for the explanation.

"Armed" survives only where it means a guard is switched on, which is a
different word doing a different job.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(world-sim): two symmetric watches in the Usage example

The example started one watch and awaited the other inline, which is exactly
the shape a reader cannot generalise from — it looks like the two calls do
different things. Both are now started, then both awaited, so the sentence
above the block and the code below it say the same thing.

Re-run before committing: same log, finalize at #6 and prepare at #7.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* docs(world-sim): neutral names in the Usage example

`prepare` / `finalize` / `held` / `committed` made a reader decode four
domain-ish names to see a mechanism that has nothing to do with any of them.
stepA and stepB, watchA and watchB: the only thing left to notice is that the
two watches stop at different points, which is the whole lesson.

This detaches the example from the workbench's `parallelStepsWorkflow`, so it
was verified against a throwaway copy of the workflow rather than assumed —
same shape, stepB at #6 and stepA at #7, replay ok.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* refactor(world-sim): one event fold, two call phases, a smaller entry

Three reductions to the same end — less surface to keep consistent — with
the scenario book as the check that none of them changed behaviour.

**One fold.** `create` validated *and* applied an event in a 17-case switch;
`foldSeededEvent` applied it again in 15 cases without validating. Two copies
of the event -> entity state machine that only a replay compares, and any
divergence between them makes a replay disagree with the run it is checking
for a reason that is not the runtime's fault. Both paths now end in one total
`applyEvent`: the write path validates first and calls it, `seedFromLog`
calls it with no validation at all, because those events were accepted once
already and re-litigating them would reject legitimate history. store.ts
loses 175 lines. Characterization tests for the seeded path went in first and
were confirmed to bite before the refactor started.

**Two phases.** `CallPhase` had a `positioned` phase between `before` and
`after`, and `runToPositionMinted` / `runToCall` to park on it. Nothing in the
book used any of the three: the mint/commit gap they existed for is reached
through `beginHookDelivery`, which owns both halves explicitly and does not
block the writer that made the write. Removing the phase also removes an
`await` from the interception path, so this was measured rather than reasoned
about — all four book runs are unchanged.

**A smaller entry.** `index.ts` re-exported the construction kit —
`createSimWorld`, `createSimStore`, `driveQueue`, `verifyReplay`,
`checkInvariants`, the clock — which nothing outside the package imports and
which made every one of their signatures a compatibility promise. The entry
is now the scenario surface; extenders import from the module. `InFlightWrite`
joins it, having been missing though `beginHookDelivery` returns it.

Unchanged, and the point of saying so: 33/6/6 mint-ordered, 39/0/0
append-only, 8 violations with `--no-fence`, 0 with both. 70 unit tests green
(up from 67), tsc and biome clean in both workspaces.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* fix(world-sim): follow the new event-result contract

Rebase fixups for four core replay commits, no behaviour change of our own.

`EventResult` is now a union — a populated page (`events` + `cursor` +
`hasMore`) or all three absent — so the three fields cannot be assembled from
three independent variables the type has no way to see agree. They travel as
one `deltaPage` object, spread as a whole or not at all. The spread has to be
conditional rather than optional: `...maybe` widens each field to `T |
undefined`, which is neither arm.

`processExitTriggersQueueRedelivery` is gone from the `World` interface —
#3385 stopped exiting on an exhausted replay budget, so there is nothing left
to tell it not to.

The book is unmoved across the rebase, which is the thing worth reporting:
33/6/6 mint-ordered, 39/0/0 append-only, 8 violations with `--no-fence`, 0
with both — and the same six ids red, not a swap that nets to the same count.
70 unit tests green.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* feat(world-sim): a scenario for the unclaimed-payload delivery race

Reproduces vercel/workflow#3406 as a pair of scenarios. A hook payload
nobody reads registers an unarmed delivery barrier, and a step result is
allowed to skip it — otherwise the workflow stalls until the barrier
registry idles. The skip is transitive, so the step also skips an armed
`wait_completed` merely parked behind that payload. Both branches then
draw their next `step_created` id in the order the log does not record.

The replay invariant cannot see this: live and replay run the same code,
make the same mistake, and agree. What is checkable is the log
disagreeing with itself — `wait_completed` is committed first, yet the
step branch draws the earlier id. Verified red on the current runtime
and green with #3406's diff applied.

`claimed-payload-under-fork` is the control: same steps, same tempo,
same log order through the step result, one branch awaiting the hook so
the payload lands claimed. It passes in both cases.

Getting there needed one new primitive. The delivery loop is serial, so
a held inline step body stops the loop inside its own delivery and no
timer can fire — every interleaving where a `wait_completed` lands while
a step result is outstanding was unreachable. `sim.deliverQueued(select?)`
takes a message out of the pending set and delivers it from the script,
concurrently with the hold; `takeById` removes it first, so the loop can
never pick up the same message.

The book is now 41 scenarios: 34/7 with 6 violations mint-ordered,
40/1 with 0 violations append-only. The six violation reds and the
--no-fence 6 -> 8 / 0 -> 0 measurements are unchanged. The new red is
the first that stays red in both worlds, because no log position is
wrong in it.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* fix(world-sim): address review on the simulation world

Fifteen findings from review, and one measurement that moved because of
them.

Correctness:

- tempo: `abort()` stored the raw `reject` rather than the wrapper that
  also disposes the watch, so a point reached after teardown blocked a
  world call on a promise nobody could release. The deadline is one-shot
  and already spent by then, so that is a hang. Route abort through the
  disposing path and make the action a no-op once aborted.
- world: `externalDepth` was a plain counter, so a step body writing
  concurrently with a scripted `deliverHook` was attributed to the
  script — invisible to any armed `runTo`, and `ext` in the trace.
  Measured: one misattribution book-wide. Scope it with
  `AsyncLocalStorage` instead.
- writers: `runToEventCommitted` matched a *rejected* create, so in
  fence scenarios a script could wake believing a write was durable when
  it had 412'd. Record `failed` on the observed point and require
  `failed: false`.
- clock/ids: reject fractional `advanceBy`, and floor in `ulid()` — a
  fractional millisecond silently minted `undefinedundefined…` ids that
  failed much later at `z.ulid()`.
- streams: literal NUL bytes as key separators, `limit: 0` paging
  forever, and a garbled cursor slicing the array away as `NaN`.
- scenario: register the handler under the exported
  `WORKFLOW_QUEUE_PREFIX`.

The count guard, which is the substantive one. Since #3145 `@workflow/core`
sends `stateEventCount` on every replay-context create and the server's
count guard defaults on, so the sim's "no client sends the count" claim
was stale in six places. `countGuard` now follows the fence, the sim
prefers the runtime's own count over its reconstruction, and the two
scenarios whose subject is isolating the watermark half say
`countGuard: false` explicitly. The scoreboard does not move under the
production-shaped default, which is itself the answer to the review's
question.

`log.monotonic-order` could never fire: its only caller fed it the sorted
array. It now takes commit order, supplied only by a world that promises
the two agree — under a mint-ordered log an out-of-order commit is the
premise the scenario injected, not a defect.

Docs: DESIGN §5 gains the two ways the sim's guards are stronger than
production's (FIFO-vs-mint-order pruning, and a fence that is exact
in-process where production's is region-local and fails open); §9's
scoreboard is regenerated and its "no fix armed anywhere real" claim
corrected; §10 gains the parallel hook-resume path, which no sim delivery
takes. `step-vs-step-fork` and its twin now say who the withheld reader
is in production.

`unclaimed-payload-under-fork` is green after the rebase — #3406 fixed
the delivery-barrier ordering — so the book is back to six reds and
stays there. Counts refreshed everywhere they appear: 35/6/6
mint-ordered, 41/0/0 append-only.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

* fix(world-sim): make the README's code samples type-check

`packages/docs-typecheck` globs `packages/*/README.md`, so the new README
went into the Docs Code Samples job and five of its `ts` blocks failed.

Four were genuine excerpts with an unbound `sim` or `spec`; one was a match-
object *sketch* containing a `…`, so not TypeScript at all — that one loses
its `ts` tag, joining the eleven other untagged blocks in the file.

The rest name what they use. That needed two `paths` entries in the checker:
`@workflow/world-sim` was unmapped, and an unresolved import is deliberately
tolerated there (`isExpectedMissingModule`), so every identifier in those
samples was `any` — they would have gone green while checking nothing.
Mapped, they are checked against the real declarations: seeding `id: 12345`,
`readyAtMsTYPO`, `dirsTYPO` and `runToEventCommittedTYPO` is caught against
`ScenarioSpec`, `PendingMessageView`, `SimBuildOptions` and `Writer`.

The lead teaser keeps its four unadorned lines and takes a `@skip-typecheck`
marker instead; the same calls appear in full, checked form further down.

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

Co-Authored-By: shalabhc <shalabh.chaturvedi@vercel.com>

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-08-11 08:37:16 -07:00
Peter Wielander 69c30ff49e Gate the unconsumed-event check on delivery idleness (#3439) 2026-08-10 17:35:08 -07:00
Caleb An 2d5ca54086 Set vercel approvers to workflow team (#3435) 2026-08-10 16:07:44 -07:00
Makoto Arata 1a64f68472 fix(core): preserve new.target in the deterministic Date override so Date subclasses work (#3372)
* test: add failing test for Date subclassing in workflow VM

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ar_tama <arata.makoto@gmail.com>

* fix(core): preserve `new.target` in the deterministic `Date` override so `Date` subclasses work in workflow functions

The VM's `Date` override was a plain function, so `class X extends Date`
lost the subclass identity: `super()` returned a fresh plain `Date` that
became `this`, dropping the subclass's methods and fields. This silently
broke `Date` subclasses like `TZDate` from `@date-fns/tz`.

Using `class Date extends Date_` keeps `new.target` intact, and `extends`
already wires up the prototype chain and statics, so the manual
`prototype` assignment and `Object.setPrototypeOf` fix-ups are no longer
needed. Determinism is unchanged: zero-arg construction still returns the
fixed timestamp and `Date.now()` is still overridden.

Fixes #3371

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ar_tama <arata.makoto@gmail.com>

* test: add failing test for calling `Date()` without `new`

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ar_tama <arata.makoto@gmail.com>

* fix(core): keep `Date()` callable without `new`

Use a plain function that branches on `new.target` and constructs via
`Reflect.construct(Date_, args, new.target)` instead of a class: subclassing
still works (`new.target` is forwarded), and calling `Date()` without `new`
now matches the spec — arguments are ignored and the (fixed) time string is
returned, where the previous override returned a `Date` object.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ar_tama <arata.makoto@gmail.com>

* chore: update changeset to match the final `Reflect.construct` implementation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: ar_tama <arata.makoto@gmail.com>

---------

Signed-off-by: ar_tama <arata.makoto@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 15:49:02 -07:00
Peter Wielander dc61ea1b13 docs(builders): make the onAfterTransform sample self-contained (#3424) 2026-08-10 13:52:01 -07:00