agent: Claude Desktop is off magpie only when Desktop itself would be (dev_quj on X)

dev_quj on X: "magpie 一直提示Claude Desktop不经过magpie,我重启了依然还是
这个提示" — the Agents row said "已不经过 magpie:配置已变更" while
Desktop ran on magpie.

The check required deploymentMode "3p" in both Claude/ and
Claude-3p/claude_desktop_config.json. Desktop decides otherwise (m4 in
4.4212's and 2.7032's index.pre.js): with a 3p configuration applied it
starts in 3p when the profile has disableDeploymentModeChooser, whatever
deploymentMode says, and otherwise unless Claude-3p's file says "1p". The
Claude folder's deploymentMode is never read. And Desktop 4.4212 deletes
Claude-3p's deploymentMode itself: a stored "1p" with no claude.ai sign-in
is dropped at start (W5r -> "[custom-3p] deploymentMode written { mode:
undefined }") and Desktop relaunches in 3p on magpie. So a file left
without the key, by Desktop or another tool, was called off magpie, and
nothing magpie could do (Reconnect writes "3p" back) kept Desktop from
dropping it again.

desktop3p now asks Desktop's question with the applied profile (magpie's
or the user's for magpie's gateway). The appliedId, address and key
checks are as they were. appReads (the "restart Desktop" notice) reads
the same effective mode instead of the two files' words, so Desktop's own
write at start isn't a change to restart for.

Real Claude Desktop 4.4212.0 (macOS zip, on mote, sandbox
--user-data-dir, never the live config): three starts with magpie's
profile applied and Claude/ {} or "3p"; Claude-3p "1p" + chooser
disabled, "1p" + chooser not set, and {} — each ran in 3p with
apiHost=http://127.0.0.1:3425 in Claude-3p's main.log, and each left
Claude-3p's file without deploymentMode. The "1p", chooser-not-set case
started in 1p, logged "deploymentMode written { mode: undefined }" and
came back in 3p. An earlier start with both files "3p" kept them.

Run at the pushed head on mote (mote busy with other sessions' GUI and
gateway suites, so the touched package only, not the full suite):
go test -count=1 -timeout 45m ./internal/agent: ok
go vet, GOOS=linux go vet, GOOS=windows go vet ./internal/agent: ok
gofmt -l internal/agent: clean

Broken by hand: desktop3p put back to the old rule (both files "3p"):
TestClaudeDesktopModeAsDesktopReadsIt red on the dropped key, the Claude
folder's key gone, "1p" with the chooser disabled, and none with the
chooser on; TestClaudeDesktopChangedSince red too. Green with the fix.
TestClaudeDesktopMSIX and TestClaudeDesktopChangedSince's 1p cases now
turn the chooser on first, as Desktop needs for 1p to count.

