Skip to content

Run lifecycle

A run is one task, from its first governed call to a terminal state. This page is how a run starts, how it ends, and how the gateway judges it once it has ended. The vocabulary (run, step, turn, action) is on Runs, steps, turns & actions; every header named here is in the agent header reference.

first call ──▶ open run ──▶ … more calls … ──▶ closing call / POST …/end / idle sweep
x-brutor-run-id same id X-Brutor-Run-End + X-Brutor-Outcome-Id
│
terminal_state + error_cause (question 1: execution)
outcome_conformance (question 2: declared?)
counts_toward_baseline (question 3: work?)
▼
run_class

There is no “start run” call. The first call that names a new run opens it. Which calls belong together depends on who drives the loop:

How the calls are linked What the agent does trace_continuity on each step Run’s chain_integrity
Your own loop (LangGraph, CrewAI, a while loop) sends the same x-brutor-run-id on every call of the task client_asserted client_asserted
The gateway delegated the call (LLM → MCP → A2A → skill) nothing; the gateway signs the chain verified intact
You were called over A2A forwards the x-brutor-delegation-* headers it received, sends no run id verified intact (or partial if the chain was dropped)
OpenTelemetry export to the inlet nothing; one trace is one run external observed_external
None of the above nothing minted each call is a one-action run
import uuid
run_id = f"screen-{application_id}-{uuid.uuid4().hex[:12]}" # new id per task
headers = {"x-brutor-run-id": run_id} # on EVERY call of the task

The id is opaque to the gateway (1–128 characters). It is never stored as sent: the gateway derives the run root from it with the tenant secret and your credential, so you cannot join or close another principal’s run, and the same id from two API keys is two runs. The derived root comes back on LLM responses:

HTTP/1.1 200 OK
x-brutor-run-id: 2R8SRAF8GXB8V7J6VZD93DRD0S
x-correlation-id: 01M5WF65S0Q8V0N6ZJ4A2C3H7D

Keep that value: it is the {root} for POST /v1/runs/{root}/end, GET /v1/runs/{root} and run feedback. Do not send it back as x-brutor-run-id — it would derive a different run.

A run ends in one of four ways. The first two are yours, and they are the only way the ledger learns what only you know.

How finalized_by When to use it
X-Brutor-Run-End (and X-Brutor-Outcome-Id) on the last call of the task explicit Always, when the task ends on a gateway call
POST /v1/runs/{root}/end explicit The task ended outside a gateway call, or the closing call could not carry the header
A gateway-signed chain ends terminal Nothing to do
An operator stops the run operator See Stopping a run
Nobody closed it: no new call within the idle window idle / sweeper Never on purpose — the run is recorded as abandoned

The idle window is run_idle_timeout_seconds on the AI System, 120 seconds by default.

# brutor-demo-screening-agent/screening_agent/graph.py — the record step
gw.mcp_call(
settings.applications_mcp_server_id,
"applications_set_recommendation",
tool_args,
run_end="completed",
outcome_id=outcome_id, # application_processed.loan_approved | loan_rejected | loan_referred
**hdr("record"),
)

The marker rides on the call’s audit row and the run is finalized once that row is written — a second or so later, never before the step itself. A bad value never fails the call: an unknown X-Brutor-Run-End is ignored (the state is then derived), and a malformed X-Brutor-Outcome-Id is kept and judged undeclared.

Terminal window
curl -s -X POST "http://localhost:8100/v1/runs/2R8SRAF8GXB8V7J6VZD93DRD0S/end" \
-H "Authorization: Bearer $BRUTOR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"state": "completed", "outcome_id": "application_processed.loan_referred"}'
Request
{ "state": "completed", "outcome_id": "application_processed.loan_referred" }

Both fields are optional. Omit state (or send "true") to let the gateway derive it. The body wins over the X-Brutor-Run-End / X-Brutor-Outcome-Id headers on the same request.

Response 200
{
"run_id": "run-01M5WMK76TKC0PR89N15H6X29E",
"root_task_id": "01ZQDZNBCX6ESPE9Z5GCMEQ2VF",
"ai_system_id": "group-01M5WEHAXGQ61T2B2NJ9V6MYRE",
"terminal_state": "completed",
"chain_integrity": "client_asserted",
"action_count": 9,
"total_cost_usd": 0.01961175,
"reopened": false,
"outcome_id": "application_processed.loan_referred",
"outcome_conformance": "declared",
"run_class": "success",
"error_cause": null
}
Status Why
400 state is not one of the six terminal states, or outcome_id does not match ^[a-z0-9_-]{1,48}(\.[a-z0-9_-]{1,48})?$. Nothing is finalized
403 The run’s steps belong to a different part of the resource-group hierarchy
404 No steps were recorded for that root (wrong root, or you sent your own id instead of the derived one)
503 The access check could not read the database; retry

