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

# Merge Run Terminal • AI Agent SDK

> merge_run_terminal: Fold a newly-observed terminal into the current one (refine-only).

# merge\_run\_terminal

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

> This function is defined in the [**run\_outcome**](../modules/run_outcome) module.

Fold a newly-observed terminal into the current one (refine-only).

Pure, deterministic, and **order-independent**: folding the same set of
observations always yields the same authoritative outcome regardless of the
sequence in which they arrive. Rules, in order:

1. No current outcome — the observation becomes authoritative.
2. Current is sticky — it can never be downgraded; keep it.
3. Observation has strictly stronger attribution
   (`aborted` > `timeout` > `failed` > `ok`) — refine to it.
4. Equal attribution strength but the observation is sticky while the
   current writer is not — promote to the sticky observation so a later
   `run_budget` / `external` / `superseded` of the same kind can no
   longer be silently downgraded by a subsequent weaker signal. Without
   this, `timeout/idle` then `timeout/run_budget` would keep the
   non-sticky idle result and stay downgradeable, so identical signals in
   the opposite order produced a different final outcome.
5. Otherwise keep `current` so the first writer of a given strength wins.

A later, weaker observation therefore never overwrites a stronger one, and
a sticky terminal always wins over an equally-ranked non-sticky one no
matter which was observed first.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def merge_run_terminal(current: Optional[RunTerminal], observed: RunTerminal) -> RunTerminal
```

## Parameters

<ParamField query="current" type="Optional[RunTerminal]" required={true}>
  No description available.
</ParamField>

<ParamField query="observed" type="RunTerminal" required={true}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="RunTerminal">
  The result of the operation.
</ResponseField>

## Uses

* `is_sticky`

## Source

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