> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Drain Marker Policy • AI Agent SDK

> DrainMarkerPolicy: Pure predicate deciding whether an external drain marker is actionable.

# DrainMarkerPolicy

> Defined in the [**protocols**](../modules/protocols) module.

<Badge color="blue">AI Agent</Badge>

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 `epoch` differs from `current_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::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
policy = DrainMarkerPolicy()
if policy.drain_requested(read_marker(), current_epoch(), monotonic()):
    await gateway.stop(drain_timeout=cfg.gateway.drain_timeout)
```

## Methods

<CardGroup cols={2}>
  <Card title="drain_requested()" icon="function" href="../functions/DrainMarkerPolicy-drain_requested">
    Return whether `marker` is a live drain request for this instance.
  </Card>
</CardGroup>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L4025">
  `praisonaiagents/gateway/protocols.py` at line 4025
</Card>
