> For the complete documentation index, see [llms.txt](https://docs.metamynd.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metamynd.ai/core-concepts/holds-claims-and-exactly-once-execution.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# Holds, Claims & Exactly-Once Execution

How an allowed action becomes a hold that one gateway claims and settles, so it runs exactly once, even with retries and timeouts.

## Holds, Claims & Exactly-Once Execution <a href="#user-content-holds-claims--exactly-once-execution" id="user-content-holds-claims--exactly-once-execution"></a>

"The gate said allow" and "the action ran exactly once" are two different statements. Between them sit a network, a gateway that may time out, a retry loop, and possibly a second process that was handed the same authorization. This page is the mental model for how MAGP closes that gap: a permitted value action becomes a **hold**, exactly one executor may **claim** it, and what happened afterwards is always something you can look up rather than guess.

#### The lifecycle <a href="#user-content-the-lifecycle" id="user-content-the-lifecycle"></a>

{% code overflow="wrap" %}

```
authorize ──▶ HOLD (budget reserved, authorizationId issued)                │                ├── nobody claims it before the hold window closes ──▶ expires, budget returned                ├── void before any claim ────────────────────────────▶ released, budget returned                │                └── CLAIM (effect/dispatching) — single-use, exactly one winner                      │                      ├── dispatched ──▶ capture (settled amount recorded) ──▶ optional refund                      ├── claimer proves nothing happened ──▶ void (released)                      └── outcome unknown ──▶ reconcile ──▶ settled / released / compensation
```

{% endcode %}

Every transition after the hold is written to a hash-chained effect ledger, so the history of an authorization is tamper-evident as well as queryable.

#### The hold <a href="#user-content-the-hold" id="user-content-the-hold"></a>

When the gate permits a value-bearing action, its last step atomically reserves the amount against the mandate's cap. That reservation is the **hold**, identified by the `authorizationId` returned to the agent.

* A hold nobody claims **expires** at the end of its hold window, and its budget is returned automatically.
* Before anyone claims it, a hold can be voided or settled lower by whoever holds the authorization id — nothing can have executed yet, so this is a release, not a report of a charge. Once settled or voided it can no longer be claimed.

#### The claim: exactly one winner <a href="#user-content-the-claim-exactly-one-winner" id="user-content-the-claim-exactly-one-winner"></a>

The service that is about to execute the action — a gateway, an MCP server, an A2A skill — first **claims** the hold with `POST /policy/mandate/authorize/{authorizationId}/effect/dispatching`.

* **The claim is single-use and atomic.** Of any number of simultaneous claimants, exactly one succeeds. Every other claim — a simultaneous loser, a later replay, a claim after the effect was dispatched or settled — is refused with `AUTHORIZATION_ALREADY_CLAIMED` (HTTP 409). The hold window is checked inside the claim itself, so a hold that lapses between a read and the claim is not claimed.
* **The claim is where the remaining checks bite.** If the agent bound its payload, the claimant must state the digest of what it is about to run and the gate compares it with the digest it stored (<a href="https://docs.metamynd.ai/core-concepts/payload-binding" target="_blank">Payload Binding</a>). If the owner restricts who may execute their holds, the claimant must be a registered, active trusted counterparty (<a href="https://docs.metamynd.ai/core-concepts/trusted-counterparties-and-payee-directory" target="_blank">Trusted Counterparties & Payee Directory</a>). A refused claim leaves the hold unclaimed, so an honest executor can still claim it.
* **The agent's rules are checked again.** If the agent has SOP or Standard rules, the claim re-runs them against the context recorded with the hold, under the rules in force now and the <a href="https://docs.metamynd.ai/core-concepts/attested-environment-facts" target="_blank">attested facts</a> about the hold's target as they stand now. A hold the rules no longer permit is refused `AUTHORIZATION_RULES_CHANGED` and voided, and nothing executes: for example, a restart allowed while a service was unhealthy, claimed after an observer said it recovered. The hold records the rule that fired (`HOLD_VOIDED:<reason code>`). The agent asks again. Changing an agent's rules runs the same check over its unclaimed holds.
* **A claimed hold is a commitment.** Once claimed, the effect may already have happened. From that point the budget stays reserved until the hold is settled or the claimer proves nothing ran — it does **not** lapse with the hold window, and nobody but the claimer can release it.
* **x402 payments** declare themselves at the claim (`x402: true`), which is what later lets an independent observer confirm a lowered settlement on-chain.

A claim that loses for an unexplained reason and leaves the hold claimable, or that overlaps an earlier attempt still being recorded, gets `EFFECT_TRANSITION_CONTENDED` — retry it once.

#### Who claimed it: signed identity vs claim token <a href="#user-content-who-claimed-it-signed-identity-vs-claim-token" id="user-content-who-claimed-it-signed-identity-vs-claim-token"></a>

The party that claims a hold is the only one who may later settle it lower, release it, or mark its outcome unknown. So it matters how the claimer is identified:

|                | **Signed service identity** (preferred)                                                                                                                                                      | **Claim token**                                                                                             |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| How            | The executor signs the claim with its own `did:key` or `did:hedera` (the `MAGP-SERVICE-v1` message, sent in `x-magp-service-*` headers), and signs every later settlement call the same way. | An anonymous claim is answered with a `claimToken`, which the claimer presents on later capture/void calls. |
| What it proves | *Who* the claimer is — a key it controls. Can be checked against the owner's registry of trusted counterparties.                                                                             | Only "I am the one who made the claim". It is a bearer secret.                                              |
| Mainnet        | Required: mainnet holds can only be claimed by a registered trusted counterparty.                                                                                                            | Refused wherever the owner's registry is enforced.                                                          |

A deployment can also require an authenticated claimer for every claim, in which case an anonymous claim is refused (`COUNTERPARTY_AUTH_REQUIRED`). The service identity is deliberately separate from the agent's: an agent must never be able to release or lower-settle a hold it authorised itself.

#### Retrying a claim safely <a href="#user-content-retrying-a-claim-safely" id="user-content-retrying-a-claim-safely"></a>

A claim whose response is lost is ambiguous: "my claim landed" and "someone else claimed" look the same. To recover, a claimant may send an `Idempotency-Key` header with the claim — 32 to 128 characters of randomness, chosen per claim call and reused only to retry that call (never the authorization id, which the agent knows).

* The gate stores only a **hash** of the key, inside the effect chain.
* A retry with the same key, from the same identity, while the effect is still in flight, is answered as a **replay** — the original grant, with `replayed: true`, and no second claim recorded.
* A "retry" after the effect was settled, released or went unknown is refused as an ordinary `AUTHORIZATION_ALREADY_CLAIMED`. A late claim can never invite a second execution.

The authorization id is the natural idempotency key for the **upstream** system: a gateway should send it upstream as `Idempotency-Key`, and must never forward an idempotency key the agent supplied. An upstream that de-duplicates on it makes the effect exactly-once even if the gateway were asked to run the same call twice.

#### After the claim: settling, releasing, and "we don't know" <a href="#user-content-after-the-claim-settling-releasing-and-we-dont-know" id="user-content-after-the-claim-settling-releasing-and-we-dont-know"></a>

| Hold state                     | Capture at the full authorised amount       | Capture at a lower amount                                                                                         | Void                                                                                          |
| ------------------------------ | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| **Unclaimed**                  | Anyone with the authorization id            | Anyone with the id (a release; the hold becomes unclaimable)                                                      | Anyone with the id                                                                            |
| **Claimed**                    | Anyone with the id (it can only spend more) | **Only the claimer** — and, where an independent observer applies, only if the observer confirms the lower amount | **Only the claimer** — and, where an observer applies, only if it affirms nothing was settled |
| **Forced into reconciliation** | Nobody (`HOLD_UNDER_RECONCILIATION`)        | Nobody                                                                                                            | Nobody                                                                                        |

A void that is refused because the hold is under reconciliation, was claimed mid-void, or its effect is already `dispatched`/`unknown` (`EFFECT_NOT_VOIDABLE`) returns **HTTP 409**; a void of a claimed hold by someone other than its claimer returns **HTTP 403** (`COUNTERPARTY_MISMATCH`). For what the settled figure rests on (`settlementEvidence`), when an observer must confirm it, and the payee account (`payTo`), see <a href="https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence" target="_blank">Settlement & Settlement Evidence</a>.

When the executor genuinely doesn't know whether the action ran — a timeout, a `5xx`, a dropped connection — it should not guess. It marks the effect **unknown** (`POST .../effect/unknown`) and asks for **reconciliation** (`POST .../effect/reconcile`), which settles on what the remote system reports. Both freeze the hold out of capture and void, so only the claimer, the mandate's owner or an admin may call them — the authorization id alone is not enough.

An owner who no longer trusts the counterparty holding a claim (typically one they have just revoked) can **force the hold into reconciliation** (`POST .../effect/force-reconcile`). From then on the claimer holds none of its powers; the hold settles only on what the settlement observer establishes or an operator decides. Nothing is released or reassigned — a hold that may have executed must not run twice.

A captured hold can later be **refunded** (`POST .../refund`). This is record-only — MetaMynd never moves money — but it reduces what the mandate's cumulative cap counts, so a refunded purchase genuinely frees budget.

#### Outcome lookup: did it happen, and is a retry safe? <a href="#user-content-outcome-lookup-did-it-happen-and-is-a-retry-safe" id="user-content-outcome-lookup-did-it-happen-and-is-a-retry-safe"></a>

`GET /policy/mandate/authorize/{authorizationId}/effect` is public and answers what became of an authorization:

| `outcome`                                    | Meaning                                                          | `nothingExecuted` | `retrySafe` |
| -------------------------------------------- | ---------------------------------------------------------------- | ----------------- | ----------- |
| `not_started`                                | authorised, unclaimed, inside its hold window                    | `true`            | `false`     |
| `expired`                                    | unclaimed, past its window; budget already returned              | `true`            | `true`      |
| `not_executed`                               | voided before a claim, cancelled by its claimer, or failed clean | `true`            | `true`      |
| `in_flight`                                  | claimed and executing (or dispatched)                            | `false`           | `false`     |
| `settled`                                    | settled; the spend is committed                                  | `false`           | `false`     |
| `unknown`                                    | ambiguous, or under reconciliation                               | `false`           | `false`     |
| `reversing` / `reversed` / `reversal_failed` | settled, then compensated                                        | `false`           | `false`     |

The two flags answer different questions. `nothingExecuted` is a fact about **now**. `retrySafe` is a promise about the **future** — nothing can execute later either — and it is the only safe basis for requesting a fresh authorization for the same intent. It is `false` for `not_started`, because that hold can still be claimed until its window closes: to retry one, void it first (a void is atomic against a claim), then read `not_executed`. Never retry an `unknown` or `in_flight` outcome blindly.

The response also carries the authorised and settled amounts and the settlement evidence. It never carries a claim token or the claimer's identity.

{% hint style="warning" %} **Capture and void are not idempotent the way a claim is.** Retrying a capture that already succeeded answers `409 NOT_HELD` (the bare code as `message`); retrying a void that already succeeded answers `200` with `voided: false, reasonCode: "NOT_HELD"`. Both look like failures to a naive retry loop but usually mean the first call landed. After a timeout, a dropped connection or a `5xx`, read `GET .../effect` before concluding a capture or void failed. {% endhint %}

#### Revocation and reissue <a href="#user-content-revocation-and-reissue" id="user-content-revocation-and-reissue"></a>

* **Revoking a mandate voids its unclaimed holds and leaves claimed holds alone.** A service has already taken those up and may be executing; they stay committed until the claimer settles them or they are reconciled. The outcome lookup of a claimed hold whose mandate was revoked mid-flight still reads `in_flight`.
* **Reissuing a mandate carries its spend.** When a mandate is reissued (key rotation, a resource-scope change, switching payload binding), the new mandate records the one it supersedes and the cap counts spend across the whole lineage — a reissue never resets the budget.

#### Where to go next <a href="#user-content-where-to-go-next" id="user-content-where-to-go-next"></a>

* <a href="https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence" target="_blank">Settlement & Settlement Evidence</a> — the wire-level rules for capture, void, observers and evidence.
* <a href="https://docs.metamynd.ai/guides/settle-a-claimed-hold" target="_blank">Settle a Claimed Hold</a> — the service-side steps with the SDKs.
* <a href="https://docs.metamynd.ai/agent-protocol/x402-payment-binding" target="_blank">x402 Payment Binding</a> — binding an x402 payment to an authorization.

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.metamynd.ai/core-concepts/holds-claims-and-exactly-once-execution.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
