vercel/workflow/migrating-world-v4-to-v5
Claude Code and agent skill by vercel/workflow
- vendor
Checking that the SKILL.md file is still in the repository.
Upgrades a custom Workflow SDK World implementation from the v4 spec, or from a 5.0.0 beta, to the current v5 spec (spec version 8). Use when a package implements the `World` interface from `@workflow/world` and is moving to 5.x, or is on a 5.0.0 beta and the runtime reports `This Workflow runtime supports Worlds with spec version 6 through 8, but the configured World declares spec version N`; or when it shows event IDs that are ULIDs rather than slot positions, `Event id is not slot-numbered`…
Install
npx vskill@latest install vercel/workflow/migrating-world-v4-to-v5SKILL.md
The same SKILL.md was published earlier as vercel/workflow/migrating-world-v4-to-v5.
Migrating a World from the v4 spec to v5
This skill is for a package that implements World from @workflow/world: a storage, queue and stream backend the Workflow runtime talks to. It is not for application code. If the task is bumping an app's workflow dependency, use the migrating-workflow-v4-to-v5 skill instead; if the app both uses Workflow and ships its own World, run that skill first and this one second.
An app on the Vercel, Local or Postgres World needs nothing from this skill. Those ship with the SDK and are already on the v5 spec.
One change dominates the work. Event ID allocation is required, is not visible from the type signatures, and a World that skips it type-checks, starts runs, and fails on the first replay. Do that part first, then the mechanical rewrites. Do not begin with the type errors: they are the small half, and finishing them produces a World that looks migrated and is not.
Which spec version a pin produces
What a World declares follows the @workflow/world version it resolves, and the runtime admits a range. Check both before deciding how much work this is.
@workflow/world | SPEC_VERSION_CURRENT / mintedSpecVersion() | Admitted by workflow 5.2.x (range 6 to 8)? | |
|---|---|---|---|
| any 4.x | 5 or below | No | |
5.0.0-beta.25 and earlier | 5 or below (no slot identity) | No | |
5.0.0-beta.35 to beta.37 | 7 | Yes, but not spec 8 | |
5.0.0-beta.39 and later, all 5.0.x stable | 8 | Yes |
The range is printed by the startup error, and lives in the bundled @workflow/core as assertWorldSupportsRuntimeProtocol. A host that bundles its own copy of the runtime has its own ceiling: grep the bundle for supports Worlds with spec version to read it. Declaring above a host's ceiling makes that host refuse the World at startup, so a World that must also run under older hosts states which host versions each of its releases supports.
A World already on a 5.0.0 beta with slot-numbered IDs does not redo step 1. Bump @workflow/world and @workflow/errors to the stable line, confirm the declaration is mintedSpecVersion() (step 2), read the spec 8 notes in step 2, then audit the step 5 contract items and the fail checklist: several of them landed late in the beta line and a beta-era World commonly misses lazy step_started, the runs.list status array and resolveData: 'skip-step-inputs'. Run the conformance suite at the new version before calling it done.
A World that predates event sourcing (it exposes runs.create, steps.update and the like, and has no events.create that drives entity state) has no v4 event log to port. The whole events.create state machine is written from scratch. Use packages/world-postgres/src/storage.ts as the reference and keep its event-by-event structure.
Intake
Before editing, establish and report each of these:
- Where the World is. Grep for
implements World,: World,World>andfrom '@workflow/world'. Read the factory it exports. - How event IDs are minted today. Grep for
eventId,ulid,uuid,nanoid,nextval,AUTO_INCREMENT,IDENTITY. Find the exact line that produces the ID written to storage. Note any place an ID is chosen before the write that stores it, for example an ID planned in advance and saved in a claim record so redeliveries reuse it. That design hands out a position before the commit and needs reworking, not porting. - What settles a write race. Read the
events.createimplementation. Note whether the ID or ordering is decided in process (read-then-write, an in-memory counter, aMath.maxover loaded events) or in the store (unique constraint, conditional write,INSERT ... ON CONFLICT, a transaction). - Which `specVersion` it declares. Grep for
specVersion. Note whether it is a literal or an imported constant. - Which optional members exist. Grep for
capabilities,analytics,getRuntimeDeadline,getEnvironment,createRunId,describeRun,getEncryptionKeyForRun,resolveLatestDeploymentId,cancelMany,experimentalSetAttributes. - Whether it provisions step topics. Grep for
'step',__wkf_step,stepQueue. - Whether it rejects stale writes. Grep for
PreconditionFailedError,preconditionGuard,stateUpdatedAt,stateEventCount,stateCursor,412. - Where its process-wide state lives. Grep the World's modules for top-level
const/letholding a pool, client, socket, registry, cache, ULID factory, or a log-once boolean. Note every one: these are correct in arequire()d package and wrong in a bundled one. - How it is tested. Grep for
@workflow/world-testingandcreateTestSuite. A World without the conformance suite wired up gets it in this migration. - What its store can make atomic. A transaction, a conditional write or unique constraint, a server-side script (Redis Lua, a Durable Object or actor that is single-threaded per run), or none (a CRDT or eventually consistent store). Step 1 depends on the answer.
- Whether bytes survive its storage and queue. v5 entity data, event data and queue payloads carry
Uint8Arrayvalues (SerializedData,stepInput.input). Grep forJSON.stringify,JSON.parse,Buffer,Binary. A store or transport that round-trips through plain JSON, or hands back a NodeBuffer, corrupts them silently. - Whether it forwards runtime parameters across a process boundary. A World whose storage sits behind HTTP, RPC or an actor call serializes
events.create()params and errors. Note where. - Which host it runs in. Node, a Worker, a browser, or a host app that bundles its own runtime (step 2 and step 7 depend on this).
- Where its runs live. Ask, or determine from the deployment model, whether a single deployment serves every run or a run is pinned to the deployment that created it. This decides the rollout in step 7 and cannot be read out of the code.
Also record the @workflow/world version it pins today and look it up in the table above.
Report anything not applicable rather than skipping it silently.
Step 1 — event ID allocation
In v4 an event ID was a ULID the World minted however it liked. In v5 an event ID is the event's position in its run's log: evnt_ followed by a 1-based slot, zero-padded to 26 characters, so a run's first event is evnt_00000000000000000000000001.
Every stored ID must equal slotToEventId(slot) exactly. Format with slotToEventId() wherever the slot is known in process. Where the slot is only known inside the store's atomic operation (the SQL below, a Redis Lua script), formatting there is correct, provided the prefix and width are derived from slotToEventId() (for example from slotToEventId(1)) rather than retyped, and the World decodes the returned ID with eventIdToSlot() before trusting it. When a script injects the ID into JSON the client already serialized, put eventId first as a fixed placeholder and replace only its first occurrence; a later field such as a hook token is user-chosen and can contain the same text. The fixed width is what makes lexicographic order the same as positional order, so a World padding to a different width sorts its own log wrongly past ten events.
There is no capability to declare and no fallback path. The runtime calls requireEventSlot() on IDs it loads, which throws Event id is not slot-numbered: <id>. This World allocates event positions the runtime cannot read.
Four rules bind the implementation. Check each against the code found in intake items 2 and 3:
- Uniqueness. Two concurrent appends must not both take a slot. Settle it where the store settles it: a unique constraint on
(runId, eventId), a conditional write, or a serializable transaction. Reading the maximum slot and adding one in process is the failure mode this rule exists for, and it survives light testing because it only breaks under concurrency. - Density. Slots run from 1 with no holes. A writer that loses a race re-derives its slot from the store and takes the next free one. Incrementing a local number after a loss leaves a permanent hole, and the runtime fails the run with
CORRUPTED_EVENT_LOGrather than replay across one. - Bump and report.
events.create()params carryeventCount: how many events the writer held in the log it replayed from, so the slot it expects iseventCount + 1. When that slot is taken, do not reject the write. Commit at the next free slot, and return the events occupying the slots you skipped on the success response, ineventswith a matchingcursorandhasMore. A stale count is the normal case for a parallel fan-out; rejecting it would serialize writes the runtime deliberately issues concurrently. A create that arrives with noeventCountcame from a caller with no loaded log (a queued step body, an out-of-band writer) and is always accepted. - Allocate at the commit. Take the slot in the same operation that appends the event, never earlier. This is what makes a reader's log a prefix of the run's log rather than a prefix with a hole in it: nothing can land behind a slot a reader has already passed. A World that hands out a slot in a request handler and commits later breaks the property every replay depends on.
The shape that satisfies all four, for a SQL store with a unique key on (run_id, event_id), is to compute the ID inside the insert and let the constraint arbitrate:
No row returned means another writer took that slot. Retry the same statement: it re-reads the maximum from a store that has already advanced, which is the bump. @workflow/world-postgres does exactly this, with a bounded retry count and jittered backoff after the first few immediate attempts, and absorbs the conflict with DO NOTHING rather than raising, because these inserts run inside a transaction an error would poison.
The exact statement matters less than the property: the slot is computed and the row is inserted in one atomic operation against the rows the constraint protects, so a loser retries against the store rather than against a number it remembered. A store without conditional writes needs a serializable transaction instead, not an in-process lock, which only orders the writers inside one process.
Read the log head before the entity state the event validates against, inside the same transaction or retry loop. The slot then fences the validation too: a writer that validated against a stale step or run row loses the slot and re-validates on the retry.
How this maps onto other stores:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 1 Nov 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/migrating-world-v4-to-v5/SKILL.md
Popularity
- Repository stars
- 2,347
- Repository forks
- 345
- 7-day trend score
- 39
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/vercel/workflow/migrating-world-v4-to-v5)