Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

provider: a routing group told its largest member's window runs to it when the user typed it (Osal on Discord)

yetonebe6a74f13eef
diff --git a/internal/agent/window_typed_test.go b/internal/agent/window_typed_test.go
index 9c7f7e16c..ab683b2e1 100644
--- a/internal/agent/window_typed_test.go
+++ b/internal/agent/window_typed_test.go
@@ -159,3 +159,81 @@ func TestSmallestMemberTypedWindow(t *testing.T) {
}
}
}
+
+// Osal on Discord: a routing group that names no size of its own is told
+// its largest member's window, and when the user typed that one (872K on
+// the provider for GPT-6 Astra, its most) Codex and Claude run to it
+// whole, as for a group following its smallest member (#2224), not to
+// magpie's default 272K (Codex showed "258k", 95% of it). A group whose
+// largest member's window nobody typed keeps the default, even with a
+// typed member smaller than it.
+func TestLargestMemberTypedWindow(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{"astra"}, Contexts: map[string]int{"astra": 872000}}))
+ must(catalog.SaveLive("w", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "astra", Context: 272000}}))
+ must(provider.SaveGroup(provider.Group{ID: "ultra", Name: "Ultra", Members: []string{"w/astra", "v/gpt"}}))
+ must(provider.SaveGroup(provider.Group{ID: "loose", Name: "Loose", Members: []string{"w/astra", "v/glm"}}))
+
+ // Codex: the gateway's list, and its context_window on disk
+ must(codex(home).Fields[0].Set("group/ultra"))
+ compacts := map[string]int{}
+ for _, m := range provider.CodexListed() {
+ compacts[m.ID] = m.Compact
+ }
+ for id, want := range map[string]int{"group/ultra": 872000, "group/loose": 0} {
+ if compacts[id] != want {
+ t.Errorf("Codex: the gateway's list compacts %s at %d; want %d", id, compacts[id], want)
+ }
+ }
+ var disk struct {
+ Models []struct {
+ Slug string `json:"slug"`
+ Context int `json:"context_window"`
+ Max int `json:"max_context_window"`
+ } `json:"models"`
+ }
+ raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
+ must(json.Unmarshal([]byte(raw), &disk))
+ for _, m := range disk.Models {
+ want := map[string][2]int{"group/ultra": {872000, 0}, "group/loose": {272000, 1000000}}
+ if w, ok := want[m.Slug]; ok && [2]int{m.Context, m.Max} != w {
+ t.Errorf("Codex: on disk %s is told %d (max %d); want %v", m.Slug, m.Context, m.Max, w)
+ }
+ }
+
+ // Claude Code: no compaction window for the typed one
+ cpath := filepath.Join(home, ".claude", "settings.json")
+ a := claude(home)
+ env := func(k string) string { v, _ := edit.GetJSON(cpath, "env."+k); return v }
+ must(a.Field("model").Set("group/ultra"))
+ if c, w := env(claudeCompactEnv), env(claudeContextEnv); c != "" || w != "872000" {
+ t.Errorf("Claude Code on the group: compact %q, window %q; want none and 872000", c, w)
+ }
+ must(a.Field("model").Set("group/loose"))
+ if c := env(claudeCompactEnv); c != "272000" {
+ t.Errorf("Claude Code on the loose group: compact %q; want the default 272000", c)
+ }
+
+ // Claude Desktop: the typed group's own autoCompactWindow; the
+ // other is left to the top-level one, the default
+ must(claudeDesktop(home).Field("provider").Set("magpie"))
+ ids := map[string]string{}
+ for _, e := range provider.Catalog() {
+ ids[e.ID] = gateway.DesktopID(e)
+ }
+ if v, _ := edit.GetJSON(path, "autoCompactWindow"); v != "272000" {
+ t.Errorf("Claude Desktop: top-level autoCompactWindow %q; want 272000", v)
+ }
+ for id, want := range map[string]string{"group/ultra": "872000", "group/loose": ""} {
+ 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)
+ }
+ }
+}
diff --git a/internal/provider/compact.go b/internal/provider/compact.go
index a16e1a4ea..9fb6bbe44 100644
--- a/internal/provider/compact.go
+++ b/internal/provider/compact.go
@@ -54,7 +54,8 @@ 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, a group's smallest member's that the user typed
-// (smallestWindow, #2224), or one set on the provider for the model or
+// (smallestWindow, #2224), its largest member's when it names no size
+// and the user typed that one (largestWindow), 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 {
@@ -75,6 +76,8 @@ func WindowTyped(id string) bool {
case g.Context == ContextSmallest:
_, typed := smallestWindow(entries, membersIn(entries, all, g))
return typed
+ case g.Context == 0:
+ return largestWindow(entries, g)
}
return false
}
diff --git a/internal/provider/group.go b/internal/provider/group.go
index c83c686a0..742be98fb 100644
--- a/internal/provider/group.go
+++ b/internal/provider/group.go
@@ -966,10 +966,11 @@ func buildGroupEntries(entries []Entry) []Entry {
var efforts []string
images, thinks, ctx, output := false, false, 0, 0
var imageInput *bool
- unknown, reasonless := false, false
+ unknown, reasonless, typed := false, false, false
if j := find(m.Provider.ID, m.Model); j >= 0 {
x := &entries[j]
efforts, images, thinks, ctx, output, imageInput = x.Efforts, x.Images, x.Reasoning, x.Context, x.Output, x.ImageInput
+ typed = x.WindowSet
unknown, reasonless = levelsUnknown(*x), x.Reasonless
}
// it reasons when a member does: the gateway sends the
@@ -1000,9 +1001,16 @@ func buildGroupEntries(entries []Entry) []Entry {
// with room for it (#700, withRoom in the gateway), so the
// agent compacts only when none has. The shortest member's,
// as it was, had Pi compact a group of 1M DeepSeeks at 200k
- // for the one free model among them that holds 200k (#712)
+ // for the one free model among them that holds 200k (#712).
+ // It is one the user typed when they typed that member's, as
+ // smallestWindow says it for a group following its smallest
+ // (Osal on Discord: an Ultra group of a ChatGPT account's
+ // GPT-6 Astra, set to its 872K on the codex provider, was
+ // handed to Codex as magpie's default 272K, ~258K at 95%)
if ctx > e.Context {
- e.Context = ctx
+ e.Context, e.WindowSet = ctx, typed
+ } else if ctx > 0 && ctx == e.Context {
+ e.WindowSet = e.WindowSet || typed
}
if i == 0 {
e.ImageInput = imageInput
@@ -1075,7 +1083,13 @@ func buildGroupEntries(entries []Entry) []Entry {
if e.ImageInput != nil && !*e.ImageInput {
e.Images = false
}
+ largest := e.Context
ruledEntry(&e, g.Live(), ms, entries)
+ if e.Context != largest {
+ // lifted by a rule of length to what its members fit, which
+ // is no member's typed window
+ e.WindowSet = false
+ }
if g.Context > 0 {
e.Context, e.WindowSet = g.Context, true
} else if g.Context == ContextSmallest {
@@ -1104,6 +1118,18 @@ func smallestWindow(entries []Entry, ms []Member) (n int, typed bool) {
return smallestWindowBy(entries, entriesBy(entries), ms)
}
+// largestWindow is the window a group that names no size of its own is
+// told, its largest member's, and whether the user typed it, as
+// buildGroupEntries says it (Entry.WindowSet).
+func largestWindow(entries []Entry, g Group) (typed bool) {
+ for _, e := range groupEntries(entries) {
+ if e.Group == g.ID {
+ return e.WindowSet
+ }
+ }
+ return false
+}
+
func smallestWindowBy(entries []Entry, find entryOf, ms []Member) (n int, typed bool) {
for _, m := range ms {
ctx, set := 0, false