The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): ask the models catalog as the newest client so GPT-6 Sol/Luna show up (#119412)
teknium11d10cef8363a
diff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex b668b7b027c..83b1cc71014 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -1813,12 +1813,37 @@ _codex_oauth_context_cache: Dict[str, Tuple[Dict[str, int], float]] = {}_codex_oauth_max_context_cache: Dict[str, Dict[str, int]] = {}_CODEX_OAUTH_CONTEXT_CACHE_TTL = 3600 # 1 hour# The Codex models endpoint reads ``client_version`` as a Codex CLI compatibility version and-# hides models whose ``minimal_client_version`` is newer, so a made-up version (the old-# "1.0.0") silently drops future models. "0.0.0" is the backend's ungated sentinel returning-# the full account catalog; other out-of-sequence values return an empty catalog and omitting-# the parameter is HTTP 400.+# hides models whose ``minimal_client_version`` is newer. "0.0.0" used to be the ungated sentinel+# returning the whole account catalog, but since the GPT-6 Sol/Luna rollout it returns a FROZEN+# legacy list (astra + the 5.6 trio) while any version at or above the newest+# ``minimal_client_version`` (0.155.0, 1.0.0, 99.0.0 alike, live 2026-09-22) returns everything the+# account is entitled to (#119412). So ask as the newest possible client first and keep "0.0.0" as+# the fallback for the day the backend rejects out-of-sequence versions again (it used to return an+# empty catalog for them; omitting the parameter is HTTP 400).+CODEX_MODELS_CATALOG_ENDPOINT = "https://chatgpt.com/backend-api/codex/models"+CODEX_NEWEST_CLIENT_VERSION = "99.0.0"CODEX_UNGATED_CLIENT_VERSION = "0.0.0"-CODEX_MODELS_CATALOG_URL = f"https://chatgpt.com/backend-api/codex/models?client_version={CODEX_UNGATED_CLIENT_VERSION}"+CODEX_MODELS_CATALOG_URLS = tuple(+ f"{CODEX_MODELS_CATALOG_ENDPOINT}?client_version={v}"+ for v in (CODEX_NEWEST_CLIENT_VERSION, CODEX_UNGATED_CLIENT_VERSION)+)+++def fetch_codex_catalog_entries(get: Callable[[str], Any]) -> Tuple[List[Any], Optional[int]]:+ """``(models, last_status)`` from the first catalog URL that answers HTTP 200 with a non-empty+ ``models`` list; ``get(url)`` is any client returning an object with ``status_code``/``json()``.+ An empty or non-200 answer on the newest-client URL falls through to the ``0.0.0`` sentinel."""+ status: Optional[int] = None+ for url in CODEX_MODELS_CATALOG_URLS:+ resp = get(url)+ status = resp.status_code+ if status != 200:+ continue+ data = resp.json()+ entries = data.get("models") if isinstance(data, dict) else None+ if isinstance(entries, list) and entries:+ return entries, status+ return [], statusdef _codex_oauth_token_fingerprint(access_token: str) -> str:@@ -1842,17 +1867,18 @@ def _fetch_codex_oauth_context_lengths_with_source(access_token: str) -> Tuple[Dheaders = {"Authorization": f"Bearer {access_token}", **codex_account_headers(access_token)}try:_ensure_requests()- resp = requests.get(CODEX_MODELS_CATALOG_URL, headers=headers, timeout=(5, 10), verify=_resolve_requests_verify())- if resp.status_code != 200:- logger.debug("Codex /models probe returned HTTP %s; falling back to hardcoded defaults", resp.status_code)+ entries, status = fetch_codex_catalog_entries(+ lambda url: requests.get(url, headers=headers, timeout=(5, 10), verify=_resolve_requests_verify())+ )+ if status != 200:+ logger.debug("Codex /models probe returned HTTP %s; falling back to hardcoded defaults", status)return {}, False- data = resp.json()except Exception as exc:logger.debug("Codex /models probe failed: %s", exc)return {}, Falseresult: Dict[str, int] = {}max_result: Dict[str, int] = {}- for item in data.get("models", []) if isinstance(data, dict) else []:+ for item in entries:slug, ctx, max_ctx = (item.get("slug"), item.get("context_window"), item.get("max_context_window")) if isinstance(item, dict) else (None, None, None)if isinstance(slug, str) and isinstance(ctx, int) and ctx > 0:result[slug.strip()] = ctxdiff --git a/hermes_cli/codex_models.py b/hermes_cli/codex_models.pyindex 68a70ba1ded..34f36334aeb 100644--- a/hermes_cli/codex_models.py+++ b/hermes_cli/codex_models.py@@ -161,12 +161,8 @@ def _fetch_models_from_api(access_token: str) -> List[str]:# masquerades as "no models") and, for residency-enforced workspaces, the residency header.from agent.codex_headers import codex_account_headersheaders = {"Authorization": f"Bearer {access_token}", **codex_account_headers(access_token)}- from agent.model_metadata import CODEX_MODELS_CATALOG_URL- resp = httpx.get(CODEX_MODELS_CATALOG_URL, headers=headers, timeout=10)- if resp.status_code != 200:- return []- data = resp.json()- entries = data.get("models", []) if isinstance(data, dict) else []+ from agent.model_metadata import fetch_codex_catalog_entries+ entries, _status = fetch_codex_catalog_entries(lambda url: httpx.get(url, headers=headers, timeout=10))except Exception as exc:logger.debug("Failed to fetch Codex models from API: %s", exc)return []diff --git a/tests/hermes_cli/test_codex_models.py b/tests/hermes_cli/test_codex_models.pyindex 66b7657726a..7af4137eb66 100644--- a/tests/hermes_cli/test_codex_models.py+++ b/tests/hermes_cli/test_codex_models.py@@ -286,45 +286,72 @@ class TestNormalizeModelForProvider:assert cli.model == "gpt-5.5"-def test_catalog_requests_use_ungated_client_version(monkeypatch):- """Both catalog request sites send the backend's ungated ``0.0.0`` sentinel: the endpoint- hides models whose ``minimal_client_version`` is newer than ``client_version``, so a- made-up version silently drops future models."""- import sys+def _gated_codex_catalog(seen_urls):+ """Backend shape since the GPT-6 Sol/Luna rollout (#119412): the ``0.0.0`` sentinel answers a+ frozen legacy list, any newer client version answers the full account catalog."""from urllib.parse import parse_qs, urlparse- from agent import model_metadata- from hermes_cli import codex_models-- seen_urls = []-class _FakeResp:status_code = 200+ def __init__(self, url):+ self.version = parse_qs(urlparse(url).query)["client_version"][0]+def json(self):- return {"models": []}+ models = [{"slug": "gpt-5.6-sol", "visibility": "list", "context_window": 272000}]+ if self.version != "0.0.0":+ models.append({"slug": "gpt-6-sol", "visibility": "list", "context_window": 272000})+ return {"models": models}- class _FakeHttpx:- @staticmethod- def get(url, headers=None, timeout=None):- seen_urls.append(url)- return _FakeResp()+ def get(url, headers=None, timeout=None, verify=None):+ seen_urls.append(url)+ return _FakeResp(url)- class _FakeRequests:- @staticmethod- def get(url, headers=None, timeout=None, verify=None):- seen_urls.append(url)- return _FakeResp()+ return get- monkeypatch.setitem(sys.modules, "httpx", _FakeHttpx)- codex_models._fetch_models_from_api(access_token="tok")- monkeypatch.setattr(model_metadata, "requests", _FakeRequests)++def test_catalog_requests_ask_as_the_newest_client(monkeypatch):+ """Both catalog request sites (picker + context probe) send a client version newer than every+ ``minimal_client_version`` on the first try, so account-visible GPT-6 Sol/Luna are not hidden+ behind the frozen ``0.0.0`` legacy list (#119412)."""+ import sys+ from urllib.parse import parse_qs, urlparse++ from agent import model_metadata+ from hermes_cli import codex_models++ seen_urls = []+ get = _gated_codex_catalog(seen_urls)+ monkeypatch.setitem(sys.modules, "httpx", type("_FakeHttpx", (), {"get": staticmethod(get)}))+ assert "gpt-6-sol" in codex_models._fetch_models_from_api(access_token="tok")+ monkeypatch.setattr(model_metadata, "requests", type("_FakeRequests", (), {"get": staticmethod(get)}))monkeypatch.setattr(model_metadata, "_ensure_requests", lambda: None)monkeypatch.setattr(model_metadata, "_codex_oauth_context_cache", {})- model_metadata._fetch_codex_oauth_context_lengths_with_source("tok")+ live, fresh = model_metadata._fetch_codex_oauth_context_lengths_with_source("tok")+ assert fresh and "gpt-6-sol" in live- assert len(seen_urls) == 2+ assert len(seen_urls) == 2 # one request per site: the newest-client answer was non-emptyfor url in seen_urls:parsed = urlparse(url)assert parsed.netloc == "chatgpt.com" and parsed.path == "/backend-api/codex/models"- assert parse_qs(parsed.query)["client_version"] == ["0.0.0"]+ assert parse_qs(parsed.query)["client_version"] != ["0.0.0"]+++def test_catalog_falls_back_to_the_ungated_sentinel_when_newest_client_is_rejected():+ """If the backend goes back to rejecting out-of-sequence versions (empty list or non-200), the+ ``0.0.0`` sentinel is tried next; a sentinel that is itself empty yields no entries."""+ from agent.model_metadata import CODEX_UNGATED_CLIENT_VERSION, fetch_codex_catalog_entries++ class _Resp:+ def __init__(self, status, models):+ self.status_code, self._models = status, models++ def json(self):+ return {"models": self._models}++ def rejecting(url):+ return _Resp(200, [{"slug": "gpt-5.5"}]) if url.endswith(CODEX_UNGATED_CLIENT_VERSION) else _Resp(400, [])++ entries, status = fetch_codex_catalog_entries(rejecting)+ assert [e["slug"] for e in entries] == ["gpt-5.5"] and status == 200+ assert fetch_codex_catalog_entries(lambda url: _Resp(200, [])) == ([], 200)