magpie icon indicating copy to clipboard operation
magpie copied to clipboard

[Bug] Docker 网关中 DSH 模型列表为空:visible all 的恢复提示无法清除模型隐藏状态

Open jinzheng8115 opened this issue 1 month ago • 3 comments

问题

远程服务器通过 Docker 部署 Magpie,本机 DeepSeek Harness Desktop 将 Magpie 的 OpenAI 兼容地址作为自定义提供商时,“获取可用模型”得到空列表。同一地址和 Key 在其他客户端能列出模型。

最终确认是 dsh 的模型可见性配置导致,并非 API Key、URL 或 DSH 的协议不兼容。但 CLI 提示的恢复命令无法恢复已有模型,连续执行仍返回空列表;最后通过备份并删除 hiddenModels.dsh 才恢复。

关联已关闭的 #3432:这里是远程 Docker 网关 + DSH 模型发现的同类实际案例,visible ... all 的恢复提示仍存在误导。

环境与边界

  • 服务端:Linux 服务器,Docker 容器运行 Magpie。
  • 客户端:本机 macOS 上的 DeepSeek Harness Desktop 0.2.1-rc.5,服务端不需要安装 DSH。
  • Magpie 容器的具体版本/镜像 digest 本次未记录,不以本机安装版本代替。
  • 本次目录中共有 13 个模型/路由组。初始“仅显示已选模型且没有任何选中项”的设置如何产生尚未确定,不认定为默认配置或自动迁移缺陷。

