Skip to content

API Reference parrot.bots.flows.core.checkpoint.recovery

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.flows.core.checkpoint.recovery

View source

FlowRecoveryService — graceful-shutdown suspend + dump (FEAT-399, TASK-2054).

Tracks active checkpointed AgentsFlow runs and suspends every one of them in parallel on graceful shutdown, within a configurable deadline (default FLOW_CHECKPOINT_SHUTDOWN_DEADLINE, 15s). Flows that miss the deadline are logged ERROR with their flow_ids — their last Redis checkpoint stays recoverable until its TTL expires (spec §3 Module 8).

Auto-resume-on-startup is an explicit spec Non-Goal — this service only suspends on shutdown; it never scans for or relaunches suspended flows.

Alias AgentsFlow

Re-exported from parrot.bots.flows.flow.flow.AgentsFlow.

Alias FLOW_CHECKPOINT_SHUTDOWN_DEADLINE

Re-exported from parrot.conf.FLOW_CHECKPOINT_SHUTDOWN_DEADLINE.

Class FlowRecoveryService

Registry of active checkpointed flows + graceful-shutdown suspend.

A flow calls register(self) when it starts a checkpointed run and unregister(self) when that run ends (normally or on error) — see AgentsFlow.run_flow()'s checkpointer lifecycle. Registration is keyed by flow.flow_id; registering again with the same id simply overwrites the previous entry (no error).

Method FlowRecoveryService.register

Register an active checkpointed flow.

register(flow: AgentsFlow) -> None

Parameter Type Default Description
flow AgentsFlow The AgentsFlow instance to track (keyed by flow.flow_id).

Method FlowRecoveryService.unregister

Unregister a flow. Idempotent — a no-op if not registered.

unregister(flow: AgentsFlow) -> None

Parameter Type Default Description
flow AgentsFlow The AgentsFlow instance to stop tracking.

Method FlowRecoveryService.shutdown

Suspend every registered flow in parallel, within deadline seconds.

Never raises — this is meant to run from an aiohttp on_shutdown hook or a signal handler, where an exception here would mask other shutdown work. Idempotent and safe to call with zero registered flows (no-op).

shutdown(deadline: float = FLOW_CHECKPOINT_SHUTDOWN_DEADLINE) -> None

Parameter Type Default Description
deadline float FLOW_CHECKPOINT_SHUTDOWN_DEADLINE Seconds to wait for all suspends to finish before giving up on the stragglers. Defaults to FLOW_CHECKPOINT_SHUTDOWN_DEADLINE (15s).

Method FlowRecoveryService.attach_to_app

Register shutdown() on an aiohttp Application's on_shutdown.

attach_to_app(app: aiohttp.web.Application) -> None

Parameter Type Default Description
app aiohttp.web.Application The aiohttp Application to attach to.

Method FlowRecoveryService.install_signal_handlers

Best-effort SIGTERM/SIGINT handlers for standalone (non-aiohttp) runners.

Skipped (logged as a warning) on platforms/loops without signal support (e.g. add_signal_handler is unavailable on the default Windows event loop) rather than raising.

install_signal_handlers(loop: asyncio.AbstractEventLoop | None = None) -> None

Parameter Type Default Description
loop asyncio.AbstractEventLoop | None None Event loop to install handlers on; defaults to the current running loop.

Function get_recovery_service

Return the process-wide default FlowRecoveryService instance.

Lets AgentsFlow and HTTP handlers (TASK-2055) share one registry without a DI framework.

get_recovery_service() -> FlowRecoveryService

Returns: FlowRecoveryService — The shared FlowRecoveryService singleton.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally