fix(models): require verified Codex discovery for GPT-6.2 choices

This commit is contained in:
Vortex Openclaw
2026-11-17 16:52:53 -08:00
committed by Bear Huddleston
parent 73466ca3a7
commit 444a6b8644
5 changed files with 56 additions and 19 deletions

View File

@@ -97,11 +97,12 @@ def _finalize_codex_models(model_ids: list[str]) -> list[str]:
return _add_context_variants(_add_forward_compat_models(model_ids))
def _drop_undiscovered_models(model_ids: list[str]) -> list[str]:
"""Only the live account catalog may advertise these plan-gated models."""
def codex_model_requires_account_discovery(model: str) -> bool:
"""Whether a Codex model is only advertised after account discovery."""
from agent.reasoning_effort import GPT62_MODEL_IDS, is_astra_model
from hermes_cli.model_normalize import normalize_model_for_provider
return [model for model in model_ids if model not in GPT62_MODEL_IDS and not is_astra_model(model)]
return is_astra_model(model) or normalize_model_for_provider(model, "openai-codex") in GPT62_MODEL_IDS
def codex_catalog_credential_identity() -> str:
@@ -226,6 +227,5 @@ def get_codex_model_ids(access_token: Optional[str] = None, base_url: Optional[s
from hermes_cli.models_catalog_static import CuratedFallbackModels
default_model = _read_default_model(codex_home)
return CuratedFallbackModels(_finalize_codex_models(_drop_undiscovered_models(_dedupe([
*([default_model] if default_model else []), *_read_cache_models(codex_home),
*DEFAULT_CODEX_MODELS]))))
hints = [*([default_model] if default_model else []), *_read_cache_models(codex_home), *DEFAULT_CODEX_MODELS]
return CuratedFallbackModels(_finalize_codex_models([m for m in hints if not codex_model_requires_account_discovery(m)]))

View File

@@ -1988,8 +1988,10 @@ 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 is_astra_model(model)
from hermes_cli.codex_models import codex_model_requires_account_discovery
slug = _normalized_cache_slug(provider)
return codex_model_requires_account_discovery(model) if slug == "openai-codex" else (
slug in {"openai", "openai-api"} and is_astra_model(model))
def cached_provider_model_ids(
@@ -1998,10 +2000,8 @@ def cached_provider_model_ids(
"""Disk-cached :func:`provider_model_ids`: fresh cache hit, else live fetch persisting a non-empty
result. Always returns a list.
``non_blocking`` marks the GUI read path (``model.options``): it NEVER waits on a provider probe.
A same-credentials row of any age is served as-is and a daemon thread warms the next open; a
cold/mismatched row returns ``[]`` so the caller keeps its curated list. One degraded provider
(hanging or timing-out ``/v1/models``) therefore delays nothing but itself (#114215)."""
``non_blocking`` never waits for a provider probe (#114215). Only fresh verified rows can
advertise account-gated models; stale rows may be served while a daemon refreshes them."""
normalized = _normalized_cache_slug(provider)
if not normalized:
return []
@@ -2014,15 +2014,14 @@ def cached_provider_model_ids(
if not force_refresh:
tier = _disk_serve_tier(entry, fp, now, is_ollama=is_ollama, ttl_seconds=ttl_seconds)
if tier is not None:
if tier is not None and entry is not None:
if tier == "stale":
_spawn_swr_refresh(normalized)
return _chat_catalog_rows(list(entry["models"]))
verified = tier == "fresh" and not entry.get("fallback")
return _chat_catalog_rows([m for m in entry["models"] if verified or not _model_requires_account_discovery(normalized, m)])
if non_blocking and not force_refresh:
# Read path: never touch the network in the caller's thread. A same-credentials row past the
# SWR window is still served (hour-old catalog beats an empty picker) while a daemon thread
# warms the next open; a cold row returns [] and the caller falls back to its curated list.
# Serve same-credential hints past the SWR window while the daemon warms the next open.
_spawn_swr_refresh(normalized)
if _cache_entry_valid(entry, fp, allow_empty=is_ollama):
return _chat_catalog_rows([

View File

@@ -2,6 +2,8 @@ import base64
import json
from unittest.mock import patch
import pytest
from hermes_cli.codex_models import (
_FORWARD_COMPAT_TEMPLATE_MODELS,
DEFAULT_CODEX_MODELS,
@@ -9,6 +11,27 @@ from hermes_cli.codex_models import (
)
@pytest.mark.parametrize("model", ["openai/gpt-6.2-sol", "openai/gpt-6.2-astra"])
@pytest.mark.parametrize("filename", ["config.toml", "models_cache.json"])
def test_prefixed_codex_hint_does_not_set_offline_default(monkeypatch, tmp_path, model, filename):
monkeypatch.setenv("CODEX_HOME", str(tmp_path))
content = f'model = "{model}"\n' if filename == "config.toml" else json.dumps({"models": [{"slug": model}]})
(tmp_path / filename).write_text(content, encoding="utf-8")
models = get_codex_model_ids()
assert models[0] == "gpt-6-sol"
assert model not in models
@pytest.mark.parametrize("model", ["gpt-6.2-sol", "openai/gpt-6.2-astra"])
def test_saved_gpt62_is_not_injected_into_codex_picker(model):
from hermes_cli.model_switch_providers import _finalize_picker_rows
for provider in ("openai-codex", "openai-api"):
rows = [{"slug": provider, "is_current": True, "total_models": 1, "models": ["gpt-6-sol"]}]
choices = _finalize_picker_rows(rows, {}, model)[0]["models"]
assert choices == (["gpt-6-sol"] if provider == "openai-codex" else [model, "gpt-6-sol"])
def _codex_jwt(subject: str) -> str:
"""JWT-shaped test stand-in: the live catalog path gates on the token parsing as a JWT
(a custom base's gateway key must stay off chatgpt.com, #121486)."""

View File

@@ -162,6 +162,20 @@ class TestProviderModelsSWR:
assert mod.cached_provider_model_ids("openai-codex", non_blocking=True) == []
spawn.assert_called_once_with("openai-codex")
@pytest.mark.parametrize("fallback,age,expected", [(False, 0, True), (True, 0, False), (False, 2, False)])
def test_codex_gpt62_cache_requires_fresh_verified_discovery(self, monkeypatch, fallback, age, expected):
from hermes_cli import models as mod
gated = ["gpt-6.2-sol", "openai/gpt-6.2-astra"]
row = {**self._cache_entry([*gated, "gpt-6-sol"], age), "fallback": fallback}
monkeypatch.setattr(mod, "_load_provider_models_cache", lambda: {"openai-codex": row})
monkeypatch.setattr(mod, "_credential_fingerprint", lambda _: "fp")
monkeypatch.setattr(mod, "_spawn_swr_refresh", lambda _: None)
monkeypatch.setattr(mod, "provider_model_ids", lambda *a, **kw: [])
assert mod.cached_provider_model_ids("openai-codex", ttl_seconds=1, non_blocking=True) == (
row["models"] if expected else ["gpt-6-sol"])
assert mod.cached_provider_model_ids("openai-codex", force_refresh=True) == ["gpt-6-sol"]
def test_force_refresh_bypasses_swr(self):
import hermes_cli.models as mod

View File

@@ -313,8 +313,9 @@ When using the Z.AI / GLM provider, Hermes automatically probes multiple endpoin
Select `gpt-6.2-astra` or `gpt-6.2-sol` with `hermes model` under **OpenAI API**
(API key) or **OpenAI Codex** (ChatGPT subscription). Explicit model selections are unchanged.
When no model is configured, OpenAI API defaults to `gpt-6.2-sol` and Codex defaults to
`gpt-6-sol`. The Codex picker shows GPT-6.2 when the account's catalog offers it.
When no model is configured, OpenAI API defaults to `gpt-6.2-sol`. Codex can use the
account's catalog when available, with `gpt-6-sol` as its curated offline fallback.
The Codex picker shows GPT-6.2 when the account's catalog offers it.
If your ChatGPT plan doesn't include GPT-6.2, select `gpt-6-sol` instead.
If your plan includes GPT-6.2 but the optional [Codex app-server runtime](../user-guide/features/codex-app-server-runtime.md)