Skip to main content

Basic Recovery

from upsonic import Agent
from upsonic.durable import FileDurableStorage

storage = FileDurableStorage(path="./checkpoints")

# Resume execution
execution_id = "20251027123456-a1b2c3d4"
agent = Agent("openai/gpt-4o-mini", name="Worker")

result = agent.continue_durable(execution_id, storage)
print(f"Resumed: {result}")

Recovery with Debug Mode

# Enable debug mode to see recovery details
agent = Agent("openai/gpt-4o-mini", name="Worker", debug=True)

# This will show:
# - Checkpoint information
# - Failed step details
# - Steps to be executed
# - Recovery progress
result = agent.continue_durable(execution_id, storage, debug=True)

Handling Different Failure Scenarios

# Check execution status before recovery
durable = DurableExecution(storage=storage, execution_id=execution_id)
exec_info = durable.get_execution_info()

if exec_info:
    status = exec_info.get('status')
    error = exec_info.get('error')

    if status == "failed":
        print(f"Execution failed at step {exec_info['step_index']}")
        print(f"Error: {error}")
        print(f"Retrying step: {exec_info['step_name']}")

        # Retry the failed execution
        agent = Agent("openai/gpt-4o-mini")
        result = agent.continue_durable(execution_id, storage)

    elif status == "paused":
        print("Execution is paused, resuming...")
        agent = Agent("openai/gpt-4o-mini")
        result = agent.continue_durable(execution_id, storage)

    elif status == "completed":
        print("Execution already completed!")
else:
    print(f"No execution found: {execution_id}")