From 036008149997ea2755f2f6c4206d8f103b46efa5 Mon Sep 17 00:00:00 2001 From: David Liu Date: Tue, 6 Oct 2026 16:24:56 +0000 Subject: [PATCH] Keep Codex's managed default model when ug saves state `codex.default_model()` called `clear_model_preferences`, so any state hydrate without the managed overlay (for example `save_state` right after `write_tool_config`) deleted the `model` ug had just written. Codex then started on whatever the gateway listed first instead of the admin's default. Looking up the default no longer rewrites config; launch still clears a stale pinned model. Co-authored-by: Isaac --- src/ucode/agents/codex.py | 1 - tests/test_agent_codex.py | 11 ++++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ucode/agents/codex.py b/src/ucode/agents/codex.py index 75606811d..8b0bcd3b0 100644 --- a/src/ucode/agents/codex.py +++ b/src/ucode/agents/codex.py @@ -788,7 +788,6 @@ def default_model(state: dict) -> str | None: return state["codex_default_model"] if smart_routing_v2.smart_routing_enabled(): return _smart_routing_config_model(state) - clear_model_preferences(state) return None diff --git a/tests/test_agent_codex.py b/tests/test_agent_codex.py index c810a1b6f..bde491007 100644 --- a/tests/test_agent_codex.py +++ b/tests/test_agent_codex.py @@ -909,15 +909,12 @@ def _isolate_profile_config(self, tmp_path, monkeypatch): monkeypatch.setattr(codex, "CODEX_CONFIG_PATH", tmp_path / "ucode.config.toml") monkeypatch.setattr(codex, "CODEX_BACKUP_PATH", tmp_path / "backup.toml") - def test_clears_profile_model_preferences(self, tmp_path): - codex.CODEX_CONFIG_PATH.write_text( - 'model = "gpt-5.6-sol"\nmodel_reasoning_effort = "medium"\n', encoding="utf-8" - ) + def test_reads_without_touching_profile_model_preferences(self, tmp_path): + original = 'model = "gpt-5.6-sol"\nmodel_reasoning_effort = "medium"\n' + codex.CODEX_CONFIG_PATH.write_text(original, encoding="utf-8") assert codex.default_model({"codex_models": ["system.ai.gpt-5-6-luna"]}) is None - doc = read_toml_safe(codex.CODEX_CONFIG_PATH) - assert "model" not in doc - assert "model_reasoning_effort" not in doc + assert codex.CODEX_CONFIG_PATH.read_text(encoding="utf-8") == original def test_none_when_no_configured_model(self): assert codex.default_model({}) is None