oxsean asked for one place to turn a model (claude-fable-5) off for good:
not reached by a direct request, an old session, a routing group member,
a fallback, a sub-agent, count_tokens or a decision model.
What changed:
- settings.DisabledModels: patterns, an exact id or a glob (* any run, /
included; ? one), matched ignoring case against provider/model, the
bare id and its last segment (provider/disabled.go). Empty by default,
so nothing changes for anyone who doesn't set it.
- Lists: buildEntries (entriesOff) leaves a disabled model out of the
catalog, so /v1/models, agents' model files and pickers, Codex's list
and every group go without it; membersIn skips it as a member, Deciders
as a decision model; codexModels drops Codex's own disabled slugs and
codexListTag changes so Codex refetches.
- Requests (gateway/disabled.go): 403 "model <id> is disabled in magpie"
in each API's error shape, at #882's choke points: serve (idOff),
perKeyBarred (no candidate: group next member, provider Fallback),
count_tokens and Gemini :countTokens, serveSystemOne,
serveDecisionGroup and postDecide, draw/video/embeddings, and
codexBackend for Codex's own bare models. A group with a member left
goes on without it; one with none left is refused naming them. A bare
id the catalog no longer has is refused as disabled, not 404. A Codex
sub-agent pick onto a disabled model stays on its lead's model.
- An unreadable settings.json is never "none disabled": the list read
last stays; with none read, every request is refused; nothing is
written over the file.
- CLI: magpie model disable <model|glob>..., enable ..., disabled
(list-disabled).
- GUI: Settings > Models > Disabled models: each pattern with the models
it matches now and Enable; Disable... opens the model picker, which
also takes a typed glob. Says only requests through magpie are covered.
POST /api/settings/disabled-models; POST /api/settings keeps the list.
Strings in zh, zh-TW, ja, de.
- docs/subsystems/gateway-routing.md: Disabled models section.
What was run (worktree at origin/main 091593f7d, private GOCACHE, temp HOME):
- gofmt -l clean; go vet on darwin (touched pkgs), GOOS=linux -tags nogui
./..., GOOS=windows ./... clean; go build ./...
- go test -count=1 ./internal/provider ./internal/gateway ./internal/cli
./internal/gui ./internal/settings: all ok (gui after adding the field to
TestSettingsSaveKeepsWhatItDoesNotSend's fixture, which it asked for).
- node --test internal/gui/tests/disabled-models.test.cjs: 16/16 (chromium
+ webkit, en/zh/ja/de, 1100/420); neighbouring Settings > Models tests
and i18n-keys: 131/131.
- Broken by hand, each turned TestDisabled* red: serve's idOff (404
instead of 403), perKeyBarred's filter (fallback reached spare), the
catalog filter (/v1/models and Codex list), countOff (count_tokens 200),
postDecide's check (decision call went out).
- Not tried with a real vendor account or a real agent.
Ref #1867
71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agentenv"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Settings' disabled models (#1867) are set on their own: the page is told
|
|
// each pattern with the models it turns off, a disabled model leaves the
|
|
// models it may pick, and the page's other saves, which never send the
|
|
// list, keep it.
|
|
func TestDisabledModelsSetting(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1", "claude-fable-5"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
type state struct {
|
|
DisabledModels []string `json:"disabledModels"`
|
|
DisabledHits map[string][]string `json:"disabledHits"`
|
|
TitleModels []struct{ ID string } `json:"titleModels"`
|
|
}
|
|
call := func(path, body string) (int, state) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var out state
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
return rec.Code, out
|
|
}
|
|
ids := func(s state) []string {
|
|
var out []string
|
|
for _, m := range s.TitleModels {
|
|
out = append(out, m.ID)
|
|
}
|
|
return out
|
|
}
|
|
code, out := call("/api/settings/disabled-models", `{"models":["*fable*"," ","*FABLE*"]}`)
|
|
if code != 200 || !slices.Equal(out.DisabledModels, []string{"*fable*"}) || !slices.Equal(out.DisabledHits["*fable*"], []string{"fake/claude-fable-5"}) {
|
|
t.Fatalf("%d %+v", code, out)
|
|
}
|
|
if got := ids(out); slices.Contains(got, "fake/claude-fable-5") || !slices.Contains(got, "fake/m1") {
|
|
t.Fatalf("pickable %v", got)
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || !slices.Equal(settings.Load().DisabledModels, []string{"*fable*"}) {
|
|
t.Fatalf("another save (%d) lost the list: %v", code, settings.Load().DisabledModels)
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark","disabledModels":[]}`); code != 200 || !slices.Equal(settings.Load().DisabledModels, []string{"*fable*"}) {
|
|
t.Fatalf("the page's save cleared the list (%d): %v", code, settings.Load().DisabledModels)
|
|
}
|
|
if code, out := call("/api/settings/disabled-models", `{"models":[]}`); code != 200 || len(out.DisabledModels) != 0 || !slices.Contains(ids(out), "fake/claude-fable-5") {
|
|
t.Fatalf("enabled: %d %+v", code, out)
|
|
}
|
|
}
|