Skip to main content

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:

ValueIdentifiesOperational guidance
workflow_idOne business jobReuse it for retries or resume; use a new value for a new job.
step_keyOne named step within that jobDerive it from the step and business record, not a random value.
Step inputThe values given to a stepKeep 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.

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())

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:

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),
)

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.