Commit Graph
50 Commits
Author SHA1 Message Date
yetone 608c1543e8 gateway: a bare model name goes to the asking agent's own subscription first
freefcw on X: Codex, started by Mirasim, asked for gpt-6-astra by its bare
name. Its own ChatGPT subscription serves it, but magpie sent it to Devin
through the group it found (auto-gpt-6-astra, soonest renewal first).
With found groups off it still went to another vendor: Resolve takes the
first provider in the Providers order, AutoStandIn and agent.Reseat did
the same.

Now:
- A bare model id the asking agent's own subscription in magpie serves (a
  provider whose Account.Agent is the agent: Codex's ChatGPT accounts,
  Claude's for Claude Code, Copilot's) goes there, found groups on or off
  (gateway ownFirst, provider.OwnRoute). count_tokens counts it there too.
- Kept as they were: a group the user made or changed by that name; a found
  group magpie set one of the agent's fields to (agent.SetToGroup over the
  applied record, #750's bare spelling included, wired as
  gateway.SetToGroup); a gateway key held to some models; ids with a
  provider in them and group refs; clients magpie doesn't know as an agent.
- Found groups off: a bare id several providers serve, none of them the
  agent's own, is refused for an agent that has a subscription of its own
  in magpie, with a 400 naming the provider/model ids and
  "magpie group auto on" (provider.OffSpread). Off, magpie picks no vendor.
- AutoStandInFor and Reseat's sameModel prefer the agent's own
  subscription for a found group that is gone.

Docs: gateway-routing.md's Model resolution row and the bare-ids section.

Run (mote, at this tree on c7ebb6f8d):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/agent ./internal/cli ./internal/gateway: all ok.

