Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,10 @@ Like any version, the preset overrides individually set routing env vars.
In the Auto flow, an explicit ordinary `--model` starts with routing off. In other
smart-routing launches, an explicit `--model`, from `ug claude --model` or a launcher
such as Omnigent, keeps subagent routing when first-prompt routing is off.
With first-prompt routing on, an explicit model still skips routing.
With first-prompt routing on, an explicit model still skips routing, except under
`ISAAC_LAUNCH_MODE=omni`: Omnigent pins every launch's model, so there the session starts on
that model and the first prompt may route it to another. Headless `-p` keeps the model and
routes only subagents.

When a model response launches a subagent, UG buffers that step and removes
premature model claims before displaying or storing them. After launch, UG renders
Expand Down
12 changes: 9 additions & 3 deletions src/ucode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4149,7 +4149,12 @@ def _should_launch_smart_routing(
) -> bool:
pinned = model is not None or has_explicit_model_arg(tool_args)
# Subagent-only routing keeps a pinned root model; first-prompt routing would replace it.
if pinned and smart_routing_v2.first_prompt_routing_enabled(agent=tool):
# `isaac omni` pins every launch, so there the pinned model is only the starting model.
if (
pinned
and smart_routing_v2.first_prompt_routing_enabled(agent=tool)
and os.environ.get(ISAAC_LAUNCH_MODE_ENV_VAR) != "omni"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lilly-luo , let me know if you prefer to use OMNIGENT =1 env var instead if we don't want to add isaac specific env var check here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability · low
this is now the third python check of ISAAC_LAUNCH_MODE == "omni" (also cli.py:3860, feedback.py:26). can we add an is_isaac_omni_launch() helper in constants/feedback so the contract string can't drift?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems legit

):
return False
return _smart_routing_launch_shape(tool, tool_args, explicit_prompt)

Expand Down Expand Up @@ -4972,8 +4977,9 @@ def _launch_tool(
ctx.args,
smart_routing_enabled=smart_routing_enabled,
explicit_prompt=explicit_prompt,
# A developer's explicit model allows only subagent-only routing. A managed default is
# the initial/fallback model and still participates in a routed session.
# Outside `isaac omni`, a developer's explicit model allows only subagent-only routing.
# A managed default is the initial/fallback model and still participates in a routed
# session.
user_pinned_model=model or forwarded_model,
provider=provider,
# Copilot picks its start model from its own catalog; the admin's or budget pick leads.
Expand Down
5 changes: 4 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,10 @@ hooks stay with the app-server. This is component coverage, not a live Windows
sign-in or TUI test.
`test_cli.py` covers forwarded model arguments under explicit enable/disable, managed
defaults and routing presets for Claude and Codex, including pinned-root bypass of
first-prompt routing and Isaac's config-only Codex launch arguments.
first-prompt routing, the `ISAAC_LAUNCH_MODE=omni` exception that keeps first-prompt routing
from the pinned model (`--disable-smart-routing` still wins), and Isaac's config-only Codex
launch arguments. `test_claude_smart_routing_v2.py` checks that a first-prompt launch with a
forwarded or ug `--model` starts Claude on that model once and installs the first-prompt hook.
The model-forwarding cases fix Codex's reported version at 0.165.0 so managed routing
does not depend on an agent installed on the test runner.
`test_smart_router.py` also runs each agent's orchestrator hook in a fresh Python
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def reject_privileged_write(path, _desired_text):
monkeypatch.delenv("ENABLE_SMART_ROUTER_ORCHESTRATOR", raising=False)
monkeypatch.delenv("SMART_ROUTER_CONFIG_VERSION", raising=False)
monkeypatch.delenv("SMART_ROUTER_NAME", raising=False)
# An `isaac omni` pane's launch mode changes which pinned launches route.
monkeypatch.delenv("ISAAC_LAUNCH_MODE", raising=False)
# On Windows, resolve_command swaps a bare program name for whatever `shutil.which`
# finds on the developer's PATH (e.g. a real `codex.CMD`). Rebind only the compatibility
# helper's `shutil` so argv stays host-independent; helper tests patch `which` explicitly.
Expand Down
55 changes: 54 additions & 1 deletion tests/test_claude_smart_routing_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,58 @@ def fake_run(argv, **kwargs):
"new": True,
}

