Skip to content

feat(core): Router seam and deterministic RuleRouter (#586 part 1a) - #650

Merged
ajianaz merged 1 commit into
developfrom
feat/rule-router
Nov 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/rule-router

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1a of #586: the Router seam and its deterministic baseline, RuleRouter, in tole-core. Nothing routes yet. The [router] config, the tole route dry run and the doctor lines are in the stacked #651. The wiring into runs, cron runs and delegated children comes in part 2, off by default.

Why

The design (profiles-collaboration-secrets.md A9.2/A9.3) requires a simple rule baseline before any learned router (LayaRouter) is trusted: LLMRouterBench shows many routers fail to beat one. The tie and doubt rules follow the routing-collapse result: ties go to the cheaper tier.

Changes

  • crates/tole-core/src/router.rs (new): platform-agnostic, no I/O, no new dependency, builds with --no-default-features.
    • Types:
      • Tier (light < standard < heavy, cost order) and TaskKind (chat, run, mission, cron, delegate);
      • Brief: the owner-side facts about a run (kind, prompt, highest tool risk, profile, job, budget left). The prompt is read only for its size and the owner's keywords.
    • Rule / When: every set condition must hold (kinds, min_chars / max_chars, min_risk / max_risk, profiles, jobs, budget_below, keywords).
      • A rule without profiles applies only to runs without a profile. A rule's tier is therefore always checked against the tier map it resolves through.
      • An unknown budget never satisfies budget_below.
    • Router trait and RuleRouter:
      • every matching rule is a candidate, and the cheapest tier wins; the first declared rule of that tier names the route;
      • an allowed-tier set can only narrow the pick;
      • no match gives Route { tier: None, source: Default }, so the configured model stays.
    • Route carries only a tier, a source and a reason. It has no field for a model name, budget, allow list or secret.
      • Route::model(&Tiers) errors on an undeclared tier and never falls back to another model.
      • Route::record redacts every string with the SecretSet before capping at 300 characters.
    • RuleRouter::check refuses, at load time and with a remedy, a rule whose tier is not declared where it resolves, or an unknown profile.
  • crates/tole-core/src/router_tests.rs (new): 10 tests.
  • CHANGELOG [Unreleased]. The threat-model row and the design "as implemented" note are in feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) #651, which makes the behaviour reachable.

Testing

  • TDD: the tests went red against a stub route (6 of 10 failed), then green.
  • 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
  • The commands above ran on the combined tree (this PR plus feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) #651).
  • cora review --no-llm --staged: no issues.
  • Mutation breaks, each restored afterwards; the tests caught all 9:
    • ties go to the costlier tier;
    • the default picks a cheaper tier;
    • allowed tiers are ignored;
    • a plain rule applies to profile runs;
    • an unknown budget satisfies budget_below;
    • keywords are case-sensitive;
    • max_risk is ignored;
    • a profile's tier is not checked;
    • the record is capped before it is redacted.

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.
@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 0b63cc3 into develop Nov 12, 2026
25 of 26 checks passed
@ajianaz
ajianaz deleted the feat/rule-router 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.

2 participants