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

# How Retry works

> Automatic recovery, corrective retry, and the evidence Lambda uses before changing stamp work.

Retry is native to stamping. The normal path owns day-to-day work: CargoWise → Lambda → Facturapi → back to CargoWise. Recovery and correction only engage when that path stalls or must continue with proof.

## Mental model

```text theme={null}
Immutable CargoWise capture (original accounting evidence)
        │
        ├── Automatic recovery
        │     re-enqueue never-started work, or resume the exact attempt
        │     no remap · no new fiscal intent · no retry run
        │
        └── Corrective retry
              preview a plan → apply only that plan hash
              either resume the exact attempt, or remap source once
              durable run + reason · never silent
```

Two ideas stay separate on purpose:

| Lane                   | Job                                                                           |
| ---------------------- | ----------------------------------------------------------------------------- |
| **Automatic recovery** | Keep stuck work moving without changing what Lambda already intended to stamp |
| **Corrective retry**   | Change course only when durable evidence says a correction is required        |

Automatic recovery is not a “retry kind.” It does not create a corrective run. When budgets are exhausted, the document becomes a [system error](/stamping/system-errors) and support uses a fresh corrective plan.

## Evidence before mutation

Lambda treats the original CargoWise capture as immutable accounting evidence. The invoice row is Lambda's current claim. Before a corrective retry mutates anything, the system asks:

1. Is this document already successful, cancelled, in flight, or waiting on a parent?
2. Does policy allow a stamp retry for the active classification?
3. Can we **resume** the exact stored attempt, or must we **reprocess** from the original capture?
4. For failed documents: is there proof the fiscal projection changed, or that an approved prerequisite was corrected?

If any answer fails the safety gate, retry blocks. See [Safety rules](/stamping/retry/safety).

## Preview, then apply

Corrective retries are plan-bound:

1. **Preview** recomputes what would happen and returns a deterministic plan hash.
2. **Apply** recomputes under lock and only proceeds if that exact hash still matches.
3. A private reason is stored on the ops run. It is not copied into customer notifications.

Stale previews fail closed. Duplicate requests for the same active operation return the same run instead of starting another.

## Strategies in one line

* **Resume attempt** — continue the exact stored Facturapi request and idempotency key.
* **Reprocess source** — remap the original capture with current Lambda code and create one new attempt only when the prior create never produced a provider invoice.

Details: [Strategies](/stamping/retry/strategies).

## Who owns what during recovery

| Owner               | Owns                                                                                 |
| ------------------- | ------------------------------------------------------------------------------------ |
| **CargoWise**       | Original accounting evidence (unchanged by retry)                                    |
| **Lambda**          | Whether resume or reprocess is allowed, plan hashing, run history, workspace actions |
| **Facturapi / SAT** | Whether a resumed or new stamp attempt is accepted                                   |
| **Support / ops**   | Corrective categories the workspace correctly withholds                              |

Stamp success and [CargoWise delivery](/stamping/how-it-works#stamp-and-delivery-are-separate) stay separate. Delivery retries never re-stamp.

## Where this sits in stamping

| Signal                                             | Related docs                                                        |
| -------------------------------------------------- | ------------------------------------------------------------------- |
| Document failed with a reviewable note             | [Failures](/stamping/failures), [Troubleshooting](/troubleshooting) |
| Configuration, transient, or permanent system stop | [System errors](/stamping/system-errors)                            |
| Why Lambda refuses to guess                        | [Rules](/stamping/rules)                                            |
| How to interact with each recovery path            | [Recovery paths](/stamping/retry/paths)                             |
