Cache provider model catalogs on disk - #522
Open
mjlbach wants to merge 2 commits into
Open
Conversation
Store the authenticated Codex model catalog under ~/.fx/cache/codex-models-<account-hash>.json and serve it for six hours before refetching. Entries are gated on a cache schema version and the Codex protocol client version, partitioned per account, written atomically, and validated with the same rules as endpoint responses. Every cache failure is a miss, never an error. The cache is disabled under the FX_E2E_OPENAI_CODEX_MODELS_URL override so e2e runs observe every request and perform no durable writes. Measured live: cold catalog fetch 1,221 ms; warm cache hit ~8 ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Extract the envelope, load, and store mechanics into core/gateway/catalog_disk_cache.zig and key every entry on a provider config: file prefix, format version, TTL, and body bound. Codex keeps its protocol client version as the format gate; Grok and the gateway gate on the fx build version because their parse rules live in this binary. Grok caches both catalog endpoints as one unit so a hit reproduces the same subscription/modalities join the network path performs. The gateway caches the raw catalog body at fetchModelCatalogResponse, the choke point shared by the runtime provider and the picker, partitioned by credential source, team, account (or credential when no stable account id exists), and resolved URL; bodies are stored only after they parse with the full-view rules. Each provider disables its cache under its loopback e2e endpoint overrides. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
~/.fx/cache/<provider>-models-<partition-hash>.jsonwith a six-hour TTL, so a cold CLI process stops paying an authenticated catalog fetch before its first requestcore/gateway/catalog_disk_cache.zig: a versioned envelope gated on a cache schema version and a provider format version, bounded file and body sizes, temp-file-and-rename writes, and every cache read/write failure treated as a miss rather than an errorfetchModelCatalogResponse, the choke point shared by the runtime provider and the model picker; partitioned by credential source, team, account (or the credential itself when no stable account id exists), and resolved URL; bodies are stored only after they parse with the full-view rules, so a cached body can never be weaker than a fetched oneMeasured live against
chatgpt.com: cold Codex catalog fetch 1,221 ms, warm cache hit ~8 ms, on an otherwise identical request path. Note the model picker andfx modelsalso serve from the cache within the TTL.Prior art at pinned revisions: Codex uses a client-version-gated disk cache with a five-minute TTL (
models-manager/src/cache.rs,manager.rs); OpenCode serves disk or embedded metadata immediately and refreshes in the background under a cross-process lock (models-dev.ts); pi compiles the Codex catalog into the release (openai-codex.models.ts).Testing
zig fmt --checkon touched fileszig build test— full suite passes; new tests cover the shared envelope (fresh round trip, stale/future/version-mismatch/schema-mismatch/malformed/missing entries, empty and oversized store rejection), Codex reviewer-model validation of cached bodies, the Grok combined-body round trip, and gateway partition separation by credential, team, URL, and public accessbun test tui-auth-source-selection.test.ts(54) andgateway-stream-lifecycle.test.tspass;cli.test.tsis 117/118, with the one failure (fx status --jsonexpectingupdate_channel: "stable"against a local dev build) reproducing identically onorigin/maincatalog cache outcome=missthenstored; the next logsoutcome=hit🤖 Generated with Claude Code