Skip to content

Model router gaps: writable + agent-def routing, miss observability, models.subagent (#285-#288) - #289

Merged
JAORMX merged 7 commits into
mainfrom
model-router-gaps-285-288
Jul 21, 2026
Merged

JAORMX merged 7 commits into
mainfrom
model-router-gaps-285-288

Conversation

@JAORMX

@JAORMX JAORMX commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the four model-router gaps found while debugging why "coder" work ran on the orchestrator model (kimi-k3) despite a configured taxonomy — one commit per issue plus a review-iteration commit:

Design record: ADR 0066 (consolidated), narrowly superseding ADR 0041's "accepted v1 residual" sentence and amending ADR 0031's agent-gating rule. Engine API changes regenerated via task api:update with engine/CHANGELOG.md entries (the #287 signature widening classified Changed/breaking; the two options + constants Added/minor).

Closes #285
Closes #286
Closes #287
Closes #288

Review

Nine-agent panel over the branch diff — Spec, Standards, Security (all-clear, CWE-cited), Architecture (no findings ≥ Medium), the reuse/duplication pair (lean), UX, DevEx, and a QA test-adequacy pass (no must-add gaps). The five confirmed should-fix findings were applied in the final commit (honest "router ACTIVE" scope disclosure, docs-example precedence fix, RouterMiss* doc-coverage correction, breaker-silence test, deliberately-not-merged sibling comments).

Verification

  • task test green at every commit and on the final tree (root -race + engine module + GOWORK=off standalone + api-compat gate + docs citation lint)
  • task lint 0 issues (root + engine); task generate artifacts committed (llms.txt, config skeleton/reference)
  • go run ./cmd/mecademo still prints a full offline session

🤖 Generated with Claude Code

JAORMX and others added 5 commits July 21, 2026 14:58
…odel

The def-less child-default model (--subagent-model, the CLAUDE_CODE_SUBAGENT_MODEL
analogue) was CLI-flag-only on both mecated and mecatui while the rest of the
operator model policy lives durably in the settings.yaml models: subtree. Add the
models.subagent: key: strict-parsed on ModelsSection, operator-tier only (a
project-tier subagent: is stripped with a WARN, the default_provider pattern),
folded by foldOperatorSubagentModel after the router fold and before
normalizeSubagentModel so the YAML value rides the SAME fail-fast validation as
the flag (a dead child-default selector fails startup — deliberately stricter
than the fail-soft models.default, because an inert child default silently runs
the whole fleet on the expensive parent model). CLI wins when both are set (the
cliModelKeys snapshot discipline). configgen example + regenerated skeleton and
configuration reference + usage docs included.

Closes #288

Co-Authored-By: Claude Fable 5 <[email protected]>
A router miss was 100% silent — six distinct fail-soft paths (degenerate input,
classifier StopError/StopCancelled, non-JSON verdict, hallucinated category,
unresolvable category target) all inherited the default model with no signal
until the breaker opened after 3 CONSECUTIVE misses, so isolated misses (and any
pattern interleaved with hits) were invisible and indistinguishable from gated
delegations. RunModelRouter and Deps.SubagentModelRouter now return a missReason
(the new RouterMiss* vocabulary; composition adds category-selector-empty /
category-target-unresolvable), consumed at the ONE dispatch-path routeTask
chokepoint as the INFO symmetric to the existing "subagent routed" line —
metadata-only (gauntlet #7: never the task prompt or classifier output, pinned
by an adversarial sentinel test), shared by all three delegation families.
Fail-soft posture unchanged; breaker-open/hardAbort skips deliberately stay
silent. Engine API change regenerated (task api:update) + CHANGELOG entry; the
SubagentPayload wire cue stays a follow-up.

Closes #287

Co-Authored-By: Claude Fable 5 <[email protected]>
mode:"read-write" silently ignored a per-call model AND the model-router pick:
resolveEngineAndLimits unconditionally clobbered the selected engine with the
one pre-built writableChildEngine, while the tool spec, the mode description,
and validateMode's own error text all promised the combination (ADR 0041 called
it an accepted v1 residual; the shipped contract said otherwise). Add the
writable per-model engine factory (WithWritableEngineFactory, the ADR 0058
agentWritableFactory sibling; composition builds it over the shared
writableExplorerDeps body — MAIN runner, direct-write parity, override id
verbatim): a writable explorer now mints its engine on the requested model
(loud model-addressable error on an unknown id, loud validateMode error when
the factory is unwired — never a silent inherit) and a routed pick applies
fail-soft. maybeRouteModel gates the classifier on the factory being wired so a
discarded pick never spends a call; writable+resume keeps the default writable
engine. Spec text updated to shipped truth; e2e proves the override model
reaches the child's request while its Write still lands in the real workspace.

Closes #285

Co-Authored-By: Claude Fable 5 <[email protected]>
…outer

An agent-def delegation was gated out of the router unconditionally under
"never override pinned intent" — but a def with no model: key pinned SCOPE, not
model intent, so a def-based review panel got zero routing and every specialist
silently inherited whatever session model the user happened to pick. Unpinned
defs (TrimSpace(def.Model)=="") are now ROUTABLE: composition computes the set
(routableAgentNames — excluding provider-switched defs, whose routed parent-
provider id would be wrong, and inline-MCP defs, which the factory would
decline) and threads it via the new WithRoutableAgents option; a routed hit
rebuilds the SAME def's scoped engine on the routed model through the existing
ADR 0035 agentModelFactory (per-def limits untouched), a miss/decline fail-
softs to the pre-built def engine. Any non-empty def model — incl. the explicit
`model: inherit` sentinel — stays pinned and never routes; explicit agent+model
and writable specialists are unchanged; the classifier is never spent on a pick
that couldn't be consumed. Precedence: per-call model > def model (incl.
inherit) > router > SubagentModel > session model. The consolidated ADR 0066
records this and the #285 writable-routing change, narrowly superseding ADR
0041's writable-residual sentence and amending ADR 0031's agent-gating rule.
Team members / Parallel branches are out of scope by decision.

