Drain Timeout Has Headroom • AI Agent SDK

drain_timeout_has_headroom: Return whether the supervisor stop-timeout leaves room to drain.

drain_timeout_has_headroom

Function

</div>

This function is defined in the protocols module.

Return whether the supervisor stop-timeout leaves room to drain.

Pure predicate used by a startup sanity check. A supervisor whose stop-timeout is shorter than `drain_timeout + headroom will SIGKILL the gateway mid-drain, leaving no explanation. This returns False only when we can prove the headroom is insufficient; when either value is unknown (None) or non-positive it returns True` (fail-open: do not emit a spurious warning when we cannot tell).

Signature

python
def drain_timeout_has_headroom(stop_timeout_s: Optional[float], drain_timeout_s: Optional[float], headroom_s: float) -> bool

Parameters

ParamField Optional[float]

The supervisor’s configured stop-timeout in seconds, or `None` when it could not be determined.

ParamField Optional[float]

The gateway’s configured drain timeout in seconds, or `None`/0 when draining is disabled.

ParamField float

Slack to reserve beyond the drain window for teardown.

Returns

ResponseField bool

`True when there is adequate headroom (or it cannot be determined), False` only when the stop-timeout is provably too short.

Source

View on GitHub

praisonaiagents/gateway/protocols.py at line 5837