Durable replay
A durable workflow saves completed step results. When it runs again with the same workflow ID, step name, stable step key, and input, it returns the saved result without calling the completed step again. This avoids repeating completed work after a restart. It cannot tell whether an external request succeeded just before the process stopped. Use a request ID that the external service recognizes on retries, or check the request status before trying again.
Keep these identities stable across process restarts:
| Value | Identifies | Operational guidance |
|---|---|---|
workflow_id | One business job | Reuse it for retries or resume; use a new value for a new job. |
step_key | One named step within that job | Derive it from the step and business record, not a random value. |
| Step input | The values given to a step | Keep them in JSON format; changing them under an existing key is rejected. |
Replay only applies when the same durable store is available. If an external request may have succeeded before the process stopped, first look up its status or send the same request ID again if the service supports that. A retry setting does not guarantee that an external action happens only once.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import SQLiteLogger, step, workflow
logger = SQLiteLogger(db_path="./data/workflow.db")
@step
async def load_record(record_id: str) -> dict[str, str]:
# This read is safe to repeat if the workflow retries it.
return {"id": record_id, "status": "ready"}
@workflow(name="record_pipeline", persistence=logger)
async def record_pipeline(record_id: str) -> dict[str, str]:
return await load_record(record_id)
async def main() -> None:
await logger.initialize()
try:
first = await record_pipeline.run("rec-123", workflow_id="run-123")
replayed = await record_pipeline.run("rec-123", workflow_id="run-123")
print(first, replayed)
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 options = { stepKey: "load-rec-123" };
const input = { record_id: "rec-123" };
const first = await wf.runHostStep(
"load_record",
input,
async () => ({ id: "rec-123", status: "ready" }),
options,
);
// Same workflow ID, step key, and input returns the stored output without re-running.
const replayed = await wf.runHostStep(
"load_record",
input,
async () => {
throw new Error("Should not execute on replay");
},
options,
);
console.log(first, replayed, wf.steps().length);
wf.close();
client.close();
The Rust API reference documents the lower-level replay helpers and their exact signatures.
wf, err := ish.NewDurableWorkflow(client, "run-123", "./data/workflow.db")
if err != nil {
panic(err)
}
defer wf.Close()
input := map[string]any{"record_id": "rec-123"}
opts := ish.HostDurableStepOptions{StepKey: "load-rec-123"}
first, err := wf.RunHostStep(ctx, "load_record", input, func(_ context.Context, _ any) (any, error) {
return map[string]any{"id": "rec-123", "status": "ready"}, nil
}, opts)
if err != nil {
panic(err)
}
replayed, err := wf.RunHostStep(ctx, "load_record", input, func(_ context.Context, _ any) (any, error) {
return nil, fmt.Errorf("should not execute on replay")
}, opts)
if err != nil {
panic(err)
}
fmt.Println(first, replayed)
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("""{"record_id":"rec-123"}""");
var options = new HostDurableStepOptions(StepKey: "load-rec-123");
var first = await wf.RunHostStepAsync("load_record", inputDoc.RootElement, (_, _) =>
{
using var outDoc = JsonDocument.Parse("""{"id":"rec-123","status":"ready"}""");
return Task.FromResult(outDoc.RootElement.Clone());
}, options);
var replayed = await wf.RunHostStepAsync("load_record", inputDoc.RootElement, (_, _) =>
throw new InvalidOperationException("Should not execute on replay"), options);
Console.WriteLine($"First={first.GetRawText()}, Replayed={replayed.GetRawText()}, Steps={wf.Steps().Count}");
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("load-rec-123", false, 0, 0.5, 2.0);
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var wf = new DurableWorkflow(client, "run-123", "./data/workflow.db")) {
var first = wf.runHostStepSync("load_record", input, value ->
mapper.createObjectNode().put("id", "rec-123").put("status", "ready"), options);
var replayed = wf.runHostStepSync("load_record", input, value -> {
throw new IllegalStateException("Should not execute on replay");
}, options);
System.out.println("Replayed: " + replayed + ", recorded steps: " + wf.steps().size());
}
A process can stop after an external service performs an action but before the workflow records the result. Durable workflows make this uncertainty explicit: completed steps replay from saved results, while an uncertain external action must be checked before it is retried.
Reconcile an interrupted step
After a crash, inspect the external system using the same idempotency key or a status lookup. If the action completed, record the result; if it did not, authorize a retry. If neither can be established safely, leave the step for manual reconciliation rather than risking a duplicate action.
Reuse a completed step across runs
In each example below, the first invocation runs the step and saves its result to SQLite. The second invocation with the same workflow ID, step key, and input receives that result without running the step again.
Record external actions before sending them
The helper shown below saves a record of an intended external action before it sends the request. It can help your application check or retry the action after a restart, but the external service must still support a stable request ID or a status lookup to prevent duplicate work:
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish.integrations.persistence import SQLiteLogger
logger = SQLiteLogger("./ish_state.db")
result = await logger.execute_transactional_side_effect(
intent_id="intent-charge-1",
step_id="charge_customer",
idempotency_key="order-42-charge",
tool_name="stripe_charge",
arguments={"amount_cents": 2500},
capability_tier="StatusLookup",
execute_fn=lambda args: charge_api(args, idempotency_key="order-42-charge"),
status_fn=lambda key: lookup_charge_status(key),
)
import { IshClient, TransactionalSideEffectSupport } from "ish-harness";
const client = new IshClient();
const persistence = await client.persistence.create({ dbPath: "./ish_state.db" });
const tx = new TransactionalSideEffectSupport(client, persistence.persistenceHandle);
const result = await tx.execute(
{
intent_id: "intent-charge-1",
step_id: "charge_customer",
idempotency_key: "order-42-charge",
tool_name: "stripe_charge",
arguments: { amount_cents: 2500 },
capability_tier: "StatusLookup",
},
async (_tool, args, key) => chargeApi(args, key),
async (key) => lookupChargeStatus(key),
);
The Rust API reference documents the lower-level replay helpers and their exact signatures.
tx, err := ish.NewTransactionalSideEffectSupport(client, persistence.PersistenceHandle)
if err != nil {
panic(err)
}
result, err := tx.Execute(
ctx,
ish.TransactionalSideEffectRequest{
IntentID: "intent-charge-1",
StepID: "charge_customer",
IdempotencyKey: "order-42-charge",
ToolName: "stripe_charge",
Arguments: map[string]any{"amount_cents": 2500},
CapabilityTier: ish.SideEffectCapabilityTierStatusLookup,
},
func(ctx context.Context, _ string, args any, key string) (any, error) {
return chargeAPI(ctx, args, key)
},
func(ctx context.Context, key string) (any, error) {
return lookupChargeStatus(ctx, key) // returns nil, nil if not found
},
)
using System.Text.Json.Nodes;
var tx = new TransactionalSideEffectSupport(client, persistence.PersistenceHandle);
var result = await tx.ExecuteAsync(
new TransactionalSideEffectRequest(
IntentId: "intent-charge-1",
StepId: "charge_customer",
IdempotencyKey: "order-42-charge",
ToolName: "stripe_charge",
Arguments: new JsonObject { ["amount_cents"] = 2500 },
CapabilityTier: SideEffectCapabilityTier.StatusLookup),
async (tool, args, key, ct) => await ChargeApiAsync(args, key, ct),
async (key, ct) => await LookupChargeStatusAsync(key, ct));
var tx = new TransactionalSideEffectSupport(client, persistence.persistenceHandle());
var args = mapper.createObjectNode().put("amount_cents", 2500);
var result = tx.execute(
new TransactionalSideEffectSupport.Request(
"intent-charge-1",
"charge_customer",
"order-42-charge",
"stripe_charge",
args,
TransactionalSideEffectSupport.CapabilityTier.StatusLookup),
(tool, payload, key) -> chargeApiAsync(payload, key),
key -> lookupChargeStatusAsync(key)
).toCompletableFuture().join();
What replay does and does not guarantee
Give a new workflow ID to start a different job. Reuse the same workflow ID, step name, step key, and input when continuing the same job. ISH reuses saved results for completed steps. If a step was interrupted while an external request was in progress, check the service before marking the step complete or trying it again. The service may have accepted the request even though ISH did not save the result. A retry policy controls how often a step function runs; it does not guarantee that an external action happens only once.
See Workflow steps for retry and approval options.