claude: Fetch models fetches models.dev's list first when it is old, so Fable 5.2 shows (hhdaxia on X)
hhdaxia on X (magpie 0.1.3504, Linux): the Claude subscription's Models editor, "vendor list · just now" after Fetch models again, lists Fable 5.1 and the 5.5s but not Fable 5.2, which Claude Code's own /model has. Cause: a Claude account's list is models.dev's anthropic list plus what Claude Code's .claude.json says beyond it (magpie asks Anthropic nothing). Its fetch rebuilt that list from the local models.dev cache, which is fetched again only once it is a day old. models.dev added claude-fable-5-2 after the user's last daily sync, so every fetch that day answered without it. Claude Code builds /model from the catalog baked into its binary (2.1.321 and the latest 2.1.322 both have latest_per_family fable: claude-fable-5-2), not from its bootstrap's additionalModelOptionsCache (here still only claude-fable-5-1[1m]), so nothing in .claude.json would have given it either. Not Linux-specific. Fix: catalog.Asked, called by the Claude account's fetch, syncs models.dev first when the cache is older than 10 minutes and wasn't tried in that time, bounded by the fetch's context; a failure is logged and the local catalog answers. Only in a process that keeps the catalog fresh (the app, magpie serve), so CLI commands and tests never reach the network. Subsystem page updated. Run on mote at59d9f5c7dplus this change: gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... ok; go test -count=1 ./internal/catalog ./internal/provider ok (0.8s, 156s). TestClaudeFetchAsksModelsDevForANewModel: a two-hour-old catalog without Fable 5.2, a fake models.dev with it; the fetch lists it first, a second fetch asks nothing more, and outside KeepFresh nothing is asked. Rebased onto5e6fb2770(54 files in internal/catalog and internal/provider changed) and run again at this tree on mote: go test -count=1 -run 'Claude|Fable|KeepFresh|Sync' ./internal/catalog ./internal/provider ok (0.6s, 30s). Broken by hand: with the catalog.Asked call taken out of the fetch the test is red ("Fable 5.2 not first after a fetch: [claude-haiku-5-5 claude-opus-5-5] (0 asks of models.dev)"). Real: a throwaway program on mote with a sandbox cache holding only Fable 5.1, three hours old, called catalog.Asked against the real https://models.dev/api.json: after it, claude-fable-5-2 is listed (1.9s). Not tried: the GUI click with a real Claude account; the full suite runs after the push and a red gets an issue.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -60,6 +60,48 @@ func Missing() {
|
||||
go fetch()
|
||||
}
|
||||
|
||||
// askedAfter is how old the catalog may be when a list made of it alone
|
||||
// is asked for again (Asked).
|
||||
var askedAfter = 10 * time.Minute
|
||||
|
||||
// Asked says a model list made of the catalog alone is being fetched: a
|
||||
// Claude subscription's, which is models.dev's anthropic list, as magpie
|
||||
// asks Anthropic nothing in Claude Code's name. The catalog is fetched
|
||||
// now, as long as ctx allows, when it is older than askedAfter and wasn't
|
||||
// tried in that time, so a model launched since the day's fetch is on the
|
||||
// list the user asked for (hhdaxia on X: Fable 5.2, on models.dev and in
|
||||
// Claude Code's /model, not after Fetch models again). Only in a process
|
||||
// that keeps the catalog fresh (KeepFresh), one fetch at a time, and a
|
||||
// failed one leaves the catalog as it was.
|
||||
func Asked(ctx context.Context) {
|
||||
if !keeping.Load() || time.Since(time.Unix(0, lastFetch.Load())) < askedAfter {
|
||||
return
|
||||
}
|
||||
if src := Source(); src != "" {
|
||||
if st, err := os.Stat(src); err == nil && time.Since(st.ModTime()) < askedAfter {
|
||||
return
|
||||
}
|
||||
}
|
||||
if !fetching.CompareAndSwap(false, true) {
|
||||
return
|
||||
}
|
||||
defer fetching.Store(false)
|
||||
lastFetch.Store(time.Now().UnixNano())
|
||||
if err := Sync(ctx); err != nil {
|
||||
log.Println("catalog:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// KeepFreshForTest has the catalog kept fresh from url, as the app's
|
||||
// backend keeps it from models.dev, for a test of what asks for it.
|
||||
func KeepFreshForTest(url string) (restore func()) {
|
||||
was := modelsDevURL
|
||||
modelsDevURL = url
|
||||
keeping.Store(true)
|
||||
lastFetch.Store(0)
|
||||
return func() { modelsDevURL = was; keeping.Store(false); lastFetch.Store(0) }
|
||||
}
|
||||
|
||||
// fetch is Sync with a bound, one at a time.
|
||||
func fetch() {
|
||||
if !fetching.CompareAndSwap(false, true) {
|
||||
|
||||
@@ -879,7 +879,10 @@ func claudeProvider(acct *Account) Provider {
|
||||
// Claude's models are the ones magpie knows and the ones Claude Code
|
||||
// was told an account has (claude_models.go): listing them would ask
|
||||
// Anthropic with the account's sign-in, which magpie never does
|
||||
acct.fetch = func(context.Context) ([]catalog.Model, error) {
|
||||
acct.fetch = func(ctx context.Context) ([]catalog.Model, error) {
|
||||
// models.dev's list, fetched again first when it is older than
|
||||
// a few minutes: a model launched since the day's sync is listed
|
||||
catalog.Asked(ctx)
|
||||
ms := claudeModels()
|
||||
return ms, catalog.SaveLive("claude", claudeBase, ms)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -208,3 +211,65 @@ func TestClaudeAccountListsFable52(t *testing.T) {
|
||||
t.Fatalf("not served beside picks of every model listed before: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch models again on a Claude subscription fetches models.dev's list
|
||||
// first when the catalog magpie keeps is older than a few minutes: a
|
||||
// model launched since the day's sync is on the list the user asked for
|
||||
// (hhdaxia on X: Fable 5.2 in Claude Code's /model, on models.dev, and
|
||||
// not in the vendor's list "just now" fetched). Outside a process that
|
||||
// keeps the catalog fresh (a CLI command, a test) nothing is fetched.
|
||||
func TestClaudeFetchAsksModelsDevForANewModel(t *testing.T) {
|
||||
home := claudeHome(t)
|
||||
claudeSignIn(t, home, time.Now().Add(time.Hour))
|
||||
t.Cleanup(catalog.Reset)
|
||||
var hits atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
hits.Add(1)
|
||||
w.Write([]byte(`{"anthropic":{"id":"anthropic","name":"Anthropic","models":{` + mdOpus55 + "," + mdHaiku55 + "," + mdFable52 + `}}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
// the day's sync, two hours before Fable 5.2 reached models.dev
|
||||
writeAnthropicCatalog(t, mdOpus55, mdHaiku55)
|
||||
old := time.Now().Add(-2 * time.Hour)
|
||||
if err := os.Chtimes(catalog.CachePath(), old, old); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fetch := func() []string {
|
||||
t.Helper()
|
||||
p, ok := find(All(), "claude")
|
||||
if !ok || p.Account == nil {
|
||||
t.Fatalf("claude: %+v %v", p, ok)
|
||||
}
|
||||
ms, err := p.Fetch(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return modelIDs(ms)
|
||||
}
|
||||
|
||||
t.Cleanup(catalog.KeepFreshForTest(srv.URL))
|
||||
if got := fetch(); len(got) == 0 || got[0] != "claude-fable-5-2" {
|
||||
t.Fatalf("Fable 5.2 not first after a fetch: %v (%d asks of models.dev)", got, hits.Load())
|
||||
}
|
||||
p, _ := find(All(), "claude")
|
||||
if !slices.ContainsFunc(p.Available(), func(m catalog.Model) bool { return m.ID == "claude-fable-5-2" }) {
|
||||
t.Fatalf("Fable 5.2 not served: %v", modelIDs(p.Available()))
|
||||
}
|
||||
// fetched again at once: models.dev is asked nothing more
|
||||
fetch()
|
||||
if n := hits.Load(); n != 1 {
|
||||
t.Fatalf("%d asks of models.dev, want 1", n)
|
||||
}
|
||||
|
||||
// a process that doesn't keep the catalog fresh asks nothing
|
||||
catalog.KeepFreshForTest(srv.URL)()
|
||||
writeAnthropicCatalog(t, mdOpus55)
|
||||
os.Chtimes(catalog.CachePath(), old, old)
|
||||
if got := fetch(); slices.Contains(got, "claude-fable-5-2") {
|
||||
t.Fatalf("models.dev asked outside KeepFresh: %v", got)
|
||||
}
|
||||
if n := hits.Load(); n != 1 {
|
||||
t.Fatalf("%d asks of models.dev, want 1", n)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user