The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(models): publish the Codex catalog cap before its context entry
kshitijk4poore0a8749ca039
diff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex 43d311e2134..5ae8ccd65af 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -1886,8 +1886,9 @@ def _fetch_codex_oauth_context_lengths_with_source(access_token: str, base_url:if isinstance(max_ctx, int) and max_ctx > 0:max_result[slug.strip()] = max_ctxif result:- _codex_oauth_context_cache[cache_key] = (result, now)+ # Max first: a reader that sees the fresh context entry must also see its cap._codex_oauth_max_context_cache[cache_key] = max_result+ _codex_oauth_context_cache[cache_key] = (result, now)return result, Truediff --git a/tests/agent/test_model_metadata.py b/tests/agent/test_model_metadata.pyindex 664ff8fd278..98c6c29bf47 100644--- a/tests/agent/test_model_metadata.py+++ b/tests/agent/test_model_metadata.py@@ -680,6 +680,25 @@ class TestCodexOAuthContextLength:)assert ctx == 272_000+ def test_catalog_max_is_published_before_the_context_entry(self):+ """A reader that sees a fresh context entry must already be able to see its cap, or a+ concurrent -900k resolution between the two writes skips the catalog max."""+ import agent.model_metadata as mm++ max_cache: dict = {}++ class _ContextCache(dict):+ def __setitem__(self, key, value):+ assert key in max_cache, "context entry published before its max_context_window cap"+ super().__setitem__(key, value)++ ok = MagicMock(status_code=200)+ ok.json.return_value = {"models": [{"slug": "gpt-5.6-luna", "context_window": 272_000, "max_context_window": 872_000}]}+ with patch.object(mm, "_codex_oauth_context_cache", _ContextCache()), patch.object(mm, "_codex_oauth_max_context_cache", max_cache), \+ patch("agent.model_metadata.model_metadata_http.get", return_value=ok):+ live, _fresh = mm._fetch_codex_oauth_context_lengths_with_source(_codex_jwt("fake-token"))+ assert live == {"gpt-5.6-luna": 272_000}+@pytest.mark.parametrize("slug", ["gpt-5.6-sol-900k"])def test_fallback_table_resolution_also_bumped(self, slug):