Repository navigation
feat(smart-routing): keep first prompt routing with a pinned model under isaac omni #1887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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( | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
| 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" | ||||||||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| def test_router_failure_launches_on_claude_default(self, tmp_path, monkeypatch, capsys, caplog): | ||||||||||||||
| caplog.set_level("DEBUG", logger="ucode.smart_routing.v2") | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
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.