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:
- No current outcome — the observation becomes authoritative.
- Current is sticky — it can never be downgraded; keep it.
- Observation has strictly stronger attribution
- (`
aborted>timeout>failed>ok`) — refine to it. - 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/idlethentimeout/run_budget` would keep the - non-sticky idle result and stay downgradeable, so identical signals in
- the opposite order produced a different final outcome.
- 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
def merge_run_terminal(current: Optional[RunTerminal], observed: RunTerminal) -> RunTerminalParameters
ParamField
Optional[RunTerminal]No description available.
ParamField
RunTerminalNo description available.
Returns
ResponseField
RunTerminalThe result of the operation.
Uses
is_sticky
Source
View on GitHubpraisonaiagents/run_outcome.py at line 408