dsh: the model shown is the start of the profile in use, and the round's log says what it wrote (#5222)

#5222: with DeepSeek Harness Desktop and four profiles, the desktop
profile started on hy4free while web, headless and open-design started
on deepseek-v4.1-flash, and magpie's log said "wrote dsh's route again"
every half minute or so. Read against dsh 0.2.1-rc.2's own source and
reproduced in a sandbox HOME with dsh's real save (saveSelection through
ConfigEditor.edit and its yaml 2.9.1 library):

- dsh saves a model picked in it into the profile in use alone. The
  profiles drifting apart is dsh's design, and each start is the user's
  own: magpie copies it nowhere.
- magpie never wrote over that pick. After dsh's save the next round
  wrote once, moving magpie's web search entry to follow the new start,
  and then wrote nothing. The log called that "wrote dsh's route again",
  which read as magpie rewriting agent-default-model.
- magpie read the start from the web profile alone, so with the desktop
  app in use the Agents page showed a model its sessions don't start on,
  and picking what it showed changed nothing there.
- A session dsh already has keeps the model of its last request until a
  model is picked in it (selectionFor in dsh-api-session-controller), as
  noticeDsh1 says. The reporter's 429s were OpenCode Zen Free's own free
  limit, reached by a session still on it; the gateway didn't change the
  model.

Now the model and effort fields read the desktop profile when DeepSeek
Harness Desktop is installed (dshLead), else web's as before, and effort
levels are checked against that model. The round logs "dsh's web search
in <file> follows the model it starts on now" when that entry is all it
moved; "wrote dsh's route again" is kept for the route itself.

Run (mote, on origin/main 7dd2434d3; rebased onto 78128b510, which touches
no internal/agent file, and -run TestDsh ./internal/agent run again at
the pushed head: ok):
- go test -run TestDsh ./internal/agent: ok
- go test ./internal/agent, go vet ./internal/agent with GOOS linux and
  windows, gofmt -l: ok (internal/agent 230.6s)
- TestDshShowsTheStartOfTheProfileInUse uses the bytes dsh's own save
  wrote in the sandbox.

Broken by hand, each red:
- dshLead ignoring the desktop profile: "model shown =
  magpie/deepseek/pro, want the desktop profile's magpie/deepseek/flash".
- the search-only write logged as a route write: "the round's log doesn't
  say its one write was the search entry".

