Current Epoch • AI Agent SDK
current_epoch: Return a stable identifier for the current OS *instantiation*.
current_epoch
Function
</div>
This function is defined in the protocols module.
Return a stable identifier for the current OS instantiation.
The epoch combines the most durable, restart-distinguishing signals available so a drain marker can be tied to the instantiation that wrote it. It is derived from (best-effort, in order of preference):
- the kernel boot id (Linux `
/proc/sys/kernel/random/boot_id`), which - changes on every reboot, and
- the start time of PID 1 (the init process), which also changes on every
- boot / container (re)start.
On platforms where neither is available the function degrades gracefully to an empty string; callers that cannot determine an epoch should treat
every marker as foreign (fail-safe: ignore stale-looking requests) by pairing this with :class:DrainMarkerPolicy, which ignores markers whose epoch does not match the current one.
Signature
def current_epoch() -> strReturns
str<pid1_start>”`) when both signals are available, or an empty string otherwise. Requiring both keeps the contract fail-closed: a partial epoch (e.g. boot_id` alone, which is unchanged across same-host container restarts) could let a durable stale marker match a fresh instance, so it is never emitted.
Uses
fh.readraw.rsplit
Source
View on GitHubpraisonaiagents/gateway/protocols.py at line 5583