Workflow steps
A durable workflow step runs a named unit of work and saves its result. On a later run with the same workflow ID, step name, stable step key, and input, ISH reuses that result instead of running the step again. This helps long pipelines continue after a restart. If the process stops during an external request, check whether that request succeeded before retrying. Keep step inputs and outputs in JSON format, a text format for common values such as objects, lists, numbers, and strings.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import SQLiteLogger, step, workflow
logger = SQLiteLogger(db_path="./data/workflow.db")
@step(retries=2, backoff_seconds=0.5, backoff_factor=2.0)
async def fetch_record(record_id: str) -> dict[str, str]:
# Make this safe to repeat if it changes an external system.
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, step_key=f"fetch-{record_id}")
import { DurableWorkflow, IshClient } from "ish-harness";
const client = new IshClient();
const wf = new DurableWorkflow(client, "record_pipeline", "./data/workflow.db");
const record = await wf.runHostStep(
"fetch_record",
{ record_id: "rec-123" },
async (input) => {
const data = input as { record_id: string };
// Make this safe to repeat if it changes an external system.
return { id: data.record_id, status: "ready" };
},
{
stepKey: "fetch-rec-123",
retries: 2,
backoffSeconds: 0.5,
backoffFactor: 2.0,
},
);
wf.close();
client.close();
The Rust API uses typed workflow methods. See the workflow API reference for its names and signatures.
wf, err := ish.NewDurableWorkflow(client, "record_pipeline", "./data/workflow.db")
if err != nil {
panic(err)
}
defer wf.Close()
record, err := wf.RunHostStep(
ctx,
"fetch_record",
map[string]any{"record_id": "rec-123"},
func(_ context.Context, input any) (any, error) {
m := input.(map[string]any)
return map[string]any{"id": m["record_id"], "status": "ready"}, nil
},
ish.HostDurableStepOptions{
StepKey: "fetch-rec-123",
Retries: 2,
BackoffSeconds: 0.5,
BackoffFactor: 2.0,
},
)
using System.Text.Json;
using Ish.Harness;
using var client = new IshClient();
using var wf = new DurableWorkflow(client, "record_pipeline", "./data/workflow.db");
using var inputDoc = JsonDocument.Parse("""{"record_id":"rec-123"}""");
var options = new HostDurableStepOptions(
StepKey: "fetch-rec-123",
Retries: 2,
BackoffSeconds: 0.5,
BackoffFactor: 2.0);
var record = await wf.RunHostStepAsync(
"fetch_record",
inputDoc.RootElement,
(input, _) =>
{
var id = input.GetProperty("record_id").GetString();
using var outDoc = JsonDocument.Parse(JsonSerializer.Serialize(new { id, status = "ready" }));
return Task.FromResult(outDoc.RootElement.Clone());
},
options);
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("record_id", "rec-123");
var options = new DurableWorkflow.HostStepOptions("fetch-rec-123", false, 2, 0.5, 2.0);
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var wf = new DurableWorkflow(client, "record_pipeline", "./data/workflow.db")) {
var record = wf.runHostStepSync(
"fetch_record",
input,
value -> mapper.createObjectNode()
.put("id", value.path("record_id").asText())
.put("status", "ready"),
options);
System.out.println(record);
}
Choose a stable replay key
By default, a step is identified by its name, position, and input. Supply an explicit step_key when identity should remain stable as you reorder code. Reusing a key with changed input is rejected rather than returning an old result.
Use an existing step store
If your application already stores step records, supply a workflow persistence
adapter with three functions: read a step result, reserve a new step so only
one worker runs it, and save its result. Python exposes WorkflowAdapterPersistence; the
Rust API accepts a DurableStepStore (including CallbackStepStore); the
TypeScript, Go, C#, and Java PersistenceStore wrappers expose
fromWorkflowAdapter, NewWorkflowAdapterPersistenceStore,
FromWorkflowAdapter, and fromWorkflowAdapter, respectively. Pass the store
to DurableWorkflow as you would a regular persistence store. The shared
runtime decides whether to reuse, start, pause, or finish a step. The supplied
functions access your storage and must reserve each step without allowing two
workers to start it at once.
This three-callback adapter supports durable host steps. To persist traces, session messages, agent checkpoints, and declarative workflow control flow, use the full StorageConnector contract or SQLite WAL.
Handle retries
Retries are useful for temporary failures, but a function that changes an external system must be safe to repeat. Use a request ID supported by that service or check its status before retrying payments, deployments, and similar actions.
| Situation | Recommended approach |
|---|---|
| Temporary network or service failure | Configure bounded retries and backoff |
| Repeatable external request | Reuse a provider-supported idempotency key |
| External result is unknown after a crash | Check provider status before retrying |
| Step needs a person to decide | Pause for approval and resume later |
See Durable Replay for recovery behavior and the API reference for step options.