agents: a model of no known window is told the default under the longest context too (ul3140773077392 on X, #6259)
settings.ContextCap held every window magpie knew, but fourteen agents write a default of their own (128000 or 200000) for a model whose window magpie doesn't know, and that default went out past the cap: Crush, ZCode, VS Code and its forks (Copilot, Zoo Code, Air), Copilot for JetBrains, Zed, jcode, Pencil, AtomCode, Kimi, OpenClaw, Snow, WorkBuddy and CodeBuddy. unknownWindow holds each default to the cap. AtomCode's output clamp used the constant and now uses the window it is told. BaoCode (a Claude Code front end) keeps its own context per model and reads no window from magpie; Claude Code gets the cap through CLAUDE_CODE_MAX_CONTEXT_TOKENS, which it does follow. Not changed. Guard: TestEveryAgentFollowsContextCap connects every agent that can be here to a provider with a 987654 model and a model of no window, under a cap of 99999, and fails on any agent file holding either window or a default. Red on the old code in 14 agents' files (checked on mote), green after. Run on mote: go test ./internal/agent ./internal/provider ok; go vet darwin, GOOS=windows, GOOS=linux -tags nogui ok; gofmt clean. Not tried: a live BaoCode, the full suite (started after the tag), GUI.
This commit is contained in:
@@ -648,7 +648,7 @@ func magpieProviderJSONAt(shape, catalog, gw string) any {
|
||||
for _, m := range models {
|
||||
window := m.Context
|
||||
if window == 0 {
|
||||
window = 200000
|
||||
window = unknownWindow(200000)
|
||||
}
|
||||
// without it Crush caps every reply at 16384 tokens, a model
|
||||
// that can write more of them never asked for it; an output
|
||||
|
||||
@@ -310,7 +310,7 @@ func atomcodeTablesAt(path, v1, key string) []edit.Table {
|
||||
for _, m := range sharedModels("atomcode") {
|
||||
ctx := m.Context
|
||||
if ctx <= 0 {
|
||||
ctx = atomcodeContext
|
||||
ctx = unknownWindow(atomcodeContext)
|
||||
}
|
||||
kvs := []edit.KV{
|
||||
{Path: "account", Value: magpieID},
|
||||
@@ -320,8 +320,8 @@ func atomcodeTablesAt(path, v1, key string) []edit.Table {
|
||||
// an output above the window is cut to it — the window AtomCode is
|
||||
// told when magpie doesn't know the model's is atomcodeContext
|
||||
if n := maxTokens(m); n > 0 {
|
||||
if m.Context <= 0 && n > atomcodeContext {
|
||||
n = atomcodeContext
|
||||
if m.Context <= 0 && n > ctx {
|
||||
n = ctx
|
||||
}
|
||||
kvs = append(kvs, edit.KV{Path: "max_tokens", Value: n})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// The longest context (settings.ContextCap) is told to every agent that is
|
||||
// written a context window (ul3140773077392 on X, #6259: dsh followed it,
|
||||
// another harness kept 200K). Each agent is connected to a provider whose
|
||||
// model has a 987654-token window under a cap of 99999; no file the agent
|
||||
// reads may hold the longer one.
|
||||
func TestEveryAgentFollowsContextCap(t *testing.T) {
|
||||
const long, capAt = "987654", 99999
|
||||
home, _ := codexHome(t, "", "")
|
||||
managed := claudeManaged
|
||||
claudeManaged = func() string { return filepath.Join(home, "managed-settings.json") }
|
||||
t.Cleanup(func() { claudeManaged = managed })
|
||||
startAlma(t)
|
||||
startShelley(t)
|
||||
os.MkdirAll(filepath.Join(home, ".hanako", "agents", "hana"), 0o755)
|
||||
os.WriteFile(filepath.Join(home, ".hanako", "agents", "hana", "config.yaml"), []byte("agent:\n name: Hana\n"), 0o644)
|
||||
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "https://example.test/v1", Key: "k",
|
||||
Models: []string{"big", "plain-model-of-no-window"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := catalog.SaveLive("v", "https://example.test/v1", []catalog.Model{{ID: "big", Context: 987654}, {ID: "plain-model-of-no-window"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := settings.Save(settings.Settings{ContextCap: 99999}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.Touched()
|
||||
for _, a := range All() {
|
||||
if a.Launch != nil || a.Native != nil || a.WSL != "" || len(a.Fields) == 0 {
|
||||
continue
|
||||
}
|
||||
t.Run(a.ID, func(t *testing.T) {
|
||||
if _, err := a.ConnectHow(); err != nil {
|
||||
t.Skip("can't be connected here:", err)
|
||||
}
|
||||
if !a.Wired() {
|
||||
t.Skip("not wired by Connect here")
|
||||
}
|
||||
SyncCatalog()
|
||||
for p, b := range agentFiles(t, home) {
|
||||
for _, d := range []string{"128000", "128_000", "200000", "250000", "262144", "256000", "131072"} {
|
||||
if strings.Contains(b, d) {
|
||||
t.Errorf("%s holds the default window %s past the cap %d", p, d, capAt)
|
||||
}
|
||||
}
|
||||
if strings.Contains(b, long) {
|
||||
t.Errorf("%s holds the window %s past the cap %d", p, long, capAt)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func copilotJBModelsJSON(hidden map[string]bool) map[string]any {
|
||||
for _, m := range sharedModels(copilotJBID) {
|
||||
context := m.Context
|
||||
if context == 0 {
|
||||
context = 128000 // the server's own default for a custom endpoint
|
||||
context = unknownWindow(128000) // the server's own default for a custom endpoint
|
||||
}
|
||||
// the output is reserved out of the window the prompt fills
|
||||
output := maxTokens(m)
|
||||
|
||||
@@ -107,7 +107,7 @@ func jcodeWant(was []jcodeModel) []jcodeModel {
|
||||
for _, m := range sharedModels("jcode") {
|
||||
ctx := m.Context
|
||||
if ctx <= 0 {
|
||||
ctx = jcodeContext
|
||||
ctx = unknownWindow(jcodeContext)
|
||||
}
|
||||
e := jcodeModel{ID: m.ID, ContextWindow: ctx, Input: []string{"text"}}
|
||||
if m.Images {
|
||||
|
||||
@@ -70,7 +70,7 @@ func kimiModelTables(path string, legacy bool, wrote map[string]map[string]strin
|
||||
name := "models." + strconv.Quote(magpieID+"/"+m.ID)
|
||||
ctx := m.Context
|
||||
if ctx <= 0 {
|
||||
ctx = kimiContext
|
||||
ctx = unknownWindow(kimiContext)
|
||||
}
|
||||
var was map[string]string
|
||||
if slices.Contains(names, name) {
|
||||
|
||||
@@ -186,7 +186,7 @@ func openClawWant(raw gjson.Result) []any {
|
||||
for _, m := range sharedModels("openclaw") {
|
||||
ctx := m.Context
|
||||
if ctx <= 0 {
|
||||
ctx = openClawContext
|
||||
ctx = unknownWindow(openClawContext)
|
||||
}
|
||||
e := openClawEntry{ID: m.ID, Name: m.ID, Input: []string{"text"}, ContextWindow: ctx}
|
||||
if m.Images {
|
||||
|
||||
@@ -105,7 +105,7 @@ func pencilProviderJSON(gw string) map[string]any {
|
||||
e["input"] = []string{"text"}
|
||||
}
|
||||
if _, ok := e["contextWindow"]; !ok {
|
||||
e["contextWindow"] = 128000
|
||||
e["contextWindow"] = unknownWindow(128000)
|
||||
}
|
||||
if _, ok := e["maxTokens"]; !ok {
|
||||
e["maxTokens"] = min(16384, e["contextWindow"].(int))
|
||||
|
||||
@@ -498,3 +498,9 @@ func group(name string, opts []Option) []Option {
|
||||
}
|
||||
|
||||
func gatewayV1() string { return gateway.URL() + "/v1" }
|
||||
|
||||
// unknownWindow is the window an agent is told of a model whose own magpie
|
||||
// doesn't know: the agent's default n, held to the longest context the user
|
||||
// set for every model (settings.ContextCap) like every window that is known
|
||||
// (ul3140773077392 on X, #6259).
|
||||
func unknownWindow(n int) int { return settings.Shared().Capped(n) }
|
||||
|
||||
@@ -491,7 +491,7 @@ func snowProfileFor(from []byte, ours bool, v1, key, ref string, wrote map[strin
|
||||
if !ours {
|
||||
snowOwnVision(sc)
|
||||
}
|
||||
ctx, out := snowContext, snowOutput
|
||||
ctx, out := unknownWindow(snowContext), snowOutput
|
||||
sees := false
|
||||
for _, m := range sharedModels("snow") {
|
||||
if m.ID == ref {
|
||||
|
||||
@@ -624,7 +624,7 @@ func vscodeGroupJSON(k vscodeKind, vendor string) map[string]any {
|
||||
for _, m := range sharedModels(k.id) {
|
||||
context := m.Context
|
||||
if context == 0 {
|
||||
context = 128000 // what VS Code takes a model of unknown window for
|
||||
context = unknownWindow(128000) // what VS Code takes a model of unknown window for
|
||||
}
|
||||
// VS Code keeps the output budget out of the window it fills with
|
||||
// the prompt, so a model whose output limit is near its window
|
||||
|
||||
@@ -359,7 +359,7 @@ const buddySmallWindow = 200000
|
||||
// agent's key.
|
||||
func buddyModel(agent, id, name string, context, output int, images bool, efforts []string) map[string]any {
|
||||
if context == 0 {
|
||||
context = 200000
|
||||
context = unknownWindow(200000)
|
||||
}
|
||||
e := map[string]any{
|
||||
"id": id, "name": name, "vendor": magpieID,
|
||||
|
||||
@@ -135,7 +135,7 @@ func zcodeProviderJSON(path string, keep bool) any {
|
||||
for _, m := range sharedModels("zcode") {
|
||||
window := m.Context
|
||||
if window == 0 {
|
||||
window = 200000
|
||||
window = unknownWindow(200000)
|
||||
}
|
||||
in := []string{"text"}
|
||||
if m.Images {
|
||||
|
||||
@@ -213,7 +213,7 @@ func zedProviderJSON(path, url string) map[string]any {
|
||||
for _, m := range sharedModels("zed") {
|
||||
context := m.Context
|
||||
if context == 0 {
|
||||
context = 128000 // Zed requires a context window for every custom model.
|
||||
context = unknownWindow(128000) // Zed requires a context window for every custom model.
|
||||
}
|
||||
// Zed's max_tokens is the window a prompt and its reply share: it
|
||||
// keeps max_output_tokens of it for the reply and lets the prompt
|
||||
|
||||
@@ -254,7 +254,7 @@ func zooCodeModelInfo(m catalog.Model) map[string]any {
|
||||
info := map[string]any{"supportsPromptCache": false, "supportsImages": m.Images}
|
||||
// Zoo Code's own default for a model it isn't told about
|
||||
// (openAiModelInfoSaneDefaults)
|
||||
info["contextWindow"] = 128_000
|
||||
info["contextWindow"] = unknownWindow(128_000)
|
||||
if m.Context > 0 {
|
||||
info["contextWindow"] = m.Context
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user