> ## 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.

# 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

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**protocols**](../modules/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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def classify_unclean_exit(prev: Optional[LifecycleRecord]) -> LifecycleRecord
```

## Parameters

<ParamField query="prev" type="Optional[LifecycleRecord]" required={true}>
  The previous process's persisted :class:`LifecycleRecord`, or `None` on a fresh store.
</ParamField>

### Returns

<ResponseField name="Returns" type="LifecycleRecord">
  class:`LifecycleRecord` for this boot.
</ResponseField>

## Uses

* `LifecycleRecord`

## Source

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