This repository was archived by the owner on Sep 30, 2026. It is now read-only.
Repository navigation
Conversation
added 2 commits
August 13, 2026 17:12
Each live jcode session kept its own in-memory usage cache, so N sessions
meant N independent pollers hitting the provider usage endpoints, the likely
cause of the constant 429s. quota-axi now owns one host-wide on-disk usage
cache; this points jcode's Anthropic and OpenAI usage fetchers at that same
file so the whole host makes roughly one usage fetch per provider-account per
TTL regardless of session count (Phase 1 of ADR 0031).
Two-layer design: the existing per-session in-memory cache stays as L1; the
shared file (${XDG_CACHE_HOME:-~/.cache}/quota-axi/quotas.json, schemaVersion
1) is L2, read-through and write-through. L2 is scoped to the host-active
account (host-global disk state read the same way by every session and by
quota-axi) and only successful fetches are written through, so all error and
429 backoff stays owned by L1 and existing backoff semantics are preserved.
The on-disk format, window identities, atomic 0600 write, and provider
ordering byte-match quota-axi's merged implementation so both tools share one
file rather than maintaining parallel formats.
Colocated tests cover round-trip conversion, byte-level schema match against
quota-axi, reading a real quota-axi-written record, stale-record rejection,
error-state exclusion (backoff preservation), schema-version guarding, and
upsert ordering.
Owner
Author
|
Superseded by #23 (rebased version of the same usage-cache converge change), which is being landed. Closing this original unmerged PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Point jcode's Anthropic and OpenAI usage fetchers at quota-axi's shared on-disk usage cache (read-through, write-through) so N live jcode sessions stop polling the provider usage endpoints independently. This is Phase 1 of the account-switch orchestrator (ADR 0031).
Today each jcode session keeps its own in-memory usage cache (300s TTL, 900s backoff on 429). With N live sessions that is N independent pollers hitting the Anthropic and OpenAI usage endpoints, the likely cause of the constant 429s. quota-axi now owns one host-wide on-disk usage cache; this change makes jcode read and write THROUGH that same file so the whole host makes roughly one usage fetch per provider-account per TTL regardless of session count.
What changed
crates/jcode-base/src/usage/shared_cache.rs: the L2 layer. Reads and writes${XDG_CACHE_HOME:-~/.cache}/quota-axi/quotas.json(schemaVersion1), byte-matching quota-axi's on-disk format, window identities, atomic 0600 write, and provider ordering.usage.rs/accessors.rs/provider_fetch.rs: the Anthropic and OpenAI usage-fetch paths now check L1 (per-session in-memory) first, then L2 (shared file) read-through, then hit the endpoint and write-through to both.Design
freshrecords; errors and 429s never reach the shared file. jcode does the same: only successful fetches are written through, and all error/rate-limit backoff (the existing 900s-on-429 behavior) stays entirely in L1. The shared file can never mask an error or shorten a backoff.state.refreshedAt) are ignored on read, matching jcode's L1CACHE_DURATIONand quota-axi's ~5min TTL, so a stale shared file cannot pin sessions to old data.five_hour/session,seven_day/weekly); quota-axi rejects a whole codex record on an unrecognized window id. jcode'ssparkwindow has no codex identity and stays L1-only.Testing
Built test-first for the L2 module. Colocated unit tests in
usage/shared_cache/tests.rs(9 tests, all passing) cover:cargo clippy -p jcode-baseis clean.Coverage gap: the unit tests exercise the L2 module (format, conversions, freshness, backoff exclusion) directly. There is no automated multi-process end-to-end test asserting host-wide fetch rate collapses from N to 1, because that needs multiple live authenticated jcode sessions against the live provider endpoints. The single-fetch property follows from the read-through + TTL logic that the unit tests do cover.