@requires_pty
@pytest.mark.parametrize(
("tool_args", "launch_model"),
[(["--model", "system.ai.claude-opus-5-5"], None), ([], "system.ai.claude-opus-5-5")],
ids=["forwarded-model", "ug-model"],
)
def test_first_prompt_launch_starts_on_a_pinned_model(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · low
can we name or set this for isaac omni? only omni launches with a pinned model reach the first-prompt hook (cli.py gates the rest), but this test reads like it's true for every pinned launch.

self, tmp_path, monkeypatch, tool_args, launch_model
):
monkeypatch.setenv("SMART_ROUTER_CONFIG_VERSION", config.FIRST_PROMPT_AND_SUBAGENT_ORCH_V0)
monkeypatch.setattr(claude, "_managed_settings_path", lambda: None)
monkeypatch.setattr(v2, "APP_DIR", tmp_path)
monkeypatch.setattr(v2, "CLAUDE_PTY_LOG", tmp_path / "v2.log")
monkeypatch.setattr(custom_oauth, "get_databricks_token", lambda *_args, **_kwargs: "token")
monkeypatch.setattr(v2, "build_auth_token_argv", lambda *_args, **_kwargs: ["/bin/ug"])
monkeypatch.setattr(
v2,
"list_anthropic_model_catalog",
lambda *_args: AnthropicModelCatalog(
model_ids=["system.ai.claude-sonnet-5"], model_id_to_display_name={}
),
)
captured: dict = {}

def fake_run(argv, **_kwargs):
captured["argv"] = argv
captured["settings"] = json.loads(Path(argv[argv.index("--settings") + 1]).read_text())
return 0

monkeypatch.setattr(claude_pty, "run_claude_pty", fake_run)
with pytest.raises(SystemExit) as exc:
v2.launch_claude(
{"workspace": "https://example.com"},
tool_args,
binary="claude",
user_settings_path=tmp_path / "settings.json",
launch_model=launch_model,
compose_settings=lambda args: ({}, list(args)),
launch_model_args=claude._launch_model_args,
model_name=claude._maybe_add_1m_suffix,
)

assert exc.value.code == 0
argv = captured["argv"]
assert argv.count("--model") == 1
assert argv[argv.index("--model") + 1] == "system.ai.claude-opus-5-5"
assert "/bin/ug claude-router-hook route-first-prompt" in {
hook["command"]
for group in captured["settings"]["hooks"]["UserPromptSubmit"]
for hook in group["hooks"]
}

