Interface IMailAnsweringSpendLedger
- Namespace
- MailFathom.Application.Retrieval.AskMail
- Assembly
- MailFathom.Application.dll
Counts what answering has cost across the current period, and decides whether another question fits inside it.
public interface IMailAnsweringSpendLedger
Remarks
One ledger for the whole deployment, because a ceiling over a period is one answer about it: a ledger per scope, per process, or per replica would let each concurrent question believe it was the first. Every member is safe to call from several runs at once.
It is the deployment's and it is durable, because the ceiling is worded as the deployment's: several replicas each counting their own would admit the replica count times what their operator agreed to, at a provider that bills for it, and a restart would begin every period again with nothing spent. ADR 0031 records the trade that was reversed to get there: a write per provider call was refused on the grounds that a question opens none of its own, and a write per admitted run was not, because a run is already about to spend a provider's tokens.
The admission is a decision and never a wait. A question over the ceiling is refused with an answer the caller can act on rather than held until the period turns over, because holding it would convert a spend ceiling into a queue of requests occupying the endpoint that serves the rest of the surface.
Two members and no way to read what has been spent, because nothing above this boundary acts on that figure: a use case decides whether to answer and never how close the period is to its ceiling. What an operator reads is published by whatever implements this, as instruments rather than as a call.
Methods
- RecordSpendAsync(ChatTokenUsage, CancellationToken)
Adds what one run consumed to the current period.
- TryAdmitRunAsync(CancellationToken)
Takes an allowance for one run, if the current period has one left.