Effect and retry declarations¶
Every method in a block's interface declares two things about its behaviour:
- Its effect: what it changes. A method may change nothing, only read, change state Xratu manages, or change something outside Xratu, such as charging a card or sending an email.
- Its retry behaviour: what may safely happen when a call's outcome is uncertain, for example when the request was sent and the response was lost.
Both are part of the interface and of its hash. The kernel decides from them whether an uncertain call may be repeated, repeated with the same key, or settled through a recovery method.
Why both are declared¶
Neither can be read from your code, and neither follows from the other. A method that charges a card changes the outside world, yet is safe to repeat with an idempotency key the payment provider recognises. A method that only reads can still be unsafe to repeat when it advances a cursor. Only the author knows which holds, so the author declares it.
Example: a charge you can check afterwards¶
The ledger block's generated guest interface shows both declarations on each method:
class LedgerGuest(Protocol):
def charge(self, request: ChargeRequest, receipt: str) -> Awaitable[TaskRef]: ...
# method ordinal 7; effect mutating_external; retry recoverable
def charge_status(self, receipt: str) -> str | Awaitable[str]: ...
# method ordinal 9; effect read_only; retry retry_safe
charge changes the outside world, so charging again after a lost response
could charge twice. It is declared recoverable instead: the caller sends a
receipt with the request, and after an uncertain call it asks
charge_status what happened, using the same receipt. The receipt travels in
the request, because the response is what may have been lost. charge_status
only reads, so repeating it is always safe.
Combinations that are refused¶
Compilation refuses declarations that contradict each other:
- "Always safe to repeat" on a method that changes state. Only a method that changes nothing or only reads may declare it.
- An external change with no retry behaviour. A method that changes something outside Xratu states what may happen after an uncertain call.
- A recovery that cannot work. A recoverable method names one of its own parameters as the receipt, and a method of the same interface as the recovery. The recovery method accepts the receipt's type and only reads.
The full set of effect and retry values is in the XCI source reference.
Changing a declaration¶
Changing a method's effect or retry declaration breaks its callers even when the parameters stay the same, because their retry handling was written for the old declaration. It needs a new major version. See Interface evolution and compatibility.