Skip to main content

Module usage_reads

Module usage_reads 

Source
Expand description

Process-wide table of Anthropic/OAuth usage reads, one entry per account slot, shared by every LocalBroker in the process (a daemon can hold several brokers, one per runtime TokenCache).

  • Single-flight. One network read per slot at a time; a reader that waited for a read in flight takes that read’s result (success or failure) and sends nothing. The per-slot gate is never removed, so invalidating a cached reading can never open a second flight.
  • Negative cache. A transient failure (usage-endpoint 429, 5xx, timeout, transport) holds the slot: reads inside the hold return the same failure with no request. Holds back off 2, 4, 8, then 10 minutes; a longer Retry-After wins, capped at 10 minutes. A success clears the hold. Credential rejections are never held (their path is unchanged).
  • Last good. The slot’s last successful snapshot and the seat it was read from, which automatic selection may use in place of a read that failed transiently (see USAGE_READ_GRACE, UsageReads::last_good_for and quota_policy::SelectionRequest::grace).

Keys are the stable slot identity (credential file + storage key + usage endpoint), never the seat digest, which changes on token rotation. Last good is bound to the account it was read from: when the credential now in the slot carries an account id, the reading counts only for that same id (a refresh rotation keeps it; a re-login to another account drops it). Credentials without an account id (an Anthropic login whose profile lookup failed, or one made before ids were recorded) cannot tell a rotation from a re-login, so their reading counts only for the exact credential it was read with: a rotation loses grace until the next good read, and a re-login to another account is never graced on the previous occupant’s reading.

Structs§

TransientReadFailure
A usage read that failed for a reason that says nothing about the account: rate limit, server error, timeout or transport. Secret-free.
UsageReads
See the module docs. process_table is the one production instance.

Enums§

Fetched
What one network read produced, before the table classifies it.
ReadError
ReadPath
How a read was answered.

Constants§

NEGATIVE_BACKOFF_CAP
Longest hold, including one asked for by Retry-After.
NEGATIVE_BACKOFF_START
First hold after a transient usage-read failure.
USAGE_READ_GRACE
A last successful reading younger than this may stand in for a read that failed transiently. Never for an exhausted window, an auth rejection or an active cooldown.
USAGE_READ_TARGET
Tracing target of the per-read INFO line (passes the daemon log filter).

Functions§

process_table
The table shared by every broker in this process.

Type Aliases§

ReadResult