Not tried: the real DeepSeek Harness Desktop app with the reporter's
profiles; a user who runs dsh's web profile while the desktop app is
installed still sees the desktop profile's start. Not changed: magpie's
writers find the first agent-default-model entry while dsh writes the
last (dshFind vs findLastIndex); no profile with two was seen (#5229).
This commit is contained in:
yetone
2026-11-04 19:23:49 +08:00
parent 461f9b1ff9
commit 844c355059
3 changed files with 183 additions and 29 deletions
+74 -27
View File
@@ -171,7 +171,7 @@ func dshAt(at place) *Agent {
// 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)) {
if usesMagpie(dshGet(dir, false)) {
return nil // the model set back does it all
}
dshWrites.Lock()
@@ -201,7 +201,7 @@ func dshAt(at place) *Agent {
},
Fields: []Field{{
Key: "model", Label: "model",
Get: func() string { return dshGet(dir) },
Get: func() string { return dshGet(dir, desktop()) },
Set: func(v string) error {
// the desktop app not opened yet, or a dsh that hasn't
// booted a profile: the profile is made as dsh makes it,
@@ -233,8 +233,8 @@ func dshAt(at place) *Agent {
// own levels), llm-deepseek's before (off, low, high or max;
// dsh's own default is high)
Key: "effort", Label: "thinking",
Get: func() string { return dshGetEffort(dir) },
Set: func(v string) error { return dshSetEffort(dir, v, gw()) },
Get: func() string { return dshGetEffort(dir, desktop()) },
Set: func(v string) error { return dshSetEffort(dir, v, gw(), desktop()) },
Options: func(cur map[string]string) []Option {
// a model through magpie that lists no levels has none in
// dsh (its route gives it no reasoningEfforts), so none is
@@ -821,14 +821,37 @@ func dshRouteLists(route *yaml.Node, id string) bool {
var dshModelLine = regexp.MustCompile(`^\s+model:\s*(.+?)\s*$`)
// dshGet reads the model new sessions start on: the one last picked in dsh,
// saved in its settings (0.1.x), else the patch list's.
func dshGet(dir string) string {
// dshLead is the profile whose start magpie shows: the desktop app's when
// DeepSeek Harness Desktop is installed (desktop), else the first, web's;
// "" before profiles. dsh saves a model picked in it into the profile in
// use alone (ConfigEditor.edit in dsh-config-editor), so the profiles can
// start on different models, each the user's own. Read from web's alone,
// the Agents page showed a model the desktop app's sessions don't start
// on, and picking what it showed changed nothing there (#5222).
func dshLead(dir string, desktop bool) string {
files := dshProfiles(dir)
if len(files) == 0 {
return ""
}
if desktop {
for _, f := range files {
if filepath.Base(filepath.Dir(f)) == "desktop" {
return f
}
}
}
return files[0]
}
// dshGet reads the model new sessions start on: the one last picked in dsh,
// saved in its settings (0.1.x), else the patch list's, the lead profile's
// (dshLead).
func dshGet(dir string, desktop bool) string {
f := dshLead(dir, desktop)
if f == "" {
return dshGetLegacy(filepath.Join(dir, "config.yaml"))
}
_, items, err := dshRead(files[0])
_, items, err := dshRead(f)
if err != nil {
return ""
}
@@ -894,7 +917,7 @@ func dshGetLegacy(path string) string {
// 0.1.5 — the key it names gone from .env, or another key under that name in
// dsh's own store, which it reads first.
func dshCheck(dir, gw string) string {
if !usesMagpie(dshGet(dir)) {
if !usesMagpie(dshGet(dir, false)) {
return ""
}
files := dshProfiles(dir)
@@ -2176,12 +2199,22 @@ func dshStartsOnMagpie(dir string, items []dshItem) bool {
// read: with none there is no route to write, and writing an empty one
// would take a working list away.
func dshRouteAgain(f string, models []catalog.Model, gw string) (bool, error) {
what, err := dshRouteAgainSaid(f, models, gw)
return what != "", err
}
// dshRouteAgainSaid is dshRouteAgain saying what it wrote, for the log:
// "route", or "search" when only magpie's web search entry moved to follow
// the model the profile starts on now — what dsh's own save of a model
// picked in it leaves for the next round, which is not magpie writing over
// that pick (#5222); "" for nothing written.
func dshRouteAgainSaid(f string, models []catalog.Model, gw string) (string, error) {
if len(models) == 0 {
return false, nil
return "", nil
}
raw, err := edit.Read(f)
if err != nil {
return false, nil
return "", nil
}
head, items, err := dshParse(f, string(raw))
if err != nil || !dshWired(items) {
@@ -2192,24 +2225,32 @@ func dshRouteAgain(f string, models []catalog.Model, gw string) (bool, error) {
// still on the old wiring is dshSync's to move (dshMove), not this
// round's to write beside.
if err != nil || dshOldWiring(items) || !dshStartsOnMagpie(dirOf(f), items) {
return false, nil
return "", nil
}
return dshWriteParsed(f, head, items, models, gw, raw)
written, err := dshWriteParsed(f, head, items, models, gw, raw)
if !written {
return "", err
}
return "route", err
}
before := dshJoin(items)
if items, err = dshPutRoute(items, true, models, gw); err != nil {
return false, nil
return "", nil
}
what := "search"
if dshJoin(items) != before {
what = "route"
}
if dshProfileList(f) {
items = dshSearchAgain(items, dshProfileHome(f), gw)
}
if dshJoin(items) == before {
return false, nil
return "", nil
}
if now, err := edit.Read(f); err != nil || !bytes.Equal(now, raw) {
return false, nil
return "", nil
}
return true, dshWrite(f, head, items)
return what, dshWrite(f, head, items)
}
// dshProfileList reports whether f is a profile's own patch list rather than
@@ -2436,13 +2477,17 @@ func dshWiredWith(dir string, files []string, models []catalog.Model) string {
}
files = append(files, dshHomePatch(dir)) // left as it is without magpie's route
for _, f := range files {
written, err := dshRouteAgain(f, models, gateway.URL())
what, err := dshRouteAgainSaid(f, models, gateway.URL())
if err != nil {
trouble = append(trouble, fmt.Sprintf("writing dsh's route again in %s: %s", f, dshWriteError(err)))
continue
}
if written {
switch what {
case "route":
log.Printf("wrote dsh's route again in %s", f)
case "search":
// agent-default-model left as dsh saved it (#5222)
log.Printf("dsh's web search in %s follows the model it starts on now", f)
}
}
// deepseek-acp's, which dsh 0.2 takes away at each start
@@ -2619,17 +2664,18 @@ func dshFiles(dir string) []string {
// writes them: every profile's (web's first), else config.yaml.
func DshPatchFiles(dir string) []string { return dshFiles(dir) }
// dshGetEffort reads the effort sessions start with.
func dshGetEffort(dir string) string {
files := dshProfiles(dir)
if len(files) == 0 {
// dshGetEffort reads the effort sessions start with, in the lead profile
// (dshLead).
func dshGetEffort(dir string, desktop bool) string {
f := dshLead(dir, desktop)
if f == "" {
_, items, err := dshRead(filepath.Join(dir, "config.yaml"))
if err != nil {
return ""
}
return dshEffortIn(items)
}
_, items, err := dshRead(files[0])
_, items, err := dshRead(f)
if err != nil {
return ""
}
@@ -2638,8 +2684,9 @@ func dshGetEffort(dir string) string {
// dshSetEffort writes v as the effort sessions start with: into
// agent-default-model (0.1.5 on), or into magpie's llm-deepseek entry
// before, dsh's own row being used whole when there is none.
func dshSetEffort(dir, v, gw string) error {
// before, dsh's own row being used whole when there is none. The levels
// offered are the lead profile's model's (dshLead), as the picker shows it.
func dshSetEffort(dir, v, gw string, desktop bool) error {
dshWrites.Lock()
defer dshWrites.Unlock()
files := dshProfiles(dir)
@@ -2647,7 +2694,7 @@ func dshSetEffort(dir, v, gw string) error {
if dshHomeHas(dir, "agent-default-model") {
files = append(files, dshHomePatch(dir))
}
model := dshGet(dir)
model := dshGet(dir, desktop)
ref, viaGateway := strings.CutPrefix(model, magpieID+"/")
levels := dshEfforts
if viaGateway {
+107
View File
@@ -0,0 +1,107 @@
package agent
import (
"bytes"
"log"
"os"
"path/filepath"
"strings"
"testing"
)
// #5222: DeepSeek Harness Desktop with four profiles (desktop, web,
// headless, open-design). A model picked in dsh is saved by dsh into the
// profile in use alone (ConfigEditor.edit), so the desktop profile started
// on hy4free while web, headless and open-design still started on
// deepseek-v4.1-flash. magpie read web's start alone: the Agents page showed
// a model the desktop app's sessions don't start on, and its log said
// "wrote dsh's route again" each time the round moved magpie's web search
// entry after dsh's save, which read as magpie writing over the pick.
//
// The desktop profile's bytes here are what dsh 0.2.1-rc.2's own save
// (dsh-agent-default-model saveSelection through the yaml 2.9.1 library)
// wrote over magpie's entry in a sandbox: the value unquoted, the effort
// added, magpie's comment kept.
func TestDshShowsTheStartOfTheProfileInUse(t *testing.T) {
home, dir, web := dshRouteHome(t)
dshKeyFixture(dir)
apps := t.TempDir()
was := appFolders
appFolders = func() []string { return []string{apps} }
t.Cleanup(func() { appFolders = was })
files := map[string]string{"web": web}
for _, p := range []string{"desktop", "headless", "open-design"} {
f := filepath.Join(dir, "profiles", p, "cordis.patch.yml")
if err := os.MkdirAll(filepath.Dir(f), 0o755); err != nil {
t.Fatal(err)
}
files[p] = f
}
for _, f := range files {
if err := os.WriteFile(f, []byte(dshProfileTemplate), 0o600); err != nil {
t.Fatal(err)
}
}
a := dsh(home)
if err := a.Field("model").Set("magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
dshWiredOnce()
read := func(p string) string { b, _ := os.ReadFile(files[p]); return string(b) }
ours := "- id: agent-default-model # magpie\n config:\n provider: magpie\n model: \"deepseek/pro\"\n"
saved := "- id: agent-default-model # magpie\n config:\n provider: magpie\n model: deepseek/flash\n reasoningEffort: high\n"
desk := read("desktop")
if !strings.Contains(desk, ours) {
t.Fatalf("magpie's start isn't as this test expects:\n%s", desk)
}
if err := os.WriteFile(files["desktop"], []byte(strings.Replace(desk, ours, saved, 1)), 0o600); err != nil {
t.Fatal(err)
}
// no desktop app: the web profile is the one shown, as before
if got := dsh(home).Field("model").Get(); got != "magpie/deepseek/pro" {
t.Fatalf("without the desktop app the model shown = %q, want web's magpie/deepseek/pro", got)
}
installApp(t, apps, "DeepSeek Harness.app", dshAppPlist)
a = dsh(home)
if got := a.Field("model").Get(); got != "magpie/deepseek/flash" {
t.Fatalf("model shown = %q, want the desktop profile's magpie/deepseek/flash, the one its sessions start on", got)
}
if got := a.Field("effort").Get(); got != "high" {
t.Fatalf("effort shown = %q, want the desktop profile's high", got)
}
// the rounds leave dsh's pick where dsh saved it and copy it nowhere:
// each profile's start is the user's own
var buf bytes.Buffer
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(os.Stderr) })
for range 3 {
var r dshRounds
if trouble := r.once(); trouble != "" {
t.Fatalf("round: %s", trouble)
}
}
log.SetOutput(os.Stderr)
if desk := read("desktop"); !strings.Contains(desk, saved) {
t.Fatalf("the rounds wrote over dsh's own pick:\n%s", desk)
}
for _, p := range []string{"web", "headless", "open-design"} {
if !strings.Contains(read(p), ours) {
t.Fatalf("the %s profile's start moved:\n%s", p, read(p))
}
}
// the one write: magpie's web search entry follows the desktop's start
if !strings.Contains(read("desktop"), " model: \"deepseek/flash\"\n") {
t.Fatalf("magpie's web search entry didn't follow the start:\n%s", read("desktop"))
}
said := buf.String()
if strings.Count(said, "dsh's web search in "+files["desktop"]+" follows the model it starts on now") != 1 {
t.Fatalf("the round's log doesn't say its one write was the search entry:\n%s", said)
}
if strings.Contains(said, "wrote dsh's route again") {
t.Fatalf("the round says it wrote dsh's route again, with the route as it was:\n%s", said)
}
}
+2 -2
View File
@@ -285,7 +285,7 @@ func TestDshSetEffortLeavesALegacyEntryWithNoCatalogAlone(t *testing.T) {
if err := os.WriteFile(path, []byte(own), 0o644); err != nil {
t.Fatal(err)
}
if err := dshSetEffort(dir, "high", gateway.URL()); err == nil {
if err := dshSetEffort(dir, "high", gateway.URL(), false); err == nil {
t.Fatal("an empty catalog should refuse the write")
}
if b, _ := os.ReadFile(path); string(b) != own {
@@ -312,7 +312,7 @@ func TestDshSetEffortWritesALegacyEntryWithTheCatalog(t *testing.T) {
if err := os.WriteFile(path, []byte("# mine\n- id: llm-deepseek # magpie\n config:\n models:\n - id: \"deepseek/pro\"\n"), 0o644); err != nil {
t.Fatal(err)
}
if err := dshSetEffort(dir, "high", gateway.URL()); err != nil {
if err := dshSetEffort(dir, "high", gateway.URL(), false); err != nil {
t.Fatal(err)
}
b, _ := os.ReadFile(path)