> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Ledger decide flow

> Switch a Midaz ledger to the Tracer decide flow with tracer.flow, and learn how the ledger obeys the outcome, verdict, and instruction of each policy control.

The decide flow is how a Midaz ledger asks Tracer for a decision that follows your [policies and bindings](https://docs.lerian.studio/en/products/tracer/policies-and-bindings.md). Tracer answers, for each control of each policy, what it decided and what the ledger must do with that. The ledger then obeys one field: the `outcome`.

**What changes in your operation:** the ledger's `tracer.mode` stops being the only switch between "report" and "block". A binding can enforce a policy on Pix and only report on TED, on the same ledger. The mode becomes the fallback for whatever no binding decides.

**Trade-off:** once your tenant publishes its first policy, a ledger on the decide flow applies only the rules and limits of published policies. Upgrade Tracer first, and plan what your first policy holds before you publish it.

> [!NOTE]
>
> The decide flow is available from the Midaz release that introduces policies. The reserve flow stays the default and is unchanged.

## Choose the flow of a ledger

***

The ledger setting `tracer.flow` picks the call the ledger makes to Tracer before it commits balances:

| `tracer.flow` | What the ledger calls | What decides |
| - | - | - |
| `reserve` (default) | `Reserve` | Every active rule and limit, and `tracer.mode` alone decides whether the ledger blocks |
| `decide` | `Decide` | The published policies and the ledger's bindings, with `tracer.mode` as the fallback for each control no binding decides |

`reserve` is never stored: a ledger that has no `flow` uses `reserve`. Any other value is refused when you write the settings.

`tracer.mode` still controls whether the ledger calls Tracer at all. With `off`, or with an honored `skip.tracer` on the transaction, the ledger makes no call, whatever the flow. Under `decide`, the ledger sends its mode as the fallback mode: `enforce` becomes `ENFORCE` and `advisory` becomes `ADVISORY`.

Set the flow in the ledger settings:

```json theme={null}
{
  "tracer": {
    "mode": "enforce",
    "failPosture": "closed",
    "timeoutMs": 250,
    "flow": "decide"
  }
}
```

See [Ledgers](https://docs.lerian.studio/en/products/midaz/ledgers.md) for the other ledger settings.

On both flows, the ledger confirms the holds when the transaction commits and releases them when it cancels.

***

## What the ledger sends

***

On the decide flow, the ledger sends the same fields as a reserve, plus its organization, its ledger, its fallback mode, and the transaction as rules see it:

* The transaction id, scheme, subType, amount, asset, description, route, timestamp, and metadata. Metadata values keep their type.
* One operation for each leg, sources and destinations, each with its amount, its account id, alias, and type.
* For each account the ledger can read: its status, segment id, portfolio id, and metadata.

When the ledger cannot read an account, it names that account's status, segment, portfolio, and metadata as unavailable fields. A rule that depends on an unavailable field is inconclusive: its policy answers `REVIEW` with the reason `rule_evaluation_error`, unless a later `DENY` or `REVIEW` rule matches. See [Absent and unavailable fields](https://docs.lerian.studio/en/products/tracer/rule-engine.md#absent-and-unavailable-fields).

The decide flow sends no merchant, and no segment or portfolio name.

***

## What Tracer answers

***

Each control of each policy gets three values:

| Field | Values | Meaning |
| - | - | - |
| `verdict` | `ALLOW`, `DENY`, `REVIEW`, `NOT_EVALUATED` | What the control decided |
| `instruction` | `ENFORCE`, `ADVISORY`, `AUDIT`, `OFF` | What the ledger does with the verdict. It comes from a binding, or from the fallback mode |
| `effect` | `REFUSE`, `PROCEED` | `REFUSE` only when the instruction is `ENFORCE` and the verdict is `DENY` or `REVIEW` |

The answer then combines them:

* **`outcome`** is `REFUSE` when any control of any policy refuses, and `PROCEED` otherwise. **The ledger obeys `outcome`.**
* **`verdict`** takes `DENY` over `REVIEW` over `ALLOW` across every control of every policy. It is diagnostic only.
* **`instructionSource`** is `BINDING` only when every control's instruction came from a binding. Otherwise it is `FALLBACK`.
* **`reason`** is filled only on `REFUSE`. It comes from, in this order, a `DENY` by a rule, a `DENY` by a limit, then a `REVIEW`.
* Holds come back only on `PROCEED`.

A refusal is a successful answer, not a transport error. A policy whose controls are all `OFF` is listed as not executed.

### Advisory and audit

A `DENY` or `REVIEW` under `ADVISORY` or `AUDIT` is reported and the transaction proceeds. It shows in `verdict` and in the per-policy results, and the ledger logs a warning and marks its trace span with `app.tracer.advisory=true`.

* Under `ADVISORY`, a limit within its ceiling holds capacity. Over the ceiling it holds nothing and reports `DENY`, and the `ENFORCE` holds stay.
* Under `AUDIT`, a limit compares the current and reserved usage with its ceiling and holds nothing.

With no binding, a refusal comes only from the `ENFORCE` fallback. An `advisory` ledger on the decide flow never refuses on a verdict, as on the reserve flow.

***

## Without published policies

***

While the tenant has no published policy, the decide flow runs the same evaluation as the reserve flow: every active rule, then every applicable limit, with the same holds. Every control takes the fallback mode, and the answer lists one policy entry with an empty `policyId` and revision `0`.

The upgrade publishes no policy, so a ledger that switches to `decide` before your first publication answers as it did on `reserve`. From your first publication on, a rule or limit outside every published policy no longer applies to the decide flow. See [The first published policy](https://docs.lerian.studio/en/products/tracer/policies-and-bindings.md#the-first-published-policy).

***

## Outcomes on the ledger

***

| Tracer answer | Ledger |
| - | - |
| `outcome=REFUSE` | Rejects before the balance commit, whatever `tracer.mode`. The code follows the refusing control, in this order: a rule `DENY` gives `0535`, a limit `DENY` gives `0177`, a `REVIEW` gives `0531` |
| `outcome=PROCEED` | Proceeds and keeps the returned holds |
| No outcome, or an answer the ledger cannot map | Applies `failPosture`, as for an unavailable Tracer |
| Its holds are already settled (`0533`) | Rejects with `0532`, whatever the mode and the posture |
| Any other failure: Tracer unavailable, a timeout, an invalid request, a refused credential | As on the reserve flow: `failPosture`, `0532` under `enforce`, `0536` |

A second decide for the same transaction behaves like a repeated reserve: Tracer evaluates it again, keeps the holds the first decide took and writes no second record. The [Midaz error list](https://docs.lerian.studio/en/reference/products/midaz/error-list.md) describes each ledger code.

***

## The validation record

***

Every decide writes one validation record, like a reserve. `GET /v1/validations?transaction_id={transactionId}` returns it. A record of the decide flow also carries:

| Field | Meaning |
| - | - |
| `outcome` | `REFUSE` or `PROCEED`, the effect the ledger obeyed |
| `instructionSource` | `BINDING` or `FALLBACK` |
| `policies` | Each policy evaluated, with its `policyId`, its `revision`, and for each control the `verdict`, `instruction`, `bindingId`, `decidedBy`, and `effect` |

A record of the reserve flow, of `POST /v1/validations`, or written before the release that introduces policies leaves these fields out. A request a partner made does not receive `policies`.

***

## Upgrade order

***

1. Run the Tracer database migration. It publishes no policy, so your active rules and limits still apply.
2. Roll out the Tracer image.
3. Roll out the ledger image.
4. Switch each ledger to `tracer.flow=decide` when you choose.

A ledger on `decide` against a Tracer that does not serve the decide call treats it as an unavailable Tracer. An `enforce` ledger with `failPosture` `closed` then rejects with `0178`.

> [!WARNING]
>
> Set every ledger back to `tracer.flow=reserve` before you roll Tracer back below the release that introduces policies. On reserve no binding applies: every active rule and limit runs, and `tracer.mode` alone decides whether the ledger blocks. Before the switch, set each ledger's `tracer.mode` to the enforcement you want without bindings. An `advisory` ledger whose bindings were `ENFORCE` stops refusing, and an `enforce` ledger whose bindings were `ADVISORY`, `AUDIT` or `OFF` starts refusing on every active rule and limit.

***

## Next steps

***

* **[Policies and bindings](https://docs.lerian.studio/en/products/tracer/policies-and-bindings.md)**: create policies, publish revisions, and bind them to a ledger.
* **[Rules engine](https://docs.lerian.studio/en/products/tracer/rule-engine.md)**: write rules over the transaction projection.
* **[Integration guide](https://docs.lerian.studio/en/products/tracer/integration-guide.md)**: the reserve flow and the HTTP validation call.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.