Skip to content

Vercel's Workflow SDK can now start a run exactly once

A duplicate start() call used to risk spinning up a second run from the same event. Version 5.4.0 closes that gap with an atomic token claim.

Source: Vercel

Vercel shipped version 5.4.0 of its Workflow SDK on 4 November, adding an atomic way to start a workflow exactly once. The previous pattern, calling getHookByToken() and then start() as two separate steps, left a gap where two near-simultaneous requests could both pass the check and each spin up its own run.

The new option claims a hook token in the same step that admits the run:

await start(myWorkflow, args, { experimental_hook: { token: `order:${orderId}` } })

A second call with the same token now throws HookConflictError, carrying the conflictingRunId of the run that already owns it, instead of quietly creating a duplicate. Inside the workflow, createHook({ token }) binds to a token claimed this way without an extra step, and a new experimental_minRetention setting controls how long a finished run keeps its token reserved before another run can claim it.

Why it matters: anything that starts a workflow from an external event, an order placed, a webhook fired, a form submitted, now gets exactly-once semantics built in, instead of a hand-rolled lookup-then-start check that still had a race condition hiding in the gap.

The caveat: both the hook option and the retention setting are marked experimental, so the API may still change before it is considered stable.

Share

More from The Wire

All briefs