Repository navigation
[AI-4351] A priority list or fallback no longer reports a router failure as the caller's mistake - #2713
[AI-4351] A priority list or fallback no longer reports a router failure as the caller's mistake#2713kanat wants to merge 5 commits into
Conversation
A priority list joined the error of each entry with errors.Join, so one entry refused as the caller's mistake made every other entry's error the caller's as well, internal failures included. It joins with routing.Join now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Text review: 2 unclear of 2
Two Nit findings, no Should fix. Each rewrite below states the same facts as the original.
[Nit] T1.1 PR title and opening (pr). The opening has four sentences, over the three-sentence limit, and "class" is never explained.
Title, rewrite:
[AI-4351] A priority list no longer reports a router failure as the caller's mistake
Opening, rewrite (two sentences, replaces the four):
When one entry of a priority list was refused for the caller's mistake, the router answered every other entry's failure as the caller's mistake too, including a failure on the router's side, such as a custom model whose key does not open. This PR keeps each entry's own kind of failure: a refused entry still gets its refusal, and a router-side failure answers "something went wrong" with the cause only in the log.
Move the routing.Join detail under the chart.
[Nit] T1.2 is an inline comment on chain_class_test.go.
| // heldModels is a customer whose model "held" is fine, whose "unreadable" fails on the | ||
| // deployment's side, and who has no other. |
There was a problem hiding this comment.
[Nit] T1.2 packs three cases into one sentence, and "held" reads as a verb as well as a model name. Rewrite:
| // heldModels is a customer whose model "held" is fine, whose "unreadable" fails on the | |
| // deployment's side, and who has no other. | |
| // heldModels is a customer with two models: "held" works, and "unreadable" fails because its lookup breaks on the deployment's side. Every other name is refused. |
There was a problem hiding this comment.
Fixed in ff5bb04: the comment now reads "heldModels is a customer with two models: "held" works, and "unreadable" fails because its lookup breaks on the deployment's side. Every other name is refused." It is a comment, so no test covers it.
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Reviewed 83a0728 merged onto main d734ca0 (the merge is a no-op). CI: the PR is a draft, so go and integration are skipped; CI runs at gh pr ready. Touched suites pass locally (routing, llmrouter, ttsrouter, sttrouter, and the four new api tests on a test DB).
No Blocker and no Should fix. Mutations at router.go:1100: Join back to errors.Join, Join over the first refusal only, and a plain error with no wrap. All three are killed by the new tests. The two "every entry refused" controls pass on the base and on the head. In Walk, router.go:911, :916 and :918 are sound, and so is sttrouter/router.go:168.
Two Questions for tickets, neither blocks this PR:
[Question] R1.1 routing/router.go:1000 and :1044. An empty entry ("target is required") and a custom/ entry on a router with no customer models (only the llm router has them) are the caller's mistake but are not marked Refused. Beside a refused entry in a list they were a 400 with text on the base and are a 500 "something went wrong" now. Alone they were already a 500. Mark both Refused.
[Question] R1.2 llmrouter/router.go:245 (same shape at :200). The per-turn fallback joins each candidate's error with a plain errors.Join. With a list of three or more where the session's own model and one fallback refuse the turn and a later fallback fails on its own account, errors.Is(err, ErrRequest) is true, so the text of the failed candidate reaches the caller in a 400. Classify those errors with routing.Join and keep the trailing plain "no fallback provider available" error out of the class, or the all-refused case would become a failure. This is the same class as AI-4351, outside this PR's brief.
Details and probes are in the reviewer's notes.
kanat
left a comment
There was a problem hiding this comment.
[security R1] VERDICT: GO
I found no security problems in this change.
- A priority list that holds an entry the router failed to resolve on its own side now gets a 500 or a "something went wrong" frame. Before, it got a 400 with that entry's error text. A list where the caller made every mistake still gets the refusal text, and that text only names what the caller sent.
- Swapping
routing.Joinback toerrors.Joinatrouter.go:1100makes three of the new tests fail: the routing table, the stream and session create. The two control tests pass both ways. - I checked the other joins this path reaches: the walk's refusals and failures, the LLM hedge, the STT live check, the close reason and the stored turn failure. They keep internal text out of what the caller gets for the cases this PR touches.
An empty entry in a priority list, or a custom/ entry on a router that holds no models of a customer's own, is the caller's to correct. Both are now marked as refusals, so a list where every entry is refused still answers with each entry's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a model fails a turn or a search and the router falls back, each candidate's failure now keeps its kind. A candidate the customer's policies do not allow counts as a refusal, like a candidate that refused the request. Once any candidate failed on its own account, the caller is told only that something went wrong; when every candidate refused, the caller gets the refusals' texts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Delta round 2, head 1e13e25 on main d734ca0. Every earlier finding is fixed and no new finding was made.
| Finding | Status | Check |
|---|---|---|
R1.1 empty entry, custom/ without customer models |
fixed | Dropping either half of the condition fails TestAPriorityListEntryTheCallerGotWrongIsRefusedBesideAnother. Widening it to every custom/ entry fails TestAPriorityListKeepsTheClassOfEachEntrysError. |
| R1.2 per-turn and search fallback joins | fixed | A plain errors.Join in either fallback fails its "a fallback failed" test. Putting the sentinel inside routing.Join fails the "every model refused" test, in both routers and in FallbackAnswerSuite. |
| S1.1 | fixed | Join ignoring ErrModelNotAllowed fails the router tests for both fallbacks and both FallbackAnswerSuite tests. |
| T1.1 to T1.3 | fixed | Title and the two comments read back. |
The ticket's mutation (resolveChain back to errors.Join) fails the routing test and the Streams and SessionCreate tests. Run on d734ca0, the new class tests fail and the all-refused controls pass.
Callers of routing.Join, before and after for a model the policy does not allow:
routing/router.go:911: no change.ErrModelNotAllowedonly comes fromallowed(), which runs before candidates start, so it never reaches this join.routing/router.goresolveChain: no change. Its entries never pass throughallowed().llmrouter/session.go:673andsearchrouter/session.go:56: a turn or search failed at its vendor and the fallback was not allowed. Before, the whole text including the vendor's URL, status and body was answered as a 400. Now it is a 500 "something went wrong" and the cause stays in the log. This is the intended change, and the PR table lists it.- The two fallback closures (
llmrouter/router.go:247,searchrouter/router.go:159): the same, with the "no fallback provider available" line kept out of the class. - The fault class shown in
session/metrics.go:177andsession/logs.go:236for that failure is now the vendor's, not the customer's config.
When only refusals and not-allowed models are joined, the answer is their texts alone. A probe of Join over each pair confirms it: not-allowed with refused gives policy text plus the refusal text, and not-allowed with a vendor failure is not a refusal, so its text is never answered. The all-refused answers (priority list, LLM fallback, search fallback) are the same as on the base.
Suites on the head: unit routing, llmrouter, searchrouter and api, plus go vet with and without -tags integration, pass. Integration routing, llmrouter, searchrouter and api (Streams, SessionCreate, Search, FallbackAnswer) pass. Of 11 mutants, none survived. The PR is a draft, so CI skips go and integration.
When a request tried several models, through a priority list or through the fallback after a failed turn or search, and one of them refused the request, the router answered every other model's failure as the caller's mistake too. This PR keeps each model's failure its own kind, and counts a model the customer's policies do not allow as a refusal. The caller now gets the refusal texts when every model refused, and "something went wrong" when any model failed for another reason, with the cause only in the log.
How it works
something went wrongTestStreamsSuite/TestAPriorityListWhoseModelKeyFailsToOpenAnswersSomethingWentWrongsomething went wrongTestSessionCreateSuite/TestAPriorityListWhoseModelKeyFailsToOpenAnswersSomethingWentWrong...TestAPriorityListOfModelsTheCustomerDoesNotHoldIsRefusedWithTheirNames(stream and session create)TestRoutingSuite/TestAPriorityListKeepsTheClassOfEachEntrysErrorcustom/on a router with no customer models, beside an unknown oneTestRoutingSuite/TestAPriorityListEntryTheCallerGotWrongIsRefusedBesideAnothersomething went wrongTestLLMRouterSuite/TestATurnThatFailedIsNotTheCallersMistakeForAFallbackThePolicyDoesNotAllow,TestFallbackAnswerSuite/TestATurnWhoseFallbackThePolicyDoesNotAllowAnswersSomethingWentWrongsomething went wrongTestLLMRouterSuite/TestATurnAFallbackFailedOnIsNotTheCallersMistakeForTheOthersRefusingItTestLLMRouterSuite/TestATurnEveryModelRefusedIsRefusedWithTheirTextsTestSearchRouterSuite/TestASearch...,TestFallbackAnswerSuite/TestASearch...routing.Joinnow treats a model the policy does not allow as a refusal, likeErrRequest. The fallback testTestAFallbackNeverReachesAModelThePolicyDoesNotAllowstill checks that the model is never asked; it now reads the policy's text in the error rather than its class, since the turn failed at its own model first. The joins inWalk(router.go:911,:916,:918) already useJoin, or join errors that are all refusals or all failures. The hedge's join (llmrouter/router.go:200) is unchanged: its error is never answered to a caller.Ticket: https://linear.app/stream/issue/AI-4351
Mutations and commands
Each mutation was applied alone and restored from the commit:
Join(refusals...)back toerrors.Join(refusals...)atrouting/router.go:1100resolveEntryno longer marks an empty entry as refusedTestAPriorityListEntryTheCallerGotWrongIsRefusedBesideAnother(empty entry)resolveEntryno longer markscustom/on a router without customer modelsrouting.Joincounts onlyErrRequestas a refusal...FallbackThePolicyDoesNotAllowrouter tests and bothTestFallbackAnswerSuitepolicy testserrors.JoinTestATurnAFallbackFailedOnIsNotTheCallersMistakeForTheOthersRefusingItrouting.JoinTestATurnEveryModelRefusedIsRefusedWithTheirTextserrors.JoinTestASearchAFallbackFailedIsNotTheCallersMistakeForTheOthersRefusingItrouting.JoinTestASearchEveryModelRefusedIsRefusedWithTheirTexts,TestASearchEveryModelRefusedAnswersTheirTextsThe new "failed" tests fail on the base too; the controls pass on the base and on the head.
Commands, in
acceleration/:go test ./internal/routing/... ./internal/llmrouter/ ./internal/searchrouter/ ./internal/api/go test -tags integration -p 1 ./internal/routing/, then./internal/llmrouter/, then./internal/searchrouter/go test -tags integration -p 1 ./internal/api/ -run 'TestStreamsSuite|TestSessionCreateSuite|TestSearchSuite|TestFallbackAnswerSuite'gofmt -l,go vet ./...,go vet -tags integration ./...🤖 Generated with Claude Code