30c55ff5e skips a nested group's effort classifier once the group above
picked, and traced it as Classified{Error: "the group above already
picked this turn's reasoning"}. The Routing page reads an Error with no
intents as "{by} was to rate how hard turn {turn} is, but couldn't —
{err} — so it reasons as the agent asked", which is wrong: the turn
reasons at the group above's pick.
Classified gets Above, the pick of the group above, in place of that
Error (also on a classifier still asked for intents), and classWhy says
"{by} wasn't asked how hard turn {turn} is: the group above picked
{level} reasoning for it.", in zh, zh-TW, ja and de too.
TestNestedGroupClassifierNotAskedWhenTheParentPicked checks the nested trace carries
Above "high" and no Error; routing-classifier-above.test.cjs checks the
line in every language at 1100px and 390px, with no sideways scroll
and without the old "reasons as the agent asked".
Run on mote: go test -tags nogui ./internal/gateway/ -run
'Nested|Classif|Intent|Effort|Rule' ok; node --test (chromium and
webkit) routing-classifier-above, routing-classifier-said,
routing-intent-fallback, routing-smart-intent and i18n-keys: 124 of 124
pass. Broken by hand: classWhy without the Above branch, the new GUI
file 0 of 10 in chromium.
Not tried: a real nested effort=auto group.
The whole batch (101e6201c..this, gua2100's five patches and three
follow-ups) at this tree, on mote: gofmt -l clean; go vet -tags nogui
for GOOS darwin, linux, windows, and go vet (GUI) darwin, all ok;
go test -tags nogui -count=1 -timeout 45m ./...: 85 packages ok and 2
reds, neither from this batch. internal/cli
TestEveryRouteHasACommandOrIsNamed is red at origin/main ad53a23dc too
(POST /api/usage/checkin-account, from e87140242; #4826). internal/gateway
TestCodexPoolSaysTheClientsVersion passes alone 3 of 3 at the base and at
this head (#4807).
102 lines
4.0 KiB
Go
102 lines
4.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #4358: a group in the group, itself effort=auto with a classifier of
|
|
// its own, is asked its classifier even when the group above it already
|
|
// picked the turn's reasoning — an answer the turn throws away, the
|
|
// requests going out at the parent's pick. The parent's pick stands, and
|
|
// the group in it is asked only when the parent gave no pick.
|
|
func TestNestedGroupClassifierNotAskedWhenTheParentPicked(t *testing.T) {
|
|
fresh(t)
|
|
parent, child := &clsUp{answer: "3"}, &clsUp{answer: "1"} // parent picks high, child low
|
|
for _, x := range []struct {
|
|
id string
|
|
up *clsUp
|
|
}{{"cp", parent}, {"cc", child}} {
|
|
srv := httptest.NewServer(x.up)
|
|
t.Cleanup(srv.Close)
|
|
if err := provider.Save(provider.Provider{ID: x.id, Name: strings.ToUpper(x.id), Key: "k" + x.id, Models: []string{"cls"}, Chat: srv.URL + "/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := catalog.SaveLive(x.id, srv.URL+"/v1", []catalog.Model{{ID: "cls", Context: 32000}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
f := &ruleUp{key: "kf"}
|
|
fs := httptest.NewServer(f)
|
|
t.Cleanup(fs.Close)
|
|
if err := provider.Save(provider.Provider{ID: "f1", Name: "F1", Key: "kf1", Models: []string{"m"}, Chat: fs.URL + "/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := catalog.SaveLive("f1", fs.URL+"/v1", []catalog.Model{{ID: "m", Context: 32000}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, g := range []provider.Group{
|
|
{Name: "Quality", Members: []string{"f1/m"}, Routing: provider.Ordered, Effort: provider.EffortAuto, Classifier: "cc/cls"},
|
|
{Name: "R", Members: []string{"group/quality"}, Routing: provider.Ordered, Effort: provider.EffortAuto, Classifier: "cp/cls"},
|
|
} {
|
|
if err := provider.SaveGroup(g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
s := New()
|
|
// the parent's classifier answers: its pick is the one sent, and the
|
|
// group in it is asked nothing
|
|
out, r := postOK(t, s, "s1", chat("fix the bug", nil, 0, `,"reasoning_effort":"medium"`))
|
|
if !strings.Contains(out, "from kf") {
|
|
t.Fatalf("%s", out)
|
|
}
|
|
if parent.n() != 1 {
|
|
t.Fatalf("the parent's classifier asked %d times", parent.n())
|
|
}
|
|
if n := child.n(); n != 0 {
|
|
t.Fatalf("the group in it asked its classifier %d times though the parent picked", n)
|
|
}
|
|
if !strings.Contains(f.last, `"reasoning_effort":"high"`) {
|
|
t.Fatalf("the parent's pick not sent: %s", f.last)
|
|
}
|
|
if r.Rule == nil || r.Rule.Pick != "high" || r.Rule.Classified == nil || r.Rule.Classified.By != "cp/cls" {
|
|
t.Fatalf("parent traced %+v", r.Rule)
|
|
}
|
|
if len(r.Nested) != 1 || r.Nested[0].Group != "quality" || r.Nested[0].Rule == nil || r.Nested[0].Rule.Pick != "" {
|
|
t.Fatalf("nested traced %+v", r.Nested)
|
|
}
|
|
// the trace says the group above picked, not that the group in it
|
|
// couldn't say (the Routing page told that as "reasons as the agent
|
|
// asked", which the turn doesn't)
|
|
if c := r.Nested[0].Rule.Classified; c == nil || c.Above != "high" || c.Error != "" {
|
|
t.Fatalf("nested classified %+v", c)
|
|
}
|
|
// the parent's classifier giving nothing, the group in it is asked as
|
|
// before: its pick is what the turn goes by
|
|
parent.set("", 500)
|
|
was := parent.n()
|
|
out, r = postOK(t, s, "s2", chat("write the parser", nil, 0, `,"reasoning_effort":"medium"`))
|
|
if !strings.Contains(out, "from kf") {
|
|
t.Fatalf("%s", out)
|
|
}
|
|
// a failing upstream is asked again (and again, the pipeline's
|
|
// same-one retries of a 500, seen on the plain intent path too);
|
|
// the turn asked it afresh, whatever the count came to
|
|
if parent.n() <= was {
|
|
t.Fatalf("the parent's classifier asked %d times, was %d", parent.n(), was)
|
|
}
|
|
if child.n() != 1 {
|
|
t.Fatalf("the fallback asked %d times", child.n())
|
|
}
|
|
if !strings.Contains(f.last, `"reasoning_effort":"low"`) {
|
|
t.Fatalf("the group in it's pick not sent: %s", f.last)
|
|
}
|
|
if r.Rule == nil || r.Rule.Pick != "" || len(r.Nested) != 1 || r.Nested[0].Rule == nil || r.Nested[0].Rule.Pick != "low" {
|
|
t.Fatalf("traced %+v %+v", r.Rule, r.Nested)
|
|
}
|
|
}
|