Skip to content

Router: expose structured routing outcome/miss reason on delegation start events #397

Closed

Description

@jhrozek

Split out from #391 (claim 3).

Claim

Router misses have useful reasons in diagnostics (classifier-error, unknown-category, breaker-open, category-target-unresolvable, etc.), but on the client event wire an unrouted delegation only has empty routed_category / routed_model. A UI cannot distinguish: router disabled/absent; explicitly pinned model; defined agent that intentionally bypassed routing; inherited default; classifier failure or breaker-open fallback. Expose a bounded structured routing outcome/reason on subagent.start, Team roster entries, and Parallel branch_start — no classifier reasoning or prompt text needed.

Investigation (verified against the codebase)

Verdict: confirmed. The wire carries only the router-hit half; every miss/gate case collapses to empty strings while the why exists only in operator diagnostics. Notably this was a deliberate deferral (ADR 0031 scoped the wire as a follow-up; ADR 0034 landed the hit fields; ADR 0035 added unconditional model) — not an oversight.

Evidence

  • Wire = hit-only: routed_category/routed_model on Subagent proto 11/12 (contracts/proto/mecatl/v1/harness.proto:1120,1125), TeamMemberSpec 5/6 (:1175,1180), Parallel 19/20 (:1353,1358) — every doc comment says "empty otherwise". Session mirrors: engine/session/event.go:546-547, 678-679, 804-805.
  • The miss-reason taxonomy exists: closed set RouterMiss{DegenerateInput,ClassifierError,Cancelled,BadVerdict,UnknownCategory} (engine/agent/modelrouter.go:41-59) + composition's category-selector-empty/category-target-unresolvable (internal/app/build.go:5203,5212) + empty-model (engine/agent/dispatch.go:1348). All are consumed by exactly one sink: the diag INFO at dispatch.go:1343-1353. Breaker-open/hardAbort return early and deliberately log nothing (dispatch.go:1221-1231).
  • The reason is dropped at the internal seam: Deps.SubagentModelRouter already returns missReason (engine/agent/loop.go:283), but parentCaps.routeTask narrows the signature to (category, model, ok) (engine/agent/subagent.go:163); the three maybeRoute* gates translate any failure to ("",""), landing verbatim as empty fields on EvSubagentStart (subagent.go:2273-2274), parallel.branch_start (parallel.go:564-565), and the team roster (teamsupervisor.go:864-869).
  • Of the five cases the issue lists, the wire distinguishes only a hit; pinned / def-pinned / inherited / router-absent / miss all read identically as routed_*="" + model=<id>.

Nuance

The reason strings are already vetted gauntlet-#7-safe metadata ("never the task prompt or the classifier's output", modelrouter.go:38-40) — putting them on the wire crosses no new trust boundary. The miss reason is already plumbed end-to-end to the dispatch chokepoint (issue #287) — the fix is additive plumbing at an existing seam, not new collection.

Proposed fix (~1-2 days)

  1. Widen internal routeTask to pass missReason through; synthesize breaker-open at dispatch.go:1221; Subagent distinguishes its own gates from args (pinned-model, agent-def-pinned-model, router-disabled, resume/fork constants).
  2. Add a routing_reason string to the 3 session payloads + 3 additive proto fields (Subagent 18, TeamMemberSpec 8, Parallel 22) + mapper population (mapper.go toProtoSubagent/Team/Parallel) + mecatui view-model.
  3. Full coverage of all five cases (incl. router-disabled as a value rather than absence) needs one new composition→engine bit (e.g. WithRouterConfigured(bool)).

Constraints

  • New ADR entry (0031/0034/0035 are frozen).
  • Additive proto fields only, next free numbers, task generate (never hand-edit contracts/gen).
  • Session payload fields are Added/minor → task api:update + engine/CHANGELOG.md note.
  • Clamp/whitespace-collapse composition-authored reason strings per the SubagentPayload.Cause precedent (event.go:594-599).
  • Update the structural leak guards (TestTeamMemberSpecHasNoContentFields/TestParallelPayloadHasNoContentFields) and the behavioral gauntlet test (teamsupervisor_router_test.go:374-395).
  • The "loop emits exactly three diagnostics lines" invariant is untouched (the field rides events, not diag).
  • Prefer widening only the internal routeTask — Deps.SubagentModelRouter is exported API already returning the reason, so no exported signature change is needed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions