Merge Run Terminal • AI Agent SDK

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

merge_run_terminal

Function

</div>

This function is defined in the 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
  4. (`aborted &gt; timeout &gt; failed &gt; ok`) — refine to it.
  5. Equal attribution strength but the observation is sticky while the
  6. current writer is not — promote to the sticky observation so a later
  7. `run_budget / external / superseded` of the same kind can no
  8. longer be silently downgraded by a subsequent weaker signal. Without
  9. this, `timeout/idle then timeout/run_budget` would keep the
  10. non-sticky idle result and stay downgradeable, so identical signals in
  11. the opposite order produced a different final outcome.
  12. 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
def merge_run_terminal(current: Optional[RunTerminal], observed: RunTerminal) -> RunTerminal

Parameters

ParamField Optional[RunTerminal]

No description available.

ParamField RunTerminal

No description available.

Returns

ResponseField RunTerminal

The result of the operation.

Uses

  • is_sticky

Source

View on GitHub

praisonaiagents/run_outcome.py at line 408