Inferable workflows are designed to be durable and maintain state across executions. This page explains the durability guarantees provided by the workflow system and how they affect your workflow execution.

Durability Guarantees

Workflow State

Every workflow execution maintains its state durably. This means:

  • The workflow can resume from where it left off after interruptions
  • All agent results are persisted and won’t be recomputed
  • The workflow state survives machine crashes and restarts
  • Multiple machines can pick up and continue the same workflow

The workflow state is tied to the executionId. As long as you use the same executionId, you’ll get the same workflow state, even if the workflow is triggered multiple times.

Configuration Options

When registering a workflow listener, you can configure how the workflow handles failures and timeouts:

These configuration options affect the durability behavior:

  • timeoutSeconds: Maximum duration a workflow can run before it’s considered failed
  • retryCountOnStall: Number of retry attempts if the workflow stalls (e.g., due to machine failures)

Choose these values based on your workflow’s typical execution time and reliability requirements. Long-running workflows may need higher timeout values.

Agent Results

Agents within a workflow have strong durability guarantees:

  • Each agent.trigger()s exactly once per unique configuration
  • Agent results are persisted and reused across workflow restarts
  • Agent results are deterministic based on their input parameters

Execution Semantics

At-Least-Once Execution

The workflow definition function may execute multiple times during a single workflow execution. This means:

  • Your workflow code should be idempotent
  • Use ctx.effect for operations that should run exactly once
  • Be careful with side effects in the main workflow code

State Persistence

Workflows maintain state through:

  1. Agent Results: All agent results are persisted and reused
  2. Effects: Effects run exactly once and their completion status is tracked
  3. Execution Progress: The workflow’s progress through its steps is tracked
  4. Input Parameters: The workflow input is preserved across restarts

Best Practices

To make the most of workflow durability:

  • Use Unique Execution IDs.

  • Use Effects for Side Operations.

  • Make Workflow Code Idempotent.

    // ✅ Good: Result is the same no matter how many times it runs
    const processedData = data.map((item) => transform(item));
    
    // ❌ Bad: Result changes with each run
    const timestamp = Date.now();
    

Limitations

While workflows are durable, there are some limitations to be aware of:

  • Local variables in the workflow function are not persisted
  • Function closures are not preserved across executions
  • Side effects in the main workflow code may run multiple times
  • The workflow definition must be deterministic for proper replay

If you need to preserve state between workflow steps, use agent results or emit events via effects.