reopened: true means the run had already been finalized and this call closed it again (a late step arrived). Error bodies are {"error": {"message": "…"}}.

GET /v1/runs/{root} returns the same rollup once the run is finalized, and 404 (“Run not finalized yet”) while it is open:

GET /v1/runs/2R8SRAF8GXB8V7J6VZD93DRD0S — 200
{
"run_id": "run-01M5WF65RFTKBC9SSFRPGDBWD9",
"root_task_id": "2R8SRAF8GXB8V7J6VZD93DRD0S",
"ai_system_id": "group-01M5WEHAXGQ61T2B2NJ9V6MYRE",
"run_class": "deviation",
"terminal_state": "completed",
"chain_integrity": "client_asserted",
"action_count": 1,
"total_cost_usd": 0.0,
"reopened": false,
"outcome_id": "made_up.thing",
"outcome_conformance": "undeclared",
"error_cause": null
}

Terminal states (question 1: did it complete without errors?)

Section titled “Terminal states (question 1: did it complete without errors?)”
terminal_state Set by Meaning
completed you, or derived The task finished and every call that ended the run succeeded
completed_degraded you, or derived Finished, but along the way a call errored or a model fell back
errored you, or derived The run could not do its job: its last call failed or was refused, or you said so
exhausted you only Your framework hit its iteration cap. The gateway cannot see your loop’s cap, so it never guesses this
abandoned you, or the idle sweep Nobody closed it and it went quiet — indistinguishable from a crash
cancelled you, or an operator Stopped on purpose

A state you send wins. Without one the gateway derives it from the run’s own calls, in this order: the last call was refused (guardrail, policy, denied approval) or failed → errored; closed by the idle sweep → abandoned; a call errored or a model fell back along the way → completed_degraded; otherwise completed.

A run that ends errored or exhausted carries an error_cause, derived by the gateway from the failing call — the last unsuccessful action before the run closed (a call held for approval is not a failure). The first rule that matches wins:

error_cause The failing call was…
blocked_by_policy refused by the gateway: a guardrail block, an argument policy, an access or grant denial, an approval denied or expired
rate_limited answered 429, any call type
model_unavailable a model call with a 5xx, a connect error or a timeout
model_rejected a model call with a 4xx other than 429
tool_failed an MCP or virtual-MCP call that failed (isError, non-2xx, transport error)
skill_failed a skill run that failed
agent_unreachable a delegated A2A call that failed or timed out (or reached an agent that is in no AI System)
delegate_deviated a delegated A2A call answered with an outcome the delegate’s own contract does not declare, or with none — see Delegated outcomes
iteration_limit — you closed the run exhausted (a failing call overrides this only if it was the run’s very last action)
client_reported — you closed the run errored and no call explains it

An errored run reports no outcome: it failed before it knew what it produced, and errors are execution, not outcomes. The Errors sub-tab of Signals shows runs by cause beside calls by type.

The run class: how every signal reads a run

Section titled “The run class: how every signal reads a run”

The three answers — execution (terminal_state), conformance (outcome_conformance) and whether the outcome is work (counts_toward_baseline, from the contract) — are combined once, into the run_class that health, the success rate, cost, baselines and the Runs list all read:

run_class When Counts in the success rate?
success completed / completed_degraded, outcome declared, counts toward the baseline yes, as a success
no_work completed / completed_degraded, outcome declared, does not count (an empty poll) no — in neither numerator nor denominator
deviation completed / completed_degraded, outcome undeclared or unreported yes, as a failure
failed errored or exhausted (or a state the platform does not know) yes, as a failure
not_decisive abandoned or cancelled no
success rate = success / (success + deviation + failed)

What declaring outcomes does to health, cost, drift and liveness is on Declared outcomes → What outcomes feed.

  1. Mint a new x-brutor-run-id per task and send it on every LLM, MCP, skill and A2A call of that task (not when you were called over A2A — forward the delegation chain instead).
  2. Name phases with X-Brutor-Step-Id if your orchestrator has them; turns are inferred if you do not send X-Brutor-Turn-Id.
  3. On the last call, send X-Brutor-Run-End: completed and the declared X-Brutor-Outcome-Id. On failure send X-Brutor-Run-End: errored (no outcome); when your loop hit its cap send exhausted.
  4. If the task ended off the gateway, or the closing call was held for approval (202), close with POST /v1/runs/{root}/end using the root from an LLM response — or, for an MCP-only run, on a final call.
  5. Never let a run fall to the idle sweep: abandoned reads like a crash.