Persistent Restart Loop Guard • AI Agent SDK
PersistentRestartLoopGuard: A :class:`RestartLoopGuard` whose events survive a process restart.
PersistentRestartLoopGuard
Defined in the protocols module.
AI Agent
A :class:RestartLoopGuard whose events survive a process restart.
The in-memory guard is reconstructed fresh on every boot, so a persisted turn that hard-crashes the whole process (OOM, segfault) can drive an infinite `supervisor → boot → auto-resume → crash loop the breaker never sees. This subclass loads its event history from an injected :class:RestartStoreProtocol` at construction and flushes back on every mutation, so the breaker observes the true cross-boot restart rate and can trip on a crash cycle slower than a single in-process window.
The window defaults to one hour (vs. the in-process 60s) because a cross-boot crash loop is paced by process (re)start latency, not by an in-loop retry. Pure decision preserved: all persistence is delegated to the injected store, so the trip logic remains provable in isolation.
Example::
guard = PersistentRestartLoopGuard(store, max_restarts=3,
window_seconds=3600)
if guard.record(now=time.time()):
# too many restart-interrupted boots — stop auto-resuming the turn
...Constructor
RestartStoreProtocolNo description available.
Methods
Record a restart at wall-clock `now` and flush to the store.
Clear the history in memory and in the durable store.
Source
View on GitHubpraisonaiagents/gateway/protocols.py at line 6258