Skip to content

Route each dispatch to a provider by repo size and mode - #267

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/provider-routing
Nov 21, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/provider-routing

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Adds optional provider routing: each run can go to a different agent provider depending on the repo's size and the mode. The design, motivation and evidence are in docs/rfcs/provider-routing.md.

Behaviour

  • No routing.json, no change. The single-harness path is untouched; this is tested to give identical argv and results.
  • With a routing file, run_agent profiles the clone into tier S, M or L and takes the first matching rule's providers. It drops any provider that isn't trusted with the mode, is below the tier, isn't local for a local_only repo, is too small for the repo, can't run here, or fails its health check. Blocked, timed-out, exit-75 or failed runs escalate to the next provider.
  • Refusal, never fallback: with no eligible provider, the run is recorded as an error that lists why each provider was skipped. A local_only repo is never sent to a cloud provider.
  • Provenance: runs gain provider and escalated_from columns (an additive migration), with optional hub fields, a status column and a provider: line in alerts. A free provider's run records no cost, because Claude Code prices every run as if a Claude model served it.
  • Concurrency: overnight respects per-provider concurrency, both while planning batches and through process-wide slots.
  • Explaining: gardener route --repo owner/name [--mode …] explains a decision.

Structure

gardener/routing/ is laid out as ports and adapters:

  • model.py holds the domain values; core.py holds the pure policy (parse, route, escalate).
  • ports/ has eight protocols, one per file. adapters/ has eleven implementations, one per file.
  • RoutingService is the composition root.
  • The safety checks stay in dispatch.py: DispatchReadiness and DispatchRunner only call check_harness_ready and run_agent.
  • Adding a provider type takes one adapter file and one registry entry.

Verification

  • Full suite: 1,467 tests pass, 2 skipped (1,457 before the package split).
  • tests/test_routing.py tests the core with one fake per port and no patching. It also checks each adapter against its port and has architecture tests: model, core and ports never import adapters, and each port or adapter file holds one class.
  • The package split was checked against the earlier single-module version on 600 combinations of mode, repo, size, health and readiness. There were 0 differences in candidates, skip reasons, harness configs and escalation results.
  • The split also made validation stricter: a provider key its harness doesn't take (e.g. a typo) or an unknown cost is now rejected, and a health reply that isn't a JSON object counts as unreachable.
  • Not yet run: the manual verification CLAUDE.md requires for dispatch changes (a real routed align, then an escalation). The RFC lists its steps; it should run before routing is relied on.

drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

https://claude.ai/code/session_01LYNeujxeMjcjdhUF7mg3s3

Optional provider routing (docs/rfcs/provider-routing.md). With no
routing.json, nothing changes. With one, run_agent profiles the repo's
clone into a size tier, picks the cheapest provider trusted with that
mode and tier (a subscription, a self-hosted model behind a Claude Code
wrapper, a command harness), and escalates down the list on blocked,
timeout, EX_TEMPFAIL or error. local_only repos never leave local
providers; with no eligible provider the run is refused, never sent to
a default.

Runs record provider and escalated_from (additive columns, hub fields,
status column, alert line); a free provider's run records no cost.
overnight batches respect per-provider concurrency, and gardener route
explains a decision.

gardener/routing/ is ports and adapters: model, a pure core, one
protocol per file in ports/, one implementation per file in adapters/,
and RoutingService as the composition root. Safety checks stay in
dispatch.py; two adapters only delegate to check_harness_ready and
run_agent. Architecture tests keep the core from importing adapters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeujxeMjcjdhUF7mg3s3
@dmccoystephenson
dmccoystephenson merged commit f8e60c5 into main Nov 21, 2026
5 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/provider-routing branch November 21, 2026 04:03
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.

1 participant