Skip to content

The agent that grows with you

refactor(openai): one is_astra_model predicate; gate Astra at the untrusted Codex inputs

kshitijk4poorb6852995ed93
diff --git a/agent/reasoning_effort.py b/agent/reasoning_effort.py
index 2d614828ae4..e5fd465488a 100644
--- a/agent/reasoning_effort.py
+++ b/agent/reasoning_effort.py
@@ -34,6 +34,7 @@ CODEX_LEGACY_EFFORTS: tuple[str, ...] = ("none", "low", "medium", "high", "xhigh
# GPT-6 Astra is account-gated and its Responses API accepts no disable/minimal
# wire level; callers normalize those requests to ``low`` at the transport boundary.
CODEX_ASTRA_EFFORTS: tuple[str, ...] = ("low", "medium", "high", "xhigh", "max")
+ASTRA_MODEL_IDS: frozenset[str] = frozenset({"gpt-6-astra", "gpt-6-astra-900k"})
#: xAI Responses — Grok 4.6+ accepts xhigh; older Grok tops out at high.
XAI_GROK46_EFFORTS: tuple[str, ...] = ("low", "medium", "high", "xhigh")
@@ -81,9 +82,16 @@ OLLAMA_CLOUD_OVERRIDES: dict[str, str] = {"xhigh": "max"}
META_AI_EFFORTS: tuple[str, ...] = ("minimal", "low", "medium", "high", "xhigh")
+def is_astra_model(model: Optional[str]) -> bool:
+ """``gpt-6-astra`` or its Hermes-side ``-900k`` picker alias, with or without a ``vendor/`` prefix.
+ The single home for the slug set: picker gating, effort vocabulary and the request sanitizer all
+ key off it, so a new Astra alias is one edit."""
+ return (model or "").strip().lower().rsplit("/", 1)[-1] in ASTRA_MODEL_IDS
+
+
def codex_supported_efforts(model: Optional[str]) -> tuple[str, ...]:
"""Supported effort set for an OpenAI/Codex Responses model."""
- if (model or "").strip().lower().rsplit("/", 1)[-1] in ("gpt-6-astra", "gpt-6-astra-900k"):
+ if is_astra_model(model):
return CODEX_ASTRA_EFFORTS
return CODEX_GPT56_EFFORTS if "gpt-5.6" in (model or "").lower() else CODEX_LEGACY_EFFORTS
diff --git a/hermes_cli/codex_models.py b/hermes_cli/codex_models.py
index 859780630b1..7d728a92f31 100644
--- a/hermes_cli/codex_models.py
+++ b/hermes_cli/codex_models.py
@@ -88,19 +88,17 @@ def _add_context_variants(model_ids: List[str]) -> List[str]:
return out
-def _finalize_codex_models(model_ids: List[str], *, allow_astra: bool = False) -> List[str]:
- """Forward-compat/context synthesis with an entitlement gate for Astra.
+def _finalize_codex_models(model_ids: List[str]) -> List[str]:
+ """Forward-compat synthesis + large-context variant synthesis."""
+ return _add_context_variants(_add_forward_compat_models(model_ids))
- Cached/configured model names are useful compatibility hints, but only the
- account-scoped Codex endpoint is authoritative for current Astra access.
- """
- from agent.model_metadata import strip_codex_context_variant_suffix
- finalized = _add_forward_compat_models(model_ids)
- if not allow_astra:
- finalized = [model for model in finalized
- if strip_codex_context_variant_suffix(model.lower()).rsplit("/", 1)[-1] != "gpt-6-astra"]
- return _add_context_variants(finalized)
+def _drop_undiscovered_astra(model_ids: List[str]) -> List[str]:
+ """Astra is account-gated: only the live account-scoped catalog may advertise it. A stale
+ ``models_cache.json`` or a ``config.toml`` default is a compatibility hint, not entitlement."""
+ from agent.reasoning_effort import is_astra_model
+
+ return [model for model in model_ids if not is_astra_model(model)]
def _extract_chatgpt_account_id(access_token: str) -> Optional[str]:
@@ -169,7 +167,7 @@ def _fetch_models_from_api(access_token: str) -> List[str]:
logger.debug("Failed to fetch Codex models from API: %s", exc)
return []
- return _finalize_codex_models(_ranked_slugs(entries), allow_astra=True)
+ return _finalize_codex_models(_ranked_slugs(entries))
def _read_default_model(codex_home: Path) -> Optional[str]:
@@ -204,8 +202,8 @@ def get_codex_model_ids(access_token: Optional[str] = None) -> List[str]:
if access_token:
api_models = _fetch_models_from_api(access_token)
if api_models:
- return _finalize_codex_models(api_models, allow_astra=True)
+ return _finalize_codex_models(api_models)
default_model = _read_default_model(codex_home)
- return _finalize_codex_models(_dedupe([
+ return _finalize_codex_models(_drop_undiscovered_astra(_dedupe([
*([default_model] if default_model else []), *_read_cache_models(codex_home),
- *DEFAULT_CODEX_MODELS]))
+ *DEFAULT_CODEX_MODELS])))
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 0784e3fd551..9b2e3c84636 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -438,7 +438,7 @@ _nous_caps_disk_checked = False
_nous_caps_warm_started = False
-from agent.reasoning_effort import clamp_effort as _clamp_effort
+from agent.reasoning_effort import clamp_effort as _clamp_effort, is_astra_model
def clamp_reasoning_effort_to_supported(
@@ -1206,8 +1206,7 @@ def _openai_catalog(normalized: str, force_refresh: bool) -> Optional[list[str]]
discovered = [m for m in curated if m.lower() in live_lower]
# Astra is intentionally absent from offline/static catalogs: the official API's
# account-scoped /models response is the only source that may advertise it.
- if "gpt-6-astra" in live_lower:
- discovered.append(next((m for m in live if m.lower() == "gpt-6-astra"), "gpt-6-astra"))
+ discovered.extend(m for m in live if is_astra_model(m))
return discovered or curated or live
@@ -1518,9 +1517,7 @@ def _normalized_cache_slug(provider: Optional[str]) -> str:
def _model_requires_account_discovery(provider: Optional[str], model: str) -> bool:
"""Astra names cannot confer API/OAuth entitlement through picker state."""
- return _normalized_cache_slug(provider) in {"openai", "openai-api", "openai-codex"} and str(model or "").strip().lower().rsplit("/", 1)[-1] in {
- "gpt-6-astra", "gpt-6-astra-900k",
- }
+ return _normalized_cache_slug(provider) in {"openai", "openai-api", "openai-codex"} and is_astra_model(model)
def cached_provider_model_ids(
diff --git a/tests/hermes_cli/test_codex_models.py b/tests/hermes_cli/test_codex_models.py
index 00d7458edb6..653d402bd5f 100644
--- a/tests/hermes_cli/test_codex_models.py
+++ b/tests/hermes_cli/test_codex_models.py
@@ -137,7 +137,7 @@ def test_astra_requires_live_codex_account_discovery(monkeypatch, tmp_path):
monkeypatch.setattr(
codex_models,
"_fetch_models_from_api",
- lambda _token: codex_models._finalize_codex_models(["gpt-6-astra"], allow_astra=True),
+ lambda _token: codex_models._finalize_codex_models(["gpt-6-astra"]),
)
entitled = get_codex_model_ids(access_token="entitled-token")
assert entitled[entitled.index("gpt-6-astra") + 1] == "gpt-6-astra-900k"