provider: a group following its smallest member runs to that member's window when the user typed it, not magpie's 272K (#2224, Zypixh)
A group set to "smallest member" was told the smallest window, but not that it was one the user typed: groupEntries set Entry.WindowSet only for a group's own size, and WindowTyped said yes only for g.Context > 0. So a 500K typed on the provider for gpt-6.1-sol reached /v1/models, yet Claude Desktop's modelSettings.<id>.autoCompactWindow and Codex's compaction were magpie's default 272K, while the same group set to 500K itself got 500K. smallestWindow now gives the smallest window among a group's members and whether the member it comes from has a typed one (a tie counts as typed); groupEntries carries that into WindowSet (Codex, CompactFor) and WindowTyped asks it for a smallest-member group (Claude Code and Desktop). Members are already flattened through groups in groups, so an outer group passes it on. A group whose smallest member's window nobody typed, and largest/unset groups, are unchanged. Run (sandbox HOME, pinned caches): - TestSmallestMemberTypedWindow (new, internal/agent): on the old code FAIL "the gateway's list compacts group/pool at 0; want 500000" and "Claude Desktop: group/pool ... compacts at "272000"; want "500000"", same for the nested group/outer; with only compact.go reverted the Desktop lines fail. With the fix ok; group/plain (untyped) stays 272000. - go test -count=1 -timeout 30m ./internal/provider/ ./internal/agent/ ./internal/gateway/: ok (374s, 958s, 1042s on a loaded machine; a first run with the default 10m timeout timed out in gateway under load) - gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. Not run: the full go test ./... (disk kept low); not tried with the real Claude Desktop.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -112,3 +113,49 @@ func TestTypedWindowReachesCodexAndClaudeCode(t *testing.T) {
|
||||
t.Errorf("Claude Code on the group with Compact at 300K: %q", c)
|
||||
}
|
||||
}
|
||||
|
||||
// #2224 (Zypixh): a group that follows its smallest member is told that
|
||||
// member's window, and when the user typed it (500K on the provider for
|
||||
// gpt-6.1-sol) Claude Desktop and Codex run to it whole, as they do for a
|
||||
// group set to 500K itself, not to magpie's default 272K. A group in a
|
||||
// group passes it on. A group whose smallest member's window nobody typed
|
||||
// keeps the default.
|
||||
func TestSmallestMemberTypedWindow(t *testing.T) {
|
||||
home, path := desktopWindowSandbox(t)
|
||||
must := func(err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
must(provider.Save(provider.Provider{ID: "w", Name: "W", Key: "k", Chat: "http://127.0.0.1:1/v1",
|
||||
Models: []string{"sol", "other"}, Contexts: map[string]int{"sol": 500000}}))
|
||||
must(catalog.SaveLive("w", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "sol", Context: 1000000}, {ID: "other", Context: 600000}}))
|
||||
must(provider.SaveGroup(provider.Group{ID: "pool", Name: "Pool", Members: []string{"w/sol", "v/glm"}, Context: provider.ContextSmallest}))
|
||||
must(provider.SaveGroup(provider.Group{ID: "outer", Name: "Outer", Members: []string{"group/pool", "v/glm"}, Context: provider.ContextSmallest}))
|
||||
must(provider.SaveGroup(provider.Group{ID: "plain", Name: "Plain", Members: []string{"w/other", "v/glm"}, Context: provider.ContextSmallest}))
|
||||
|
||||
// Codex: the gateway's list and its context_window
|
||||
must(codex(home).Fields[0].Set("group/pool"))
|
||||
compacts := map[string]int{}
|
||||
for _, m := range provider.CodexListed() {
|
||||
compacts[m.ID] = m.Compact
|
||||
}
|
||||
for id, want := range map[string]int{"group/pool": 500000, "group/outer": 500000, "group/plain": 0} {
|
||||
if compacts[id] != want {
|
||||
t.Errorf("Codex: the gateway's list compacts %s at %d; want %d", id, compacts[id], want)
|
||||
}
|
||||
}
|
||||
|
||||
// Claude Desktop: each group's own autoCompactWindow
|
||||
must(claudeDesktop(home).Field("provider").Set("magpie"))
|
||||
ids := map[string]string{}
|
||||
for _, e := range provider.Catalog() {
|
||||
ids[e.ID] = gateway.DesktopID(e)
|
||||
}
|
||||
for id, want := range map[string]string{"group/pool": "500000", "group/outer": "500000", "group/plain": "272000"} {
|
||||
if v, _ := edit.GetJSON(path, budgetPath(ids[id])); v != want {
|
||||
t.Errorf("Claude Desktop: %s (%s) compacts at %q; want %q", id, ids[id], v, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,14 +53,30 @@ func CompactFor(s settings.Settings, e Entry, find func(string) (Group, []Member
|
||||
|
||||
// WindowTyped says the window agents are told for a model, by its
|
||||
// catalog id (as CompactSet takes it), is one the user typed: the
|
||||
// group's own size, or one set on the provider for the model or all of
|
||||
// its models. Claude Code then isn't handed magpie's default compaction
|
||||
// window for it (CompactFor's rule).
|
||||
// group's own size, a group's smallest member's that the user typed
|
||||
// (smallestWindow, #2224), or one set on the provider for the model or
|
||||
// all of its models. Claude Code then isn't handed magpie's default
|
||||
// compaction window for it (CompactFor's rule, as Entry.WindowSet).
|
||||
func WindowTyped(id string) bool {
|
||||
id = catalogID(id)
|
||||
if strings.HasPrefix(id, GroupPrefix) {
|
||||
g, _, ok := GroupFinder()(id)
|
||||
return ok && g.Context > 0
|
||||
gid, ok := GroupIDOf(id)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
entries := providerEntries()
|
||||
all := groupsIn(entries)
|
||||
g, ok := groupOf(all, gid)
|
||||
switch {
|
||||
case !ok || g.Disabled:
|
||||
return false
|
||||
case g.Context > 0:
|
||||
return true
|
||||
case g.Context == ContextSmallest:
|
||||
_, typed := smallestWindow(entries, membersIn(entries, all, g))
|
||||
return typed
|
||||
}
|
||||
return false
|
||||
}
|
||||
pid, model, ok := strings.Cut(id, "/")
|
||||
if !ok {
|
||||
|
||||
@@ -774,7 +774,6 @@ func groupEntries(entries []Entry) []Entry {
|
||||
// gateway sends max to the members that have no ultra
|
||||
ultra := false
|
||||
chatgpt := false // a ChatGPT account answers for a member
|
||||
smallest := 0 // the smallest window a member is known to have
|
||||
for i, m := range ms {
|
||||
chatgpt = chatgpt || m.Provider.Account != nil && m.Provider.Account.Agent == "codex"
|
||||
if !slices.ContainsFunc(ms[:i], func(o Member) bool { return o.Provider.ID == m.Provider.ID }) {
|
||||
@@ -822,9 +821,6 @@ func groupEntries(entries []Entry) []Entry {
|
||||
if ctx > e.Context {
|
||||
e.Context = ctx
|
||||
}
|
||||
if ctx > 0 && (smallest == 0 || ctx < smallest) {
|
||||
smallest = ctx
|
||||
}
|
||||
if i == 0 {
|
||||
e.ImageInput = imageInput
|
||||
} else {
|
||||
@@ -899,8 +895,8 @@ func groupEntries(entries []Entry) []Entry {
|
||||
ruledEntry(&e, g.Live(), ms, entries)
|
||||
if g.Context > 0 {
|
||||
e.Context, e.WindowSet = g.Context, true
|
||||
} else if g.Context == ContextSmallest && smallest > 0 {
|
||||
e.Context = smallest
|
||||
} else if smallest, typed := smallestWindow(entries, ms); g.Context == ContextSmallest && smallest > 0 {
|
||||
e.Context, e.WindowSet = smallest, typed
|
||||
}
|
||||
e.Family = g.Family
|
||||
out = append(out, e)
|
||||
@@ -908,6 +904,33 @@ func groupEntries(entries []Entry) []Entry {
|
||||
return out
|
||||
}
|
||||
|
||||
// smallestWindow is the smallest window a member of ms is known to have
|
||||
// (0 when none is), and whether the user typed it, on the member's
|
||||
// provider for its model or all of its models. A group told its
|
||||
// smallest member's window is then told one the user typed (#2224: a
|
||||
// group following its smallest member, a 500K the user set on it, was
|
||||
// handed to Claude Desktop and Codex as magpie's default 272K, which a
|
||||
// group set to 500K itself wasn't). A tie counts as typed: the window is
|
||||
// the user's either way.
|
||||
func smallestWindow(entries []Entry, ms []Member) (n int, typed bool) {
|
||||
for _, m := range ms {
|
||||
ctx, set := 0, false
|
||||
for _, x := range entries {
|
||||
if x.Provider.ID == m.Provider.ID && x.Model == m.Model {
|
||||
ctx, set = x.Context, x.WindowSet
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case ctx <= 0:
|
||||
case n == 0 || ctx < n:
|
||||
n, typed = ctx, set
|
||||
case ctx == n:
|
||||
typed = typed || set
|
||||
}
|
||||
}
|
||||
return n, typed
|
||||
}
|
||||
|
||||
// levelsUnknown reports whether nothing magpie reads says which reasoning
|
||||
// levels the model of x takes, or that it takes none: it has none in the
|
||||
// catalog, no account's list gives it, its vendor and its maker don't list
|
||||
|
||||
Reference in New Issue
Block a user