gateway: Claude Desktop's connection check asks no group classifier
CyberCaius on Discord, after v0.1.1847: with Desktop's default a routing
group, the first connection check as Desktop starts ends in 499 and the
second passes; with a model as the default it never does.
The check ({"max_tokens":1,"messages":[{"role":"user","content":"."}]})
is not streamed, and Desktop gives it 10 seconds as it starts
(AbortSignal.timeout(1e4) in its app.asar 2.7032, one retry when it is
"unreachable"; 8 seconds from Test connection). Through a group with
intent rules or Effort auto, magpie first asked the group's classifier
what "." is, up to the Classifier timeout (8s by default), then sent the
check on. A cold or slow classifier plus the member's answer is past 10
seconds, and Desktop cancels it (499). The second check doesn't wait:
the classifier failed and rests for 30s, or its verdict for "." is kept.
A model never classifies, so it never waits.
The check is no user's turn, so it now asks no classifier (as a
classifier's own call doesn't) and goes by the group's order. The rule's
trace says why. A user's turn from Desktop is still classified.
Measured (a fake classifier, group with one intent rule, Desktop's check
twice, on mote): before, a classifier slow past its timeout gave 8.01s
then 8ms; one taking 3s gave 3.02s then 9ms. After: 19ms and 9ms, 7ms
and 9ms, the classifier asked 0 times. Ruled out on the way: key-member
groups vs a model show no first-vs-second difference (instant, 3s slow,
429 and 503 on the first call); the held-stream keepalive (15s) is not
reached, the check isn't streamed.
Run: TestClaudeDesktopProbeAsksNoClassifier (new) with
TestClaudeDesktopProbe*, TestDesktopProbe, TestIntent* and
TestClassifier*; go test ./internal/gateway; gofmt -l; go vet for
darwin, linux and windows.
Broken by hand: the old condition (RouterAgent only) back, the new test
is red ("the check asked the classifier 1 times", asked of ".").
Not tried: a real Claude Desktop start against a group with a real
classifier; the allowance first read (provider.Allowances, up to 3s once
after magpie starts) is left as it is, as a model's check pays it too.
This commit is contained in:
@@ -185,3 +185,49 @@ func TestOwnCacheKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Claude Desktop's check through a routing group with intent rules is
|
||||
// answered by the group's order, not after its classifier: the check is
|
||||
// no user's turn, and Desktop gives it 10 seconds as it starts. Asked of
|
||||
// the classifier, the first check after a start waited up to the
|
||||
// Classifier timeout (8s) on a ".", and Desktop cancelled it as a 499;
|
||||
// the second passed on the verdict kept (CyberCaius on Discord,
|
||||
// v0.1.1847). A user's turn from Desktop still asks it.
|
||||
func TestClaudeDesktopProbeAsksNoClassifier(t *testing.T) {
|
||||
resetClassified(t)
|
||||
s, a, _, c := intented(t, provider.Rule{Use: "b/big", Intent: "writing or fixing tests"})
|
||||
c.set("1", 0)
|
||||
if err := provider.SetModelOrder("claude-desktop", []string{"group/r"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
desktopPicked.Lock()
|
||||
desktopPicked.model, desktopPicked.from = "", ""
|
||||
desktopPicked.Unlock()
|
||||
send := func(body string) (int, string) {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest("POST", "/v1/messages", strings.NewReader(body))
|
||||
req.Header.Set("x-api-key", Token+"-claude-desktop")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh) Claude/2.7032.0 Chrome/140.0 Electron/38.0")
|
||||
rec := httptest.NewRecorder()
|
||||
s.Handler().ServeHTTP(rec, req)
|
||||
return rec.Code, rec.Body.String()
|
||||
}
|
||||
const probe = `{"model":"magpie-claude-haiku-5-5","max_tokens":1,"messages":[{"role":"user","content":"."}]}`
|
||||
if code, body := send(probe); code != 200 {
|
||||
t.Fatalf("probe: %d %s", code, body)
|
||||
}
|
||||
if n := c.n(); n != 0 {
|
||||
t.Fatalf("the check asked the classifier %d times: %s", n, c.last())
|
||||
}
|
||||
r := lastRoute(s)
|
||||
if a.last == "" || r.Rule == nil || r.Rule.Classified == nil || !strings.Contains(r.Rule.Classified.Error, "Claude Desktop's connection check") {
|
||||
t.Fatalf("not answered by the group's first member, or the trace doesn't say why: %q %+v", a.last, r.Rule)
|
||||
}
|
||||
// a user's turn through the same group is still classified
|
||||
if code, body := send(`{"model":"group/r","max_tokens":32000,"stream":true,"messages":[{"role":"user","content":"add a unit test for the parser"}]}`); code != 200 {
|
||||
t.Fatalf("turn: %d %s", code, body)
|
||||
}
|
||||
if c.n() != 1 {
|
||||
t.Fatalf("a user's turn asked the classifier %d times", c.n())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1806,9 +1806,11 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// the group's, as "group/<id>" is, rather than one provider's that
|
||||
// serves it: the Routing view shows the group it went to
|
||||
asked = call.Model
|
||||
desktopCheck := false // Claude Desktop's check that the gateway answers
|
||||
if agent == "claude-desktop" {
|
||||
sub, _ := subagentOf(r.Header)
|
||||
probe := desktopProbe(body)
|
||||
desktopCheck = probe
|
||||
asked = desktopTurn(asked, body, fromClaudeCode(r.Header), sub != "")
|
||||
if probe {
|
||||
// its check, asked for room every model answers in
|
||||
@@ -2058,8 +2060,17 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// a classifier's own call to a group (a group's classifier may be one)
|
||||
// asks no classifier in turn: one that is, however far round, the group
|
||||
// asking would ask itself for ever
|
||||
//
|
||||
// Nor does Claude Desktop's check (desktopProbe): it is no user's turn,
|
||||
// and it has 10 seconds to be answered as Desktop starts (8 from Test
|
||||
// connection). Asked of a group with intent rules or Effort auto, its
|
||||
// "." waited on the classifier first, up to the Classifier timeout's 8
|
||||
// seconds, so the first check after a start was cancelled as a 499
|
||||
// and the second, its verdict kept or the classifier resting, passed
|
||||
// (CyberCaius on Discord, v0.1.1847). It goes by the group's order,
|
||||
// as a model's check does.
|
||||
ask := s.askClassifier
|
||||
if r.Header.Get("User-Agent") == RouterAgent {
|
||||
if r.Header.Get("User-Agent") == RouterAgent || desktopCheck {
|
||||
ask = nil
|
||||
} else {
|
||||
// a wait magpie knows of, before a route is begun (unrouted.go)
|
||||
|
||||
@@ -306,7 +306,7 @@ func ruleFor(key string, g provider.Group, ms []provider.Member, req *Request, a
|
||||
case g.Classifier == "":
|
||||
c.Error = "the group has no classifier"
|
||||
case ask == nil:
|
||||
c.Error = "nothing to ask the classifier with: this is a classifier's own call"
|
||||
c.Error = "nothing to ask the classifier with: this is a classifier's own call, or Claude Desktop's connection check"
|
||||
case text == "":
|
||||
c.Error = "the message has no words to classify"
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user