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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
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())
import { DurableWorkflow, IshClient } from "ish-harness";
const client = new IshClient();
const wf = new DurableWorkflow(client, "run-123", "./data/workflow.db");
const result = await wf.runHostStep(
"fetch_record",
{ id: "rec-123" },
async (input) => {
const data = input as { id: string };
return { id: data.id, status: "ready" };
},
);
console.log(result);
wf.close();
client.close();
The Rust API uses typed workflow methods. See the workflow API reference for its names and signatures.
package main
import (
"context"
"fmt"
"github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
wf, err := ish.NewDurableWorkflow(client, "run-123", "./data/workflow.db")
if err != nil {
panic(err)
}
defer wf.Close()
out, err := wf.RunHostStep(
context.Background(),
"fetch_record",
map[string]any{"id": "rec-123"},
func(_ context.Context, input any) (any, error) {
m := input.(map[string]any)
return map[string]any{"id": m["id"], "status": "ready"}, nil
},
ish.HostDurableStepOptions{},
)
if err != nil {
panic(err)
}
fmt.Println(out)
}
using System.Text.Json;
using Ish.Harness;
using var client = new IshClient();
using var wf = new DurableWorkflow(client, "run-123", "./data/workflow.db");
using var inputDoc = JsonDocument.Parse("""{"id":"rec-123"}""");
var result = await wf.RunHostStepAsync(
"fetch_record",
inputDoc.RootElement,
(input, _) =>
{
var id = input.GetProperty("id").GetString();
using var outDoc = JsonDocument.Parse(JsonSerializer.Serialize(new { id, status = "ready" }));
return Task.FromResult(outDoc.RootElement.Clone());
});
Console.WriteLine(result.GetRawText());
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.ishharness.DurableWorkflow;
import io.github.ishharness.IshClient;
import java.nio.file.Path;
var mapper = new ObjectMapper();
var input = mapper.createObjectNode().put("id", "rec-123");
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var wf = new DurableWorkflow(client, "run-123", "./data/workflow.db")) {
var result = wf.runHostStepSync(
"fetch_record",
input,
value -> mapper.createObjectNode()
.put("id", value.path("id").asText())
.put("status", "ready"),
new DurableWorkflow.HostStepOptions());
System.out.println(result);
}
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 restart | A durable step | Workflow steps |
| A sequence with cached results and retries | Multiple durable steps | Workflow steps and replay |
| A set of known branches that can run concurrently | Fan-out and a join | Fan-out, conditionals, and loops |
| A process that must pause for review | An approval gate | Approval snapshots |
| A sequence of external changes that needs cleanup on failure | Compensation handlers | Fan-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.