Skip to content

Router: expose routing miss/gate reason on delegation-start events (#397) - #408

Merged
jhrozek merged 5 commits into
mainfrom
396-sse-missing-on-run
Aug 10, 2026
Merged

jhrozek merged 5 commits into
mainfrom
396-sse-missing-on-run

Conversation

@jhrozek

@jhrozek jhrozek commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Widens the internal routeTask seam so router misses/gates (pinned model, agent-def-pinned, resume, fork, router-disabled, breaker-open, target-unavailable, aborted) surface a bounded routing_reason string on subagent.start, the Team roster, and Parallel branch_start — previously every non-hit case collapsed to an indistinguishable empty routed_*.
  • Follow-up commit closes review findings on top of the initial implementation: mecatui projects routing_reason across the Subagent/Parallel/Team render paths, Subagent attribution correctly prioritizes explicit resume/fork/per-call-model/agent-def choices over router absence, CHANGELOG entries reclassified under the correct Added/Changed headings, ADR 0083 + doc lifecycle filled in, and routingReasonPayload confines the wire value to a closed allowlist (never raw composition/callback text) — closing a gauntlet-ACP: accept client-provided streaming-HTTP MCP servers #7 gap.
  • Regenerates engine/api/agent.txt/session.txt for WithPinnedAgents and RoutingReasonTargetUnavailable, which were added but missing from the api-compat snapshot.

Fixes #397

Test plan

  • task lint (root + engine + provider/* modules)
  • task api:update / api-compat gate green
  • go test ./engine/... ./cmd/mecatui/... ./internal/adapter/server/... ./internal/apicheck/...
  • go run ./cmd/mecademo — full offline session still prints turn/tool.call/permission.ask+approval/result
  • Six-axis panel review (Spec vs Router: expose structured routing outcome/miss reason on delegation start events #397, Standards, software-architect, secure-code-reviewer, library-reuse, code-duplication) — all clean after fixing the api-compat gap

🤖 Generated with Claude Code

@JAORMX JAORMX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panel review — Approve.

Sound discipline throughout. routingReasonPayload is the single chokepoint applied at every emit site (subagent foreground+background, parallel branch_start incl. cancelled-before-start, team roster): it whitespace-collapses + clamps to 200 runes AND confines the wire to a closed event-safe allowlist (the 8 session.RoutingReason* gates + 5 RouterMiss* + 2 composition codes + empty-model), so a non-allowlisted string an external composition returns (provider error body, classifier output, task excerpt) degrades to the generic routing-miss label — gauntlet #7 holds at the projection rather than trusting compositions. The reason never carries model ids or def names (preserving metrics-label cardinality hygiene), and the closed set is mirrored consistently across all three delegation families + proto (additive fields 18/8/25) + mecatui — no half-wiring.

The -1120 deletion is internal parentCaps.routeTask plumbing (the exported Deps.SubagentModelRouter 5-tuple is untouched); the one exported change (Supervisor.MemberRouting 2→3 returns) is correctly classified Changed in CHANGELOG + api/agent.txt/session.txt, WithPinnedAgents is Added, and the api-compat gate passes. reconcileRoutedModel correctly clears routed fields and reports route-target-unavailable when a factory declines a routed target. Tests cover each gate/miss reason, the allowlist attack surface, and all emit paths; the no-content-leak guards scan RoutingReason by reflection.

Non-blocking notes: (1) no composition-level e2e asserting a detailed reason (e.g. category-selector-empty (category=large)) reduces end-to-end through buildModelRouterTask to a delegation-start event — the reduction and gate pass-through are unit-tested, so the composition-to-wire seam is only indirectly verified; a single e2e would close it. (2) The PR removed a blank line in engine/CHANGELOG.md and a pre-existing merged-bullet wart remains — cosmetic, not correctness. Good to merge.

jhrozek added a commit that referenced this pull request Aug 9, 2026
Add a composition-level e2e test proving buildModelRouterTask's
detailed category-selector-empty miss reduces to the static wire code
before reaching a delegation-start event, closing the previously
indirect composition-to-wire seam. Also fix two cosmetic CHANGELOG.md
formatting issues (a merged bullet, a dropped blank line).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jhrozek
jhrozek force-pushed the 396-sse-missing-on-run branch from 2d87f8f to e4874d1 Compare August 9, 2026 19:21
jhrozek and others added 5 commits August 10, 2026 09:59
…nts (#397)

The delegation-start events (EvSubagentStart, parallel branch_start, team
roster) carried only the router-HIT half (routed_category/routed_model);
every miss/gate collapsed to empty strings while the *why* existed only in
operator diagnostics. A UI could not distinguish router-disabled, pinned
model, agent-def pinned, inherited default, classifier failure, or
breaker-open.

Plumb the already-returned missReason through the internal routeTask seam
and add a bounded, additive routing_reason to the three session payloads +
three proto fields (Subagent 18, TeamMemberSpec 8, Parallel 25) + server
mappers. Empty on a routed hit; a session.RoutingReason* gate constant
(pinned-model / agent-def-pinned-model / resume / fork / router-disabled /
breaker-open / aborted) or a classifier/composition miss string otherwise.
Gauntlet-#7 safe (never the task prompt or classifier reasoning), clamped
at the emit site. Widens only the internal routeTask + MemberRouting (2->3);
Deps.SubagentModelRouter is untouched. ADR 0083.

Co-Authored-By: mecatl <[email protected]>
…#397)

Addresses the follow-up review findings on the routing-reason feature:
mecatui now projects routing_reason across Subagent/Parallel/Team render
paths, Subagent attribution correctly prioritizes explicit resume/fork/
per-call-model/agent-def choices over router absence, the CHANGELOG entries
are reclassified under the correct Added/Changed headings, ADR 0083 and the
doc lifecycle are filled in, and routingReasonPayload now emits only bounded
static codes (never raw composition/callback text) to close a gauntlet-#7
gap. Also regenerates engine/api/agent.txt and engine/api/session.txt for
WithPinnedAgents and RoutingReasonTargetUnavailable, which were added by
this diff but missing from the api-compat snapshot.

Fixes #397

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Add a composition-level e2e test proving buildModelRouterTask's
detailed category-selector-empty miss reduces to the static wire code
before reaching a delegation-start event, closing the previously
indirect composition-to-wire seam. Also fix two cosmetic CHANGELOG.md
formatting issues (a merged bullet, a dropped blank line).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Rebasing 396-sse-missing-on-run onto main surfaced a gap the
structural UTF8 fuzz test (added upstream after this branch forked)
flags automatically: Subagent/Team/Parallel RoutingReason is
harness/composition-authored bare metadata reduced to a closed
allowlist (routingReasonPayload), never producer text, so it belongs
in harnessTokenFields alongside the sibling RoutedCategory/RoutedModel
fields rather than through valid().

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The rebase onto origin/main (which had just merged PR #428's llms.txt
regen) resolved the llms.txt conflict by taking main's side verbatim,
but that snapshot predates this branch's own docs/adr/0083 and other
router-reason doc additions being re-applied on top. Regenerate for
real against the final tree; task docs:check --strict passes clean
(0 broken links/anchors/ambiguous/orphans).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jhrozek
jhrozek force-pushed the 396-sse-missing-on-run branch from e4874d1 to 78334bc Compare August 10, 2026 08:07
@jhrozek
jhrozek merged commit f85f0c8 into main Aug 10, 2026
15 checks passed
@jhrozek
jhrozek deleted the 396-sse-missing-on-run branch August 10, 2026 08:21
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.

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

2 participants