Route only explicit Codex and Claude invocations through smart routing - #502
Open
lilly-luo wants to merge 6 commits into
Open
Route only explicit Codex and Claude invocations through smart routing#502lilly-luo wants to merge 6 commits into
lilly-luo wants to merge 6 commits into
Conversation
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
from
September 4, 2026 22:58
6dd7576 to
dcda6c4
Compare
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
from
September 4, 2026 23:10
dcda6c4 to
586eeef
Compare
codex / claude (no prompt) and codex -- '<>' and claude -- '<>' to smart router
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
2 times, most recently
from
September 4, 2026 23:47
c5e15dc to
c8ec0f0
Compare
lilly-luo
marked this pull request as ready for review
September 4, 2026 23:54
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
from
September 5, 2026 00:04
c8ec0f0 to
354c435
Compare
codex / claude (no prompt) and codex -- '<>' and claude -- '<>' to smart router
lilly-luo
commented
Sep 5, 2026
Comment on lines
-502
to
-525
| version_text = agent_version(binary) | ||
| parsed_version = _parse_version(version_text) | ||
| if parsed_version is not None and parsed_version < MINIMUM_ROUTING_CODEX_VERSION: | ||
| raise RuntimeError( | ||
| "Codex smart routing requires Codex " | ||
| f"{MINIMUM_ROUTING_CODEX_VERSION_TEXT} or newer; found {version_text}." | ||
| ) | ||
|
|
||
| def _app_server_start_model() -> str: | ||
| managed_model = default_model(state) | ||
| if managed_model: | ||
| return managed_model | ||
| models = routing_models(state) | ||
| if models: | ||
| return codex_model_id(models[0]) | ||
| return APP_SERVER_SMART_ROUTING_STARTING_MODEL | ||
|
|
||
| smart_routing_v2.launch_codex( | ||
| state, | ||
| tool_args, | ||
| binary=binary, | ||
| start_model=_app_server_start_model(), | ||
| render_overlay=render_overlay, | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
this is all moved to _launch_smart_routing and is identical
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
3 times, most recently
from
September 5, 2026 00:17
245a4a5 to
28bcd18
Compare
lilly-luo
force-pushed
the
stack/lilly/only-do-smart-routing-for-2-cases-codex
branch
from
September 5, 2026 00:20
28bcd18 to
9cd4c7e
Compare
lilly-luo
commented
Sep 5, 2026
Comment on lines
-1210
to
-1236
| def _uses_interactive_tui(tool_args: list[str]) -> bool: | ||
| if any(arg in CLAUDE_NONINTERACTIVE_FLAGS for arg in tool_args): | ||
| return False | ||
|
|
||
| index = 0 | ||
| while index < len(tool_args): | ||
| arg = tool_args[index] | ||
| if arg == "--": | ||
| return True | ||
| if arg in CLAUDE_VALUE_OPTIONS: | ||
| index += 2 | ||
| continue | ||
| if arg in CLAUDE_OPTIONAL_VALUE_OPTIONS: | ||
| if index + 1 < len(tool_args) and not tool_args[index + 1].startswith("-"): | ||
| index += 2 | ||
| else: | ||
| index += 1 | ||
| continue | ||
| if arg.startswith("-"): | ||
| index += 1 | ||
| continue | ||
| # Claude accepts an initial prompt positionally and still opens the TUI. | ||
| # Keep prompts inside the V2 PTY while bypassing utility subcommands. | ||
| return arg not in CLAUDE_SUBCOMMANDS | ||
| return True | ||
|
|
||
|
|
Collaborator
Author
There was a problem hiding this comment.
this was very much not needed. now, we just look and see if claude either (1) has no subcommand or (2) has a -- . if (1) or (2) is true, we smart route
lilly-luo
commented
Sep 5, 2026
Comment on lines
-528
to
-549
| if tool_args[:1] == ["app"]: | ||
| # `codex app` rejects --profile. Pass the ucode profile as --config | ||
| # overrides instead, preserving its Databricks provider and auth | ||
| # settings without changing the user's base config.toml. | ||
| profile_doc = read_toml_safe(CODEX_CONFIG_PATH) | ||
| if not profile_doc: | ||
| raise RuntimeError( | ||
| f"Cannot launch Codex app with the ucode profile because {CODEX_CONFIG_PATH} " | ||
| "is missing or empty. Run `ucode configure --agents codex` first." | ||
| ) | ||
| config_args = codex_config_args(profile_doc) | ||
| exec_or_spawn([binary, "app", *config_args, *tool_args[1:]]) | ||
| return # unreachable in production (exec replaces the process) | ||
| # Run codex with --profile first — the TUI and runtime subcommands | ||
| # (exec/resume/mcp/...) keep ucode's Databricks routing, including any added | ||
| # by future codex versions. codex rejects the global --profile on | ||
| # server-family subcommands (app-server, mcp-server, ...), which are | ||
| # caller-configured anyway (e.g. omnigent runs `codex app-server` with its | ||
| # own CODEX_HOME); on that rejection we relaunch without --profile. | ||
| # | ||
| # The retry is gated on the attempt failing *fast*: the rejection is a | ||
| # parse-time error (~0.15s), whereas a session that actually starts can only |
Collaborator
Author
There was a problem hiding this comment.
this was all very much not needed. we can just pass in --config for everything and do the parsing from toml -> config
lilly-luo
commented
Sep 5, 2026
Collaborator
Author
There was a problem hiding this comment.
this file introduces parsing of the tomlkit item in case it is nested.
lilly-luo
requested review from
andy-xu-db,
david-siqi-liu and
rohita5l
and removed request for
david-siqi-liu and
rohita5l
September 5, 2026 01:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://databricks.atlassian.net/browse/AIGTWY-4551
explanation
currently, we are invoking smart routing for /every/ codex and claude command. in reality, we only want to invoke smart routing in 2 cases:
claude/codexempty - this opens a tui and we route on the first promptclaude -- 'hi'/codex -- 'hi'- this opens a tui with 'hi' as the first prompt.;claude --model xxorcodex --model yyshould not invoke smart routing.this PR makes 3 changes so that
ucode codex upgradeanducode codex app-serverwill work:ucode codex updateanducode codex app-servercontinue working without having to maintain a hardcoded subcommand list.ucode codex update. This is because we, by default, pass the ucode config as argument--profileto all codex commands. however, onlycodexandcodex mcptake --profile. instead, the other commands take --config. so i change codex to pass in --config insteaducode codex upgradewould return the error below. this is because when we pass --config instead of --profile to codex, we need to serialize the toml file. the serialization logic had to be updated as a result of tomlkit upgrading to 15.0.finally after 1, 2, and 3 -
ucode codex upgradeanducode codex app-serverwork.test
ENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode claudeENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode codexENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode claude -- 'hi'ENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode codex -- 'hi'ENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode claude --model system.ai.glm-5-2ENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode codex --model system.ai.glm-5-2ENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode codex updateENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode claude upgradeENABLE_SMART_ROUTING_V2=1 SMART_ROUTER_NAME=task_v2 uv run ucode codex app-serverthe below cmds should be unchanged, i tested to ensure no regression
ENABLE_SMART_ROUTING_V2=0 uv run ucode claudeENABLE_SMART_ROUTING_V2=0 uv run ucode codexENABLE_SMART_ROUTING_V2=0 uv run ucode claude --model system.ai.glm-5-2ENABLE_SMART_ROUTING_V2=0 uv run ucode codex --model system.ai.glm-5-2ENABLE_SMART_ROUTING_V2=0 uv run ucode claude -- 'hi'ENABLE_SMART_ROUTING_V2=0 uv run ucode codex -- 'hi'ENABLE_SMART_ROUTING_V2=0 uv run ucode codex updateENABLE_SMART_ROUTING_V2=0 uv run ucode claude upgradeENABLE_SMART_ROUTING_V2=0 uv run ucode codex app-serverbefore (confirming i repro'd the issue) :
after (it's fixed)