Skip to content

Durable tasks and workflows

Experimental (accepted VIP-55, VIP-60). Requires "vibe": { "experimental": ["builtins"] } in tsconfig.json or vibe.config.json; without it the compiler reports EK3013. 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!E return type must be annotated (never write R). The body checks against A and E; services read by the body belong to the task's implementation, not callers. Omit the body to declare a step implemented separately via Charge.toLayer(effect (order) => …).
  • Schema types: Parameter, A, and E types must have a schema form (string, schema declarations, Date, ReadonlySet<T>, and other mapped types). Unmappable types (Set<string>, unknown, plain type aliases) report EK2109. Derived schemas live on TaskName.schemas (payload, success, error).
  • Options and tags: static readonly members pass through as options. The durable tag defaults to <package>#<Name> (from package.json), keeping runs valid if the file moves; static readonly key = "billing/Charge" overrides it. Duplicate tags in a package report EK5503.
  • Call site: Tasks run only as workflow steps. Calling one outside a workflow—even inside an effect block within a workflow—reports EK5502.

Workflows

  • Deterministic plan: call may omit its return type (inferred from its steps). Inside it, try may run only steps: a task, another workflow, W.child(…) (runs a child workflow and awaits it), or try.all/try.race/try.any over steps (EK5504). Reading clocks, randomness, or module-level let reports EK5505; loops and reassignments report EK5506; reaching itself through steps reports EK5507. Put non-deterministic or looping work in a task.
  • Retries and handoffs: A retryPolicy lacking both maxAttempts and expirationMs warns EK5509 (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 by static readonly maxRounds; needs no return annotation for self-handoff; valid only directly after return, else EK5508).
  • Execution and layers: try Triage("smithersai/vibelang") runs to completion and requires Effect's WorkflowEngine (provided by Experimental.Durable.memory or layerSql). Triage.layer bundles 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.

CodeCondition
EK5501Body contains anything besides one non-static effect call and static readonly initializers (e.g., second call, instance field, type parameter)
EK5502Task called outside a workflow step
EK5503Duplicate durable tag in the same package
EK5504Workflow try operand is not a step or step combinator
EK5505Workflow reads clock, randomness, or module-level let
EK5506Workflow contains a loop or reassignment
EK5507Workflow recursively reaches itself through steps
EK5508.to(...) handoff used outside a return
EK5509Warning: retryPolicy omits both maxAttempts and expirationMs
EK5801Warning: a task requiring HttpClient or ChildProcessSpawner omits static readonly tier. It defaults to "sealed". Declare the tier that describes the task’s effects.
EK2109Task parameter, success, or error type lacks a schema form