Skip to content

feat(cli): route new runs, missions, delegated children and cron runs (#586 part 2) - #652

Merged
ajianaz merged 4 commits into
developfrom
feat/rule-router-wiring
Nov 13, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/rule-router-wiring

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 2 of #586: the RuleRouter wired into the places a model is chosen today, behind config and off by default. Merging this PR closes #586.

Depends on: #650 (part 1a, tole_core::router) and #651 (part 1b, [router], tole route, doctor), both merged. This branch has the latest develop merged in (a merge commit) and now targets develop.

Why

Parts 1a and 1b made routing declarable and checkable, but nothing used it. This applies a route to the run it was made for, once per run and never per turn, so the prompt cache survives. Nothing but the model changes.

Changes

  • routing::route_new_session, the single entry point:

    • off unless [router] enabled = true;
    • a session that already has fact/model is left alone (an explicit choice wins);
    • a broken router is an error;
    • otherwise it writes the routed model as fact/model (when a rule matched) and the decision as fact/route (Route::record: redacted, then capped);
    • it returns a one-line summary for stderr.
  • routing::mission_kind: a mission with TOLE_AGENT_DEPTH ≥ 1 (a delegated child) routes as delegate.

  • tole_core::tool::ToolRegistry::max_risk feeds the brief's tool risk.

  • Call sites, each after the session exists and before the provider is built:

    • run_command, chat_command (fresh only), tui_command (fresh only, quiet), all through HostConfig::route;
    • mission::run_mission (fresh only), through a closure that carries the mission's budget tier;
    • cron::agent::run_agent: a new run of a job without a --model pin, on the job's own prompt (never the webhook context), with the job name, profile and token budget.
  • Owner decisions (2026-11-13), as documented in feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) #651:

    • a matching rule replaces the configured model, whether it comes from TOLE_MODEL, the config's model or a profile's default; only a session's own model and a cron job's --model pin are never routed;
    • a rule without profiles applies only to runs without a profile.

    tole route keeps feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) #651's wording, which shows the configured model and its source.

  • No stray session files: run, chat, the TUI and mission check the router before their session file exists, so a broken router leaves nothing behind. A cron run fails with the remedy.

  • Unchanged: budgets, allow lists, plan mode and secrets are built exactly as before, and the e2e test compares the tools sent with and without a route. tole serve / ACP sessions and the TUI's /new are not routed.

  • Docs: CHANGELOG, design A9.3 "as implemented, part 2", the threat-model row, the README status line and config row, and docs/epics.md, all per AGENTS.md §7.

Testing

  • cargo fmt --all
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace
  • cargo test -p tole-core --no-default-features
  • No-mcp CI commands:
    • cargo check -p tole-cli --no-default-features
    • cargo clippy -p tole-cli --no-default-features --features shell-tools -- -D warnings
    • cargo test -p tole-cli --no-default-features
  • All of the above ran on this head, after the merge of develop.
  • cora review --no-llm --staged: no issues (on the part 2 commit; the merge only resolved conflicts with feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) #651's text).
  • New tests:
    • 3 unit tests in routing_tests.rs;
    • tests/router_wiring_e2e.rs: 4 tests on the real binary with a mock provider. They cover:
      • a routed run, a default run and routing off;
      • the same tools with and without a route;
      • a broken router (no provider request, no session file);
      • a mission routed as mission, and as delegate at depth 1;
      • cron routed, default and pinned (a pinned job keeps its pin even when a rule matches it).
  • Mutation breaks, each restored afterwards; the tests caught all 9:
    • an explicit model is ignored;
    • the route is not recorded;
    • a broken router falls back;
    • the delegate depth is ignored;
    • a run is routed as chat;
    • the run's pre-check is dropped;
    • a mission is not routed;
    • cron routes pinned jobs;
    • the cron brief loses the job name.

tole_core::router: a Router returns a Route (tier light/standard/heavy,
source, reason), never a model name, budget, allow list or secret.
RuleRouter takes every matching rule, picks the cheapest tier (ties go
cheaper; the first rule of that tier names the route), narrows to an
allowed-tier set, and keeps the configured model when nothing matches.
check() refuses a rule whose tier is not declared where it resolves or
an unknown profile, naming the remedy. Route::record redacts with the
process secrets before it caps. Platform-agnostic, no new dependency.
…part 1b)

[router] is off unless the user config says enabled = true. Tiers
([router.tiers], profiles.<name>.models) and rules come from the user
config only; a project config can only set enabled = false or narrow
allow_tiers, and anything else is ignored with a warning. An unknown
tier, kind or risk, an undeclared tier or an unknown profile is a load
error naming the remedy, never a fallback to another model. tole route
prints the tier, model and reason a run would get without calling a
provider, redacted; tole doctor and config check show names only.
…#586 part 2)

With [router] enabled in the user config, a new run, chat, TUI session,
mission, delegated child (TOLE_AGENT_DEPTH >= 1, routed as delegate) and
cron agent run is routed once, before its first provider call; resumed
sessions keep their model. An explicit model wins: a session that
already has fact/model and a cron job with a --model pin are not
routed. The routed model is stored as fact/model and the decision,
redacted then capped, as fact/route. Budgets, allow lists, plan mode
and secrets are untouched. A broken router stops the run before its
session file exists (a cron run fails with the remedy).
@ajianaz
ajianaz changed the base branch from feat/rule-router-config to develop November 13, 2026 00:32
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 016658a into develop Nov 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the feat/rule-router-wiring branch November 20, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: model routing by task weight — RuleRouter baseline, LayaRouter via systemone

2 participants