# When a deal goes wrong

Open a dispute on a deal or a tab period, add evidence, read the automatic findings, record the outcome with the parties, the rail or a named arbiter, and export the signed bundle for a rail.

Use this when a report arrives late, a delivery's hash doesn't match, or a tab's call count is off. A dispute puts both sides' evidence in one place: the signed offer, the acceptance, approvals, the payment reference, the delivery receipt, usage statements and both agents' records. Deterministic findings say what that evidence shows. The parties, the rail or the arbiter named in the offer record the outcome. Opening, responding, adding evidence, arbitrating and exporting are free.

**Before you begin:** you have a [deal](https://provenanceauth.com/docs/authorize/guides/buy-from-agents.md) or a [tab](https://provenanceauth.com/docs/authorize/guides/pay-per-call-with-tabs.md) with another company's agent.

## How a dispute runs

| State | What happens |
| --- | --- |
| `draft` | A deal that ends `delivery_mismatch` gets a draft. Only the buyer sees it. |
| `open` | The buyer opened it. The seller has 5 days to respond. |
| `responded` | The seller accepted or contested. |
| `resolved` | The parties, the rail or the arbiter recorded `buyer_favored`, `seller_favored` or `split`. |
| `withdrawn` | The buyer withdrew it. |
| `expired` | 60 days passed with no outcome. |

Every step is a row in the dispute's hash-chained history and a `dispute` row in both companies' decision ledgers. Each change of state sends a `dispute.*` webhook to both sides and to a named arbiter: opened, responded, resolved and expired.

## 1. Open a dispute (buyer)

Open it within 30 days of the deal's deadline or its delivery, whichever is later. One dispute per deal can be open at a time.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/deals/$DEAL_ID/disputes \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "reason": "not_as_offered", "statement": "The report has 12 pages; the offer said 20.", "amount_claimed": 20 }'
```

| Reason | Use it when |
| --- | --- |
| `not_delivered` | Nothing arrived. |
| `late` | It arrived after the deadline. |
| `not_as_offered` | It isn't what the offer described. |
| `content_mismatch` | Its hash differs from the signed delivery receipt. |
| `overcharged` | You were charged more than agreed. |
| `unauthorized` | Nobody on your side authorized the deal. |
| `other` | Something else (a statement is required). |

**From a mismatch draft.** When your confirmed hash differed from the seller's delivery receipt, open the draft as it stands with [`POST /v1/authorize/disputes/{id}/open`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-open). List your drafts with `GET /v1/authorize/disputes?status=draft`.

**For a tab.** When a UTC day settles with the two counts more than 2% apart, the day is `contested`. Dispute a period inside it with [`POST /v1/authorize/tabs/{id}/disputes`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-tabs-id-disputes) and `{ period_start, period_end, claimed_calls }`, within 30 days of the day's end.

## 2. Read the bundle and findings

[`GET /v1/authorize/disputes/{id}`](https://provenanceauth.com/docs/api/disputes.md#get-v1-authorize-disputes-id) returns the dispute with its bundle, findings and history. Each bundle item has a type, a sha256 hash and who supplied it: the buyer, the seller or Provenance. Signed items, such as the offer and the delivery receipt, carry their content.

Each finding is a check over the evidence as it stood when the dispute opened:

| Check | What it compares |
| --- | --- |
| `delivery_hash_matches` | The hash the buyer confirmed against the seller's signed delivery receipt |
| `delivered_by_deadline` | The delivery time against the offer's deadline |
| `total_within_offer` | The deal's total against the offer's total |
| `acceptance_within_mandate_and_policy` | Whether the acceptance passed the buyer's grant, budget and policy at the time |
| `seller_key_active_at_signing` | Whether the seller's key was active when it signed the offer |
| `offer_unexpired_at_acceptance` | The acceptance time against the offer's expiry |
| `usage_counts_match` | The seller's statements against the buyer's count for the period (tabs) |
| `statements_within_price` | Each statement against `max_per_call` (tabs) |
| `day_within_cap` | The day's usage against `daily_cap` (tabs) |
| `run_record_chain_buyer`, `run_record_chain_seller` | Each agent's run record, when one is linked to the deal |

Each finding's result says which side the evidence supports, `neutral`, or `not_checkable` when the evidence isn't there, and lists the items it used. A finding describes the evidence; the outcome comes from the parties, the rail or the arbiter.

## 3. Add evidence (either side)

While the dispute is open, each side may add up to 20 items: the content (base64, up to 10 MB) or only its hash for material you keep yourself.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/disputes/$DISPUTE_ID/evidence \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "kind": "document", "description": "The first page of the PDF we received",
        "content": "'"$(base64 -w0 first-page.pdf)"'", "content_type": "application/pdf" }'
```

Content is sealed at rest with AES-256-GCM. Each item's hash goes into the history, and nothing can be removed. The other side and a named arbiter read it with [`GET /v1/authorize/disputes/{id}/evidence/{evidence_id}/content`](https://provenanceauth.com/docs/api/disputes.md#get-v1-authorize-disputes-id-evidence-evidence-id-content).

## 4. Respond (seller)

You have 5 days. Accept the claim, or contest it with a statement:

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/disputes/$DISPUTE_ID/respond \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "action": "accept", "statement": "We sent the UK edition by mistake." }'
```

After you accept, refund on your rail and record the rail, its reference and the amount with [`POST /v1/authorize/disputes/{id}/refund`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-refund). The dispute resolves `buyer_favored`, decided by the parties. You can also send the refund with the accept. With no response in 5 days, the response reads `unanswered` and the dispute stays open for an outcome.

## 5. Record the outcome

Who decides is fixed by the offer the buyer accepted. The offer's `arbiter` field sets it:

| `arbiter` in the offer | Who decides | How |
| --- | --- | --- |
| absent | The parties | One side proposes with [`POST /v1/authorize/disputes/{id}/propose`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-propose); the other accepts with [`POST /v1/authorize/disputes/{id}/accept_proposal`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-accept-proposal). |
| `"rail"` | The rail | Either side records the rail's case reference, then its outcome, with [`POST /v1/authorize/disputes/{id}/rail_case`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-rail-case). |
| an `arb_…` id | That arbiter | The arbiter records the outcome and its statement. See [Act as an arbiter](https://provenanceauth.com/docs/authorize/guides/act-as-an-arbiter.md). |

The buyer can withdraw at any time before an outcome with [`POST /v1/authorize/disputes/{id}/withdraw`](https://provenanceauth.com/docs/api/disputes.md#post-v1-authorize-disputes-id-withdraw). Each side can set its own case owner with `assign` and keep private notes with `notes`; the other side sees only a note's hash in the history.

When the dispute ends, [`GET /v1/authorize/disputes/{id}/receipt`](https://provenanceauth.com/docs/api/disputes.md#get-v1-authorize-disputes-id-receipt) returns a signed receipt with the outcome, who recorded it and any refund reference.

## 6. Export for a rail

[`GET /v1/authorize/disputes/{id}/bundle`](https://provenanceauth.com/docs/api/disputes.md#get-v1-authorize-disputes-id-bundle) returns the bundle with every hash, the findings and the public history, plus `token`: an ES256 JWS (`typ: evidence+jwt`) over the sha256 of the bundle's canonical JSON, signed with the key in our JWKS. Attach both to the rail's dispute. Anyone can check them offline:

```ts
import { verifyDisputeBundle } from "@provenanceauth/rails/disputes";

