Skip to content

[AI-4351] A priority list or fallback no longer reports a router failure as the caller's mistake - #2713

Open
kanat wants to merge 5 commits into
mainfrom
kanat/ai-4351-priority-list-error-class
Open

kanat wants to merge 5 commits into
mainfrom
kanat/ai-4351-priority-list-error-class

Conversation

@kanat

@kanat kanat commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

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

llm.providers = [custom/<key fails to open>, custom/not-there]

resolveChain
  entry 1 -> internal failure (ErrCustomModelKey)
  entry 2 -> refused (ErrRequest)
        |
        v  Join(...)                       before: errors.Join(...)
  failedBeside{ said: both texts,          class: refused, so the caller
                failed: entry 1 only }     is sent both texts
        |
        v
  not a refusal -> "something went wrong"; the cause stays in the log

per-turn LLM fallback, search fallback
  own model fails --> fallback walks the other candidates
                        candidate refused        (ErrRequest)
                        candidate not allowed    (ErrModelNotAllowed)
                        candidate failed         (anything else)
                      errors.Join( routing.Join(candidates...),
                                   "no fallback provider available" )
                                   ^ not a candidate's error, kept out of the class
  routing.Join(own model's error, fallback's error)
        |
        v
  every one refused -> the refusal texts; any one failed -> "something went wrong"
Case Answer before Answer now Test
Stream start, key fails to open + unknown model refusal text quoting the failed entry something went wrong TestStreamsSuite/TestAPriorityListWhoseModelKeyFailsToOpenAnswersSomethingWentWrong
Session create from an agent config with the same list 400 quoting the failed entry 500 something went wrong TestSessionCreateSuite/TestAPriorityListWhoseModelKeyFailsToOpenAnswersSomethingWentWrong
Every entry refused (control, same answer on the base) refusal text naming each entry unchanged ...TestAPriorityListOfModelsTheCustomerDoesNotHoldIsRefusedWithTheirNames (stream and session create)
Class of the error for each mix of failed and refused entries refused whenever one entry was refused only when all were TestRoutingSuite/TestAPriorityListKeepsTheClassOfEachEntrysError
An empty entry, or custom/ on a router with no customer models, beside an unknown one 400 naming each entry unchanged (both are now marked as refusals) TestRoutingSuite/TestAPriorityListEntryTheCallerGotWrongIsRefusedBesideAnother
A turn fails, and its fallback is a model the policy does not allow 400 quoting the failed turn something went wrong TestLLMRouterSuite/TestATurnThatFailedIsNotTheCallersMistakeForAFallbackThePolicyDoesNotAllow, TestFallbackAnswerSuite/TestATurnWhoseFallbackThePolicyDoesNotAllowAnswersSomethingWentWrong
A turn two models refuse and a third fails 400 quoting the third something went wrong TestLLMRouterSuite/TestATurnAFallbackFailedOnIsNotTheCallersMistakeForTheOthersRefusingIt
A turn every model refuses (control) 400 with the refusals unchanged TestLLMRouterSuite/TestATurnEveryModelRefusedIsRefusedWithTheirTexts
The same three cases for a search as for a turn as for a turn TestSearchRouterSuite/TestASearch..., TestFallbackAnswerSuite/TestASearch...

routing.Join now treats a model the policy does not allow as a refusal, like ErrRequest. The fallback test TestAFallbackNeverReachesAModelThePolicyDoesNotAllow still 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 in Walk (router.go:911, :916, :918) already use Join, 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:

Mutation Fails
Join(refusals...) back to errors.Join(refusals...) at routing/router.go:1100 the three "failed beside refused" priority-list tests
resolveEntry no longer marks an empty entry as refused TestAPriorityListEntryTheCallerGotWrongIsRefusedBesideAnother (empty entry)
resolveEntry no longer marks custom/ on a router without customer models same test (custom entry)
routing.Join counts only ErrRequest as a refusal both ...FallbackThePolicyDoesNotAllow router tests and both TestFallbackAnswerSuite policy tests
LLM fallback back to a plain errors.Join TestATurnAFallbackFailedOnIsNotTheCallersMistakeForTheOthersRefusingIt
LLM fallback puts "no fallback provider available" inside routing.Join TestATurnEveryModelRefusedIsRefusedWithTheirTexts
Search fallback back to a plain errors.Join TestASearchAFallbackFailedIsNotTheCallersMistakeForTheOthersRefusingIt
Search fallback puts the trailing error inside routing.Join TestASearchEveryModelRefusedIsRefusedWithTheirTexts, TestASearchEveryModelRefusedAnswersTheirTexts

The 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

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 kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment on lines +9 to +10
// heldModels is a customer whose model "held" is fine, whose "unreadable" fails on the
// deployment's side, and who has no other.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Nit] T1.2 packs three cases into one sentence, and "held" reads as a verb as well as a model name. Rewrite:

Suggested change
// 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[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.Join back to errors.Join at router.go:1100 makes 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.

kanat and others added 4 commits November 29, 2026 12:56
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 kanat changed the title [AI-4351] A priority list keeps the class of each entry's error [AI-4351] A priority list or fallback no longer reports a router failure as the caller's mistake Nov 29, 2026

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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. ErrModelNotAllowed only comes from allowed(), which runs before candidates start, so it never reaches this join.
  • routing/router.go resolveChain: no change. Its entries never pass through allowed().
  • llmrouter/session.go:673 and searchrouter/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:177 and session/logs.go:236 for 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.

@kanat
kanat marked this pull request as ready for review November 29, 2026 18:25

This branch has not been deployed

No deployments
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