From 224ea7d5bee5759e1e2bfeac8aca4a0c3d9503a5 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 19 Oct 2026 12:00:12 +0800 Subject: [PATCH] catalog: a reset drops what a request built of the old catalog 5351343e7 keeps what a request built of the catalog for the next request within heldFor, dropped by every write magpie makes. A reset of models.dev's catalog (catalog.Reset) wasn't one of them: Sync tells Touched after it, but a Reset alone left the providers' entries with the old windows and output limits for up to a second, and Pi's and Crush's model lists written in that second carried them (TestPiModelsCarryMaxTokens, TestCrushModelsCarryMaxTokens red in the full run: "unknown output sent: ...maxTokens:131072"). Reset now tells Forget (provider.Changed) after it lets go of its lock. Test: TestHoldKeptUntilAWrite gains "the catalog reset". Broken by hand (Reset not telling Forget): red, "the catalog reset: built 0 times, want 1", and both agent tests red again; fixed, the agent tests pass 3 of 3. Run: go test ./internal/catalog -count 1: ok (3.4s); go test ./internal/provider -run TestHoldKeptUntilAWrite: ok; go test ./internal/agent -run 'TestPiModelsCarryMaxTokens|TestCrushModelsCarryMaxTokens' -count 3: ok; go vet ./internal/catalog ./internal/provider. --- internal/catalog/catalog.go | 10 ++++++++-- internal/provider/hold_test.go | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 82da1d966..a410b3870 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -615,12 +615,18 @@ func load() map[string]mdProvider { return mdev } -// Reset forgets the loaded catalog so the next call re-reads the cache. +// Reset forgets the loaded catalog so the next call re-reads the cache, +// and tells Forget: what the provider package built of the old one (the +// windows and output limits of its entries) is kept between requests +// for a moment, and would answer for the old catalog meanwhile. func Reset() { loadMu.Lock() - defer loadMu.Unlock() loaded = false mdev, images, windows, outputs, efforts, thinks, names, listed, canonical = nil, nil, nil, nil, nil, nil, nil, nil, nil + loadMu.Unlock() + if Forget != nil { + Forget() + } } // Sync downloads the models.dev catalog into CachePath. It serializes with diff --git a/internal/provider/hold_test.go b/internal/provider/hold_test.go index a7124d289..6b5c415e5 100644 --- a/internal/provider/hold_test.go +++ b/internal/provider/hold_test.go @@ -89,8 +89,8 @@ func TestHoldKeptForTheNextRequest(t *testing.T) { // What is held across requests is built again when anything it was built // from may have moved: a write that only tells filememo (settings.Save, an // account's file), the providers' or the settings' file written by -// another process (the CLI's "magpie group add"), and the groups served -// or not (GateGroups, ServeGroups). +// another process (the CLI's "magpie group add"), the groups served or +// not (GateGroups, ServeGroups), and the models.dev catalog read again. func TestHoldKeptUntilAWrite(t *testing.T) { defer func(d time.Duration) { heldFor = d }(heldFor) heldFor = time.Minute // a loaded machine's pause between requests isn't the change @@ -123,6 +123,9 @@ func TestHoldKeptUntilAWrite(t *testing.T) { os.WriteFile(settings.Path(), []byte(`{}`), 0o600) }}, {"the groups gated", func() { GateGroups(nil)() }}, + // models.dev's catalog read again: the entries' windows and + // output limits come from it (Pi's maxTokens, Crush's default) + {"the catalog reset", catalog.Reset}, } { was := n c.write()