> ## 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.

# How Lerian STA works

> How Lerian STA works: outbound submission and inbound file discovery to BACEN, protocol state machine, SHA-256 integrity, retry budgets, and operator actions.

Lerian STA moves files in two directions. Each exchange is one **transfer** — a single file that moves between the institution and BACEN. A **protocol number** tracks the transfer through BACEN's protocol lifecycle. Each end verifies the **SHA-256**.

## Outbound submission

***

The institution, or an upstream Lerian product, hands Lerian STA a file for BACEN. Lerian STA then obtains a **protocol number** from BACEN. It uploads the file's bytes. BACEN validates the bytes against the declared **SHA-256**.

The transfer advances through BACEN's lifecycle:

| State                       | Meaning                                           |
| --------------------------- | ------------------------------------------------- |
| **Protocol generated**      | BACEN has assigned the protocol number.           |
| **Transmitting**            | Lerian STA is uploading the bytes.                |
| **Integrity check**         | BACEN is validating the declared SHA-256.         |
| **Received**                | BACEN has received the file.                      |
| **Delivered**               | BACEN has delivered the file to its destination.  |
| **In processing**           | BACEN is processing the file.                     |
| **Accepted**                | BACEN has accepted the file — a terminal success. |
| **Rejected / Inconsistent** | BACEN has refused the file — a terminal failure.  |

Upload retries within a **bounded budget**. Once Lerian STA exhausts the retry budget, it cancels the transfer. Each protocol also carries a bounded wall-clock **TTL** — 44 hours by default. Lerian STA must finish the upload before BACEN expires the protocol.

## Inbound discovery and download

***

Lerian STA polls BACEN for available files, per active tenant, on a configured cadence.

For each file, Lerian STA matches the file's **BACEN system code** against the tenant's **inbound source configurations**. It then downloads the bytes. It verifies the bytes against BACEN's reported **SHA-256**. It stores the file durably in object storage.

A hash mismatch or a download failure retries within a bounded budget. Once Lerian STA exhausts the budget, it quarantines the transfer to a terminal failure — inconsistent or canceled. It does not deliver the file to its source product.

## Operator actions

***

An operator can act only where the transfer's state and configuration permit it:

* **Cancel** only when the canonical state machine permits a transition to `Canceled`; it is not allowed from every non-terminal state.
* **Retry** an outbound transfer only when it is non-terminal, has upload budget remaining, and its protocol TTL has not expired.
* **Mark urgent** only for an inbound transfer in `AvailableForDownload` whose source configuration has urgency enabled; it fails closed otherwise.

Lerian STA also cancels a transfer when its BACEN protocol expires.
