pub struct ProviderCallBudget { /* private fields */ }Expand description
A shared limit on underlying provider turns across cloned requests.
Transports must consume one slot immediately before each provider attempt, including repairs and restart retries. Failed attempts also consume a slot. An in-process harness run is one attempt however many model requests it sends, so one slot means the same on every backend.
Implementations§
Source§impl ProviderCallBudget
impl ProviderCallBudget
Sourcepub fn with_ledger(
remaining: usize,
ledger: Arc<dyn ProviderCallLedger>,
) -> Self
pub fn with_ledger( remaining: usize, ledger: Arc<dyn ProviderCallLedger>, ) -> Self
Creates a budget whose shared pool reports each charge and refund to
ledger. remaining is the credit still available, for example after
restoring spending recorded before a restart.
Sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Returns available shared calls plus this budget’s reserved initial call. Calls reserved by other budgets are unavailable to this budget.
Sourcepub fn extend(&self, calls: usize)
pub fn extend(&self, calls: usize)
Adds calls to this budget’s shared pool, for every clone and
reservation that draws from it. Enclosing ceilings keep their own
limits. The ledger is not told: a grant raises the limit the host
recorded, and no call is spent or refunded.
Sourcepub fn with_ceiling(self, ceiling: Self) -> Self
pub fn with_ceiling(self, ceiling: Self) -> Self
Adds an enclosing workflow ceiling while preserving the caller’s own limit. Each distinct shared counter charges every provider attempt once.
Sourcepub fn reserve(&self) -> Result<Self, OneShotError>
pub fn reserve(&self) -> Result<Self, OneShotError>
Atomically reserves one initial attempt in a child budget.
The returned budget and its clones redeem that call once through
consume; subsequent attempts charge the shared pool normally.
Dropping all child clones before redemption refunds the reservation
to its source. Admission must retain the child through worker delivery.
§Errors
Returns the same exhaustion error as consume when no call is
available.
Sourcepub fn ensure_available(&self) -> Result<(), OneShotError>
pub fn ensure_available(&self) -> Result<(), OneShotError>
Checks for exhaustion without charging a turn at an outer boundary.
§Errors
Returns an input-size reduction error when no slots remain.
Sourcepub fn consume(&self) -> Result<(), OneShotError>
pub fn consume(&self) -> Result<(), OneShotError>
Charges one underlying provider attempt atomically. Redeems a reserved initial call before charging the shared pool.
§Errors
Returns an input-size reduction error before execution when exhausted. Failed consumption refunds every debit, including reserved credit.