Skip to main content

Module quota_tracker

Module quota_tracker 

Source
Expand description

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

Unifies three signals into one verdict per provider:

  1. Self-tracked counter (primary)ProviderBudget tracks tokens oxios itself sent. The base signal. Works on ZAI/Minimax today with zero endpoint work.
  2. Reactive override (safety net) — when a real request 429s or hits QuotaExhausted / Transient (which is what classify.rs maps rate-limit/429 to), we mark the provider CooledDown until resets_at ?? now + window. This is the drift failsafe: even if the counter still shows headroom, a 429 always wins.
  3. Recalibration (accuracy upgrade) — where a [crate::api::quota::QuotaFetcher] exists, periodic recalibration snaps the self-tracked counter to real provider state.

§Decision rule

availability(p):
  if reactive_cooldown[p] active:    return CooledDown(cooldown[p].until)
  if not eligible:                    return Ineligible
  rem% = counter[p].remaining_percent # snapped to last recalibration
  if rem% <= min_remaining_percent:   return Draining
  return Available

Structs§

CooldownRecord
Reactive cooldown record. The 429 failsafe.
QuotaTracker
The QuotaTracker.
QuotaTrackerSnapshot
Snapshot of a provider’s tracker state — used by the API to render the live status panel.
RecalibrationRecord
One recalibration event for the report.

Enums§

Availability
Per-provider availability verdict (RFC-031 §4).
RecalibrationOutcome
Outcome of one recalibration attempt.