Durable tasks and workflows
Experimental (accepted VIP-55, VIP-60). Requires
"vibe": { "experimental": ["builtins"] }intsconfig.jsonorvibe.config.json; without it the compiler reportsEK3013. Any release may change or remove it.
A task is one journaled step of a durable run, and a workflow is a deterministic plan over tasks. Both have a class-shaped body with one effect call method and static readonly options. They run on Experimental.Durable, so crashed runs resume where they stopped and finished steps never run twice.
schema Issue { number: number; title: string }
task FetchIssues {
static readonly retryPolicy = { initialMs: 1000, factor: 2, maxMs: 4000, maxAttempts: 3 }
effect call(repo: string): ReadonlyArray<Issue>!string {
if (repo === "") throw "no repository"
return [{ number: 1, title: repo }]
}
}
export workflow Triage {
effect call(repo: string) {
const issues = try FetchIssues(repo)
return issues.length
}
}Run a workflow inside its layer and an engine. A second call with equal input joins the first run instead of rerunning the task:
schema Ticket { number: number; title: string }
task ListIssues {
effect call(repo: string): ReadonlyArray<Ticket>!string { return [{ number: 1, title: repo }] }
}
export workflow CountIssues {
effect call(repo: string) { return (try ListIssues(repo)).length }
}
export effect function main() {
provide Layer.provideMerge(CountIssues.layer, Experimental.Durable.memory) {
const first = try CountIssues("smithersai/vibelang")
const again = try CountIssues("smithersai/vibelang")
return first + again
}
}Experimental.Durable.memory keeps state in-process; layerSql persists runs in a database across restarts.
Tasks
- Signature boundary: Every parameter and an
A!Ereturn type must be annotated (never writeR). The body checks againstAandE; services read by the body belong to the task's implementation, not callers. Omit the body to declare a step implemented separately viaCharge.toLayer(effect (order) => …). - Schema types: Parameter,
A, andEtypes must have a schema form (string,schemadeclarations,Date,ReadonlySet<T>, and other mapped types). Unmappable types (Set<string>,unknown, plain type aliases) reportEK2109. Derived schemas live onTaskName.schemas(payload,success,error). - Options and tags:
static readonlymembers pass through as options. The durable tag defaults to<package>#<Name>(frompackage.json), keeping runs valid if the file moves;static readonly key = "billing/Charge"overrides it. Duplicate tags in a package reportEK5503. - Call site: Tasks run only as workflow steps. Calling one outside a workflow—even inside an
effectblock within a workflow—reportsEK5502.
Workflows
- Deterministic plan:
callmay omit its return type (inferred from its steps). Inside it,trymay run only steps: a task, another workflow,W.child(…)(runs a child workflow and awaits it), ortry.all/try.race/try.anyover steps (EK5504). Reading clocks, randomness, or module-levelletreportsEK5505; loops and reassignments reportEK5506; reaching itself through steps reportsEK5507. Put non-deterministic or looping work in a task. - Retries and handoffs: A
retryPolicylacking bothmaxAttemptsandexpirationMswarnsEK5509(suppressed if a spread or computed property may supply a bound).return Fix.to(issue, attempt + 1)ends the current round and starts the next in the same run (bounded bystatic readonly maxRounds; needs no return annotation for self-handoff; valid only directly afterreturn, elseEK5508). - Execution and layers:
try Triage("smithersai/vibelang")runs to completion and requires Effect'sWorkflowEngine(provided byExperimental.Durable.memoryorlayerSql).Triage.layerbundles the workflow and its tasks.
Rules and diagnostics
task and workflow are contextual keywords—only recognized at statement start followed on the same line by a name—so const task = 1, task as Job, and workflow.run() stay valid TypeScript.
| Code | Condition |
|---|---|
EK5501 | Body contains anything besides one non-static effect call and static readonly initializers (e.g., second call, instance field, type parameter) |
EK5502 | Task called outside a workflow step |
EK5503 | Duplicate durable tag in the same package |
EK5504 | Workflow try operand is not a step or step combinator |
EK5505 | Workflow reads clock, randomness, or module-level let |
EK5506 | Workflow contains a loop or reassignment |
EK5507 | Workflow recursively reaches itself through steps |
EK5508 | .to(...) handoff used outside a return |
EK5509 | Warning: retryPolicy omits both maxAttempts and expirationMs |
EK5801 | Warning: a task requiring HttpClient or ChildProcessSpawner omits static readonly tier. It defaults to "sealed". Declare the tier that describes the task’s effects. |
EK2109 | Task parameter, success, or error type lacks a schema form |