Skip to main content

Module quota_tracker

Module quota_tracker 

Source
Expand description

QuotaTracker — the per-provider availability decision layer (RFC-031 v2 §4).

Unifies three signals into one verdict per provider:

  1. Live quota snapshot (v2 primary) — when a [crate::api::quota::QuotaFetcher] exists for the provider, its most recent super::live_quota::QuotaSnapshot is the authoritative signal for both eligibility and remaining_percent. Auto-discovers providers that the user has not added to [[token-maxing.providers]].
  2. Self-tracked counter (fallback)ProviderBudget tracks tokens oxios itself sent. Used when no live fetcher exists, or as a consistency check between polls.
  3. Reactive cooldown (safety net) — when a real request 429s or hits QuotaExhausted / Transient, we mark the provider CooledDown until resets_at ?? now + window. Drift failsafe.

§Decision rule (v2)

availability(p):
  if reactive_cooldown[p] active:    return CooledDown(...)
  if live_snapshot(p) exists:
    if plan_type == Metered:         return Ineligible  // metered-never
    if plan_type == Subscription && usable signal:
      rem% = live.remaining_percent
      if rem% <= min_remaining_percent: return Draining
      return Available
  // v1 fallback: config gate + self-tracked counter.
  if !cfg.is_eligible(p):            return Ineligible
  rem% = counter[p].remaining_percent
  ...

Structs§

CooldownRecord
QuotaTracker
The QuotaTracker.
QuotaTrackerSnapshot
RecalibrationRecord

Enums§

Availability
Per-provider availability verdict (RFC-031 §4).
RecalibrationOutcome