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/.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/AGENTS.md b/AGENTS.md index 4f36cd5ca..027b4e643 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -475,7 +475,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 8d7c51d52..537860782 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,9 @@ 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`. +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. @@ -725,23 +725,24 @@ 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**. 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. + +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 -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`), @@ -804,10 +805,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/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 36e7f26e5..55557d5ca 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, @@ -4455,6 +4456,12 @@ def _launch_tool( routing_unavailable = codex_agent.minimum_version_error( smart_routing_enabled=True ) + 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: diff --git a/tests/README.md b/tests/README.md index c8fba0e59..29bac0709 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,24 @@ # 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 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). + +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. +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`. Checks resolve external and pay-per-token destinations using selected credentials; @@ -1110,7 +1129,9 @@ when forwarded after UG's `--`; option-only suffixes are not mistaken for prompt The launch-policy matrix uses one native model spelling per tool; shared parser, classifier and routed-launch tests retain the split, equals and short-form checks. -`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 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 saved-model, `--model VALUE` and `--model=VALUE` variants cover native TUI launch; @@ -1122,13 +1143,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. @@ -1519,8 +1543,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/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 d8fcd6f74..9af096803 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 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 `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 @@ -99,6 +106,16 @@ 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 explicitly uses code mode and separately requires +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. + 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. @@ -1305,8 +1322,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.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 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 @@ -1572,7 +1590,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. @@ -1580,11 +1598,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'`. @@ -1806,14 +1824,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_codex_v2_routing.py b/tests/integration/test_ug_codex_v2_routing.py index 01a582fc4..50ab5b84f 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) @@ -74,8 +76,9 @@ def _seed_user_owned_native_codex_settings(session) -> tuple[Path, bytes, bytes] "model_option", [None, "--model", "--model="], ids=["saved", "split", "equals"] ) def test_ug_codex_native_v2_plain_assignment_routing(live_session, workspace, model_option): - """Scenario: configure ug with a user-owned native v2 catalog and observer hook, - then delegate one multiline file task with subagent-only routing. Launch with + """Scenario: configure ug with a user-owned native v2 catalog that exposes tools + in code mode and an observer hook, then delegate one multiline file task through + code mode with subagent-only routing. Launch with the saved model or explicitly enable routing and forward either native model syntax. Expected: the native child and actual hook input contain the exact assignment, @@ -89,6 +92,8 @@ def test_ug_codex_native_v2_plain_assignment_routing(live_session, workspace, mo 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/test_ug_smart_routing_hooks.py b/tests/integration/test_ug_smart_routing_hooks.py index c2b8fc8cb..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 @@ -1002,8 +985,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 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. """ @@ -1011,7 +995,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 ) @@ -1027,8 +1011,17 @@ def test_smart_router_managed_default_matches_codex_version_at_launch( # TODO: remove once the latest recipe supports codex session.env["SMART_ROUTER_NAME"] = "m2-r315-quality-20260929" with AgentTerminal( - session, "codex", [str(session.binary), "codex"], "smart-router-managed-default" + session, + "codex", + [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 @@ -1042,13 +1035,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.164.0 or newer" in launch_text, transcript + 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/integration/utils/agents/codex.py b/tests/integration/utils/agents/codex.py index 0a12261f9..49ff2ef93 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( @@ -66,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_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 b04ccd95f..33bb9bfac 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1132,7 +1132,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) @@ -1196,9 +1196,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.163.0"]) - @pytest.mark.parametrize("recovery", ["decline", "upgrade", "disable", "managed-default"]) - def test_codex_routing_version_requires_upgrade_or_explicit_disable( + @pytest.mark.parametrize( + "installed_version", ["0.156.0", "0.164.0", "0.170.0", "0.171.0-alpha.12"] + ) + @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 @@ -1209,8 +1224,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): @@ -1219,7 +1238,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.164.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): @@ -1233,16 +1255,24 @@ 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") 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 == "upgrade" + "ucode.agents.prompt_yes_no_default", + side_effect=answer_upgrade, ) as prompt, ): calls["launch"].side_effect = launch @@ -1250,14 +1280,21 @@ def launch_native(*_args, **_kwargs): 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) - if recovery in {"decline", "managed-default"}: + assert routed == (["0.171.0"] if recovery in {"upgrade", "managed-upgrade"} else []) + managed_fallback = recovery.startswith("managed") and recovery != "managed-upgrade" + assert bool(plain) == (managed_fallback or recovery == "disable") + assert updates == ( + [] if recovery in {"decline", "disable", "managed-default"} else [["codex", "update"]] + ) + 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( @@ -1314,7 +1351,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) @@ -1364,7 +1401,7 @@ def test_forwarded_model_keeps_subagent_routing( self, monkeypatch, tool, model, version, launch_args, 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" ) managed = None if version is None: diff --git a/tests/test_codex_smart_routing_v2.py b/tests/test_codex_smart_routing_v2.py index 979542ee3..948794816 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)) @@ -857,7 +857,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_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_contract.py b/tests/test_integration_contract.py index ad353e44f..49f95fd5c 100644 --- a/tests/test_integration_contract.py +++ b/tests/test_integration_contract.py @@ -283,7 +283,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] @@ -475,7 +475,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 diff --git a/tests/test_integration_evidence.py b/tests/test_integration_evidence.py index be7e5ba98..2020a71ee 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): @@ -1184,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"