Skip to content

feat(delegation): exact-route provider pinned to one route, no fallback (D02 prerequisite) - #1028

Open
razi-exo wants to merge 1 commit into
feat/swarm-delegation-model-routesfrom
feat/swarm-exact-route-provider
Open

razi-exo wants to merge 1 commit into
feat/swarm-delegation-model-routesfrom
feat/swarm-exact-route-provider

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

Adds two router helpers that let a caller pin one configured route for a delegate turn, with no fallback to any other route. Nothing in delegation calls them yet. D02 runtime activation is still future work.

What changes

  • Router.stream(..., _exact="provider:model") (private, optional): the chain becomes that one route. Credential rotation, cooldowns, circuit breaker and the spend guard of the same Router all still apply. A bad ref raises ValueError before anything is streamed.
  • Router.provider_for(ref, role="delegate"): a RoleProvider for one route on the same Router (one shared cooldown, breaker and spend state). It checks shape, known provider and the provider's roles table, and raises ValueError before any credential is read.
  • _exhausted, _chain_cooldowns and _refused take an optional _chain, so wait hints and refusals describe only the route the call walked.
  • docs/SWARM-DELEGATION.md records these helpers and keeps runtime activation in the not-built list.

Scope

Area Path Status
Exact-route pin, no fallback src/exo/core/models/router.py done
Prerequisite docs docs/SWARM-DELEGATION.md done
Tests tests/test_router_exact_route.py (new, 15 tests) done

No change to Delegator, the child loop, route_config.py, or any default Router behaviour.

Validation

Head HEAD of feat/swarm-exact-route-provider, base feat/swarm-delegation-model-routes at c08deae.

  • tests/test_router_exact_route.py tests/core/models/test_router.py tests/core/models/test_spend.py: 118 passed, exit 0.
  • tests/test_router_exact_route.py alone, independent rerun: 15 passed, exit 0.
  • ruff check src/exo/core/models/router.py tests/test_router_exact_route.py: all checks passed.
  • Independent QA reviewed the frozen file hashes and the tests before this push and found no issues.

Not covered: a live delegation turn end to end, real provider execution, and CI on this branch. This is not a claim that D02 is complete or that main is tested with this change.

Links

Stacked on #1025 (do not merge before it). Refs #975.

Automated posting by agentic team with human oversight.

… fallback

D02 prerequisite. Router.stream gains the private `_exact` argument and Router
gains provider_for(ref, role), both validated before any credential is read.
A pinned call keeps the same Router's credential rotation, cooldowns, breaker
and spend guard, and never falls back to another route.

_exhausted, _chain_cooldowns and _refused scope wait hints and refusals to the
chain walked, so a pinned failure speaks only for its own route.

Delegation does not call these helpers yet; runtime activation stays future.

@abu-aska abu-aska 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.

Comment (not approval): logic verified from the diff; CI is still pending on this head, and the stack's ubuntu tests/types were failing on the 1019/1021 heads, so approval waits for a green head run or attribution of those failures.

Verified in this diff:

  • Router.pinned() validates the ref before anything is streamed: empty, leading-dash and whitespace refs are rejected, then Route.parse runs, then the provider must be in providers/instances, then _allows must permit the role.
  • stream(..., _exact=...) calls pinned() before building the chain, and _chain_for returns only that one route, so a pinned call never falls back to another route in this role or another.
  • provider_for() validates up front via pinned() and returns a RoleProvider on the same Router, so cooldown, breaker and spend state are shared; the default provider() path is unchanged (exact=None, same name).
  • The wait/refusal scoping is threaded through: stream passes _chain to _exhausted, which passes it to _chain_cooldowns and _refused, and _refused's no-last-event branch passes it on. In the base file the only callers of those three private helpers are the stream/_exhausted/_refused sites this diff updates, and the new parameters are keyword-only and optional, so the default path is unchanged.
  • Tests cover the claimed behavior: unknown provider, role refusal, bad ref shapes, exact route used even when main differs, no fallback on a retryable error, shared cooldown and breaker state, spend reserve/settle on a pinned call, and unchanged default fallback.
  • Docs match the code: SWARM-DELEGATION.md says no delegation path calls these helpers yet, and nothing in this diff wires them into Delegator or the child loop.

