The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(runtime): honor model.openai_runtime: codex_app_server across all ladder rungs (#115169)
rocks7378d2ea58fa45f
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.pyindex 68da8dec168..9c3ed44b080 100644--- a/hermes_cli/runtime_provider.py+++ b/hermes_cli/runtime_provider.py@@ -715,6 +715,10 @@ def _resolve_oauth_runtime(provider, requested_provider, model_cfg, target_modelspec = _OAUTH_RUNTIME_PROVIDERS[provider]creds = spec.resolve()api_mode = spec.api_mode(_effective_model(model_cfg, target_model)) if callable(spec.api_mode) else spec.api_mode+ # model.openai_runtime opt-in (#115169): the OAuth rung receives model_cfg directly, so apply+ # the rewrite here too — ambient-config-only application at the resolve_runtime_provider+ # choke point would not cover direct callers of this rung. Idempotent with that application.+ api_mode = _maybe_apply_codex_app_server_runtime(provider=provider, api_mode=api_mode, model_cfg=model_cfg)return _runtime(provider, api_mode, (creds.get("base_url") or "").rstrip("/") or spec.default_base_url,creds.get("api_key", ""), source=creds.get("source", spec.default_source),**{spec.expiry_key: creds.get(spec.expiry_key)}, requested_provider=requested_provider)@@ -913,6 +917,12 @@ def resolve_runtime_provider(*, requested: Optional[str] = None, explicit_api_ke_raise_if_local_alias_missing_endpoint(requested_provider, explicit_base_url)runtime = next(r for r in _ladder_rungs(requested_provider, explicit_api_key, explicit_base_url, target_model) if r)_raise_for_credentialless_bare_custom(requested_provider, runtime)+ # model.openai_runtime opt-in: rewrite api_mode at the single choke point so every+ # ladder rung (OAuth, explicit-key, pool, shortcuts) honors it, not just the pool+ # rung's in-situ application below (#115169). Idempotent with that application.+ runtime["api_mode"] = _maybe_apply_codex_app_server_runtime(+ provider=runtime.get("provider", ""), api_mode=runtime.get("api_mode", ""),+ model_cfg=_get_model_config())return runtimediff --git a/tests/hermes_cli/test_openai_runtime_override.py b/tests/hermes_cli/test_openai_runtime_override.pynew file mode 100644index 00000000000..fffe7c677b9--- /dev/null+++ b/tests/hermes_cli/test_openai_runtime_override.py@@ -0,0 +1,65 @@+"""model.openai_runtime: codex_app_server must survive runtime resolution (#115169).++The rewrite was only applied on the credential-pool rung; the OAuth path (the+normal openai-codex route) and explicit-key paths silently dropped it.+"""++from __future__ import annotations++from unittest.mock import patch++from hermes_cli import runtime_provider as rp++FAKE_CODEX_CREDS = {+ "base_url": "https://chatgpt.com/backend-api/codex",+ "api_key": "tok",+ "source": "hermes-auth-store",+ "last_refresh": 1,+}+++def _model_cfg(runtime_value):+ cfg = {"provider": "openai-codex", "default": "gpt-5.6-luna"}+ if runtime_value is not None:+ cfg["openai_runtime"] = runtime_value+ return cfg+++class TestOAuthPathHonorsOpenaiRuntime:+ def test_codex_app_server_applied(self):+ with patch.object(rp, "resolve_codex_runtime_credentials", return_value=dict(FAKE_CODEX_CREDS)):+ rt = rp._resolve_oauth_runtime("openai-codex", "openai-codex",+ _model_cfg("codex_app_server"), None)+ assert rt["api_mode"] == "codex_app_server"++ def test_unset_stays_codex_responses(self):+ with patch.object(rp, "resolve_codex_runtime_credentials", return_value=dict(FAKE_CODEX_CREDS)):+ rt = rp._resolve_oauth_runtime("openai-codex", "openai-codex",+ _model_cfg(None), None)+ assert rt["api_mode"] == "codex_responses"++ def test_auto_stays_codex_responses(self):+ with patch.object(rp, "resolve_codex_runtime_credentials", return_value=dict(FAKE_CODEX_CREDS)):+ rt = rp._resolve_oauth_runtime("openai-codex", "openai-codex",+ _model_cfg("auto"), None)+ assert rt["api_mode"] == "codex_responses"+++class TestFullLadderHonorsOpenaiRuntime:+ def test_codex_app_server_survives_ladder(self):+ # The hermetic conftest points HERMES_HOME at an empty tempdir, so the+ # ambient config cannot carry the flag — inject model_cfg at the same+ # seam the rest of this suite uses (monkeypatch.setattr(rp, "_get_model_config", ...)).+ with patch.object(rp, "resolve_codex_runtime_credentials", return_value=dict(FAKE_CODEX_CREDS)), \+ patch.object(rp, "_get_model_config", return_value=_model_cfg("codex_app_server")):+ rt = rp.resolve_runtime_provider(requested="openai-codex")+ assert rt["provider"] == "openai-codex"+ assert rt["api_mode"] == "codex_app_server"+++class TestNonEligibleProvidersUnaffected:+ def test_actual_route_clobber_unchanged(self):+ # provider "actual" is not eligible for the openai_runtime rewrite; the+ # is_actual_route chat_completions normalization must keep working.+ rt = rp._runtime("actual", "codex_app_server", "https://api.actual.inc/v1", "k")+ assert rt["api_mode"] == "chat_completions"