ISSUE DESCRIPTION Stale 'clientversion' fallback causes 503 'noplansupportformodel' for…
- User
ISSUE DESCRIPTION
Stale 'client_version' fallback causes 503 'no_plan_support_for_model' for newer models (e.g. gpt-5.5) when GitHub releases API rate-limits
Summary
When
app/core/clients/codex_version.pycannot fetch the latest codex release fromapi.github.com/repos/openai/codex/releases/latest(e.g. anonymous-rate-limited with HTTP 403), it logs:codeGitHub releases API returned HTTP 403 GitHub fetch failed and no cached version; falling back to settings default 0.101.0and falls back to
Settings.model_registry_client_version(default0.101.0). The model registry refresh (app/core/openai/model_refresh_scheduler.py→clients/model_fetcher.fetch_models_for_plan) then asks upstream/codex/models?client_version=0.101.0. Upstream gates newer model slugs behind newer client versions, so the response excludes e.g.gpt-5.5.As a result,
ModelRegistry.model_plansnever gets agpt-5.5entry,_filter_accounts_for_modelinmodules/proxy/load_balancer.py:1168returns an empty set, and every Codex request forgpt-5.5is rejected with:codeproxy_error_response status=503 code=no_plan_support_for_model message=No accounts with a plan supporting model 'gpt-5.5'…even though the actual Codex CLI is on
0.130.0and the account's ChatGPT subscription does support the model (calling/backend-api/codex/models?client_version=0.130.0through the LB returns 200 with the model present).Reproduction
- Run
ghcr.io/soju06/codex-lb:1.17.0on a host where anonymous GitHub API requests are 403'ed. - Connect a current Codex CLI (e.g.
@openai/codex@0.130.0) configured withmodel = \"gpt-5.5\". - Observe startup log line:
GitHub fetch failed and no cached version; falling back to settings default 0.101.0
- Every
POST /backend-api/codex/responsesreturns 503 with codeno_plan_support_for_model.
Setting
CODEX_LB_MODEL_REGISTRY_CLIENT_VERSION=0.130.0and recreating the container fully resolves the symptom.Suggested fixes
- Run
- Assistant
I'll start by exploring the repository to understand its structure and locate the relevant files mentioned in the issue description. Let's first get an overview.
- Assistant
Let me get a better view of the repository structure.
- Assistant
Let me explore the key files mentioned in the issue. First, let me look at the codex_version.py file:
- Assistant
Now let me look at the settings file to understand the default value:
- Assistant
Let me look at the model_fetcher.py to understand how the version is used:
- Assistant
Now let me check the test files related to codex_version to understand the expected behavior:
- Assistant
Let me look at the model refresh scheduler and the load balancer to understand the full flow:
- Assistant
Now let me check the tests for the model_fetcher to understand the expected behavior:
- Assistant
Let me check the load_balancer.py to understand the
_filter_accounts_for_modelfunction: - Assistant
Let me view the _filter_accounts_for_model function:
- Assistant
Let me look at the model_registry.py to understand how plan_types_for_model works:
- Assistant
Let me see the full model_registry.py:
- Assistant
Let me search for where client_version might be passed by the client:
- Assistant
Let me look at how the proxy receives requests from the Codex CLI and check the proxy API:
- Assistant
Let me check how the proxy handles requests and if there's any version information passed:
- Assistant
Let me look more at how the proxy handles requests and where client version info might be passed:
- Assistant
Let me look at the proxy's responses endpoint, which is the main endpoint that Codex CLI uses:
- Assistant
Let me look at how requests come in and check if the Codex CLI sends a
client_version: - Assistant
Let me look at how the proxy service handles requests and see if there's a way to extract client version:
- Assistant
Let me look at the relevant section in service.py:
- Assistant
Good - the Codex CLI sends
x-openai-client-versionheader. Now let me look at the proxy responses endpoint to understand the flow: - Assistant
Let me look at the responses endpoint:
- Assistant
Now I need to understand the full picture. Let me check how the version is used in the load balancer and what the client sends:
- Assistant
Now I understand the issue. Let me create a reproduction script first to verify my understanding:
- Assistant
I need to run the test from within the project, likely in the virtual environment.
- Assistant
Let me try using the venv Python directly from the project directory.
- Assistant
Good, I've reproduced the issue. Now let me understand the full settings and how version is used:
- Assistant
Let me look at how the proxy service handles requests to see where client version is available:
- Assistant
Let me check the load_balancer.py proxy_responses function to understand the flow:
- Assistant
Let me check if there are any query parameters being extracted from requests:
- Assistant
Let me look at the service.py to see where the x-openai-client-version header is used:
- Assistant
Let me look at how the proxy responses endpoint works to see where client version might be available:
- Assistant
Let me look at the
_stream_responsesfunction which is called by the mainresponsesendpoint: - Assistant
Now let me understand the full issue. The problem is that when GitHub API is rate-limited, the codex version cache falls back to a stale
0.101.0, which causes the model registry to exclude newer models. Let me look at how settings work: - Assistant
Now let me look at the existing test structure to understand how to approach the fix:
- Assistant
Now let me look at what tests exist for model_fetcher and model_refresh_scheduler:
- Assistant
Let me now look at how the load balancer's _filter_accounts_for_model function works and how the proxy handles requests:
- Assistant
Let me look at how the settings handle file paths and see how disk caching could work:
- Assistant
Now let me check if there's already any disk caching infrastructure in the codebase:
- Assistant
Now let me understand what approach would be best. Looking at the issue description, they suggest several fixes. Let me think about which approach is most practical and robust:
-
Bump the baked-in default
model_registry_client_versionon each release - This is the simplest approach but still has the problem of being stale between releases. -
Add a secondary version source (npm registry) - This is good because npm is not rate-limited the same way as GitHub API.
-
Cache the fetched version on disk - This helps survive container restarts and transient failures.
-
Honor the client's own
client_versionquery string as a hint - This is the most robust approach because it uses the actual client version.
Looking at the code, I think the best approach is to combine approaches 2 and 3, and also make it so that the client version can be used as a hint.
Let me look at how the proxy handles requests to see if we can extract the client version:
-
- Assistant
Now I have a good understanding of the issue. Let me create a plan to fix it:
- Add npm registry as a secondary version source in
codex_version.pywhen GitHub fails - Cache the fetched version on disk so it survives container restarts
- Add a method to accept client version hints from the proxy when a newer client connects
Let me start by looking at how the proxy handles requests to see where we can intercept client version:
- Add npm registry as a secondary version source in
- Assistant
Let me look at how the proxy handles requests to see where we can extract the client version from headers:
- Assistant
Now I understand the full picture. Let me plan my fix:
The issue is:
- When GitHub API is rate-limited (HTTP 403), the codex version cache falls back to the settings default of
0.101.0 - This stale version is used to fetch models from upstream
- Upstream gates newer models behind newer client versions
- So models like
gpt-5.5are not included when usingclient_version=0.101.0 - As a result,
ModelRegistry.model_plansnever gets agpt-5.5entry - Every request for
gpt-5.5is rejected with 503no_plan_support_for_model
The suggested fixes are:
- Bump the baked-in default
model_registry_client_versionon each release - Add a secondary version source (npm registry)
- Cache the fetched version on disk
- Honor the client's own
client_versionquery string as a hint
- When GitHub API is rate-limited (HTTP 403), the codex version cache falls back to the settings default of
- Assistant
Now let me look at how the startup works and how the proxy handles requests:
- Assistant
Let me look at what the Codex CLI sends in headers:
- Assistant
Now let me understand the full flow better. Let me look at how the proxy handles requests and where the client's version can be extracted:
- Assistant
Let me look at how requests are handled in the load_balancer:
- Assistant
The load_balancer doesn't seem to have headers references. Let me look at the proxy service:
- Assistant
Let me now check what's in the settings for data directory:
- Assistant
Now I have a good understanding of the issue. Let me implement a comprehensive fix. The approach will be:
- Add npm registry as a secondary version source - npm is not rate-limited like GitHub
- Cache the fetched version on disk - survives container restarts
- Honor client's
client_versionhint - when a newer Codex CLI connects, use its version to bootstrap
Let me start implementing:
- Assistant
Let me use the correct syntax for the edit command:
- Assistant
Now I need to rewrite the CodexVersionCache class with the new features. Let me do that:
- Assistant
Let me verify the complete file:
- Assistant
Good. Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
Good, the existing tests pass. Now let me check if there are any other tests that might be affected:
- Assistant
Let me also run the model refresh scheduler test:
- Assistant
Let me run all unit tests to make sure nothing is broken:
- Assistant
All unit tests pass. Now I need to think about what else needs to be done. Let me look at how the proxy handles requests to see if we should hook up the
offer_versionmethod to thex-openai-client-versionheader: - Assistant
Let me look at the service.py to understand how the proxy handles requests and where we can hook in:
- Assistant
Let me look at the proxy service's stream_responses method more carefully to understand where headers are processed:
- Assistant
Let me look at the proxy service's stream_responses method:
- Assistant
Let me look at the _stream_responses function in api.py to see where we can add the client version hint:
- Assistant
Let me look for a good place to hook in the client version hint. I'll check if there's a middleware or dependency injection point:
- Assistant
Let me look at how the ProxyContext is created and if it receives the request headers:
- Assistant
Let me look for ProxyContext in the codebase:
- Assistant
Let me search more broadly for ProxyContext:
- Assistant
Let me look at the ProxyContext class and get_proxy_context function to understand where we can hook in the client version hint.
- Assistant
Let me look at how the responses endpoint is called and where I can add the client version hint. Let me check the
_stream_responsesfunction more carefully: - Assistant
Let me look at the full _stream_responses function to see where to add the client version hint:
- Assistant
Now let me also look at how chat completions are handled to see if we need to handle that case too:
- Assistant
Now let me implement the client version hint in the proxy layer. I'll add it to the
_stream_responsesfunction: - Assistant
Now I need to define the
_maybe_offer_client_versionfunction somewhere in the api.py file. Let me find a good place to add it: - Assistant
Let me look at the imports section to add the helper function:
- Assistant
Now I need to add the import for the codex version cache and the helper function. Let me first add the import:
- Assistant
I accidentally created a duplicate section. Let me fix this:
- Assistant
Let me fix the duplicate import:
- Assistant
I have a duplicate import. Let me reset the file and start fresh:
- Assistant
Now let me make a clean edit. First, let me add the import:
- Assistant
Good, now I need to add the helper function. Let me find a good place to add it:
- Assistant
Now I need to add the helper function. Let me add it before the router definition:
- Assistant
I see there's a duplicate "router = APIRouter(" line. Let me fix that:
- Assistant
Good, the duplicate is fixed. Now I need to add the call to
_maybe_offer_client_versionin the_stream_responsesfunction. Let me find that function again: - Assistant
Now I need to add the call to
_maybe_offer_client_versionin the_stream_responsesfunction. Let me edit that section: - Assistant
I see that I accidentally removed the "owns_reservation" and "reservation" lines. Let me fix this:
- Assistant
Now let me check if there are any issues with the settings initialization. Let me look at how get_settings works:
- Assistant
Let me check the get_settings function to understand how it works:
- Assistant
Let me check if there's any caching for get_settings:
- Assistant
Good,
get_settingsis cached withlru_cache. Now let me check if the module-level initialization could cause issues. Let me simplify the _default_cache_file function: - Assistant
I see there's still a duplicate function. Let me fix this:
- Assistant
I keep getting duplicates. Let me reset and rewrite the entire file cleanly:
- Assistant
Let me rewrite the entire file cleanly:
- Assistant
Let me use bash to write the file directly:
- Assistant
Now let me also restore the api.py file and make clean changes:
- Assistant
Let me write the api.py file with the minimal changes needed. First let me check what the current file looks like:
- Assistant
Now let me make the changes to the api.py file using sed:
- Assistant
Now I need to add the helper function. Let me find where to add it:
- Assistant
Let me add the helper function after line 146. I'll use sed to insert it:
- Assistant
Let me verify the changes:
- Assistant
Now I need to add the call to
_maybe_offer_client_versionin the_stream_responsesfunction. Let me find it: - Assistant
Let me look at the function:
- Assistant
Now I need to add the call to
_maybe_offer_client_versionin the_stream_responsesfunction. Let me use sed to insert it: - Assistant
Let me add the _maybe_offer_client_version call before apply_api_key_enforcement on line 1829:
- Assistant
Let me verify the changes:
- Assistant
Good! Now let me run the existing tests to make sure everything still works:
- Assistant
Good, the existing tests pass. Now let me run the full unit test suite to make sure I haven't broken anything:
- Assistant
All 1889 unit tests pass! Now let me create a test script to verify that my fix resolves the issue described in the issue:
- Assistant
Excellent! All tests pass. Now let me verify that the existing tests still pass:
- Assistant
All tests pass. Now let me run the full unit test suite one more time to make sure everything is working correctly:
- Assistant
All 1889 unit tests pass! Now let me create a summary of the changes I made and verify the fix resolves the original issue. Let me first check if there are any integration tests related to this:
- Assistant
Good. Now let me review the changes I've made by looking at the diff:
- Assistant
Let me check the full diff to make sure everything looks good:
- Assistant
The diff looks clean and complete. Let me now run the full unit test suite one more time to make sure everything is working correctly:
- Assistant
All 1889 unit tests pass. Let me also run the integration tests to make sure nothing is broken:
- Assistant
Excellent! All integration tests pass as well. Now let me create a final verification script that demonstrates the fix resolves the original issue:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.