@requires_pty
def test_does_not_restore_when_wrapper_never_switches(self, tmp_path, monkeypatch):
user_settings = tmp_path / "settings.json"
Expand Down Expand Up @@ -2369,13 +2421,14 @@ def test_prompt_argument_is_routed_without_reading_stdin(self, tmp_path, monkeyp
assert argv[argv.index("--model") + 1] == "system.ai.claude-sonnet-5[1m]"
assert argv[-4:] == ["-p", "fix the parser", "--output-format", "json"]

def test_explicit_model_skips_routing(self, tmp_path, monkeypatch):
def test_explicit_model_keeps_the_model_and_routes_only_subagents(self, tmp_path, monkeypatch):
launched, prompts = self._launch(
monkeypatch, tmp_path, ["-p", "fix the parser", "--model", "opus"]
)

assert prompts == []
assert launched["argv"].count("--model") == 1
assert launched["settings"]["env"][v2.ENABLE_SUBAGENT_ROUTING_ENV_VAR] == "1"
Comment on lines 2430 to +2431

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · low
can we assert the --model value is still opus? the name says "keeps the model", but the count check still passes if routing swaps in the routed model.

Suggestion:

Suggested change
assert launched["argv"].count("--model") == 1
assert launched["settings"]["env"][v2.ENABLE_SUBAGENT_ROUTING_ENV_VAR] == "1"
argv = launched["argv"]
assert argv.count("--model") == 1
assert argv[argv.index("--model") + 1] == "opus"
assert launched["settings"]["env"][v2.ENABLE_SUBAGENT_ROUTING_ENV_VAR] == "1"


def test_router_failure_launches_on_claude_default(self, tmp_path, monkeypatch, capsys, caplog):
caplog.set_level("DEBUG", logger="ucode.smart_routing.v2")
Expand Down
66 changes: 57 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ def select_and_launch_agent(*args, **kwargs):
launch.assert_called_once()


# Each way a launch pins the main model: Claude's forwarded --model, ug's own --model.
_PINNED_MODEL_LAUNCHES = [
("claude", ["--model", "fixed"], None),
("claude", ["-p", "hi", "--model", "fixed"], None),
("claude", [], "fixed"),
("codex", [], "fixed"),
]

_NOTICE_VISIBILITY_CASES = [
(smart_routing_config.SUBAGENT_ORCH_V0_BLIND_SUBAGENT_MODEL, False),
(smart_routing_config.SUBAGENT_ORCH_V0, True),
Expand Down Expand Up @@ -998,15 +1006,7 @@ def test_provider_routing_is_supported_for_claude_and_codex(self, tool, expected

assert options.launch_smart_routing is expected

@pytest.mark.parametrize(
("tool", "tool_args", "model"),
[
("claude", ["--model", "fixed"], None),
("claude", ["-p", "hi", "--model", "fixed"], None),
("claude", [], "fixed"),
("codex", [], "fixed"),
],
)
@pytest.mark.parametrize(("tool", "tool_args", "model"), _PINNED_MODEL_LAUNCHES)
@pytest.mark.parametrize(
("routing_env", "expected"),
[
Expand All @@ -1032,6 +1032,25 @@ def test_explicit_model_keeps_only_subagent_routing(

assert options.launch_smart_routing is expected

@pytest.mark.parametrize(("tool", "tool_args", "model"), _PINNED_MODEL_LAUNCHES)
@pytest.mark.parametrize(("launch_mode", "expected"), [("omni", True), ("direct", False)])
def test_isaac_omni_explicit_model_keeps_first_prompt_routing(
self, monkeypatch, tool, tool_args, model, launch_mode, expected
):
monkeypatch.setenv("ENABLE_SMART_ROUTING_V2", "1")
monkeypatch.setenv("ISAAC_LAUNCH_MODE", launch_mode)

options = cli_mod._launch_options(
tool,
tool_args,
smart_routing_enabled=True,
explicit_prompt=False,
user_pinned_model=model,
provider=None,
)

assert options.launch_smart_routing is expected

@pytest.mark.parametrize(
("tool_args", "expected"),
[
Expand Down Expand Up @@ -1434,6 +1453,35 @@ def test_forwarded_model_keeps_subagent_routing(
assert result.exit_code == 0, result.output
assert observed == [routed]

@pytest.mark.parametrize(
"tool,model",
[("claude", "claude-opus-5-5"), ("codex", "gpt-6.2-astra")],
)
@pytest.mark.parametrize(
("launch_args", "routed"),
[([], True), (["--disable-smart-routing"], False)],
ids=["first-prompt-version", "disable-flag"],
)
def test_isaac_omni_forwarded_model_keeps_first_prompt_routing(
self, monkeypatch, tool, model, launch_args, routed
):
monkeypatch.setattr(
cli_mod.codex_agent, "agent_version", lambda *_args, **_kwargs: "0.171.0"
)
monkeypatch.setenv("ISAAC_LAUNCH_MODE", "omni")
monkeypatch.setenv(
"SMART_ROUTER_CONFIG_VERSION", smart_routing_config.FIRST_PROMPT_AND_SUBAGENT_ORCH_V0
)
observed = []
with _launch_policy_patches(None) as calls:
calls["launch"].side_effect = lambda *_args, options, **_kwargs: observed.append(
options.launch_smart_routing
)
result = runner.invoke(app, [tool, *launch_args, "--", "--model", model])

assert result.exit_code == 0, result.output
assert observed == [routed]

@pytest.mark.parametrize(
"native_args",
[
Expand Down
Loading