Skip to content

fix(router): let [router] model rules reach daemon-dispatched items - #577

Merged
getappz merged 2 commits into
masterfrom
task/162-feature-make-router-model-rules-actually
Aug 21, 2026
Merged

fix(router): let [router] model rules reach daemon-dispatched items#577
getappz merged 2 commits into
masterfrom
task/162-feature-make-router-model-rules-actually

Conversation

@getappz

@getappz getappz commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

Two stacked short-circuits in resolve_agent() (src/cli/work.rs) and route() (crates/agent-registry/src/router.rs) both returned model: None unconditionally whenever the agent was already fixed — true for every normal daemon dispatch (the daemon always passes an explicit agent). This meant a [router] rule's model field, and therefore the Claude→ClinePass model mapping (clinepass_model_for_claude, already built and unit-tested), never actually reached a real dispatch.

Fix

Added agent_registry::model_for_task(), which does the same first-match rule lookup as route() but returns only the matched rule's model, independent of agent selection. Both short-circuits (resolve_agent's explicit branch, and route()'s assigned_agent branch) now call it while leaving the already-fixed agent untouched. metadata.model/--model overrides still win over a [router] rule, unchanged.

Closes #162.

Test plan

  • cargo build --workspace — clean
  • cargo test -p agentflare-agent-registry — 55/55 pass
  • cargo test --bin agentflare resolve_agent — 15/15 pass
  • bash scripts/loc-gate.sh — passes on all touched files (3 unrelated pre-existing failures confirmed present on master with this diff stashed out)
  • New tests: explicit_assignment_still_picks_up_a_matching_rules_model (router.rs), resolve_agent_explicit_flag_still_picks_up_a_matching_rules_model (work_model_routing_tests.rs)
  • One pre-existing, unrelated failure (mcp_prompts::tests::optimize_review_returns_full_skill_body) reproduces identically without this change — not caused by this fix

Summary by CodeRabbit

  • Bug Fixes

    • Explicitly selected agents now apply the model configured by matching routing rules.
    • Agent selection and automatic routing now use consistent task details when determining models.
  • Tests

    • Added coverage confirming that explicit agent selections are preserved while matching model-routing rules are applied.

resolve_agent's explicit branch and route()'s assigned_agent short-circuit
both used to return model: None unconditionally, so a rule's model field
was unreachable for any item with an already-fixed agent -- which is every
normal daemon dispatch. Add model_for_task() to look up a matching rule's
model independent of agent selection, and call it from both short-circuits
while leaving the already-fixed agent untouched.

Agentflare-Agent: claude-code
Agentflare-Branch: task/162-feature-make-router-model-rules-actually
Agentflare-Item: 162
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2611f05a-0e1b-487a-8acb-436a7f1eb538

📥 Commits

Reviewing files that changed from the base of the PR and between c39ad45 and 87b4ba8.

📒 Files selected for processing (4)
  • crates/agent-registry/src/lib.rs
  • crates/agent-registry/src/router.rs
  • src/cli/work.rs
  • src/cli/work_model_routing_tests.rs

Included review availability: 1 review is currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

The router now exposes configured model lookup for task contexts. Explicit agent resolution preserves the selected agent while applying a matching rule’s model. Automatic routing reuses the shared task-context construction. Tests cover both behaviors.

Changes

Routing model resolution

Layer / File(s) Summary
Router model lookup
crates/agent-registry/src/lib.rs, crates/agent-registry/src/router.rs
The crate re-exports model_for_task. The router applies first-match rules, populates explicit route decisions with matching models, and tests installed and uninstalled agent cases.
CLI explicit-agent routing
src/cli/work.rs, src/cli/work_model_routing_tests.rs
resolve_agent shares task-context construction across routing paths. Explicit agent selection now returns the selected agent with the matching configured model. Tests cover the urgent rule case.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 87b4b

This change allows configured router model mappings to reach daemon-dispatched items without changing explicit agent selection or override precedence; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the router model-rule fix for daemon-dispatched items.
Description check ✅ Passed The description explains the change, rationale, tests, known failure, and issue link, but omits the template's Notes for reviewers section.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/162-feature-make-router-model-rules-actually

Comment @coderabbitai help to get the list of available commands.

@getappz
getappz force-pushed the task/162-feature-make-router-model-rules-actually branch from 87b4ba8 to d5fc407 Compare August 21, 2026 08:31
@getappz
getappz merged commit 9cfe1bf into master Aug 21, 2026
16 checks passed
@getappz
getappz deleted the task/162-feature-make-router-model-rules-actually branch August 21, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant