From ae72be2ea27c8aec0c8b51349103b2843a9d7586 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Tue, 17 Nov 2026 21:38:18 +0000 Subject: [PATCH 01/14] feat(codex): show Smart Router state in experimental footer --- AGENTS.md | 1 + README.md | 17 ++ docs/codex-smart-router-statusline.md | 61 ++++++ src/ucode/agents/codex.py | 1 + src/ucode/smart_routing/codex_statusline.py | 154 +++++++++++++ src/ucode/smart_routing/session_env.py | 4 +- src/ucode/smart_routing/v2.py | 18 +- tests/README.md | 10 + tests/integration/README.md | 8 + tests/test_codex_smart_routing_v2.py | 55 ++++- tests/test_codex_statusline.py | 230 ++++++++++++++++++++ 11 files changed, 550 insertions(+), 9 deletions(-) create mode 100644 docs/codex-smart-router-statusline.md create mode 100644 src/ucode/smart_routing/codex_statusline.py create mode 100644 tests/test_codex_statusline.py diff --git a/AGENTS.md b/AGENTS.md index c96efeefa..e4711cc5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -370,6 +370,7 @@ Fields live in `~/.codex/ucode.config.toml` and `/etc/codex/managed_config.toml` | `mcp_servers` | Ignore | Merge | Managed file; add/update the config's MCP server entries, other entries left alone. A same-name entry in `~/.codex/config.toml` of the other transport (stdio vs HTTP) is removed, since Codex would merge the two into an invalid entry | | Smart Router and Smart Router Orchestrator hooks | Merge | Merge | Launch-only `PreToolUse`, plus `UserPromptSubmit` and compact `SessionStart` with `ENABLE_SMART_ROUTER_ORCHESTRATOR=1`; Codex combines them with its native hook sources and applies project trust; `features.hooks` is enabled for a smart-routed launch | | Native v2 collaboration | Launch-only (-c), never written | Launch-only (-c), never written | `features.multi_agent_v2.non_code_mode_only=false` and matching `root_agent_usage_hint_text` / `subagent_usage_hint_text` override saved values for the session; only for smart routing on Codex 0.164.0 or newer. User config files, general developer instructions, and native delegation-mode controls are preserved | +| Smart Router footer | Launch-only (-c), never written | Launch-only (-c), never written | On routed Codex 0.171.0-alpha.12 or newer, enable `features.tui_extensions_statusline`, select `tui.status_line_provider`, and add only `mcp_servers.ug-smart-router-statusline`. The app-server owns the session-local stdio provider; the terminal client receives the feature and selection overrides. Older clients receive none of these fields. Saved footer settings and unrelated MCP servers are preserved. Do not require an alpha or raise the minimum version before stable validation | | Smart Router native metadata | Launch-only (-c), never written | Launch-only (-c), never written | `responses_api_metadata.smart_router_recipe_name` records the configured recipe. The app-server interposer updates `smart_router_state` per main turn; spawn hooks stamp child task names. Reserve the state key for the interposer; a static config value would override turn updates | diff --git a/README.md b/README.md index 5edf8c029..37c274b5a 100644 --- a/README.md +++ b/README.md @@ -613,6 +613,23 @@ bypass `spawn_agent` have no guaranteed marker. Reserve `smart_router_state` for per-turn metadata; a static Codex `responses_api_metadata` entry with that name would override dynamic values. +Routed Codex terminal sessions on **0.171.0-alpha.12 or newer** show +`smart router ON/OFF` beside the current model, directory, and remaining context. +This uses Codex's experimental MCP status-line provider API. Earlier versions, +including stable 0.169.0, keep their existing footer. UG does not install an alpha +or raise its minimum Codex version for this feature. + +The indicator reads the same session controls as routing on each refresh, including +after `$smart-router off` and `$smart-router on`. Unreadable controls show +`smart router UNKNOWN` until a later refresh succeeds. Each launch has its own +local provider and controls file. UG enables and selects its footer for that launch +only; saved status-line settings and other MCP servers are preserved. The selected +footer replaces the normal footer's item layout for that session. This does not add +an indicator to the Codex desktop app or other app-server clients. + +For alpha validation and the stable-release rollout gate, see +[Codex Smart Router footer](docs/codex-smart-router-statusline.md). + ### Smart Router Orchestrator Use `SMART_ROUTER_CONFIG_VERSION` at launch to select a smart-routing configuration. diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md new file mode 100644 index 000000000..2d71a39c4 --- /dev/null +++ b/docs/codex-smart-router-statusline.md @@ -0,0 +1,61 @@ +# Codex Smart Router footer + +The terminal footer uses the experimental MCP status-line provider API first +available in Codex `0.171.0-alpha.12`. UG registers a local stdio provider for each +routed launch and selects it in the terminal client. Both configurations are +launch-only. The provider needs no gateway credentials or network access. + +The indicator reflects the latest session controls, rather than a turn's original +routing attribution. Existing children and an ongoing main turn keep their original +attribution after a toggle. A failed controls read shows `UNKNOWN` without stopping +Codex's polling, so the next successful read can recover. + +## Validation + +Install the checkout in an isolated Python environment and use Codex +`0.171.0-alpha.12` on that environment's PATH. Do not replace the user's stable +installation as part of automated tests. Check both `codex --version` and `ug --version`. + +Run the offline checks: + +```bash +uv run pytest tests/test_codex_statusline.py tests/test_codex_smart_routing_v2.py \ + tests/test_codex_metadata.py tests/test_agent_codex.py tests/test_smart_router.py \ + tests/test_smart_routing_config.py tests/test_integration_contract.py +just lint +``` + +For a configured test workspace and an explicitly selected profile: + +1. Launch `SMART_ROUTER_CONFIG_VERSION=subagent_only_v0 ug codex`. Check the + native footer shows `smart router ON` alongside model and project directory. +2. Ask Codex to read a file containing an unpredictable value. Require the correct + value in its completed answer, rather than accepting a startup banner as inference. +3. Submit `$smart-router off`. After the command succeeds, require `smart router OFF` + in the footer without restarting the conversation. +4. Submit `$smart-router on` and require `smart router ON` again. Complete another + file task in the same conversation. +5. Open a second session. Toggle one and check the other session's footer is unchanged. +6. Repeat with `first_prompt_and_subagent_no_orch_v0` and complete an initial prompt. +7. Repeat on Windows. Confirm both the app-server and remote terminal receive the + correct configuration, including when paths contain spaces. +8. Compare saved Codex settings before and after, allowing only Codex-owned trust + records. Existing footer preferences and unrelated MCP registrations must survive. +9. On stable `0.169.0`, confirm routed launch still works with its existing footer. + +Existing native routing journeys can be run with pinned alpha through +`scripts/run_integration.py --ug-version checkout --codex-version 0.171.0-alpha.12 +--profile --workspace -- -k routing_toggle`. +Those journeys verify inference and session continuity; the footer assertions above +are additional manual UI checks. + +## Stable rollout + +Keep the feature PR in draft while testing the alpha. Do not force users onto an +experimental Codex release. Before delivery, identify the first stable release +containing the provider API, rerun protocol, UI, and routed inference checks on that +exact build, then update UG's minimum Codex version and its existing upgrade tests. +Version `0.171.0` is a candidate, not a confirmed stable release target. + +Upstream contract and starter: +[create-statusline](https://github.com/openai/codex/blob/rust-v0.171.0-alpha.12/codex-rs/skills/src/assets/samples/create-statusline/SKILL.md). diff --git a/src/ucode/agents/codex.py b/src/ucode/agents/codex.py index 7ccd8ac57..3a518c27e 100644 --- a/src/ucode/agents/codex.py +++ b/src/ucode/agents/codex.py @@ -2108,6 +2108,7 @@ def _launch_smart_routing(state: dict, tool_args: list[str]) -> None: binary=binary, start_model=start_model, render_overlay=_render_launch_overlay, + codex_version=agent_version(binary), ) diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py new file mode 100644 index 000000000..77033bfaf --- /dev/null +++ b/src/ucode/smart_routing/codex_statusline.py @@ -0,0 +1,154 @@ +"""Session-local MCP footer for Codex's experimental status line providers.""" + +from __future__ import annotations + +import json +import os +import re +import sys +from pathlib import Path, PurePosixPath, PureWindowsPath +from typing import Any, TextIO + +from ucode.smart_routing.session_env import SESSION_ENV_VAR, session_routing_enabled + +MINIMUM_VERSION = (0, 171, 0) +MINIMUM_ALPHA = 12 +SERVER_NAME = "ug-smart-router-statusline" +TOOL_NAME = "statusline" +RESOURCE_URI = "ui://ug-smart-router/footer" +STATE_META_KEY = "com.openai/codex-statusline-state" +TOOL = { + "name": TOOL_NAME, + "title": "Unity Gateway Smart Router", + "description": "Show this session's Smart Router state in the Codex footer.", + "inputSchema": {"type": "object", "properties": {}}, + "annotations": {"readOnlyHint": True}, + "_meta": {"openai/ui": {"entrypoints": [{"type": "statusline", "resourceUri": RESOURCE_URI}]}}, +} + + +def supported_version(version: str) -> bool: + match = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d+))?(?:\+[\w.-]+)?", version) + if match is None: + return False + release = tuple(int(part) for part in match.group(1, 2, 3)) + if release != MINIMUM_VERSION: + return release > MINIMUM_VERSION + stage, number = match.group(4, 5) + return stage != "alpha" or int(number) >= MINIMUM_ALPHA + + +def launch_config(version: str, controls: Path) -> dict: + if not supported_version(version): + return {} + return { + "features.tui_extensions_statusline": True, + "tui.status_line_provider": {"server": SERVER_NAME, "tool": TOOL_NAME}, + "mcp_servers": { + SERVER_NAME: { + "command": sys.executable, + "args": ["-X", "utf8", "-m", __name__], + "env": {SESSION_ENV_VAR: str(controls)}, + "enabled": True, + } + }, + } + + +def _text(value: str, color: str) -> dict: + return {"type": "text", "props": {"color": color}, "children": [value]} + + +def render(state: dict[str, Any]) -> dict: + controls = os.environ.get(SESSION_ENV_VAR) + try: + if not controls: + raise ValueError("No session controls") + enabled = session_routing_enabled(Path(controls), retry=False) + label, color = ("ON", "green") if enabled else ("OFF", "yellow") + except (OSError, UnicodeError, ValueError): + label, color = "UNKNOWN", "yellow" + + thread = state.get("thread", {}) + model = thread.get("model", {}) + model_name = model.get("display_name") or model.get("id") or "Codex" + if model.get("reasoning_level"): + model_name += " " + model["reasoning_level"] + children = [_text(f"smart router {label}", color), _text(model_name, "status-model")] + cwd = thread.get("workspace", {}).get("cwd") + if cwd: + path = PureWindowsPath(cwd) if "\\" in cwd else PurePosixPath(cwd) + children.append(_text(path.name or str(path), "status-path")) + used = thread.get("usage", {}).get("context", {}).get("used_percentage") + if isinstance(used, (int, float)) and not isinstance(used, bool): + remaining = max(0, min(100, round(100 - used))) + children.append(_text(f"{remaining}% context left", "status-usage")) + separated: list = [] + for child in children: + if separated: + separated.append("·") + separated.append(child) + return {"type": "row", "props": {"gap": 1, "wrap": "wrap"}, "children": separated} + + +def respond(method: str, params: dict) -> dict: + if method == "initialize": + return { + "protocolVersion": "2025-06-18", + "capabilities": {"tools": {}, "resources": {}}, + "serverInfo": {"name": SERVER_NAME, "version": "1.0.0"}, + } + if method == "ping": + return {} + if method == "tools/list": + return {"tools": [TOOL]} + if method == "tools/call": + if params.get("name") != TOOL_NAME: + raise ValueError("Unknown tool") + return {"content": [{"type": "text", "text": f"Footer resource: {RESOURCE_URI}"}]} + if method == "resources/list": + return { + "resources": [{"name": "footer", "uri": RESOURCE_URI, "mimeType": "application/json"}] + } + if method == "resources/templates/list": + return {"resourceTemplates": []} + if method == "resources/read": + if params.get("uri") != RESOURCE_URI: + raise ValueError("Unknown resource") + state = params.get("_meta", {}).get(STATE_META_KEY, {}) + return { + "contents": [ + { + "uri": RESOURCE_URI, + "mimeType": "application/json", + "text": json.dumps(render(state)), + } + ] + } + raise KeyError(method) + + +def serve(stdin: TextIO, stdout: TextIO) -> None: + for line in stdin: + reply: dict = {"jsonrpc": "2.0", "id": None} + try: + request = json.loads(line) + if not isinstance(request, dict) or not isinstance(request.get("method"), str): + reply["error"] = {"code": -32600, "message": "Invalid request"} + elif "id" not in request: + continue + else: + reply["id"] = request["id"] + reply["result"] = respond(request["method"], request.get("params", {})) + except json.JSONDecodeError: + reply["error"] = {"code": -32700, "message": "Parse error"} + except KeyError: + reply["error"] = {"code": -32601, "message": "Method not found"} + except (TypeError, ValueError, AttributeError): + reply["error"] = {"code": -32602, "message": "Invalid parameters"} + stdout.write(json.dumps(reply) + "\n") + stdout.flush() + + +if __name__ == "__main__": + serve(sys.stdin, sys.stdout) diff --git a/src/ucode/smart_routing/session_env.py b/src/ucode/smart_routing/session_env.py index e0a7a295b..10ea8bb18 100644 --- a/src/ucode/smart_routing/session_env.py +++ b/src/ucode/smart_routing/session_env.py @@ -73,8 +73,8 @@ def _read_with_retry(path: Path) -> dict[str, str]: time.sleep(CONTROLS_READ_RETRY_SECONDS) -def session_routing_enabled(path: Path) -> bool: - overrides = _read_with_retry(path) +def session_routing_enabled(path: Path, *, retry: bool = True) -> bool: + overrides = _read_with_retry(path) if retry else _read(path) return not all( overrides.get(key) == "0" for key in (ENABLE_SMART_ROUTING_ENV_VAR, ENABLE_SUBAGENT_ROUTING_ENV_VAR) diff --git a/src/ucode/smart_routing/v2.py b/src/ucode/smart_routing/v2.py index ef1dff29f..08d918c03 100644 --- a/src/ucode/smart_routing/v2.py +++ b/src/ucode/smart_routing/v2.py @@ -58,7 +58,7 @@ install_skill, uninstall_agent_skill, ) -from ucode.smart_routing import claude_routing, orchestrator, routing, session_log +from ucode.smart_routing import claude_routing, codex_statusline, orchestrator, routing, session_log from ucode.smart_routing.claude_hooks import ( FIRST_PROMPT_SOCKET_ENV, ROUTE_SUBAGENT_MOD_EVENT, @@ -885,6 +885,7 @@ def launch_codex( binary: str, start_model: str | None, render_overlay: Callable[..., dict], + codex_version: str = "unknown", ) -> NoReturn: workspace = state.get("workspace") if not workspace: @@ -935,6 +936,8 @@ def launch_codex( overlay[f"shell_environment_policy.set.{SESSION_PYTHON_ENV_VAR}"] = os.environ[ SESSION_PYTHON_ENV_VAR ] + statusline_config = codex_statusline.launch_config(codex_version, session_env_path) + config_io.deep_merge_dict(overlay, statusline_config) config_args = codex_config_args(overlay) first_prompt = first_prompt_routing_enabled(agent=AGENT_CODEX) app_port = _free_port() @@ -981,7 +984,18 @@ def launch_codex( } ) tui = subprocess_cross_os.popen( - [binary, *provider_args, "--remote", tui_url, "--model", start_model, *tool_args] + [ + binary, + *provider_args, + *codex_config_args( + {key: value for key, value in statusline_config.items() if key != "mcp_servers"} + ), + "--remote", + tui_url, + "--model", + start_model, + *tool_args, + ] ) try: returncode = tui.wait() diff --git a/tests/README.md b/tests/README.md index 65474d7f7..fe69db59c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,15 @@ # Test suites and user journeys +`test_codex_statusline.py` covers the experimental footer's version boundary, +live control-file reads, ON/OFF/UNKNOWN recovery, per-thread display inputs, MCP +advertisement and protocol errors, and isolation between two real stdio provider +processes. `test_codex_smart_routing_v2.py` checks that both POSIX and Windows +launches wire the provider into the app-server and its selection into the terminal, +with first-prompt routing on or off. Stable 0.169.0 and alpha.11 receive no new +fields. These are offline component checks; native alpha UI and credentialed +gateway validation are separate, as described in the +[validation guide](../docs/codex-smart-router-statusline.md). + `test_security_scan_request.py` verifies the default-branch Security Scan's request validation, GitHub-sourced policy metadata, main policy checkout and isolated hosted scan. This prerequisite installs the producer and reusable consumer without making existing CI diff --git a/tests/integration/README.md b/tests/integration/README.md index 06498d52e..5d8bee0e6 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -1,5 +1,13 @@ # Integration tests +The experimental Codex footer has offline protocol, process-isolation, and launcher +coverage in `../test_codex_statusline.py` and `../test_codex_smart_routing_v2.py`. +The stable CI baseline does not exercise this new renderer. Test it with pinned +Codex `0.171.0-alpha.12` using the +[footer validation steps](../../docs/codex-smart-router-statusline.md). A native +footer or resource read alone does not establish gateway inference or routed-child +coverage. Keep the stable rollout gated on validation of the actual stable build. + `../test_agent_codex.py::TestCodexManagedConfig` covers managed catalog backup and rollback with real backup/revert logic and temporary-file privileged writers: a second user's configure/revert, failed TOML updates, failed rollback/revert, and later catalog edits. These component checks do not diff --git a/tests/test_codex_smart_routing_v2.py b/tests/test_codex_smart_routing_v2.py index 8a55204a5..9b636893e 100644 --- a/tests/test_codex_smart_routing_v2.py +++ b/tests/test_codex_smart_routing_v2.py @@ -3,6 +3,7 @@ import json import os import subprocess +import sys import tomllib from pathlib import Path from types import SimpleNamespace @@ -145,6 +146,7 @@ def launch_v2(state, tool_args, **kwargs): "binary": "codex", "start_model": "gpt-start", "render_overlay": codex._render_launch_overlay, + "codex_version": "0.164.0", }, ) ] @@ -252,8 +254,9 @@ def test_startup_config_precedence( @pytest.mark.parametrize("platform_name", ["posix", "nt"]) @pytest.mark.parametrize("first_prompt", [False, True]) + @pytest.mark.parametrize("codex_version", ["0.169.0", "0.171.0-alpha.11", "0.171.0-alpha.12"]) def test_owns_app_server_interposer_and_tui_lifecycle( - self, tmp_path, monkeypatch, platform_name, first_prompt + self, tmp_path, monkeypatch, platform_name, first_prompt, codex_version ): processes = [] interposer_args = {} @@ -309,6 +312,11 @@ def start_interposer(*args, **kwargs): monkeypatch.setattr(codex_interposer, "start_interposer_thread", start_interposer) + def render_overlay(*args, **kwargs): + overlay = codex.render_overlay(*args, **kwargs) + overlay["mcp_servers"] = {"other-server": {"command": "other-helper"}} + return overlay + with pytest.raises(SystemExit) as exc: v2.launch_codex( { @@ -320,7 +328,8 @@ def start_interposer(*args, **kwargs): ["--search"], binary="codex", start_model="gpt-start", - render_overlay=codex.render_overlay, + render_overlay=render_overlay, + codex_version=codex_version, ) assert exc.value.code == 7 @@ -334,9 +343,9 @@ def start_interposer(*args, **kwargs): "--config", ] assert processes[0].argv[7].startswith("model_providers.Databricks={") - assert processes[0].argv[8] == "--config" - hook_override = processes[0].argv[9] - assert hook_override.startswith("hooks.PreToolUse=[{") + hook_override = next( + arg for arg in processes[0].argv if arg.startswith("hooks.PreToolUse=[{") + ) assert 'matcher = "Agent|.*spawn_agent$"' in hook_override assert "codex-router-hook route-subagent" in hook_override assert f"--host {WS}" in hook_override @@ -345,6 +354,7 @@ def start_interposer(*args, **kwargs): assert "--model system.ai.glm-5-2" in hook_override config_values = processes[0].argv[3:-2:2] config = tomllib.loads("\n".join(config_values)) + assert config["mcp_servers"]["other-server"] == {"command": "other-helper"} assert config["responses_api_metadata"]["smart_router_recipe_name"] == ( v2.routing.configured_router_name() ) @@ -385,6 +395,39 @@ def start_interposer(*args, **kwargs): "gpt-start", "--search", ] + has_statusline = codex_version == "0.171.0-alpha.12" + statusline_args = [ + "--config", + "features.tui_extensions_statusline=true", + "--config", + 'tui.status_line_provider={server = "ug-smart-router-statusline", tool = "statusline"}', + ] + if has_statusline: + expected_tui_args = [*statusline_args, *expected_tui_args] + assert statusline_args[1] in config_values + assert statusline_args[3] in config_values + server_config = next( + value + for value in config_values + if value.startswith("mcp_servers.ug-smart-router-statusline=") + ) + assert json.dumps(sys.executable) in server_config + assert ( + 'args = ["-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"]' + in server_config + ) + assert json.dumps(os.environ["UCODE_SESSION_ENV_FILE"]) in server_config + else: + assert not any( + value.startswith( + ( + "features.tui_extensions_statusline=", + "tui.status_line_provider=", + "mcp_servers.ug-smart-router-statusline=", + ) + ) + for value in config_values + ) if platform_name == "nt": assert tui_argv[:4] == [ "codex", @@ -397,6 +440,8 @@ def start_interposer(*args, **kwargs): else: assert tui_argv == ["codex", *expected_tui_args] assert not any(arg.startswith("hooks.") for arg in tui_argv) + assert not any(arg.startswith("mcp_servers.") for arg in tui_argv) + assert user_config.read_bytes() == saved_config assert interposer_args["args"] == (v2.LOOPBACK_HOST, "ws://127.0.0.1:41001") assert interposer_args["kwargs"]["available_models"] == [ "system.ai.gpt-5-6-sol", diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py new file mode 100644 index 000000000..00ec4c59e --- /dev/null +++ b/tests/test_codex_statusline.py @@ -0,0 +1,230 @@ +"""Offline protocol and session isolation checks for the experimental Codex footer.""" + +import io +import json +import os +import queue +import subprocess +import sys +import threading + +import pytest + +from ucode.constants import ENABLE_SMART_ROUTING_ENV_VAR, ENABLE_SUBAGENT_ROUTING_ENV_VAR +from ucode.smart_routing import codex_statusline as statusline +from ucode.smart_routing.session_env import SESSION_ENV_VAR, set_session_environment, start_session + + +def _labels(tree): + if isinstance(tree, str): + return tree + return " ".join(_labels(child) for child in tree.get("children", [])) + + +def _read_lines(stream, replies): + for line in stream: + replies.put(line) + + +@pytest.mark.parametrize( + ("version", "supported"), + [ + ("unknown", False), + ("0.169.0", False), + ("0.170.0", False), + ("0.171.0-alpha.2", False), + ("0.171.0-alpha.11", False), + ("0.171.0-alpha.12", True), + ("0.171.0-alpha.13", True), + ("0.171.0-beta.1", True), + ("0.171.0-rc.1", True), + ("0.171.0", True), + ("0.171.0+build.1", True), + ("0.171.0-dev", False), + ("0.172.0", True), + ], +) +def test_statusline_version_boundary(version, supported): + assert statusline.supported_version(version) is supported + + +def test_launch_config_pins_session_without_credentials(tmp_path): + controls = tmp_path / "controls with spaces.json" + config = statusline.launch_config("0.171.0-alpha.12", controls) + server = config["mcp_servers"][statusline.SERVER_NAME] + assert server["command"] == sys.executable + assert server["args"] == ["-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"] + assert server["env"] == {SESSION_ENV_VAR: str(controls)} + assert config["features.tui_extensions_statusline"] is True + assert config["tui.status_line_provider"] == { + "server": statusline.SERVER_NAME, + "tool": statusline.TOOL_NAME, + } + assert statusline.launch_config("0.169.0", controls) == {} + + +def test_footer_tracks_session_toggles_and_current_thread(tmp_path, monkeypatch): + monkeypatch.setenv(SESSION_ENV_VAR, str(tmp_path / "controls.json")) + (tmp_path / "controls.json").write_text("{}") + state = { + "thread": { + "model": {"display_name": "GPT Test", "reasoning_level": "high"}, + "workspace": {"cwd": "/projects/my-app"}, + "usage": {"context": {"used_percentage": 25}}, + } + } + labels = _labels(statusline.render(state)) + assert "smart router ON" in labels + assert "GPT Test high" in labels + assert "my-app" in labels + assert "75% context left" in labels + set_session_environment( + {ENABLE_SMART_ROUTING_ENV_VAR: "0", ENABLE_SUBAGENT_ROUTING_ENV_VAR: "0"} + ) + assert "smart router OFF" in _labels(statusline.render(state)) + set_session_environment( + {ENABLE_SMART_ROUTING_ENV_VAR: "0", ENABLE_SUBAGENT_ROUTING_ENV_VAR: "1"} + ) + state["thread"]["model"] = {"display_name": "Other thread"} + assert "smart router ON" in _labels(statusline.render(state)) + assert "Other thread" in _labels(statusline.render(state)) + assert "GPT Test" not in _labels(statusline.render(state)) + + +def test_footer_handles_missing_snapshot_and_windows_paths(tmp_path, monkeypatch): + controls = tmp_path / "controls.json" + controls.write_text("{}") + monkeypatch.setenv(SESSION_ENV_VAR, str(controls)) + assert "Codex" in _labels(statusline.render({})) + assert "my-app" in _labels( + statusline.render({"thread": {"workspace": {"cwd": r"C:\projects\my-app"}}}) + ) + + +@pytest.mark.parametrize("contents", [None, "not-json", "[]", '{"unrecognized": "1"}']) +def test_unreadable_controls_show_unknown_and_recover(tmp_path, monkeypatch, contents): + controls = tmp_path / "controls.json" + monkeypatch.setenv(SESSION_ENV_VAR, str(controls)) + if contents is not None: + controls.write_text(contents) + assert "smart router UNKNOWN" in _labels(statusline.render({})) + controls.write_text("{}") + assert "smart router ON" in _labels(statusline.render({})) + + +def test_footer_does_not_retry_blocked_file_reads(tmp_path, monkeypatch): + def blocked(*_args, **_kwargs): + raise PermissionError("locked") + + monkeypatch.setenv(SESSION_ENV_VAR, str(tmp_path / "controls.json")) + monkeypatch.setattr(statusline.Path, "read_text", blocked) + monkeypatch.setattr( + "ucode.smart_routing.session_env.time.sleep", lambda _: pytest.fail("slept") + ) + assert "smart router UNKNOWN" in _labels(statusline.render({})) + + +def test_missing_session_controls_never_uses_inherited_on_state(monkeypatch): + monkeypatch.delenv(SESSION_ENV_VAR, raising=False) + monkeypatch.setenv(ENABLE_SMART_ROUTING_ENV_VAR, "1") + assert "smart router UNKNOWN" in _labels(statusline.render({})) + + +def test_stdio_errors_leave_provider_available(): + requests = [ + "not-json", + "[]", + json.dumps({"jsonrpc": "2.0", "method": "notifications/initialized"}), + json.dumps({"jsonrpc": "2.0", "id": 1, "method": "unknown"}), + json.dumps( + {"jsonrpc": "2.0", "id": 2, "method": "resources/read", "params": {"uri": "other"}} + ), + json.dumps({"jsonrpc": "2.0", "id": 3, "method": "tools/list"}), + ] + output = io.StringIO() + statusline.serve(io.StringIO("\n".join(requests) + "\n"), output) + replies = [json.loads(line) for line in output.getvalue().splitlines()] + assert [reply["error"]["code"] for reply in replies[:-1]] == [-32700, -32600, -32601, -32602] + assert replies[-1]["result"]["tools"][0]["_meta"]["openai/ui"]["entrypoints"] == [ + {"type": "statusline", "resourceUri": statusline.RESOURCE_URI} + ] + + +def test_real_stdio_process_keeps_sessions_separate_and_polls_live_controls(): + processes = [] + try: + for enabled in (True, False): + env = os.environ.copy() + controls = start_session(env) + if not enabled: + controls.write_text( + json.dumps( + {ENABLE_SMART_ROUTING_ENV_VAR: "0", ENABLE_SUBAGENT_ROUTING_ENV_VAR: "0"} + ) + ) + server = statusline.launch_config("0.171.0-alpha.12", controls)["mcp_servers"][ + statusline.SERVER_NAME + ] + process = subprocess.Popen( + [server["command"], *server["args"]], + env=env, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + encoding="utf-8", + ) + replies = queue.Queue() + threading.Thread( + target=_read_lines, args=(process.stdout, replies), daemon=True + ).start() + processes.append((process, controls, replies)) + for process, _controls, replies in processes: + process.stdin.write( + json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize"}) + "\n" + ) + process.stdin.flush() + assert json.loads(replies.get(timeout=10))["result"]["capabilities"] == { + "tools": {}, + "resources": {}, + } + for expected in (("ON", "OFF"), ("OFF", "OFF"), ("ON", "OFF")): + for (process, controls, replies), label in zip(processes, expected, strict=True): + if controls == processes[0][1]: + controls.write_text( + json.dumps( + { + ENABLE_SMART_ROUTING_ENV_VAR: "0", + ENABLE_SUBAGENT_ROUTING_ENV_VAR: "1" if label == "ON" else "0", + } + ) + ) + process.stdin.write( + json.dumps( + { + "jsonrpc": "2.0", + "id": 2, + "method": "resources/read", + "params": { + "uri": statusline.RESOURCE_URI, + "_meta": { + statusline.STATE_META_KEY: { + "thread": {"workspace": {"cwd": r"C:\projects\项目目录"}} + } + }, + }, + }, + ensure_ascii=False, + ) + + "\n" + ) + process.stdin.flush() + resource = json.loads(replies.get(timeout=10))["result"]["contents"][0] + assert f"smart router {label}" in _labels(json.loads(resource["text"])) + assert "项目目录" in _labels(json.loads(resource["text"])) + finally: + for process, controls, _replies in processes: + process.terminate() + process.communicate(timeout=5) + controls.unlink() + controls.parent.rmdir() From ae88c6551b5aaf7856eac9d31f41f349008149b3 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Tue, 17 Nov 2026 21:46:11 +0000 Subject: [PATCH 02/14] fix(codex): keep footer available for nullable snapshots --- src/ucode/smart_routing/codex_statusline.py | 20 ++++++++--- src/ucode/smart_routing/v2.py | 4 +-- tests/README.md | 2 +- tests/integration/README.md | 1 + tests/test_codex_statusline.py | 39 +++++++++++++++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py index 77033bfaf..0053e08c5 100644 --- a/src/ucode/smart_routing/codex_statusline.py +++ b/src/ucode/smart_routing/codex_statusline.py @@ -55,6 +55,18 @@ def launch_config(version: str, controls: Path) -> dict: } +def tui_config(config: dict) -> dict: + return { + key: config[key] + for key in ("features.tui_extensions_statusline", "tui.status_line_provider") + if key in config + } + + +def _object(value: Any) -> dict: + return value if isinstance(value, dict) else {} + + def _text(value: str, color: str) -> dict: return {"type": "text", "props": {"color": color}, "children": [value]} @@ -69,17 +81,17 @@ def render(state: dict[str, Any]) -> dict: except (OSError, UnicodeError, ValueError): label, color = "UNKNOWN", "yellow" - thread = state.get("thread", {}) - model = thread.get("model", {}) + thread = _object(_object(state).get("thread")) + model = _object(thread.get("model")) model_name = model.get("display_name") or model.get("id") or "Codex" if model.get("reasoning_level"): model_name += " " + model["reasoning_level"] children = [_text(f"smart router {label}", color), _text(model_name, "status-model")] - cwd = thread.get("workspace", {}).get("cwd") + cwd = _object(thread.get("workspace")).get("cwd") if cwd: path = PureWindowsPath(cwd) if "\\" in cwd else PurePosixPath(cwd) children.append(_text(path.name or str(path), "status-path")) - used = thread.get("usage", {}).get("context", {}).get("used_percentage") + used = _object(_object(thread.get("usage")).get("context")).get("used_percentage") if isinstance(used, (int, float)) and not isinstance(used, bool): remaining = max(0, min(100, round(100 - used))) children.append(_text(f"{remaining}% context left", "status-usage")) diff --git a/src/ucode/smart_routing/v2.py b/src/ucode/smart_routing/v2.py index 08d918c03..9d661afb0 100644 --- a/src/ucode/smart_routing/v2.py +++ b/src/ucode/smart_routing/v2.py @@ -987,9 +987,7 @@ def launch_codex( [ binary, *provider_args, - *codex_config_args( - {key: value for key, value in statusline_config.items() if key != "mcp_servers"} - ), + *codex_config_args(codex_statusline.tui_config(statusline_config)), "--remote", tui_url, "--model", diff --git a/tests/README.md b/tests/README.md index fe69db59c..419d7f1ce 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,7 @@ # Test suites and user journeys `test_codex_statusline.py` covers the experimental footer's version boundary, -live control-file reads, ON/OFF/UNKNOWN recovery, per-thread display inputs, MCP +live control-file reads, ON/OFF/UNKNOWN recovery, nullable per-thread display inputs, MCP advertisement and protocol errors, and isolation between two real stdio provider processes. `test_codex_smart_routing_v2.py` checks that both POSIX and Windows launches wire the provider into the app-server and its selection into the terminal, diff --git a/tests/integration/README.md b/tests/integration/README.md index 5d8bee0e6..06ed513fa 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -2,6 +2,7 @@ The experimental Codex footer has offline protocol, process-isolation, and launcher coverage in `../test_codex_statusline.py` and `../test_codex_smart_routing_v2.py`. +Those component checks also cover nullable snapshots and terminal config isolation. The stable CI baseline does not exercise this new renderer. Test it with pinned Codex `0.171.0-alpha.12` using the [footer validation steps](../../docs/codex-smart-router-statusline.md). A native diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py index 00ec4c59e..11bae3d82 100644 --- a/tests/test_codex_statusline.py +++ b/tests/test_codex_statusline.py @@ -63,6 +63,45 @@ def test_launch_config_pins_session_without_credentials(tmp_path): assert statusline.launch_config("0.169.0", controls) == {} +def test_terminal_config_contains_only_feature_and_selection(tmp_path): + config = statusline.launch_config("0.171.0-alpha.12", tmp_path / "controls.json") + config["server_only"] = "private" + assert statusline.tui_config(config) == { + "features.tui_extensions_statusline": True, + "tui.status_line_provider": { + "server": statusline.SERVER_NAME, + "tool": statusline.TOOL_NAME, + }, + } + assert statusline.tui_config({}) == {} + + +@pytest.mark.parametrize( + "state", + [ + None, + {"thread": None}, + {"thread": []}, + {"thread": {"model": None}}, + {"thread": {"model": []}}, + {"thread": {"workspace": None}}, + {"thread": {"usage": None}}, + {"thread": {"usage": {"context": None}}}, + ], +) +def test_nullable_snapshots_keep_footer_available(tmp_path, monkeypatch, state): + controls = tmp_path / "controls.json" + controls.write_text("{}") + monkeypatch.setenv(SESSION_ENV_VAR, str(controls)) + reply = statusline.respond( + "resources/read", + {"uri": statusline.RESOURCE_URI, "_meta": {statusline.STATE_META_KEY: state}}, + ) + labels = _labels(json.loads(reply["contents"][0]["text"])) + assert "smart router ON" in labels + assert "Codex" in labels + + def test_footer_tracks_session_toggles_and_current_thread(tmp_path, monkeypatch): monkeypatch.setenv(SESSION_ENV_VAR, str(tmp_path / "controls.json")) (tmp_path / "controls.json").write_text("{}") From 1d03365c819e975e7d37863a802ab275f5c38c73 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Tue, 17 Nov 2026 22:12:30 +0000 Subject: [PATCH 03/14] docs(codex): distinguish native onboarding from footer preferences --- docs/codex-smart-router-statusline.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md index 2d71a39c4..503537cdc 100644 --- a/docs/codex-smart-router-statusline.md +++ b/docs/codex-smart-router-statusline.md @@ -39,8 +39,10 @@ For a configured test workspace and an explicitly selected profile: 6. Repeat with `first_prompt_and_subagent_no_orch_v0` and complete an initial prompt. 7. Repeat on Windows. Confirm both the app-server and remote terminal receive the correct configuration, including when paths contain spaces. -8. Compare saved Codex settings before and after, allowing only Codex-owned trust - records. Existing footer preferences and unrelated MCP registrations must survive. +8. Compare saved footer preferences and MCP registrations before and after. + Codex may add its own trust and onboarding records, such as + `tui.screen_reader_detection_done`; compare `tui.status_line` and + `tui.status_line_provider` independently of that bookkeeping. 9. On stable `0.169.0`, confirm routed launch still works with its existing footer. Existing native routing journeys can be run with pinned alpha through From 880b2f98b4cdaf1bbc50608504ced129d2a8dfa7 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Wed, 18 Nov 2026 16:32:47 +0000 Subject: [PATCH 04/14] fix(codex): match Claude Smart Router state badges --- README.md | 4 ++- docs/codex-smart-router-statusline.md | 11 ++++++--- src/ucode/smart_routing/codex_statusline.py | 27 ++++++++++++++++++--- tests/README.md | 3 ++- tests/integration/README.md | 4 ++- tests/test_codex_statusline.py | 25 ++++++++++++++++++- 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37c274b5a..9f3da3a87 100644 --- a/README.md +++ b/README.md @@ -614,7 +614,9 @@ per-turn metadata; a static Codex `responses_api_metadata` entry with that name would override dynamic values. Routed Codex terminal sessions on **0.171.0-alpha.12 or newer** show -`smart router ON/OFF` beside the current model, directory, and remaining context. +`smart router` with a green `ON` or gray `OFF` badge beside the current model, +directory, and remaining context, matching Claude's badge colors. The indicator +stays visible when routing is off, as Claude's prompt hint does. This uses Codex's experimental MCP status-line provider API. Earlier versions, including stable 0.169.0, keep their existing footer. UG does not install an alpha or raise its minimum Codex version for this feature. diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md index 503537cdc..26458a72e 100644 --- a/docs/codex-smart-router-statusline.md +++ b/docs/codex-smart-router-statusline.md @@ -10,6 +10,11 @@ routing attribution. Existing children and an ongoing main turn keep their origi attribution after a toggle. A failed controls read shows `UNKNOWN` without stopping Codex's polling, so the next successful read can recover. +The state badge matches Claude's Smart Router banner: bold black `ON` on green, +or bold black `OFF` on gray. Claude keeps an ON/OFF hint below the prompt after its +temporary banner disappears; disabling routing does not hide that hint. Codex keeps +the badge in its persistent footer, since this API only controls the footer. + ## Validation Install the checkout in an isolated Python environment and use Codex @@ -28,11 +33,11 @@ just lint For a configured test workspace and an explicitly selected profile: 1. Launch `SMART_ROUTER_CONFIG_VERSION=subagent_only_v0 ug codex`. Check the - native footer shows `smart router ON` alongside model and project directory. + native footer shows `smart router` with a green `ON` badge alongside model and project directory. 2. Ask Codex to read a file containing an unpredictable value. Require the correct value in its completed answer, rather than accepting a startup banner as inference. -3. Submit `$smart-router off`. After the command succeeds, require `smart router OFF` - in the footer without restarting the conversation. +3. Submit `$smart-router off`. After the command succeeds, require a gray `OFF` + badge in the footer without restarting the conversation. The indicator stays visible. 4. Submit `$smart-router on` and require `smart router ON` again. Complete another file task in the same conversation. 5. Open a second session. Toggle one and check the other session's footer is unchanged. diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py index 0053e08c5..d37611807 100644 --- a/src/ucode/smart_routing/codex_statusline.py +++ b/src/ucode/smart_routing/codex_statusline.py @@ -71,22 +71,43 @@ def _text(value: str, color: str) -> dict: return {"type": "text", "props": {"color": color}, "children": [value]} +def _router_indicator(label: str) -> dict: + if label == "UNKNOWN": + return _text("smart router UNKNOWN", "yellow") + badge = { + "type": "row", + "props": {"gap": 0, "background": "green" if label == "ON" else "#808080"}, + "children": [ + { + "type": "text", + "props": {"color": "black", "weight": "bold"}, + "children": [f" {label} "], + } + ], + } + return { + "type": "row", + "props": {"gap": 1}, + "children": [_text("smart router", "primary"), badge], + } + + def render(state: dict[str, Any]) -> dict: controls = os.environ.get(SESSION_ENV_VAR) try: if not controls: raise ValueError("No session controls") enabled = session_routing_enabled(Path(controls), retry=False) - label, color = ("ON", "green") if enabled else ("OFF", "yellow") + label = "ON" if enabled else "OFF" except (OSError, UnicodeError, ValueError): - label, color = "UNKNOWN", "yellow" + label = "UNKNOWN" thread = _object(_object(state).get("thread")) model = _object(thread.get("model")) model_name = model.get("display_name") or model.get("id") or "Codex" if model.get("reasoning_level"): model_name += " " + model["reasoning_level"] - children = [_text(f"smart router {label}", color), _text(model_name, "status-model")] + children = [_router_indicator(label), _text(model_name, "status-model")] cwd = _object(thread.get("workspace")).get("cwd") if cwd: path = PureWindowsPath(cwd) if "\\" in cwd else PurePosixPath(cwd) diff --git a/tests/README.md b/tests/README.md index 419d7f1ce..39a49ccdf 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,8 @@ # Test suites and user journeys `test_codex_statusline.py` covers the experimental footer's version boundary, -live control-file reads, ON/OFF/UNKNOWN recovery, nullable per-thread display inputs, MCP +live control-file reads, Claude-style green ON/gray OFF badges, ON/OFF/UNKNOWN recovery, +nullable per-thread display inputs, MCP advertisement and protocol errors, and isolation between two real stdio provider processes. `test_codex_smart_routing_v2.py` checks that both POSIX and Windows launches wire the provider into the app-server and its selection into the terminal, diff --git a/tests/integration/README.md b/tests/integration/README.md index 06ed513fa..f29802730 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -2,7 +2,9 @@ The experimental Codex footer has offline protocol, process-isolation, and launcher coverage in `../test_codex_statusline.py` and `../test_codex_smart_routing_v2.py`. -Those component checks also cover nullable snapshots and terminal config isolation. +Those component checks also cover Claude-style green ON/gray OFF badges, nullable +snapshots, and terminal config isolation. Native UI checks must verify badge colors +as well as the ON/OFF text; OFF remains visible, matching Claude's persistent hint. The stable CI baseline does not exercise this new renderer. Test it with pinned Codex `0.171.0-alpha.12` using the [footer validation steps](../../docs/codex-smart-router-statusline.md). A native diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py index 11bae3d82..110aa6303 100644 --- a/tests/test_codex_statusline.py +++ b/tests/test_codex_statusline.py @@ -18,7 +18,7 @@ def _labels(tree): if isinstance(tree, str): return tree - return " ".join(_labels(child) for child in tree.get("children", [])) + return " ".join(" ".join(_labels(child) for child in tree.get("children", [])).split()) def _read_lines(stream, replies): @@ -140,6 +140,29 @@ def test_footer_handles_missing_snapshot_and_windows_paths(tmp_path, monkeypatch ) +@pytest.mark.parametrize( + ("enabled", "label", "background"), [(True, "ON", "green"), (False, "OFF", "#808080")] +) +def test_footer_matches_claude_badges(tmp_path, monkeypatch, enabled, label, background): + controls = tmp_path / "controls.json" + controls.write_text( + json.dumps( + { + ENABLE_SMART_ROUTING_ENV_VAR: "0", + ENABLE_SUBAGENT_ROUTING_ENV_VAR: "1" if enabled else "0", + } + ) + ) + monkeypatch.setenv(SESSION_ENV_VAR, str(controls)) + indicator = statusline.render({})["children"][0] + assert _labels(indicator) == f"smart router {label}" + badge = indicator["children"][1] + assert badge["props"] == {"gap": 0, "background": background} + assert badge["children"] == [ + {"type": "text", "props": {"color": "black", "weight": "bold"}, "children": [f" {label} "]} + ] + + @pytest.mark.parametrize("contents", [None, "not-json", "[]", '{"unrecognized": "1"}']) def test_unreadable_controls_show_unknown_and_recover(tmp_path, monkeypatch, contents): controls = tmp_path / "controls.json" From a8c681bf6bed20be01cee2e035db1b1ba714e574 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Wed, 18 Nov 2026 17:22:38 +0000 Subject: [PATCH 05/14] fix(codex): exclude working directory from footer imports --- src/ucode/smart_routing/codex_statusline.py | 2 +- tests/README.md | 4 ++-- tests/integration/README.md | 5 +++-- tests/test_codex_smart_routing_v2.py | 2 +- tests/test_codex_statusline.py | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py index d37611807..0ce620454 100644 --- a/src/ucode/smart_routing/codex_statusline.py +++ b/src/ucode/smart_routing/codex_statusline.py @@ -47,7 +47,7 @@ def launch_config(version: str, controls: Path) -> dict: "mcp_servers": { SERVER_NAME: { "command": sys.executable, - "args": ["-X", "utf8", "-m", __name__], + "args": ["-P", "-X", "utf8", "-m", __name__], "env": {SESSION_ENV_VAR: str(controls)}, "enabled": True, } diff --git a/tests/README.md b/tests/README.md index d530ca746..d34562f81 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,8 +4,8 @@ live control-file reads, Claude-style green ON/gray OFF badges, ON/OFF/UNKNOWN recovery, nullable per-thread display inputs, MCP advertisement and protocol errors, and isolation between two real stdio provider -processes. `test_codex_smart_routing_v2.py` checks that both POSIX and Windows -launches wire the provider into the app-server and its selection into the terminal, +processes using Python's `-P` launch flag. `test_codex_smart_routing_v2.py` checks +that both POSIX and Windows launches wire the provider into the app-server and its selection into the terminal, with first-prompt routing on or off. Stable 0.169.0 and alpha.11 receive no new fields. These are offline component checks; native alpha UI and credentialed gateway validation are separate, as described in the diff --git a/tests/integration/README.md b/tests/integration/README.md index 29d9b2421..9cdb6bc84 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -3,8 +3,9 @@ The experimental Codex footer has offline protocol, process-isolation, and launcher coverage in `../test_codex_statusline.py` and `../test_codex_smart_routing_v2.py`. Those component checks also cover Claude-style green ON/gray OFF badges, nullable -snapshots, and terminal config isolation. Native UI checks must verify badge colors -as well as the ON/OFF text; OFF remains visible, matching Claude's persistent hint. +snapshots, Python's `-P` provider launch flag, and terminal config isolation. Native +UI checks must verify badge colors as well as the ON/OFF text; OFF remains visible, +matching Claude's persistent hint. The stable CI baseline does not exercise this new renderer. Test it with pinned Codex `0.171.0-alpha.12` using the [footer validation steps](../../docs/codex-smart-router-statusline.md). A native diff --git a/tests/test_codex_smart_routing_v2.py b/tests/test_codex_smart_routing_v2.py index 7541c69e8..dc41469ac 100644 --- a/tests/test_codex_smart_routing_v2.py +++ b/tests/test_codex_smart_routing_v2.py @@ -413,7 +413,7 @@ def render_overlay(*args, **kwargs): ) assert json.dumps(sys.executable) in server_config assert ( - 'args = ["-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"]' + 'args = ["-P", "-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"]' in server_config ) assert json.dumps(os.environ["UCODE_SESSION_ENV_FILE"]) in server_config diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py index 110aa6303..d290f90c9 100644 --- a/tests/test_codex_statusline.py +++ b/tests/test_codex_statusline.py @@ -53,7 +53,7 @@ def test_launch_config_pins_session_without_credentials(tmp_path): config = statusline.launch_config("0.171.0-alpha.12", controls) server = config["mcp_servers"][statusline.SERVER_NAME] assert server["command"] == sys.executable - assert server["args"] == ["-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"] + assert server["args"] == ["-P", "-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"] assert server["env"] == {SESSION_ENV_VAR: str(controls)} assert config["features.tui_extensions_statusline"] is True assert config["tui.status_line_provider"] == { From cb9fc5f78f5d49ff3f1b61ee036d09eace9664ca Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 13:48:21 +0000 Subject: [PATCH 06/14] feat(codex): require stable 0.171.0 for Smart Router footer --- .github/workflows/integration.yml | 6 +- AGENTS.md | 4 +- README.md | 37 ++++----- docs/codex-smart-router-statusline.md | 39 +++++++--- src/ucode/agents/codex.py | 21 +++-- src/ucode/cli.py | 8 ++ src/ucode/smart_routing/codex_statusline.py | 18 +---- src/ucode/smart_routing/v2.py | 3 +- tests/README.md | 26 +++---- tests/integration/README.md | 23 +++--- tests/integration/test_ug_codex_app_server.py | 2 +- .../test_ug_smart_routing_hooks.py | 32 ++++++-- tests/test_agent_codex.py | 12 ++- tests/test_cli.py | 31 +++++--- tests/test_codex_smart_routing_v2.py | 78 ++++++++----------- tests/test_codex_statusline.py | 31 +------- tests/test_integration_contract.py | 4 +- 17 files changed, 187 insertions(+), 188 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index daaf28f24..2a1fd725d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -704,7 +704,7 @@ jobs: CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} DEPENDENCY: ${{ inputs.dependency }} AGENT: ${{ matrix.agent }} - CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || inputs.codex_version || '0.156.0' }} # Smoke cases already ran on this OS in the smoke job; don't repeat them here. TEST_MARKER: live and ${{ matrix.agent }} and not soft_fail and not smoke and not anthropic_mps and not codex_relay and ${{ matrix.smart_routing && 'codex_smart_routing' || 'not codex_smart_routing' }} ARTIFACT_NAME: integration-full-${{ matrix.agent }}-${{ matrix.os }}${{ matrix.smart_routing && '-smart-routing' || '' }} @@ -913,7 +913,7 @@ jobs: env: DEPENDENCY: ${{ inputs.dependency }} AGENT: ${{ matrix.agent }} - CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || inputs.codex_version || '0.156.0' }} ARTIFACT_NAME: integration-managed-${{ matrix.agent }}${{ matrix.smart_routing && '-smart-routing' || '' }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -1002,7 +1002,7 @@ jobs: matrix: include: ${{ fromJSON(needs.dedicated-cuj-plan.outputs.cujs) }} env: - CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || matrix.test == 'test_cuj7_model_discovery.py') && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || matrix.test == 'test_cuj7_model_discovery.py') && '0.171.0' || inputs.codex_version || '0.156.0' }} UV_INDEX_URL: https://pypi.org/simple # Every CUJ runner installs from PyPI at once; ride out slow responses instead of failing a shard. UV_HTTP_TIMEOUT: "120" diff --git a/AGENTS.md b/AGENTS.md index e1b0051b3..e136fbb4d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -474,8 +474,8 @@ Fields live in `~/.codex/ucode.config.toml` and `/etc/codex/managed_config.toml` | `otel.trace_exporter` | Ignore | Create/replace | In `~/.codex/config.toml` when the config enables tracing, for Codex desktop; another exporter and other telemetry settings left alone | | `mcp_servers` | Ignore | Merge | Managed file; add/update the config's MCP server entries, other entries left alone. A same-name entry in `~/.codex/config.toml` of the other transport (stdio vs HTTP) is removed, since Codex would merge the two into an invalid entry | | Smart Router and Smart Router Orchestrator hooks | Merge | Merge | Launch-only `PreToolUse`, plus `UserPromptSubmit` and compact `SessionStart` with `ENABLE_SMART_ROUTER_ORCHESTRATOR=1`; Codex combines them with its native hook sources and applies project trust; `features.hooks` is enabled for a smart-routed launch | -| Native v2 collaboration | Launch-only (-c), never written | Launch-only (-c), never written | `features.multi_agent_v2.non_code_mode_only=false` and matching `root_agent_usage_hint_text` / `subagent_usage_hint_text` override saved values for the session; only for smart routing on Codex 0.164.0 or newer. User config files, general developer instructions, and native delegation-mode controls are preserved | -| Smart Router footer | Launch-only (-c), never written | Launch-only (-c), never written | On routed Codex 0.171.0-alpha.12 or newer, enable `features.tui_extensions_statusline`, select `tui.status_line_provider`, and add only `mcp_servers.ug-smart-router-statusline`. The app-server owns the session-local stdio provider; the terminal client receives the feature and selection overrides. Older clients receive none of these fields. Saved footer settings and unrelated MCP servers are preserved. Do not require an alpha or raise the minimum version before stable validation | +| Native v2 collaboration | Launch-only (-c), never written | Launch-only (-c), never written | `features.multi_agent_v2.non_code_mode_only=false` and matching `root_agent_usage_hint_text` / `subagent_usage_hint_text` override saved values for the session; only for smart routing on Codex 0.171.0 or newer. User config files, general developer instructions, and native delegation-mode controls are preserved | +| Smart Router footer | Launch-only (-c), never written | Launch-only (-c), never written | On routed Codex 0.171.0 or newer, enable `features.tui_extensions_statusline`, select `tui.status_line_provider`, and add only `mcp_servers.ug-smart-router-statusline`. The app-server owns the session-local stdio provider; the terminal client receives the feature and selection overrides. Routed launches require stable 0.171.0 or newer through the existing upgrade gate. Saved footer settings and unrelated MCP servers are preserved. The footer relies on that launch gate; do not add a second version probe | | Smart Router native metadata | Launch-only (-c), never written | Launch-only (-c), never written | `responses_api_metadata.smart_router_recipe_name` records the configured recipe. The app-server interposer updates `smart_router_state` per main turn; spawn hooks stamp child task names. Reserve the state key for the interposer; a static config value would override turn updates | diff --git a/README.md b/README.md index e05ea04ad..d80ce0299 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ When Claude Code or Codex is older than the minimum version `ug` supports, `ug` asks before upgrading it in place. Set `UG_AUTO_UPGRADE_AGENT=1` to upgrade without asking, for example from a launcher that manages the agent install. -Codex smart routing now requires 0.164.0, including existing managed-enabled +Codex smart routing now requires 0.171.0, including existing managed-enabled workspaces. See the [compatibility and upgrade note](#codex-smart-routing-compatibility) for upgrading or launching with `--disable-smart-routing`. @@ -687,18 +687,15 @@ Routing-enabled responses are buffered until each model step completes. ### Codex smart-routing compatibility -Smart routing now requires Codex 0.164.0 -or newer, including workspaces that already enable managed smart routing. Users on -Codex 0.156–0.163 who previously launched successfully must upgrade or explicitly -run `ug codex --disable-smart-routing`. UG offers its usual upgrade prompt for a -known older version and checks the result before launching. Declining, failing, or -remaining below 0.164.0 after the upgrade keeps the routed launch blocked. This -intentional requirement ensures native v2 provides readable delegated assignments; -UG does not silently disable routing. A routed `ug codex app-server` cannot prompt, -because its stdin carries the client's protocol, so on a known older Codex it warns -on stderr and runs without smart routing instead. Ordinary launches require Codex 0.156.0 -and newer. The general integration CI baseline is 0.156.0; routing cases use -0.165.0. +Smart routing requires Codex **0.171.0 or newer**, including workspaces that already +use managed routing. A known older client cannot silently fall back to unrouted work. Earlier versions, including 0.171.0 prereleases, must upgrade +or explicitly run `ug codex --disable-smart-routing`. UG offers its usual upgrade +prompt and checks the result before launching. Declining or failing the upgrade +keeps the routed launch blocked. `UG_AUTO_UPGRADE_AGENT=1` runs that upgrade without +asking. This requirement provides both the native Smart Router footer and readable +delegated assignments; UG does not silently disable routing. Ordinary launches +require Codex 0.156.0 or newer. Routing CI pins stable 0.171.0; the general baseline +remains 0.156.0. An inconclusive Codex version probe is retried once with a longer timeout. If the version is still unknown, UG stops without offering or running an update and asks @@ -739,13 +736,11 @@ bypass `spawn_agent` have no guaranteed marker. Reserve `smart_router_state` for per-turn metadata; a static Codex `responses_api_metadata` entry with that name would override dynamic values. -Routed Codex terminal sessions on **0.171.0-alpha.12 or newer** show -`smart router` with a green `ON` or gray `OFF` badge beside the current model, -directory, and remaining context, matching Claude's badge colors. The indicator -stays visible when routing is off, as Claude's prompt hint does. -This uses Codex's experimental MCP status-line provider API. Earlier versions, -including stable 0.169.0, keep their existing footer. UG does not install an alpha -or raise its minimum Codex version for this feature. +Routed Codex terminal sessions show `smart router` with a green `ON` or gray `OFF` +badge beside the current model, directory, and remaining context. The indicator +stays visible when routing is off, as Claude's prompt hint does. The MCP status-line +provider API ships in stable Codex 0.171.0 and still requires its experimental +feature flag, which UG supplies for that launch. The indicator reads the same session controls as routing on each refresh, including after `$smart-router off` and `$smart-router on`. Unreadable controls show @@ -755,7 +750,7 @@ only; saved status-line settings and other MCP servers are preserved. The select footer replaces the normal footer's item layout for that session. This does not add an indicator to the Codex desktop app or other app-server clients. -For alpha validation and the stable-release rollout gate, see +For validation and upgrade behavior, see [Codex Smart Router footer](docs/codex-smart-router-statusline.md). ### Smart Router Orchestrator diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md index 26458a72e..e133526b6 100644 --- a/docs/codex-smart-router-statusline.md +++ b/docs/codex-smart-router-statusline.md @@ -1,7 +1,7 @@ # Codex Smart Router footer The terminal footer uses the experimental MCP status-line provider API first -available in Codex `0.171.0-alpha.12`. UG registers a local stdio provider for each +shipped in stable Codex `0.171.0`. UG registers a local stdio provider for each routed launch and selects it in the terminal client. Both configurations are launch-only. The provider needs no gateway credentials or network access. @@ -18,7 +18,7 @@ the badge in its persistent footer, since this API only controls the footer. ## Validation Install the checkout in an isolated Python environment and use Codex -`0.171.0-alpha.12` on that environment's PATH. Do not replace the user's stable +`0.171.0` on that environment's PATH. Do not replace the user's installation as part of automated tests. Check both `codex --version` and `ug --version`. Run the offline checks: @@ -48,21 +48,36 @@ For a configured test workspace and an explicitly selected profile: Codex may add its own trust and onboarding records, such as `tui.screen_reader_detection_done`; compare `tui.status_line` and `tui.status_line_provider` independently of that bookkeeping. -9. On stable `0.169.0`, confirm routed launch still works with its existing footer. +9. With an older client, verify the upgrade gate blocks routed launch until the + upgrade succeeds. `--disable-smart-routing` retains ordinary launch behavior. -Existing native routing journeys can be run with pinned alpha through -`scripts/run_integration.py --ug-version checkout --codex-version 0.171.0-alpha.12 +Existing native routing journeys can be run with pinned stable Codex through +`scripts/run_integration.py --ug-version checkout --codex-version 0.171.0 --profile --workspace -- -k routing_toggle`. Those journeys verify inference and session continuity; the footer assertions above are additional manual UI checks. -## Stable rollout +## Stable validation -Keep the feature PR in draft while testing the alpha. Do not force users onto an -experimental Codex release. Before delivery, identify the first stable release -containing the provider API, rerun protocol, UI, and routed inference checks on that -exact build, then update UG's minimum Codex version and its existing upgrade tests. -Version `0.171.0` is a candidate, not a confirmed stable release target. +On 2026-11-20, native Linux Codex `0.171.0` passed ON/OFF/ON badge rendering and +UNKNOWN/read recovery. An isolated-wheel Arclet run against the supplied workspace +completed five hidden-file tasks across two concurrent sessions and a first-prompt +launch, with installed-skill toggles, unchanged conversation identity, independent +controls, and unchanged saved footer settings and UG profile. GPT-6-Luna was selected +through ordinary user settings. Seven installation checks passed. + +Successful router selection remains unverified: first-prompt routing returned HTTP +400/downstream 422 and fell back; delegated child file tasks completed but produced +no routing decision. These are separate from the passing footer checks. Native +Windows rendering remains untested. + +## Required upgrade + +Routed launches require stable Codex `0.171.0` or newer. Earlier builds, including +`0.171.0-alpha.*`, must pass the existing native upgrade flow before starting. +Declining or failing the upgrade blocks routed launch; `--disable-smart-routing` +keeps ordinary launch behavior. `UG_AUTO_UPGRADE_AGENT=1` selects automatic upgrade. +The footer is registered after that launch gate, without a second version probe. Upstream contract and starter: -[create-statusline](https://github.com/openai/codex/blob/rust-v0.171.0-alpha.12/codex-rs/skills/src/assets/samples/create-statusline/SKILL.md). +[create-statusline](https://github.com/openai/codex/blob/rust-v0.171.0/codex-rs/skills/src/assets/samples/create-statusline/SKILL.md). diff --git a/src/ucode/agents/codex.py b/src/ucode/agents/codex.py index f2e3189d6..36529695d 100644 --- a/src/ucode/agents/codex.py +++ b/src/ucode/agents/codex.py @@ -147,8 +147,8 @@ # older releases ignore it and would leave developers free to bypass the gateway. MINIMUM_CODEX_VERSION = (0, 156, 0) MINIMUM_CODEX_VERSION_TEXT = "0.156.0" -MINIMUM_SMART_ROUTING_CODEX_VERSION = (0, 164, 0) -MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT = "0.164.0" +MINIMUM_SMART_ROUTING_CODEX_VERSION = (0, 171, 0) +MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT = "0.171.0" # Codex 0.134.0 introduced per-profile config files; older releases use the legacy layout. LEGACY_LAYOUT_CODEX_VERSION = (0, 134, 0) LEGACY_LAYOUT_CODEX_VERSION_TEXT = "0.134.0" @@ -191,6 +191,14 @@ def _parse_version(value: str) -> tuple[int, int, int] | None: return int(major), int(minor), int(patch) +def _smart_routing_version_supported(version: str) -> bool: + parsed = _parse_version(version) + return parsed is not None and ( + parsed > MINIMUM_SMART_ROUTING_CODEX_VERSION + or (parsed == MINIMUM_SMART_ROUTING_CODEX_VERSION and "-" not in version.partition("+")[0]) + ) + + def minimum_version_error(*, smart_routing_enabled: bool = False) -> str | None: version = agent_version(SPEC["binary"]) parsed = _parse_version(version) @@ -206,11 +214,11 @@ def minimum_version_error(*, smart_routing_enabled: bool = False) -> str | None: "or newer. Run `codex --version` to check the installation, " "or launch with --disable-smart-routing." ) - if parsed >= MINIMUM_SMART_ROUTING_CODEX_VERSION: + if _smart_routing_version_supported(version): return None return ( f"Codex smart routing requires Codex {MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT} " - f"or newer for readable delegated assignments; found {version}. " + f"or newer for the Smart Router footer and native delegation; found {version}. " "Upgrade Codex or launch with --disable-smart-routing." ) if parsed is None or parsed >= MINIMUM_CODEX_VERSION: @@ -1959,8 +1967,8 @@ def _app_server_needs_newer_codex(tool_args: list[str]) -> bool: """ if not is_codex_app_server_launch(tool_args): return False - parsed = _parse_version(agent_version(SPEC["binary"])) - return parsed is not None and parsed < MINIMUM_SMART_ROUTING_CODEX_VERSION + version = agent_version(SPEC["binary"]) + return _parse_version(version) is not None and not _smart_routing_version_supported(version) def launch( @@ -2161,7 +2169,6 @@ def _launch_smart_routing( binary=binary, start_model=start_model, render_overlay=_render_launch_overlay, - codex_version=agent_version(binary), **( {"launch_config": launch_config, "available_models": models} if launch_config is not None diff --git a/src/ucode/cli.py b/src/ucode/cli.py index e2860fff3..8d3f120e4 100644 --- a/src/ucode/cli.py +++ b/src/ucode/cli.py @@ -39,6 +39,7 @@ configure_single_tool, configure_tool, ensure_bootstrap_dependencies, + ensure_minimum_version, ensure_provider_state, explicit_model_arg_value, install_databricks_ai_tools_for_agents, @@ -4457,6 +4458,13 @@ def _launch_tool( ) except RuntimeError as exc: routing_unavailable = str(exc) + else: + if routing_unavailable: + ensure_minimum_version( + "codex", + lambda: codex_agent.minimum_version_error(smart_routing_enabled=True), + ) + routing_unavailable = None if routing_unavailable: print_warning(f"{routing_unavailable} Running without smart routing.") smart_routing_enabled = False diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py index 0ce620454..99d0e3361 100644 --- a/src/ucode/smart_routing/codex_statusline.py +++ b/src/ucode/smart_routing/codex_statusline.py @@ -4,15 +4,12 @@ import json import os -import re import sys from pathlib import Path, PurePosixPath, PureWindowsPath from typing import Any, TextIO from ucode.smart_routing.session_env import SESSION_ENV_VAR, session_routing_enabled -MINIMUM_VERSION = (0, 171, 0) -MINIMUM_ALPHA = 12 SERVER_NAME = "ug-smart-router-statusline" TOOL_NAME = "statusline" RESOURCE_URI = "ui://ug-smart-router/footer" @@ -27,20 +24,7 @@ } -def supported_version(version: str) -> bool: - match = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d+))?(?:\+[\w.-]+)?", version) - if match is None: - return False - release = tuple(int(part) for part in match.group(1, 2, 3)) - if release != MINIMUM_VERSION: - return release > MINIMUM_VERSION - stage, number = match.group(4, 5) - return stage != "alpha" or int(number) >= MINIMUM_ALPHA - - -def launch_config(version: str, controls: Path) -> dict: - if not supported_version(version): - return {} +def launch_config(controls: Path) -> dict: return { "features.tui_extensions_statusline": True, "tui.status_line_provider": {"server": SERVER_NAME, "tool": TOOL_NAME}, diff --git a/src/ucode/smart_routing/v2.py b/src/ucode/smart_routing/v2.py index 8373dd28e..50f4f144a 100644 --- a/src/ucode/smart_routing/v2.py +++ b/src/ucode/smart_routing/v2.py @@ -1091,7 +1091,6 @@ def launch_codex( binary: str, start_model: str | None, render_overlay: Callable[..., dict], - codex_version: str = "unknown", launch_config: dict | None = None, available_models: list[str] | None = None, ) -> NoReturn: @@ -1150,7 +1149,7 @@ def launch_codex( overlay[f"shell_environment_policy.set.{SESSION_PYTHON_ENV_VAR}"] = os.environ[ SESSION_PYTHON_ENV_VAR ] - statusline_config = codex_statusline.launch_config(codex_version, session_env_path) + statusline_config = codex_statusline.launch_config(session_env_path) config_io.deep_merge_dict(overlay, statusline_config) config_args = codex_config_args(overlay) if app_server_launch: diff --git a/tests/README.md b/tests/README.md index 1b238f0c5..507b40ea5 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,15 +1,15 @@ # Test suites and user journeys -`test_codex_statusline.py` covers the experimental footer's version boundary, -live control-file reads, Claude-style green ON/gray OFF badges, ON/OFF/UNKNOWN recovery, -nullable per-thread display inputs, MCP -advertisement and protocol errors, and isolation between two real stdio provider -processes using Python's `-P` launch flag. `test_codex_smart_routing_v2.py` checks -that both POSIX and Windows launches wire the provider into the app-server and its selection into the terminal, -with first-prompt routing on or off. Stable 0.169.0 and alpha.11 receive no new -fields. These are offline component checks; native alpha UI and credentialed -gateway validation are separate, as described in the -[validation guide](../docs/codex-smart-router-statusline.md). +`test_codex_statusline.py` covers live control-file reads, Claude-style green ON/gray +OFF badges, ON/OFF/UNKNOWN recovery, nullable snapshots, MCP advertisement and +protocol errors, and two real stdio providers using Python's `-P` flag. +`test_codex_smart_routing_v2.py` checks POSIX/Windows wiring and the required upgrade +from older builds to stable 0.171.0. `test_agent_codex.py` owns version boundaries, +including prerelease rejection at the minimum, and slow-probe recovery; +`test_cli.py` covers explicit and managed upgrade/decline/disable through the public command. The separate +footer version gate was removed because routed launch now enforces the requirement. +These are component checks; native UI and credentialed gateway validation are +separate, as described in the [validation guide](../docs/codex-smart-router-statusline.md). Custom Codex model-service metadata has component coverage in `test_codex_catalog.py`, `test_databricks.py`, `test_agent_codex.py`, and `test_published_agent_config.py`. @@ -1105,7 +1105,7 @@ gateway provider on Windows while Unix launch arguments stay unchanged and routi hooks stay with the app-server. This is component coverage, not a live Windows sign-in or TUI test. -`integration/test_ug_codex_v2_routing.py` checks native v2 on Codex 0.164.0 or newer: +`integration/test_ug_codex_v2_routing.py` checks native v2 on Codex 0.171.0 or newer: the exact multiline assignment reaches the real hook, router, and native child; the child completes on the routed model while the parent stays pinned. The audit's SHA-256 digest and character count identify that exact assignment without @@ -1512,8 +1512,8 @@ Databricks Hosted configure/TUI, custom OAuth CLI TUI, and headless argument journeys for both agents, in two parallel jobs. After smoke finishes, the full suite runs the remaining live cases in separate agent and OS jobs, with cases serial inside each VM. Codex smoke and general full/managed coverage retain -0.156.0. Separate required full and managed matrix rows use 0.165.0 only for -`codex_smart_routing` cases; CUJ4 also uses 0.165.0, while other CUJs retain +0.156.0. Separate required full and managed matrix rows use 0.171.0 only for +`codex_smart_routing` cases; CUJ4 also uses 0.171.0, while other CUJs retain 0.156.0. The catalog-fallback routing-off case stays on the baseline version. The existing workflow contract tests collect both selections and require disjoint case sets whose union preserves coverage. Windows' existing native-toggle exclusions remain. diff --git a/tests/integration/README.md b/tests/integration/README.md index f32a30721..01286edf1 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -1,16 +1,17 @@ # Integration tests -The experimental Codex footer has offline protocol, process-isolation, and launcher +The Codex footer has offline protocol, process-isolation, and launcher coverage in `../test_codex_statusline.py` and `../test_codex_smart_routing_v2.py`. Those component checks also cover Claude-style green ON/gray OFF badges, nullable snapshots, Python's `-P` provider launch flag, and terminal config isolation. Native UI checks must verify badge colors as well as the ON/OFF text; OFF remains visible, matching Claude's persistent hint. -The stable CI baseline does not exercise this new renderer. Test it with pinned -Codex `0.171.0-alpha.12` using the +Routing CI now pins stable Codex `0.171.0`; older routed clients must upgrade +through the existing gate (component coverage includes decline/failure and +prereleases). The separate footer version gate was removed. Native UI checks use the [footer validation steps](../../docs/codex-smart-router-statusline.md). A native footer or resource read alone does not establish gateway inference or routed-child -coverage. Keep the stable rollout gated on validation of the actual stable build. +coverage. Windows native footer rendering remains a manual validation step. CUJ7's `test_ug_claude_saved_provider_smart_routing` and `test_ug_codex_saved_provider_smart_routing` configure a saved provider in the unmanaged @@ -1317,8 +1318,8 @@ their original legacy-env cases remain, and the Claude skill toggles add a manag which `smart_routing.enabled` alone routes Claude subagents with Smart Router Orchestrator and no first-prompt wrapper starts. Codex's managed default has two launch journeys. `test_smart_router_managed_default_matches_codex_version_at_launch` reads the actual native -version. Before 0.164.0 it requires a version warning, no upgrade prompt, no routing skills, -and completed native child work without routing. On supported versions it instead requires +version. Before 0.171.0 it declines the required upgrade and requires a blocked launch, +then explicitly disables routing and completes native child work without routing skills. On supported versions it instead requires both skills, a completed routed child and parent answer, and a correlated decision. This keeps the same journey valid for pinned, latest-agent, and explicit-version runs. `test_smart_router_managed_default_routes_supported_codex_at_launch` runs in the routing-capable Codex lane and requires both skills, a completed child and parent @@ -1567,7 +1568,7 @@ The complete integration suite collects 131 executions (128 with Claude and Code See the named coverage and gaps matrix in [../README.md](../README.md). -The native v2 assignment journey requires Codex 0.164.0 or newer. It uses a bundled +The native v2 assignment journey requires Codex 0.171.0 or newer. It uses a bundled v2 catalog and a user-owned observer hook, without test-supplied native feature flags. It checks the exact multiline assignment at PreToolUse and the actual native recipient, and matches the router decision's SHA-256 digest and character count to that assignment. @@ -1575,11 +1576,11 @@ The observer retains the caller's task name; the child path includes `__sr_on` f The launch/off/on journeys match audit digests against native assignment text; CUJ4 matches them against the recorded real router requests. Full native plaintext, completed parent and child models, and preserved settings remain required. Select it with -`--codex-version 0.165.0 -- -k test_ug_codex_native_v2_plain_assignment_routing`. +`--codex-version 0.171.0 -- -k test_ug_codex_native_v2_plain_assignment_routing`. The `codex_smart_routing` marker also selects the native launch/off/on journeys, managed routing banner, catalog-fallback routing-on case, and the routing-on `ug codex app-server` help and client cases. The baseline lane keeps one routing-on -app-server client case, which checks that Codex below 0.164.0 runs the app-server +app-server client case, which checks that Codex below 0.171.0 runs the app-server without smart routing and without an upgrade prompt. To reproduce the baseline lane, use `--codex-version 0.156.0 -- -m 'live and not codex_smart_routing'`. @@ -1801,14 +1802,14 @@ headless argument, and custom OAuth CLI TUI journeys for each agent (six cases, two agent jobs per OS). Full excludes the smoke cases, which smoke already ran on the same OS. Codex 0.156.0 remains the default for installation, smoke, general full/managed journeys, and dedicated CUJs. Routing cases run in separate required -matrix rows with Codex 0.165.0; only the dedicated CUJ4 runner uses that newer pin. +matrix rows with Codex 0.171.0; dedicated CUJ4 and CUJ7 runners use that newer pin too. The full selections are disjoint within each agent and OS: | Agent lane | Marker | | --- | --- | | Claude | `live and claude and not soft_fail and not smoke and not codex_smart_routing` | | Codex 0.156.0 | `live and codex and not soft_fail and not smoke and not codex_smart_routing` | -| Codex 0.165.0 | `live and codex and not soft_fail and not smoke and codex_smart_routing` | +| Codex 0.171.0 | `live and codex and not soft_fail and not smoke and codex_smart_routing` | Managed Codex uses the same marker split on its managed workspace, retaining both-agent installation in each row. The catalog-fallback routing-off parameter, direct router-hook diff --git a/tests/integration/test_ug_codex_app_server.py b/tests/integration/test_ug_codex_app_server.py index 1f6ea9602..9e0aa8c82 100644 --- a/tests/integration/test_ug_codex_app_server.py +++ b/tests/integration/test_ug_codex_app_server.py @@ -61,7 +61,7 @@ def test_ug_codex_app_server_runs_unrouted_below_routing_floor(live_session, wor r"(\d+)\.(\d+)\.(\d+)", session.run("--version", binary=session.which("codex")).stdout ) assert version, "`codex --version` reported no semver" - if tuple(map(int, version.groups())) >= (0, 164, 0): + if tuple(map(int, version.groups())) >= (0, 171, 0): return session.run( "configure", diff --git a/tests/integration/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index c2b8fc8cb..4c1750ad7 100644 --- a/tests/integration/test_ug_smart_routing_hooks.py +++ b/tests/integration/test_ug_smart_routing_hooks.py @@ -41,7 +41,7 @@ use_smart_routing_fixture, ) from utils.request_recorder import record_claude_response_protocol, served_inference_request -from utils.terminal import AgentTerminal +from utils.terminal import AgentTerminal, TerminalProcess pytestmark = pytest.mark.harness_latest @@ -1002,8 +1002,9 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( ): """Scenario: launch the installed Codex with managed smart routing and no explicit opt-in. - Expected: a native child and parent complete the tagged calculation. Before Codex 0.164.0, - ug warns without an upgrade prompt, routing skills, or a routing decision. Supported versions + Expected: a native child and parent complete the tagged calculation. Before Codex 0.171.0, + declining the required upgrade blocks launch; explicit routing disable then permits native + child work without routing skills or a routing decision. Supported versions install both skills and complete the child with a correlated decision and orchestration notice. Neither version routes the first prompt. """ @@ -1011,7 +1012,7 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( version_output = session.run("--version", binary=session.which("codex")).stdout version_match = re.search(r"\b(\d+)\.(\d+)\.(\d+)\b", version_output) assert version_match is not None, version_output - routing_supported = tuple(int(part) for part in version_match.groups()) >= (0, 164, 0) + routing_supported = tuple(int(part) for part in version_match.groups()) >= (0, 171, 0) _select_smart_router_version( session, "codex", workspace, tmp_path, routing_supported, MANAGED_DEFAULT ) @@ -1026,8 +1027,27 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( if routing_supported: # TODO: remove once the latest recipe supports codex session.env["SMART_ROUTER_NAME"] = "m2-r315-quality-20260929" + else: + with TerminalProcess( + session, "codex", [str(session.binary), "codex"], "managed-upgrade-declined" + ) as gate: + gate.wait_for( + lambda screen: "Upgrade Codex if available?" in screen, + "the required managed-routing upgrade", + ) + gate.send("n\r", "decline the required upgrade") + gate.wait_for(lambda _: gate.ended, "blocked launch to exit") + gate.child.close(force=False) + assert gate.child.exitstatus != 0 + assert "Codex smart routing requires Codex 0.171.0 or newer" in " ".join( + ANSI.sub("", "".join(gate.output)).split() + ) + session.assert_not_routed() with AgentTerminal( - session, "codex", [str(session.binary), "codex"], "smart-router-managed-default" + session, + "codex", + [str(session.binary), "codex", *([] if routing_supported else ["--disable-smart-routing"])], + "smart-router-managed-default", ) as tui: tui.boot() installed_skills = _installed_skills(session, "codex") @@ -1047,8 +1067,6 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( assert "Running without smart routing." not in launch_text, transcript assert "[ROUTE]" not in session.routing_log("codex") else: - assert "Codex smart routing requires Codex 0.164.0 or newer" in launch_text, transcript - assert "Running without smart routing." in launch_text, transcript session.assert_not_routed() diff --git a/tests/test_agent_codex.py b/tests/test_agent_codex.py index 05c00e299..29a185692 100644 --- a/tests/test_agent_codex.py +++ b/tests/test_agent_codex.py @@ -40,8 +40,14 @@ class TestMinimumVersion: ("0.156.0", False), ("0.158.0", False), ("0.163.0", False), - ("0.164.0", True), - ("0.165.0", True), + ("0.164.0", False), + ("0.165.0", False), + ("0.170.0", False), + ("0.171.0-alpha.12", False), + ("0.171.0-rc.1", False), + ("0.171.0", True), + ("0.171.0+build-test", True), + ("0.172.0-alpha.1", True), ("1.0.0", True), ], ) @@ -68,7 +74,7 @@ def test_unknown_version_does_not_block(self, monkeypatch): @pytest.mark.parametrize( ("version", "allowed"), - [("0.165.0", True), ("0.163.0", False), ("unknown", False), (None, False)], + [("0.171.0", True), ("0.170.0", False), ("unknown", False), (None, False)], ) def test_smart_routing_rechecks_an_unknown_version_with_a_longer_bound( self, monkeypatch, version, allowed diff --git a/tests/test_cli.py b/tests/test_cli.py index 2f8a97a58..e20a30eeb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1119,7 +1119,7 @@ def test_managed_smart_routing_overrides_env_vars_but_not_the_flag_or_a_version( self, monkeypatch, tool, launch_args, launch_env, expected_version, routed_tools ): monkeypatch.setattr( - cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.165.0" + cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.171.0" ) for name, value in launch_env.items(): monkeypatch.setenv(name, value) @@ -1183,8 +1183,10 @@ def test_auto_version_survives_materialization_and_does_not_leak( assert result.exit_code == 0, result.output assert observed == [enabled, False] - @pytest.mark.parametrize("installed_version", ["0.156.0", "0.163.0"]) - @pytest.mark.parametrize("recovery", ["decline", "upgrade", "disable", "managed-default"]) + @pytest.mark.parametrize("installed_version", ["0.156.0", "0.170.0", "0.171.0-alpha.12"]) + @pytest.mark.parametrize( + "recovery", ["decline", "upgrade", "disable", "managed-default", "managed-upgrade"] + ) def test_codex_routing_version_requires_upgrade_or_explicit_disable( self, tmp_path, monkeypatch, installed_version, recovery ): @@ -1206,7 +1208,7 @@ def update(argv, **_kwargs): return subprocess.CompletedProcess(argv, 0, stdout="0.265.0\n", stderr="") assert argv == ["codex", "update"] updates.append(argv) - version = "0.164.0" + version = "0.171.0" return subprocess.CompletedProcess(argv, 0) def launch_native(*_args, **_kwargs): @@ -1220,7 +1222,7 @@ def launch_native(*_args, **_kwargs): launch = cli_mod.launch_agent # An explicit version keeps Codex routed (managed config is then ignored). The # managed-default case leaves the selector unset: the shared preset applies. - if recovery == "managed-default": + if recovery.startswith("managed"): monkeypatch.delenv("SMART_ROUTER_CONFIG_VERSION", raising=False) else: monkeypatch.setenv("SMART_ROUTER_CONFIG_VERSION", "subagent_orch_v0") @@ -1229,18 +1231,23 @@ def launch_native(*_args, **_kwargs): with ( _launch_policy_patches(managed) as calls, patch( - "ucode.agents.prompt_yes_no_default", return_value=recovery == "upgrade" + "ucode.agents.prompt_yes_no_default", + return_value=recovery in {"upgrade", "managed-upgrade"}, ) as prompt, ): calls["launch"].side_effect = launch args = ["codex", "--disable-smart-routing"] if recovery == "disable" else ["codex"] result = runner.invoke(app, args) - assert result.exit_code == (1 if recovery == "decline" else 0), result.output - assert routed == (["0.164.0"] if recovery == "upgrade" else []) - assert bool(plain) == (recovery in {"disable", "managed-default"}) - assert updates == ([["codex", "update"]] if recovery == "upgrade" else []) - assert prompt.call_count == (0 if recovery in {"disable", "managed-default"} else 1) + assert result.exit_code == (1 if recovery in {"decline", "managed-default"} else 0), ( + result.output + ) + assert routed == (["0.171.0"] if recovery in {"upgrade", "managed-upgrade"} else []) + assert bool(plain) == (recovery == "disable") + assert updates == ( + [["codex", "update"]] if recovery in {"upgrade", "managed-upgrade"} else [] + ) + assert prompt.call_count == (0 if recovery == "disable" else 1) if recovery in {"decline", "managed-default"}: output = " ".join(_strip_ansi(result.output).split()) assert f"found {installed_version}" in output @@ -1301,7 +1308,7 @@ def test_warns_once_and_launches_unrouted_when_version_leaves_codex_unrouted( self, monkeypatch, tool, launch_args, launch_env, managed_routing, warned, routed ): monkeypatch.setattr( - cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.165.0" + cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.171.0" ) for name, value in launch_env.items(): monkeypatch.setenv(name, value) diff --git a/tests/test_codex_smart_routing_v2.py b/tests/test_codex_smart_routing_v2.py index 766763932..fbf119a2e 100644 --- a/tests/test_codex_smart_routing_v2.py +++ b/tests/test_codex_smart_routing_v2.py @@ -48,15 +48,15 @@ class TestLaunchCodex: @pytest.mark.parametrize( ("installed_version", "accept_upgrade", "upgraded_version", "auto_upgrade"), [ - ("0.164.0", False, None, False), - ("0.163.0", True, "0.164.0", False), - ("0.163.0", True, "0.164.0", True), - ("0.163.0", False, None, False), - ("0.163.0", True, None, False), - ("0.163.0", True, "0.163.0", False), + ("0.171.0", False, None, False), + ("0.170.0", True, "0.171.0", False), + ("0.170.0", True, "0.171.0", True), + ("0.170.0", False, None, False), + ("0.170.0", True, None, False), + ("0.170.0", True, "0.170.0", False), ("unknown", True, "unknown", False), ("unknown", True, "unknown", True), - ("0.163.0", True, "unknown", False), + ("0.170.0", True, "unknown", False), ], ids=[ "supported", @@ -115,24 +115,24 @@ def update_binary(argv, **kwargs): monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) def launch_v2(state, tool_args, **kwargs): - assert version == "0.164.0", "unsupported Codex reached execution" + assert version == "0.171.0", "unsupported Codex reached execution" calls.append((state, tool_args, kwargs)) raise SystemExit(0) monkeypatch.setattr(v2, "launch_codex", launch_v2) state = {"workspace": WS} - allowed = installed_version == "0.164.0" or upgraded_version == "0.164.0" + allowed = installed_version == "0.171.0" or upgraded_version == "0.171.0" with pytest.raises(SystemExit if allowed else RuntimeError) as exc: codex.launch(state, tool_args, options=options) - needs_upgrade = installed_version == "0.163.0" + needs_upgrade = installed_version == "0.170.0" assert prompts == ( [("Upgrade Codex if available?", True)] if needs_upgrade and not auto_upgrade else [] ) assert updates == ([["codex", "update"]] if needs_upgrade and accept_upgrade else []) if not allowed: - assert "requires Codex 0.164.0" in str(exc.value) + assert "requires Codex 0.171.0" in str(exc.value) if version == "unknown": assert "codex --version" in str(exc.value) assert calls == [] @@ -146,7 +146,6 @@ def launch_v2(state, tool_args, **kwargs): "binary": "codex", "start_model": "gpt-start", "render_overlay": codex._render_launch_overlay, - "codex_version": "0.164.0", }, ) ] @@ -184,7 +183,7 @@ def test_codex_launch_bypasses_routing_for_other_shapes(self, tmp_path, monkeypa assert launches == [["codex", "--config", 'model_provider="ucode-databricks"', *tool_args]] @pytest.mark.parametrize( - ("installed_version", "routed"), [("0.163.0", False), ("0.164.0", True)] + ("installed_version", "routed"), [("0.170.0", False), ("0.171.0", True)] ) def test_app_server_routes_only_from_codex_routing_floor( self, tmp_path, monkeypatch, capsys, installed_version, routed @@ -221,13 +220,13 @@ def test_app_server_routes_only_from_codex_routing_floor( ("plain", ["codex", "--config", 'model_provider="ucode-databricks"', *tool_args]) ] assert ( - "Smart routing requires Codex 0.164.0 or newer; found 0.163.0. " + "Smart routing requires Codex 0.171.0 or newer; found 0.170.0. " "Running the app-server without smart routing." ) in warning def test_codex_launch_normalizes_cached_bootstrap_model(self, monkeypatch): calls = [] - monkeypatch.setattr(codex, "agent_version", lambda _: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _: "0.171.0") monkeypatch.setenv(v2.ENABLE_SMART_ROUTING_ENV_VAR, "1") monkeypatch.setattr(codex, "custom_catalog_models", lambda: None) monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) @@ -272,7 +271,7 @@ def test_startup_config_precedence( monkeypatch.delenv("CODEX_HOME", raising=False) monkeypatch.setattr(codex, "CODEX_CONFIG_PATH", profile_path) monkeypatch.setattr(codex, "codex_managed_config_path", lambda: managed_path) - monkeypatch.setattr(codex, "agent_version", lambda _: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _: "0.171.0") monkeypatch.setattr(codex, "custom_catalog_models", lambda: None) if custom_home: monkeypatch.setenv("CODEX_HOME", str(config_home)) @@ -296,9 +295,8 @@ def test_startup_config_precedence( @pytest.mark.parametrize("platform_name", ["posix", "nt"]) @pytest.mark.parametrize("first_prompt", [False, True]) - @pytest.mark.parametrize("codex_version", ["0.169.0", "0.171.0-alpha.11", "0.171.0-alpha.12"]) def test_owns_app_server_interposer_and_tui_lifecycle( - self, tmp_path, monkeypatch, platform_name, first_prompt, codex_version + self, tmp_path, monkeypatch, platform_name, first_prompt ): processes = [] interposer_args = {} @@ -373,7 +371,6 @@ def render_overlay(*args, **kwargs): binary="codex", start_model="gpt-start", render_overlay=render_overlay, - codex_version=codex_version, ) assert exc.value.code == 7 @@ -439,39 +436,26 @@ def render_overlay(*args, **kwargs): "gpt-start", "--search", ] - has_statusline = codex_version == "0.171.0-alpha.12" statusline_args = [ "--config", "features.tui_extensions_statusline=true", "--config", 'tui.status_line_provider={server = "ug-smart-router-statusline", tool = "statusline"}', ] - if has_statusline: - expected_tui_args = [*statusline_args, *expected_tui_args] - assert statusline_args[1] in config_values - assert statusline_args[3] in config_values - server_config = next( - value - for value in config_values - if value.startswith("mcp_servers.ug-smart-router-statusline=") - ) - assert json.dumps(sys.executable) in server_config - assert ( - 'args = ["-P", "-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"]' - in server_config - ) - assert json.dumps(os.environ["UCODE_SESSION_ENV_FILE"]) in server_config - else: - assert not any( - value.startswith( - ( - "features.tui_extensions_statusline=", - "tui.status_line_provider=", - "mcp_servers.ug-smart-router-statusline=", - ) - ) - for value in config_values - ) + expected_tui_args = [*statusline_args, *expected_tui_args] + assert statusline_args[1] in config_values + assert statusline_args[3] in config_values + server_config = next( + value + for value in config_values + if value.startswith("mcp_servers.ug-smart-router-statusline=") + ) + assert json.dumps(sys.executable) in server_config + assert ( + 'args = ["-P", "-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"]' + in server_config + ) + assert json.dumps(os.environ["UCODE_SESSION_ENV_FILE"]) in server_config if platform_name == "nt": assert tui_argv[:4] == [ "codex", @@ -897,7 +881,7 @@ def start_interposer(*args, **kwargs): def test_start_model_comes_from_custom_catalog(self, monkeypatch): calls = [] - monkeypatch.setattr(codex, "agent_version", lambda _binary: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _binary: "0.171.0") monkeypatch.setenv(v2.ENABLE_SMART_ROUTING_ENV_VAR, "1") monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) monkeypatch.setattr(codex, "_smart_routing_config_model", lambda state: None) diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py index d290f90c9..51bbf3528 100644 --- a/tests/test_codex_statusline.py +++ b/tests/test_codex_statusline.py @@ -26,31 +26,9 @@ def _read_lines(stream, replies): replies.put(line) -@pytest.mark.parametrize( - ("version", "supported"), - [ - ("unknown", False), - ("0.169.0", False), - ("0.170.0", False), - ("0.171.0-alpha.2", False), - ("0.171.0-alpha.11", False), - ("0.171.0-alpha.12", True), - ("0.171.0-alpha.13", True), - ("0.171.0-beta.1", True), - ("0.171.0-rc.1", True), - ("0.171.0", True), - ("0.171.0+build.1", True), - ("0.171.0-dev", False), - ("0.172.0", True), - ], -) -def test_statusline_version_boundary(version, supported): - assert statusline.supported_version(version) is supported - - def test_launch_config_pins_session_without_credentials(tmp_path): controls = tmp_path / "controls with spaces.json" - config = statusline.launch_config("0.171.0-alpha.12", controls) + config = statusline.launch_config(controls) server = config["mcp_servers"][statusline.SERVER_NAME] assert server["command"] == sys.executable assert server["args"] == ["-P", "-X", "utf8", "-m", "ucode.smart_routing.codex_statusline"] @@ -60,11 +38,10 @@ def test_launch_config_pins_session_without_credentials(tmp_path): "server": statusline.SERVER_NAME, "tool": statusline.TOOL_NAME, } - assert statusline.launch_config("0.169.0", controls) == {} def test_terminal_config_contains_only_feature_and_selection(tmp_path): - config = statusline.launch_config("0.171.0-alpha.12", tmp_path / "controls.json") + config = statusline.launch_config(tmp_path / "controls.json") config["server_only"] = "private" assert statusline.tui_config(config) == { "features.tui_extensions_statusline": True, @@ -224,9 +201,7 @@ def test_real_stdio_process_keeps_sessions_separate_and_polls_live_controls(): {ENABLE_SMART_ROUTING_ENV_VAR: "0", ENABLE_SUBAGENT_ROUTING_ENV_VAR: "0"} ) ) - server = statusline.launch_config("0.171.0-alpha.12", controls)["mcp_servers"][ - statusline.SERVER_NAME - ] + server = statusline.launch_config(controls)["mcp_servers"][statusline.SERVER_NAME] process = subprocess.Popen( [server["command"], *server["args"]], env=env, diff --git a/tests/test_integration_contract.py b/tests/test_integration_contract.py index 5c3529a58..cd960ba0f 100644 --- a/tests/test_integration_contract.py +++ b/tests/test_integration_contract.py @@ -282,7 +282,7 @@ def test_live_ci_lanes_together_cover_every_blocking_live_case(agent): for name in ("full", "managed"): assert "smart_routing: [false]" in jobs[name] assert ( - "CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || " + "CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || " "inputs.codex_version || '0.156.0' }}" ) in jobs[name] assert "matrix.smart_routing && '-smart-routing' || ''" in jobs[name] @@ -474,7 +474,7 @@ def test_dedicated_cuj_ci_runs_each_discovered_file_on_its_own_runner(): assert '"@github/copilot@$COPILOT_VERSION"' in job assert ( "CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || " - "matrix.test == 'test_cuj7_model_discovery.py') && '0.165.0' || " + "matrix.test == 'test_cuj7_model_discovery.py') && '0.171.0' || " "inputs.codex_version || '0.156.0' }}" ) in job From 34fc74bf8e730c641f40741279ffc985878dc522 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 13:50:07 +0000 Subject: [PATCH 07/14] test(codex): close upgrade-check terminal through PTY interface --- tests/integration/test_ug_smart_routing_hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index 4c1750ad7..f6c2d923d 100644 --- a/tests/integration/test_ug_smart_routing_hooks.py +++ b/tests/integration/test_ug_smart_routing_hooks.py @@ -1037,7 +1037,7 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( ) gate.send("n\r", "decline the required upgrade") gate.wait_for(lambda _: gate.ended, "blocked launch to exit") - gate.child.close(force=False) + gate.child.close() assert gate.child.exitstatus != 0 assert "Codex smart routing requires Codex 0.171.0 or newer" in " ".join( ANSI.sub("", "".join(gate.output)).split() From baaf4ab4d67db7327d65946adfeef8d30b16fd57 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 13:58:23 +0000 Subject: [PATCH 08/14] feat(codex): require stable 0.171.0 for routed launches --- .github/workflows/integration.yml | 6 ++-- AGENTS.md | 2 +- README.md | 25 +++++++-------- src/ucode/agents/codex.py | 20 ++++++++---- src/ucode/cli.py | 8 +++++ tests/README.md | 13 ++++++-- tests/integration/README.md | 21 ++++++++---- tests/integration/test_ug_codex_app_server.py | 2 +- .../test_ug_smart_routing_hooks.py | 32 +++++++++++++++---- tests/test_agent_codex.py | 12 +++++-- tests/test_cli.py | 31 +++++++++++------- tests/test_codex_smart_routing_v2.py | 32 +++++++++---------- tests/test_integration_contract.py | 4 +-- 13 files changed, 134 insertions(+), 74 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index daaf28f24..2a1fd725d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -704,7 +704,7 @@ jobs: CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} DEPENDENCY: ${{ inputs.dependency }} AGENT: ${{ matrix.agent }} - CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || inputs.codex_version || '0.156.0' }} # Smoke cases already ran on this OS in the smoke job; don't repeat them here. TEST_MARKER: live and ${{ matrix.agent }} and not soft_fail and not smoke and not anthropic_mps and not codex_relay and ${{ matrix.smart_routing && 'codex_smart_routing' || 'not codex_smart_routing' }} ARTIFACT_NAME: integration-full-${{ matrix.agent }}-${{ matrix.os }}${{ matrix.smart_routing && '-smart-routing' || '' }} @@ -913,7 +913,7 @@ jobs: env: DEPENDENCY: ${{ inputs.dependency }} AGENT: ${{ matrix.agent }} - CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || inputs.codex_version || '0.156.0' }} ARTIFACT_NAME: integration-managed-${{ matrix.agent }}${{ matrix.smart_routing && '-smart-routing' || '' }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -1002,7 +1002,7 @@ jobs: matrix: include: ${{ fromJSON(needs.dedicated-cuj-plan.outputs.cujs) }} env: - CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || matrix.test == 'test_cuj7_model_discovery.py') && '0.165.0' || inputs.codex_version || '0.156.0' }} + CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || matrix.test == 'test_cuj7_model_discovery.py') && '0.171.0' || inputs.codex_version || '0.156.0' }} UV_INDEX_URL: https://pypi.org/simple # Every CUJ runner installs from PyPI at once; ride out slow responses instead of failing a shard. UV_HTTP_TIMEOUT: "120" diff --git a/AGENTS.md b/AGENTS.md index 0ca63a8e7..676b5f166 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -474,7 +474,7 @@ Fields live in `~/.codex/ucode.config.toml` and `/etc/codex/managed_config.toml` | `otel.trace_exporter` | Ignore | Create/replace | In `~/.codex/config.toml` when the config enables tracing, for Codex desktop; another exporter and other telemetry settings left alone | | `mcp_servers` | Ignore | Merge | Managed file; add/update the config's MCP server entries, other entries left alone. A same-name entry in `~/.codex/config.toml` of the other transport (stdio vs HTTP) is removed, since Codex would merge the two into an invalid entry | | Smart Router and Smart Router Orchestrator hooks | Merge | Merge | Launch-only `PreToolUse`, plus `UserPromptSubmit` and compact `SessionStart` with `ENABLE_SMART_ROUTER_ORCHESTRATOR=1`; Codex combines them with its native hook sources and applies project trust; `features.hooks` is enabled for a smart-routed launch | -| Native v2 collaboration | Launch-only (-c), never written | Launch-only (-c), never written | `features.multi_agent_v2.non_code_mode_only=false` and matching `root_agent_usage_hint_text` / `subagent_usage_hint_text` override saved values for the session; only for smart routing on Codex 0.164.0 or newer. User config files, general developer instructions, and native delegation-mode controls are preserved | +| Native v2 collaboration | Launch-only (-c), never written | Launch-only (-c), never written | `features.multi_agent_v2.non_code_mode_only=false` and matching `root_agent_usage_hint_text` / `subagent_usage_hint_text` override saved values for the session; only for smart routing on Codex 0.171.0 or newer. User config files, general developer instructions, and native delegation-mode controls are preserved | | Smart Router native metadata | Launch-only (-c), never written | Launch-only (-c), never written | `responses_api_metadata.smart_router_recipe_name` records the configured recipe. The app-server interposer updates `smart_router_state` per main turn; spawn hooks stamp child task names. Reserve the state key for the interposer; a static config value would override turn updates | diff --git a/README.md b/README.md index 4503e9d1f..90ba6f24f 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ When Claude Code or Codex is older than the minimum version `ug` supports, `ug` asks before upgrading it in place. Set `UG_AUTO_UPGRADE_AGENT=1` to upgrade without asking, for example from a launcher that manages the agent install. -Codex smart routing now requires 0.164.0, including existing managed-enabled +Codex smart routing now requires 0.171.0, including existing managed-enabled workspaces. See the [compatibility and upgrade note](#codex-smart-routing-compatibility) for upgrading or launching with `--disable-smart-routing`. @@ -687,18 +687,17 @@ Routing-enabled responses are buffered until each model step completes. ### Codex smart-routing compatibility -Smart routing now requires Codex 0.164.0 -or newer, including workspaces that already enable managed smart routing. Users on -Codex 0.156–0.163 who previously launched successfully must upgrade or explicitly -run `ug codex --disable-smart-routing`. UG offers its usual upgrade prompt for a -known older version and checks the result before launching. Declining, failing, or -remaining below 0.164.0 after the upgrade keeps the routed launch blocked. This -intentional requirement ensures native v2 provides readable delegated assignments; -UG does not silently disable routing. A routed `ug codex app-server` cannot prompt, -because its stdin carries the client's protocol, so on a known older Codex it warns -on stderr and runs without smart routing instead. Ordinary launches require Codex 0.156.0 -and newer. The general integration CI baseline is 0.156.0; routing cases use -0.165.0. +Smart-routed terminal launches require Codex **0.171.0 or newer**, including +workspaces that already use managed routing. Earlier versions, including 0.171.0 +prereleases, must upgrade or explicitly run `ug codex --disable-smart-routing`. +UG offers its usual upgrade prompt and checks the result before launching. +Declining or failing the upgrade keeps the routed launch blocked. +`UG_AUTO_UPGRADE_AGENT=1` runs that upgrade without asking. The stable floor provides +native delegation and status-line provider support. Ordinary launches retain the +0.156.0 minimum; routing CI pins 0.171.0. + +A routed `ug codex app-server` cannot prompt because its stdin carries the client's +protocol. On a known older Codex it warns on stderr and runs without smart routing. An inconclusive Codex version probe is retried once with a longer timeout. If the version is still unknown, UG stops without offering or running an update and asks diff --git a/src/ucode/agents/codex.py b/src/ucode/agents/codex.py index f8e298a48..ed5465d29 100644 --- a/src/ucode/agents/codex.py +++ b/src/ucode/agents/codex.py @@ -147,8 +147,8 @@ # older releases ignore it and would leave developers free to bypass the gateway. MINIMUM_CODEX_VERSION = (0, 156, 0) MINIMUM_CODEX_VERSION_TEXT = "0.156.0" -MINIMUM_SMART_ROUTING_CODEX_VERSION = (0, 164, 0) -MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT = "0.164.0" +MINIMUM_SMART_ROUTING_CODEX_VERSION = (0, 171, 0) +MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT = "0.171.0" # Codex 0.134.0 introduced per-profile config files; older releases use the legacy layout. LEGACY_LAYOUT_CODEX_VERSION = (0, 134, 0) LEGACY_LAYOUT_CODEX_VERSION_TEXT = "0.134.0" @@ -191,6 +191,14 @@ def _parse_version(value: str) -> tuple[int, int, int] | None: return int(major), int(minor), int(patch) +def _smart_routing_version_supported(version: str) -> bool: + parsed = _parse_version(version) + return parsed is not None and ( + parsed > MINIMUM_SMART_ROUTING_CODEX_VERSION + or (parsed == MINIMUM_SMART_ROUTING_CODEX_VERSION and "-" not in version.partition("+")[0]) + ) + + def minimum_version_error(*, smart_routing_enabled: bool = False) -> str | None: version = agent_version(SPEC["binary"]) parsed = _parse_version(version) @@ -206,11 +214,11 @@ def minimum_version_error(*, smart_routing_enabled: bool = False) -> str | None: "or newer. Run `codex --version` to check the installation, " "or launch with --disable-smart-routing." ) - if parsed >= MINIMUM_SMART_ROUTING_CODEX_VERSION: + if _smart_routing_version_supported(version): return None return ( f"Codex smart routing requires Codex {MINIMUM_SMART_ROUTING_CODEX_VERSION_TEXT} " - f"or newer for readable delegated assignments; found {version}. " + f"or newer for native delegation and status-line provider support; found {version}. " "Upgrade Codex or launch with --disable-smart-routing." ) if parsed is None or parsed >= MINIMUM_CODEX_VERSION: @@ -1959,8 +1967,8 @@ def _app_server_needs_newer_codex(tool_args: list[str]) -> bool: """ if not is_codex_app_server_launch(tool_args): return False - parsed = _parse_version(agent_version(SPEC["binary"])) - return parsed is not None and parsed < MINIMUM_SMART_ROUTING_CODEX_VERSION + version = agent_version(SPEC["binary"]) + return _parse_version(version) is not None and not _smart_routing_version_supported(version) def launch( diff --git a/src/ucode/cli.py b/src/ucode/cli.py index e2860fff3..8d3f120e4 100644 --- a/src/ucode/cli.py +++ b/src/ucode/cli.py @@ -39,6 +39,7 @@ configure_single_tool, configure_tool, ensure_bootstrap_dependencies, + ensure_minimum_version, ensure_provider_state, explicit_model_arg_value, install_databricks_ai_tools_for_agents, @@ -4457,6 +4458,13 @@ def _launch_tool( ) except RuntimeError as exc: routing_unavailable = str(exc) + else: + if routing_unavailable: + ensure_minimum_version( + "codex", + lambda: codex_agent.minimum_version_error(smart_routing_enabled=True), + ) + routing_unavailable = None if routing_unavailable: print_warning(f"{routing_unavailable} Running without smart routing.") smart_routing_enabled = False diff --git a/tests/README.md b/tests/README.md index 62436535c..67329d735 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,12 @@ # Test suites and user journeys +The Codex smart-routing floor is stable 0.171.0. `test_agent_codex.py` covers the +stable boundary, prerelease rejection at the minimum, and slow-probe recovery. +`test_codex_smart_routing_v2.py` and `test_cli.py` cover explicit/managed required +upgrades, refusal/failure, and explicit routing disable. Routing CI pins 0.171.0. +These are component checks; the installed-version journeys are documented in the +[integration guide](integration/README.md). + Custom Codex model-service metadata has component coverage in `test_codex_catalog.py`, `test_databricks.py`, `test_agent_codex.py`, and `test_published_agent_config.py`. Checks resolve external and pay-per-token destinations using selected credentials; @@ -1094,7 +1101,7 @@ gateway provider on Windows while Unix launch arguments stay unchanged and routi hooks stay with the app-server. This is component coverage, not a live Windows sign-in or TUI test. -`integration/test_ug_codex_v2_routing.py` checks native v2 on Codex 0.164.0 or newer: +`integration/test_ug_codex_v2_routing.py` checks native v2 on Codex 0.171.0 or newer: the exact multiline assignment reaches the real hook, router, and native child; the child completes on the routed model while the parent stays pinned. The audit's SHA-256 digest and character count identify that exact assignment without @@ -1501,8 +1508,8 @@ Databricks Hosted configure/TUI, custom OAuth CLI TUI, and headless argument journeys for both agents, in two parallel jobs. After smoke finishes, the full suite runs the remaining live cases in separate agent and OS jobs, with cases serial inside each VM. Codex smoke and general full/managed coverage retain -0.156.0. Separate required full and managed matrix rows use 0.165.0 only for -`codex_smart_routing` cases; CUJ4 also uses 0.165.0, while other CUJs retain +0.156.0. Separate required full and managed matrix rows use 0.171.0 only for +`codex_smart_routing` cases; CUJ4 also uses 0.171.0, while other CUJs retain 0.156.0. The catalog-fallback routing-off case stays on the baseline version. The existing workflow contract tests collect both selections and require disjoint case sets whose union preserves coverage. Windows' existing native-toggle exclusions remain. diff --git a/tests/integration/README.md b/tests/integration/README.md index 8e34ecb8c..7516a1f9f 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -1,5 +1,12 @@ # Integration tests +Routing CI pins stable Codex 0.171.0. Component checks in `../test_agent_codex.py`, +`../test_codex_smart_routing_v2.py`, and `../test_cli.py` cover the required version, +explicit/managed upgrades, refusal/failure, and routing disable. The managed-default +journey on older clients declines the upgrade, requires a blocked launch, then +explicitly disables routing to complete native child work. The app-server protocol +journey retains its known-old-client fallback without an interactive prompt. + CUJ7's `test_ug_claude_saved_provider_smart_routing` and `test_ug_codex_saved_provider_smart_routing` configure a saved provider in the unmanaged workspace and launch the native TUI with `--enable-smart-routing`. They require a completed @@ -1305,8 +1312,8 @@ their original legacy-env cases remain, and the Claude skill toggles add a manag which `smart_routing.enabled` alone routes Claude subagents with Smart Router Orchestrator and no first-prompt wrapper starts. Codex's managed default has two launch journeys. `test_smart_router_managed_default_matches_codex_version_at_launch` reads the actual native -version. Before 0.164.0 it requires a version warning, no upgrade prompt, no routing skills, -and completed native child work without routing. On supported versions it instead requires +version. Before 0.171.0 it declines the required upgrade and requires a blocked launch, +then explicitly disables routing and completes native child work without routing skills. On supported versions it instead requires both skills, a completed routed child and parent answer, and a correlated decision. This keeps the same journey valid for pinned, latest-agent, and explicit-version runs. `test_smart_router_managed_default_routes_supported_codex_at_launch` runs in the routing-capable Codex lane and requires both skills, a completed child and parent @@ -1555,7 +1562,7 @@ The complete integration suite collects 131 executions (128 with Claude and Code See the named coverage and gaps matrix in [../README.md](../README.md). -The native v2 assignment journey requires Codex 0.164.0 or newer. It uses a bundled +The native v2 assignment journey requires Codex 0.171.0 or newer. It uses a bundled v2 catalog and a user-owned observer hook, without test-supplied native feature flags. It checks the exact multiline assignment at PreToolUse and the actual native recipient, and matches the router decision's SHA-256 digest and character count to that assignment. @@ -1563,11 +1570,11 @@ The observer retains the caller's task name; the child path includes `__sr_on` f The launch/off/on journeys match audit digests against native assignment text; CUJ4 matches them against the recorded real router requests. Full native plaintext, completed parent and child models, and preserved settings remain required. Select it with -`--codex-version 0.165.0 -- -k test_ug_codex_native_v2_plain_assignment_routing`. +`--codex-version 0.171.0 -- -k test_ug_codex_native_v2_plain_assignment_routing`. The `codex_smart_routing` marker also selects the native launch/off/on journeys, managed routing banner, catalog-fallback routing-on case, and the routing-on `ug codex app-server` help and client cases. The baseline lane keeps one routing-on -app-server client case, which checks that Codex below 0.164.0 runs the app-server +app-server client case, which checks that Codex below 0.171.0 runs the app-server without smart routing and without an upgrade prompt. To reproduce the baseline lane, use `--codex-version 0.156.0 -- -m 'live and not codex_smart_routing'`. @@ -1789,14 +1796,14 @@ headless argument, and custom OAuth CLI TUI journeys for each agent (six cases, two agent jobs per OS). Full excludes the smoke cases, which smoke already ran on the same OS. Codex 0.156.0 remains the default for installation, smoke, general full/managed journeys, and dedicated CUJs. Routing cases run in separate required -matrix rows with Codex 0.165.0; only the dedicated CUJ4 runner uses that newer pin. +matrix rows with Codex 0.171.0; dedicated CUJ4 and CUJ7 runners use that newer pin too. The full selections are disjoint within each agent and OS: | Agent lane | Marker | | --- | --- | | Claude | `live and claude and not soft_fail and not smoke and not codex_smart_routing` | | Codex 0.156.0 | `live and codex and not soft_fail and not smoke and not codex_smart_routing` | -| Codex 0.165.0 | `live and codex and not soft_fail and not smoke and codex_smart_routing` | +| Codex 0.171.0 | `live and codex and not soft_fail and not smoke and codex_smart_routing` | Managed Codex uses the same marker split on its managed workspace, retaining both-agent installation in each row. The catalog-fallback routing-off parameter, direct router-hook diff --git a/tests/integration/test_ug_codex_app_server.py b/tests/integration/test_ug_codex_app_server.py index 1f6ea9602..9e0aa8c82 100644 --- a/tests/integration/test_ug_codex_app_server.py +++ b/tests/integration/test_ug_codex_app_server.py @@ -61,7 +61,7 @@ def test_ug_codex_app_server_runs_unrouted_below_routing_floor(live_session, wor r"(\d+)\.(\d+)\.(\d+)", session.run("--version", binary=session.which("codex")).stdout ) assert version, "`codex --version` reported no semver" - if tuple(map(int, version.groups())) >= (0, 164, 0): + if tuple(map(int, version.groups())) >= (0, 171, 0): return session.run( "configure", diff --git a/tests/integration/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index c2b8fc8cb..f6c2d923d 100644 --- a/tests/integration/test_ug_smart_routing_hooks.py +++ b/tests/integration/test_ug_smart_routing_hooks.py @@ -41,7 +41,7 @@ use_smart_routing_fixture, ) from utils.request_recorder import record_claude_response_protocol, served_inference_request -from utils.terminal import AgentTerminal +from utils.terminal import AgentTerminal, TerminalProcess pytestmark = pytest.mark.harness_latest @@ -1002,8 +1002,9 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( ): """Scenario: launch the installed Codex with managed smart routing and no explicit opt-in. - Expected: a native child and parent complete the tagged calculation. Before Codex 0.164.0, - ug warns without an upgrade prompt, routing skills, or a routing decision. Supported versions + Expected: a native child and parent complete the tagged calculation. Before Codex 0.171.0, + declining the required upgrade blocks launch; explicit routing disable then permits native + child work without routing skills or a routing decision. Supported versions install both skills and complete the child with a correlated decision and orchestration notice. Neither version routes the first prompt. """ @@ -1011,7 +1012,7 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( version_output = session.run("--version", binary=session.which("codex")).stdout version_match = re.search(r"\b(\d+)\.(\d+)\.(\d+)\b", version_output) assert version_match is not None, version_output - routing_supported = tuple(int(part) for part in version_match.groups()) >= (0, 164, 0) + routing_supported = tuple(int(part) for part in version_match.groups()) >= (0, 171, 0) _select_smart_router_version( session, "codex", workspace, tmp_path, routing_supported, MANAGED_DEFAULT ) @@ -1026,8 +1027,27 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( if routing_supported: # TODO: remove once the latest recipe supports codex session.env["SMART_ROUTER_NAME"] = "m2-r315-quality-20260929" + else: + with TerminalProcess( + session, "codex", [str(session.binary), "codex"], "managed-upgrade-declined" + ) as gate: + gate.wait_for( + lambda screen: "Upgrade Codex if available?" in screen, + "the required managed-routing upgrade", + ) + gate.send("n\r", "decline the required upgrade") + gate.wait_for(lambda _: gate.ended, "blocked launch to exit") + gate.child.close() + assert gate.child.exitstatus != 0 + assert "Codex smart routing requires Codex 0.171.0 or newer" in " ".join( + ANSI.sub("", "".join(gate.output)).split() + ) + session.assert_not_routed() with AgentTerminal( - session, "codex", [str(session.binary), "codex"], "smart-router-managed-default" + session, + "codex", + [str(session.binary), "codex", *([] if routing_supported else ["--disable-smart-routing"])], + "smart-router-managed-default", ) as tui: tui.boot() installed_skills = _installed_skills(session, "codex") @@ -1047,8 +1067,6 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( assert "Running without smart routing." not in launch_text, transcript assert "[ROUTE]" not in session.routing_log("codex") else: - assert "Codex smart routing requires Codex 0.164.0 or newer" in launch_text, transcript - assert "Running without smart routing." in launch_text, transcript session.assert_not_routed() diff --git a/tests/test_agent_codex.py b/tests/test_agent_codex.py index 05c00e299..29a185692 100644 --- a/tests/test_agent_codex.py +++ b/tests/test_agent_codex.py @@ -40,8 +40,14 @@ class TestMinimumVersion: ("0.156.0", False), ("0.158.0", False), ("0.163.0", False), - ("0.164.0", True), - ("0.165.0", True), + ("0.164.0", False), + ("0.165.0", False), + ("0.170.0", False), + ("0.171.0-alpha.12", False), + ("0.171.0-rc.1", False), + ("0.171.0", True), + ("0.171.0+build-test", True), + ("0.172.0-alpha.1", True), ("1.0.0", True), ], ) @@ -68,7 +74,7 @@ def test_unknown_version_does_not_block(self, monkeypatch): @pytest.mark.parametrize( ("version", "allowed"), - [("0.165.0", True), ("0.163.0", False), ("unknown", False), (None, False)], + [("0.171.0", True), ("0.170.0", False), ("unknown", False), (None, False)], ) def test_smart_routing_rechecks_an_unknown_version_with_a_longer_bound( self, monkeypatch, version, allowed diff --git a/tests/test_cli.py b/tests/test_cli.py index 2f8a97a58..e20a30eeb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1119,7 +1119,7 @@ def test_managed_smart_routing_overrides_env_vars_but_not_the_flag_or_a_version( self, monkeypatch, tool, launch_args, launch_env, expected_version, routed_tools ): monkeypatch.setattr( - cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.165.0" + cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.171.0" ) for name, value in launch_env.items(): monkeypatch.setenv(name, value) @@ -1183,8 +1183,10 @@ def test_auto_version_survives_materialization_and_does_not_leak( assert result.exit_code == 0, result.output assert observed == [enabled, False] - @pytest.mark.parametrize("installed_version", ["0.156.0", "0.163.0"]) - @pytest.mark.parametrize("recovery", ["decline", "upgrade", "disable", "managed-default"]) + @pytest.mark.parametrize("installed_version", ["0.156.0", "0.170.0", "0.171.0-alpha.12"]) + @pytest.mark.parametrize( + "recovery", ["decline", "upgrade", "disable", "managed-default", "managed-upgrade"] + ) def test_codex_routing_version_requires_upgrade_or_explicit_disable( self, tmp_path, monkeypatch, installed_version, recovery ): @@ -1206,7 +1208,7 @@ def update(argv, **_kwargs): return subprocess.CompletedProcess(argv, 0, stdout="0.265.0\n", stderr="") assert argv == ["codex", "update"] updates.append(argv) - version = "0.164.0" + version = "0.171.0" return subprocess.CompletedProcess(argv, 0) def launch_native(*_args, **_kwargs): @@ -1220,7 +1222,7 @@ def launch_native(*_args, **_kwargs): launch = cli_mod.launch_agent # An explicit version keeps Codex routed (managed config is then ignored). The # managed-default case leaves the selector unset: the shared preset applies. - if recovery == "managed-default": + if recovery.startswith("managed"): monkeypatch.delenv("SMART_ROUTER_CONFIG_VERSION", raising=False) else: monkeypatch.setenv("SMART_ROUTER_CONFIG_VERSION", "subagent_orch_v0") @@ -1229,18 +1231,23 @@ def launch_native(*_args, **_kwargs): with ( _launch_policy_patches(managed) as calls, patch( - "ucode.agents.prompt_yes_no_default", return_value=recovery == "upgrade" + "ucode.agents.prompt_yes_no_default", + return_value=recovery in {"upgrade", "managed-upgrade"}, ) as prompt, ): calls["launch"].side_effect = launch args = ["codex", "--disable-smart-routing"] if recovery == "disable" else ["codex"] result = runner.invoke(app, args) - assert result.exit_code == (1 if recovery == "decline" else 0), result.output - assert routed == (["0.164.0"] if recovery == "upgrade" else []) - assert bool(plain) == (recovery in {"disable", "managed-default"}) - assert updates == ([["codex", "update"]] if recovery == "upgrade" else []) - assert prompt.call_count == (0 if recovery in {"disable", "managed-default"} else 1) + assert result.exit_code == (1 if recovery in {"decline", "managed-default"} else 0), ( + result.output + ) + assert routed == (["0.171.0"] if recovery in {"upgrade", "managed-upgrade"} else []) + assert bool(plain) == (recovery == "disable") + assert updates == ( + [["codex", "update"]] if recovery in {"upgrade", "managed-upgrade"} else [] + ) + assert prompt.call_count == (0 if recovery == "disable" else 1) if recovery in {"decline", "managed-default"}: output = " ".join(_strip_ansi(result.output).split()) assert f"found {installed_version}" in output @@ -1301,7 +1308,7 @@ def test_warns_once_and_launches_unrouted_when_version_leaves_codex_unrouted( self, monkeypatch, tool, launch_args, launch_env, managed_routing, warned, routed ): monkeypatch.setattr( - cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.165.0" + cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.171.0" ) for name, value in launch_env.items(): monkeypatch.setenv(name, value) diff --git a/tests/test_codex_smart_routing_v2.py b/tests/test_codex_smart_routing_v2.py index 4826bfde3..3e2d7bf90 100644 --- a/tests/test_codex_smart_routing_v2.py +++ b/tests/test_codex_smart_routing_v2.py @@ -47,15 +47,15 @@ class TestLaunchCodex: @pytest.mark.parametrize( ("installed_version", "accept_upgrade", "upgraded_version", "auto_upgrade"), [ - ("0.164.0", False, None, False), - ("0.163.0", True, "0.164.0", False), - ("0.163.0", True, "0.164.0", True), - ("0.163.0", False, None, False), - ("0.163.0", True, None, False), - ("0.163.0", True, "0.163.0", False), + ("0.171.0", False, None, False), + ("0.170.0", True, "0.171.0", False), + ("0.170.0", True, "0.171.0", True), + ("0.170.0", False, None, False), + ("0.170.0", True, None, False), + ("0.170.0", True, "0.170.0", False), ("unknown", True, "unknown", False), ("unknown", True, "unknown", True), - ("0.163.0", True, "unknown", False), + ("0.170.0", True, "unknown", False), ], ids=[ "supported", @@ -114,24 +114,24 @@ def update_binary(argv, **kwargs): monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) def launch_v2(state, tool_args, **kwargs): - assert version == "0.164.0", "unsupported Codex reached execution" + assert version == "0.171.0", "unsupported Codex reached execution" calls.append((state, tool_args, kwargs)) raise SystemExit(0) monkeypatch.setattr(v2, "launch_codex", launch_v2) state = {"workspace": WS} - allowed = installed_version == "0.164.0" or upgraded_version == "0.164.0" + allowed = installed_version == "0.171.0" or upgraded_version == "0.171.0" with pytest.raises(SystemExit if allowed else RuntimeError) as exc: codex.launch(state, tool_args, options=options) - needs_upgrade = installed_version == "0.163.0" + needs_upgrade = installed_version == "0.170.0" assert prompts == ( [("Upgrade Codex if available?", True)] if needs_upgrade and not auto_upgrade else [] ) assert updates == ([["codex", "update"]] if needs_upgrade and accept_upgrade else []) if not allowed: - assert "requires Codex 0.164.0" in str(exc.value) + assert "requires Codex 0.171.0" in str(exc.value) if version == "unknown": assert "codex --version" in str(exc.value) assert calls == [] @@ -182,7 +182,7 @@ def test_codex_launch_bypasses_routing_for_other_shapes(self, tmp_path, monkeypa assert launches == [["codex", "--config", 'model_provider="ucode-databricks"', *tool_args]] @pytest.mark.parametrize( - ("installed_version", "routed"), [("0.163.0", False), ("0.164.0", True)] + ("installed_version", "routed"), [("0.170.0", False), ("0.171.0", True)] ) def test_app_server_routes_only_from_codex_routing_floor( self, tmp_path, monkeypatch, capsys, installed_version, routed @@ -219,13 +219,13 @@ def test_app_server_routes_only_from_codex_routing_floor( ("plain", ["codex", "--config", 'model_provider="ucode-databricks"', *tool_args]) ] assert ( - "Smart routing requires Codex 0.164.0 or newer; found 0.163.0. " + "Smart routing requires Codex 0.171.0 or newer; found 0.170.0. " "Running the app-server without smart routing." ) in warning def test_codex_launch_normalizes_cached_bootstrap_model(self, monkeypatch): calls = [] - monkeypatch.setattr(codex, "agent_version", lambda _: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _: "0.171.0") monkeypatch.setenv(v2.ENABLE_SMART_ROUTING_ENV_VAR, "1") monkeypatch.setattr(codex, "custom_catalog_models", lambda: None) monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) @@ -270,7 +270,7 @@ def test_startup_config_precedence( monkeypatch.delenv("CODEX_HOME", raising=False) monkeypatch.setattr(codex, "CODEX_CONFIG_PATH", profile_path) monkeypatch.setattr(codex, "codex_managed_config_path", lambda: managed_path) - monkeypatch.setattr(codex, "agent_version", lambda _: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _: "0.171.0") monkeypatch.setattr(codex, "custom_catalog_models", lambda: None) if custom_home: monkeypatch.setenv("CODEX_HOME", str(config_home)) @@ -852,7 +852,7 @@ def start_interposer(*args, **kwargs): def test_start_model_comes_from_custom_catalog(self, monkeypatch): calls = [] - monkeypatch.setattr(codex, "agent_version", lambda _binary: "0.164.0") + monkeypatch.setattr(codex, "agent_version", lambda _binary: "0.171.0") monkeypatch.setenv(v2.ENABLE_SMART_ROUTING_ENV_VAR, "1") monkeypatch.setattr(codex, "clear_model_preferences", lambda state: False) monkeypatch.setattr(codex, "_smart_routing_config_model", lambda state: None) diff --git a/tests/test_integration_contract.py b/tests/test_integration_contract.py index 5c3529a58..cd960ba0f 100644 --- a/tests/test_integration_contract.py +++ b/tests/test_integration_contract.py @@ -282,7 +282,7 @@ def test_live_ci_lanes_together_cover_every_blocking_live_case(agent): for name in ("full", "managed"): assert "smart_routing: [false]" in jobs[name] assert ( - "CODEX_VERSION: ${{ matrix.smart_routing && '0.165.0' || " + "CODEX_VERSION: ${{ matrix.smart_routing && '0.171.0' || " "inputs.codex_version || '0.156.0' }}" ) in jobs[name] assert "matrix.smart_routing && '-smart-routing' || ''" in jobs[name] @@ -474,7 +474,7 @@ def test_dedicated_cuj_ci_runs_each_discovered_file_on_its_own_runner(): assert '"@github/copilot@$COPILOT_VERSION"' in job assert ( "CODEX_VERSION: ${{ (matrix.test == 'test_cuj4_smart_routing.py' || " - "matrix.test == 'test_cuj7_model_discovery.py') && '0.165.0' || " + "matrix.test == 'test_cuj7_model_discovery.py') && '0.171.0' || " "inputs.codex_version || '0.156.0' }}" ) in job From 7e264b8ed9564f8591247c00119d3f7cd54bd0b3 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 14:30:54 +0000 Subject: [PATCH 09/14] fix(codex): preserve managed routing fallback after skipped upgrade --- README.md | 28 ++++----- src/ucode/cli.py | 5 +- tests/README.md | 17 ++++-- tests/integration/README.md | 9 +-- .../test_ug_smart_routing_hooks.py | 33 +++++------ tests/test_cli.py | 58 ++++++++++++++----- 6 files changed, 90 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 90ba6f24f..ce293550b 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ without asking, for example from a launcher that manages the agent install. Codex smart routing now requires 0.171.0, including existing managed-enabled workspaces. See the [compatibility and upgrade note](#codex-smart-routing-compatibility) -for upgrading or launching with `--disable-smart-routing`. +for upgrade offers and automatic fallback when managed routing is unavailable. Use `ug opencode --model system.ai.glm-5-3` (or `-m`) to select a configured model for one launch. OpenCode's `provider/model` form is also accepted. @@ -687,11 +687,13 @@ Routing-enabled responses are buffered until each model step completes. ### Codex smart-routing compatibility -Smart-routed terminal launches require Codex **0.171.0 or newer**, including -workspaces that already use managed routing. Earlier versions, including 0.171.0 -prereleases, must upgrade or explicitly run `ug codex --disable-smart-routing`. -UG offers its usual upgrade prompt and checks the result before launching. -Declining or failing the upgrade keeps the routed launch blocked. +Smart-routed terminal launches require Codex **0.171.0 or newer**. For earlier +versions, including 0.171.0 prereleases, UG offers its usual upgrade prompt and +checks the result before enabling routing. When routing comes from the workspace's +managed default, declining or failing the upgrade warns and launches Codex without +smart routing. An update that leaves Codex below the routing minimum takes the same +fallback. Explicit routing requests remain blocked until the upgrade succeeds or +the user passes `--disable-smart-routing`. `UG_AUTO_UPGRADE_AGENT=1` runs that upgrade without asking. The stable floor provides native delegation and status-line provider support. Ordinary launches retain the 0.156.0 minimum; routing CI pins 0.171.0. @@ -700,9 +702,9 @@ A routed `ug codex app-server` cannot prompt because its stdin carries the clien protocol. On a known older Codex it warns on stderr and runs without smart routing. An inconclusive Codex version probe is retried once with a longer timeout. If the -version is still unknown, UG stops without offering or running an update and asks -you to check `codex --version`. `--disable-smart-routing` also bypasses this routing -version check. +version is still unknown, managed routing warns and launches without routing; +explicit routing requests stop and ask you to check `codex --version`. Neither case +offers or runs an update. `--disable-smart-routing` also bypasses this routing version check. For a routed launch, UG's `-c` overrides take precedence over saved values for `features.multi_agent_v2.non_code_mode_only` (set to `false`), @@ -765,10 +767,10 @@ managed default model, without routing or orchestration. `--enable-smart-routing workspace smart routing keep this version, so Codex stays unrouted: ug warns and launches it like a plain `ug codex`, without the Smart Router skills or routing hooks. -Managed smart routing launches Codex without routing when its installed version is too old -or unavailable, or when it uses a ChatGPT subscription relay. These automatic fallbacks warn -without prompting for an upgrade. Explicit routing requests still require a supported version -and direct provider. +Managed smart routing offers an upgrade when Codex is too old. If the upgrade is declined, +fails, or leaves Codex too old, the same launch warns and continues without smart routing. +An unknown version or a ChatGPT subscription relay also falls back, without an upgrade +prompt. Explicit routing requests still require a supported version and direct provider. `SMART_ROUTER_NAME` still selects the router independently of the preset. diff --git a/src/ucode/cli.py b/src/ucode/cli.py index 8d3f120e4..16d3b306d 100644 --- a/src/ucode/cli.py +++ b/src/ucode/cli.py @@ -4456,15 +4456,14 @@ def _launch_tool( routing_unavailable = codex_agent.minimum_version_error( smart_routing_enabled=True ) - except RuntimeError as exc: - routing_unavailable = str(exc) - else: if routing_unavailable: ensure_minimum_version( "codex", lambda: codex_agent.minimum_version_error(smart_routing_enabled=True), ) routing_unavailable = None + except RuntimeError as exc: + routing_unavailable = str(exc) if routing_unavailable: print_warning(f"{routing_unavailable} Running without smart routing.") smart_routing_enabled = False diff --git a/tests/README.md b/tests/README.md index 67329d735..a61a17c16 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,8 +2,10 @@ The Codex smart-routing floor is stable 0.171.0. `test_agent_codex.py` covers the stable boundary, prerelease rejection at the minimum, and slow-probe recovery. -`test_codex_smart_routing_v2.py` and `test_cli.py` cover explicit/managed required -upgrades, refusal/failure, and explicit routing disable. Routing CI pins 0.171.0. +`test_codex_smart_routing_v2.py` and `test_cli.py` cover explicit/managed upgrade +offers, refusal/failure, and explicit routing disable. Managed defaults warn and +continue unrouted after refusal, updater failure, EOF with updater failure, or an +update that leaves the client too old; explicit routing remains gated. Routing CI pins 0.171.0. These are component checks; the installed-version journeys are documented in the [integration guide](integration/README.md). @@ -1111,13 +1113,16 @@ the Databricks provider are preserved. `test_agent_codex.py` covers the routing minimum version separately from ordinary launches. `test_codex_smart_routing_v2.py` checks the native v2 overrides take precedence over conflicting saved values in both launch paths, with saved files unchanged, -and the shared upgrade flow. Codex 0.163 cannot reach execution when the upgrade is +and the shared upgrade flow. Explicitly routed Codex 0.170 cannot reach execution when the upgrade is declined, fails, or leaves the version below the routing minimum. Unrecognized versions stop before an upgrade prompt or updater, including automatic-update mode; successful and automatic upgrades of known old versions allow routing. -The managed-launch cases in `test_cli.py` exercise Codex 0.156 and 0.163 through the -real version gate: declining blocks launch, upgrading to 0.164 allows routing, and -`--disable-smart-routing` allows an ordinary launch without invoking the updater. +The managed-launch cases in `test_cli.py` exercise Codex 0.156, 0.164, 0.170, and +0.171.0-alpha.12 through the real version gate. Declining, failed/manual or automatic +updates, EOF followed by update failure, and an update that leaves the version old +all warn and launch unrouted with routing environment controls disabled. Upgrading +to stable 0.171.0 allows routing. `--disable-smart-routing` allows an ordinary launch +without invoking the updater. Every case checks launch-scoped environment restoration. `test_codex_routing.py` checks that long Unicode assignments reach the router and hook unchanged while audits contain their hash and length, and bound each reason to 1,000 characters. Shared-writer coverage keeps Claude's full task and reason fields intact. diff --git a/tests/integration/README.md b/tests/integration/README.md index 7516a1f9f..f62144b28 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -3,8 +3,8 @@ Routing CI pins stable Codex 0.171.0. Component checks in `../test_agent_codex.py`, `../test_codex_smart_routing_v2.py`, and `../test_cli.py` cover the required version, explicit/managed upgrades, refusal/failure, and routing disable. The managed-default -journey on older clients declines the upgrade, requires a blocked launch, then -explicitly disables routing to complete native child work. The app-server protocol +journey on older clients declines the upgrade and requires the same launch to warn +and complete native child work without routing or an extra flag. The app-server protocol journey retains its known-old-client fallback without an interactive prompt. CUJ7's `test_ug_claude_saved_provider_smart_routing` and @@ -1312,8 +1312,9 @@ their original legacy-env cases remain, and the Claude skill toggles add a manag which `smart_routing.enabled` alone routes Claude subagents with Smart Router Orchestrator and no first-prompt wrapper starts. Codex's managed default has two launch journeys. `test_smart_router_managed_default_matches_codex_version_at_launch` reads the actual native -version. Before 0.171.0 it declines the required upgrade and requires a blocked launch, -then explicitly disables routing and completes native child work without routing skills. On supported versions it instead requires +version. Before 0.171.0 it declines the offered upgrade, requires a warning, and +completes native child work in the same launch without routing skills or an explicit +disable flag. It also verifies the installed version is unchanged. On supported versions it instead requires both skills, a completed routed child and parent answer, and a correlated decision. This keeps the same journey valid for pinned, latest-agent, and explicit-version runs. `test_smart_router_managed_default_routes_supported_codex_at_launch` runs in the routing-capable Codex lane and requires both skills, a completed child and parent diff --git a/tests/integration/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index f6c2d923d..e8bab0eab 100644 --- a/tests/integration/test_ug_smart_routing_hooks.py +++ b/tests/integration/test_ug_smart_routing_hooks.py @@ -41,7 +41,7 @@ use_smart_routing_fixture, ) from utils.request_recorder import record_claude_response_protocol, served_inference_request -from utils.terminal import AgentTerminal, TerminalProcess +from utils.terminal import AgentTerminal pytestmark = pytest.mark.harness_latest @@ -1003,7 +1003,7 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( """Scenario: launch the installed Codex with managed smart routing and no explicit opt-in. Expected: a native child and parent complete the tagged calculation. Before Codex 0.171.0, - declining the required upgrade blocks launch; explicit routing disable then permits native + declining the offered upgrade warns and continues in the same launch, permitting native child work without routing skills or a routing decision. Supported versions install both skills and complete the child with a correlated decision and orchestration notice. Neither version routes the first prompt. @@ -1027,28 +1027,18 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( if routing_supported: # TODO: remove once the latest recipe supports codex session.env["SMART_ROUTER_NAME"] = "m2-r315-quality-20260929" - else: - with TerminalProcess( - session, "codex", [str(session.binary), "codex"], "managed-upgrade-declined" - ) as gate: - gate.wait_for( - lambda screen: "Upgrade Codex if available?" in screen, - "the required managed-routing upgrade", - ) - gate.send("n\r", "decline the required upgrade") - gate.wait_for(lambda _: gate.ended, "blocked launch to exit") - gate.child.close() - assert gate.child.exitstatus != 0 - assert "Codex smart routing requires Codex 0.171.0 or newer" in " ".join( - ANSI.sub("", "".join(gate.output)).split() - ) - session.assert_not_routed() with AgentTerminal( session, "codex", - [str(session.binary), "codex", *([] if routing_supported else ["--disable-smart-routing"])], + [str(session.binary), "codex"], "smart-router-managed-default", ) as tui: + if not routing_supported: + tui.wait_for( + lambda screen: "Upgrade Codex if available?" in screen, + "the offered managed-routing upgrade", + ) + tui.send("n\r", "decline the offered upgrade and continue without routing") tui.boot() installed_skills = _installed_skills(session, "codex") assert ("smart-router" in installed_skills) is routing_supported, installed_skills @@ -1062,11 +1052,14 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( transcript = "".join(tui.output) assert SMART_ROUTING_BANNER not in transcript, transcript launch_text = " ".join(ANSI.sub("", transcript).split()) - assert "Upgrade Codex if available?" not in launch_text, transcript + assert ("Upgrade Codex if available?" in launch_text) is not routing_supported, transcript if routing_supported: assert "Running without smart routing." not in launch_text, transcript assert "[ROUTE]" not in session.routing_log("codex") else: + assert "Codex smart routing requires Codex 0.171.0 or newer" in launch_text, transcript + assert "Running without smart routing." in launch_text, transcript + assert session.run("--version", binary=session.which("codex")).stdout == version_output session.assert_not_routed() diff --git a/tests/test_cli.py b/tests/test_cli.py index e20a30eeb..36287fa86 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1183,11 +1183,24 @@ def test_auto_version_survives_materialization_and_does_not_leak( assert result.exit_code == 0, result.output assert observed == [enabled, False] - @pytest.mark.parametrize("installed_version", ["0.156.0", "0.170.0", "0.171.0-alpha.12"]) @pytest.mark.parametrize( - "recovery", ["decline", "upgrade", "disable", "managed-default", "managed-upgrade"] + "installed_version", ["0.156.0", "0.164.0", "0.170.0", "0.171.0-alpha.12"] ) - def test_codex_routing_version_requires_upgrade_or_explicit_disable( + @pytest.mark.parametrize( + "recovery", + [ + "decline", + "upgrade", + "disable", + "managed-default", + "managed-upgrade", + "managed-failed", + "managed-still-old", + "managed-eof", + "managed-auto-failed", + ], + ) + def test_codex_routing_upgrade_preserves_managed_fallback( self, tmp_path, monkeypatch, installed_version, recovery ): codex = cli_mod.codex_agent @@ -1198,8 +1211,12 @@ def test_codex_routing_version_requires_upgrade_or_explicit_disable( monkeypatch.setattr(codex, "CODEX_CONFIG_PATH", profile) monkeypatch.setattr(codex, "agent_version", lambda *_args, **_kwargs: version) monkeypatch.setattr(codex, "_launch_token", lambda *_args, **_kwargs: "token") - monkeypatch.setattr(codex, "exec_or_spawn", lambda argv: plain.append(argv)) - monkeypatch.setenv(agents.AUTO_UPGRADE_AGENT_ENV, "0") + monkeypatch.setattr( + codex, "exec_or_spawn", lambda argv: plain.append((argv, _routing_env())) + ) + monkeypatch.setenv( + agents.AUTO_UPGRADE_AGENT_ENV, "1" if recovery == "managed-auto-failed" else "0" + ) monkeypatch.setattr(agents.shutil, "which", lambda binary: f"/tools/{binary}") def update(argv, **_kwargs): @@ -1208,7 +1225,10 @@ def update(argv, **_kwargs): return subprocess.CompletedProcess(argv, 0, stdout="0.265.0\n", stderr="") assert argv == ["codex", "update"] updates.append(argv) - version = "0.171.0" + if recovery in {"managed-failed", "managed-eof", "managed-auto-failed"}: + raise subprocess.CalledProcessError(1, argv) + if recovery != "managed-still-old": + version = "0.171.0" return subprocess.CompletedProcess(argv, 0) def launch_native(*_args, **_kwargs): @@ -1228,30 +1248,40 @@ def launch_native(*_args, **_kwargs): monkeypatch.setenv("SMART_ROUTER_CONFIG_VERSION", "subagent_orch_v0") managed = {"enabled_agents": {"codex": {"smart_routing_enabled": True}}} env_before = _routing_env() + confirm_upgrade = agents.prompt_yes_no_default + + def answer_upgrade(prompt, *, default): + if recovery == "managed-eof": + return confirm_upgrade(prompt, default=default) + return recovery not in {"decline", "managed-default"} + with ( _launch_policy_patches(managed) as calls, patch( "ucode.agents.prompt_yes_no_default", - return_value=recovery in {"upgrade", "managed-upgrade"}, + side_effect=answer_upgrade, ) as prompt, ): calls["launch"].side_effect = launch args = ["codex", "--disable-smart-routing"] if recovery == "disable" else ["codex"] result = runner.invoke(app, args) - assert result.exit_code == (1 if recovery in {"decline", "managed-default"} else 0), ( - result.output - ) + assert result.exit_code == (1 if recovery == "decline" else 0), result.output assert routed == (["0.171.0"] if recovery in {"upgrade", "managed-upgrade"} else []) - assert bool(plain) == (recovery == "disable") + managed_fallback = recovery.startswith("managed") and recovery != "managed-upgrade" + assert bool(plain) == (managed_fallback or recovery == "disable") assert updates == ( - [["codex", "update"]] if recovery in {"upgrade", "managed-upgrade"} else [] + [] if recovery in {"decline", "disable", "managed-default"} else [["codex", "update"]] ) - assert prompt.call_count == (0 if recovery == "disable" else 1) - if recovery in {"decline", "managed-default"}: + assert prompt.call_count == (0 if recovery in {"disable", "managed-auto-failed"} else 1) + if managed_fallback or recovery == "decline": output = " ".join(_strip_ansi(result.output).split()) assert f"found {installed_version}" in output assert "--disable-smart-routing" in output + assert ("Running without smart routing." in output) is managed_fallback + if managed_fallback: + assert {key: plain[0][1][key] for key in ROUTING_OFF} == dict.fromkeys(ROUTING_OFF) + assert version == installed_version assert _routing_env() == env_before @pytest.mark.parametrize( From 258edb2498faddd384773d6c253b4d7147de43c5 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 14:33:12 +0000 Subject: [PATCH 10/14] docs(codex): describe managed upgrade fallback for footer launches --- docs/codex-smart-router-statusline.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md index e133526b6..ea7a2eb11 100644 --- a/docs/codex-smart-router-statusline.md +++ b/docs/codex-smart-router-statusline.md @@ -48,8 +48,10 @@ For a configured test workspace and an explicitly selected profile: Codex may add its own trust and onboarding records, such as `tui.screen_reader_detection_done`; compare `tui.status_line` and `tui.status_line_provider` independently of that bookkeeping. -9. With an older client, verify the upgrade gate blocks routed launch until the - upgrade succeeds. `--disable-smart-routing` retains ordinary launch behavior. +9. With an older client and explicit routing selected, verify the upgrade gate blocks + routed launch until the upgrade succeeds. With managed routing and no explicit + selection, decline the upgrade and require a warning, a completed task, and no footer. + `--disable-smart-routing` retains ordinary launch behavior. Existing native routing journeys can be run with pinned stable Codex through `scripts/run_integration.py --ug-version checkout --codex-version 0.171.0 @@ -77,6 +79,8 @@ Routed launches require stable Codex `0.171.0` or newer. Earlier builds, includi `0.171.0-alpha.*`, must pass the existing native upgrade flow before starting. Declining or failing the upgrade blocks routed launch; `--disable-smart-routing` keeps ordinary launch behavior. `UG_AUTO_UPGRADE_AGENT=1` selects automatic upgrade. +When routing comes from the managed default, an unsuccessful upgrade instead warns +and continues without routing or the footer, with no extra launch flag required. The footer is registered after that launch gate, without a second version probe. Upstream contract and starter: From b8341b3de8536e39c415a1be0ca68f10b80e01fe Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 14:53:48 +0000 Subject: [PATCH 11/14] fix(ci): align Codex pins and verify encrypted native task delivery --- .github/workflows/polly-review.yml | 2 +- tests/README.md | 7 +++ tests/integration/README.md | 6 +++ .../test_ug_smart_routing_hooks.py | 21 +------- tests/integration/utils/agents/codex.py | 48 +++++++++++++++++ tests/test_integration_evidence.py | 52 +++++++++++++++++++ 6 files changed, 116 insertions(+), 20 deletions(-) diff --git a/.github/workflows/polly-review.yml b/.github/workflows/polly-review.yml index 1013b289f..dfe19ead8 100644 --- a/.github/workflows/polly-review.yml +++ b/.github/workflows/polly-review.yml @@ -54,7 +54,7 @@ jobs: OMNIGENT_SKIP_WEB_UI: "true" # Same pins as integration.yml. CLAUDE_VERSION: 2.1.290 - CODEX_VERSION: 0.165.0 + CODEX_VERSION: 0.171.0 PYPI_INDEX: https://databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple steps: - name: Resolve the pull request diff --git a/tests/README.md b/tests/README.md index a61a17c16..029c58033 100644 --- a/tests/README.md +++ b/tests/README.md @@ -9,6 +9,13 @@ update that leaves the client too old; explicit routing remains gated. Routing C These are component checks; the installed-version journeys are documented in the [integration guide](integration/README.md). +Codex calculation routing evidence supports plaintext assignments and native encrypted +delivery. Plaintext must match the audited assignment digest. For encrypted delivery, +the original spawn's ciphertext must match the child's NEW_TASK receipt, and its task +name must match the audited fallback digest. Component checks reject mismatched names, +ciphertexts, missing delivery, and non-spawn calls. This does not establish plaintext +routing for encrypted tasks; the dedicated native v2 assignment journey checks that separately. + Custom Codex model-service metadata has component coverage in `test_codex_catalog.py`, `test_databricks.py`, `test_agent_codex.py`, and `test_published_agent_config.py`. Checks resolve external and pay-per-token destinations using selected credentials; diff --git a/tests/integration/README.md b/tests/integration/README.md index f62144b28..4192b44a0 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -106,6 +106,12 @@ still require real routed work. Offline evidence checks reject mistyped markers and wrong results in either the parent or child answer. These checks do not establish the live model's copying-error rate. +Codex may persist an encrypted child assignment. Calculation journeys then correlate +the original spawn ciphertext with the child's NEW_TASK receipt and require the audit's +task-name fallback digest, while plaintext assignments require their full-text digest. +The existing parent/child completion, selected model, and live decision checks still apply. +The native v2 assignment journey separately requires plaintext at the hook and child. + File-read tasks use six-character hidden values. Offline Copilot evidence checks reject truncated final answers and tool-result echoes; they do not measure live copying reliability. diff --git a/tests/integration/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index e8bab0eab..2216f7fa4 100644 --- a/tests/integration/test_ug_smart_routing_hooks.py +++ b/tests/integration/test_ug_smart_routing_hooks.py @@ -23,7 +23,7 @@ claude_delivered_child_answers, parent_tool_calls, ) -from utils.agents.codex import completed_smart_router_results +from utils.agents.codex import completed_smart_router_results, routed_assignment_digests from utils.evidence import ( FileTask, SubagentCalculation, @@ -151,24 +151,7 @@ def _run_calculation( assert new_decisions, new_decisions if agent == "codex": - # Correlate the audit hashes with plaintext assignments in native rollouts. - assignments = set() - for records in agent_sessions(session, agent).values(): - for row in records: - item = row.get("payload", {}) - if row.get("type") != "response_item" or item.get("type") != "agent_message": - continue - for part in item.get("content", []): - text = part.get("text", "") - if part.get("type") != "input_text" or not text.startswith( - "Message Type: NEW_TASK\n" - ): - continue - _, separator, assignment = text.partition("\nPayload:\n") - if separator and task.marker in assignment: - assignments.add( - hashlib.sha256(assignment.strip().encode("utf-8")).hexdigest() - ) + assignments = routed_assignment_digests(agent_sessions(session, agent), task.marker) assert all(row["task_sha256"] in assignments for row in new_decisions), new_decisions else: assert all(task.marker in row.get("task_name", "") for row in new_decisions), new_decisions diff --git a/tests/integration/utils/agents/codex.py b/tests/integration/utils/agents/codex.py index 0a12261f9..e36255374 100644 --- a/tests/integration/utils/agents/codex.py +++ b/tests/integration/utils/agents/codex.py @@ -1,5 +1,6 @@ """Codex-specific integration evidence and model discovery helpers.""" +import hashlib import json from ..model_discovery import codex_model_in_picker as model_in_picker @@ -12,6 +13,7 @@ "completed_task_models", "completed_command_outputs", "completed_smart_router_results", + "routed_assignment_digests", "model_in_picker", ] @@ -19,6 +21,52 @@ EVIDENCE_KIND = "client-selected model" +def routed_assignment_digests(sessions: dict[str, list[dict]], marker: str) -> set[str]: + """Match plaintext assignments or encrypted delivery with its original task-name fallback.""" + records = [row for rows in sessions.values() for row in rows] + digests = set() + encrypted_deliveries = set() + for row in records: + item = row.get("payload", {}) + if row.get("type") != "response_item" or item.get("type") != "agent_message": + continue + for part in item.get("content", []): + text = part.get("text", "") + if part.get("type") != "input_text" or not text.startswith("Message Type: NEW_TASK\n"): + continue + header, separator, assignment = text.partition("\nPayload:\n") + if not separator: + continue + if marker in assignment: + digests.add(hashlib.sha256(assignment.strip().encode("utf-8")).hexdigest()) + elif not assignment.strip() and marker in header: + encrypted_deliveries.update( + content["encrypted_content"] + for content in item.get("content", []) + if content.get("type") == "encrypted_content" + and isinstance(content.get("encrypted_content"), str) + and content["encrypted_content"] + ) + for row in records: + item = row.get("payload", {}) + if ( + row.get("type") != "response_item" + or item.get("type") != "function_call" + or not item.get("name", "").endswith("spawn_agent") + ): + continue + arguments = json.loads(item["arguments"]) + message, name = arguments.get("message"), arguments.get("task_name") + if ( + isinstance(message, str) + and message in encrypted_deliveries + and isinstance(name, str) + and marker in name + ): + digests.add(hashlib.sha256(name.strip().encode("utf-8")).hexdigest()) + return digests + + def assert_agent_interaction_completed(records: list[dict], target: str, thread_id: str) -> None: """Require the native delivery receipt, shared by direct tools and code mode.""" assert any( diff --git a/tests/test_integration_evidence.py b/tests/test_integration_evidence.py index be7e5ba98..999bced21 100644 --- a/tests/test_integration_evidence.py +++ b/tests/test_integration_evidence.py @@ -1,5 +1,6 @@ """Unit checks for interpreting terminal evidence, not live agent substitutes.""" +import hashlib import json import os import re @@ -816,6 +817,57 @@ def test_tagged_calculation_uses_a_short_native_task_name(): assert re.fullmatch(r"[a-z][a-z0-9_]{0,11}", task.marker) +@pytest.mark.parametrize("encrypted", [False, True]) +def test_codex_assignment_digests_match_native_delivery(encrypted): + marker = "ug_123abc" + assignment = f"Calculate 1+1 and reply {marker}=2" + ciphertext = "gAAAAABrAFzz" + "a" * 80 + content = [ + { + "type": "input_text", + "text": f"Message Type: NEW_TASK\nTask name: /root/{marker}__sr_on\n" + "Sender: /root\nPayload:\n" + ("" if encrypted else assignment), + } + ] + if encrypted: + content.append({"type": "encrypted_content", "encrypted_content": ciphertext}) + call = { + "type": "function_call", + "name": "spawn_agent", + "arguments": json.dumps( + {"task_name": marker, "message": ciphertext if encrypted else assignment} + ), + } + delivery = {"type": "agent_message", "content": content} + sessions = { + "parent": [{"type": "response_item", "payload": call}], + "child": [{"type": "response_item", "payload": delivery}], + } + expected = marker if encrypted else assignment + assert codex.routed_assignment_digests(sessions, marker) == { + hashlib.sha256(expected.encode()).hexdigest() + } + assert not codex.routed_assignment_digests(sessions, "ug_other") + if not encrypted: + assert hashlib.sha256(marker.encode()).hexdigest() not in codex.routed_assignment_digests( + sessions, marker + ) + return + for changed in ( + {"task_name": "ug_other", "message": ciphertext}, + {"task_name": marker, "message": ciphertext + "different"}, + {"task_name": marker, "message": {"encrypted": ciphertext}}, + ): + call["arguments"] = json.dumps(changed) + assert not codex.routed_assignment_digests(sessions, marker) + call["arguments"] = json.dumps({"task_name": marker, "message": ciphertext}) + call["name"] = "send_message" + assert not codex.routed_assignment_digests(sessions, marker) + call["name"] = "spawn_agent" + content.pop() + assert not codex.routed_assignment_digests(sessions, marker) + + @pytest.mark.parametrize("agent", ["claude", "codex"]) @pytest.mark.parametrize("child", [False, True]) def test_tagged_calculation_rejects_mistyped_marker_and_wrong_result(tmp_path, agent, child): From 57c3df6199bb9c398c6f692c5966346343b7b931 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 15:22:27 +0000 Subject: [PATCH 12/14] test(codex): match native task transport and guarded toggle recovery --- tests/README.md | 5 ++- tests/e2e_cuj/test_cuj4_smart_routing.py | 2 +- tests/integration/README.md | 5 ++- tests/integration/test_ug_codex_v2_routing.py | 4 +- tests/integration/utils/agents/codex.py | 14 +++++++ tests/test_cuj_evidence.py | 7 +++- tests/test_integration_evidence.py | 39 +++++++++++++++++++ 7 files changed, 70 insertions(+), 6 deletions(-) diff --git a/tests/README.md b/tests/README.md index 029c58033..70200896d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,6 +15,9 @@ the original spawn's ciphertext must match the child's NEW_TASK receipt, and its name must match the audited fallback digest. Component checks reject mismatched names, ciphertexts, missing delivery, and non-spawn calls. This does not establish plaintext routing for encrypted tasks; the dedicated native v2 assignment journey checks that separately. +The encrypted-request matcher accepts the exact enabled-attribution suffix on a child +task name, rejecting disabled and arbitrary suffixes. Toggle evidence still requires a +successful state change; only an explicitly denied duplicate after that success is tolerated. Custom Codex model-service metadata has component coverage in `test_codex_catalog.py`, `test_databricks.py`, `test_agent_codex.py`, and `test_published_agent_config.py`. @@ -1110,7 +1113,7 @@ gateway provider on Windows while Unix launch arguments stay unchanged and routi hooks stay with the app-server. This is component coverage, not a live Windows sign-in or TUI test. -`integration/test_ug_codex_v2_routing.py` checks native v2 on Codex 0.171.0 or newer: +`integration/test_ug_codex_v2_routing.py` checks native v2 through code mode on Codex 0.171.0 or newer: the exact multiline assignment reaches the real hook, router, and native child; the child completes on the routed model while the parent stays pinned. The audit's SHA-256 digest and character count identify that exact assignment without diff --git a/tests/e2e_cuj/test_cuj4_smart_routing.py b/tests/e2e_cuj/test_cuj4_smart_routing.py index 105955c71..6c55f953b 100644 --- a/tests/e2e_cuj/test_cuj4_smart_routing.py +++ b/tests/e2e_cuj/test_cuj4_smart_routing.py @@ -205,7 +205,7 @@ def _task_inference_request(requests, agent, prompt, *, after=0): and isinstance(content, list) ): # Encrypted Codex child instructions leave only task_name readable. - if entry["recipient"].rsplit("/", 1)[-1] == prompt and any( + if entry["recipient"].rsplit("/", 1)[-1] in {prompt, prompt + "__sr_on"} and any( isinstance(part, dict) and part.get("type") == "encrypted_content" and isinstance(part.get("encrypted_content"), str) diff --git a/tests/integration/README.md b/tests/integration/README.md index 4192b44a0..bed28e170 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -110,7 +110,10 @@ Codex may persist an encrypted child assignment. Calculation journeys then corre the original spawn ciphertext with the child's NEW_TASK receipt and require the audit's task-name fallback digest, while plaintext assignments require their full-text digest. The existing parent/child completion, selected model, and live decision checks still apply. -The native v2 assignment journey separately requires plaintext at the hook and child. +The native v2 assignment journey explicitly uses code mode and separately requires +plaintext at the hook and child. Direct native calls may remain encrypted. Toggle +evidence accepts the exact guard rejection of a duplicate off call only after a +successful off result; it still rejects an initial denial or any other failed call. File-read tasks use six-character hidden values. Offline Copilot evidence checks reject truncated final answers and tool-result echoes; they do not measure live copying reliability. diff --git a/tests/integration/test_ug_codex_v2_routing.py b/tests/integration/test_ug_codex_v2_routing.py index 662dbfa26..188d47060 100644 --- a/tests/integration/test_ug_codex_v2_routing.py +++ b/tests/integration/test_ug_codex_v2_routing.py @@ -72,7 +72,7 @@ def _seed_user_owned_native_codex_settings(session) -> tuple[Path, bytes, bytes] def test_ug_codex_native_v2_plain_assignment_routing(live_session, workspace): """Scenario: configure ug with a user-owned native v2 catalog and observer hook, - then delegate one multiline file task with subagent-only routing. + then delegate one multiline file task through code mode with subagent-only routing. Expected: the native child and actual hook input contain the exact assignment, matched by the router decision's digest. One native child completes on the selected model; the parent stays on @@ -85,6 +85,8 @@ def test_ug_codex_native_v2_plain_assignment_routing(live_session, workspace): assignment = task.prompt + '\nKeep this literal: café λ; "quotes", \\slashes, {braces}.' task_name = "ug_native_file" prompt = ( + "Use code mode to call the native spawn_agent tool with a plaintext message; " + "do not call collaboration.spawn_agent directly. " f'Delegate to one native child with task_name "{task_name}". ' "Set message to exactly the assignment between BEGIN and END, preserving the newline.\n" f"BEGIN\n{assignment}\nEND\n" diff --git a/tests/integration/utils/agents/codex.py b/tests/integration/utils/agents/codex.py index e36255374..49ff2ef93 100644 --- a/tests/integration/utils/agents/codex.py +++ b/tests/integration/utils/agents/codex.py @@ -114,6 +114,20 @@ def completed_smart_router_results(records: list[dict], action: str) -> list[dic continue if item.get("arguments", {}).get("action") != action: continue + if ( + action == "off" + and results + and item.get("status") == "failed" + and item.get("success") is False + and item.get("content_items") + == [ + { + "type": "inputText", + "text": "Use $smart-router off to turn Smart Router off. Routing is unchanged.", + } + ] + ): + continue assert item.get("status") == "completed" and item.get("success") is True, item contents = item.get("content_items") assert isinstance(contents, list) and len(contents) == 1, item diff --git a/tests/test_cuj_evidence.py b/tests/test_cuj_evidence.py index af5ce0185..980254815 100644 --- a/tests/test_cuj_evidence.py +++ b/tests/test_cuj_evidence.py @@ -375,12 +375,13 @@ def test_cuj_task_inference_only_allows_claude_child_transport_newline(agent, af _task_inference_request([request], agent, prompt, after=after) -def test_cuj_codex_encrypted_child_inference_matches_routed_task_name(): +@pytest.mark.parametrize("suffix", ["", "__sr_on"]) +def test_cuj_codex_encrypted_child_inference_matches_routed_task_name(suffix): request = _inference_request(CODEX, 3, "parent prompt", [{"name": "exec"}]) message = { "type": "agent_message", "author": "/root", - "recipient": "/root/read_file", + "recipient": "/root/read_file" + suffix, "content": [{"type": "encrypted_content", "encrypted_content": "gAAAAAopaque"}], } request.payload["input"].append(message) @@ -391,6 +392,8 @@ def test_cuj_codex_encrypted_child_inference_matches_routed_task_name(): for change in ( {"type": "message", "role": "user"}, {"recipient": "/root/another_task"}, + {"recipient": "/root/read_file__sr_off"}, + {"recipient": "/root/read_file_other"}, {"content": [{"type": "input_text", "text": "read_file"}]}, {"content": [{"type": "encrypted_content", "encrypted_content": ""}]}, ): diff --git a/tests/test_integration_evidence.py b/tests/test_integration_evidence.py index 999bced21..2020a71ee 100644 --- a/tests/test_integration_evidence.py +++ b/tests/test_integration_evidence.py @@ -1236,6 +1236,45 @@ def test_codex_compacted_prompt_uses_adjacent_native_spawn(): ) +def test_codex_skill_confirmation_allows_only_guarded_duplicates_after_success(): + successful = { + "type": "DynamicToolCall", + "tool": "ug_smart_router", + "arguments": {"action": "off"}, + "status": "completed", + "success": True, + "content_items": [{"type": "inputText", "text": '{"message":"Smart Router is off"}'}], + } + denied = { + **successful, + "status": "failed", + "success": False, + "content_items": [ + { + "type": "inputText", + "text": "Use $smart-router off to turn Smart Router off. Routing is unchanged.", + } + ], + } + + def records(*items): + return [ + {"type": "event_msg", "payload": {"type": "item_completed", "item": item}} + for item in items + ] + + assert codex.completed_smart_router_results(records(successful, denied), "off") == [ + {"message": "Smart Router is off"} + ] + with pytest.raises(AssertionError): + codex.completed_smart_router_results(records(denied), "off") + with pytest.raises(AssertionError): + codex.completed_smart_router_results(records(denied, successful), "off") + denied["content_items"][0]["text"] = "Another failure. Routing is unchanged." + with pytest.raises(AssertionError): + codex.completed_smart_router_results(records(successful, denied), "off") + + def test_claude_follow_ups_accept_repeated_resumes_of_the_same_child(): calls = [_call(1), _call(2)] assert claude.assert_follow_ups_resumed(calls, _records(_RESUMED, _RESUMED)) == "child-id" From 42ffa30b31d2c6fc8cb6b7ffda9a852c85d7ebd0 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 15:22:29 +0000 Subject: [PATCH 13/14] fix(codex): keep footer tool out of model declarations --- docs/codex-smart-router-statusline.md | 1 + src/ucode/smart_routing/codex_statusline.py | 5 ++++- tests/test_codex_statusline.py | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/codex-smart-router-statusline.md b/docs/codex-smart-router-statusline.md index ea7a2eb11..7438d867b 100644 --- a/docs/codex-smart-router-statusline.md +++ b/docs/codex-smart-router-statusline.md @@ -4,6 +4,7 @@ The terminal footer uses the experimental MCP status-line provider API first shipped in stable Codex `0.171.0`. UG registers a local stdio provider for each routed launch and selects it in the terminal client. Both configurations are launch-only. The provider needs no gateway credentials or network access. +Its MCP tool is visible only to the app, so it is excluded from model-facing tool declarations. The indicator reflects the latest session controls, rather than a turn's original routing attribution. Existing children and an ongoing main turn keep their original diff --git a/src/ucode/smart_routing/codex_statusline.py b/src/ucode/smart_routing/codex_statusline.py index 99d0e3361..513ce06a7 100644 --- a/src/ucode/smart_routing/codex_statusline.py +++ b/src/ucode/smart_routing/codex_statusline.py @@ -20,7 +20,10 @@ "description": "Show this session's Smart Router state in the Codex footer.", "inputSchema": {"type": "object", "properties": {}}, "annotations": {"readOnlyHint": True}, - "_meta": {"openai/ui": {"entrypoints": [{"type": "statusline", "resourceUri": RESOURCE_URI}]}}, + "_meta": { + "ui": {"visibility": ["app"]}, + "openai/ui": {"entrypoints": [{"type": "statusline", "resourceUri": RESOURCE_URI}]}, + }, } diff --git a/tests/test_codex_statusline.py b/tests/test_codex_statusline.py index 51bbf3528..c48f80216 100644 --- a/tests/test_codex_statusline.py +++ b/tests/test_codex_statusline.py @@ -53,6 +53,14 @@ def test_terminal_config_contains_only_feature_and_selection(tmp_path): assert statusline.tui_config({}) == {} +def test_statusline_tool_is_visible_to_the_app_only(): + (tool,) = statusline.respond("tools/list", {})["tools"] + assert tool["_meta"]["ui"]["visibility"] == ["app"] + assert tool["_meta"]["openai/ui"]["entrypoints"] == [ + {"type": "statusline", "resourceUri": statusline.RESOURCE_URI} + ] + + @pytest.mark.parametrize( "state", [ From b94ff3097d2b7bc0aea2828557b35f90c0d99611 Mon Sep 17 00:00:00 2001 From: Mason Cao Date: Fri, 20 Nov 2026 15:29:35 +0000 Subject: [PATCH 14/14] test(codex): opt native catalog into plaintext code-mode scenario --- tests/README.md | 4 +++- tests/integration/README.md | 3 ++- tests/integration/test_ug_codex_v2_routing.py | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/README.md b/tests/README.md index 70200896d..c00fcd1a4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1113,7 +1113,9 @@ gateway provider on Windows while Unix launch arguments stay unchanged and routi hooks stay with the app-server. This is component coverage, not a live Windows sign-in or TUI test. -`integration/test_ug_codex_v2_routing.py` checks native v2 through code mode on Codex 0.171.0 or newer: +`integration/test_ug_codex_v2_routing.py` checks native v2 through code mode on Codex 0.171.0 or newer. +Its pre-existing user-owned catalog opts native tools into code mode, overriding the +bundled model's direct-only preference. This transport exposes plaintext assignments: the exact multiline assignment reaches the real hook, router, and native child; the child completes on the routed model while the parent stays pinned. The audit's SHA-256 digest and character count identify that exact assignment without diff --git a/tests/integration/README.md b/tests/integration/README.md index bed28e170..3de95136d 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -111,7 +111,8 @@ the original spawn ciphertext with the child's NEW_TASK receipt and require the task-name fallback digest, while plaintext assignments require their full-text digest. The existing parent/child completion, selected model, and live decision checks still apply. The native v2 assignment journey explicitly uses code mode and separately requires -plaintext at the hook and child. Direct native calls may remain encrypted. Toggle +plaintext at the hook and child. Its user-owned catalog explicitly exposes native tools +in code mode; direct-only bundled settings are not a plaintext guarantee. Direct native calls may remain encrypted. Toggle evidence accepts the exact guard rejection of a duplicate off call only after a successful off result; it still rejects an initial denial or any other failed call. diff --git a/tests/integration/test_ug_codex_v2_routing.py b/tests/integration/test_ug_codex_v2_routing.py index 188d47060..ac3a50c40 100644 --- a/tests/integration/test_ug_codex_v2_routing.py +++ b/tests/integration/test_ug_codex_v2_routing.py @@ -40,6 +40,8 @@ def _seed_user_owned_native_codex_settings(session) -> tuple[Path, bytes, bytes] selected = [model for model in models if model["slug"] in CODEX_NATIVE_CATALOG_MODELS] assert {model["slug"] for model in selected} == set(CODEX_NATIVE_CATALOG_MODELS) assert all(model.get("multi_agent_version") == "v2" for model in selected) + for model in selected: + model["multi_agent_tools_in_code_mode"] = True codex_home = session.home / ".codex" codex_home.mkdir(parents=True, exist_ok=True) @@ -71,8 +73,9 @@ def _seed_user_owned_native_codex_settings(session) -> tuple[Path, bytes, bytes] def test_ug_codex_native_v2_plain_assignment_routing(live_session, workspace): - """Scenario: configure ug with a user-owned native v2 catalog and observer hook, - then delegate one multiline file task through code mode with subagent-only routing. + """Scenario: configure ug with a user-owned native v2 catalog that exposes native + tools in code mode and an observer hook, then delegate one multiline file task + through code mode with subagent-only routing. Expected: the native child and actual hook input contain the exact assignment, matched by the router decision's digest. One native child completes on the selected model; the parent stays on