const jwks = await (await fetch(`${process.env.PROVENANCE_API}/.well-known/jwks.json`)).json();
const { bundle, token } = exported;
const r = await verifyDisputeBundle(bundle, token, jwks);
// r.valid: the bundle is unchanged, every embedded item hashes to its hash, and the history is one chain.
```

The export leaves out notes and assignments.

## In the console

Authorize → Disputes lists your disputes from both sides and the ones you arbitrate, filtered by state, reason or role. A deal's drawer in Authorize → Deals links to its disputes, where the buyer can open one. The case page shows the findings, the timeline and the evidence bundle, with only the actions open to you: respond, record a refund, propose an outcome, record a rail case or, for a named arbiter, record the outcome.

## Track records

Only disputes that ended with an outcome count. A seller's record gains `dispute_rate` (resolved disputes per accepted deal) and `disputes_seller_favored_rate`; withdrawn and expired disputes never count against it. A buyer's record gains `disputes_filed_rate` and `disputes_withdrawn_rate`, shown to sellers on the deal approval page. Rates appear once a record has 50 completed deals from 5 companies, and loop-flagged deals never count.

## Errors you might see

| Code | What to do |
| --- | --- |
| `dispute_window_closed` | The 30 days have passed. Settle it with the seller directly or through the rail. |
| `dispute_already_open` | Add to the open dispute, or open its draft (`error.details.dispute_id`). |
| `dispute_state_invalid` | Read the dispute: `status`, `decider` and `actions` say what can happen next. |
| `arbiter_not_named` | Only the arbiter the offer named records this outcome. |
| `evidence_limit_reached` | Combine related files into one item, or send a hash. |
| `dispute_evidence_not_configured` | The server has no evidence key yet. The bundle and findings still work. |

## See also

- [Act as an arbiter](https://provenanceauth.com/docs/authorize/guides/act-as-an-arbiter.md)
- [Buy from agents](https://provenanceauth.com/docs/authorize/guides/buy-from-agents.md)
- [Sell to agents](https://provenanceauth.com/docs/authorize/guides/sell-to-agents.md)
- [Pay per call with tabs](https://provenanceauth.com/docs/authorize/guides/pay-per-call-with-tabs.md)
