Skip to main content

Durable workflows

Use DurableWorkflow when your application knows the steps that should run and needs to recover their progress after interruption. Python and Rust also expose the name Workflow. The same workflow supports a single step, a sequence, parallel branches, joins, bounded map work, conditional routes, loops, approval gates, and compensation.

import asyncio

from ish import SQLiteLogger, step, workflow

logger = SQLiteLogger(db_path="./data/workflow.db")


@step
async def fetch_record(record_id: str) -> dict[str, str]:
return {"id": record_id, "status": "ready"}


@workflow(name="record_pipeline", persistence=logger)
async def record_pipeline(record_id: str) -> dict[str, str]:
return await fetch_record(record_id)


async def main() -> None:
await logger.initialize()
try:
# Reuse this ID when resuming this same business job.
result = await record_pipeline.run("rec-123", workflow_id="run-123")
print(result)
finally:
await logger.close()


asyncio.run(main())

Use an Agent when a model should choose the next tool from the conversation and results. Use a workflow when your code should choose the next step. A workflow step may call an agent when a stage needs model reasoning.

What happens when a workflow runs​

The workflow definition owns routing; step functions do the work. ISH evaluates the declared routes, limits parallel work, and records each step result. A completed step can be replayed from the same persistence store without running its function again. If a process stops during an external request, check whether the request succeeded before retrying it.

Choose workflow identity​

Treat workflow_id as the saved identity of one business job. Supply the same ID when retrying or resuming that job after a process restart; generate a new ID for a genuinely new job. Give steps that change an external system a stable request ID tied to the business operation, such as charge-order-1842. If the external service supports idempotency keys (request IDs that make repeated submissions safe), pass the same key on every retry. A random workflow ID on each retry creates a new run and cannot reuse the prior run's completed steps.

The persistence store must survive the process restart for replay to work. A completed step is reused when its workflow identity, step key, and input match. If the process stops after an external service accepts a request but before the step result is saved, it may not be clear whether the request succeeded. Check the service's status or retry using the same request ID if that service supports one. ISH records workflow progress in its database, but cannot include an unrelated service's work in that database update.

Choose a workflow shape​

If your process is…Use…Guide
A completed operation whose saved result should be reused after restartA durable stepWorkflow steps
A sequence with cached results and retriesMultiple durable stepsWorkflow steps and replay
A set of known branches that can run concurrentlyFan-out and a joinFan-out, conditionals, and loops
A process that must pause for reviewAn approval gateApproval snapshots
A sequence of external changes that needs cleanup on failureCompensation handlersFan-out, conditionals, and loops

Retries may run a step function more than once. Saving workflow progress cannot make a separate service's action happen only once. Use an operation that safely accepts repeated requests, or send the same idempotency key on every retry.

Python exposes @workflow and @step as conveniences over the durable runtime. The other SDKs expose DurableWorkflow methods such as runHostStep and runStep. All use the same Rust workflow and persistence engine.

Guides​

  • Define steps — choose step names, configure retries, and request approval before a step runs.
  • Durable replay — how completed work is reused after restart and how to handle an uncertain external action.