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-Afterwins, 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_forandquota_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§
- Transient
Read Failure - A usage read that failed for a reason that says nothing about the account: rate limit, server error, timeout or transport. Secret-free.
- Usage
Reads - See the module docs.
process_tableis the one production instance.
Enums§
- Fetched
- What one network read produced, before the table classifies it.
- Read
Error - Read
Path - 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.