gateway: the Qoder plugin's nameless tool call rests nobody (plugins#579)
Qoder plugin 0.2.51 answers 502 "the model's native tool call has no name; it is not sent on as a tool" when qfmodel twice began a native tool call without a name before anything of the reply was sent. That is the model's glitch, not the account's, but failure() read it as failOther and restAfterMarked rested the account for fallbackCooldown (a minute), so the user's next turn skipped it. cutWords now also matches that sentence, so the 502 takes the failCut lane the plugins' cut-short error already has (#2873): asked again once where it stood (cutReasks), then the next account or group member, with no rest and no failure counted. The match is the plugin's whole clause, not "has no name", so other bodies keep their lanes. Siblings: failCut is decided in failure() alone, and read by restAfterMarked (no rest) and the serve loop's retry (gateway.go); both take the new words through it. No other plugin in magpie-community/ plugins says these words (grep of packages/*.mjs at 5403c21). Run (on mote, atbbdd9eb55+ this change; rebased onto2640ac0f0, which touches internal/provider/migrate_qoder.go only): - go test -count=1 -timeout 45m ./internal/gateway: ok (764s) - gofmt -l internal/gateway: clean - go vet ./internal/gateway for darwin, GOOS=linux, GOOS=windows: ok Broken by hand: with routing.go from origin/main, TestPluginNamelessCallFailsOverNotRested fails (try 0 Fail "other" with a Rest set) and TestPluginNamelessWords fails for the 502 body and the stream error event; TestPluginOrdinary502StillRests passes on both. Not tried: a real qoder-cn account that hits the glitch; the tests use a scripted upstream with the plugin's errorResponse bytes, not the plugin host.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// The Qoder plugin's 502 for a reply whose only answer was a native tool
|
||||
// call the model never named, as its errorResponse sends it once its own
|
||||
// second ask came back the same (magpie-community/plugins#579, packages/
|
||||
// qoder's NAMELESS): qfmodel's glitch, which the next ask mostly isn't.
|
||||
const namelessSaid = `{"error":{"message":"the model's native tool call has no name; it is not sent on as a tool","type":"qoder_error","code":502}}`
|
||||
|
||||
// A nameless call fails over as a cut does, and nobody rests: the account
|
||||
// did nothing a minute of backoff would mend (plugins#579: it was rested
|
||||
// for fallbackCooldown, and the user's next turn skipped it).
|
||||
func TestPluginNamelessCallFailsOverNotRested(t *testing.T) {
|
||||
fresh(t)
|
||||
a := &scripted{replies: []reply{{502, "application/json", namelessSaid}}}
|
||||
b := &scripted{replies: []reply{{200, "text/event-stream", chatStreamSaid("from b")}}}
|
||||
scriptedOn(t, "a", provider.Chat, a)
|
||||
scriptedOn(t, "b", provider.Chat, b)
|
||||
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"a/m", "b/m"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New()
|
||||
code, body := postAs(t, s, "", `{"model":"group/g","stream":true,"messages":[{"role":"user","content":"hi"}]}`)
|
||||
if code != 200 || !strings.Contains(body, "from b") || b.n != 1 {
|
||||
t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
r := s.trace.routes[len(s.trace.routes)-1]
|
||||
for i, try := range r.Tries[:len(r.Tries)-1] {
|
||||
if try.Fail != failCut || try.Rest != nil {
|
||||
t.Fatalf("try %d: %+v", i, try)
|
||||
}
|
||||
}
|
||||
if s.resting("a") || s.resting("b") || len(routed.failures) != 0 {
|
||||
t.Fatalf("a nameless call is nobody's fault: a resting %v, b %v, failures %v", s.resting("a"), s.resting("b"), routed.failures)
|
||||
}
|
||||
|
||||
// the next request asks a first again
|
||||
a.replies = []reply{{200, "text/event-stream", chatStreamSaid("from a")}}
|
||||
code, body = postAs(t, s, "", `{"model":"group/g","stream":true,"messages":[{"role":"user","content":"hi"}]}`)
|
||||
if code != 200 || !strings.Contains(body, "from a") || b.n != 1 {
|
||||
t.Fatalf("next request: %d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
}
|
||||
|
||||
// A 502 that is not the plugin's nameless call still rests the account
|
||||
// as before.
|
||||
func TestPluginOrdinary502StillRests(t *testing.T) {
|
||||
fresh(t)
|
||||
a := &scripted{replies: []reply{{502, "application/json", `{"error":{"message":"upstream connect error","type":"qoder_error","code":502}}`}}}
|
||||
b := &scripted{replies: []reply{{200, "text/event-stream", chatStreamSaid("from b")}}}
|
||||
scriptedOn(t, "a", provider.Chat, a)
|
||||
scriptedOn(t, "b", provider.Chat, b)
|
||||
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"a/m", "b/m"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New()
|
||||
code, body := postAs(t, s, "", `{"model":"group/g","stream":true,"messages":[{"role":"user","content":"hi"}]}`)
|
||||
if code != 200 || !strings.Contains(body, "from b") {
|
||||
t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
if !s.resting("a") || s.resting("b") {
|
||||
t.Fatalf("an ordinary 502 rests its account: a %v, b %v", s.resting("a"), s.resting("b"))
|
||||
}
|
||||
}
|
||||
|
||||
// The words alone decide it, in a body or a stream's error event, and
|
||||
// words that are near them are not them.
|
||||
func TestPluginNamelessWords(t *testing.T) {
|
||||
for _, x := range []struct {
|
||||
status int
|
||||
body string
|
||||
want string
|
||||
}{
|
||||
{502, namelessSaid, failCut},
|
||||
{200, `data: {"error":{"message":"the model's native tool call has no name; it is not sent on as a tool","code":502}}`, failCut},
|
||||
{502, `{"error":{"message":"tool call has no name"}}`, failOther},
|
||||
{502, `{"error":{"message":"the tool has no name"}}`, failOther},
|
||||
} {
|
||||
if got := failure(x.status, []byte(x.body)); got != x.want {
|
||||
t.Errorf("failure(%d, %s) = %s, want %s", x.status, x.body, got, x.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,8 +355,12 @@ var (
|
||||
// stopped before the call was whole, and the plugin ends the turn as a
|
||||
// failure "the gateway can retry or fail over" — its words, shared by
|
||||
// the plugins that read text-form calls (magpie-community/plugins#38,
|
||||
// packages/trae and packages/qoder's CUT_SHORT; #2873)
|
||||
cutWords = regexp.MustCompile(`(?i)tool call, written as text, was cut short`)
|
||||
// packages/trae and packages/qoder's CUT_SHORT; #2873). The Qoder
|
||||
// plugin's NAMELESS is one too: qfmodel began a native tool call and
|
||||
// never named it, twice, before anything of the reply was given — the
|
||||
// model's glitch, not the account's, and asked again it mostly answers
|
||||
// (magpie-community/plugins#579)
|
||||
cutWords = regexp.MustCompile(`(?i)tool call, written as text, was cut short|native tool call has no name; it is not sent on as a tool`)
|
||||
)
|
||||
|
||||
// Why a candidate failed, as rest tells it.
|
||||
|
||||
Reference in New Issue
Block a user