A routing group's first member answering ModelScope's 400 "Model id :
deepseek-ai/DeepSeek-V4.1-Flash , has no provider supported" ended the
group request: the words matched none of the refusal classes that make
a 400 retryable, so the client got the 400 and its own retries landed
on the same dead seat — the reporter watched 28 in a row, the later
members never asked.
What changed: unservedWords takes the vendor wordings that say the
model is served nowhere on this member — ModelScope's "has no provider
supported" (the report's usage.jsonl), and Azure OpenAI's for a
deployment its resource has none of, code DeploymentNotFound ("The API
deployment for this resource does not exist"; Microsoft Q&A, Stack
Overflow — its 404 fails over by status already, the wording covers the
400s a relay passes on). An unserved refusal keeps the poison pill's
line: a plain bad request ("Invalid parameter", "field required")
still ends the route, as it would fail on every member, and
shapeRefused still excludes these words — the seat rests on its
model's own key (restAfterMarked's unserved branch, the #1235
mechanism), so the key's other models stay live and the group's next
request passes the dead seat.
Run: go test ./internal/gateway/ (TestGroupFailsOverAModelWithNoProvider
red on upstream/main, green here; the family and the plain-400 guards
green); -race targeted; gofmt; vet darwin/linux/windows; builds
darwin, linux and windows (-tags nogui).
Reviewed and landed as one batch of 12 commits (gua's #4593, #3269,
#3881, #2887, #3289, #2718, #2855, Edward4226's #2718 key-path
sibling, and four review follow-ups). Run for the batch, whose last
commit's tree is 5d58a75f3:
- Full suite before the rebase (base d307aa648, wsl-run magpie-desktop,
go test -tags nogui -count=1 -timeout 45m ./...): 81 packages ok. Reds,
all with issues and none in code this batch touches: internal/agent
TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir
(#4033, #3548, #3141); gateway TestUnroutedHeldReportSaved (#4300);
gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestColdTurnsTaken (#4510); provider
TestClaudeAccountServesModelsListedSinceItsFetch (#3174). Run alone at
origin/main 573b21f4b, TestGrokInstalled, TestOmpDetectedWithPiDir
and TestSettingsSaveKeepsWhatItDoesNotSend are red there too. The
other four pass there alone.
- After the rebase onto origin/main 573b21f4b, at this tree:
internal/usage, update, gateway and provider ok. In internal/agent,
the #4033/#3141 install-detection reds plus TestCopilotFolderFrom-
AnIDEPluginIsNotTheCLI and TestZedAppPath. Those two are flaky the
same way at origin/main (-count=10 alone: 4 and 5 of 10 red) and are
already listed in #4033. The #3269 tests (TestCopilotLauncher*) pass
5 of 5.
- Rebased onto origin/main ef63ef4a2. The #2855 commit met 0b9727ec9
(#2974) in responses.go: the streamed item's done now takes both, the
upstream's own id (thinkUp) and the made-over item; and in
gateway-routing.md main's paragraph is kept with #2855's clause. That
matches gua's latest head (range-diff: context only). At tree d7c76c6fa:
internal/gateway, provider, usage, redact and update ok; vet
GOOS=linux -tags nogui ./internal/..., darwin and GOOS=windows for
gateway and provider.
- Rebased last onto origin/main d8f7d089f (5 commits: internal/agent
and GUI files only). At tree 0d4bfd8c8, the pushed one: internal/agent's
TestCopilotLauncher*, TestClaude*, TestOwn* and TestVSCode* ok, -count=3;
TestCopilotFolderFromAnIDEPluginIsNotTheCLI red once there, as it is at
main (#4033). Vet of internal/agent: darwin, linux and windows.
- gofmt -l clean. On mote: go vet darwin, GOOS=linux -tags nogui and
GOOS=windows.
- Broken by hand, each turning its guard red: the lift gate
(TestReadingKeepsARefusalsRest, TestAutoVisionKeepsOffARefusedAccount);
the named-time condition (TestNamedQuotaTimeReplacesAGuess); the
filter-chain hop (WholeReply/glm-5.3-flash); Edward's aAt
(TestKeyAllowanceElapsedResetStartsAgain); and the old
magpieMadeReasoning, which panics in TestMadeReasoningSaysItsTextOnce/
no_summary. Every new test of gua's is red at base d307aa648.
Not tried: real OpenAI, DeepSeek, GLM or ChatGPT accounts; a real VS Code
1.144 install on Windows; a GUI run (no GUI files are touched).
Generated-by: GLM-5.3-Flash (ZCode)
82 lines
3.8 KiB
Go
82 lines
3.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// modelscopeNoProvider400 is ModelScope's answer to a model id none of its
|
|
// instances serves, as the reporter of #2887's usage.jsonl has it: the
|
|
// request itself is fine, and a member that serves the model may answer it.
|
|
const modelscopeNoProvider400 = `{"error":{"message":"Model id : deepseek-ai/DeepSeek-V4.1-Flash , has no provider supported"}}`
|
|
|
|
// A member whose vendor serves the model nowhere hands the request to the
|
|
// group's next one, and the model rests on that key alone, as any unserved
|
|
// model's does — so the client's own retry, landing on the group again, is
|
|
// no longer sent to the dead seat first (#2887: 28 requests in a row hit
|
|
// the first member and the later ones were never asked).
|
|
func TestGroupFailsOverAModelWithNoProvider(t *testing.T) {
|
|
fresh(t)
|
|
a := &scripted{replies: []reply{{400, "", modelscopeNoProvider400}}}
|
|
b := &scripted{replies: []reply{{200, "", chatOK}}}
|
|
scriptedOn(t, "ms", provider.Chat, a)
|
|
scriptedOn(t, "b", provider.Chat, b)
|
|
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"ms/m", "b/m"}, Routing: provider.Ordered}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := New()
|
|
code, body := postAs(t, s, "", `{"model":"group/g","messages":[{"role":"user","content":"hi"}]}`)
|
|
if code != 200 || !strings.Contains(body, "hello") || a.n != 1 || b.n != 1 {
|
|
t.Fatalf("%d %s (ms %d, b %d)", code, body, a.n, b.n)
|
|
}
|
|
r := s.trace.routes[len(s.trace.routes)-1]
|
|
if len(r.Tries) != 2 || r.Tries[0].Status != 400 || r.Tries[0].Fail != failOther {
|
|
t.Fatalf("tries %+v", r.Tries)
|
|
}
|
|
if rest := r.Tries[0].Rest; rest == nil || rest.Key != "ms/m" {
|
|
t.Fatalf("the model alone was to rest: %+v", r.Tries[0].Rest)
|
|
}
|
|
|
|
// the rested seat is passed over: the next group request, as the
|
|
// client's retry is, is answered by the second member alone
|
|
code, body = postAs(t, s, "", `{"model":"group/g","messages":[{"role":"user","content":"hi"}]}`)
|
|
if code != 200 || !strings.Contains(body, "hello") || a.n != 1 || b.n != 2 {
|
|
t.Fatalf("next: %d %s (ms %d, b %d)", code, body, a.n, b.n)
|
|
}
|
|
|
|
for _, x := range []struct {
|
|
status int
|
|
body string
|
|
want bool
|
|
}{
|
|
{400, modelscopeNoProvider400, true},
|
|
// as magpie tells it on, with the provider's name before, and
|
|
// ModelScope's own invalid_request_error type around it
|
|
{400, `ModelScope: ` + modelscopeNoProvider400, true},
|
|
{400, `{"error":{"message":"Model id : deepseek-ai/DeepSeek-V4.1-Flash , has no provider supported","type":"invalid_request_error"}}`, true},
|
|
// Azure OpenAI's error for a deployment its resource has none of
|
|
// (DeploymentNotFound, "The API deployment for this resource does
|
|
// not exist"): a 404 fails over by its status already, a relay's
|
|
// 400 says the words
|
|
{400, `{"error":{"code":"DeploymentNotFound","message":"The API deployment for this resource does not exist. If you created the deployment recently, please wait a few minutes and try again."}}`, true},
|
|
{400, `{"error":{"message":"Deployment not found for ModelName: gpt-4o"}}`, true},
|
|
// model_not_found fails over as it did
|
|
{400, `{"error":{"message":"The model gpt-x does not exist","code":"model_not_found"}}`, true},
|
|
// a request at fault stays the agent's: no member is asked after
|
|
{400, `{"error":{"message":"Invalid parameter: messages.3.content"}}`, false},
|
|
{400, `{"error":{"message":"messages: field required"}}`, false},
|
|
} {
|
|
if got := retryable(x.status, []byte(x.body)); got != x.want {
|
|
t.Errorf("retryable(%d, %s) = %v", x.status, x.body, got)
|
|
}
|
|
if got := shapeRefused(x.status, []byte(x.body)); got {
|
|
t.Errorf("shapeRefused(%d, %s) = %v; an unserved model rests, it is not a shape", x.status, x.body, got)
|
|
}
|
|
}
|
|
if !modelRefused(400, []byte(modelscopeNoProvider400)) {
|
|
t.Errorf("modelRefused false: the model wouldn't rest alone on its key")
|
|
}
|
|
}
|