Closes #286

Co-Authored-By: Claude Fable 5 <[email protected]>
Five confirmed findings from the review panel: the build-once "router ACTIVE"
line now discloses the WIDENED routing scope (plain + writable-explorer +
unpinned agent-def delegations — the at-startup spend signal the docs already
carried); the model-routing.md subagent: example no longer contradicts the
router precedence configured in the same snippet (it is the fail-soft floor
when a taxonomy is present); the RouterMiss* const-block doc states honestly
that the constants enumerate RunModelRouter's closed output set while the
composition closure may return open-set informational reasons (log-only, not a
branchable enum); a new TestRouterBreakerOpenSkipStaysSilent pins that the
breaker-OPEN skip path emits no per-miss INFO (count == max, not max+skips);
and the two deliberately-unmerged select siblings carry reciprocal comments
naming their divergences to preempt future DRY pressure.

Co-Authored-By: Claude Fable 5 <[email protected]>
@JAORMX
JAORMX requested a review from jhrozek July 21, 2026 13:09

@jhrozek jhrozek 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.

Reviewed via 4-way panel (spec compliance, architecture/layering, security, test coverage) — all clean, no blocking issues.

  • Spec: all four fixes (#285-#288) implement the described behavior; precedence chain (per-call > def model > router > --subagent-model > session) traced and correct.
  • Architecture: layering respected, no adapter/os/gRPC leakage into engine/agent; "provider fixed, re-derive via factory" discipline holds for all new engine-minting paths.
  • Security: model routing doesn't affect the command runner/permission mode for writable Subagents; router-miss logging confirmed metadata-only (no prompt/arg leakage); models.subagent: operator-tier enforcement is structural, not just documented; no panic/nil-deref on unwired factories.
  • Tests: strong coverage including an adversarial canary-string test proving no-leak for #287 and exact-count assertions proving the precedence rungs. One minor gap: mode:"read-write" + named agent: with the router wired has no direct test confirming the classifier is skipped (defensive early-return in subagent.go:1805) — low risk, worth a follow-up test but not blocking.

🤖 Generated with Claude Code

@JAORMX
JAORMX merged commit 4ade4c5 into main Jul 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment