RestartLoopGuard
Defined in the protocols module.AI Agent Pure rolling-window predicate that trips on a rapid restart loop. A companion to :func:
classify_exit_reason for the crash-loop breaker
referenced in Issue #3021. Where classify_exit_reason maps a single
exit to a supervisor exit code, this tracks the rate of restart-worthy
boots so a process that keeps crashing-on-resume can stop auto-resuming the
offending work rather than wedging in a tight restart loop.
It is intentionally side-effect free (records timestamps only, no I/O, no
heavy deps) so both gateway runtimes (BotOS and WebSocketGateway)
can reuse the same decision and prove it in isolation. The caller feeds a
monotonic timestamp each time a restart-interrupted boot is observed and
asks whether the breaker has tripped.
A trip means: at least max_restarts restarts occurred within the last
window_seconds. When tripped, the caller should stop auto-resuming the
offending session (while still serving real inbound) instead of restarting
it again immediately.
Example::
Constructor
int
default:"3"
No description available.
float
default:"60.0"
No description available.
Methods
record()
Record a restart at
now and return whether the breaker tripped.tripped()
Return whether the breaker is currently tripped without recording.
reset()
Clear the recorded restart history (e.g. after a clean run).
Source
View on GitHub
praisonaiagents/gateway/protocols.py at line 4398