Broken by hand, each red:
- ownFirst off in serve (and AutoStandIn back):
  TestBareNameGoesToTheAgentsOwnSubscription went to the relay with groups
  on, and again with groups off alone (the reporter's two cases).
- OffSpread check off: TestBareNameOnSeveralVendorsRefusedWhileGroupsOff
  answered 200 from the relay.
- SetToGroup check off: TestBareNameOfAGroupSetOnTheAgentStaysTheGroups.
- The user's-group and own-entry checks off: TestOwnRoute, TestOffSpread.

Not run at this head: the full ./... suite (mote's suite.lock had five
suites queued); it runs under the lock after the push, any red filed.
Not tried: a real Codex with a real Devin plugin account; Reseat's own
preference has no test of its own (needs a fetched Codex account in the
agent package's sandbox).

Reported-by: freefcw (X)
2026-11-09 16:28:02 +08:00
JoeyWu-techandyetone 6cfe786351 agent: Codex that can't be joined again isn't connected by its helper models alone (#3868)
why8023: Codex switched off and on again showed 「已接入」 with its
subagents' and memories' models back, while its own model never reached
magpie. fae438b4a (NancyTom18 on X) made reconnect call Join first, which
fixed the ChatGPT sign-in case, but where Join can't apply then (a
model_provider of the user's own, magpie API) reconnect still put the
helper fields back alone and answered Wired(), which a helper field on
one of magpie's models makes true. So the switch said connected while
Codex's own turns went to the user's provider.

Now, when Join doesn't join and the model Codex was on wasn't one of
magpie's, reconnect gives up and the switch connects Codex as at first,
on one of magpie's models. Where its model was magpie's, that model
routes it, as before. docs/subsystems/agent-wiring.md says so.

coffemon's (JoeyWu-tech) patch 9ee95ba9, re-ported onto fae438b4a: main
already joins first, so only the !ok check is taken, with his
TestCodexOffAndOnJoinsAgainWithItsHelpersOnMagpie (seven cases, all
green on main too since fae438b4a). TestCodexOwnProviderOffAndOnIsNot-
ConnectedByItsHelpers is new and covers the case that was left: a relay
model_provider, Connect, subagents' model on magpie, gpt-5.5 picked
back, off and on.

Run (mote-run, macOS, go1.26.8, -tags nogui):
- the new test: ok. With the check turned off by hand (if false && ...):
  red, "on again ({How:again ...}) with its own model off magpie".
- TestCodexOffAndOnJoinsAgainWithItsHelpersOnMagpie,
  TestCodexReconnectStaysJoined, TestCodexConnectKeepsItsPick,
  TestReconnectKeepsTheLastPick, TestCodexDisconnectStaysWithAccountsOn
  and the OpenCode/OpenChamber tests: ok.

Not tried: the Agents page and a real Codex on a relay afterwards; the
test drives ConnectHow and Disconnect, which the switch calls, with
config.toml in a sandbox HOME.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).

Co-authored-by: yetone <9rqwv2ak@gmail.com>
2026-11-03 20:38:11 +08:00
yetone c1457f2eec agent: Drift makes a field's options once a look
Drift asked magpieValue up to three times a field: once to find the
field on magpie's models, then for magpie's record and the value now.
Each ask made the field's options anew, and Claude Code's (its own
models and claudeViaMagpie) are long. fieldOptions keeps each field's
options, by key, for one Drift; magpieValue is unchanged for the other
callers.

Run on mote at this tree:
- gofmt clean; go vet ./internal/agent ok on darwin, GOOS=windows and
  GOOS=linux.
- TestDriftMakesAFieldsOptionsOnce ok 3 of 3 alone. Broken by hand
  (opts left nil in Drift): "one Drift made the field's options 3
  times, want once".
- go test ./internal/agent: ok (324.6s).

Real accounts (sandbox copy of the owner's config, network blocked,
40 rounds of /api/drift, /api/state, /api/providers), v0.1.2488 tree
against this one:
- Drift 54.3 -> 45.3 MB, magpieValue 47.1 -> 42.6 MB, claudeIn.func57
  39.7 -> 33.8 MB; total 613 -> 587 MB (totals move +-25 MB between
  runs).
- /api/state and /api/drift byte for byte the same.
- footprint peak 138 MB, RSS 180 MB: unchanged.

Not run: the gui suite (gui is not touched).

Run at 573b21f4b; picked onto 3f2faef62 after it (11 commits, in
internal/agent only dsh.go and a Responses test), not run again there.
2026-11-01 06:30:39 +08:00
yetone 6712e367e8 agent: a look at the stash shares one read of it
Each /api/state and /api/drift poll asked the stash (stash.json) for one
value hundreds of times, through Detected, Drift and the agents' wiring
checks, and each ask read the file and parsed it again. In a real-account
heap profile (20 rounds of drift, state and providers) stashLoad was
24-34 MB of what was allocated.

stashShared reads it through filememo.Read, so every look shares one
parse until the file changes, by magpie or by another process. Every
read-only caller uses it now, the 24 files here and QwenPaw's
unstashPeek. stashLoad, which callers change and write back, still gives
each its own map, cloned from the same parse.

Real use: the owner's real-account sandbox, offline (proxy to :9),
20 warm rounds of /api/drift, /api/state and /api/providers:
- allocated 477 MB (d307aa648) -> 411 MB; stashLoad is out of the
  profile.
- /api/state and /api/drift bytes identical to d307aa648's (cmp).

Run on mote (mote-run, Go 1.26.8), at this head rebased on d307aa648:
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestStashLooksShareOneRead alone, 3 times: ok.
- Broken by hand (stashShared reading through stashLoad): red, "a look
  at the stash read and parsed it again".
- go test -timeout 45m ./internal/agent ./internal/gateway: ok (263s,
  691s).
2026-11-01 05:32:29 +08:00
yetone 4182e68ab4 agent: whether the installed magpie wired an agent is looked up in the bytes read, not a copy
A magpie beside the installed one (a dev build on its own port) asks,
for each field's drift, whether the agent's config names the installed
magpie's gateway (theInstalled). It took edit.Read's copy of the file
and two strings of it: with a Codex config.toml of 1.5 MB (one table
per project trusted) that was 311 MB in 60 drift polls of a sandbox
built from 4a7d1c63a plus the next commit, more than everything else
the poll allocated (219 MB).

It now looks in the bytes filememo keeps, with bytes.Contains, as
nothing is written from them. A magpie on the installed port never
gets here (elsewhere() is false), so users of a release are unchanged.

TestInstalledWiringReadsNoCopy: a 1 MB config wired to the installed
magpie is seen as its, and 10 looks allocate under 1 MB.
TestDriftInstalledMagpie still tells the installed wiring from one to
neither. Broken by hand: the copy and strings put back, red.

Run at this tree on mote: gofmt clean; go vet ./internal/agent on darwin, linux and windows; go test -count=1 -timeout 45m ./internal/agent ok (194.5s)
2026-11-01 00:43:45 +08:00
JoeyWu-tech cff2852ca8 agent: Claude Code's own endpoint is never asked whether it is magpie (#3480)
zhangt2333 (#3480): magpie sent GET / (Go-http-client/1.1) about every
30s to the ANTHROPIC_BASE_URL in ~/.claude/settings.json of a Claude
Code it never connected, with nothing shown and nothing to turn it off.
Every read of Claude Code the Agents page makes (/api/state, /api/drift
each 15s) goes through routed(), which asked a base URL that can be
another way to magpie (proxyBase: an address on another machine, or one
on loopback with a path of its own) whether it answers as magpie, for
#1985's reverse proxy, whatever key Claude Code sends there. One read
pass asked it about 65 times; the probe cache sends that as one GET once
its answer is older than 20s (reachAge), every 30s on the page's poll.

The address is now asked only while what Claude Code sends is for magpie
(claudeProxied, claudeKeyed): a key the gateway takes (keyHolds, as
Check already asks of ANTHROPIC_AUTH_TOKEN), or none where it keeps its
claude.ai sign-in through magpie (claude.login, on a Claude Code magpie
wired, wired_at, which Disconnect forgets, where the gateway takes any
key). With a key of the user's own, the base URL is their endpoint, and
nothing asks it: the reads (routed), a pick (gwAt), Check (its managed
settings' and settings.json's URL), and a request's stand-ins
(claudeStandInAt, now given the place, and claudeClassifierIn), a WSL
distro's Claude Code's too. Check says such a Claude Code's address as
it is, unasked (whatsOff: wiringOff's words, without its probe; an
administrator's in managed settings too): with a model named as one of
magpie's there, as a relay can name its own, "Claude Code's
ANTHROPIC_BASE_URL (settings.json) is <its endpoint>, not magpie's
gateway at <the gateway>", or "is gone" with none, which main said of
it too once the address had answered as not magpie. #1985's proxy keeps
magpie's key, so it is asked and kept as before.

The key, not a record of what magpie wrote: wired_at is from 10-08
(#1218), so a Claude Code connected before it and not picked since has
none, and a Claude Code magpie wired and then moved to a relay of the
user's own (CC Switch, its own key) would still have that relay asked.
The claude.ai sign-in can lean on it: it came with it (#1218), and its
setting, on a routed Claude Code only, stamps it.

Before and after, for a read, a pick or a request's stand-in while
ANTHROPIC_BASE_URL is not the gateway's and proxyBase takes it:
  before: GET <base>/ in the background, at most every 20s
  after: the same while Claude Code sends a key the gateway takes or
  keeps its claude.ai sign-in through magpie; otherwise never, and the
  address is not magpie's
Changed with it: a Claude Code pointed by hand at a proxy to magpie with
a key of its own, drift on main too (its key "was changed"; now its
address), is no longer taken as routed there, so a pick writes magpie's
address and key, keeping its own for Disconnect, where it kept the
proxy.

Not changed: the other agents ask an address only from magpie's own
entry in their config, or once on one of magpie's models (T3 Code's
wired, Gemini CLI's isMagpie(model), Hermes's onMagpie and
providers.magpie, dsh's usesMagpie), so none asks one of the user's own.
A Claude Code magpie wired keeping its claude.ai sign-in, then moved by
hand to an endpoint of the user's own with an ANTHROPIC_API_KEY alone
and not disconnected, is still asked, as before: magpie reads no
ANTHROPIC_API_KEY of Claude Code's.

Cost: a never-connected Claude Code with its own key at such an address,
the case this reaches: a read pass took 5.5 to 6.0ms on origin/main and
9.4 to 9.8ms with this (three runs each, taking turns, 200 passes, at
load 46 to 50; the key's read and access.Authenticate at ~65 calls a
pass), on the 15s drift poll. A connected Claude Code (the gateway's
address) and one on Anthropic's own endpoint (no base URL) never get
there.

docs/subsystems/agent-wiring.md (Drift) says it.

What was run (tree c7f75f7a, on origin/main 74dcf40a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
  magpie web --no-open, built -tags nogui from origin/main and from
  this, each in a sandbox HOME of its own (env -i), with a settings.json
  on a local relay that logs what it gets
  (http://127.0.0.1:<port>/corp-relay, a key of its own) and listens
  before magpie starts, /api/drift read every 5s:
    model opus, 120s: main, GET /corp-relay/ (Go-http-client/1.1) every
    20s from the first read, 6 in all; this, none. Neither touched
    settings.json.
    model fakeco/fake-1 (a provider magpie has), 60s: main, 3 GETs;
    this, none. Both said "Claude Code's ANTHROPIC_BASE_URL
    (settings.json) is http://127.0.0.1:<port>/corp-relay, not magpie's
    gateway at http://127.0.0.1:<port>" from the first read.
    Run once more with magpie up before the relay listened: main 5 GETs
    and 2, its first ask made before then, this none, the rest the
    same.
  magpie claude fakeco/fake-1, then its ANTHROPIC_BASE_URL moved by hand
  to the relay answering GET / as magpie, magpie's key kept, 60s: both
  asked it every 20s, 3 GETs, no drift. Both wrote settings.json again
  at start with every key and value the same (a label's "·", which the
  hand edit had escaped, now as is). Run once more with magpie up
  before the relay listened: both drifted "… is <the relay>, not
  magpie's gateway …" on the first read and took
  CLAUDE_CODE_AUTO_MODE_SERVER out of settings.json, then asked it
  every 20s with no drift, the address kept; main does it the same, not
  this change.
  TestClaudeOwnEndpointNeverAsked (nginx: its own key in
  ANTHROPIC_AUTH_TOKEN; local: in ANTHROPIC_API_KEY) and
  TestWSLClaudeOwnEndpointNeverAsked: pass. Broken by hand, each red:
    claudeProxied without claudeKeyed: "never connected: asked
    [https://relay.example/anthropic https://relay.example/anthropic …]"
    (and the WSL test)
    Check's addresses asked whatever the key (keyed true): "a model of
    magpie's name: asked [https://relay.example/anthropic]"
    Check's address unsaid without magpie's key: "its own key, a model
    of magpie's name: … ANTHROPIC_AUTH_TOKEN (settings.json) was
    changed, so magpie's gateway won't take its requests" (nginx), "… is
    gone, so Claude Code sends magpie its claude.ai sign-in …" (local)
    the administrator's address asked whatever the key: "its own key, an
    administrator's proxy: … ANTHROPIC_BASE_URL (settings.json) is
    https://relay.example/anthropic, not magpie's gateway …"
    claudeStandInAt, then claudeClassifierIn, on surelyMagpie alone:
    "never connected: asked [https://relay.example/anthropic]" (and the
    WSL test)
    claudeKeyed with no claude.ai branch: "the claude.ai sign-in at the
    proxy: drift … ANTHROPIC_BASE_URL (settings.json) is <the proxy>,
    not magpie's gateway …" (and the WSL test)
    its claude.ai branch without wired_at: local only, "asked after
    Disconnect: [https://relay.example/anthropic …]"
    its claude.ai branch on this machine's stash keys: the WSL test
    alone, the same as with no claude.ai branch
  agent-wiring.md's reverse proxy checks (TestReverseProxy…,
  TestClaudeBehindLocalProxyKeepsIt, …), Drift, the sign-in's and
  TestKeptAddress: ok, but for TestWSLColdPlaceOpensNothing (e54a7d50,
  #3896: a stopped distro's rows read none of its files), red at
  origin/main and with this change alike (#3924): the same eight looks
  under .hermes/profiles, none under .claude
  gofmt -l of every .go file: nothing. GOOS=linux, windows and darwin
  go vet -tags nogui ./..., GOOS=windows go vet ./...: exit 0.
  GOOS=linux and darwin go build -tags nogui ./..., GOOS=windows go
  build ./...: exit 0. Untagged linux vet and build stop at pkg-config
  (no libsoup-3.0 or gio-unix-2.0 here)
  full suite, go test -tags nogui -count=1 -timeout 45m ./... (8m19s,
  load 42 at its start, Bun 1.4.2 on PATH): 68 packages ok, reds in 8:
    internal/agent TestInstalledVersion,
    TestCursorFolderFromTheEditorIsNotTheCLI,
    TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
    TestOmpDetectedWithPiDir (#3141); the two Reasonix tests (#3641);
    TestCodexDriftReached (#3398); TestWSLColdPlaceOpensNothing (#3924,
    above)
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram, umask 077 (#3640)
    internal/gateway TestPluginToldWhereTheAgentWorks (#3675)
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie (#3649)
    internal/proc TestEnvOfChild (#3906)
    internal/provider: "fatal error: close of synctest channel from
    outside bubble" in TestUnreadLoginsWriteErrorsKeepCredentials
    (#3632), which ends the package's run
    internal/tui TestTUIFetchesSubscriptionModels/agent (#3919)
  On origin/main 1a804859, where #3924's fix is in, with this commit
  cherry-picked (a scratch worktree, not this tree): go test
  ./internal/agent has the reds 1a804859 has alone, #3141's, #3398's
  and #3641's, and TestWSLColdPlaceOpensNothing passes.
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestInstalledVersion and
  TestZedAppPath come and go here: -count=5, 12 of 15 red with this
  and 11 of 15 at 1a804859.
Not tried: macOS, Windows, a real WSL distro (its Claude Code's stash
keys are only tested), Claude Code itself sending through the relay, a
company's real proxy.

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00
yetone 70a0c387cb agent: a provider named magpie written by hand is the user's, not connected (JFunfunfun on X)
Pi set up by hand on a provider of its own named magpie (magpie/<model>
at the gateway) read as connected in magpie: every catalog change wrote
magpie's list over that provider, RenameProvider rewrote its refs, Drift
offered Reconnect, and Disconnect took the provider out.

0911a65e7 (yyddbds, MiMo) already holds a ListOnly agent's sync until
it is Wired; that still let a hand-written config that names a magpie
model (JFunfunfun's Pi) read as Wired. Both gates now apply.
Its test's last case said a magpie model picked by hand on MiMo's own
magpie provider connects it; that is JFunfunfun's case, so it now
stays the user's until connected in magpie (listonly_test.go, and the
doc's ListOnly line says so).

An agent whose magpie is a provider of its own config (Spelled, not
Native) is now connected only when magpie set it up (setUp): a field in
applied.json, the new applied.Kept that Keep leaves instead of deleting
the record, or the <id>.connect.was stash Connect has written since
10-03. Otherwise (handWired) it isn't Wired, has no Drift, and
SyncCatalog, RenameProvider and renameRefs skip it; Disconnect is a
no-op as it is for any unwired agent. Connecting it in magpie takes it
on as before; Disconnect after that skips putting back "was" values
that were themselves magpie's (dsh errored on them). RenameLegacy
records the dial/ -> magpie/ values it writes, and moveEfforts (the
Cursor/Antigravity effort ids, at start-up) leaves a hand-written
magpie/<ref> alone. Aside keeps its own
key-based ownership. OpenCode's own-gateway-provider test now connects
through Apply as `magpie opencode` does.

Run (on mote, at this head, rebased on f2c6831a3): go test -tags nogui
-count=1 ./internal/agent ./internal/cli ./internal/library
./internal/gui; go vet darwin/linux/windows of internal/agent and
internal/cli; gofmt -l. internal/agent again after the ListOnly test
change: ok. Pushed on ceef9e943, whose five commits since touch usage,
sessions, library, provider movers and gui only.
New tests: TestPiHandWiredMagpieProviderIsTheirs (pi's literal
settings.json/models.json in a sandbox HOME, files byte-identical after
SyncCatalog, RenameProvider and Disconnect), TestPiConnectedBefore-
StaysConnected (applied record, gone model, connect.was, applied then
Keep), TestHandWiredMagpieProviderSiblings (29 Spelled agents). All fail
on the old code.
Tests that wrote a connected agent's files by hand (Pi, OpenCode,
Hermes, omp, dsh, the Kilo plugin, Cursor efforts, and the cli's
save-then-sync test) now also mark it as Connect leaves it
(setUpInMagpie, the connect.was stash); without it they read as
hand-written, which is what this change is about.

Broken by hand, each red: the Sync gate, the rename gates, the Drift
gate, Keep deleting the record, the was-skip in Disconnect, the
moveEfforts gate (TestMoveCursorEfforts' hand-wired case).

Not tried: a real pi binary against the gateway. Users connected
between 09-23 and 10-03 who pressed Keep (record deleted before this)
read as not connected; one Connect brings them back and pi keeps
working meanwhile. Agents without Spelled (Claude Code, Codex, Gemini
and others) decide by their own checks and are unchanged.
2026-10-30 14:45:56 +08:00
yetone fae438b4a5 agent: Codex switched on again is joined, and its own models say where a pick goes
NancyTom18 on X: Codex on a routing group, Disconnect and restore, switched
on again, then an OpenAI model picked: every OpenAI row said 直连. After a
routing group again they said 经 magpie.

Reproduced in a sandbox HOME (ChatGPT sign-in, a group): reconnect put the
group back by Apply alone, so Codex was beside its sign-in and not joined
(codex.joined went with the Disconnect). Picking one of its own models then
took magpie out (set → unroute, #940): config.toml had no openai_base_url
and no model_provider, so Codex went straight to OpenAI and the 直连 tags
were true. Back on the group, the rows said via magpie from routed(), while
a pick would again go straight to OpenAI, with no ask: that label was false.

- reconnect calls Join first where the agent has one, so a Codex switched
  on again comes back as the switch first connects it: joined, its own
  models staying through magpie.
- modelOptions: beside its sign-in, not joined (with ChatGPT), and failover
  off, Codex's own models say Direct "OpenAI", so the picker tags them
  直连 and asks before a pick takes Codex off magpie.

Tests: TestCodexReconnectStaysJoined (red on the old applied.go: "connected
again, not joined"), TestCodexBesideOwnModelsSayDirect (red on the old
codex.go: "gpt-5.5 says via"). Each fix reverted by hand, its test went red.

Run on mote at this tree: go test -timeout 45m ./... all ok except
internal/gui TestMainWindowCorners/macOS_26_SDK, mote's macOS 27 red filed
as #3949 (window chrome, untouched here). go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./..., go build ./..., gofmt -l
clean. GUI files unchanged; agent-leave-magpie and agent-path-same pass in
Chromium and WebKit (4/4 each).

Not tried: a real Codex binary with a real ChatGPT sign-in sending a turn;
the route is read from config.toml as Codex's own provider rules read it.
A Codex already beside a group from before this release stays so: its
OpenAI rows now say 直连 and ask; switching it off and on joins it.
2026-10-29 07:32:05 +08:00
yetone 62045475b4 library: Codex on magpie reaches a command's MCP server through the gateway, run only while a thread uses it (#3885)
Codex starts every stdio server in its config once for each thread it
has loaded and keeps them as long as the thread: YPYT1 counted 204 node
processes, 21 GB, beside one Codex. While Codex is on magpie (Wired, not
disconnected, this machine's gateway key, not WSL) the library now gives
it a server run by a command as url = <gateway>/mcp/run/<name>, which
magpie serves over streamable HTTP and runs the command for itself
(internal/library/mcp_run.go):

- a session (Mcp-Session-Id) starts its own child only when it sends
  something past initialize, the first page of tools/prompts/resources
  lists and ping; those are answered from what the first child said for
  the same command, args and env, and a list_changed from a child drops
  that list;
- a (re)started child gets the session's own initialize replayed, so a
  server that keeps state per client still keeps it per thread;
- a child idle for 15 minutes is stopped (a later call starts it again),
  DELETE stops it, and a server changed or removed from the library has
  its children stopped at the next sync;
- server-initiated requests and notifications go to the session's newest
  open stream (GET, or a POST answered as SSE).
The gateway route lets only this machine in: no Origin, a loopback Host,
no forwarded or LAN address (TestRunMCPThisComputerOnly). A server with
an env var magpie hasn't, a remote one, and Codex off magpie, in WSL or
on another machine's key keep the command as before. agent.Rewired
re-syncs the library when Codex is connected or disconnected, so it is
handed the commands back when it leaves magpie.

Tests (internal/library/mcp_run_test.go, a fake server): starts on a
call and not on initialize/lists, idle end and DELETE, a server's own
request round-trips, list_changed, a changed/removed spec, an unknown
session, and the Codex entry in a sandbox (url when wired, the command
back when not, a keyed env var kept as a command). Each was red with its
part broken by hand: the init cache removed, the sweep off, runsFor
forced false, forget a no-op, the Origin/Host guard dropped.

Real runs:
- mote, sandbox HOME, real codex 0.162.1 + @modelcontextprotocol/
  server-memory: config.toml gets url = "http://127.0.0.1:3581/mcp/run/
  mem"; codex app-server's mcpServerStatus/list lists its 9 tools
  through the bridge.
- this Mac, sandbox HOME with only the DeepSeek provider copied, codex
  0.162.1 on deepseek/deepseek-flash: a real turn called mem
  create_entities and read_graph through the bridge and answered with
  the stored observation. Three codex exec turns at once that used no
  tool started 0 memory-server node processes (before: one each).
- Windows 11 (xiaomi-gpu), sandbox profile, codex 0.161.0: url entry
  written, app-server lists the 9 tools, 0 memory-server node.exe left
  after Codex closed.

Run at the pushed head (mote): GOOS=linux/windows/darwin go vet -tags
nogui ./internal/library/ ./internal/gateway/ ./internal/agent/: ok.
go test -count=1 -timeout 45m ./internal/library/ ./internal/gateway/
./internal/agent/ ./internal/gui/: library ok (167s), gateway ok
(596s), agent ok (279s); gui FAIL only TestMainWindowCorners/macOS_26_SDK
("a toolbar doesn't change the corners ... yet the main window's was
taken off"), #3949, red on mote's macOS 27 on main too; no gui or AppKit
file is touched here.
Windows (win-run): go test -run 'TestRun|TestFakeRunServer|TestMCPProxy'
./internal/library/ ./internal/gateway/: ok.

Not tried: the Codex desktop app (the same config.toml), a server that
asks the client for sampling or elicitation in a real agent. Codex picks
up the new entries when it restarts.

Reported-by: YPYT1
2026-10-29 03:06:48 +08:00
yetone a7072926d6 agent: connecting Kiro Crew connects the harness it is set to (wuping9525)
wuping9525 (Discord, Windows): Kiro Crew's Agent Harness was Claude Code,
Claude Code was installed but not connected to magpie, and turning Kiro
Crew on refused with "connect Codex, Claude Code, ... first". On a Mac it
worked only because a harness (Codex/Claude Code) was already connected;
Crew's home is found the same way on Windows (USERPROFILE\.kiro\crew).

Now, when agent.acp_backend names one of magpie's harnesses (codex,
claude, opencode, pi, goose) and that agent is installed but not
connected, connecting Kiro Crew connects it in the same action and runs
Crew on it; the notice says so. The stash's kirocrew.joined records it.
Kiro Crew's Disconnect disconnects that agent again only if magpie
connected it and the user hasn't disconnected it since (kiroCrewUserLeft
in Agent.Disconnect); a disconnect the user made before stays recorded as
theirs. A failed Crew write undoes the join. config.local.json pins,
kas/kiro/deepseek and harnesses not installed behave as before.

Windows: the adapter search also tries npm's .cmd/.exe/.bat shim names,
and the app is detected by ~\.kirocrew-app\.venv\Scripts\kirocrew.exe.
New notice translated in zh, zh-TW, ja, de; docs/subsystems/agent-wiring.md
and docs/reference.md updated.

Run (macOS, sandbox HOME, GOMODCACHE/GOCACHE pinned), at base 11c3fbb19;
after rebasing on 2921471de (no change under internal/agent or internal/gui
since), go vet and go test -run 'KiroCrew|Disconnect' ./internal/agent
again: ok.
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gui: ok
  (252s, 62s)
- new tests: TestKiroCrewConnectsItsHarness (real Claude Code wiring in a
  sandbox), TestKiroCrewLeavesTheUsersHarness (connected before, taken
  back after, off before), TestKiroCrewHarnessNotHere, TestKiroCrewOnWindows
  (kiroCrewOS forced to windows, PATH emptied)
- gofmt -l clean; go vet nogui for darwin, linux, windows; windows build
- GUI: agent-kiro-crew-lang, i18n-keys, gui-de, gui-ja, gui-zh-tw in
  chromium and webkit: 35/35 pass

Broken by hand, each red: no join (ConnectsItsHarness, taken back after,
off before), no kiroCrewUserLeft hook (taken back after), always forgetting
the user's disconnect (off before), no .cmd names and no venv exe
(OnWindows), no leave on Disconnect (ConnectsItsHarness, off before);
notice dropped from the NOTICES list: agent-kiro-crew-lang 9 red.

Not tried: a real Kiro Crew or Windows machine (the Windows box's ssh
timed out); the disconnect preview doesn't show the joined harness's
files, since it copies only Crew's folder.
2026-10-26 16:31:14 +08:00
yetone 81a24cf8fe groups: a found group is listed as auto/<model id as the vendor spells it>
ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.

What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
  public one). Every old form is still accepted as input forever:
  provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
  gateway (validateModel), keys, stats, affinity and usage, so both ids
  route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
  (allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
  exists, found groups are listed by their old id (AutoRefsOn) and
  auto/<x> means that provider's model. Documented in
  docs/subsystems/gateway-routing.md.

Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).

Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.

Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
  nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
  gateway, whose failures were the tests' expected ids (updated here)
  and two regressions now fixed (bare ids; desktop models hiding groups
  by prefix). Every failing test passes on rerun. Load average was
  ~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
  TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
  10.19s), and it fails the same in a git-archive export of 33dbdcc52.
- agent and gateway in full, -p 2 -timeout 120m: gateway ok (2996s).
  agent failed four tests that still expected the old ids
  (TestOmp/PiModelsAskedOnTheirNativeAPI, TestReseatFoundGroupsOff,
  TestReseatKeepsAFoundGroupWithAProviderOff); updating them showed the
  Reseat bug above. After the fix, go test -count=1 -timeout 120m
  ./internal/agent/: ok (1000s, load ~160-220).
- GUI files the change reaches, chromium and webkit: group-found-off and
  the routing files pass, except routing-bodies, routing-model-rest,
  routing-keys-fold and routing-request-metrics, which fail the same with
  33dbdcc52's JS.

Broken by hand and watched red, then restored: CanonicalRef in
validateModel (both-ids routing test), allows() (key tests both ways),
the Save refusal and AutoRefsOn checks in Ref/CanonicalRef (provider
named auto), catalog.Lists' preference (models.dev lookup of the part
after auto/), renameFoundGroups' applied.json check and its SyncCatalog
call (user values kept), PublicRef in visible.go, the codexcat prefix,
samePick in Reseat (TestReseatFoundGroupsOff: opus left on the gone
group).
TestBareModelIDsShared was red before the bare.go fix.

Not verified: no real agent, vendor or models.dev client run; no run on
the Windows box. Settings pickers (vision, title model) holding a saved
group/auto-... value may show it as saved. codexcat can't tell a stored
"auto" provider apart, so its models lose the "text only" hint. The
pre-existing reds above are not filed.
2026-10-20 00:18:51 +08:00
yetone d9b943555d agent: a key of the gateway's own in place of magpie's still reaches magpie (#2510, PaulT on Discord)
PaulT made a key under Gateway keys and put it in Hermes's config.yaml
(providers.magpie.api_key) in place of `magpie`. Requests went through
magpie, but the picker said Hermes's api_key was changed and that
magpie's gateway won't take its requests.

The class: wiringOff, and the key checks of Codex
([model_providers.magpie] experimental_bearer_token), Qwen Code
(env.MAGPIE_API_KEY) and Reasonix (its env file), accepted only the exact
key magpie wrote. A sync also wrote `magpie` back over the user's key,
in mergeKept (every yamlKept/jsonKept agent) and in Reasonix's install.

keyHolds(v, want) is the one check now. Where want is a key magpie gives
for its gateway (gateway.Token, the LAN key, or a TokenFor), it takes any
v that access.Authenticate takes, the same test dsh has used since #1332.
It never stands in for a URL or another value. A key the gateway doesn't
take, or one turned off, is still drift and is still written over.

Run, at 8b84dc902 in its own worktree, with a sandbox HOME:
- TestHermesWithAGatewayKeyOfTheUsers: an issued key in Hermes's
  config.yaml is no drift and survives a sync. A key the gateway doesn't
  take is drift and is replaced by the sync.
- TestKeyHoldsTakesAGatewayKey: covers magpie's own key, TokenFor, a
  foreign key, an empty key, and a URL or mode value.
- Broken by hand: with keyHolds back to v == want, both tests are red
  ("a key the gateway issued is drift"). With mergeKept's keep removed,
  the sync test is red ("a sync wrote over the user's key: magpie").
- gofmt -l clean; go vet -tags nogui on darwin, linux and windows ok.
- go test -timeout 45m ./... (pipefail): every package ok except these:
  - internal/agent and internal/gateway ran out of the 45m budget twice.
    The load average was ~130-250, from other sessions on this machine.
    Each was then run in full in shards, every test from its own
    go test -list, each shard with its own 45m: agent 855 tests in 3
    shards, ok. gateway 2113 tests in 5 shards, ok.
  - internal/gui: TestPanelJoinsFullScreenSpaces, open as #2450 (macOS 26.2).
  - gateway's TestMaxRPMGroupPrefersMemberWithRoom: a 1s bar under load,
    open as #2520. It passed in the sharded run.
- Not tried: a real Hermes run. It re-bootstraps its launcher under a
  sandbox HERMES_HOME, so this was read from the config only.
2026-10-16 20:08:01 +08:00
yetone b03031738b agent: a model picked in Codex's /model beside its ChatGPT sign-in is not drift (#2424)
Connected beside the ChatGPT sign-in (openai_base_url to magpie), Codex
picking one of its own models in /model still goes through magpie, but
Drift() called it "replaced" and the Agents row went red with Reconnect,
which reads as a broken gateway (Essaim8, #2424). Joined agents already
treated such a pick as one made in the agent; Beside now does too, for
Codex and StepCode alike. Wired() already counted both as connected.
Without a sign-in a model off magpie is still told as replaced.

Run:
- TestCodexOwnPickAfterMagpieModelStaysConnected and
  TestCodexGroupByItsModelName red on the old applied.go (drift
  "replaced" on gpt-6.1-sol / gpt-6.1 / gpt-5.5 beside the sign-in),
  green after.
- go test ./internal/agent ./internal/gui ok; gofmt clean; go vet
  -tags nogui for darwin, linux, windows ok on agent, gui, gateway.
Full suite: go test -tags nogui -count=1 -timeout 45m ./... ok, every package (at this batch head).
2026-10-16 00:26:29 +08:00
yetoneandggbdpq 58651568b3 agent, sessions, provider: a state file that doesn't parse is kept aside, not written over as empty (#2263, ggbdpq)
applied.json, wsl.json and sessions-wsl.json were read as empty when they
didn't parse, and the next save wrote that emptiness over them. What
magpie had applied to each agent, the WSL distros and the WSL session
listing were lost with no copy. stash.json already kept a bad file aside
as .bad-<time>. Each of these now does the same through one helper,
lastgood.KeepUnparsed, instead of a copy per file:
- It does nothing when the file is missing or empty.
- When the file doesn't unmarshal into the reader's own type
  (lastgood.Into[T]), it copies the file aside (KeepBad).
- It stops the write when the copy can't be kept.

This also fixes the issue's claim about stash.json. Stash judged a file
with json.Valid, so `[]`, which a map reader takes as empty, was written
over unkept. Its failed copy was only logged, and the write went ahead
anyway. Both are fixed (TestUnreadStashArrayKeptAside), and
gateway-hidden.json uses the same helper.

Siblings found by going through every single-file JSON reader that takes
a bad file as empty and then writes it whole:
- stepfun-auth
- login-returns
- quota-history
- balance-history
- credits-daily
- Claude Desktop tiers
- plugin updates
- usage's computer id
- davsync's sync state

Each now keeps a bad copy. Caches that are rebuilt from the vendor are
left alone; docs/subsystems/providers-accounts.md lists them.

Run:
- gofmt -l, go vet (darwin -tags nogui, GOOS=linux -tags nogui,
  GOOS=windows): clean.
- go test -tags nogui -p 4 -timeout 40m ./... with the other three
  commits of this push: see the last one's body.

Broken by hand: on the code before this, these fail:
- the issue's applied_keep_test.go and wsl_keep_test.go
- TestUnreadStashArrayKeptAside
- TestUnreadStateKeptAside (10 subtests)
- the gateway, usage, davsync and plugin _keep tests
TestKeepUnparsed and TestKeepUnparsedFailsWhenItCantBeKept cover the
helper.

I dropped a test, "not written when it can't be kept", for stash. It passed
on the old code too, because a read-only folder also stops the atomic
write.

Not tried: a real WSL distro.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 09:36:26 +08:00
yetone b7a2e73761 agent: connecting an app that gets magpie's models as its provider, with none listed for it, says why instead of reporting success (Lumens on Discord)
Lumens (v0.1.1233) connected WorkBuddy from the Agents page. The toast
said it was connected, but the toggle flipped straight back and
WorkBuddy had no magpie models. For agents that take magpie itself as
the provider (WorkBuddy, WorkBuddy AI, ZCode, Pencil, T3 Code, Copilot
JetBrains), Agent.connect() went down the "magpie" branch and called
Apply without checking whether any model was listed for the agent. With
none listed (no provider or subscription yet, or "only picked" with
every pick gone), Apply wrote nothing, connect still answered 200, and
the next read found nothing wired.

The fix applies, then, if the agent still doesn't read as wired, returns
the same NoModelsError or AllHiddenError the field-less path already
used. The GUI already maps both to no_models and all_hidden, in all five
languages. The check comes after Apply because Cursor Private Inference
is wired through its environment with no models at all, and
TestCursorLocalConnects keeps that connecting. The noModelLeft helper is
shared with the existing field-less path.

Tests:
- TestConnectMagpieAsProviderWithNoModelLeft (agent): WorkBuddy with no
  provider gives NoModelsError. With its only picked provider switched
  off it gives AllHiddenError and stays unwired. Switched back on, it
  connects and is wired.
- TestAgentConnectNoModelsMagpieAsProvider (gui): POST
  /api/agents/connect/workbuddy with nothing in magpie gives 400
  no_models. The old code gave 200.
Both fail on the old code.

Run:
- gofmt -l is clean.
- go vet passes on darwin, on GOOS=linux -tags nogui and on GOOS=windows,
  for internal/agent and internal/gui.
- go test -tags nogui passes for ./internal/agent and ./internal/gui under
  a sandbox HOME (load ~250 from sibling sessions).
- An earlier full ./... run: gateway, library and provider passed on a
  rerun with a longer -timeout. Their first run hit the 10m timeout under
  load, with no assertion failures.

Not tried: the real WorkBuddy app, and Lumens' own settings, which
haven't been seen. Left for its own change: workbuddyWired counts only
vendor "magpie" entries, while buddyWrite also treats an entry under
magpie's key that WorkBuddy re-saved as vendor "Custom" as magpie's.
2026-10-14 20:01:06 +08:00
ChampionTina c1e354245d agent, gui: connecting an agent whose model list holds none of magpie's models says so, in the reader's language (#1989, znuaibot)
znuaibot's case: OpenCode shown only its one picked model, whose provider
was switched off. connect() found no field to set, and since the catalog
still held models (shown 0, hidden 7) it said only "OpenCode can't be
connected to magpie", which sent the user looking at the agent rather
than at the model list that emptied it.

znuaibot's patch (74160e1f) told the case apart in connect(). Changed on
review: the plain English error would have reached the GUI untranslated
(NoModelsError beside it is said by code), so the case is a typed
AllHiddenError, fail() answers it with code all_hidden, and the GUI says
it in en/zh/zh-TW/ja/de, pointing at the agent's Model list → Pick (the
names the Agents page uses).

Run: TestConnectWithEveryModelTakenOut (agent) reproduces the case with
a provider switched off under OpenCode's picked list: on the old connect
it FAILs with "OpenCode can't be connected to magpie"; passes now, and
connects once the provider is on again. TestAgentConnectAllHidden (gui)
checks the code. agent-connect-no-models.test.cjs now runs both codes in
Chromium and WebKit, en/zh/ja/de: 16/16 pass, and with app.js's
all_hidden line removed the 8 all_hidden cases FAIL. gui-de, gui-ja,
gui-zh-tw, i18n-keys: pass. Full internal/agent and internal/gui: see
the push record on #1989.
2026-10-14 05:43:48 +08:00
yetone ffd0778696 agent: an agent reaching magpie through a reverse proxy isn't drift, and a sync keeps the proxy's path (#1985)
davisjiahao put magpie behind a company nginx (https://ai.corp.example/magpie)
and pointed their agents there with magpie's key. Every agent whose Check
compares its URL exactly called that "unwired", offered Reconnect (which
writes 127.0.0.1 back), and each start's sync replaced the origin but
dropped the /magpie path.

Decision: a URL that isn't magpie's is still magpie when it ends with
magpie's path, the rest is an http/https address on another machine, and
GET <rest>/ answers as the gateway's GET / ({"name":"magpie"}). Something
else there (a relay CC Switch wrote) stays drift. Loopback on another port
is magpie on an older port: drift, never probed. An unknown answer is not
drift (as unreachable/proxied), so Reconnect isn't offered before the
probe has answered.

- reach.go: magpieAt / realMagpieProbe / reachesMagpie, probed in the
  background through the existing cache; answersAsMagpie shared with
  codex_proxy.go's realProxyProbe. offLoopback takes https too.
- applied.go: wiringOff (the choke point for ~40 agents) accepts it;
  Codex's "bypassed" isn't told for a request to the host the config
  keeps magpie at, or one the gateway saw from it after.
- claude.go (managed settings) and reasonix.go: their own exact checks.
- codex.go: codexKeptGateway keeps https, default ports and a path prefix
  (#816's kept address, trusted by magpie's key); viaBase matches the kept
  codexURL, since at.host() falls back to loopback for https.
- keptaway.go: awayPath keeps the path every URL at the away address had.
- Port moves need nothing: Rewire/OnGateway re-set only unwired agents.
- Picking a model in magpie still points the agent at this magpie
  (documented, unchanged).

Run (sandbox HOME, worktree):
- go test -tags nogui ./internal/agent: ok (297s) rebased on 12ecb6d8e.
  Before the rebase only TestFolderVarsAreListed failed, fixed on main by
  c6de0d2a5.
- New proxy_kept_test.go: every agent behind the proxy has no Check/
  unwired drift, at a relay all but Codex are told, SyncCatalog keeps
  https://ai.corp.example/magpie with its path in every file; Claude
  managed settings; unknown-then-not-magpie; loopback not probed; the
  real probe against httptest serving the gateway's handler under
  /magpie/; Codex https kept address, Reached and lastSeen; signed-in
  Codex via openai_base_url; awayPath table.
- Broke each fix by hand, each went red: wiringOff (claude, claude-desktop,
  gemini, opencode... told), claude managed, reasonix, awayPath (every
  synced file lost /magpie), bypassed host and lastSeen, unknown-as-drift,
  codexKeptGateway http-only/no-path, viaBase.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: a real nginx (Host rewriting, auth in front of GET /), the
Windows box, a real CC Switch. No GUI change.
2026-10-13 18:07:03 +08:00
yetone f156d90460 agent, gui: Codex isn't handed to a magpie it can't reach, through a proxy or after magpie quits (Muma102kMichael, Leon920717, thisisvainxx on X)
Muma102kMichael (Windows): after magpie took Codex over, every project
and every new chat got 502. Codex's reqwest sends its requests for
http://127.0.0.1:3425 through HTTP_PROXY/ALL_PROXY or the system's
proxy, and only an exact IP or a CIDR in NO_PROXY (on Windows, with no
NO_PROXY, the bypass list with "*." removed) keeps 127.0.0.1 off it:
"127.*" and "localhost" don't, and macOS' exceptions aren't read. A
proxy in global mode answers 502 for every request. With [features]
respect_system_proxy Codex asks the system alone and goes direct with
no proxy set there. Account failover, which magpie writes uninvited
when 2+ ChatGPT accounts are on, put all of Codex's traffic, its own
models included, behind that proxy.

- codex_proxy.go works out Codex's proxy the way Codex does and probes
  GET / through it (must answer as magpie). Failover waits for that
  probe and isn't written while the proxy doesn't pass Codex on; one
  written before goes again.
- New drift kind "proxied": the Agents pill says Codex reaches magpie
  through a proxy that doesn't pass its requests on, How to fix names
  the fix (DIRECT rule for 127.0.0.0/8, NO_PROXY=127.0.0.1, or
  127.0.0.1 in Windows' bypass list), and the dialog has a one-click
  Disconnect from magpie (also on unreachable drift).
- Leon920717: after quitting magpie Codex kept retrying. The app that
  serves the gateway now takes failover out in OnShutdown
  (EndCodexFailover); the next start's Sync writes it again. A
  connected Codex is kept (its model is magpie's; Disconnect restores).
  A kill or crash still leaves failover in place.
- thisisvainxx: "several restarts". Codex's app-server keeps the base
  URL it started with, and KeepCodexDaemonCurrent ends with magpie, so
  EndCodexFailover restarts it when no codex session is on it.

Run:
- real codex-cli 0.162.1 in a sandbox CODEX_HOME against a fake 502
  proxy and a fake gateway: NO_PROXY=localhost,127.* -> 30 POSTs to the
  proxy; NO_PROXY=localhost -> proxy; NO_PROXY=127.0.0.1 -> gateway;
  respect_system_proxy with HTTP_PROXY set -> gateway directly.
- go test -tags nogui ./internal/agent/ (full package, 465s, ok) and
  the new tests after the daemon change; each new test went red with
  its guarantee broken by hand (failover gate, drift, EndFailover,
  daemon restart on quit).
- node --test agent-proxied/agent-unreachable/agent-failover/
  agent-disconnect-preview: 104 passed, chromium + webkit, en zh zh-TW
  ja de, window and panel.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui clean.
Not tried: the quit path in the real app, on the Windows box, or
whether computer use / remote connection broke for this same reason.
2026-10-11 23:00:00 +08:00
yetone 64262a19f0 agent: Prime Agent is an Agents-page row, wired like Pi into ~/.prime/agent, and Disconnect puts its files back (#1528, takltc)
What changed
- internal/agent/primeagent.go: Prime Agent (PrimeIntellect-ai/prime-agent,
  CLI prime-agent) through the piLike path, as OmO was added. Its folder is
  ~/.prime/agent or PRIME_AGENT_CODING_AGENT_DIR (~ expands, as upstream's
  agent_dir does; appdir now lets that variable carry ~). models.json and
  settings.json were checked against upstream v0.10.0 (pa-core settings and
  models registry): Pi's camelCase fields, the same thinking levels and
  enabledModels rules. Connect writes providers.magpie, defaultProvider and
  defaultModel and keeps the user's providers and settings. Only the global
  settings.json is written; allowedModels and subagentDefaultModel are left
  alone.
- Prime Agent sends no User-Agent, so its provider block carries the key
  magpie-prime-agent and the usage log names it (piLikeKeyed). The block is
  Pi's otherwise, compat.sendSessionAffinityHeaders included (Prime Agent's
  openai_completions honours it), kept as the user set it (piBlockKept).
- Disconnect restores both files byte-for-byte: before magpie's first write
  a copy is kept (*.before-magpie, or a note that the file was absent), and
  Disconnect puts it back when nothing else changed since (Agent.Restore). A
  file changed while connected is left with only magpie's part taken out.
- WSL kind, agentenv, the icon, PICKS_ITSELF in the GUI, docs and READMEs.

Run
- go test -tags nogui ./internal/agent ./internal/appdir ./internal/agentenv
  ./internal/library ./internal/usage; the new tests went red with the key,
  the restore, the ~ expansion, PICKS_ITSELF and the icon each taken out.
- pi-default-note.test.cjs in chromium and webkit.
- Real use: prime-agent 0.10.0 installed into a sandbox HOME, a sandbox
  gateway on 127.0.0.1:3651 and a fake upstream on 3652. The interactive
  TUI with no flags started on magpie/fake/echo-1, the fake got the request
  and usage.jsonl recorded agent "prime-agent". `magpie prime-agent default`
  put models.json back byte-for-byte; settings.json got its values back, but
  Prime Agent rewrites the whole file when it runs (every key, nulls), so
  that file is equal in content, not bytes. Reconnecting over that
  null-filled file and disconnecting again left it byte-identical. After
  the rebase onto 7a5536793 (compat in Pi's block) the turn was run again:
  same result, and both files byte-identical after Disconnect.
  `prime-agent -p` ignores the saved default upstream (print mode picks a
  featured model); with --provider magpie --model it goes through magpie.
- gofmt -l, GOOS=linux and GOOS=windows go vet, full go test ./...
2026-10-11 03:11:33 +08:00
yetone 4e584faa51 agent: a Codex the user disconnected stays disconnected through restarts and updates (paynezhuang)
paynezhuang on Discord: magpie's first start pointed Codex at the gateway
by itself; they switched Codex on, chose "Disconnect from magpie", and after
each update and restart config.toml had openai_base_url again.

Cause: Codex's Sync runs at every start (SyncCatalog) and calls failover(),
which writes openai_base_url whenever Codex is signed in to ChatGPT and
another of the user's ChatGPT accounts is on in magpie. Nothing told it the
user had taken magpie out. The same Sync's #701 branch (sign-in "magpie
API" on one of Codex's own models) wired a disconnected Codex again too, and
with magpie API Disconnect itself left failover's base URL behind (its own
model Set ran failover).

Fix: Disconnect marks the agent disconnected in the stash
(<id>.disconnected) before it writes anything; connect() and an Apply that
leaves the agent wired take the mark out. Codex's failover treats a marked
Codex as having no other account on (and takes out a base URL it owns), and
the #701 re-wire skips it. Failover for a Codex never disconnected, and a
base URL written by hand (#856), are as before.

Siblings: TestDisconnectStaysThroughSync connects and disconnects every
non-WSL agent with fields, then runs SyncCatalog and dsh's KeepDshWired
round twice: none is wired again and no file outside magpie's own changes.
It passes on the old code too (only Codex had the problem); it guards the
class. Cursor, Copilot CLI and Devin can't be connected in the sandbox and
skip; Native (Aside) and Launch agents don't Sync wiring.

Run:
- TestCodexDisconnectStaysWithAccountsOn (ChatGPT and magpie API) and
  TestCodexAPIDisconnectStays fail on the old code ("start 0 after
  Disconnect wired Codex again", "disconnect left magpie in") and pass now.
- go test -tags nogui ./internal/agent ./internal/gui . (sandbox HOME): ok
- gofmt -l, go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/agent: clean
- Real magpie (nogui build, `magpie web --gateway`) under a scratchpad
  HOME, gateway 127.0.0.1:3481, web 3482, fake ChatGPT auth.json plus a
  second ChatGPT login on: old build re-wrote openai_base_url 2s after a
  restart following Disconnect. New build: first run wires (failover),
  connect, disconnect, restart as 0.1.99998, then start as 0.1.99999
  (last-version moved): config.toml byte-identical to after Disconnect,
  no failover; connecting again wires it and a restart keeps it.
2026-10-10 19:17:53 +08:00
yetone a5114d931f agent: Claude Desktop from its MSIX isn't said to be off magpie when the package's copy is emptied, and Reconnect puts its gateway back (dumplings)
dumplings (Windows, Desktop 2.31226.0 from the MSIX) saw "Claude Desktop
已不经过 magpie:配置已变更" while Desktop ran on magpie, and Reconnect
didn't clear it; switching Desktop's provider off magpie and back did.
Two causes:

- Check went over both sets of folders magpie writes for a packaged
  Desktop (the package's LocalCache and the real ones, as which build
  is installed can't be told) and failed when either was off magpie.
  2.31226 reads the real %LOCALAPPDATA%\Claude-3p (bg5eau, already in
  desktopdir), so the package's copy, emptied, isn't Desktop off
  magpie. desktopRead now judges only the set whose Claude-3p Desktop
  ran in last ("Local State", desktopdir.LastRun), every set when it
  ran in none, as before.
- Reapply on an unwired drift re-set the field drift shows on and
  fields on magpie's models. Desktop's drift shows on a tier (sonnet,
  on a magpie model), and its provider field ("magpie") isn't a model,
  so the gateway was never written back. Reapply now also re-sets a
  field whose value is magpie itself, as Wired already counts it.

The reporter's analysis said 2.31226's AppxManifest excludes
Claude-3p from virtualization; that manifest wasn't seen here (the
Windows box has no MSIX Desktop), the fix rests on Desktop reading the
real Claude-3p, which bg5eau's case showed.

Run: TestClaudeDesktopMSIXChecksTheFoldersDesktopRuns (MSIX layout:
package Roaming\Claude and Local\Claude-3p with an older Local State,
the real Claude-3p newer); red with Check over every set, and red
with Reapply without the magpie-valued field. go test -tags nogui for
internal/agent, internal/desktopdir, internal/gui, internal/library;
the agent package's TestClaudeDesktop* built for windows/amd64 and run
on the Windows box, all pass; gofmt -l; go vet -tags nogui on darwin,
GOOS=linux and GOOS=windows for internal/agent, internal/desktopdir.
2026-10-10 19:01:11 +08:00
yetone 0bf9d77d3f agent tests: TestDriftBypassed's request reaching the gateway is kept to its run, so -count=2 passes
The test stood for a request with usage.Saw("codex"). Saw's record lasts
the process, which the gateway relies on (LastSeen answers from it before
a request is written to the log), so a second run started with a request
seconds old, newer than its prompt five minutes back, and found nothing
bypassed ("bypassed: <nil>", also on origin/main).

Drift reads LastSeen through a package variable the test replaces with its
own clock; production still reads usage.LastSeen. That Saw is LastSeen's
answer at once moves to usage's own TestSawIsLastSeen, which removes its
record afterwards.

-run 'TestDrift|TestSawIsLastSeen' -race -count=5 passes; before, -count=2
failed.
2026-10-07 03:03:06 +08:00
yetone 99f07249e8 agent: Claude Code's tiers and subagents following a main model moved onto the model magpie gave them aren't "changed outside magpie" (#1050, cjyrainbow: Claude Code · WSL Ubuntu 已在 magpie 之外换掉 claude/claude-sonnet-5-5[1m])
With the sonnet tier and the subagents on Sonnet 5.5 and the main model
on Opus 5.5, moving the main model to Sonnet 5.5 in Claude Code's own
/model left the two following it: they read as empty, and Drift took
that for the agent's default replacing the Sonnet 5.5 in applied.json.
Drift now reads an empty field that follows another (Follows) as on that
field's model, so the usual rules apply: a move between magpie's models
isn't drift, the main model taken off magpie still is. The subagents
field now says it follows the main model, and a stopped WSL distro's
agent keeps Follows too.

TestClaudeFollowerOnTheMainModelIsNoDrift and
TestWSLClaudeFollowerOnTheMainModelIsNoDrift (running and stopped
distro) build #1050's record through Apply and the switch through
/model + Follow. Without the change both fail with
"replaced Field:sonnet Now: Want:anth/claude-sonnet-5-5[1m]"; without
the wsl.go line the stopped distro still does. go test -race
./internal/agent ./internal/profile pass.
2026-10-07 02:25:49 +08:00
yetone 588e51ea4c agent, gui: an agent connected by its config to an address where nothing answers is told, not shown connected (#1013, cjyrainbow: Codex Desktop's WSL environment reads Windows' ~/.codex/config.toml, whose openai_base_url and [model_providers.magpie].base_url the reporter pointed at Windows as WSL sees it, forwarded to 127.0.0.1:3425 by a portproxy of their own; after a reboot the portproxy listened no more and the Agents page still said Codex was connected) — Drift looked only at the config, which was right. Now an agent pointed at an address off loopback (this machine's Codex at an address the user kept, #816, through Agent.reach; every WSL twin under NAT, at Windows as the distro sees it, through Agent.Gateway) has that address tried from here (reach.go: GET /v1/models, any HTTP status an answer, 2 s timeout, in the background, at most every 20 s per address, never waited for), and one that doesn't answer while the gateway answers on loopback is a new drift, "unreachable", with Addr and the advice in Detail: under WSL (or on Windows) magpie with Settings › Share on local network on, or the user's netsh interface portproxy, which may need setting up again after a restart; Windows' firewall allowing the port for the WSL network; on Windows 11, networkingMode=mirrored; elsewhere, the forward to start again or gateway.URL() to point at. An answer not had yet, and a gateway down on loopback too, are no drift. The config is never changed for it, except where the address is one a WSL distro reached Windows at before (distro.Was, the last 4 kept in wsl.json as a re-probe finds Gateway changed) and the distro reaches Windows at another now: Drift's Move names that one, and Reapply moves the config there (Agent.move; Codex's codexMoveGateway rewrites openai_base_url and magpie's own provider's base_url, only where they begin with the old address). An address no distro was seen at is the user's own and is never offered a move. In the GUI the row's line says "{agent} is set up, but nothing answers at the address it reaches magpie by" in red with the advice as its tooltip, and its pill is "How to fix" (an i, not the reapply arrow), which opens the advice in a dialog (too long for the status line; it wraps and can be copied) and sets nothing — or "Use <address>" (the existing "Use {url}" string) when there is a Move, which reapplies; two new t() strings with zh, ja and de. The probe runs from Windows, not from inside WSL, so a firewall keeping WSL out isn't seen; the advice names it. TestKeptAddressNotAnswering (the reporter's case: Codex at 172.28.96.1, unreachable with the address and loopback in the detail; no drift once it answers, none with the gateway down too), TestKeptAddressProbeNeverWaitedFor, TestKeptAddressMovedWithWSL (Move from a Was address, Reapply rewrites both URLs, Check empty and no drift after; a 10.0.0.7 address is told but never moved) and TestWSLAgentAddressNotAnswering (Codex in a NAT distro told, with Share on local network, portproxy and firewall; a mirrored one never probed) fail without the Drift change and pass; TestLoopbackNotProbed, TestReachProbe (httptest: a 401 is an answer, a closed port none) and TestWSLWas pass. TestMain stubs reachProbe so no test dials out. -race -count=10 on them; go test -tags nogui ./internal/... under a temp HOME, go vet (darwin, windows), gofmt -l, linux and windows (nogui) builds pass. agent-unreachable.test.cjs (the window at 560px and the tray panel at 440px: the red line and tooltip, How to fix's dialog posting nothing, Use <address> posting the reapply, no sideways scroll) fails on main and passes on Chromium and WebKit in en, zh, ja and de; agent-connect, agent-layout, agent-field-names, aside-native, gui-de, gui-ja and i18n-keys pass on both. Not tried on a real WSL NAT setup (the Windows test box didn't answer ssh). docs/subsystems/agent-wiring.md says it. 2026-10-06 19:17:55 +08:00
wizzy-yangandwizzy-yang 6f391bc8f2 provider, agent, cli: a routing group's id carries Claude Code's [1m] mark (#1000)
wherever a ref is read back from an agent's settings

An agent on a routing group is shown, on the Providers page, on each of
that group's providers — the row's middle holds one button per agent, and
`uses` is what the Routing page's "n agents routed through it" counts.
A group whose model has a 1M window is written into Claude Code's
settings with the mark Claude Code itself puts on it
(`group/auto-deepseek-v4-1-flash[1m]`), and GroupFor takes the mark off
for the gateway; the rest did not. So the group was not found, and an
agent Claude Code had on it was listed on none of the group's providers,
while every request it made went through them.

Four places read such a ref back:

- provider.GroupFinder, which the Providers page asks (agentUses)
- agent.sameModel, which moves an agent whose group is gone to the same
  model from a provider still serving it — the mark left on made the
  comparison against AutoGroupOf find nothing, and the agent stayed on a
  group nobody serves
- agent.groupNamed, which says whether two values of a field reach the
  same group, one of them read back from the agent's own settings
- the CLI's groupUses, which lists "← agent" beside a group: the marked
  id was filed under one no group has, and Claude Code was on no row

Each takes the mark off, as GroupFor does. A group's own members are not
touched: those are the group's structure, never a ref from an agent's
settings, and a [1m] there is a model's, not the group's.

group_uses_test covers the page (a group found with and without the mark,
and the row naming the agent on the group's provider); applied_test covers
groupNamed; reseat_test covers the move (the marked group ref finds the
same model elsewhere, and a group that is nobody else's still gives
nothing); groups_cli_test covers the CLI, with Claude Code's settings.json
as the reporter's reads. Each fails without its fix. go build, go vet
pass; go test ./internal/agent/ passes, and the failures that remain are
the ones a clean origin/main has too (Aside's symlinks, ~/.codex
dependence, VSCode's launchers, a flaky Zed case).

Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
2026-10-06 16:02:03 +08:00
yetone ab47042ba8 agent: Codex on one of magpie's models beside its ChatGPT sign-in stays connected when Codex writes one of its own models back, and connecting keeps the model it was on through magpie where it can't join (#940, xybio)
Picked "via magpie" on a ChatGPT-signed Codex, a magpie model is set beside the sign-in: openai_base_url to the gateway, the magpie table, no model_provider. When Codex itself (its /model, or a Codex app still running on its old pick) then wrote one of its own models back (gpt-6.1-sol), Wired found nothing to say magpie had put it there, so the row read Not connected while its config still pointed at magpie's gateway. Set so, Codex keeps a codex.beside mark (gone when magpie becomes its provider, on a pick of its own through the picker, or on disconnect), and Agent.Beside makes Wired true on it; the model written back is still told as a change from outside (#750's drift stays). Connecting where Codex can't join (its ChatGPT allowance used up, or a model_provider of its own) went to the first of magpie's other models (Grok 4.7, "magpie doesn't serve the model it was on"), since Codex's field leaves out magpie's codex/* models: Agent.OwnVia now finds the model it is on as magpie serves it on the user's ChatGPT account (codex/gpt-6.1-sol), and Connect keeps it there.

TestCodexOwnPickAfterMagpieModelStaysConnected and TestCodexConnectKeepsItsOwnModelThroughMagpie are new; with the change taken out the first reads the reported config (model gpt-6.1-sol, openai_base_url, [model_providers.magpie], no model_provider) as not connected and the second connects to fake/m1 "first". Tested in temp HOMEs only. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (internal/proc TestUserPath timed out waiting on a login shell under load once, and passes on its own).
2026-10-06 02:30:31 +08:00
yetone 58ecd4454c davsync, agent: sync turned off and on again to the same server keeps what changed here, and an agent shown only routing groups connects on the first (#939, aiirobyte)
Off deleted sync-state.json, so turning sync on again made this computer a
new one: the first sync brought the server's whole setup in over it, and
every agent changed while sync was off went back to the server's older
fields. Off now keeps what this computer last synced (dropping only the
error, notice, undo and usage state), so it resumes: changes here go up.
TestOffAndOnAgainKeepsChangesHere fails without it (Codex's model went
back to "gpt-old").

The Agents switch said "magpie has no models Codex can use" when the only
models shown to the agent were routing groups (its own ChatGPT account's
are left out of Codex's list), while `magpie codex group/folia-1` worked.
Connect now falls back to the first routing group.
TestConnectOnARoutingGroupAlone fails without it.
2026-10-06 02:16:08 +08:00
yetone b2a3449021 gui, agent: the models picked for a WSL agent are the ones its picker, its own menu and the gateway list, and a model taken out leaves the picker at once (#927, cjyrainbow)
Claude Code · WSL Ubuntu's model list kept what it picked under its row's
id, claude@wsl:Ubuntu, while everything that lists models for it reads
claude's: the default-model picker (claudeViaMagpie), the models written
into its settings and the gateway's /v1/models for its key (magpie-claude).
The line said 2 models; the picker and Claude Code's own menu had them all.
Agent.ListsFor is the id a row's models are kept and read under, the
Windows twin's for a distro's agent, and the Agents page's model list and
line use it (Codex · WSL's order too).

Closing the list wrote the hidden set and refreshed the state afterwards,
but the click that closed it was the one on the model picker, which opened
on the row's old options. The row's pickers now drop what was taken out as
the list closes; what was put back comes with the state.

TestAgentModelsWSL (FakeWSL distro with Claude Code) and
agent-models-picker.test.cjs (Chromium, WebKit, en, zh) are new and fail
without the change. go vet, go build (darwin, GOOS=linux nogui,
GOOS=windows) and go test -tags nogui ./... under a temp HOME pass; the
agent-models*, click-scroll, codex-model-order and agent-model-groups GUI
tests pass.
2026-10-06 00:31:46 +08:00
yetone 528d6c12dc agent, gui: Codex left on model_provider = "magpie" with no [model_providers.magpie] loads its config again, and connecting with nothing in magpie says what to do, in the reader's language (Tystem on Discord) — the Codex app said "无法加载 config.toml … Model provider magpie not found", magpie showed Codex as not connected on "deepseek-flash", and its switch answered only "Codex can't be connected to magpie", in English. Codex looks model_provider up in [model_providers.*] as it loads config.toml (codex-rs: "Model provider {id} not found"), so the key without the table keeps it from loading any config, a new thread too, not just an old one. magpie never writes one without the other: it takes model_provider out whenever it steps out as the provider (disconnect, Unwire, a model of Codex's own, Join) and keeps the table so the threads started on magpie still open. That is unchanged, and TestCodexSteppingOutLeavesNoHalfState now covers it. Another tool or a hand edit had taken the table away. Sync, at magpie's start and whenever the catalog changes, now writes the table back whenever the config names magpie as its provider, at the top or in a profile, and has no table, whether Codex is connected or not. Check reports that state too. A config magpie can't parse is still only reported, never written to. A Connect that finds none of magpie's models because no provider or subscription has been added answers agent.NoModelsError, "Add a provider or subscription in magpie first, then connect Codex". /api answers it with code no_models and the agent's name, which app.js says through t() (en/zh/ja/de). docs/reference.md no longer says the table goes with a native model. TestCodexProviderWithoutTable (top and profile: Check says so, Sync writes the table) and TestConnectWithNoModels in internal/agent, TestAgentConnectNoModels in internal/gui, and agent-connect-no-models.test.cjs (WebKit, en/zh/ja/de: the toast in the reader's language, the switch back off, no scroll, no native dialog) are new and fail without the change; the latter's en case passes either way, as the server's message is English. Chromium wouldn't launch on this machine for this test or the existing agent-connect.test.cjs. TestCodexSyncAddsBaseURLToProvider now expects the table added to a hand-made provider that had none. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. In the first full run, internal/gui's TestProvidersAnswerWhileListsComeIn and internal/proc's TestUserPath failed under load; both passed alone and in the second full run. 2026-10-05 21:09:13 +08:00
Junjie Zhou 4a97acf12a refactor(agent): separate Aside provider connection from model settings (#827)
* refactor(agent): connect Aside as a native provider with verified settings

* fix(agent): offer explicit offline Aside model and disconnect actions

Offer Save for next start after an initial runtime read failure, using a
structured API error instead of saved runtime state. Keep refusals and
failed readbacks on the live error path.

Add a separate offline disconnect confirmation that restores the checked
file plan, clears restore records and removes the provider last. Bind the
confirmation to its preview revision and roll back ordinary write failures.

Cover offline API and browser flows, cancellation, stale plans, missing
CLI, restore metadata and native provider spelling. Keep state file-only.
2026-10-05 14:37:44 +08:00
yetone 2880b95b60 settings, gateway: the gateway's port is set in Settings › Network › Gateway, and every agent magpie connected moves with it (Magic_zero on Discord: 能否添加自定义端口号 — 3425 is taken on their machine, and they want a port of their own that is easy to remember and tell apart)
Before this, only MAGPIE_ADDR could move the gateway, and the app on a Mac or one started from the Start menu has no easy way to set an env var.

The setting:
- Settings has a Gateway port field. Any port from 1024 to 65535 can be typed, then applied with Apply or Enter.
- The port is saved in settings.json and kept on this computer (KeepOwn), so a backup or WebDAV doesn't carry it across.
- MAGPIE_ADDR, where it is set, still comes first. The field is then off and says so.
- A port out of range is refused in the page.
- A port another program listens on is refused: "port N is in use by another program: pick another one". The gateway stays where it was.
- With another magpie serving the gateway, the field says to set the port there.

On a change:
- The listener moves live (Relisten listens on the new port before closing the old one).
- When the old port had been taken by another program and nothing served, the gateway starts on the new one.
- Every agent connected to magpie has its config rewritten with the new URL (agent.OnGateway before the move, agent.Rewire after):
  - each one whose wiring is now "unwired" is set again;
  - Codex signed in with ChatGPT is joined again and keeps its own model;
  - Cursor Private Inference's variables and dsh's routes follow.
- What each agent had before magpie (the stash) is kept through this. Before, setting an agent again on the old URL would have written magpie's old URL and token over it.
- The page says how many agents moved.

What follows the saved port (through gateway.Addr()/URL() and settings.GatewayAddr):
- the CLI and healthcheck;
- Running();
- LAN sharing (Port);
- the drift check for the installed magpie, from beside a MAGPIE_ADDR one;
- importapps' "is this entry magpie's own" check.

zh, ja and de strings.

Tests, all failing on the old code:
- TestPortMovesEveryAgent: every agent with a config file is connected at 3591 and moved to 3592. No file keeps 3591, and none is off afterwards.
- TestPortMovesJoinedCodex.
- TestPortLeavesAnUnwiredAgent.
- TestPortKeepsWhatAnAgentHadBefore: the relay URL and own token come back on disconnect.
- TestDriftInstalledMagpieOnItsPort.
- TestSetPortMovesTheGateway, through the API: taken, out of range, moved, the old port silent, POST /api/settings keeps it, MAGPIE_ADDR refused.
- TestSetPortServesWhenTheOldOneWasTaken.
- TestGatewayURLOnSettingsPort.
- gateway-port.test.cjs on WebKit, en and zh:
  - out of range, taken (translated), applied by Enter, the agents counted, the new URL shown;
  - the MAGPIE_ADDR state;
  - no select, no left border, and the page never scrolls (the row is swapped whole, or WebKit laid the list out empty and the view jumped).

Sandbox run (own HOME, settings port 3591, magpie web on 3593):
- Claude Code (over a relay with its own token) and Codex were connected at 3591.
- POST /api/settings/port:
  - 3594, held by another program: refused, in use;
  - 80: refused;
  - 3592: moved [Claude Code, Codex].
- Both configs then say 3592. The gateway answers on 3592 and not on 3591, and `magpie healthcheck` exits 0.
- `magpie claude default` gave back https://relay.example and own-token.

lan-docker, settings-sections, settings-groups, click-scroll, gateway-caller-keys, gui-ja, gui-de and webdav-settings-refresh pass on WebKit.

go vet, the builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 11:28:51 +08:00
yetone 165fee0df5 agent: an agent's own provider named as one of magpie's isn't magpie's, in every agent that spells a model provider/model (the rest of #835) — OpenHanako's own deepseek/deepseek-v4-pro read as magpie's deepseek, and so did a model of any agent's own provider whose name magpie has a provider by: Pi's, Crush's, Hermes's, OpenCode's relay/glm-4.6 with magpie's relay had the row connected on the agent's own model, and Disconnect from magpie put that model back and left the row connected. An agent says how magpie's values are spelled in it (Spelled, replacing #835's Prefixed): magpie/<ref> for Antigravity CLI, Pi, OmO, Aside, Goose, Zed, VS Code, Crush, DeepSeek Harness, Command Code, fx, omp, Hermes, Mister Morph, Kimi Code, Empryo, MiniMax Code, Droid, Qoder, Qoder CN, Grok Build, AtomCode, Cline and OpenHanako, whose every Get spells magpie's so (a sandbox Set of magpie/relay/glm-4.6 read back as that in each); for OpenCode, MiMo Code and OpenChamber also a provider of the config's own that sends to magpie's gateway, as openCodeRef names a model there. A stopped WSL distro's agent keeps its live one's. Left as they are: Claude Code, Claude Desktop, Codex, Gemini CLI, Cursor, Copilot, Devin (magpie's are bare refs there), Muse Code (a model with / is magpie's by design: Meta's have none), Alma (its own are providerId:model), Air (magpie's only). TestOwnProviderNamedAsMagpies (26 agents: own relay/glm-4.6 not connected, Connect, Disconnect puts it back and the row is off) fails on the old code in each; TestOpenCodeGatewayProviderIsMagpies. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 06:49:45 +08:00
yetone b590edb5ef agent, gui: Claude Code taken off magpie by Default goes under Not set up and says Default (EZN7L2C3, #834 on v0.1.920) — picking Default and confirming Use default left the row up among the connected ones while it said Not connected, its model read Pick a model and its list had magpie's models alone. Default takes Claude Code's tiers and subagent model out with magpie's endpoint; Apply recorded only the field picked, so those read as changed outside magpie (replaced drift) and the drift kept the row up. Apply now records every field magpie set before that the change moves too. An agent not connected whose list has models of its own (Claude Code's, asked of Anthropic directly) now says what it is on, its Default or its own model, and lists everything as when connected: Default, its own models, magpie's. TestClaudeDefaultLeavesNoDrift (fails on the old code: drift replaced opus; a tier changed outside magpie is still said to be); claude-default-off.test.cjs (WebKit, en and zh: folded under Not set up, switch off, Default shown, Default current with the direct and via-magpie models listed, no scroll; fails on the old code: Pick a model / 选模型). agent-path-same, agent-leave-magpie, claude-picker-fold, claude-direct, agent-start-pick, model-rate, unlisted-models, agent-connect, agent-field-names, pi-default-note, click-scroll, desktop-model-menu, model-pick, favorite-star, agent-disconnect, agent-layout, gui-ja and gui-de pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 06:40:46 +08:00
yetone 6fb05259d7 agent: OpenHanako's own provider named as one of magpie's isn't magpie's, so Disconnect from magpie takes it off and the row says Not connected (Hu9956, #835) — OpenHanako spells every model provider/id, its own providers' as magpie's (magpie/<ref>), and a value of its own DeepSeek, deepseek/deepseek-v4-pro, read as magpie's deepseek/deepseek-v4-pro because magpie has a provider of that name. So the row stayed 已接入 on it: Disconnect put back the model the agent had before (its own deepseek/deepseek-v4-pro), took magpie's provider out, and the row still read as connected, on and on. An agent can now say what each of magpie's values in it starts with (Prefixed, magpie/ for OpenHanako); a value without it is the agent's own, never magpie's. TestHanakoOwnProviderNamedAsMagpies (own relay/glm-4.6 with magpie's relay: not wired, Connect, Disconnect puts it back and the row is off) 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. 2026-10-05 06:35:59 +08:00
yetone 2a4042a94d perf: magpie opens and shows the Agents page in a fraction of the time it took (Junjie Zhou on Discord: 8 个 agent 30 个 provider … 每次我打开的时候都会很慢,要好几秒。setting 页面秒进后 我切换到 agent 就有问题) — at start, writing the agents' model lists (agent.SyncCatalog) built every provider's catalog thousands of times with nothing held, each build reading migrations.json, settings and groups again: 6000+ file reads and ~8.5s of CPU in the first 8s with the owner's 30-odd providers, all competing with the first /api/state and the Agents page. Now SyncCatalog, magpieModels and main's start-up moves run under provider.Hold, migrations, groups, settings and a provider's fetched models are held for a second like the rest, and filememo.Hold lets a GET /api/* not stat a file it confirmed unchanged within the last second (any magpie write, Changed() or a recent mtime still reads it again). A big ~/.codex/config.toml parsed in quadratic time (the TOML parser's Shape counts newlines from the start for every key): a 3 MB one took 5.4s, now 0.04s (tomlShaper). theInstalled reads through edit.Read's memo. Measured with a copy of the owner's magpie config and agent configs under a sandbox HOME, the real server in WebKit: CPU in the first 8s 8.59s → 0.39s, page up 475 → 75ms, Agents rows drawn 775 → 325ms after start; the agents' written model files are unchanged (pi byte for byte, opencode the same models). TestTOMLShaperMatchesParser, TestTOMLBigFileParsesInLinearTime (fails on the old code), TestHold (filememo), TestHoldReadsMigrationsOnce. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 03:02:40 +08:00
yetone 2dc8e249cb 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. 2026-10-04 22:03:41 +08:00
yetone 7cc44b68a9 agent: Codex on a routing group's model name is still connected, not "switched off it outside magpie" (#750, Windows 11, magpie 0.1.812, Codex 0.160.0: Codex set to group/auto-gpt-6-1-sol in magpie, its config.toml then reading model = "gpt-6.1-sol" with openai_base_url still magpie's gateway, and the Agents page kept saying 在 magpie 之外被从 … 切走了 with 重新接入, coming back a while after each reconnect) — the gateway takes a model's name without a provider in it as the group of that model (provider.GroupFor: gpt-6.1-sol is group/auto-gpt-6-1-sol), so Codex's requests still went to the group; but Drift compared the field with what magpie recorded setting (applied.json) by string, and gpt-6.1-sol is neither that nor one of magpie's models by magpieValue (isMagpie wants a provider/model id, and Codex's options list it as its own or not at all), so it read as "replaced". What writes gpt-6.1-sol into config.toml is not magpie (no agent path writes a group's model name; set writes the group id as picked) and wasn't found — the Codex app persisting its thread's model by its own name is the likely one — which is why it came back after each reapply. Drift now passes over a field whose value and magpie's recorded one reach the same routing group, one by the group's id and one by its model's name (sameGroup, groupNamed: a group/… id as it is, "magpie/" taken off, else GroupFor); Codex's internal wired() and Agent.Wired (through a new Agent.Routed hook, Codex's routed(): openai_base_url or magpie as its provider) count the group's model name as magpie's only when magpie set that group on the field and Codex's config still sends its model to the gateway, so a Codex taken off magpie on gpt-6.1-sol is not connected, and a Codex's own gpt-5.5 that happens to have an auto group is no more magpie's than before (failover's base URL is untouched). Disconnect takes the field off the group's model name as it does off the group's id (back to Codex's default), rather than leaving Codex asking OpenAI for gpt-6.1-sol. Another group's model (gpt-6.1) or one no group has (gpt-5.5) is still "replaced". The reporter's ask to say which setting differs: the drift's detail already names it ("model is …, not … as magpie set it", the base URL or provider table for unwired) in the status line's and the Apply again pill's tooltip; that is left as it is. Tests: TestCodexGroupByItsModelName (two providers serving gpt-6.1-sol and gpt-6.1, signed in with ChatGPT and with an API key: group/auto-gpt-6-1-sol set, then config.toml's model rewritten to gpt-6.1-sol — Wired and no drift; no route to magpie — not wired; gpt-6.1 and gpt-5.5 — replaced) and TestCodexGroupByItsModelNameDisconnect fail on the old code (not wired, drift replaced, gpt-6.1-sol and the base URL left after Disconnect) and pass. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried on Windows or with the reporter's Codex and groups; not checked: what in Codex rewrites the model to gpt-6.1-sol. 2026-10-04 13:11:23 +08:00
yetone b56e1ff931 agent: a model picker says which way each model goes, a pick that takes a connected agent off magpie is asked first, and the switch says what it started the agent on (#726, EZN7L2C3 on v0.1.804: with Claude Code connected, Opus 5.5 moved it under 未设置 with 接入 off, Sonnet 5.5 turned it back on, and neither said "via magpie") — the connected Claude Code picker lists Claude Code's own Anthropic models (claudeOwn, direct "Anthropic") under the "Claude Code" header with nothing saying they are not through magpie, and the ones on its own account through magpie fold into "N models via magpie"; the reporter's Opus 5.5 was the own one, and Set with a model not magpie's unroutes Claude Code (unroute puts back the pre-magpie endpoint and token), so Wired() went false and the row folded under Not set up as v0.1.798 does with an agent not on magpie — what was written and the grouping agreed, nothing said why. Not connected, the row's picker lists magpie's models only, and picking one connects first (Agent.Pick), which is why Sonnet 5.5 turned 接入 on; that pop is the narrow one, where "<email> · via magpie" could be cut off at the end (the reporter at 00:56: the 未设置 dropdown did say via magpie).
Now each row in a field that mixes the two carries a tag: "via magpie" (经 magpie) on magpie's, "direct, not via magpie" (直连,不经 magpie) on the agent's own, and "off magpie" (不经 magpie) on Default where picking it takes the agent off; the note no longer ends in "via magpie", so it is said once and never cut. A pick in the field an agent is connected through that takes it from one of magpie's models off magpie — one of its own models, or Default — (leavesMagpie) opens a confirm as the switch's off does (askLeave, the disconnect-ask dialog, Cancel focused): it says what the pick does, that 「接入」 goes off (and the row goes under Not set up when other agents are on magpie), and that running copies take it once reopened. Default's offers Disconnect and restore beside Use default, the two not being the same: Default leaves the agent as installed (magpie's endpoint and models out, its own default model) and neither puts back what it had before magpie nor keeps the models for the next switch-on, which Disconnect does. Confirmed, it is written as before (setPick, the old commit body), Default saying "no longer goes through magpie · on its own default".

Switched on, the status says what model the agent was started on and why: agent.ConnectHow returns a Connection (how: kept, again, joined, magpie, same, alike, default, first; field; value) from the rule Connect follows (reconnect's memory; Codex on ChatGPT joined, its own last pick kept and magpie's models in its /model; else the model it was on through magpie — its own account, a subscription, a key — or its alias family, or with none set its catalog's first; else the first on its own account, the first subscription, the first), POST /api/agents/connect/{id} returns it as state.connected, and app.js says e.g. "Claude Code is connected to magpie · on Claude Sonnet 5.5 through magpie: it had no model set, so the first of its own". Connect is ConnectHow without the answer. New strings have their Chinese.

TestConnectSaysHow (alike for {"model":"opus"}, kept when connected, again after a disconnect, first for a model magpie doesn't serve) and agent-leave-magpie.test.cjs (the tags in a long-noted pop, Opus asked with nothing posted until Use, Cancel leaving it connected, Default's ask offering Disconnect and restore, a pick within magpie's and one connecting an unconnected agent not asked, the switch's how in the status, no click moving the page, en and zh) fail on the old code (ConnectHow undefined; no .badge.path) and pass; claude-picker-fold's note expectations drop "· via magpie" and it checks the tags. go vet, builds (nogui, GOOS=windows, GOOS=linux nogui), go test -tags nogui ./internal/agent ./internal/gui under a temp HOME, and the agent-*, claude-*, click-scroll and show-unset-agent GUI tests in WebKit pass; the rest of the suite fails as on HEAD (cli-update's tight row and others), and Chromium doesn't start in this sandbox. Not tried with the reporter's accounts or in the desktop window.
2026-10-04 09:12:05 +08:00
yetone df27f0882a agent: the 接入 switch and a model picked in the row, both (owner: 对于那种想在 magpie 中一键设置 Agent 模型的用户能否也兼容一下,鱼和熊掌都要兼得); a row opens in place and slides as on iOS (owner: 展开的时候,上/下 padding 变了,导致抖动;展开和折叠都没有 iOS 那种丝滑优雅精致的动画)
Every agent row keeps its 接入 switch and now has its model picker beside it. Picking a magpie model on an agent that isn't connected connects it first (agent.Pick, used by /api/set), so one pick sets the agent up; disconnecting still puts back what the agent had. The intro line says both ways.

An opened row shook: the connected row centred its lines in its 56px min-height, and the 3px row-gap couldn't be folded away, so opening moved the name and the switch and changed the space under them. The first line now has its own height and isn't centred, the row-gap is 0 with the spacing in margins, and the opened part starts where the shut row ended (56/56 at 980px, 90/90 at 560px; the name at 8px and the switch at 19px open and shut). Opening and closing animate the part's height, padding, margin and border on iOS's sheet curve cubic-bezier(.32,.72,0,1), 460 ms open and 340 ms shut, and what's in it fades in from 6px above; a row already open slides shut before another opens. With reduced motion it opens at once.

Gemini CLI's .env made by magpie for its key was left holding a newline after a disconnect (main too): DelEnvFile now removes a dotenv file once the deleted keys were all it held.

TestPickConnectsFirst, the only.env case in TestEnvFile, agent-start-pick and agent-expand-steady (name and switch unmoved, the opened part's top at the shut row's end, at least 3 heights between on the way open and shut, growing/shrinking only, chromium and webkit at 980 and 560px) fail on the old code and pass. Tests that open rows wait for the slide. In a sandbox HOME with real accounts: Claude Code and Gemini CLI picked while not connected answer PONG and disconnect back to what they had; Goose's pick → disconnect round trip is byte-identical (goose itself stops at a Linear MCP OAuth, so no request). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui for edit, agent and gui under a temp HOME pass; GUI tests that fail here fail the same on 82340f41 (account-arrange, cli-update, mobile-web, provider-levels-scroll, provider-proxy, redact-rule-row, routing-compact, provider-detect-models, plugin-move).
2026-10-04 02:05:10 +08:00
yetone 42a2b1113a agent: switched off and on again, an agent is back on the magpie models it was on, and Goose keeps its own model through a round trip — found running connect/disconnect twice for every agent against real configs in a sandbox HOME: turning one on again picked magpie's default instead of what the user had picked (OpenCode's model and small_model, Codex's model and effort, Pi, dsh, Hermes, Grok), and Goose lost GOOSE_PROVIDER/GOOSE_MODEL (its field clears both keys; on main too). Disconnect now stashes what it took off (<id>.reconnect: the values, which were routed through magpie, and what it left), and Connect puts them back when the agent is still as Disconnect left it — models on magpie first, so Gemini's model signs it in before its provider, and a value the model brought along (Codex's effort) is recorded as magpie's; changed since, Connect picks as before. Connect stashes what the agent was on (<id>.connect.was), and Disconnect sets back a field it left empty when that was the user's own (Goose's anthropic/claude-opus-5-5). TestReconnectKeepsTheLastPick, TestGooseRoundTripKeepsItsOwnModel and the new reconnect check in TestGeminiConnectRoundTrip fail on the old code and pass. Sandbox matrix: all 20 agents with a switch connect, disconnect and reconnect twice with the right state, every disconnect preview line is in the real change; 13 CLIs (claude, codex, gemini, opencode, pi, goose, crush, droid, grok, cline, omp, agy, commandcode) answer through the sandbox magpie. 2026-10-04 02:05:10 +08:00
yetone 661d27b560 agent: the disconnect preview right on Windows, and the Codex panel says what connecting does (owner: 去 Windows 测试机上测一下 / 是不是需要界面上解释一下现在的逻辑) — on the Windows test box Claude Code's and OpenCode's disconnect previews were empty though both were connected. Claude: the dry run's temporary home has no ~/.codex/auth.json, so a codex/… model wasn't magpie's there; the magpie asking now writes the providers it has on into that home and the dry run takes their models as magpie's (TestDryRunKnowsTheAskersProviders). OpenCode: magpie/codex/gpt-6.1-sol, a model its copy of magpie's list didn't have yet, read as not connected and Disconnect left it on magpie; a magpie/… value whose model magpie routes is magpie's (TestOpenCodeOnAModelNotInItsList). The preview pairs a line going back only with one as deep (Claude's model, not a modelPicker row) and doesn't mask …_TOKENS counts. The Codex panel, joined: 「重开 Codex 后,/model 里自己的模型照旧,magpie 的模型也在里面。」, and 新会话默认 says 「和 Codex 的 /model 是同一个选择,在哪边改都行」 rather than 「不设就用 Codex 自己上次的选择」 beside a value (/api/state: joined). On Windows (sandbox USERPROFILE/APPDATA, real accounts): previews for Claude, OpenCode, Codex and Gemini; disconnecting all four restored them (Claude back to opus, Gemini to Google sign-in, Codex keeps its [model_providers.magpie] by design), real ~/.claude untouched; real Claude Code requests via yylx/claude-opus-5-5 and codex/gpt-5.5 answered. The new tests fail on the old code. go vet, builds (darwin, GOOS=linux, GOOS=windows), go test -tags nogui -count=1 ./... under a temp HOME and the 34 agent GUI tests pass but cli-update, menu-scroll and old-webkit, which fail on main too. 2026-10-04 02:05:10 +08:00
yetone c47fee0b26 agents: Codex keeps its own last pick when connected, and every connected line starts 「已接入 ·」 (owner: 让 Codex 记住上次的选择,要统一)
Connecting Codex wrote a start model (it picked stepfun/step-1-32k, a dead one, for a ChatGPT sign-in). Signed in with ChatGPT, Codex now joins magpie by the base URL alone (Agent.Join): openai_base_url to magpie's gateway, magpie's provider table for the threads started on it, CC Switch's tables taken over, the models cache aged — and model untouched, the one last picked in its /model. Agent.Joined keeps it Wired while it is on a model of its own; failover leaves a joined Codex alone; a model of its own picked in magpie keeps it connected; Disconnect leaves Codex on the model it is on rather than the one before connecting. An API key or a provider of its own still connects on one of magpie's models, as its own can't be reached through magpie's provider.

The connected line for agents picking in their own list (Codex, OpenCode, …) read 「120 个模型在 OpenCode 的 /models 里」; now 「已接入 · OpenCode 的 /models 里有 120 个模型」, as the others.

TestCodexConnectKeepsItsPick fails on the old code (connected on fake/m1). Real Codex in a sandbox HOME with the owner's ChatGPT account: connect left model = "gpt-5.4" (Codex's), wired, no drift; codex exec on gpt-5.5 and on deepseek/deepseek-v4-flash both answered through magpie. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass; agent GUI tests pass but cli-update, menu-scroll and old-webkit, which fail on main too.
2026-10-04 02:05:10 +08:00
yetone d0d098c69f agents: the 「接入」 boards filled in — the opened row as designed, real accounts tried
- The opened row follows the boards: what to do in the agent, running copies with the old list, Claude Code's tiers (each with its own effort beside its model again, #536), the model list by whose models they are with what's hidden, the model new sessions start on, what connecting costs (Gemini's Google sign-in), and the files put back on disconnect, shown line by line.
- Disconnecting asks first and shows the lines it puts back. Secrets are masked, and a config of tens of thousands of lines diffs in a fraction of a second.
- Connecting prefers the agent's own subscription when magpie serves it (Claude, Codex).
- The dry run goes through proc.
- Every model hidden still keeps the row connected, with the way back to the list (#356).
- Routing groups are named in Chinese.
- Phone widths: the pickers and squares wrap inside the opened row, and the name stays beside its logo.

GUI tests moved to the new rows: connected fixtures carry refs and open the row from its link. tier-effort and mobile-web each found a real gap and now guard the fix.

Tried in a sandbox HOME with the owner's real accounts:
- Claude Code: connected, a request answered, and disconnect restored the settings exactly.
- OpenCode: a request answered.
- Gemini CLI: connected.
- Codex: connected.
- Model list picks were saved.

go vet, builds (darwin, GOOS=windows, GOOS=linux -tags nogui) and go test -tags nogui ./... under a temp HOME pass. The agent GUI tests pass except cli-update's tight-row case, menu-scroll and old-webkit, which fail on main too.
2026-10-04 02:05:10 +08:00
yetone 90d884ee60 agents: a switch connects an agent to magpie, and its models are picked in the agent (prototype, the owner: 在 agent 页面不应该是为 agent 选择某个模型,而是应该有个「接入」的开关) — agent.Connect sets the agent's main field to one of magpie's models (the one serving the model it is on now, else the first) or to magpie itself for an app whose one setting is magpie as its provider; that writes the provider and the whole catalog, so the agent's own list has every model. POST /api/agents/connect/{id}. Each row with magpie models to offer gets a switch and a line under its name (已接入 · 在 Codex 里用 /model 选 magpie 的模型 / 未接入 · Codex 用它自己的设置); off goes through the existing Disconnect dialog. Claude Code's /model lists only its tiers, so while routed magpie also writes modelPicker (2.1.287) with every magpie model, taken out on disconnect; one the user wrote is left alone. Checked in a sandbox HOME against a fake upstream: Codex 0.160 /model lists and uses magpie's models, OpenCode models, Pi --list-models, Crush's providers, Claude Code /model after connect; disconnect puts Codex back on gpt-5.4/high. 2026-10-04 02:05:09 +08:00
yetone dfc074afdb agents: Disconnect from magpie takes out everything magpie wrote into an agent's config and puts back what it had before (Fate on Discord: 移除由Magpie写入的配置,也就是重置功能,这个好像不是很明显。初步体验好像是选择默认就会清除写入的配置吗?希望能有一个更直接的交互动作,来代表移除由Magpie写入的配置。) — there was no one action for it, and picking Default isn't it: Default is the agent as installed, and for Codex, Claude Code and Gemini CLI it also forgets the stash, so the user's own provider or relay (model_provider + its table, ANTHROPIC_BASE_URL/AUTH_TOKEN, GOOGLE_GEMINI_BASE_URL/GEMINI_API_KEY and sign-in) was lost rather than put back. agent.Disconnect reuses each agent's own restore path: a new Agent.Unwire, for those three, runs the unroute their own-model pick already used (codex.go and claude.go have it pulled out of set as unroute; gemini.go's was there) and then forgets the stash, and every other field magpie set — each one reading a magpie value, or the value applied.json recorded and Unwire left — is set to "" through its own Set, which for every other agent unstashes what it had. applied.json forgets the agent (Keep), so no drift says it was switched off magpie. Agent.Wired (magpie or a magpie model in any field) goes to the GUI as agentJSON.wired; an agent magpie isn't in is left byte for byte. POST /api/agents/disconnect/{id} runs it under edit.Atomically as Sync and the fields' Sets are.
In the GUI, an agent magpie is in has "Disconnect from magpie" (断开 magpie(还原配置)) in its row's menu (its logo, or a right-click; beside Apply again), with a tooltip saying what it does, and in its model picker right under Default, so the two aren't taken for each other; the logo's title says the menu has it. It asks first in the app's own dialog (askDisconnect, as askReset and askForgetSaved do; no native confirm), and the row is then drawn from the answer: the model the agent had, no longer wired, and the status line says so. Every new string has its Chinese. The drag grip stays hover-only; no click moves the page.

What it leaves: Codex keeps magpie's [model_providers.magpie] table, as its own-model pick does, for threads started on it; with several ChatGPT accounts in magpie, Codex failover may write openai_base_url again on a later sync. A relay's own ANTHROPIC_MODEL in Claude Code's env was never stashed, so it doesn't come back; modelSettings effort entries for magpie models may stay in settings.json.

Tests: TestCodexDisconnect (own provider, own provider signed in, nothing set: the top keys as before, the user's provider table untouched, no subagent model, no catalog file, no stash, not wired, no drift), TestClaudeDisconnect (own relay and nothing set: settings.json as before), TestGeminiDisconnect, TestDisconnectUnwiredLeavesConfig, TestAgentDisconnectAPI; internal/gui/tests/agent-disconnect.test.cjs (WebKit, English and Chinese: only a wired agent has it in the menu and the picker, the in-app dialog, Cancel posts nothing, Disconnect posts and the row shows the old model, no native dialog, the page doesn't move). click-scroll, agent-grip, agent-layout, agent-models, agent-model-groups, model-pick, favorite-star, claude-picker-fold and panel-effort pass under WebKit; menu-scroll fails on /api/plugins/updates unmocked, as it does on main. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. Not run against a live agent config.
2026-10-03 02:42:09 +08:00
cyxer000andyetone 1ec5495b26 agents: omp's roles pick their own models (subagents, smol, slow), keep their thinking level, and get back what they had before magpie (#325)
* agents: omp's subagents and small role pick their own models, through magpie too

* agents: omp keeps a role's thinking level and the model it had before magpie, and offers the slow and designer roles

A role set to "anthropic/claude-opus-5:max" and switched to a magpie model lost its ":max", and resetting it deleted the key rather than putting the user's model back. The level now goes with the new model (omp clamps one the model lacks, never fails), the model the role had before magpie is stashed and restored, and the reviewer's @slow and the designer's @designer roles are fields beside subagents and small.

* gui: omp's slow and designer roles follow the model, as its subagents do

Unset, both roles take the session's model, yet the picker offered them omp's Default and no typed model. They are now squares beside subagents, with Same as model first and a model typed in taken as it is.

* agents: omp's thinking level no longer hides a role's model from magpie, and the model alone clears it — magpie omp magpie/x/y:high is taken, a role moved back to omp's own is drift, a list of models comes back on reset, and designer (gone in omp 18.1.5) goes

A role on "magpie/deepseek/pro:max" matched the picker only through the
option offered for its level beside the model, and only for the value in
the file now. So the CLI refused a model typed at a level, a recorded
value at a level the current one didn't share wasn't known for magpie's
(no "replaced" drift), and a level could never be taken away: a model
picked without one took the old one on.

An agent may now say what it keeps after the model (Agent.SplitSuffix;
omp's is its level). Drift, Reseat, RenameProvider, Spell and the CLI's
field-for-value match the model and put the suffix back after the one
they move to; agents without it are unchanged. The option at the level
stays: it keeps the level. Another model keeps it too; the same model
picked alone clears it.

A role omp falls back through (a YAML list, or the comma list omp joins
it into, settings.ts modelRoleValueFromUnknown) read as nothing, so it
wasn't stashed and a reset deleted it. It reads as that comma list now,
is stashed and comes back; a list has no level of its own.

omp 18.1.5 removed the designer role (CHANGELOG), so its field goes. The
smol role, like task and slow, gives its agents the session's model when
unset; its field is labelled smol, as omp names it, so the GUI can show it
as the others without touching other agents' "small".

* gui: omp's smol role follows the model as its subagents and slow role do, and designer goes

smol unset gives omp's scout and sonic the session's model, so it is a
square after the pickers with "Same as model" first, as subagents and
slow are (a feather). Its label is smol, not small: OpenCode's, Crush's
and OpenChamber's small model stays a picker. designer, a role omp 18.1.5
removed, leaves FOLLOWS_MODEL, the glyphs and i18n.

* agents: the note on omp's fallback chains says their keys are roles, and from omp 18 models too

ompRefKeys' comment had retry.fallbackChains keyed by model. omp 16.3.5 takes only a role's name there (session/agent-session.ts: "a mapping of role names to selector arrays"); omp 18.4.4 takes a role's name or a model selector (session/retry-fallback-chains.ts). Walking the keys stays: a role's name is no magpie model and is passed over. Follow-up to the review of #340.

* agents: omp reads whether it is on magpie one way, and a role at a level that a fallback chain names too is renamed once in each

Rebased on #340, one scan over omp's config (ompRefs) answers both questions: magpie's provider stays in models.yml while anything under ompRefKeys is on magpie, as #340 has it, and Check looks at the wiring while any role under modelRoles is, as this PR had it; a fallback chain or enabledModels alone keeps the provider without being checked.

A provider renamed moves a role at a thinking level through SplitSuffix first, then RenameRefs the rest, which finds no old name left in the roles: each place moves once, the level kept.

* agents: a fallback chain alone on magpie has omp's wiring checked, and a role set off magpie mends it

Check now reads the same keys dropMagpie does (ompRefKeys: every role, retry.fallbackChains, enabledModels, task.agentModelOverrides): whatever keeps magpie's provider in models.yml has its baseUrl checked, so a chain on magpie whose wiring something else moved no longer fails its fallback silently. Applying again sets the model role, which may be omp's own; a role set off magpie while something else still names it now writes magpie's provider afresh instead of leaving it as it is, so that mends the wiring. Review of #325.

* agents: an omp role that is a list of models stays the user's own, even starting on one of magpie's, and comes back as it was written

A role omp falls back through ([magpie/deepseek/flash, openai/gpt-6], or the same as a comma-separated string) was taken for one of magpie's models because it started with magpie/: magpie taking the role over stashed nothing, and a reset deleted it. Only one model, no comma, is magpie's now: SplitSuffix answers whether a value is one model, and Spell, drift (magpieValue), Reseat, RenameProvider and the CLI's fieldForValue leave a list alone. The stash keeps a YAML list as the YAML it was written in (edit.GetYAMLText), and a reset puts it back so, flow or block; a comma-separated string comes back a string. A provider renamed moves the names inside a list through RenameRefs, once, and in the lists the stash keeps too. Review of #325.

* gui: a test holds omp's subagents, smol and slow roles as squares that follow the model, and OpenCode's small model a picker

omp-roles.test.cjs, in Chromium and WebKit, English and Chinese, API faked: the three roles are squares after the model's picker, unset named "same as model" (「同主模型」) and set naming their model; smol's picker opens on "Same as model" with the model beside it, and a pick sends it and shows it. OpenCode's small model stays a picker. With smol and slow taken out of FOLLOWS_MODEL it fails at "small is a square". Review of #325.

* gateway: a Claude Code run whose subagent ended on StructuredOutput is let go, and runs left waiting on tool calls are bounded (#345) — a workflow's subagents end on StructuredOutput, which the client answers itself, so the bridge's claude -p waited 30 minutes for a result that never came, one process per subagent. Such a run now waits 30s (for a schema error the client sends at once) and ends; of other runs waiting 5 minutes or more on their caller's tools, 16 are kept, the longest waiting let go first (one that then gets its results starts anew with the whole conversation). TestClaudeRunEndsAfterStructuredOutput and TestClaudeParkedRunsAreBounded fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

* plugins: a built-in moved onto its plugin looks and works as it did (你确保插件版的订阅 provider 和其对应的内置的…都保持一模一样了吗?) — moved onto its plugin, a built-in lost pieces: its tile's name, icon, plans and risk note went to the plugin's own, "Add account" still opened the built-in's sign-in (in the app, on the server and in `magpie accounts add`), an agent's own sign-in the built-in still found showed a second usage card of the same account, the account's plan badge went, WorkBuddy's daily check-in stopped, the provider's icon and site were the plugin's, WorkBuddy AI's card was named WorkBuddy, and Devin, which had no card of its own, lost the plugin's. Now a moved built-in keeps its tile and risk sheet and signs in through its plugin; its cards take the built-in's place and name, and it has none of its own; the plan the plugin tells stays with the account; WorkBuddy checks in through the plugin, which signs the call; a card is left out only where its built-in's slot showed it. TestMovedBuiltinQuiet, TestWorkBuddyCheckinThroughPlugin, TestMoveToPlugin (Devin-like card) and TestPluginUsage (plan kept) fail without the change. Command Code and Devin moved and back in a sandbox HOME: one card each, plan, name. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; plugin-move, plugin-signin, commandcode-risk, old-webkit pass; click-scroll's WebKit fails the same on origin/main under this load.

* provider: the Providers and Gateway pages no longer wait on `claude --version` (deluxe on Discord: on Omarchy the two pages never loaded) — on Omarchy `claude` is a mise wrapper that installs or updates Claude Code before it answers, which on a slow network takes minutes or never ends; magpie asked it with no limit and with a lock held, so /api/providers (fetching the Claude account's models) and every Claude request waited with it. The CLI is now asked in the background, given a minute, and a caller waits at most 3s before the version it has stands in; a late answer is taken once it comes. Reproduced on an Omarchy VM (/api/providers unanswered after 100s on v0.1.516, 3.7s with the change). TestClaudeVersionDoesNotWaitForAStalledCLI and TestClaudeVersionTakenWhenItComes fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

* plugins: a plugin's account behaves as its built-in's (the user: 插件版的订阅 provider 和内置的…保持一模一样了吗) — a plugin's failed sign-in now says why ("the sign-in failed: the sign-in page expired") instead of a bare failure; a plugin account the provider refuses with 401 is marked lapsed, "<user>'s <provider> sign-in has expired — sign in again", beside the account and on its usage card as a built-in's is, and the mark goes when it answers again or is signed in anew; a Devin or Command Code account taken from the agent's CLI moves to the plugin marked as the CLI's and back as the agent's own, so the one it follows stays the one the CLI is signed in to. TestPluginProvider (lapsed), TestMoveSideState (cli) and TestPluginSignIn (reason) fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

* agents: "Hide all" in an agent's model list keeps its line, and an uninstalled Gemini CLI goes from the Agents page (#356, #230) — the line under an agent ("Showing 0 / N models") came only when a picker still listed one of magpie's models, so hiding them all took away the one way back; it now stays while any is hidden. Gemini CLI was taken as present from what it leaves in ~/.gemini (settings.json, .env, installation_id…), which stays after it is uninstalled, so its row stayed, offering to set up a CLI that can't run; it is now its gemini binary. TestAgentModelLineAllHidden and TestGeminiNotAntigravity fail without the change; agent-models-all-hidden.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/agent ./internal/gui ./internal/library ./internal/provider pass; agent-models, click-scroll, old-webkit pass.

* gateway: Codex's Responses Lite tools reach SuperGrok and every other backend, and a group moves on when a member can't read a request (#350) — Codex sends a Lite model's tools as an additional_tools input item, its own functions in a "functions" namespace; magpie relayed the item to xAI, which 422s on it (unknown item type), and translated routes (Cursor, Anthropic, Chat…) dropped it, so the model had no tools. Outside OpenAI the item's tools now go in tools, the functions namespace opened into plain tools and earlier calls un-namespaced; OpenAI and the ChatGPT account still get Codex's own form. A 400/422 over the request's shape (failed to deserialize, unknown item type/parameter…) now moves to the group's next member, each asked once, the member not resting; the Routing page says so. TestAdditionalToolsRelayed, TestAdditionalToolsTranslated and TestGroupFailsOverARequestShape fail without the change; routing-shape.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, routing-wb-refused pass.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-01 01:15:55 +08:00
yetone f7e38d0d2e agents: a magpie on a port of its own (magpie-dev, a sandbox) takes an agent wired to the installed magpie's gateway (127.0.0.1:3425) for that one's, not drift — the two took turns flagging Codex with Apply again, each rewiring it to itself 2026-09-27 14:54:35 +08:00
yetone a9aeb4d45f agent(codex): a Codex that couldn't reach magpie says so — the Codex app writes no history.jsonl, so a Codex it started while magpie wasn't running (the gateway refused it, and it built its model list without magpie's) or before magpie set it up (its requests still went to chatgpt.com or an old port) looked fine; magpie now reads the newest model request Codex logged since it was set (logs_*.sqlite, read-only, a day at most) and shows Apply again with the time and why, and to quit and reopen Codex 2026-09-26 01:16:27 +08:00
yetone 1b5d1f87db agent: every agent on a magpie model says when it was taken off magpie behind its back, not only Codex — each checks what magpie wired into it to reach the gateway (Claude Code's env base URL and token, and a managed-settings base URL that wins over them; Gemini CLI's .env and its auth type; OpenCode, Pi, Crush, Command Code, Hermes, omp and Grok Build's magpie provider; DeepSeek Harness's llm-deepseek entry and its key in .env), and one pointed elsewhere or gone shows Apply again with what is off in its tooltip; Claude Code, like Codex, is also said to be bypassed when it was used and nothing of it reached the gateway (its history.jsonl), and slash commands no longer count as use. A test takes every such agent off the gateway and back 2026-09-26 01:10:40 +08:00
yetone 04302b1e63 agent(codex): a Codex taken off magpie behind its back says so, with Apply again — something else rewriting config.toml (another switcher, an installer, a profile of its own) left the row showing a magpie model while Codex asked OpenAI for it, and the user blamed magpie; magpie now remembers what it set on each agent (applied.json) and tells three kinds of drift apart: the wiring gone (the provider table, catalog or base URL, or a profile overriding them), a magpie model replaced by one of Codex's own, and a Codex used since with none of its requests reaching the gateway (history.jsonl against when the gateway last saw it — an old process on an old config). A drifted row carries a coral Apply again pill on its name's line (a badge on the logo in the panel), the reason in its tooltip, Keep current settings in the row menu; the window asks /api/drift every 15s, so it shows without a reload 2026-09-26 01:05:19 +08:00