Classify Unclean Exit • AI Agent SDK

classify_unclean_exit: Classify the previous boot's exit and return a fresh boot record (pure).

classify_unclean_exit

Function

</div>

This function is defined in the protocols module.

Classify the previous boot’s exit and return a fresh boot record (pure).

Given the record persisted by the previous process, decide whether that process exited cleanly and stamp a new `phase="running" record for this boot. Side-effect free so it is provable in isolation, mirroring :func:classify_exit_reason`.

Rules:

  • No prior record ⇒ first boot / fresh store: `exit_kind="unknown"` (the
  • caller must never treat `"unknown"` as healthy, but there is nothing to
  • resume).
  • Prior `phase == "exited"` ⇒ the previous process reached its graceful
  • stop: `exit_kind="clean"`.
  • Prior `phase in ("running", "draining")` ⇒ the previous process died
  • before recording a clean exit (SIGKILL/OOM/segfault/orchestrator kill):
  • `exit_kind="unclean", and suspected_oom` when its last memory sample
  • was at/above `oom_fraction` of the budget.

The returned record carries forward the prior `restart_events` so the persistent restart-loop guard sees the full cross-boot history.

Signature

python
def classify_unclean_exit(prev: Optional[LifecycleRecord]) -> LifecycleRecord

Parameters

ParamField Optional[LifecycleRecord]

The previous process’s persisted :class:LifecycleRecord, or `None` on a fresh store.

Returns

ResponseField LifecycleRecord

class:LifecycleRecord for this boot.

Uses

  • LifecycleRecord

Source

View on GitHub

praisonaiagents/gateway/protocols.py at line 6180