Not tried: Windows' Desktop (MSIX or classic) and a real gateway request
from Desktop; a signed-in claude.ai cookie (Desktop keeps "1p" then,
which magpie says only with the chooser on); dev_quj's own files, so
this is the class the report is in, not their proven trigger. No other
desktop agent reads a mode the same way; Codex/WorkBuddy checks unchanged.
This commit is contained in:
yetone
2026-10-31 21:11:45 +08:00
parent ba7c890223
commit 3ecc02b78b
4 changed files with 113 additions and 12 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ something else shows up as drift.
- Codex's "subagent model" field writes nothing to Codex's config: its lead names each subagent's model in `spawn_agent`, which `[agents]` can't overrule. It is magpie's setting (`settings.CodexSubagentModel`, [`codex_subagent.go`](../../internal/provider/codex_subagent.go)), and the gateway moves the subagent's request onto it (see [gateway routing](gateway-routing.md)). Its options are every model and routing group Codex's own lists show (`CatalogFor("codex")`, so a model taken out of them or not picked is left out here too), ChatGPT accounts' first (#1633: a lead on a chat provider wants its subagents there too). A task a ChatGPT-backed lead sealed opens only on a ChatGPT account, so the gateway keeps such a subagent on its own model when the one set is another provider's. Its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup put back on another computer still applies (`ApplyFields` stops at the first failed Set), and refuses one of Codex's own bare names.
- Claude Desktop's "subagent model" field (`subagent_model`, `desktopSubagentField` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)) writes nothing to Desktop's config: Desktop runs its Code tab's Claude Code with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1`, under which Claude Code ignores `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` and the tier variables in its settings files' `env` ("Ignoring … this session's provider routing is managed by the host", Claude Code 2.1.295), and the env Desktop builds for the Code tab has no key for it (Desktop 2.31226). It is magpie's setting (`settings.DesktopSubagentModel`, [`desktop_subagent.go`](../../internal/provider/desktop_subagent.go)), and the gateway moves each subagent's turn onto it (see [gateway routing](gateway-routing.md)). It is labelled as Codex's, so the Agents page gives it the same square. Its options are magpie's models and groups as Desktop's list shows them (`viaMagpie("claude-desktop")`), while Desktop is on magpie, as for the tiers. A Desktop alias picked is kept by its catalog id (`DesktopCatalogID`). Like Codex's, its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup still applies, and refuses a bare name. It is `Live`: the gateway reads it on each request.
- Claude Desktop's "subagent effort" (`desktopSubagentEffortField`, `settings.DesktopSubagentEffort`) is also Quiet and Live. Default keeps the effort the request asks for, including disabled thinking; it never selects a new default. A picked level works independently of the subagent model: no model pick, the same model and an unavailable model pick all still take the effort. While wired, the field offers the selected model's levels, or the standard levels when its model is inherited or unavailable; a model marked reasonless offers none. The stored pick survives model changes. A disconnected preference can be saved or cleared without connecting Desktop or showing restart advice, so profile restoration and Disconnect can restore a value saved before connecting; reconnect returns to the last live pick. `subEffortTitle` gives Desktop the Claude Code default explanation; Codex's default meaning is unchanged. The gateway fits each attempt to its actual model and preserves fixed group-member efforts (see [gateway routing](gateway-routing.md)).
- Claude Desktop picks its userData in its main process before any window opens: while a 3p configuration is applied and `deploymentMode` isn't `"1p"`, it is `Claude-3p` (Desktop 2.7032's `index.pre.js`, `app.setPath("userData", …-3p)`). So turning Desktop onto magpie shows none of the chats, projects and Code sessions of the Anthropic sign-in, which stay in `Claude` (xgddm88 on X: 之前的工程和会话记录全没了). magpie writes nothing in `Claude` but `deploymentMode` in its `claude_desktop_config.json`, and reads its `config.json` for the language; Off brings that history back. A row not yet connected says so before it is turned on (`CONNECT_BEFORE` in `app.js`), the opened row once it is on (`CONNECT_COST`), and the notice after each change (`noticeClaudedesktop3`, `noticeClaudedesktop4`; `TestClaudeDesktopKeepsTheSignedInHistory`, `desktop-history.test.cjs`). Opus beside the gateway's other models in that mode comes from a Claude subscription added in magpie. With `disableDeploymentModeChooser` unset Desktop's login screen would offer Claude.ai sign-in too; magpie still seeds it (as CC Switch does), so the way back is Off.
- Claude Desktop picks its userData in its main process before any window opens: while a 3p configuration is applied and `deploymentMode` isn't `"1p"`, it is `Claude-3p` (Desktop 2.7032's `index.pre.js`, `app.setPath("userData", …-3p)`). So turning Desktop onto magpie shows none of the chats, projects and Code sessions of the Anthropic sign-in, which stay in `Claude` (xgddm88 on X: 之前的工程和会话记录全没了). magpie writes nothing in `Claude` but `deploymentMode` in its `claude_desktop_config.json`, and reads its `config.json` for the language; Off brings that history back. A row not yet connected says so before it is turned on (`CONNECT_BEFORE` in `app.js`), the opened row once it is on (`CONNECT_COST`), and the notice after each change (`noticeClaudedesktop3`, `noticeClaudedesktop4`; `TestClaudeDesktopKeepsTheSignedInHistory`, `desktop-history.test.cjs`). Opus beside the gateway's other models in that mode comes from a Claude subscription added in magpie. With `disableDeploymentModeChooser` unset Desktop's login screen would offer Claude.ai sign-in too; magpie still seeds it (as CC Switch does), so the way back is Off. The drift check asks Desktop's own question (`desktop3p`, `m4` in 4.4212's and 2.7032's `index.pre.js`): Desktop is off magpie only when Claude-3p's `deploymentMode` is `"1p"` and the applied profile leaves the chooser on. The `Claude` folder's `deploymentMode` isn't read, and Desktop 4.4212 deletes Claude-3p's itself (a stored `"1p"` with no claude.ai sign-in is dropped at start, `deploymentMode written { mode: undefined }`), so a missing one is still magpie (dev_quj on X; `TestClaudeDesktopModeAsDesktopReadsIt`).
- Claude Desktop's 3p mode runs in a userData of its own (`Claude-3p`), whose `config.json` (Desktop's own settings, not `claude_desktop_config.json`) starts with no `locale`, so Desktop on magpie came up in the system's language rather than the one picked signed in with Anthropic (memory and Osal on Discord). Turning Desktop onto magpie copies that one key, `locale`, from the signed-in userData's `config.json` (`Claude`, `%APPDATA%\Claude` on Windows, the first set's before the others) into `Claude-3p/config.json` when that file is missing or a JSON object without one (`desktopCarryLocale` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)); only a name Desktop takes for a catalog is carried. A `locale` already in `Claude-3p`, Desktop's or set by hand, is never written over, and no other key of that file is ever written. Off removes the file only when magpie made it and it still holds nothing but the language carried (`TestClaudeDesktopCarriesTheLanguage`, `TestClaudeDesktopKeepsThe3pLanguage`, `TestClaudeDesktopUserEditsThenReapply`). Desktop shows the language only where its 3p window has that catalog: the window is Desktop's bundled UI (`Resources/ion-dist`, 11 catalogs and no Chinese in 2.7032, 2.9939, 3.6556.2 and 4.4212.0 (packed as `Resources/ion-dist.asar` there), while 3.6556.2's main process has `zh-Hans` and `zh-Hant` for the signed-in window). On every start that window asks the main process for its own pick (`requestLocaleChange`: its localStorage, else `navigator.languages` mapped onto its 11, else `en-US`), and the main process writes it into `Claude-3p/config.json`. So a Chinese `locale` there, carried or set by hand, is `en-US` again after each start, written by Desktop and not by magpie (Dx25 on Discord, Windows); nothing magpie writes can keep it. So the GUI says it to a Chinese reader: Claude Desktop's opened row on Agents has a line that Desktop on magpie is Anthropic's gateway window, with no Chinese, and that its Chinese comes back once disconnected, and the switch-on notice says the same in Chinese (GZXYMH on X, `desktop-lang.test.cjs`).
- Claude Desktop's sessions (Code and Cowork, `claude-code-sessions` and `local-agent-mode-sessions`) are kept in the userData Desktop runs in, keyed by account and organization (the claude.ai login signed in; in 3p the install id in `ant-did` and the profile's organization, both stable). So on magpie, in `Claude-3p`, the sessions made signed in with Anthropic are out of sight but untouched in `Claude`, and they show again when Desktop is switched back (lambdua on X: "切换账号,对话都不见"); claude.ai chats live on Anthropic's servers and 3p never shows them. magpie never writes or removes a session. Desktop imports them itself (Settings → Import: the signed-in userData, `~/.claude/projects`, other `Claude*` folders), copying under new ids and leaving the originals, but in 3p only when the profile's policy `claudeAiImport.enabled` is true (off by default, 3p only, from 1.28929.0). magpie's profile gets `"claudeAiImport":{"enabled":true,"bannerBehavior":"detect"}` once per folder set (`desktopSeedImport`, marked in the stash as `claude-desktop.import`): on the switch on and, for a Desktop already on magpie, from `Sync` at magpie's start. A `claudeAiImport` already there is kept, and one the user removes is not written again (`TestClaudeDesktopOffersItsSessionImport`).
- Claude Desktop's 3p mode reads its MCP servers (Settings → Developer, its connector list) from `Claude-3p/claude_desktop_config.json`, a file of its own, so on magpie the servers the user added signed in with Anthropic, in `Claude/claude_desktop_config.json`, were gone from the list (aa86222 on Discord: connectors didn't sync). Turning Desktop onto magpie copies each of those `mcpServers` entries that `Claude-3p` has none of the same name for (`desktopCarryMCP` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)); one of that name already there, the user's or the Library's (which writes both files), stays. `Sync` does it once for a Desktop already on magpie (`claude-desktop.mcp-seen`), so a server the user takes out in 3p isn't brought back. What was copied is stashed (`claude-desktop.mcp`), and off takes back each one still as copied; one the user changed since stays (`TestClaudeDesktopCarriesTheMCPServers`, `TestClaudeDesktopMCPKeepsThe3pServers`, `TestClaudeDesktopSyncCarriesTheMCPServersOnce`). Claude's file is never written. A claude.ai account's connectors can't come along: Desktop calls them through claude.ai with that account (`/api/organizations/<org>/mcp/servers/<id>/tools/call`, refused with `no_active_org` without one, Desktop 2.7032), and 3p mode has no account; Anthropic's docs say "Made by Anthropic" connectors are only in standard Desktop, and others reach 3p through `managedMcpServers` or plugins (claude.com/docs/third-party/claude-desktop/extensions).
+11 -3
View File
@@ -238,11 +238,19 @@ func (a *Agent) appReads() (files []string, reads func() string) {
return files, func() string {
var b strings.Builder
for _, p := range ps {
m, _ := edit.GetJSON(p.config, "deploymentMode")
m3, _ := edit.GetJSON(p.config3p, "deploymentMode")
id, _ := edit.GetJSON(p.meta, "appliedId")
applied := p.prof
if f := desktopAppliedGateway(p); f != "" {
applied = f
}
// the mode Desktop starts in, not the files' words: it
// drops a stored deploymentMode itself (desktop3p)
mode := "1p"
if desktop3p(p, applied) {
mode = "3p"
}
prof, _ := edit.Read(p.prof)
b.WriteString(m + "\n" + m3 + "\n" + id + "\n")
b.WriteString(mode + "\n" + id + "\n")
b.Write(prof)
b.WriteString("\n")
// a profile of the user's for magpie's gateway, applied
+24 -6
View File
@@ -5,7 +5,9 @@ package agent
// Free account signed in sees only "Get Claude Code" there). The mode is
// claude_desktop_config.json's deploymentMode, in its own folder and in
// Claude-3p beside it; the gateway is a profile in Claude-3p/configLibrary,
// the one _meta.json applies:
// the one _meta.json applies. magpie writes "3p" in both, but Desktop reads
// only Claude-3p's, and not even that one when the profile disables its
// chooser (desktop3p):
//
// Claude/claude_desktop_config.json {"deploymentMode":"3p",…}
// Claude-3p/claude_desktop_config.json {"deploymentMode":"3p",…}
@@ -244,11 +246,6 @@ func desktopRead(ps []desktopPaths) []desktopPaths {
// desktopCheck is what keeps one set of Desktop's folders off magpie's
// gateway, "" for nothing.
func desktopCheck(p desktopPaths) string {
m, _ := edit.GetJSON(p.config, "deploymentMode")
m3, _ := edit.GetJSON(p.config3p, "deploymentMode")
if m != "3p" || m3 != "3p" {
return "Claude Desktop's deploymentMode (claude_desktop_config.json) is no longer 3p, so it signs in with Anthropic rather than using magpie"
}
prof := p.prof
if id, _ := edit.GetJSON(p.meta, "appliedId"); id != desktopProfileID {
// one for magpie's gateway the user applied is on magpie too
@@ -256,6 +253,9 @@ func desktopCheck(p desktopPaths) string {
return "Claude Desktop uses another gateway configuration now (appliedId in configLibrary/_meta.json), not magpie's"
}
}
if !desktop3p(p, prof) {
return "Claude Desktop's deploymentMode (Claude-3p/claude_desktop_config.json) is 1p now, so it signs in with Anthropic rather than using magpie"
}
want := agentKey("claude-desktop")
return wiringOff("Claude Desktop", prof, func(k string) (string, bool) {
v, ok := edit.GetJSON(prof, k)
@@ -276,6 +276,24 @@ func desktopCheck(p desktopPaths) string {
}, "inferenceGatewayBaseUrl", gateway.URL(), "inferenceGatewayApiKey", want)
}
// desktop3p: Desktop starts in its 3p mode with prof, the gateway profile
// it applies, as Desktop decides it (m4 in 4.4212's and 2.7032's
// index.pre.js): with the profile's disableDeploymentModeChooser, whatever
// deploymentMode says, and otherwise unless Claude-3p's
// claude_desktop_config.json holds "1p" — none is 3p. The Claude folder's
// deploymentMode isn't read, and Desktop deletes Claude-3p's itself: a
// stored "1p" with no claude.ai sign-in is dropped at start and Desktop
// relaunches in 3p ("deploymentMode written { mode: undefined }"), so
// requiring "3p" in both files called a Desktop on magpie off it (dev_quj
// on X: "已不经过 magpie:配置已变更" after a restart).
func desktop3p(p desktopPaths, prof string) bool {
if c, _ := edit.GetJSON(prof, "disableDeploymentModeChooser"); c == "true" {
return true
}
m, _ := edit.GetJSON(p.config3p, "deploymentMode")
return m != "1p"
}
// desktopKeyTaken: the gateway takes v where magpie gives Desktop want,
// as keyHolds says, or v is a key of magpie's own (gateway.Token, or one
// naming an agent) where want is one too: the gateway takes those alike.
+77 -2
View File
@@ -244,6 +244,65 @@ func TestClaudeDesktopKeepsTheUsers(t *testing.T) {
}
}
// dev_quj on X: "Claude Desktop 已不经过 magpie:配置已变更" after a
// restart, with Desktop on magpie. Desktop 4.4212 drops a stored
// deploymentMode itself and never reads the Claude folder's, so the check
// follows Desktop's own rule (desktop3p): off magpie only when Claude-3p
// says "1p" and the profile leaves Desktop's chooser on.
func TestClaudeDesktopModeAsDesktopReadsIt(t *testing.T) {
home, p := desktopSandbox(t)
a := claudeDesktop(home)
if err := a.Field("provider").Set("magpie"); err != nil {
t.Fatal(err)
}
quiet := func(why string) {
t.Helper()
if c := a.Check(); c != "" {
t.Errorf("%s: check %q", why, c)
}
if d := a.Drift(); d != nil && d.Kind == "unwired" {
t.Errorf("%s: drift %+v", why, d)
}
}
said := func(why string) {
t.Helper()
if c := a.Check(); !strings.Contains(c, "is 1p now") {
t.Errorf("%s: check %q", why, c)
}
if d := a.Drift(); d == nil || d.Kind != "unwired" {
t.Errorf("%s: drift %+v", why, d)
}
}
quiet("on")
// what 4.4212 writes at start ("deploymentMode written { mode: undefined }")
desktopWrite(t, p.config3p, `{"preferences":{"x":1}}`)
quiet("Claude-3p's deploymentMode dropped by Desktop")
desktopWrite(t, p.config, `{}`)
quiet("the Claude folder's deploymentMode gone")
desktopWrite(t, p.config3p, `{"deploymentMode":"1p"}`)
quiet("1p with the chooser off: Desktop starts in 3p")
if err := edit.SetJSON(p.prof, edit.KV{Path: "disableDeploymentModeChooser", Value: false}); err != nil {
t.Fatal(err)
}
said("1p picked in Desktop's chooser")
desktopWrite(t, p.config3p, `{}`)
quiet("none with the chooser on: Desktop starts in 3p")
desktopWrite(t, p.config3p, `{"deploymentMode":"1p"}`)
if err := a.Reapply(); err != nil {
t.Fatal(err)
}
quiet("after Reconnect")
// another gateway applied is still said
meta := desktopJSON(t, p.meta)
meta["appliedId"] = "mine"
b, _ := json.Marshal(meta)
desktopWrite(t, p.meta, string(b))
if c := a.Check(); !strings.Contains(c, "another gateway") {
t.Errorf("another profile applied: check %q", c)
}
}
// Desktop or the user changing things after magpie: Check says so, off
// leaves what they chose, and the profile the user's own settings in it.
func TestClaudeDesktopChangedSince(t *testing.T) {
@@ -271,10 +330,20 @@ func TestClaudeDesktopChangedSince(t *testing.T) {
if c := a.Check(); c != "" {
t.Errorf("check after on: %s", c)
}
// the Claude folder's deploymentMode is one Desktop doesn't read
desktopWrite(t, p.config, `{"deploymentMode":"1p"}`)
if c := a.Check(); c != "" {
t.Errorf("check: the Claude folder's 1p is said: %s", c)
}
// Claude-3p's is, with the profile's chooser on
if err := edit.SetJSON(p.prof, edit.KV{Path: "disableDeploymentModeChooser", Value: false}); err != nil {
t.Fatal(err)
}
desktopWrite(t, p.config3p, `{"deploymentMode":"1p"}`)
if c := a.Check(); c == "" {
t.Error("check: 1p is fine")
}
desktopWrite(t, p.config3p, `{"deploymentMode":"3p"}`)
// off: the user's 1p stays, their profile is applied again
if err := f.Set(""); err != nil {
t.Fatal(err)
@@ -533,8 +602,11 @@ func TestClaudeDesktopMSIX(t *testing.T) {
t.Errorf("check: %s", c)
}
// Desktop's chooser turns the real one back to 1p: the check says so
if err := edit.SetJSON(r.prof, edit.KV{Path: "disableDeploymentModeChooser", Value: false}); err != nil {
t.Fatal(err)
}
desktopWrite(t, r.config3p, `{"deploymentMode":"1p","preferences":{"x":1}}`)
if c := a.Check(); !strings.Contains(c, "no longer 3p") || !strings.Contains(c, r.dir3p) {
if c := a.Check(); !strings.Contains(c, "is 1p now") || !strings.Contains(c, r.dir3p) {
t.Errorf("check: %q", c)
}
desktopWrite(t, r.config3p, `{"deploymentMode":"3p","preferences":{"x":1}}`)
@@ -639,8 +711,11 @@ func TestClaudeDesktopMSIXChecksTheFoldersDesktopRuns(t *testing.T) {
}
// the one Desktop runs in, turned back to 1p, is said
r := desktopPathsOf(filepath.Join(local, "Claude"), real3p)
if err := edit.SetJSON(r.prof, edit.KV{Path: "disableDeploymentModeChooser", Value: false}); err != nil {
t.Fatal(err)
}
desktopWrite(t, r.config3p, `{"deploymentMode":"1p","preferences":{"x":1}}`)
if c := a.Check(); !strings.Contains(c, "no longer 3p") || !strings.Contains(c, real3p) {
if c := a.Check(); !strings.Contains(c, "is 1p now") || !strings.Contains(c, real3p) {
t.Fatalf("check: %q", c)
}
if d := a.Drift(); d == nil || d.Kind != "unwired" {