Skip to content

The agent that grows with you

fix: keep model.openai_runtime=codex_app_server across /model switch; document the overlay rung

teknium15f914154fdf9
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py
index 402c44438e4..e753a8d8c7f 100644
--- a/hermes_cli/model_switch.py
+++ b/hermes_cli/model_switch.py
@@ -1484,10 +1484,11 @@ def _resolve_switch_credentials(st: _Switch) -> Optional[ModelSwitchResult]:
# Fills an empty mode (alias cleared it) and overrides a STALE mode carried from previous
# session state when the host mandates one wire protocol (e.g. gpt-5.x on api.openai.com
- # would otherwise 400 on tools+reasoning).
+ # would otherwise 400 on tools+reasoning). ``codex_app_server`` is the resolver's
+ # ``model.openai_runtime`` opt-in, not a wire protocol the host can mandate: keep it.
from hermes_cli.providers import is_actual_route
mandated_mode = "chat_completions" if is_actual_route(st.target_provider, st.base_url) else host_mandated_api_mode(st.base_url)
- if mandated_mode is not None:
+ if mandated_mode is not None and st.api_mode != "codex_app_server":
st.api_mode = mandated_mode
st.api_mode = st.api_mode or determine_api_mode(st.target_provider, st.base_url)
return None
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index 49e1d1917d7..a9de4133062 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -906,6 +906,8 @@ def resolve_runtime_provider(*, requested: Optional[str] = None, explicit_api_ke
keyless fallback as ``auth_error``) → minimax-oauth
→ external-process → anthropic env → bedrock → registry api_key providers
8. OpenRouter / bare-custom fallback
+ 9. ``model.openai_runtime`` overlay (openai/openai-codex only): rewrites the picked rung's
+ api_mode to ``codex_app_server``; the rung's credential/endpoint is then not used
target_model overrides model_cfg["default"] when computing provider-specific api_mode (e.g.
OpenCode Zen/Go where different models route through different API surfaces)."""
requested_provider = resolve_requested_provider(requested)
@@ -916,8 +918,12 @@ def resolve_runtime_provider(*, requested: Optional[str] = None, explicit_api_ke
# model.openai_runtime is applied ONCE, after the ladder: every rung (pool, OAuth store,
# explicit --api-key/--base-url, env key) hardcodes the wire api_mode for openai/openai-codex,
# so applying the opt-in inside one rung left the others on codex_responses (#115169).
- runtime["api_mode"] = _maybe_apply_codex_app_server_runtime(
+ api_mode = _maybe_apply_codex_app_server_runtime(
provider=runtime.get("provider", ""), api_mode=runtime.get("api_mode", ""), model_cfg=_get_model_config())
+ if api_mode != runtime.get("api_mode"):
+ logger.info("model.openai_runtime=codex_app_server overrides the %s runtime (source=%s); its credential/endpoint "
+ "is not used — the app-server authenticates with its own login", runtime.get("provider"), runtime.get("source"))
+ runtime["api_mode"] = api_mode
return runtime
diff --git a/tests/hermes_cli/test_model_switch_openai_api_mode.py b/tests/hermes_cli/test_model_switch_openai_api_mode.py
index fd890a51578..fe61b03b897 100644
--- a/tests/hermes_cli/test_model_switch_openai_api_mode.py
+++ b/tests/hermes_cli/test_model_switch_openai_api_mode.py
@@ -135,3 +135,22 @@ def test_generic_relay_not_clobbered_on_meta_switch():
# so it stays chat_completions (not forced to codex_responses).
assert result.success
assert result.api_mode == "chat_completions"
+
+
+def test_openai_runtime_codex_app_server_survives_host_mandate():
+ """``model.openai_runtime: codex_app_server`` must survive the /model switch (#115169).
+
+ The resolver applies the opt-in after its ladder and hands ``api_mode=codex_app_server``
+ to the switch; api.openai.com's host-mandated ``codex_responses`` is a wire-protocol
+ correction for stale modes and must not overwrite the app-server runtime selection.
+ """
+ result = _run_openai_switch(
+ raw_input="gpt-5.6-sol",
+ current_provider="openrouter",
+ current_model="anthropic/claude-opus-4.8",
+ explicit_provider="openai-api",
+ runtime_api_mode="codex_app_server",
+ )
+ assert result.success, f"switch_model failed: {result.error_message}"
+ assert result.target_provider == "openai-api"
+ assert result.api_mode == "codex_app_server"