fix(models): honor resolved Codex identity in ACP and Desktop
Some checks failed
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
Docs Search Monitor / probe (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Canary Release / Tag, draft, and start the canary build (push) Has been cancelled
Canary Release / Prune canaries older than 14 days (push) Has been cancelled

This commit is contained in:
Vortex Openclaw
2026-11-17 18:10:35 -08:00
committed by Bear Huddleston
parent 864fd57c59
commit 730d593fe3
6 changed files with 82 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ import logging
from pathlib import Path
from acp.schema import (
AvailableCommand, AvailableCommandsUpdate, ModelInfo, SessionConfigOptionSelect, SessionConfigSelectOption,
AvailableCommand, AvailableCommandsUpdate, SessionConfigOptionSelect, SessionConfigSelectOption,
SessionInfoUpdate, SessionMode, SessionModeState, SessionModelState, UnstructuredCommandInput, Usage, UsageUpdate,
)
@@ -125,10 +125,9 @@ async def session_config_options(client, session_id, models, info, mode_id):
def model_state(info: dict) -> SessionModelState | None:
"""The picker for the session's model (``session.info``), from the shared inventory; a single
current-model row when nothing is listable, as main's ``_build_model_state``. Blocking."""
"""The picker for ``session.info`` from shared inventory, with a current-model fallback. Blocking."""
from acp_adapter.auth import detect_provider
from acp_adapter.model_catalog import build_model_state, encode_model_choice
from acp_adapter.model_catalog import build_model_state, fallback_model_state
model = str(info.get("model") or "").strip()
provider = info.get("provider") or detect_provider() or "openrouter"
try:
@@ -138,10 +137,7 @@ def model_state(info: dict) -> SessionModelState | None:
except Exception:
# Boundary: a broken inventory must not fail session/new; the current model still shows.
logger.debug("Could not build ACP model state", exc_info=True)
if not model:
return None
choice = encode_model_choice(provider, model)
return SessionModelState(available_models=[ModelInfo(model_id=choice, name=model)], current_model_id=choice)
return fallback_model_state(model, provider)
def provenance_meta(home: Path, acp_session_id: str, session_id: str) -> dict | None:

View File

@@ -152,6 +152,19 @@ def encode_model_choice(provider: str | None, model: str | None) -> str:
return f"{raw_provider}:{raw_model}" if raw_provider else raw_model
def fallback_model_state(model: str, provider: str) -> SessionModelState | None:
"""Keep the current identity when inventory is unavailable, without offering gated models."""
from hermes_cli.codex_models import codex_model_requires_account_discovery
from hermes_cli.models import normalize_provider
if not model:
return None
codex = _semantic_provider(provider, normalize_provider) == "openai-codex"
choice = encode_model_choice("openai-codex" if codex else provider, model)
available = [] if codex and codex_model_requires_account_discovery(model) else [ModelInfo(model_id=choice, name=model)]
return SessionModelState(available_models=available, current_model_id=choice)
@dataclass
class _ModelCatalog:
"""Deduplicated ACP model rows from the inventory + named endpoints.
@@ -238,8 +251,9 @@ class _ModelCatalog:
def build_model_state(model: str, provider: str, base_url: str) -> SessionModelState | None:
"""Picker state from the shared inventory + named endpoints; ``None`` when nothing is listable
(caller falls back to a single current-model row). Raises on inventory failure."""
from hermes_cli.codex_models import codex_model_requires_account_discovery
from hermes_cli.inventory import build_models_payload, load_picker_context
from hermes_cli.models import _model_requires_account_discovery, normalize_provider, provider_label
from hermes_cli.models import normalize_provider, provider_label
normalized_provider = normalize_provider(provider)
context = load_picker_context().with_overrides(
@@ -263,7 +277,8 @@ def build_model_state(model: str, provider: str, base_url: str) -> SessionModelS
# runs on the canonical endpoint — alone, or picking "current" re-routes to the proxy.
all_rows = payload.get("providers") or []
canonical_current = any(
str(r.get("slug") or "").strip().lower() == current_choice_provider and not r.get("is_user_defined")
not r.get("is_user_defined") and _semantic_provider(str(r.get("slug") or ""), normalize_provider)
== _semantic_provider(current_choice_provider, normalize_provider)
for r in all_rows
)
inventory_rows: list = []
@@ -284,6 +299,8 @@ def build_model_state(model: str, provider: str, base_url: str) -> SessionModelS
cat.add_inventory_rows(inventory_rows, provider_label)
cat.add_named_catalogs(named_catalogs, current_choice_provider)
available_models = cat.models
if cat.semantic(cat.current_choice_provider) == "openai-codex":
cat.current_choice_provider = "openai-codex"
def empty_applies(provider_id: str) -> bool:
return _empty_catalog_applies(provider_id, cat.empty_authoritative, normalize_provider)
@@ -295,7 +312,7 @@ def build_model_state(model: str, provider: str, base_url: str) -> SessionModelS
if current_is_empty:
available_models = [m for m in available_models if " • current" not in str(m.description or "")]
current_model_id = "" if current_is_empty else encode_model_choice(cat.current_choice_provider, model)
requires_discovery = cat.current_choice_provider == "openai-codex" and _model_requires_account_discovery("openai-codex", model)
requires_discovery = cat.current_choice_provider == "openai-codex" and codex_model_requires_account_discovery(model)
if current_model_id and not requires_discovery and current_model_id not in {item.model_id for item in available_models}:
provider_name = provider_label(normalized_provider)
available_models.insert(0, ModelInfo(

View File

@@ -19,7 +19,7 @@ import acp
from acp.schema import (
AgentCapabilities, AgentMessageChunk, AuthenticateResponse, ClientCapabilities, ForkSessionResponse,
Implementation, InitializeResponse, ListSessionsResponse, LoadSessionResponse, McpServerHttp, McpServerSse,
McpServerStdio, ModelInfo, NewSessionResponse, PromptCapabilities, PromptResponse, ResumeSessionResponse,
McpServerStdio, NewSessionResponse, PromptCapabilities, PromptResponse, ResumeSessionResponse,
SessionCapabilities, SessionForkCapabilities, SessionInfo, SessionInfoUpdate, SessionListCapabilities,
SessionMode, SessionModeState, SessionModelState, SessionResumeCapabilities, SetSessionConfigOptionResponse,
SetSessionModeResponse, SetSessionModelResponse, TextContentBlock, Usage, UsageUpdate, UserMessageChunk,
@@ -32,7 +32,7 @@ from acp_adapter.events import (
AssistantMessageIdAllocator, _build_plan_update_from_todo_result, _send_update, flush_open_tool_calls,
make_message_cb, make_step_cb, make_thinking_cb, make_tool_progress_cb,
)
from acp_adapter.model_catalog import build_model_state, encode_model_choice
from acp_adapter.model_catalog import build_model_state, fallback_model_state
from acp_adapter import modes as _modes
from acp_adapter.permissions import make_approval_callback
from acp_adapter.provenance import session_provenance_meta
@@ -343,10 +343,7 @@ class HermesACPAgent(SlashCommandsMixin, acp.Agent):
except Exception:
logger.debug("Could not build ACP model state", exc_info=True)
if not model:
return None
choice = encode_model_choice(provider, model)
return SessionModelState(available_models=[ModelInfo(model_id=choice, name=model)], current_model_id=choice)
return fallback_model_state(model, provider)
def _switch_model(
self, state: SessionState, raw_model: str, *, keep_endpoint: bool = False

View File

@@ -564,6 +564,29 @@ describe('the current model the catalog omits (#57534)', () => {
expect(row.textContent).toContain('Qwen 2.5 72B Instruct')
})
it.each(['openai-codex', 'review-proxy'])('keeps the current model for a custom endpoint named %s', async slug => {
const model = 'gpt-6.2-sol'
const provider = `custom:${slug}`
getGlobalModelOptions.mockResolvedValue({
providers: [
{
aliases: [provider],
api_url: 'https://proxy.example/v1',
is_user_defined: true,
models: ['gpt-6-sol'],
name: 'Proxy',
slug
}
]
})
renderMenu({ model, provider })
await screen.findByText(modelDisplayParts('gpt-6-sol').name)
expect(screen.getByText(modelDisplayParts(model).name).closest('[role="menuitem"]')).not.toBeNull()
})
it('does not inject the current model into a provider that is not the current one', async () => {
// current.provider has no row; the model must not leak into another group.
getGlobalModelOptions.mockResolvedValue({

View File

@@ -1371,7 +1371,7 @@ function groupModels(
// Keep the OpenRouter/custom fallback (#57534), but don't synthesize
// Codex choices the backend omitted. The composer still shows the current model.
if (
provider.slug !== 'openai-codex' &&
(provider.slug !== 'openai-codex' || provider.is_user_defined) &&
catalogProviderMatches(provider, current.provider) &&
current.model &&
!allFamilies.some(family => family.id === current.model || family.fastId === current.model)

View File

@@ -22,18 +22,47 @@ MANTLE_URL = "https://bedrock-mantle.us-east-1.api.aws/openai/v1"
@pytest.mark.parametrize("listed", [[], ["gpt-6-sol"], ["gpt-6-sol", "gpt-6.2-sol"]])
def test_codex_session_model_is_not_an_undiscovered_choice(listed):
@pytest.mark.parametrize("provider", ["openai-codex", "chatgpt", "chatgpt-codex"])
def test_codex_session_model_is_not_an_undiscovered_choice(listed, provider):
inventory = {"providers": [{"slug": "openai-codex", "models": listed}]}
with patch("hermes_cli.inventory.build_models_payload", return_value=inventory), patch(
"acp_adapter.model_catalog._named_custom_provider_catalogs", return_value=[]
):
picker = build_model_state("gpt-6.2-sol", "openai-codex", "")
picker = build_model_state("gpt-6.2-sol", provider, "")
assert picker is not None
assert picker.current_model_id == "openai-codex:gpt-6.2-sol"
assert [item.model_id for item in picker.available_models] == [f"openai-codex:{model}" for model in listed]
def test_custom_codex_key_keeps_its_current_model():
inventory = {"providers": [
{"slug": "openai-codex", "models": ["gpt-6-sol"]},
{"slug": "openai-codex", "models": ["proxy-model"], "is_user_defined": True,
"api_url": "https://proxy.example/v1"},
]}
with patch("hermes_cli.inventory.build_models_payload", return_value=inventory), patch(
"acp_adapter.model_catalog._named_custom_provider_catalogs",
return_value=[("custom:openai-codex", "Proxy", [("proxy-model", "")])],
):
picker = build_model_state("gpt-6.2-sol", "custom:openai-codex", "https://proxy.example/v1")
assert picker is not None
assert picker.current_model_id == "custom:openai-codex:gpt-6.2-sol"
assert picker.available_models[0].model_id == picker.current_model_id
def test_gateway_catalog_failure_keeps_codex_current_id_without_offering_it():
from acp_adapter.gateway_session_meta import model_state
with patch("hermes_cli.inventory.build_models_payload", side_effect=RuntimeError("inventory unavailable")):
picker = model_state({"model": "gpt-6.2-sol", "provider": "chatgpt"})
assert picker is not None
assert picker.current_model_id == "openai-codex:gpt-6.2-sol"
assert picker.available_models == []
def _cfg(providers=None, custom_providers=None):
cfg = {}
if providers is not None: