From c79400556c5b1152123ea5c2c1d7b23cf585d655 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 16:32:21 +0800 Subject: [PATCH] agent: a Claude model on Bedrock runs to its own window in Claude Code, not 272K MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 划船不靠桨 on Discord (0.1.1306) asked why magpie sets CLAUDE_CODE_AUTO_COMPACT_WINDOW=272000 for a 1M model. writeCompact already skips the working window for Anthropic's Claude models and for routing groups made only of them (provider.ClaudeGroup). But the agent package's claudeModel only knew a name that starts with "claude", so a 1M Claude model listed under Amazon Bedrock's name (us.anthropic.claude-opus-…[1m]) was held to 272K, while a group of the same model ran to 1M. claudeModel now asks provider.ClaudeModel, which takes the vendor prefix off first. The reporter's own setup (a deepseek-v4-flash auto routing group of WorkBuddy, Qoder and a newapi relay) is not this bug. A probe in a sandbox HOME showed 272000 for group/auto-deepseek-v4-flash, its [1m] form and auto/deepseek-v4-flash, the group listed at its largest member's 1048576. That is settings.WorkingWindow, the default for any non-Claude model or mixed group over 272K (e950eb08). Settings -> Long conversations -> Full window, Compact at (global, per provider or per model), or a window typed on the group lift it. tune's compaction advice covers Claude models only, so it isn't the source. Test: TestClaudeCompactWindowBedrockClaude. A 1M Bedrock Claude model with [1m] leaves the env unset, after Sync too, and a 1M Nova model on the same provider still gets 272000. On the old claudeModel it fails with "a 1M Claude model on Bedrock is compacted at \"272000\"". Run at this head: gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...; go build for all three. Then go test -timeout 45m ./... under a sandbox HOME: every package ok except internal/agent, internal/gateway and internal/library, which timed out at 45m at load average ~25 (other sessions' suites), each with a test 1-3s old running, so no hang. Rerun alone (-timeout 60m): agent ok 2660s, gateway ok 2238s, library ok 2151s. That suite ran at base ba319a758. Rebased on e65688886 (three commits, in library and redact only): go build ./... and go test ./internal/agent -run Compact pass at the pushed head. Not changed: the 272K default for non-Claude models and mixed groups. Also not changed: a Claude [1m] model picked mid-session in /model while the main model is not Claude still runs under the main model's env until the next session. --- internal/agent/claude.go | 10 +++--- internal/agent/claude_compact_test.go | 47 +++++++++++++++++++++++++++ internal/provider/provider.go | 4 +++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/internal/agent/claude.go b/internal/agent/claude.go index 51f3d33ea..38d2c4857 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -2390,11 +2390,13 @@ func claude1MFor(agent string) func(ref string) string { // claudeModel says a model ref (magpie/v/claude-opus-5-5[1m], or Claude // Code's own claude-opus-5-5) is one of Anthropic's Claude models, by -// whichever provider it comes. +// whichever provider it comes and by whatever name it gives it: Amazon +// Bedrock's us.anthropic.claude-opus-… too, which Claude Code knows by the +// same "opus-…" it looks for, and which a group of was already taken for +// Claude's (provider.ClaudeGroup) while the model alone was held to the +// working window (划船不靠桨 on Discord). func claudeModel(ref string) bool { - m := strings.TrimSuffix(ref, "[1m]") - m = m[strings.LastIndex(m, "/")+1:] - return strings.HasPrefix(strings.ToLower(m), "claude") + return provider.ClaudeModel(strings.TrimSuffix(ref, "[1m]")) } // claudeOwnCompact says the settings.json at path has an auto-compact diff --git a/internal/agent/claude_compact_test.go b/internal/agent/claude_compact_test.go index 91836cd21..f3345084c 100644 --- a/internal/agent/claude_compact_test.go +++ b/internal/agent/claude_compact_test.go @@ -269,3 +269,50 @@ func TestClaudeGroupCompactWindow(t *testing.T) { t.Fatalf("autoCompactWindow changed: %q", v) } } + +// A Claude model runs to its whole window whatever name its provider gives +// it: Amazon Bedrock names Claude Opus us.anthropic.claude-…, which +// magpie's [1m] Claude Opus there was not taken for, so Claude Code was +// held to 272K on a 1M Claude model (划船不靠桨 on Discord), while a group +// of the same model ran to 1M (provider.ClaudeGroup). Another vendor's 1M +// model on the same provider is still compacted at the working window. +func TestClaudeCompactWindowBedrockClaude(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + const opus, nova = "us.anthropic.claude-opus-5-5-v1", "us.amazon.nova-premier-v1" + if err := provider.Save(provider.Provider{ID: "br", Name: "Bedrock", Chat: "https://example.test/v1", Key: "k", + Models: []string{opus, nova}}); err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("br", "https://example.test/v1", []catalog.Model{{ID: opus, Context: 1000000}, {ID: nova, Context: 1000000}}); err != nil { + t.Fatal(err) + } + path := filepath.Join(home, ".claude", "settings.json") + writeFile(t, path, `{}`) + a := claude(home) + compact := func() string { v, _ := edit.GetJSON(path, "env."+claudeCompactEnv); return v } + must := func(err error) { + t.Helper() + if err != nil { + t.Fatal(err) + } + } + must(a.Field("model").Set("br/" + opus + "[1m]")) + if compact() != "" { + t.Fatalf("a 1M Claude model on Bedrock is compacted at %q", compact()) + } + must(a.Sync()) + if compact() != "" { + t.Fatalf("a 1M Claude model on Bedrock, synced: %q", compact()) + } + if top, _ := edit.GetJSON(path, "autoCompactWindow"); top != "" { + t.Fatalf("a 1M Claude model on Bedrock got autoCompactWindow %q", top) + } + must(a.Field("model").Set("br/" + nova + "[1m]")) + if compact() != "272000" { + t.Fatalf("another vendor's 1M model on Bedrock: %q", compact()) + } +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6e8a7beec..5fd0acd16 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1542,6 +1542,10 @@ func claudeModel(model string) bool { return strings.HasPrefix(m, "claude") || bedrockClaude(m) } +// ClaudeModel is claudeModel for another package: whether model, after any +// vendor prefix, is one of Anthropic's Claude models by its name. +func ClaudeModel(model string) bool { return claudeModel(model) } + // openAIModel is whether model is one of OpenAI's own by its name: a GPT, // a Codex or an o-series model, after any vendor prefix. func openAIModel(model string) bool {