agent: dsh on a DeepSeek model picked in its own /model stays connected while magpie's route is in its list (Fate on Discord: DSH went back to Not connected) — magpie connects dsh by putting its route among dsh's custom providers and starting it on one of magpie's models; a model of DeepSeek's own picked in dsh is saved in its settings.yaml over the patch list, and the Agents page, which called an agent connected only when its model field was magpie's, showed it Not connected, though the route, its key and magpie's models in dsh's /model were all still there. dsh now has Joined (the first profile's patch list has magpie's route), as Codex signed in with ChatGPT does, so it reads Connected · pick magpie's models with /model, and a pick off magpie while joined isn't drift ("changed outside magpie"). Disconnect in that state has an Unwire that takes the route, the start magpie wrote and the key out of every profile and .env and leaves the model picked in dsh; on one of magpie's models it does nothing and the model set back does it all, as before. TestDshOwnPickStaysConnected (connect, a DeepSeek pick in settings.yaml: wired, no drift; Disconnect: the template as it was, no key, the pick kept) fails on the old code. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.

This commit is contained in:
yetone
2026-10-04 22:03:41 +08:00
parent ee3fca6375
commit 2dc8e249cb
3 changed files with 107 additions and 1 deletions
+4 -1
View File
@@ -135,9 +135,12 @@ func (a *Agent) Drift() *Drift {
}
}
rec := appliedOf(a.ID)
// still joined, a model off magpie is one picked in the agent, beside
// magpie's in its list (dsh's /model), not a change from outside
joined := a.Joined != nil && a.Joined()
for _, f := range a.Fields {
want, ok := rec.Fields[f.Key]
if !ok || vals[f.Key] == want || !magpieValue(a, f, want, vals) || magpieValue(a, f, vals[f.Key], vals) || sameGroup(want, vals[f.Key]) {
if !ok || joined || vals[f.Key] == want || !magpieValue(a, f, want, vals) || magpieValue(a, f, vals[f.Key], vals) || sameGroup(want, vals[f.Key]) {
continue
}
return &Drift{Kind: "replaced", Field: f.Key, Now: vals[f.Key], Want: want,
+27
View File
@@ -112,6 +112,33 @@ func dshAt(at place) *Agent {
return strings.Join(notes, " ")
},
Check: func() string { return dshCheck(dir, gw()) },
// a model of DeepSeek's own picked in dsh (saved in its settings)
// leaves magpie's route in its list: dsh is still connected, its
// /model has magpie's models beside DeepSeek's (Fate on Discord:
// DSH went back to Not connected)
Joined: func() bool {
files := dshProfiles(dir)
if len(files) == 0 {
return false
}
_, items, err := dshRead(files[0])
return err == nil && dshWired(items)
},
// connected so, Disconnect takes the route out, the start magpie
// wrote and its key; the model picked in dsh stays its own
Unwire: func() error {
if usesMagpie(dshGet(dir)) {
return nil // the model set back does it all
}
dshWrites.Lock()
defer dshWrites.Unlock()
for _, f := range dshProfiles(dir) {
if err := dshSetFile(f, "", true, nil, gw()); err != nil {
return err
}
}
return dshEnv(dir, false)
},
Fields: []Field{{
Key: "model", Label: "model",
Get: func() string { return dshGet(dir) },
+76
View File
@@ -0,0 +1,76 @@
package agent
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A model of DeepSeek's own picked in dsh's /model, which dsh saves in its
// settings over the patch list, leaves dsh connected: magpie's route is
// still in its list, beside DeepSeek's (Fate on Discord: DSH went back to
// Not connected). Disconnect then takes the route, magpie's start and its
// key out, and the model picked in dsh stays.
func TestDshOwnPickStaysConnected(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("DSH_HOME", "")
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
if err := provider.Save(provider.Provider{ID: "glm", Name: "GLM", Chat: "https://glm.test/v1", Key: "k", Models: []string{"glm-5.3"}}); err != nil {
t.Fatal(err)
}
dir := filepath.Join(home, ".dsh")
template := "# Your patch layer for this dsh profile.\n[]\n"
web := filepath.Join(dir, "profiles", "web", "cordis.patch.yml")
os.MkdirAll(filepath.Dir(web), 0o755)
os.WriteFile(web, []byte(template), 0o644)
settings := filepath.Join(dir, "settings.yaml")
read := func(p string) string { b, _ := os.ReadFile(p); return string(b) }
a := dsh(home)
if a.Wired() {
t.Fatal("wired before anything")
}
if err := a.Pick("model", "magpie/glm/glm-5.3"); err != nil {
t.Fatal(err)
}
if !a.Wired() {
t.Fatal("not wired on magpie's model")
}
// picked in dsh: DeepSeek's own
os.WriteFile(settings, []byte("ui:\n theme: dark\nagent-default-model:\n provider: deepseek-official\n model: deepseek-v4-flash\n"), 0o644)
if got := a.Field("model").Get(); got != "deepseek-v4-flash" {
t.Fatalf("model: %q", got)
}
if !a.Wired() {
t.Fatal("dsh went back to Not connected with magpie's route still in its list")
}
if d := a.Drift(); d != nil {
t.Fatalf("drift: %+v", d)
}
if err := a.Disconnect(); err != nil {
t.Fatal(err)
}
if a.Wired() {
t.Fatal("still wired after Disconnect")
}
if got := read(web); got != template {
t.Fatalf("the patch list after Disconnect:\n%q", got)
}
if strings.Contains(read(filepath.Join(dir, ".env")), dshKeyRef) {
t.Fatal("the key outlived the route")
}
if s := read(settings); !strings.Contains(s, "model: deepseek-v4-flash") || !strings.Contains(s, "theme: dark") {
t.Fatalf("the pick made in dsh was lost:\n%s", s)
}
if got := a.Field("model").Get(); got != "deepseek-v4-flash" {
t.Fatalf("model after Disconnect: %q", got)
}
}