Files
magpie/internal/gateway/kiro_overflow_test.go
T
yetone 0c31638045 kiro: the mover installs 0.1.24, which says a too-long conversation as one
ergou0954_54426 on Discord routes by intent across Kiro's Claude and GPT
models and DeepSeek, and sometimes a turn failed with Kiro saying the
context was exceeded. Kiro says a conversation is past the model's window
in three ways, and the plugin up to 0.1.23 turned only the HTTP 400 into
the "input is too long for the model's context" that the gateway reads as
an overflow (tooLong). The same ValidationException as an exception in
Kiro's event stream came out as a 502, so the gateway took it for a
passing vendor fault: it rested the account, asked Kiro again (15 asks
for a lone provider in a probe), and never told the agent
context_length_exceeded, so the agent never compacted. A reply Kiro
stopped with MODEL_CONTEXT_WINDOW_EXCEEDED came out as finished.
plugins e8050e8 (kiro 0.1.24, on npm) answers both as the 400 that says
too long. Routing was already right: roomy skips a member whose known
window the request is past, and withRoom moves an overflow to a member
with room.

The min goes to 0.1.24 so keepMovedCurrent updates every moved user.
TestKiroMoverHasTheTooLongFix holds it there.
TestKiroPluginOverflowGoesToAMemberWithRoom pins what the gateway does with
0.1.24's two wordings: in a group the other member answers, the try is
failOverflow with no rest, and alone the agent gets context_length_exceeded
after a single ask.

Run on mote: go vet ./internal/provider ./internal/gateway; go test
-timeout 45m -count=1 ./internal/provider (ok 150s) ./internal/gateway
(ok 712s). gofmt -l clean. Broken by hand: at origin/main's min 0.1.23,
TestKiroMoverHasTheTooLongFix fails. A probe with 0.1.23's 502 body
showed Fail other, a rest, and a vendor 502 for the lone provider.
Not run: the full ./... suite (another session's full suite held mote),
and a real Kiro account pushed past its window.
2026-11-01 11:30:12 +08:00

53 lines
2.4 KiB
Go

package gateway
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// What the Kiro plugin answers from 0.1.24 for a conversation past the
// model's window, each way Kiro says it (an exception in its event stream,
// a reply stopped with MODEL_CONTEXT_WINDOW_EXCEEDED), is read as an
// overflow: another member with room answers, the Kiro account doesn't
// rest and isn't asked again, and with no member left the agent is told
// context_length_exceeded, so it compacts (ergou0954_54426 on Discord:
// Kiro's models beside DeepSeek in intent routing, "kiro 那边报错说超出上下文").
// Before 0.1.24 the stream's exception was a 502 the gateway took for a
// passing vendor fault (TestKiroMoverHasTheTooLongFix holds the min).
// The member ids are neutral: kiro is a retired built-in the gateway hands
// to the plugin host.
func TestKiroPluginOverflowGoesToAMemberWithRoom(t *testing.T) {
for _, msg := range []string{
"input is too long for the model's context: ValidationException: Input is too long. (CONTENT_LENGTH_EXCEEDS_THRESHOLD)",
"input is too long for the model's context: the reply stopped as the model's context window was full (MODEL_CONTEXT_WINDOW_EXCEEDED)",
} {
fresh(t)
over := `{"type":"error","error":{"type":"invalid_request_error","message":"` + msg + `"}}`
kiro := &scripted{replies: []reply{{400, "application/json", over}}}
other := &scripted{replies: []reply{{200, "", chatOK}}}
scriptedOn(t, "k", provider.Chat, kiro)
scriptedOn(t, "d", provider.Chat, other)
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"k/m", "d/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") || kiro.n != 1 || other.n != 1 {
t.Fatalf("%s\ngroup: %d %s (kiro %d, other %d)", msg, code, body, kiro.n, other.n)
}
r := s.trace.routes[len(s.trace.routes)-1]
if len(r.Tries) != 2 || r.Tries[0].Fail != failOverflow || r.Tries[0].Rest != nil {
t.Fatalf("%s\ntries %+v", msg, r.Tries)
}
// alone, the agent is told it overflowed, asked once
kiro.n = 0
code, body = postAs(t, s, "", `{"model":"k/m","messages":[{"role":"user","content":"hi"}]}`)
if code != 400 || !strings.Contains(body, "context_length_exceeded") || kiro.n != 1 {
t.Fatalf("%s\nalone: %d %s (kiro %d)", msg, code, body, kiro.n)
}
}
}