# Halt a run

Group an orchestrator and its subagents in a run, stop every one of them with one call, and let the run guard halt a team that misbehaves.

Use this when an agent team works on a task: an orchestrator and the subagents it starts. A run groups them, so one call stops the whole team on its next request. The run guard counts what the team does and can flag or halt it for you.

**Before you begin:** your orchestrator works under a person's grant and [delegates to subagents](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md). Runs, halts and the guard are free.

## 1. Start a run

[`POST /v1/mandate/runs`](https://provenanceauth.com/docs/api/runs.md#post-v1-mandate-runs) returns a `run_…` id. Name the person's grant as `root_grant_id`, so the guard can watch its budget:

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

curl -s $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "device_id": "dev_00000000000000000000000000000001", "purpose": "Restock printer paper for the office",
        "constraints": { "max_amount": 80, "budget_amount": 200, "budget_window": "month",
                         "allowed_counterparties": ["paper.example", "ink.example"], "expires_at": "2027-12-31T23:59:59Z" } }' | tee parent.json
export PARENT_ID=$(jq -r .id parent.json)

curl -s $PROVENANCE_API/v1/mandate/runs \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{ \"name\": \"Restock printer paper\", \"root_grant_id\": \"$PARENT_ID\" }" | tee run.json
export RUN_ID=$(jq -r .id run.json)
```

**Node**

```ts
const run = await prov.mandate.runs.create({ name: "Restock printer paper", rootGrantId: parent.id });
```

**Python**

```python
run = prov.mandate.runs.create(name="Restock printer paper", root_grant_id=parent["id"])
```

```json
{
  "object": "run",
  "status": "active"
}
```

## 2. Join the team to the run

Pass `run_id` when the orchestrator authorizes and when it delegates. A child grant inherits its parent's run, and every token minted in the run carries a `run` claim after its usual claims.

**curl**

```bash
curl -s $PROVENANCE_API/v1/mandate/grants/$PARENT_ID/delegate \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{ \"agent_session_id\": \"sess_paperfinder_9\", \"purpose\": \"Find A4 paper prices\", \"run_id\": \"$RUN_ID\",
        \"constraints\": { \"allowed_counterparties\": [\"paper.example\"] } }"
```

```json
{
  "object": "grant",
  "depth": 1
}
```

Read the run with [`GET /v1/mandate/runs/{id}`](https://provenanceauth.com/docs/api/runs.md#get-v1-mandate-runs-id): the team, the guard's counts and, newest first, every purchase that went over a limit (`escalations`) and every structure the orchestrator proposed (`delegation_proposals[]`). Each carries how the person decided in [`approval_context`](https://provenanceauth.com/docs/concepts/approval-context.md). The console's run page lists them under **Approvals**.

Every run, on the list and its page, carries `title`: its name, else the root grant's purpose, or null when it has neither (show the id). It also says what outside agents did in it: `outside_proposals` (their proposals, not counting withdrawn ones), `outside_briefs` (briefs the run sent them) and `latest_outside_proposal` (the one waiting on a person, else the accepted one, else the newest).

[`GET /v1/mandate/runs`](https://provenanceauth.com/docs/api/runs.md#get-v1-mandate-runs) takes `outside_agent=proposed` for the runs with a proposal, `took_part` for any outside agent and `none` for neither, alone or with `status`, `q` and the created range. The console's runs list has the same as its **Outside proposals** tab and its Filter menu's **Outside agent** field.

## 3. Halt it

[`POST /v1/mandate/runs/{id}/pause`](https://provenanceauth.com/docs/api/runs.md#post-v1-mandate-runs-id-pause) stops the team in one call:

**curl**

```bash
curl -s $PROVENANCE_API/v1/mandate/runs/$RUN_ID/pause \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "reason": "Buying from a store it was told to avoid" }'
```

**Node**

```ts
await prov.mandate.runs.halt(run.id, { reason: "Buying from a store it was told to avoid" });
```

**Python**

```python
prov.mandate.runs.halt(run["id"], reason="Buying from a store it was told to avoid")
```

```json
{
  "object": "run",
  "status": "halted"
}
```

A halt revokes every grant in the run and everything delegated below them, and locks every member session. Each member's next verify fails with `run_halted`, whether or not its token carries the `run` claim. The halt is on the decision ledger, and the `mandate.run.halted` webhook fires. A halted run takes no new members (`run_halted`).

In the console, **Mandate → Runs** shows each run's team, the guard's counters and **Halt run** (owners, admins and developers).

## 4. Resume it

An owner or admin resumes a halted run in the console, after looking at what happened. Resuming unlocks the sessions; revoked grants stay revoked, so the orchestrator delegates again for any work left. An API key can't resume a run.

## 5. Let the run guard watch the team

Each rule counts per run over a window (10 minutes by default) and acts when it reaches its threshold. Set them in **Settings → Agents → Agent teams** or with [`PUT /v1/mandate/settings/run_guard`](https://provenanceauth.com/docs/api/runs.md#put-v1-mandate-settings-run-guard).

| Rule | Counts | Default |
| --- | --- | --- |
| `denials` | Denied requests in the run | Flag at 5 |
| `out_of_scope` | Attempts outside a grant's counterparties or action types | Halt at 3 |
| `budget_pressure` | The person's budget spent or asked for, as a percent | Flag at 80 |
| `fan_out` | New subagent sessions | Flag at 20 |
| `canary` | [Canary](https://provenanceauth.com/docs/trace/guides/trace-rules.md#on-model-output) trips in a member's session | Flag at 1 |
| `off_task` | `off_task` denials, actions outside the purpose, inconsistent checks | Halt at 2 |

A flag records a trip on the run and sends `mandate.run.flagged`; a halt halts the run as in step 3. To try new thresholds first, set a `shadow` copy: it counts the same events and reports would-have-tripped counts on the run, and never acts. The guard counts behaviour and never reads content.

Your policy can also use the run's facts (listed in [policies](https://provenanceauth.com/docs/concepts/policies.md#facts)), such as `run.depth`. For example, ask a person for anything below the orchestrator:

```json
{
  "rules": [
    { "id": "ask-for-subagents", "when": [{ "fact": "run.depth", "op": "gte", "value": 1 }], "require": { "approval": true } }
  ]
}
```

## Errors you might see

| Code | What to do |
| --- | --- |
| `run_halted` | The run is halted. An owner or admin resumes it, or start a new run. |
| `run_state_invalid` | Read the run's `status`: an ended run can't be halted, and only a halted run resumes. |
| `dashboard_session_required` | Resume the run as an owner or admin in the console. |
| `resource_missing` | No such run on your account. |

## See also

- [Delegate to subagents](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md)
- [Keep subagents on task](https://provenanceauth.com/docs/mandate/guides/keep-subagents-on-task.md)
- [Policies](https://provenanceauth.com/docs/concepts/policies.md)
