Drain Marker Policy • AI Agent SDK
DrainMarkerPolicy: Pure predicate deciding whether an external drain marker is actionable.
DrainMarkerPolicy
Defined in the protocols module.
AI Agent
Pure predicate deciding whether an external drain marker is actionable.
A drain marker is a small JSON object written by an operator / deploy step (via `praisonai gateway drain`) into a well-known path. A background watcher in the wrapper reads it and asks this policy whether the running gateway should react. The decision is intentionally side-effect free so it is provable in isolation without a live gateway or filesystem.
A marker is honoured only when it requests a drain for the current instantiation:
- a missing marker (`
None`) is never a drain request; - a marker carrying no `
epoch` is treated as foreign and ignored, so a - hand-rolled or legacy file cannot wedge a process;
- a marker whose `
epochdiffers fromcurrent_epoch` is stale — it - survived a reboot/restart on a durable volume — and is ignored;
- a current-epoch marker is honoured (subject to an optional
- already-handled de-duplication via `
last_handled_epoch`).
Example::
policy = DrainMarkerPolicy()
if policy.drain_requested(read_marker(), current_epoch(), monotonic()):
await gateway.stop(drain_timeout=cfg.gateway.drain_timeout)Methods
Source
View on GitHubpraisonaiagents/gateway/protocols.py at line 5638