Legion.Recovery (Legion v0.5.0)

View Source

Worker which runs the recovery process for interrupted runs.

Legion's supervisor starts this worker only when :recovery is configured:

config :legion, :recovery,
  stores: [MyApp.AgentStore],
  store_scan_limit: 100,
  concurrent_request_limit: 10

The worker calls list(store_scan_limit) on every configured store, selects payloads with status: :running and no parent_agent_id, then invokes Legion.recover/2 for each selected run, with at most concurrent_request_limit recoveries in flight.

Recovery deliberately does not restart sub-agents. A parent can persist its state before a code evaluation dispatches a sub-agent, then crash before the following checkpoint records that dispatch. When the parent recovers, it can replay that evaluation and dispatch a new sub-agent; recovering the recorded child independently could execute the same work twice.

store_scan_limit limits payloads read from each store. concurrent_request_limit limits recoveries in flight across all stores and defaults to 3. Recovery runs asynchronously during application startup. The worker performs the recovery scan, then exits and is not restarted. Configure it through the application environment rather than starting it directly.

The temporary agent process drives each interrupted run to completion, then stops.