agent: Claude Code's model field appends the kept list without a copy first
The model field (and a WSL Claude Code's, asleep) appended claudeViaMagpie's list to Claude Code's own models, which copies it, after claudeViaMagpie had copied it once already: 6.3 MB of forty polls with real accounts. claudeViaShared gives the list kept, read only, to such a caller; the append makes the field's list one of its own. claudeViaMagpie still gives every other caller a copy. TestClaudeViaMagpieKept now also writes into the model field's options and checks that neither kept list (folded or not) changes. Run on mote at68ebd1ec4plus this change: - gofmt; go vet darwin, windows, linux: ok - go test ./internal/agent -timeout 45m: ok (317.0s), with the test's first version, which read only the unfolded list - that version broken by hand (the field returns the kept list itself) went red on the folded-list check, not its own; the check now reads both lists. Alone 3/3 ok, and broken by hand red with "reached the options kept (folded true)"; the whole package not run again after - real accounts, sandbox HOME, network blocked, 40 polls, against v0.1.2494's change set: claudeIn.func57 23.4 -> 19.1 MB, claudeViaMagpie's 6.3 MB copy gone; state and drift answers byte for byte the same; footprint peak 141 MB, RSS at end 181 MB (noise between runs is about this size) Not run: the GUI suite (no GUI file changed), Windows and Linux test runs. Rebased onto9f75279e9(two GUI commits, nothing in internal/agent); not run again there.
This commit is contained in:
@@ -1755,7 +1755,7 @@ func claudeIn(at place) *Agent {
|
||||
// time, folded in the picker (#496). Only this machine's: a
|
||||
// distro's Claude Code has a sign-in of its own, which magpie
|
||||
// doesn't read
|
||||
return append(group(name, own), claudeViaMagpie(name == "Claude Code" && at.id == "")...)
|
||||
return append(group(name, own), claudeViaShared(name == "Claude Code" && at.id == "")...)
|
||||
},
|
||||
}, {
|
||||
// the effort Claude Code starts with, as its /effort saves it: under
|
||||
@@ -2489,11 +2489,19 @@ func claudeAliasOption(v string, ms []catalog.Model, tier func(string) string) (
|
||||
// tier fields asked it each poll, for the picker and again for Drift, a
|
||||
// list built anew each time, 30 MB of forty polls with real accounts.
|
||||
func claudeViaMagpie(fold bool) []Option {
|
||||
return slices.Clone(claudeViaShared(fold))
|
||||
}
|
||||
|
||||
// claudeViaShared is claudeViaMagpie without the caller's own copy, the
|
||||
// list kept, read only: for a caller appending it to a list of its own,
|
||||
// which copies it anyway (Claude Code's model field, 5 MB of forty polls
|
||||
// copied twice).
|
||||
func claudeViaShared(fold bool) []Option {
|
||||
key := "\x00claude-via"
|
||||
if fold {
|
||||
key += "-folded"
|
||||
}
|
||||
return builtOptions.get(key, func() []Option { return buildClaudeVia(fold) })
|
||||
return builtOptions.shared(key, func() []Option { return buildClaudeVia(fold) })
|
||||
}
|
||||
|
||||
// buildClaudeVia is claudeViaMagpie built afresh.
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@@ -42,6 +45,22 @@ func TestClaudeViaMagpieKept(t *testing.T) {
|
||||
if got := values(); !got["oa/gpt-5.4"] {
|
||||
t.Fatalf("a caller's write reached the options kept: %v", got)
|
||||
}
|
||||
// the model field appends the list kept to its own models: its
|
||||
// options are a list of their own too
|
||||
home := os.Getenv("HOME")
|
||||
writeFile(t, filepath.Join(home, ".claude", "settings.json"), `{}`)
|
||||
field := claude(home).Field("model").Options(map[string]string{})
|
||||
if !slices.ContainsFunc(field, func(o Option) bool { return o.Value == "oa/gpt-5.4" }) {
|
||||
t.Fatal("the model field doesn't offer oa's models")
|
||||
}
|
||||
for i := range field {
|
||||
field[i].Value = "x"
|
||||
}
|
||||
for _, fold := range []bool{false, true} {
|
||||
if slices.ContainsFunc(claudeViaMagpie(fold), func(o Option) bool { return o.Value == "x" }) {
|
||||
t.Fatalf("a write to the model field's options reached the options kept (folded %v)", fold)
|
||||
}
|
||||
}
|
||||
// folded and not are kept apart
|
||||
for _, o := range claudeViaMagpie(true) {
|
||||
if o.Value == "x" {
|
||||
|
||||
@@ -508,7 +508,7 @@ var wslKinds = []wslKind{
|
||||
case "model":
|
||||
// whether it has a base URL of its own is the distro's file
|
||||
return func(cur map[string]string) []Option {
|
||||
return append(group("Claude Code", claudeOwn(cur["model"], nil, catalog.Provider("anthropic"))), claudeViaMagpie(false)...)
|
||||
return append(group("Claude Code", claudeOwn(cur["model"], nil, catalog.Provider("anthropic"))), claudeViaShared(false)...)
|
||||
}
|
||||
case "effort", "ultracode":
|
||||
// their own options read only what was last seen
|
||||
|
||||
Reference in New Issue
Block a user