Task State (Survive Restarts & Crashes)
Use this when: An agent runs multi-step pipelines where a crash or timeout would lose intermediate progress. Save progress before risky steps; recall on boot. Retries with the same Idempotency-Key never double-charge.
// 1. Save checkpoint before executing risky step ($0.02 for 12h)
const taskId = "task-sync-9481";
const checkpointKey = `checkpoint:${taskId}`;
await payFetch(`https://memwry.servitor.workers.dev/mem/orchestrator/${checkpointKey}/12h`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": `idem_${taskId}_step3`
},
body: JSON.stringify({
completedSteps: ["fetch_data", "transform_schema"],
currentStep: "load_destination",
cursor: "rec_9938102"
})
});
// 2. On worker restart or crash recovery:
const recoveryRes = await fetch(`https://memwry.servitor.workers.dev/mem/orchestrator/${checkpointKey}`);
if (recoveryRes.ok) {
const state = await recoveryRes.json();
console.log("Resuming task from cursor:", state.cursor);
}