实际排查与复现过程

  1. DSH 请求 GET /v1/models 时带有:

    User-Agent: deepseek-harness/0.2.1-rc.5 (+https://github.com/deepseek-ai/deepseek-harness)
    

    对同一端点、同一 Key,仅切换 User-Agent:普通客户端得到非空模型列表;DSH 标识得到 HTTP 200 和空列表:

    {"data":[],"has_more":false,"object":"list"}
    

    后续确认这是 Magpie 将该客户端识别为 dsh 并应用模型展示配置的结果,而不是需要屏蔽或伪装 User-Agent。

  2. 在服务器查询:

    docker exec magpie /magpie visible dsh
    

    关键输出:

    ! dsh is shown none of them: it is shown only the models picked for it, and none is · tick some in its list on the Agents page, or magpie visible dsh --show-new
      dsh is shown only the models picked for it: 13 not picked, and a new one stays off until it is ticked · magpie visible dsh --show-new shows new ones
      dsh is shown every provider's models · magpie visible dsh <family>,… narrows it
    
  3. 按提示执行:

    docker exec magpie /magpie visible dsh --show-new
    

    输出变为:

    ✓ saved
    ! dsh is shown none of them: nothing is in  · magpie visible dsh all shows it every model
      13 taken out of dsh's list on the Agents page
      dsh is shown every provider's models · magpie visible dsh <family>,… narrows it
    
  4. 再按提示执行:

    docker exec magpie /magpie visible dsh all
    

    仍得到同样的关键输出:

    ✓ saved
    ! dsh is shown none of them: nothing is in  · magpie visible dsh all shows it every model
      13 taken out of dsh's list on the Agents page
      dsh is shown every provider's models · magpie visible dsh <family>,… narrows it
    

    命令提示会让用户重复执行无法解决当前状态的 all。其中 nothing is in 后的范围说明也是空白。

当前绕法与验证

容器 /config 为持久挂载。备份对应 magpie/settings.json 后,仅删除 hiddenModels 下的 dsh 项,不改动其他客户端的隐藏配置。

随后:

  • docker exec magpie /magpie visible dsh 正常列出 13 个模型/路由组;
  • 本机 DSH 重新获取模型列表并成功完成配置。

这证明当前案例的问题是客户端专属的模型展示配置。没有为了修复本问题而修改 DSH、API 地址、Key 或 User-Agent。

对当前主分支的核对

核对提交 30cd39f19b6dc5bde6432842bddfd916e2975780 的源码,行为与上述现象一致:

  • internal/cli/visible_cli.go:visible <agent> all 的实现只删除 Visible[id],不会清除 HiddenModels[id] 或 PickedModels[id],但帮助文字是 show the agent every model again。
  • internal/provider/visible.go:SetOnlyPicked(agent, false) 会把当前未选中的模型转换为 HiddenModels[agent],以保留当前展示状态。所以 --show-new 不会让已有的 13 个模型重新显示。这一策略本身可以合理,但不适合作为空列表的直接恢复建议。

期望改进

  1. 根据实际限制层生成准确的诊断:区分供应商/分组范围、仅选中模型模式、逐个模型的隐藏列表。当只有隐藏列表导致为空时,不再建议无法生效的 visible <agent> all。
  2. 在 CLI 提供明确的恢复入口,例如独立的“显示当前全部模型/清除隐藏列表”选项,或为指定 Agent 启用指定模型的命令;避免只能到 Agents 页面或手改 JSON。此处不要求取消用户有意设置的模型可见性策略。
  3. 帮助文档明确 all 的范围,并解释 --show-new 保留已有隐藏状态的含义。
  4. 增加回归覆盖:存在模型目录、dsh 的选中集合为空 → --show-new → all,确保最终诊断给出的恢复方法确实能解除对应限制。

jinzheng8115 avatar Oct 31 '26 14:10 jinzheng8115

take

ggbdpq avatar Nov 01 '26 09:11 ggbdpq

Fixed on top of 1adff3779 — the source-level diagnosis in this issue is exactly right, and visible <agent> all now does what its own hints promise.

Summary

magpie visible <agent> all removed only the visibility narrowing (Visible[agent]) and left HiddenModels[agent] and PickedModels[agent] in place, while every recovery hint promises a full recovery: magpie models says "magpie visible all shows it every model", so does the gateway's refusal to name a model, and the usage text says "show the agent every model again". An agent shown none of them — shown only the models picked for it with none picked, then switched to --show-new, which keeps what it is shown by writing the rest into HiddenModels — stayed empty through all, and the hint told the user to run all again; deleting hiddenModels.<agent> from settings.json was the only way back (#4587; #3432 is the same trap for an only-picked agent with some picks).

Root cause

SetOnlyPicked(agent, false) deliberately preserves what the agent is shown right now: everything not picked becomes a HiddenModels entry (#1337). That policy is fine — the issue says so too — but visible <agent> all, the one recovery command every hint points at, undid only the narrowing, so the 13 kept models stayed kept and the hint looped.

Fix

visible <agent> all now takes the per-model hidden list and the only-picked switch out together with the narrowing: typing all is the user explicitly asking for every model again, not a default that overwrites their picks. The per-model checkbox semantics on the Agents page, the settings API (which never overwrites these maps) and --show-new's keep-what-is-shown behavior are untouched. The usage line for all states the wider scope now; the recovery hints needed no wording change — they became true.

Verification

Check Result
New TestVisibleAllShowsTakenOutModels — the issue's exact sequence: only-picked with none picked → --show-new fills HiddenModels → all FAIL before the fix (the CLI printed the same "✓ saved / is shown none of them / 3 taken out" loop as reported), PASS after
New TestVisibleAllTakesOnlyPickedOut — #3432's variant: only-picked with 1 of 3 picked → all FAIL before, PASS after
Ablation: product file reverted to the branch's parent (1adff3779), tests kept both new tests fail again, PASS after restore
go test -tags nogui ./internal/cli/ (full package, sandboxed HOME) ok
Targeted tests with -race; gofmt -l; go vet; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; go build on darwin / linux / windows all pass

Not verified

Not run against a real Docker deployment or a real DSH Desktop client; the gateway's /v1/models narrowing reads the same CatalogFor lists the tests assert on, but the remote scenario itself is untested here.

Attribution: AI-written; I've read the whole diff and the tests pass. Please keep the author (ggbdpq) or add Co-authored-by: ggbdpq <[email protected]>.

patch: fix(cli): visible all clears the models taken out and the only-picked switch (#4587) — git am applies it as is; SHA-256 first 16: 9634b8d88f600888
From e581838db85923d69d76378e4f8385338e77110c Mon Sep 17 00:00:00 2001
From: ggbdpq <[email protected]>
Date: Sun, 1 Nov 2026 16:33:17 +0800
Subject: [PATCH] fix(cli): visible <agent> all clears the models taken out and
 the only-picked switch
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

What changed: `magpie visible <agent> all` took only the visibility
narrowing out, leaving HiddenModels and PickedModels in place. An agent
shown none of them — shown only the models picked for it with none picked,
then switched to --show-new, which keeps what it is shown by taking the
rest out — stayed none through `all`, the very recovery `magpie models`
and the gateway's refusal to name a model point at; only deleting
hiddenModels.<agent> from settings.json brought the models back (#4587, a
DSH behind a Docker gateway saw an empty model list; #3432, closed as not
planned, the same for an only-picked agent). `all` now takes the hidden
models and the only-picked switch out together with the narrowing, and its
usage line says so.

Run: go test ./internal/cli/ -run 'TestVisibleAll' -tags nogui — two new
tests fail before the change and pass after it.

Generated-by: GLM-5.3-Flash (ZCode)
---
 internal/cli/visible_cli.go      |  9 ++++-
 internal/cli/visible_cli_test.go | 69 ++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/internal/cli/visible_cli.go b/internal/cli/visible_cli.go
index 50920e361..d66bb958e 100644
--- a/internal/cli/visible_cli.go
+++ b/internal/cli/visible_cli.go
@@ -19,7 +19,8 @@ const visibleUsage = `usage:
   magpie visible <agent> <name>[,<name>…] show the agent only these: families (a tag set with
                                           magpie provider set <id> family=relay, or magpie group set),
                                           provider ids and group ids
-  magpie visible <agent> all              show the agent every model again
+  magpie visible <agent> all              show the agent every model again, the ones taken out of
+                                          its list one by one too
   magpie visible <agent> --only-picked    show the agent only the models ticked for it now; a model
                                           that comes later, of any provider, stays off until it is
                                           ticked in its list on the Agents page
@@ -102,6 +103,12 @@ func visibleCmd(args []string) error {
 	list := splitList(strings.Join(args[1:], ","))
 	if len(list) == 1 && strings.EqualFold(list[0], "all") {
 		delete(s.Visible, id)
+		// all is the recovery the hints point at (magpie models, the
+		// gateway's refusal to name a model): the models taken out of the
+		// agent's list one by one, and the only-picked switch, keep it
+		// shown none or fewer unless these go too (#4587)
+		delete(s.HiddenModels, id)
+		delete(s.PickedModels, id)
 	} else {
 		known := visibleNames()
 		for i, n := range list {
diff --git a/internal/cli/visible_cli_test.go b/internal/cli/visible_cli_test.go
index 0a66edff6..3b998f4a4 100644
--- a/internal/cli/visible_cli_test.go
+++ b/internal/cli/visible_cli_test.go
@@ -37,6 +37,75 @@ func TestVisibleKeyLowered(t *testing.T) {
 	}
 }
 
+// all shows the agent every model again: the models taken out of its list
+// one by one (HiddenModels) go with the narrowing, or the recovery the
+// hints point at doesn't. An agent shown none of them — only the models
+// picked for it, and none picked — stayed none through --show-new (which
+// keeps what it is shown by taking the rest out) and through all, and only
+// deleting hiddenModels.<agent> from settings.json brought the models
+// back (#4587: a DSH behind a Docker gateway saw an empty model list).
+func TestVisibleAllShowsTakenOutModels(t *testing.T) {
+	t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "config"))
+	if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2", "m3"}}); err != nil {
+		t.Fatal(err)
+	}
+	t.Cleanup(func() { provider.Delete("relay") })
+	if err := provider.SetOnlyPicked("dsh", true); err != nil {
+		t.Fatal(err)
+	}
+	if err := provider.SetPickedModels("dsh", nil); err != nil {
+		t.Fatal(err)
+	}
+	if shown, _ := provider.CatalogFor("dsh"); len(shown) != 0 {
+		t.Fatalf("want none picked, shown none; got %d", len(shown))
+	}
+	if err := visibleCmd([]string{"dsh", "--show-new"}); err != nil {
+		t.Fatal(err)
+	}
+	if ids := settings.Load().HiddenModels["dsh"]; len(ids) != 3 {
+		t.Fatalf("--show-new keeps what is shown by taking the rest out; hidden: %v", ids)
+	}
+	if shown, _ := provider.CatalogFor("dsh"); len(shown) != 0 {
+		t.Fatalf("want still none shown after --show-new; got %d", len(shown))
+	}
+	if err := visibleCmd([]string{"dsh", "all"}); err != nil {
+		t.Fatal(err)
+	}
+	if ids := settings.Load().HiddenModels["dsh"]; len(ids) != 0 {
+		t.Fatalf("all left %d taken out: %v", len(ids), ids)
+	}
+	if shown, _ := provider.CatalogFor("dsh"); len(shown) != 3 {
+		t.Fatalf("all shows %d of 3: %v", len(shown), shown)
+	}
+}
+
+// all takes the only-picked switch out too: an agent shown only the models
+// picked for it kept the ones not picked off through all, though the error
+// naming it says all shows it every model (#3432: zcode/GLM-5.3 stayed off
+// Claude Code after all).
+func TestVisibleAllTakesOnlyPickedOut(t *testing.T) {
+	t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "config"))
+	if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2", "m3"}}); err != nil {
+		t.Fatal(err)
+	}
+	t.Cleanup(func() { provider.Delete("relay") })
+	if err := provider.SetOnlyPicked("claude", true); err != nil {
+		t.Fatal(err)
+	}
+	if err := provider.SetPickedModels("claude", []string{"m1"}); err != nil {
+		t.Fatal(err)
+	}
+	if err := visibleCmd([]string{"claude", "all"}); err != nil {
+		t.Fatal(err)
+	}
+	if _, only := provider.PickedModels("claude"); only {
+		t.Fatal("all left claude shown only the models picked for it")
+	}
+	if shown, _ := provider.CatalogFor("claude"); len(shown) != 3 {
+		t.Fatalf("all shows %d of 3: %v", len(shown), shown)
+	}
+}
+
 // magpie models and magpie visible take a WSL agent by its id, in the
 // distro's own case or any other: before, both lowered what was typed and
 // then matched it exactly against ids that keep the distro's case (#271).
-- 
2.50.1 (Apple Git-155)

Branch with the commit: hunt115-d2-4587 (head e581838db85923d69d76378e4f8385338e77110c).

ggbdpq avatar Nov 01 '26 09:11 ggbdpq

Landed in v0.1.2652 as 3b7fe8e5f (ggbdpq's commit as it was). Without the change, TestVisibleAllShowsTakenOutModels and TestVisibleAllTakesOnlyPickedOut are red. Not tried: the real CLI against a live agent config.

What was run (mote, -tags nogui): every patch's own tests pass. With each patch's product change reverted by hand, its tests go red. At the rebased tree (bfa911da8 on origin/main d89f03aa9), these package runs (-timeout 45m) pass: library, provider, agent, netproxy, davsync and cli. In gateway every test passes except TestCodexPoolSaysTheClientsVersion, which is red the same way in a gateway run at d89f03aa9 alone (#4807). gofmt -l prints nothing; go vet passes for darwin, linux and windows. Provider, gui and library passed again after the final rebase. GUI: routing-classifier-said, routing-intent-fallback, routing-smart-intent and i18n-keys pass, 104 of 104, in chromium and webkit.

yetone avatar Nov 01 '26 21:11 yetone