Skip to content

[codex] Scope model cache by provider and account - #30984

Closed
won-openai wants to merge 1 commit into
mainfrom
won/fix-provider-scoped-model-cache
Closed

won-openai wants to merge 1 commit into
mainfrom
won/fix-provider-scoped-model-cache

Conversation

@won-openai

Copy link
Copy Markdown
Contributor

Why

Guardian intentionally resolves codex-auto-review through an offline model-catalog lookup. The on-disk models_cache.json was shared across every configured provider and ChatGPT account, while cache eligibility checked only client version and TTL.

That allowed another provider or account refresh to overwrite the file. The next OpenAI Guardian lookup then applied the foreign catalog and reported catalog_missing. The regression test reproduces the production symptom: cache an OpenAI catalog containing codex-auto-review, overwrite it from a second provider, then perform an offline OpenAI lookup. Before this fix, codex-auto-review disappeared.

What changed

  • Persist a cache key containing the configured provider ID, effective auth mode, and account ID.
  • Reject legacy or mismatched cache entries instead of applying another provider or account's catalog.
  • Refetch when an equal-ETag TTL renewal finds a mismatched cache key.
  • Pass the configured provider ID into the model manager and cover both provider and account contamination paths.

Validation

  • just test -p codex-models-manager — 40 passed.
  • just test -p codex-model-provider — 50 passed.
  • Scoped codex-app-server, codex-memories-write, and codex-core tests passed.
  • just fix -p codex-models-manager -p codex-model-provider -p codex-core -p codex-app-server -p codex-memories-write
  • just fmt

@nerdchanii

Copy link
Copy Markdown

I found an additional production-shaped cache dimension that this draft does
not currently cover: originator / client surface. Full report and
measurements: #33593.

The A/B reproduction uses:

  • the exact same Codex 0.144.5 executable SHA;
  • the same configured provider, effective auth mode, ChatGPT account,
    client version, token, URL, User-Agent, and CODEX_HOME;
  • two different app-server originators.

Changing only originator returns different /models ETags and different
gpt-5.6-sol metadata (v1/direct versus v2/code_mode_only). Both
app-servers persist to the same models_cache.json, and the refresh workers
repeat the overwrite approximately every three minutes.

With the current ModelsCacheKey proposed here, both producers still have the
same provider_id + auth_mode + account_id key. Adding originator only as
another validation field would prevent applying the other surface's catalog,
but the single last-writer-wins file would still evict the previous catalog and
lose its offline state.

The regression test that distinguishes the two designs is:

  1. Same provider/account/version, two originators, two ETags/catalogs.
  2. Alternate online refreshes in one CODEX_HOME.
  3. Drop both managers and recreate them.
  4. Perform offline lookup for each originator.
  5. Verify that each recovers its own catalog.

That likely requires independent per-identity slots/files (plus atomic
replacement), rather than only a cache eligibility key on one global file.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants