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:GitHub 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:proxy_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
A few low-effort options, any one would help:
- Bump the baked-in default
model_registry_client_versionon each release so it tracks the recent@openai/codexversion (or read it from a generated file at build time).
- Run
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the model_registry to better understand how it works.
Assistant
Let me explore other related files like the load_balancer, where the issue manifests:
Assistant
Now let me look at the tests directory:
Assistant
Now let me look at the model_fetcher tests:
Assistant
Now I have a good understanding. Let me explore the proxy entry points to understand more:
Assistant
Let me look at where models are requested - specifically with
client_version:Assistant
Let me now understand what files like the data dir is, where we could potentially store the version cache:
Assistant
Now I understand the issue. Let me look at what tests exist around the model registry to understand the snapshot/refreshing logic:
Assistant
Now let me think about the solution. The issue is fairly straightforward:
- The system fetches the Codex version from GitHub releases API.
- When GitHub rate-limits (HTTP 403) and there's no cached version, it falls back to the configured
model_registry_client_versiondefault, which is hardcoded to0.101.0. - When the configured version is too old, the upstream API doesn't return new models like
gpt-5.5. - Since
gpt-5.5isn't in the model registry, the load balancer rejects requests for it.
The suggested fixes include:
- Bumping the default version.
- Adding a secondary version source (npm).
- Caching the fetched version to disk so it survives container restarts.
- Honoring the client's
client_versionquery string as a hint.
Let me consider the best combination of fixes:
- Fix 1 (bump default): Simple but has the same issue over time (newer Codex versions keep coming).
Assistant
Good. Let me confirm the issue by writing a small reproduction:
Assistant
Issue reproduced. Now let me explore where the
client_versioncould be observed from inbound requests:Assistant
Let me look at how the client_version might come in via headers:
Assistant
The client may send
x-openai-client-version. Now let me design my fix:Assistant
Now let me think through my plan and implement the fix. The core issue is that when the GitHub API is rate-limited at startup AND there is no in-memory or on-disk cache, the system silently falls back to a stale configured default (
0.101.0), and the upstream API gates newer models behind newer client versions.My fix strategy:
- Primary fix: Persistent disk cache — Cache the last-known-good version to a file in the data dir. This survives container restarts and GitHub transient 403s. If we successfully fetch the version once, subsequent starts use the cached value until the cache TTL expires.
- Wire disk cache into the fallback chain so a successful prior fetch is preferred over the static
0.101.0default. - Honor the
x-openai-client-versionheader as a "freshness hint" that bumps the persistent cache when a newer client is observed (defense-in-depth).
Let me write the fix:
Assistant
Now I'm ready to write the fix:
Assistant
Let me simplify the code. The complex
record_observed_versionwas overdone. Let me rewrite it cleaner:Assistant
Now let me think about the second part: hooking into the request flow so the cache gets bumped when a newer client advertises itself. Let me look at where client version info might come in:
Assistant
Let me look at how Codex CLI sends version info:
Assistant
Let me see how to wire in
record_observed_version:Assistant
Let me look at where the proxy handles Codex requests and see if there's a good hook point:
Assistant
Now let me wire the cache-bump into the proxy request flow. I'll add a small helper and hook it into
_stream_responsessince that's the central Codex handler:Assistant
Let me add the helper function and a hook in
_stream_responses:Assistant
Now let me add the helper function and hook:
Assistant
Let me add the helper function in
codex_version.pyand wire it into_stream_responses:Assistant
Now let me add a helper function that extracts and records a version from request headers:
Assistant
The edit messed up the file. Let me fix it:
Assistant
The file is structured awkwardly with imports not at the top. Let me rewrite the file cleanly:
Assistant
Now let me verify the file imports cleanly:
Assistant
Excellent! The fix works correctly. Now let me also test the disk persistence layer:
Assistant
Now let me test edge cases (corrupt disk cache, etc.):
Assistant
Now let me see how the existing tests work to ensure I don't break anything:
Assistant
All existing tests pass. Now let me run the broader tests to make sure I haven't broken anything:
Assistant
Let me also run the full unit test suite to confirm nothing breaks:
Assistant
All 1889 tests pass. Now let me wire in the cache-bump on requests. Let me see where to add it:
Assistant
Let me add the hook in
_stream_responses:Assistant
Now let me add the import and the hook to
_stream_responses:Assistant
Now let me add the call inside
_stream_responses:Assistant
The edit left a duplicated line. Let me fix it:
Assistant
The edit broke the downstream_turn_state block. Let me reset and try again:
Assistant
Let me revert the api.py file and reapply properly:
Assistant
Now let me apply the changes correctly using sed:
Assistant
Now let me verify the file syntax is still correct:
Assistant
Let me also try to import the module:
Assistant
Let me run the relevant unit tests again to make sure nothing's broken:
Assistant
All 1889 tests still pass. Now let me also write a comprehensive script to reproduce the original issue and confirm my fix:
Assistant
The Scenario 3 test was mixing local cache and the singleton. Let me fix and retest:
Assistant
Excellent! All three scenarios work as expected. Now let me run the integration tests too to confirm nothing's broken:
Assistant
All 649 integration tests pass. Now let me clean up the temp test files and verify the final diff:
Assistant
Now let me also look at the chat_responses path to see if we should wire it there too. Let me check if ChatCompletions requests go through a similar path:
Assistant
Let me check the other response entry points to see if the hint should be applied there too:
Assistant
This is
/v1/responseswhich goes through_stream_responsesor_collect_responses. Let me check_collect_responses:Assistant
Let me also add the hook in
_collect_responsesfor consistency:Assistant
Hmm, but
_collect_responsesdoesn't accept forwarded_headers, so the hook should always userequest.headers. Let me apply the patch:Actually wait. Reading the issue description more carefully, the issue specifically mentions Codex CLI sends
client_version. Codex CLI uses/responseswhich goes through_stream_responses. The non-streaming/v1/responsesis for OpenAI Python SDK clients.But who knows - maybe a CLI client sometimes uses non-streaming? Let me add it there too to be safe. The cost is minimal.
Assistant
Let me run the unit tests again to make sure nothing broke:
Assistant
All tests pass. Now let me also run the integration tests for proxy responses to make sure nothing broke:
Assistant
All 52 tests pass. Let me also run the full integration suite once more to be sure:
Assistant
Let me also do a comprehensive sanity check with my reproduction script to verify the fix:
Assistant
Bug in edge case - empty string after strip. Let me fix:
Assistant
There's again a duplicate-line issue. Let me look at it more carefully and fix it:
Assistant
Now let me re-run the verification:
Assistant
All tests pass, including all edge cases! Let me re-run the existing tests to confirm no regressions:
Assistant
Now let me also do one more check - what happens when DEFAULT_HOME_DIR is writable (the normal case):
Assistant
Let me also write a simple test to verify the default home directory case:
Assistant
OK so the persistent path is
/root/.codex-lb/codex_version_cache.json. The issue earlier was that I was settingcache._persistent_pathAFTER the cache was already constructed, but the_load_persistenthad already run with the original path. Let me debug more carefully:Assistant
The disk cache works correctly. Let me also test that the data dir gets created automatically:
Assistant
Nested directories are created on demand. Now let me check what the expected default persistent path looks like for the production environment:
Assistant
Good. In docker, the home directory is
/var/lib/codex-lb, which is the data volume. So our persistent cache file will be at/var/lib/codex-lb/codex_version_cache.json, inside the persistent volume. This is exactly what we want.Now let me also make sure the OpenAPI response didn't break anything by looking at the actual change in api.py:
Assistant
Now let me check the full codex_version.py file once more:
Assistant
Let me verify the model registry also has a TTL that might delay the fix:
Assistant
Let me do one final comprehensive test:
Assistant
All tests pass! Let me clean up the test file and run the unit tests one more time:
Assistant
All 1889 unit tests pass. Now let me also think about the full diff one more time:
Assistant
Let me also check the websocket endpoint to see if I should wire the hint there too:
Assistant
Let me also add the hook to the websocket handler:
Assistant
Oops, looks like the patch got applied twice. Let me check around line 575:
Assistant
That's the
/v1/responses/websocketendpoint. The patch found both websocket handlers (the originalresponses_websocketat line ~430 andv1_responses_websocketat line ~560ish). Both are Codex websocket endpoints. That's actually correct - I want to bump on both.Let me verify the syntax is still correct:
Assistant
All 34 tests pass. Let me also run the websocket-related integration tests:
Assistant
Excellent! All 42 websocket tests pass. Let me also check the
internal_bridge_responsesendpoint since it also handles Codex responses:Assistant
internal_bridge_responsesflows through_stream_responseswhich is already hooked. Let me check the compact endpoint:Assistant
Let me look at the final diff:
Assistant
Let me run the full unit + integration test suite one more time to confirm everything passes:
Assistant
All 2538 tests pass. Let me also do one more comprehensive review by listing what we've changed and what the expected behavior is:
Assistant
Good, no temp files left. Let me also clean up any leftover disk cache files from my testing:
Assistant
Let me view the final version of api.py:
Assistant
The fix is in place and tests pass. Let me also think about whether to do anything special for the issue's other suggested fixes:
The issue mentions 4 potential fixes:
- Bump the baked-in default
model_registry_client_versionon each release - not done, would require release process changes. The disk cache + hint fixes the symptom without needing to release new images. - Add a secondary version source (npm) - not done, would add complexity. The disk cache is simpler and more robust.
- Cache the fetched version on disk - DONE ✅
- Honor the client's own
client_versionquery string as a hint - DONE ✅ (via header)
I've addressed suggestions 3 and 4, which together cover both:
- Existing installations (have prior disk cache)
- Fresh installations (no disk cache, but client advertises version in headers)
Let me do one last comprehensive review of the changes:
- Bump the baked-in default
Assistant
Let me now write a comprehensive summary and verify everything:
Assistant
The summary.py test had a bug (signature mismatch in
_session). Let me fix it:Assistant
The fix demonstrates the bug is resolved. Let me clean up:
Assistant
Now let me also clean up the test files in
/root/.codex-lb/that were created during testing:Assistant
Let me verify the final diff one more time before submission:
Assistant
Let me do one last test run to confirm nothing is broken:
Assistant
All 54 tests pass! Now let me make sure I've handled the checklist items:
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
- ✅ I created reproduction scripts that demonstrated the original issue (cache falling back to
0.101.0when GitHub returns 403) and confirmed the fix resolves it.
2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- ✅ I created reproduction scripts that demonstrated the original issue (cache falling back to
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.