What changed: the gateway keeps, per classifier model, why it couldn't
say the last time it was asked (an error from the request, or an answer
that was no number of the list) and when, until it answers again
(gateway.ClassifierFailure). The first failure, and each one that says
something new, is written to the log once ("routing: the classifier X
couldn't say: ..."). /api/groups sends it as a group's classifierFailed,
and the group's card on Routing shows a line "Classifier failed 3 min
ago: <why>" with an amber dot (no stripe); its title says that until the
classifier answers, no rule with an intent matches and turns reason as
the agent asked. Strings in en, zh, zh-TW, ja and de.
Why: versun's MLX-Serve answered its Clef decision model, asked as a
chat model, with a 400. The only place that said so was each request's
own details; the group's rules with an intent quietly never matched,
which read as the routing working. The preset itself is fixed in the
commit before this one (versun's, cherry-picked).
Run:
- go test: TestClassifierFailureIsKept (gateway: a 400, kept while
resting, "not a number", cleared by an answer) and
TestGroupsSayAClassifierThatFailed (gui: only the failing group's JSON
has classifierFailed). Each went red with its line removed by hand
(the record in classify(), the fill in groupsState).
- group-classifier-failed.test.cjs: chromium and webkit, en zh zh-TW ja
de, at 1100 and 420: 20/20; with classifierFailed dropped from the
fixture's reading in groupRow, 10/10 of one engine red. i18n-keys
passes.
- go test -tags nogui ./internal/provider ./internal/usage ./internal/cli:
ok. ./internal/gateway hit the 10m default timeout at load ~150-190
(other sessions); rerun with a longer timeout before the push, below.
- go test ./internal/gui: TestDockJoinLeadsCommandTab (Command-Tab order
had kitty in front) and TestMainWindowCorners (measuring killed under
load) failed; both are desktop-window tests this change doesn't touch.
Not verified: a real MLX-Serve; versun ran his own.
82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #1929 (versun): a group whose classifier couldn't say the last time it
|
|
// was asked says why on the Routing page's card, rather than only in each
|
|
// request's details while its rules with an intent quietly never match. A
|
|
// group whose classifier answered, or that has none, says nothing.
|
|
func TestGroupsSayAClassifierThatFailed(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
for _, id := range []string{"a", "b"} {
|
|
if err := provider.Save(provider.Provider{ID: id, Name: id, Key: "k" + id, Chat: "http://127.0.0.1:1/v1", Models: []string{"m"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// MLX-Serve's own words, its decision model asked as a chat model
|
|
const why = `b/m: This is a typed-decision model; it cannot serve chat/text requests. Use POST /v1/decisions instead.`
|
|
at := time.Now().Add(-time.Minute).Truncate(time.Second)
|
|
was := classifierFailure
|
|
t.Cleanup(func() { classifierFailure = was })
|
|
classifierFailure = func(model string) (string, time.Time, bool) {
|
|
if model == "b/m" {
|
|
return why, at, true
|
|
}
|
|
return "", time.Time{}, false
|
|
}
|
|
for _, g := range []provider.Group{
|
|
{ID: "intent", Name: "Intent", Members: []string{"a/m", "b/m"}, Classifier: "b/m", Rules: []provider.Rule{{Use: "b/m", Intent: "planning"}}},
|
|
{ID: "fine", Name: "Fine", Members: []string{"a/m", "b/m"}, Classifier: "a/m", Rules: []provider.Rule{{Use: "b/m", Intent: "planning"}}},
|
|
{ID: "plain", Name: "Plain", Members: []string{"a/m", "b/m"}},
|
|
} {
|
|
if err := provider.SaveGroup(g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
b, _ := json.Marshal(groupsState())
|
|
var st struct {
|
|
Groups []struct {
|
|
ID string `json:"id"`
|
|
ClassifierFailed *struct {
|
|
Error string `json:"error"`
|
|
At time.Time `json:"at"`
|
|
} `json:"classifierFailed"`
|
|
} `json:"groups"`
|
|
}
|
|
if err := json.Unmarshal(b, &st); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
seen := 0
|
|
for _, g := range st.Groups {
|
|
switch g.ID {
|
|
case "intent":
|
|
seen++
|
|
if g.ClassifierFailed == nil || g.ClassifierFailed.Error != why || !g.ClassifierFailed.At.Equal(at) {
|
|
t.Fatalf("the failing classifier's group: %+v", g.ClassifierFailed)
|
|
}
|
|
case "fine", "plain":
|
|
seen++
|
|
if g.ClassifierFailed != nil {
|
|
t.Fatalf("%s: %+v", g.ID, g.ClassifierFailed)
|
|
}
|
|
}
|
|
}
|
|
if seen != 3 {
|
|
t.Fatalf("groups: %s", b)
|
|
}
|
|
if strings.Count(string(b), `"classifierFailed"`) != 1 {
|
|
t.Fatalf("classifierFailed sent for a group it isn't for: %s", b)
|
|
}
|
|
}
|