From e2a65cbc9bd4c8d2d14eabc24611b6ee5f4131a9 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 20:12:31 +0800 Subject: [PATCH] dsh: a start on a found group's old id moves onto the id its route lists (zyh6036 on X) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zyh6036 on X: DeepSeek Harness Desktop showed no model after magpie turned dsh on and the app restarted, while the profile's patch file was full of magpie's gateway. Cause: a dsh start (agent-default-model) magpie had set to a found routing group keeps the id the group had then, group/auto-. Since 81a24cf8f the group is listed as auto/, and that is the only id magpie's routes list. dsh looks up the start by route and id, finds nothing, and shows "Select model" with nothing picked. The owner's live desktop profile was in this state: the start was "group/auto-gpt-6-sol" and the route listed auto/gpt-6-sol. renameFoundGroups never reached it, because it moves only values that applied.json records, and there was no dsh record there. Fix: dshStartOnItsRoute already moves a start onto the route its model is on now. It now also moves a start whose id magpie no longer lists it by (provider.PublicRef for a found group, provider.RenamedRef for a renamed provider) onto the id the route lists. The effort and the other keys in the entry stay. It runs on every route write, in every profile (desktop, web, CLI) and in the home layer, so KeepDshWired repairs an existing install within a round. The fix is not OS-specific. Run at this head (rebased on bb5eb83c3), on mote (macOS) through mote-run: - go test ./internal/agent ./internal/provider -count=1 -timeout 45m: ok (284s, 164s) - go test ./internal/agent -run 'Dsh|FoundGroup|Drift|Keeps': ok - GOOS=windows go vet ./...: ok - GOOS=linux go vet ./internal/agent ./internal/provider: ok (a GOOS=linux vet of ./... from macOS stops in wails' cgo files) - go vet ./internal/agent (darwin): ok - gofmt -l: clean The full suite was not run, so that another session's suite on mote isn't held up (one full suite per machine). Only internal/agent changed. The -run 'Dsh|...' subset ran before the rebase. Broken by hand: with dsh.go at HEAD, TestDshStartOnAFoundGroupsOldIdMovesOntoItsId fails, and the start stays "group/auto-pro" in the web profile. Real app: DeepSeek Harness 0.2.1-rc.5 on mote, each run in a sandbox HOME and DSH_HOME: - Fresh wiring shows magpie's models, whether the app was opened first or magpie wrote first. - A copy of the owner's live desktop patch: every route is listed, but the seat reads "Select model". - The same copy with the start as the fix writes it (auto/gpt-6-sol): the seat reads "GPT-6 Sol · routing group High", ticked in the picker. Not tried: - Running the fixed magpie binary itself against that copy. The unit test covers the magpie side. - Windows' desktop app. - Whether zyh6036's install was in this state. A store or key that doesn't resolve also empties the list (seen with no key at all), and their reply will say which. --- docs/subsystems/agent-wiring.md | 2 +- internal/agent/dsh.go | 24 +++++++++++++++------ internal/agent/dsh_route_test.go | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 7c0c16c60..ee434de78 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -70,7 +70,7 @@ something else shows up as drift. - Each model magpie writes into ZCode's `providerModelRules` has native web search (`properties.supportsNativeWebSearch`, "原生联网搜索") on while the provider's format is Anthropic Messages, the only format ZCode sends it on (`zcodeWebSearch`). The models magpie turned it on for are kept in the stash under `zcode.web_search`, so a model the user unticked in ZCode (which takes the key out of the rule) stays off, a value in the rule stays, a manual rule is left alone, and a stash that can't be read turns nothing on. On another format magpie's own on is taken out. Disconnect forgets the list. - The YAML ones go through `yamlKept` and `mergeKept` in [`sync.go`](../../internal/agent/sync.go). Each is tested by a `TestKeepsTheUsersSettings`. - Copilot in JetBrains IDEs keeps its Bring Your Own Key providers in the Copilot language server's `byok.json`, shared with Xcode's and Eclipse's Copilot (`copilotJetBrains` in [`copilotjetbrains.go`](../../internal/agent/copilotjetbrains.go)). magpie writes its own three keys there, `magpie-provider-config`, `magpie-api-key` and `magpie-models-config`, in the bytes the server itself writes, and only when they differ; the user's providers and keys stay. A magpie model the user hid in Manage Models (`isRegistered: false`) stays hidden through a sync. A new file is made 0600 in a 0700 folder, as the server makes it. -- dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (`dshKinds` in [`dsh.go`](../../internal/agent/dsh.go); 01huadalang on Discord): `magpie` (Chat Completions) for most models, `magpie-responses` (`openai-responses`) for a model served on Responses, `magpie-anthropic` (`anthropic-messages`, the gateway root, `forceAdaptiveThinking` where `AdaptiveThinking` or `AdaptiveWithEffort`, so Max reaches GLM-5.3 as max) for one served on Messages, by the model's `APIs` (`dshRouteOf`). A model's `APIs` is the one its provider serves it on best (`Provider.Native`, in `magpieModels`, [`route.go`](../../internal/agent/route.go)), and Pi, omp and droid read it the same way. For a custom provider with more than one URL that is the API its Base URL was given as (`BaseAPI`), after the vendor rules (an OpenAI model on OpenAI's API, a Claude where Messages is served): a relay set to Responses whose Chat URL Detect found beside it had its GPTs on dsh's Chat route (nb5p on Discord, `TestDshCustomResponsesProvider`). dsh's bundled pi-ai (`@earendil-works/pi-ai`, dsh 0.2.1-rc.2) takes `openai-responses` as a route's `api`. A routing group has `responses` when every member is best on Responses (`allResponses`, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (`agent-default-model`) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (`dshStartOnItsRoute`), its effort and marks kept. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id. +- dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (`dshKinds` in [`dsh.go`](../../internal/agent/dsh.go); 01huadalang on Discord): `magpie` (Chat Completions) for most models, `magpie-responses` (`openai-responses`) for a model served on Responses, `magpie-anthropic` (`anthropic-messages`, the gateway root, `forceAdaptiveThinking` where `AdaptiveThinking` or `AdaptiveWithEffort`, so Max reaches GLM-5.3 as max) for one served on Messages, by the model's `APIs` (`dshRouteOf`). A model's `APIs` is the one its provider serves it on best (`Provider.Native`, in `magpieModels`, [`route.go`](../../internal/agent/route.go)), and Pi, omp and droid read it the same way. For a custom provider with more than one URL that is the API its Base URL was given as (`BaseAPI`), after the vendor rules (an OpenAI model on OpenAI's API, a Claude where Messages is served): a relay set to Responses whose Chat URL Detect found beside it had its GPTs on dsh's Chat route (nb5p on Discord, `TestDshCustomResponsesProvider`). dsh's bundled pi-ai (`@earendil-works/pi-ai`, dsh 0.2.1-rc.2) takes `openai-responses` as a route's `api`. A routing group has `responses` when every member is best on Responses (`allResponses`, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (`agent-default-model`) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (`dshStartOnItsRoute`), its effort and marks kept. A start on a model by an id magpie lists it by no longer, a found group's `group/auto-` (now `auto/`, `provider.PublicRef`) or a renamed provider's (`provider.RenamedRef`), moves onto the id its route lists, in every profile and the home layer: dsh finds the start by that id, and the desktop app showed no model picked while its patch list held every route (zyh6036 on X, `TestDshStartOnAFoundGroupsOldIdMovesOntoItsId`). `renameFoundGroups` moves only a value applied.json records, and the start dsh read was not one (none on the owner's install either), nor is a pick made in dsh. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id. - The names every agent's model list gets are `provider.Labels`' ([`modelprefs.go`](../../internal/provider/modelprefs.go)). With Provider in model names off (or own, for names the user gave), a name stands alone unless another model in the same list reads the same, when both keep their provider's after it. A routing group named as anything else in the list keeps "· routing group", and the model it shares the name with stays plain: the group found for a model served by two providers, one of them hidden from the agent, had the shown model read "GPT-6.1 Terra · MyGateway" beside its provider's plain "GPT-6.1 Sol" (nb5p on Discord; `TestPlainNames`, `TestSuffixMode`, `TestPlainOwnNamesGroups`). - dsh takes a model's listed `maxTokens` as every request's output and reserves it, with 65536 of headroom, out of `contextWindow` before deciding when to compact (compaction-basic's `resolveCompactSpec`: the smaller of 80% of the window and window − maxTokens − 65536). A vendor's reply limit near its window had dsh compact at 41248 of a 500000 group (#2823) or fail with no budget (524288/524288, LoKi on Discord; 131072/65536), so magpie lists it held to what leaves dsh half the window to compact in (window/2 − 65536), or to a quarter of the window where that is more (every window under 262144, as VS Code and Copilot in JetBrains hold it), on every route and in the older `llm-deepseek` entry (`dshMaxTokens`). A quarter alone cut DeepSeek's 393216 on its 1000000 window to 250000 (#3298); now it keeps all of it and dsh compacts at 541248, while 500000/393216 is held to 184464 and compacts at 250000. A Max output the user set stays as they set it (`outputOr`), even one that leaves dsh no budget. `TestDshOutputLeavesCompactionRoom`. - While magpie serves, `KeepDshWired` writes the routes again every 30 seconds, since dsh writes over its patch list. A round that writes nothing is kept (`dshRounds`), and the next round does nothing when nothing it reads has changed since. It checks the bytes of dsh's files (every profile's `cordis.patch.yml`, the home layer, `settings.yaml`, `.env`, `.credentials.yaml`, `config.yaml`) and the gateway's address. It also checks `provider.StampNow`: no Changed, plugin change or `filememo.Forget`, the same environment, and the providers', settings' and catalog's files unchanged. The models are built again when that stamp moves, and at least every `dshModelsFor` (5 minutes) for what no stamp sees, such as another app's account file or a date-retired model. Building the whole catalog and every route each round allocated 12 GB of a user's 35.7 GB in 48 minutes (`TestDshRoundWithNothingChangedBuildsNothing`, `TestDshRoundAfterAChangeWritesAgain`). diff --git a/internal/agent/dsh.go b/internal/agent/dsh.go index cff60ff8e..55648c514 100644 --- a/internal/agent/dsh.go +++ b/internal/agent/dsh.go @@ -1672,8 +1672,12 @@ func dshKindConfig(k dshKind, models []catalog.Model, api, gw string) dshPiRoute // dshStartOnItsRoute moves a start (agent-default-model) on a model of // magpie's to the route that model is on now: dsh finds a model by its // route and id, and fails a session started on a route that no longer has -// it. The model, effort and everything else in the entry stay, and so does -// a start on a model magpie no longer gives dsh (dshCheck says so). +// it. A start on a model by an id magpie lists it by no longer (a found +// group's group/auto-, now auto/; a renamed provider's) moves +// onto the id the route lists: dsh finds no model by the old one, and its +// desktop app showed no model picked (zyh6036 on X). The effort and +// everything else in the entry stay, and so does a start on a model magpie +// no longer gives dsh (dshCheck says so). func dshStartOnItsRoute(items []dshItem, models []catalog.Model) []dshItem { for i, it := range items { if it.id != "agent-default-model" { @@ -1683,13 +1687,18 @@ func dshStartOnItsRoute(items []dshItem, models []catalog.Model) []dshItem { if !isDshRoute(c["provider"]) || c["model"] == "" { continue } - want := "" - for _, m := range models { - if m.ID == c["model"] { - want = dshRouteOf(m) + want, id := "", c["model"] + for _, ref := range []string{id, provider.PublicRef(id), provider.RenamedRef(id), provider.PublicRef(provider.RenamedRef(id))} { + for _, m := range models { + if m.ID == ref { + want, id = dshRouteOf(m), ref + } + } + if want != "" { + break } } - if want == "" || want == c["provider"] { + if want == "" || want == c["provider"] && id == c["model"] { continue } n, err := dshNode(it) @@ -1697,6 +1706,7 @@ func dshStartOnItsRoute(items []dshItem, models []catalog.Model) []dshItem { continue } yamlSetKey(yamlMapping(n, "config"), "provider", &yaml.Node{Kind: yaml.ScalarNode, Value: want}) + yamlSetKey(yamlMapping(n, "config"), "model", &yaml.Node{Kind: yaml.ScalarNode, Value: id, Style: yaml.DoubleQuotedStyle}) if lines, err := dshNodeLines(n); err == nil { items[i].lines = lines } diff --git a/internal/agent/dsh_route_test.go b/internal/agent/dsh_route_test.go index 538e5a342..0c21f2333 100644 --- a/internal/agent/dsh_route_test.go +++ b/internal/agent/dsh_route_test.go @@ -816,3 +816,40 @@ func TestDshPickSaysOldSessionsKeepTheirModel(t *testing.T) { t.Fatalf("an old dsh not running was told something: %q", n) } } + +// zyh6036 on X: dsh's desktop app showed no model picked, while its patch +// list was full of magpie's routes. magpie had set it to start on a found +// group by the id it had then, group/auto-; the group is listed as +// auto/ since, and dsh finds a start by the id on its route, so it +// found none. The start moves onto the id the route lists, in each +// profile, the desktop app's too, and in the home layer; the effort stays. +func TestDshStartOnAFoundGroupsOldIdMovesOntoItsId(t *testing.T) { + _, dir, web := dshRouteHome(t) + dshKeyFixture(dir) + // deepseek and spare both serve pro: magpie finds the group + if err := provider.Save(provider.Provider{ID: "spare", Name: "Spare", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"pro"}}); err != nil { + t.Fatal(err) + } + if got := provider.PublicRef("group/auto-pro"); got != "auto/pro" { + t.Fatalf("the found group is listed as %q", got) + } + desktop := filepath.Join(dir, "profiles", "desktop", "cordis.patch.yml") + os.MkdirAll(filepath.Dir(desktop), 0o755) + start := "- id: agent-default-model\n config:\n provider: magpie\n model: \"group/auto-pro\"\n reasoningEffort: \"high\"\n" + for _, f := range []string{web, desktop} { + os.WriteFile(f, []byte("# Your patch layer for this dsh profile.\n"+dshRouteFixture("auto/pro")+start), 0o644) + } + home := dshHomePatch(dir) + os.WriteFile(home, []byte(dshRouteFixture("auto/pro")+start), 0o644) + dshWiredOnce() + for _, f := range []string{web, desktop, home} { + b, _ := os.ReadFile(f) + s := string(b) + if !strings.Contains(s, "- id: auto/pro") { + t.Fatalf("%s: the route has not the group:\n%s", f, s) + } + if strings.Contains(s, "group/auto-pro") || !strings.Contains(s, " provider: magpie\n model: \"auto/pro\"\n reasoningEffort: \"high\"\n") { + t.Fatalf("%s: the start is not on the id its route lists:\n%s", f, s) + } + } +}