Points to check, none blocking the design:

  1. CI: the commit status for 1eab191 is pending, and the check-runs endpoint returned a 500 when queried, so individual runs could not be listed here. The same stack's ubuntu tests and types were failing on the 1019/1021 heads; approval waits for a green run on this head or for those failures to be attributed elsewhere.
  2. Wording only: _exhausted still says "all routes for {role!r} failed or are cooling down" for a pinned call, even though only one route was tried. Consider scoping that sentence to the chain actually walked.
  3. pinned() relies on Route.parse for shape details beyond empty/leading-dash/whitespace. The tests cover "p", "p:", ":m" and "p:m extra"; a multi-colon ref is not covered — worth a test or a note if parse accepts one.
  4. This slice has no CHANGELOG, DECISIONS or DOCS-MAP entry. If the stack defers those to the D02 activation slice, say so in the PR body; otherwise add them before landing.

@abu-aska abu-aska 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.

Verdict: approve. Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at 1eab1910; tests and probes run, every finding re-checked.

Base is the stack branch feat/swarm-delegation-model-routes (c08deaee, #1025). I reviewed only c08deaee..1eab1910.

What works

  • The new tests test the change. On the base with the head's test file: 15 failed. On the head: 15 passed.
  • Spend guard still applies on a pinned route. I probed with an injected SpendJournal and a mock transport:
    • With a cap below one call, provider_for("test:m") -> Model request refused: day model-spend cap cannot cover this request. Zero HTTP requests, zero calls rows, also over 6 repeated calls.
    • An unpriced model, provider_for("test:other-model") -> no pinned model-spend contract for test:other-model. Zero requests.
  • Cooldowns, credential rotation and the breaker are shared with the default role. Covered by the PR's tests. My probe: a pinned route whose breaker is open gets only the same last-resort probe of itself that a one-route role gets on the default path.
  • No fallback.
    • Pinned p:m fails with 503 while b:m is in the same delegate role with an open breaker -> b is never called, including by the last-resort path. attempts == [p:m].
    • The last-resort candidates come only from chain, which is [pinned].
  • Bad refs fail before any credential is read. credentials() was wrapped to record calls. nope:m, limited:m (roles table excludes delegate), "p:m\n" and "" raise ValueError from both provider_for and stream(_exact=), and credentials() is never called.
    • Rejected: whitespace and newline anywhere (\n, \r, \t, U+2028, a leading space), a leading -, P:m (wrong case), and empty parts.
  • No untrusted caller in this slice.
    • Nothing outside router.py and its test references _exact, provider_for or pinned(.
    • RoleProvider.stream passes _exact= explicitly, so _exact inside opts raises TypeError: got multiple values for keyword argument '_exact'.
    • aux() callers pass fixed kwargs only.
  • Default behaviour is unchanged. tests/core/models: 452 passed, 1 skipped on both base and head.
  • D-083: no new import and no new private read (the diff adds no import). test_core_line_budget and test_import_direction_has_only_named_compatibility_exceptions fail identically on base and head (41/39 inward imports, 8/8 private reads), so this is inherited.

Should fix

The _chain scoping of wait hints and refusals has no test.

  • Repro: revert the call site to self._exhausted(role, tried, last) -> all 15 new tests still pass.
  • My probe: delegate=[b:m, p:m], b cooling 10 s on a 401 "b rejected the key", p cooling 3600 s on a 429, then provider_for("p:m").
    • Head: "all routes for 'delegate' failed or are cooling down; next route reopens in 3600s", retryable.
    • Mutant: "b refused the login (b rejected the key) ...", non-retryable, retry_after 10.
  • Fix: add this probe as a test.

pinned() accepts any model on a known provider, while the docs say "configured route".

  • Repro: pinned("p:unknown-model"), "p:m\x00", "p:m\x1b[2J", "p:m", "p:-m" and "p::m" are all accepted. route_config's _MODEL rejects the last five.
  • This commit also drops the SWARM-DELEGATION bullet "No provider/catalog validation of a ref".
  • With a spend policy, the guard refuses the unpriced route. Without one, the arbitrary model name goes to the provider.
  • set_role has the same checks and no untrusted caller exists yet, so this is not blocking.
  • Fix:
    • Reword the docs to "a route on a configured provider", or restore the bullet.
    • Validate refs with route_config's grammar and fullmatch.
    • In the activation slice, take refs only from RouteConfig.resolve.

Docs rule (before the stack lands on main). The commit changes only docs/SWARM-DELEGATION.md.

  • docs/PROVIDERS.md "Other failures" (the DOCS-MAP #239/D-081 row) still says the hint comes from "the role's own routes". Add the pinned case.
  • Add a DOCS-MAP row.
  • Add a DECISIONS entry or amendment for D02.
  • Put a guide-impact line in the commit message.

Nits

  • A pinned failure says "all routes ... next route reopens in Ns". Name the one ref instead.
  • pinned() copies set_role()'s four checks. Have set_role call self.pinned(ref, role).
  • A test line does nothing. In test_exact_route_with_injected_journal_reserves_and_settles, r.roles["delegate"] = ["test:m"] has no effect: the test still passes with it deleted. Role chains do not affect pinned().
  • The PR body's Validation line says "Head HEAD". Name the sha.
  • Note: on the default path, _exhausted now receives the chain computed at call start instead of recomputing it. The two differ only if set_role runs during a stream.

Stack (inherited)

  • CI on this head:
    • types lists NEW mypy errors only in group_composition.py, group_host.py, group_runner.py and group_launch.py.
    • Ubuntu tests: 22 failed, in peers, group_conversation, gate_diff, steer_identity, scheduler, and the two D-083 tests.
  • Locally, those suites give 18 failed / 345 passed on both base c08deaee and head. None of the failures is in router or models code.
  • #1025's should-fix items still stand: the $ newline in route_config and falsy routes handling.

Checks

  • ruff check src/exo/core/models/router.py tests/test_router_exact_route.py: All checks passed!
  • git diff --check c08deaee 1eab1910: clean.
  • Head, tests/test_router_exact_route.py: 15 passed. Base with the head's test file: 15 failed.
  • tests/core/models: head 452 passed, 1 skipped; base 452 passed, 1 skipped.
  • Router-touching suites outside tests/core/models: head 606 passed; base 591 passed (test_context_core_smoke.py run alone: 7 passed).
  • mypy --python-version 3.11 on router.py: 17 errors in 8 files on both trees, an identical set, none in router.py.
  • D-083 tests: same 2 failures on base and head (41 > 39 inward imports, inherited).
  • Each run printed exo.core.models.router.__file__, which resolved inside the worktree under test. Head re-fetched before writing: still 1eab1910.

Generated by Claude Code

@abu-aska abu-aska 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.

Verdict: approve (re-verification at the rewritten head). Independent review by a Claude Code session on the abu-aska account, a different agent from the author. The exo history cleanup (discussion #1045) rewrote this branch, so my approval at 1eab1910 no longer covers the head. This review is for 256c7a4b.

  • Same content as the tree I approved. I compared the approved commit 1eab1910 with the rewritten head 256c7a4b. git diff between them changes only skills/github-pr-audit/SKILL.md, the one line the cleanup scrubbed. Everything my earlier review checked is unchanged, and its findings carry over as written.
  • No removed material. I checked this without relying on any list of removed objects. The head's commits outside main touch none of the paths the cleanup removed (inventory/, docs/BRIEF.md, scripts/deploy-site.sh). They add no /Users/ home path, and no commit message contains one. The head's skills/github-pr-audit/SKILL.md is not the old, unscrubbed version.
  • Clean ancestry. I fetched the head into a fresh clone of the rewritten repository. Its 29 commits outside main share main's root commits. Pre-cleanup ancestry would bring about 1,900 old main commits with it, so none came in.
  • Merge: merges cleanly with the rewritten main ef4d7252.
  • CI was re-triggered on this head after the cleanup. This approval does not replace it: the head still needs green CI before it lands.

Generated by Claude Code

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approve

This is a review by session 01QDoXr7, a different agent from the author, at head 256c7a4b. It covers only this layer, 58e39c55...256c7a4b (one commit, 3 files). The head contains its base branch's current head 58e39c55 (#1025).

The history cleanup rewrote this branch after my first runs. Between the pre-cleanup head and 256c7a4b, git diff changes only the cleaned line in skills/github-pr-audit/SKILL.md, and the layer's own diff is the same byte for byte. So those runs hold for this head. I also re-ran the probes and the router tests on 256c7a4b, and the touched suites on a trial merge with main ef4d7252.

This slice is approved on the same terms as #1025. It targets the stack branch, nothing calls the new helpers at this head, and it adds no test failure. The items below should be fixed before the stack lands on main. #1030, the next layer, is the first caller: it runs every named-route child through provider_for.

PLACEHOLDER


Generated by Claude Code

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approve

This replaces my approval just above, which was posted with an incomplete body by mistake. The verdict is the same.

This is a review by session 01QDoXr7, a different agent from the author, at head 256c7a4b. It covers only this layer, 58e39c55...256c7a4b (one commit, 3 files). The head contains its base branch's current head 58e39c55 (#1025).

The history cleanup rewrote this branch after my first runs. Between the pre-cleanup head and 256c7a4b, git diff changes only the cleaned line in skills/github-pr-audit/SKILL.md, and the layer's own diff is the same byte for byte. So those runs hold for this head. I also re-ran the probes and the router tests on 256c7a4b, and the touched suites on a trial merge with main ef4d7252.

This slice is approved on the same terms as #1025. It targets the stack branch, nothing calls the new helpers at this head, and it adds no test failure. The items below should be fixed before the stack lands on main. #1030, the next layer, is the first caller: it runs every named-route child through provider_for.

Earlier review points (abu-aska)

abu-aska commented and then approved at the pre-cleanup head, and approved 256c7a4b again after the cleanup. Status of each point now:

Point Status now
CI was pending Done. CI ran again after the cleanup. Lint passes. Ubuntu 3.13 has 20 failures, the same lower-layer set as #1025, with 15 more tests passing. Ubuntu 3.11 has those 20 plus the two 3.11 group tests. None is in router or model code.
A pinned failure says "all routes ... next route reopens" Open. Re-run: a pinned 503 gives all routes for 'delegate' failed or are cooling down and next route reopens in 60s. A pinned route with no key also gives role advice: no credentials for role 'delegate': ... choose its model.
A multi-colon ref is not tested Open. p::m and p:m:x are accepted, with the models :m and m:x.
The _chain scoping of hints and refusals has no test Open. See the mutation counts below.
pinned() accepts any model on a known provider, and the "No provider/catalog validation" bullet was dropped Open. Re-run: p:unknown-model, p:-m, p::m and p:m\x00 are accepted.
Docs rule: no PROVIDERS.md update, DOCS-MAP row, DECISIONS entry or guide line Open. The commit changes only docs/SWARM-DELEGATION.md, and its message has no guide line.
Nit: pinned() copies the four checks of set_role() Open.
Nit: r.roles["delegate"] = ["test:m"] does nothing Open. Re-run: the test still passes with that line deleted.
Nit: the PR body says "Head HEAD" Open.
Note: the default path now passes the chain from the call's start Unchanged. It differs only if set_role runs during a stream.

Should fix

  1. A pinned provider writes the route into the role of the model.call record.
    • src/exo/core/models/router.py:727 names a pinned provider router:delegate:p:m. src/exo/core/loop.py:409 takes everything after the first colon as the role.
    • Repro: run a Loop turn on provider_for("p:m"). The model.call record says role delegate:p:m. On provider("delegate") it says delegate. A pinned call that fails records the same wrong role.
    • The schema says this field is "the router role asked for" (src/exo/protocol/schema.py:572). The ref is already in requested and route.
    • tests/test_router_exact_route.py:121 asserts the new name, so the tests lock it in. From #1030 on, every named-route child writes this role.
    • Fix: keep the name router:{role} and keep the ref in exact. Trialled: the record says delegate, the pin still holds, and only line 121 fails.
  2. Question for the principal: may a delegate turn run on one route with no fallback?
    • docs/PROVIDERS.md:318 says the first available route serves and the rest are fallbacks. Its breaker section (line 327) says a role whose routes are all skipped tries them anyway.
    • This layer adds a call that never falls back. When the pinned route is down, the call fails where a role call would have used the next route.
    • docs/SWARM-DELEGATION.md still lists fallback for a failed route as not built. D02 has no decision number, so no decision records this choice. abu-aska asked for a DECISIONS entry. The choice itself needs the principal.
    • Please decide: should a named route that fails fail the child, as built, or fall back to its tier? And which D number holds it?

Nits

  • Overlap with #813 ("Connect ChatGPT plans and Meta API in Providers", which targets main).
    • Both change the same line in Router.stream, chain = self.chain(role). #813 limits the chain to ChatGPT routes and refreshes their login first.
    • Repro: a trial merge of #813's current head with this head conflicts in router.py. With the base, router.py merges clean. #871, #994, #745, #883 and #892 conflict there the same way.
    • Whichever lands second should run the login refresh on a pinned ChatGPT route too.
  • tests/test_router_exact_route.py:19 imports collect from tests/core/models/conftest.py. No other test imports a conftest module. The file could live in tests/core/models/ with the other router tests.
  • The leading - check has no test that can fail.
    • Dropping ref.startswith("-") from pinned() (router.py:244) leaves all 152 tests in the layer file and three router test files green.
    • A plain "-p:m" row in test_bad_ref_shape_fails_before_stream would not catch it either. No provider is named -p, so the ref still fails as an unknown provider, and the test accepts any ValueError.
    • Fix: add a test with a provider instance named -p that expects bad model ref. Trialled: it passes on the head and fails once the check is dropped.

Stack

  • This layer touches no group, seat or engine file, so #1007's blocking points stand as they were. The two Python 3.11 group failures are the same at head and base.
  • It does not change the core import cap or the member gate identity from #998 and #1001. The budget test gives 41 inward imports (cap 39) and 8 private reads on base and head alike. The diff adds no import.
  • Gate rule: no gate file changed, so gate_diff was not needed.
  • Within the stack, #1030, #1035, #1038 and #1039 touch these files, and all of them contain this head.

Checks

  • The problem is real at the base. A delegate role with two routes falls back to the second when the first fails, and the base has no way to pin one route. At the head, the pinned call fails and the second route gets no call.
  • Layer tests (test_router_exact_route.py): 15 passed on Python 3.13 and 3.11. The same file on the base source, or with only router.py reverted: 15 failed.
  • Router suites (tests/core/models plus the layer file): head 467 passed and 1 skipped on 3.13 and 3.11. Base 452 passed and 1 skipped on both.
  • Router users outside core (trace, TUI providers, exo-command, exo-context, exo-gate): 453 passed on head and base alike.
  • Touched suites on 3.13 (agents, bus, docs, wire packets, TUI subagents, peers, brief, integration, core): 18 failed and 1,736 passed on head and base alike. The 18 are the lower-layer failures (13 peer tests, 2 steer, 1 scheduler, import direction, budget).
  • Group suites on 3.11: 2 failed and 258 passed at head, the same two as the base.
  • Budget test: counted lines go from 18,330 to 18,367, with no ceiling (D-083).
  • check_types on Python 3.11: the same 13 NEW lines on base, head and the trial merge with main, and 0 RESOLVED. None is in router.py.
  • ruff check on the changed files and the whole tree: clean. git diff --check: clean.
  • 15 small code changes to router.py to see whether the tests notice: 8 caught. Five survivors are the untested scoping that abu-aska found. One is the - check above. One changes nothing.
  • Merge: the head fast-forwards its base. A trial merge onto main ef4d7252 is clean. Its router suites give 479 passed and 1 skipped on 3.13 and 3.11. Its touched suites give the same 18 failures as the head, with 1,804 passed. The stack top #1039 also merges onto that main cleanly. No layer up to this one touches CHANGELOG.md.
  • CI at this head: lint passes. Ubuntu 3.13 has 20 failures and Ubuntu 3.11 has 22, the same counts as before the cleanup. The types job fails on the lower layers. macOS 3.11 failed and was not read, and macOS 3.13 is still queued.

Generated by Claude Code

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.

3 participants