Opening DeepSeek's editor and pressing Save without changing anything hung
for seconds (witt-bit, still on v0.1.1246). Save stored providers.json
whatever it held, and every store calls catalog.Touched, which runs
agent.SyncCatalog: every set-up agent's config built and written again
(Claude Code, Codex, Pi, dsh, Hermes, Grok, ZCode and the rest), synchronously
in the save request. Goroutine dumps every ~100ms during a save in a sandbox
HOME with the owner's providers and agents' configs (no credentials) showed
the save handler runnable in SyncCatalog the whole time, not waiting on
network or a lock. Save now compares what it would store with what is
stored and, when they are the same bytes, writes nothing and tells no agent.
A save that changes something still does both.
Measured in that sandbox (magpie web, Playwright clicking DeepSeek > Save):
before 1616, 5407, 1843 ms for POST /api/provider/save; after 212, 132, 145,
147 ms, and providers.json's md5 the same before and after.
Tests: TestSaveUnchangedTellsNoAgent (new) fails on the old Save ("an
unchanged save told the agents 1 times; want none") and passes now.
Full suite: SUITE_LINE
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// Save pressed on a provider's editor left as it was writes nothing and
|
|
// hands the agents nothing: each hand-over re-wrote every agent's config,
|
|
// seconds with many agents set up, and the DeepSeek editor's Save hung on
|
|
// it (#1962, witt-bit). A save that changes something still tells them.
|
|
func TestSaveUnchangedTellsNoAgent(t *testing.T) {
|
|
limitsHome(t)
|
|
in := Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "sk-1", Models: []string{"deepseek-v4-flash", "deepseek-v4-pro"}}
|
|
if err := Save(in); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, err := os.ReadFile(Path())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
told := 0
|
|
catalog.Changed = func() { told++ }
|
|
t.Cleanup(func() { catalog.Changed = nil })
|
|
|
|
if err := Save(in); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if told != 0 {
|
|
t.Errorf("an unchanged save told the agents %d times; want none", told)
|
|
}
|
|
after, err := os.ReadFile(Path())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(before, after) {
|
|
t.Errorf("an unchanged save rewrote providers.json:\n%s\nwas\n%s", after, before)
|
|
}
|
|
|
|
in.Key = "sk-2"
|
|
if err := Save(in); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if told != 1 {
|
|
t.Errorf("a new key told the agents %d times; want once", told)
|
|
}
|
|
if p, err := Find("deepseek"); err != nil || p.Key != "sk-2" {
|
|
t.Errorf("the new key wasn't saved: %+v, %v", p, err)
|
|
}
|
|
}
|