Commit Graph
769 Commits
Author SHA1 Message Date
yetone 5416fdb76b agent: Claude Code on magpie keeps its MCP tools deferred (ENABLE_TOOL_SEARCH)
cybercaius on Discord (#help): the MCP router's 245 tools took 124K
tokens of a 341K context ("Magpie ×245" in Usage › Context). Claude Code
before 2.1.304 keeps tool search off behind an ANTHROPIC_BASE_URL that
isn't Anthropic's, so every router tool's definition went on every
request. 2.1.304 (10-19) turned it on for gateways itself, but a
conversation begun without it stays held off.

While Claude Code is routed through magpie, magpie now writes
env.ENABLE_TOOL_SEARCH="true" into ~/.claude/settings.json: Claude
Code's own documented switch, no prompt or identity change. The gateway
carries deferred tools to every upstream already (#2660,
withoutDeferredTools). It follows the auto-mode review's ownership:
magpie's value is stashed (claude.tool_search), a value the user set,
an empty one too, is theirs, and magpie's goes in desktopOnly/unroute.
T3 Code's magpie instance gets the same "true" in its environment
unless the user gave it a value there.

Not changed, filed as #4755: agents with no tool search of their own
(OpenCode, Gemini CLI, ...) still get the router's whole list; a lazy
router mode for them needs an owner decision. Not changed: Codex, which
already sends tool_search on magpie's catalog (0.165.0 measured: 14
tools, no MCP ones), and newmax/claudescience, which run Claude Code
through the SDK and set no gateway env of this kind.

Run:
- Real Claude Code 2.1.290 on mote, sandbox HOME, sandbox magpie serve
  on 127.0.0.1:3563 built from this tree, a fake Anthropic upstream, a
  245-tool stdio MCP server in the Library behind the router, wired
  with `magpie claude up/fake-1`: first /v1/messages had 12 tools,
  27,443 bytes of tools JSON (+~9KB of deferred names in the messages).
  The same with magpie's ENABLE_TOOL_SEARCH taken out (the old
  wiring): 266 tools, 245 of them MCP, 242,346 bytes.
- Without magpie, against a capture server: 2.1.200 to 2.1.303 send
  every MCP tool (239-257KB); 2.1.304 to 2.1.316 defer them (~28KB);
  ENABLE_TOOL_SEARCH=true in settings.json env or the process env makes
  2.1.200, 2.1.260 and 2.1.290 defer them too.
- TestClaudeToolSearchOn, TestT3CodeToolSearchOn (new); #4755 filed.
- go test -tags nogui ./internal/agent on mote; GOOS=linux and
  GOOS=windows go vet ./internal/agent; gofmt -l.
Broken by hand: writeSearch stashing nothing and writing nothing, and
T3's entry left out: both new tests red. The user-value check skipped:
TestClaudeToolSearchOn red on the user's "false".
Not tried: a real model loading a deferred router tool through
ToolSearch and calling it via magpie (gateway tests cover deferred
tools); Claude Code on Windows/Linux; T3 Code's real app.
2026-11-01 16:15:27 +08:00
yetone 3defaf6622 dsh: a new desktop profile gets magpie's routes when the start is the user's (zyh6036 on X)
DeepSeek Harness Desktop 0.2.1-rc.5's picker listed only "DeepSeek 账号".
The app reads $DSH_HOME/profiles/desktop (apps/desktop/src/paths.ts) and
makes it from an empty template on its first start. dshFillNewProfiles
gave such a profile magpie's routes only when a wired profile started on
one of magpie's models; with the web profile wired but started on one of
dsh's own, it returned early and the desktop profile stayed bare. Now a
bare profile gets the routes alone in that case (no start written, the
user's pick stays theirs), and nothing is filled when no profile is wired.

Run:
- go test ./internal/agent -run TestDshFillNewProfiles on mote at
  ed5872d18: the new TestDshFillNewProfilesWhenTheStartIsTheUsers red on
  the old code (desktop profile left as the template), green after.
- go vet ./internal/agent (darwin, GOOS=linux, GOOS=windows) and
  go test -count=1 -timeout 45m ./internal/agent on mote: ok (183s).
- Real DeepSeek Harness Desktop 0.2.1-rc.5 (official zip, sha512 checked
  against nightly-mac.yml) on mote, sandbox DSH_HOME, not signed in:
  first start wrote profiles/desktop/cordis.patch.yml as the empty
  template; with a route-only patch (no agent-default-model), as this
  change writes, the picker listed the Magpie group (35 models).

Broken by hand: the no-profile-wired guard taken out, the test's last
check goes red (web and desktop templates filled).

Not tried: the reporter's own patch (not sent yet); a signed-in DeepSeek
account in the desktop app; the full go test ./... suite; Windows.

At the pushed head (rebased on e84870f17): go test -count=1 -run Dsh
./internal/agent on mote ok, gofmt -l clean.
2026-11-01 13:29:19 +08:00
yetoneandFake Trader 0cabaaf243 agent: a portable VS Code on a Mac is wired in its code-portable-data folder (#4151)
faketrader runs VS Code portable on a Mac: /usr/local/bin/code links into
/Applications/Code/Visual Studio Code.app, and the build reads
/Applications/Code/code-portable-data/user-data/User. magpie detected it
but wrote ~/Library/Application Support/Code/User, which that build never
reads. Their patch on #4151 is the base; this takes its rule and makes it
VS Code's own (configurePortable in src/bootstrap-node.ts), on every OS:

- A build is portable when its product.json has no `target` (an
  installer's build has one) and its data folder exists: on a Mac
  product.json's `portable`, else `<applicationName>-portable-data`,
  beside the .app; on Windows and Linux `data` beside the install, also
  for a build that updates into `<install>/<version>/resources/app`.
- The build is the one the launcher on PATH is, through a Scoop shim and
  every symlink. A launcher whose product.json names another editor (a
  fork's `code`) isn't the build's. With no launcher of its own, a Mac
  reads the app folders and Spotlight and takes a portable bundle only
  when every bundle found is that one; beside an installed bundle, which
  one runs is unknown and nothing moves.
- VS Code, Insiders and VSCodium each go by their own bundle and launcher.
- User and extensions come from one place (vscodeDirs): connect, Sync,
  profiles and Disconnect use the portable User folder, and Zoo Code is
  found by its extension in <data>/extensions and writes its import file
  there. Windows' Zoo Code under Scoop looked in ~/.vscode/extensions.
- Disconnect's preview is refused for a file in a portable data folder:
  the preview's child keeps PATH, and its launcher would reach the build's
  real files, not the copy. That also covers Scoop under home on Windows,
  which main previewed.
- An installed build with no portable folder keeps the OS's folder and
  ~/.vscode/extensions, unchanged.

#3260 and #4009 (Windows): 509d8e7d1 (ggbdpq) already moved Scoop's
`current\data`; this adds the target check, the versioned layout, the
Windows Zoo Code folder and the preview refusal above.

Tests (fixtures under t.TempDir, never /Applications or ~/Library; app
folders and Spotlight stubbed): TestVSCodeMacPortableDirs (stable,
Insiders, product's `portable`, no data folder, Windows' `data` name,
another editor, another channel's folder, unreadable product, installer
target), TestVSCodeMacPortableLinkChain (three links, folders with
spaces), TestVSCodeMacPortableWiring, TestVSCodeMacPortableWithoutLauncher,
TestVSCodeMacPortableLauncherPicks, TestVSCodeMacPortableForkLauncher,
TestVSCodePortableProduct (Windows/Linux: target, fork product, versioned
install, Zoo Code, Scoop preview).

Broken by hand, each went red and was restored: main's rule on darwin
(6 Mac tests FAIL, standard folder used), target ignored (Dirs, Product),
no preview refusal (Wiring, Product), first bundle wins
(WithoutLauncher), fork launcher decides (ForkLauncher), Zoo Code on
home's extensions (3 FAIL). On origin/main the new tests don't compile
(vscodeDirs is new); break #1 is main's Mac behaviour.

Run:
- mote (macOS 27), full suite at this change on 479476784:
  go test -tags nogui -timeout 45m -count=1 ./... : 85 packages ok
  (internal/agent 405s, gateway 832s, provider 251s), internal/gui red on
  two filed tests this change doesn't reach: TestSettingsSaveKeepsWhat-
  ItDoesNotSend (SearchAll, #4514) and TestColdTurnsTaken (#4510).
  Rebased onto 90c02326b (gui takeover, sessions save, kiro min; nothing
  in internal/agent): go build, go vet of agent/gui/sessions/provider and
  go test of internal/agent, internal/sessions, internal/provider again
  at the pushed head: ok (agent 352s, sessions 110s, provider 228s).
- mote (macOS 27): go test -tags nogui ./internal/agent -run
  'TestVSCode|TestZooCode' ok; gofmt -l clean; go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., GOOS=linux
  go build -tags nogui, GOOS=windows go build ok.
- win-run (Windows 11) and wsl-run (Ubuntu 24.04): the agent tests above
  plus Preview, ok.
- Real use on mote, sandbox HOME, PATH=$SB/bin:/usr/bin:/bin: VS Code
  1.144.0 darwin-arm64 from update.code.visualstudio.com unpacked to
  "$SB/Apps With Space/Code/Visual Studio Code.app", `code` linked
  bin/code -> "link one/code" -> the bundle's bin/code. Without
  code-portable-data, `magpie agents` lists ~/Library/Application
  Support/Code/User/settings.json; with it, ".../code-portable-data/
  user-data/User/settings.json". The real `code --install-extension
  zoocodeorganization.zoo-code` put Zoo Code 3.94.0 in
  code-portable-data/extensions (no ~/.vscode made), and magpie then
  listed Zoo Code at the portable User folder. `magpie vscode
  deepseek/deepseek-chat` wrote settings.json and chatLanguageModels.json
  there, `magpie vscode default` took magpie out of both, and Zoo Code's
  connect wrote its import file under the portable globalStorage and its
  disconnect removed the setting; ~/Library/Application Support/Code was
  never made.
- Real use on xiaomi-gpu (Windows 11), sandbox USERPROFILE/APPDATA,
  PATH=<install>\bin;System32: VS Code's win32-x64 ZIP (its versioned
  layout, <install>\2c33b50b16\resources\app) unpacked to "Apps With
  Space\VSCode". Without data, `magpie agents` lists ~\AppData\Roaming\
  Code\User\settings.json; with data, <install>\data\user-data\User\
  settings.json. The real code.cmd --install-extension put Zoo Code in
  data\extensions (no ~\.vscode), magpie then listed Zoo Code there,
  and connect/disconnect wrote and cleaned that User folder; %APPDATA%\Code
  was never made.

Not tried / not handled: VS Code's window wasn't opened to see the model
picker (headless ssh). VSCODE_PORTABLE isn't read: it is the editor's
environment, not magpie's. A Windows or Linux portable build with no
launcher on PATH isn't found (there is no standard place to look). A group
an older magpie wrote in the OS's folder for a portable build stays there;
connecting again writes the portable one. A Claude Code or Codex extension
in a portable build doesn't keep that CLI from showing as gone: #4672.

Co-authored-by: Fake Trader <9635792+faketrader@users.noreply.github.com>
2026-11-01 11:55:33 +08:00
yetone 733fac48fb qwenpaw: each model says how its thinking is set, and the editor sets the level (Pkh)
Pkh (Discord, 0.1.2509 on Linux, QwenPaw 2.2.2.post1): QwenPaw's
thinking strength did nothing on magpie's models.

Cause, from QwenPaw 2.2.2.post1's own source:
- providers/provider.py thinking_control() takes a model's
  thinking_control, else its thinking_param_style; with neither it is
  ThinkingControl() of kind "unknown".
- providers/thinking.py resolve_thinking drops an unknown control to
  inherit, so agent.json's thinking_level was never sent.
- magpie wrote neither key in magpie.json's models, so every magpie
  model was "unknown".

Change:
- qwenpawModelJSON writes thinking_param_style "effort" and
  reasoning_effort_options for a model whose catalog efforts include
  levels QwenPaw names (minimal, low, medium, high, xhigh, max), in
  QwenPaw's order. "none" is left out: QwenPaw's off sends
  enable_thinking / thinking extra_body, which the gateway strips for
  some upstreams.
- Both keys are magpie-owned. A model whose efforts go away has them
  taken back. A null magpie writes where it never wrote is dropped,
  so a user's own config_overrides are kept.
- The QwenPaw agent editor gets an effort field over agent.json's
  thinking_level. "" writes inherit. Setting a level drops
  thinking_budget, which QwenPaw's validator requires. A budget or
  off level the user set is shown and kept.
- Docs: agent-wiring.md and reference.md.

Run:
- gofmt -l: clean.
- go vet darwin, windows, and linux (-tags nogui): clean (mote).
- go test -timeout 45m ./internal/agent/...: ok (mote).
- go test ./internal/gui: 3 reds, also red on origin/main 8ac1c7a56
  and already filed (#4514, #3949, #4510).
- Real QwenPaw 2.2.2.post1 in a sandbox HOME, in WSL magpie-desktop:
  - Loaded magpie's generated magpie.json and agent.json with
    QwenPaw's own ProviderManager and AgentProfileConfig.
  - kimi/k2 resolves to {kind: effort, efforts: [low, medium, high,
    max]}.
  - A real request to a local capture server carries
    reasoning_effort "high" at level high, and none at inherit.
  - The old file's model resolves to kind unknown, and sends nothing
    at any level.

Broken by hand:
- With the origin qwenpaw.go, both new tests are red.
- Without the thinking_budget delete, TestQwenPawEffortField is red.
- Without the new owned keys, the take-back assertion is red.

Not tried:
- QwenPaw's full app UI against a running magpie gateway.
2026-11-01 10:54:38 +08:00
yetone da0005df81 agent: /api/state lists running agents once in 3s, not with a pgrep each call
/api/state asks StaleCopies for every wired agent, and each pattern
started `pgrep -lf`, which walks every process's arguments. On a Mac
with ~1000 processes that was most of a state call: 45ms each, on every
page switch, save and GUI poll, with a pgrep child seen in 25 of 40
samples.

StaleCopies now reads runningLately: a pattern's listing is kept for
3s, with each process's start (not its age), so an age read later is
still right. A fresh listing (a restart waiting for its app to end)
replaces what was kept, so the look that finds the app gone is what the
next poll sees. A test that fakes running is asked each time. The
waits in apprestart still list now.

Run (mote, this tree):
- go vet ./internal/agent ./internal/gui; GOOS=linux and GOOS=windows
  go vet ./internal/agent: ok.
- TestRunningListedOnceInAWhile, TestRunningNeedsNoPs: ok.
  Broken by hand (every call lists): red, "listed 6 times in a row,
  want 1".
- go test ./internal/agent ./internal/provider: ok. ./internal/gui:
  only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK (#3949), both red on main too.

Real accounts (sandbox HOME from a copy of the live accounts, on this
Mac with its real Codex app, daemons and CLI running):
- /api/state, 10 calls after 200: v0.1.2519 43-60ms, this 8.4-21ms
  (twice each, alternating). pgrep children in 40 samples: 26 and 24
  before, 1 and 1 after.
- Each wired agent's stale copies (Codex: app, two daemons, cli, each
  with its start) are the same from both binaries, read twice 4s apart.

Not run: the full ./... suite; Linux and Windows runs of the agent
package (vet only).

Picked onto 9be72c948 (origin/main at push); not run again there.
2026-11-01 10:32:21 +08:00
yetone 9be72c9480 zcode: a level's thinking carries its budget, and the user's own level options stay (#3852)
Review of d7e1e284f, two things it changed beyond its case:

- Every level that thinks was written as {"thinking":{"type":"enabled"}}
  with no budget_tokens. ZCode puts a level's options in the request, so
  a Claude before 4.6 (Sonnet 4.5, Haiku 4.5, a relay's) asked through
  magpie at any level would be sent "enabled" without the budget
  Anthropic's Messages API requires with it, a 400 it didn't get before.
  Each level now carries the budget the gateway reads that effort as
  (gateway.ThinkingBudget, budgetOf: low 4096 ... max 32000). The
  gateway already makes it adaptive for Claude 4.6 and later
  (adaptiveThinking; ZCode's output_config.effort wins over the budget)
  and fits it under max_tokens (maxoutput.go).
- providerOptionsByLevel was written over on every sync. A user who put
  their own there (the workaround for this very bug) lost it. A level's
  options already in config.json now stay; no magpie before #3852
  wrote any, so whatever is there is the user's.

Tests: TestZCodeOutputAndReasoning expects the budgets;
TestZCodeKeepsTheUsersLevelOptions keeps a hand-written high level and
fills the others.

Run on mote: go test -run TestZCode ./internal/agent, ok. Broken by
hand: the kept options ignored and the budget left out, and those two
tests fail.
Not tried: a real ZCode 3.x (this Mac has Z Code 0.9.1, a different
app; mote has none), so ZCode putting the options in the body is the
reporter's and the author's reading of zcode.cjs, not seen here.

Batch record (gua's #2833 #3052 #3205 #3867 #4107 #4247 #4245 #4113
#3852 and the three review follow-ups; #4106 left out, its test isn't
red without its fix, see the issue):
- Full run on mote before the rebase (base fa4704f06): gofmt -l clean;
  go vet on darwin, GOOS=linux -tags nogui and GOOS=windows clean;
  go test -count=1 -timeout 45m ./...: 85 packages ok, internal/gui red
  in TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK (#3949), both already filed, and
  neither in a file this batch touches.
- Rebased on origin/main 9162277b9, at this tree, on mote: gofmt clean;
  go test -count=1 -timeout 45m ./internal/gateway/... ./internal/agent
  ./internal/library ./internal/handoff ./internal/routes, all ok
  (and ./internal/redact ok at the base before, b2145eac1). Then
  rebased again on ccb75030a (#4371, fastjson.go only) and
  ./internal/gateway/... run again at that tree: ok (636s). Pushed on 8ac1c7a56 (internal/catalog
  only), where catalog, handoff and library ran whole and the batch's
  gateway (Bili, TestRuleCompact, Kimi, TestClaudeMem, the two stall
  tests) and agent (TestZCode) tests ran: all ok. The whole gateway
  package was not run again on top of 8ac1c7a56.
- Windows (win-run): -run TestClaudeMem ./internal/gateway ok; with
  claude_room.go put back, TestClaudeMemRunsFromTheCgroup hangs in
  readLimit to the 5m timeout.
- Linux (wsl-run): ./internal/handoff ./internal/library ok; with the
  fixes put back, TestGiveKeepsTheListenerNonblocking,
  TestSaveDropsEmptyApplied and TestSyncAloneLeavesNoEmptyApplied fail.
Not tried: real Kimi, ZCode 3.x, Alma or bili accounts; #4245 is a
test-only change and was not reproduced red.
2026-11-01 10:26:42 +08:00
ggbdpq bc7d833916 zcode: the reasoning keys ZCode reads, not OpenCode's (#3852)
magpie's ZCode takeover wrote a model's reasoning as
{"enabled":true,"variants":[…],"defaultVariant":…} — OpenCode's
shape, which ZCode's config.json provider entry is loosely modeled
on. ZCode's own schema for it is
{enabled?, levels?, defaultLevel?, providerOptionsByLevel?}
(resources/glm/zcode.cjs, same in the 3.12.3 the issue reports and
in the 3.16.3 checked on this machine; "defaultVariant" has no
occurrence in the 3.16.3 runtime at all). Its .passthrough() keeps
the unknown keys and ignores them, so ZCode picked a level, sent
output_config.effort and never a thinking field — and an
always-thinking upstream model (Kimi Code's kimi/k3.1-pro, for one)
refused every request with 400.

magpie now writes the keys ZCode reads: levels and defaultLevel it
had all along, plus providerOptionsByLevel with thinking on for
every level and off for the one named "disabled". The kept default
a sync reads back now looks for defaultLevel, falling back to the
defaultVariant an older magpie wrote (a key ZCode never read, only
magpie) so a user's choice survives the first sync after the
upgrade. The provider_config.json rule side is untouched: its
optionSpecs.reasoningLevel.values is already a key ZCode reads.

The OpenCode family keeps variants/defaultVariant: there those are
the keys the app reads.

Fixes #3852

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 10:22:57 +08:00
yetone b62b914964 agent: Claude Code's model field joins its own models with magpie's list once
Claude Code's model field appended its own models to the list it keeps
of magpie's (claudeViaShared), a copy of the whole catalog on every
call, as withVia did for the other agents until cdfdb62c6. With real
accounts, 40 window polls spent 9 MB flat in that append.

withVia's cache is now joinedVia, keyed by the caller, and the field
reads through it, here and in a distro asleep (wsl.go). withVia still
gives the shared list itself when there are no own models; joinedVia
always gives a list apart from via, so a write to the model field's
options never reaches the list kept (TestClaudeViaMagpieKept).

Run on mote (macOS), at this tree:
- gofmt clean; go vet ./internal/agent for darwin, windows and linux.
- TestClaudeModelFieldKeepsTheJoinedList, TestWithVia*, TestClaudeVia*
  and TestSameOption* alone 3/3 ok.
- Broken by hand: the plain append back -> "Claude Code's own models
  joined its list from magpie again"; joinedVia handing out via with no
  own models -> TestClaudeViaMagpieKept "a write to the model field's
  options reached the options kept (folded true)".
- go test ./internal/agent ./internal/tui ./internal/cli: ok.
- go test ./internal/gui: red only on #4514 and #3949, as before.
- Real-account sandbox, 40 window polls against the GroupFinder tree:
  Agent.Picks 56.4 -> 42.6 MB, gui.state 138.0 -> 130.0 MB; /api/state
  and drift output byte-identical; phys_footprint_peak 139 MB.
Not run: the whole ./... suite; a real WSL distro.
2026-11-01 08:35:37 +08:00
yetone ffc18a850d agent: an app folder is listed and an Info.plist read again only when it changed
The Agents page asks every desktop app whether it is installed, and its
version, on each poll. Each ask listed /Applications and ~/Applications
whole (os.ReadDir, for the one-level-down folders of #2325) and read
every candidate bundle's Info.plist. With real accounts, 40 window polls
spent 38.6 MB of allocations in Agent.Detected, 14.5 MB of it ReadDir.

folderSubs keeps a folder's non-bundle subfolders while its
modification time stays (adding, removing or renaming an entry changes
it), and bundleInfo keeps what an Info.plist said while its size and
modification time stay. A time under 2s old is never trusted, as git
treats a racily clean index. macBundle and desktopApp.version read
through bundleInfo; what each reports is unchanged.

Run on mote (macOS), at this tree:
- gofmt clean; go vet ./internal/agent for darwin, windows and linux ok.
- TestAppFoldersReadAgainOnlyWhenChanged alone 3/3 ok.
- Broken by hand: never trusting the kept list and plist -> "an
  unchanged app folder and Info.plist cost 1268 allocations a look";
  trusting them whatever changed -> "Moved.app in a folder added since
  isn't found" and "Kept.app's Info.plist says another id now".
- go test ./internal/agent ./internal/tui ./internal/cli: ok.
- go test ./internal/gui (with the next commit's providers.go too): red
  only on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949), as before.
- Real-account sandbox, 40 window polls against v0.1.2504's tree:
  total allocations 509.9 -> 427.6 MB, Agent.Detected 38.6 -> 21.5 MB,
  os.ReadDir 14.5 -> 4.0 MB; /api/state and drift output byte-identical.
  phys_footprint_peak 139 MB (136 before; within run noise).
Not run: the whole ./... suite; the Linux and Windows app paths (they
don't reach these readers).
2026-11-01 08:12:34 +08:00
yetone cdfdb62c69 agent: a model field's list is joined with the catalog once while neither changed
Each agent's model field returned append(its own models,
viaMagpieShared(...)...), a copy of the whole catalog's options for
each field of each agent on every poll: Picks was 94.7 MB of 496 MB
over forty polls of the Agents page with real accounts. withVia keeps
the joined list per agent and prefix while the own models read the same
(sameOption, field by field) and the catalog's list is the very one
kept (same array), and joins it again when either changed. The list is
read only and clipped, as viaMagpieShared's is; every caller of a
field's Options reads it, Picks clones it before it drops anything.
The 52 `return append(own, viaMagpieShared(...)...)` sites call it.
omp's and Reasonix's planner edit the joined list after the append, and
Grok's writes Same into its copy, so they keep their own copies.

TestWithViaKeepsTheJoinedList: the same own models give the same array,
own models changed in a value or only an icon are joined anew, a
provider saved since is listed, and nothing joined is the catalog's own
list. TestSameOptionReadsEveryField sets each field of Option alone and
fails when sameOption doesn't see it. Broken by hand: never answering
from the kept list ("the same own models joined the catalog again"),
and FastFor left out of sameOption ("sameOption doesn't read
Option.FastFor").

Run on mote: both tests alone 3 of 3; internal/agent, internal/tui and
internal/cli ok; internal/gui red only on TestSettingsSaveKeepsWhatItDoesNotSend
(#4514) and TestMainWindowCorners (#3949); gofmt, vet and GOOS=windows
and linux vet clean. Real accounts in a sandbox HOME, forty polls:
Picks 94.7 MB -> 51.2 MB, state 190.8 MB -> 154.0 MB, state and drift
replies byte for byte the same as before. Footprint peak 136 MB.
2026-11-01 07:54:54 +08:00
ggbdpq 2c33db2499 agent: VS Code 1.139's versioned layout hides the launcher's marker
Tony-ooo's retest (magpie 0.1.2322, VS Code 1.144.0 on Windows): the
false positive of #3269 is back — bin\copilot-shim on PATH, no ~\.copilot,
and magpie ls still lists Copilot CLI. The marker check 6f435677c reads
six product.json places around the launcher (its folder and two above,
directly or under resources\app), and all six are absent: VS Code 1.139's
versioned Windows layout (win32VersionedUpdate) keeps the app's payload
in a folder named for the build's commit — the short hash, ten lowercase
hex digits, 2c33b50b16 for 1.144.0 — with resources\app under it and bin
beside it (microsoft/vscode#343045), so product.json is at
<install>\2c33b50b16\resources\app\product.json, one level under the
deepest place the walk reaches.

The walk now also takes a build folder a commit's short hash names: a
child of any of the three folders whose name is ten lowercase hex digits
and that keeps resources\app\product.json there. A folder of the user's
is not named as a commit's short hash is, so the cap keeps its meaning —
nothing wider than the same three folders is read, and a product.json
further up still says nothing of an editor.

vscodeCodeBinary is left alone: it reads product.json to tell WHICH build
a code launcher belongs to, and when it reads none, keeping the PATH
fallback is that function's own documented behavior; #3269's judge only
asks whether an editor keeps the folder at all.

Run:
- TestCopilotLauncherBesideTheBuildsHashFolderIsNotTheCLI (new): red on
  fb29cd30f ("VS Code 1.144's copilot launcher is taken for the Copilot
  CLI"; "the CLI looked for is .../bin/copilot-shim/copilot, the
  launcher"), green now.
- The name guard alone is the mutation: commitHashName made to take
  every name turns the same test's last case red ("a folder beside bin
  that is no build's hash counts as an editor's install").
- TestCopilotLauncherFromAnEditorIsNotTheCLI: green (1.143's layout, a
  Mac's app, bin itself, the CLI where a user's installs put it, npm's
  global under a far product.json, a link on PATH).
- go test -tags nogui ./internal/agent: green but TestMothX, which fails
  the same on the untouched tree (this Mac's PATH has a real mothx).
- gofmt -l internal/agent clean; go vet darwin, GOOS=linux -tags nogui,
  GOOS=windows; go build darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: a real Windows 1.144.0 install — this was written on a Mac;
the layout is read from microsoft/vscode#343045 and from Tony-ooo's
paths on disk.

Reviewed and landed as one batch of 12 commits (gua's #4593, #3269,
#3881, #2887, #3289, #2718, #2855, Edward4226's #2718 key-path
sibling, and four review follow-ups). Run for the batch, whose last
commit's tree is 5d58a75f3:
- Full suite before the rebase (base d307aa648, wsl-run magpie-desktop,
  go test -tags nogui -count=1 -timeout 45m ./...): 81 packages ok. Reds,
  all with issues and none in code this batch touches: internal/agent
  TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir
  (#4033, #3548, #3141); gateway TestUnroutedHeldReportSaved (#4300);
  gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510); provider
  TestClaudeAccountServesModelsListedSinceItsFetch (#3174). Run alone at
  origin/main 573b21f4b, TestGrokInstalled, TestOmpDetectedWithPiDir
  and TestSettingsSaveKeepsWhatItDoesNotSend are red there too. The
  other four pass there alone.
- After the rebase onto origin/main 573b21f4b, at this tree:
  internal/usage, update, gateway and provider ok. In internal/agent,
  the #4033/#3141 install-detection reds plus TestCopilotFolderFrom-
  AnIDEPluginIsNotTheCLI and TestZedAppPath. Those two are flaky the
  same way at origin/main (-count=10 alone: 4 and 5 of 10 red) and are
  already listed in #4033. The #3269 tests (TestCopilotLauncher*) pass
  5 of 5.
- Rebased onto origin/main ef63ef4a2. The #2855 commit met 0b9727ec9
  (#2974) in responses.go: the streamed item's done now takes both, the
  upstream's own id (thinkUp) and the made-over item; and in
  gateway-routing.md main's paragraph is kept with #2855's clause. That
  matches gua's latest head (range-diff: context only). At tree d7c76c6fa:
  internal/gateway, provider, usage, redact and update ok; vet
  GOOS=linux -tags nogui ./internal/..., darwin and GOOS=windows for
  gateway and provider.
- Rebased last onto origin/main d8f7d089f (5 commits: internal/agent
  and GUI files only). At tree 0d4bfd8c8, the pushed one: internal/agent's
  TestCopilotLauncher*, TestClaude*, TestOwn* and TestVSCode* ok, -count=3;
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI red once there, as it is at
  main (#4033). Vet of internal/agent: darwin, linux and windows.
- gofmt -l clean. On mote: go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- Broken by hand, each turning its guard red: the lift gate
  (TestReadingKeepsARefusalsRest, TestAutoVisionKeepsOffARefusedAccount);
  the named-time condition (TestNamedQuotaTimeReplacesAGuess); the
  filter-chain hop (WholeReply/glm-5.3-flash); Edward's aAt
  (TestKeyAllowanceElapsedResetStartsAgain); and the old
  magpieMadeReasoning, which panics in TestMadeReasoningSaysItsTextOnce/
  no_summary. Every new test of gua's is red at base d307aa648.
Not tried: real OpenAI, DeepSeek, GLM or ChatGPT accounts; a real VS Code
1.144 install on Windows; a GUI run (no GUI files are touched).

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 07:06:19 +08:00
yetone d8f7d089f1 agent: Claude Code's model field appends the kept list without a copy first
The model field (and a WSL Claude Code's, asleep) appended
claudeViaMagpie's list to Claude Code's own models, which copies it,
after claudeViaMagpie had copied it once already: 6.3 MB of forty polls
with real accounts. claudeViaShared gives the list kept, read only, to
such a caller; the append makes the field's list one of its own.
claudeViaMagpie still gives every other caller a copy.

TestClaudeViaMagpieKept now also writes into the model field's options
and checks that neither kept list (folded or not) changes.

Run on mote at 68ebd1ec4 plus this change:
- gofmt; go vet darwin, windows, linux: ok
- go test ./internal/agent -timeout 45m: ok (317.0s), with the test's
  first version, which read only the unfolded list
- that version broken by hand (the field returns the kept list itself)
  went red on the folded-list check, not its own; the check now reads
  both lists. Alone 3/3 ok, and broken by hand red with "reached the
  options kept (folded true)"; the whole package not run again after
- real accounts, sandbox HOME, network blocked, 40 polls, against
  v0.1.2494's change set: claudeIn.func57 23.4 -> 19.1 MB,
  claudeViaMagpie's 6.3 MB copy gone; state and drift answers byte for
  byte the same; footprint peak 141 MB, RSS at end 181 MB (noise between
  runs is about this size)

Not run: the GUI suite (no GUI file changed), Windows and Linux test runs.

Rebased onto 9f75279e9 (two GUI commits, nothing in internal/agent); not run again there.
2026-11-01 07:05:05 +08:00
yetone 68ebd1ec4a agent: a provider's options an agent reaches on its own are kept
Goose's model field asked ownOptions each poll, for the picker and again
for Drift, and each provider's models were made into options anew
(catalog.Provider, options, group, its icon): ownOptionsFrom was 21.2 MB
of forty polls with real accounts. For agents without a registry of
their own (native == nil), each provider's options are now kept in
ownBuilt per provider.StampNow (a minute at most) and copied into the
caller's list; Pi's and omp's, which read their own registries, are
built as before (ownProvider is the old loop body).

TestOwnOptionsKept: a catalog of 200 OpenAI models; asking again takes a
fifth or less of the allocations building does, a caller's write doesn't
reach what is kept, and a model the catalog lists since is offered.

Run on mote at c1457f2ee plus this commit and the next one (Goose's own
options kept), together:
- gofmt; go vet darwin, windows, linux: ok
- TestClaudeViaMagpieKept and TestOwnOptionsKept alone 3/3 ok
- go test ./internal/agent -timeout 45m: ok (267.7s)
- real accounts, sandbox HOME, network blocked, 40 polls, both commits
  against c1457f2ee: state and drift answers byte for byte the same;
  footprint peak 134 MB, RSS at end 177 MB
- broken by hand (ownOptionsFrom builds each time): red, "took 211
  allocations, building them 202"
- ownOptionsFrom 21.2 -> 7.0 MB, gooseIn.func10 28.9 -> 16.0 MB; Picks
  134 -> 118 MB with the commit before

Not run: the GUI suite (no GUI file changed), Windows and Linux test runs.

Picked onto ef63ef4a2 (with ef63ef4a2, Codex's subagent models kept, and gateway, redact and GUI commits; none in internal/agent); not run again there.
2026-11-01 06:53:25 +08:00
yetone 5e0d4e1282 agent: Claude Code's magpie list is kept as viaMagpie is
Claude Code's model and tier fields asked claudeViaMagpie each poll, for
the picker and again for Drift, and it built the list anew each time:
19.1 MB of forty polls of the Agents, Providers and Drift answers with
real accounts. It is now kept in builtOptions per provider.StampNow (a
minute at most), folded and not apart, and each caller has a copy of
its own (buildClaudeVia is the old body).

TestClaudeViaMagpieKept: a provider of 102 models; asking again takes a
fifth or less of the allocations building does, a caller's write doesn't
reach the kept list, the folded list is kept apart, and a provider saved
since is offered.

Run on mote at c1457f2ee plus this commit and the next one (Goose's own
options kept), together:
- gofmt; go vet darwin, windows, linux: ok
- TestClaudeViaMagpieKept and TestOwnOptionsKept alone 3/3 ok
- go test ./internal/agent -timeout 45m: ok (267.7s)
- real accounts, sandbox HOME, network blocked, 40 polls, both commits
  against c1457f2ee: state and drift answers byte for byte the same;
  footprint peak 134 MB, RSS at end 177 MB
- broken by hand (claudeViaMagpie builds each time): red, "took 345
  allocations, building them 345"
- claudeViaMagpie 19.1 MB -> 6.3 MB, claudeIn.func57 33.8 -> 23.4 MB

Not run: the GUI suite (no GUI file changed), Windows and Linux test runs.

Picked onto ef63ef4a2 (with ef63ef4a2, Codex's subagent models kept, and gateway, redact and GUI commits; none in internal/agent); not run again there.
2026-11-01 06:53:24 +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
ggbdpq 1cf66e4b17 agent: a tool asked on Responses says strict: false, its optional parameters stay optional (#3055)
What changed: OpenAI's Responses API takes a function tool whose strict
is left out as a strict-mode one and normalizes its schema, where every
property is required, so a tool's optional parameters came back filled
(#3055, ArakawaHenri). pi-ai (dsh's llm-pi-ai, Pi and its kin) says
strict: false on an ordinary tool only when the model's compat says
supportsStrictMode, which it takes as false where the compat is left
out. magpie now says it: every model of a dsh route whose api stands as
openai-responses carries compat.supportsStrictMode, by the api the route
has now (the one the user picked in dsh's Models page kept), not by its
name, beside the keys they set there (dshKeepCompat); and piModelJSON
says it for a model best served on Responses, which Pi's and StepCode's
models.json carry (Pencil's entries stay on Chat throughout). omp's
models.yml is left alone: omp turns a models.yml away over a field its
schema doesn't name (16.3.5 over a max), so the compat needs an omp
version of its own pinned first. docs/subsystems/agent-wiring.md says
so.

Run: new TestDshTellsAResponsesToolsStrictIsOff and
TestPiTellsAResponsesToolsStrictIsOff fail without the change (the
first with "a model asked on Responses isn't told strict is off:
Compat:<nil>", the second with "resp/gpt-5.5 is asked on Responses and
isn't told strict is off") and pass with it; removing only the dsh case
turns the first red and only it, removing only the piModelJSON compat
line turns the second red and only it. go test ./internal/agent/
(TestMothX fails the same with both files back at the baseline here, so
not from this change), gofmt -l on the changed files (nothing), go vet
./..., GOOS=linux GOARCH=amd64 go vet -tags nogui ./...,
GOOS=windows GOARCH=amd64 go vet ./..., go build . (darwin arm64),
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -tags nogui .,
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags nogui .,
GOOS=windows GOARCH=amd64 go build -o /dev/null .

Landed (yetone). Broken by hand on mote: with the dsh case and
piModelJSON's compat line taken out, both new tests are red ("a model
asked on Responses isn't told strict is off: … Compat:<nil>",
"resp/gpt-5.5 is asked on Responses and isn't told strict is off").
Run at the pushed head: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:21:39 +08:00
yetone bb478f0e50 agent: a look that only ranges over magpie's models reads the list kept
magpieModels gives each caller its own copy of the list it keeps per
agent. Most callers only range over it, or count it, and a range copies
each model anyway, so the copy guarded nothing for them (the models'
own lists were shared before too: the copy was shallow). sharedModels
is the list kept, read only; every `range magpieModels(` and
`len(magpieModels(` in internal/agent (39 files) takes it. Callers that
keep the list, append to it or hand it on still get their copy.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls of /api/state, /api/providers and drift, pprof alloc_space
between two heap snapshots, 616405061 (mrows) vs this (mshare):
  stampedLists.get's slices.Clone 36.7 MB -> gone (under pprof's cut);
  most of it was piOffered (22.5 MB) and claudeViaMagpie (13.7 MB)
  total 637 MB -> 584 MB (runs vary +-25 MB)
  /api/state and drift bodies byte-identical, /api/providers equal but
  for `fetched` and `lapsed` (a refused refresh in the blocked sandbox)

TestModelReadersShareTheList: sharedModels gives the kept array, not a
copy, and no non-test file in internal/agent ranges over or counts
magpieModels(. Broken by hand on mote: sharedModels through get fails
"a shared look copies the kept list"; one `range magpieModels("kimi")`
put back fails naming kimi.go.

Run on mote at this tree (before rebase): gofmt; go vet for darwin,
windows and linux; the new test with TestMagpieModelsKeptWhileCatalogStays,
TestKeptListSharedWithoutACopy and TestViaMagpieKept 3/3 ok;
go test ./internal/agent ok (201s); go test ./internal/gui: only the
known reds TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949).
Not run: the full ./... suite.
2026-11-01 06:09:56 +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 93879515a0 agent: QwenPaw, each of its agents' active_model one of magpie's (pkh1585 on Discord)
pkh1585 asked for QwenPaw (AgentScope, github.com/agentscope-ai/QwenPaw)
on Discord. Read in its source, 2.2.2.post1, as data:

- Its folder is QWENPAW_WORKING_DIR, else ~/.copaw when that exists (the
  old name), else ~/.qwenpaw; WORKING_DIR/.env is loaded without
  overriding the environment. config.json's agents.profiles lists the
  agents, each with a workspace_dir whose agent.json holds active_model
  {provider_id, model}, read again on each message.
- Providers are no plain config: SECRET_DIR (QWENPAW_SECRET_DIR, else
  "<WORKING_DIR>.secret") holds providers/{builtin,custom}/<id>.json,
  read once at start. A plain api_key there is encrypted to "ENC:" at
  start, so that is the place QwenPaw itself keeps keys.

What magpie does now:

- `magpie qwenpaw <model>` and the GUI: a row per QwenPaw agent
  (qwenpaw#<id>, the default one as plain qwenpaw), skipping agents whose
  backend is ACP (another CLI runs those) and agents turned off.
- Connecting writes providers/custom/magpie.json (mode 600, the gateway's
  /v1 and the magpie-qwenpaw key, magpie's models as extra_models with
  their window, output and tool use) and sets that agent's active_model
  to {magpie, <provider>/<model>}. The old active_model is stashed as it
  was and put back verbatim on disconnect, absent and null included.
  The provider file is removed only when no QwenPaw agent still uses it.
- A sync after QwenPaw re-saved the provider (encrypted key, discovered
  models, its own defaults) keeps what QwenPaw wrote and changes only
  what magpie owns, so a second connect leaves the file as it is.
- The notice says QwenPaw reads providers at start-up: restart it once
  after connecting and after magpie's models change. New text in every
  locale.
- appdir: QWENPAW_WORKING_DIR and QWENPAW_SECRET_DIR take ~/ as QwenPaw's
  expanduser does; agentenv clears them in tests.
- README (en, zh), docs/reference.md, agent-wiring.md, the site's agent
  list and start pages (en, zh, ja), icon.

Run:
- internal/agent's QwenPaw tests (Connect, AgentsAreRows, SyncKeeps-
  WhatQwenPawChanged, Check, NotStartedYet, Folders, OwnModelAfter-
  Magpies, SyncAfterQwenPawSaved, NullModelRestored) on mote, and the
  all-agent tests (applied, rewire, lan_kept, proxy_kept, spelled) with
  a QwenPaw fixture.
- Broken by hand, each red: always rewriting the key
  (SyncKeepsWhatQwenPawChanged), removing the provider while another
  agent uses it (AgentsAreRows), no backend filter (AgentsAreRows lists
  qwenpaw#coder), dropping the keep of QwenPaw's own fields
  (SyncAfterQwenPawSaved), IsObject for Exists (NullModelRestored).
- Real QwenPaw 2.2.2.post1 (Python 3.12 via uv) in a sandbox HOME on
  the Linux box (WSL magpie-desktop), magpie on 3741, a fake OpenAI
  upstream on 3742: first start wrote config.json and agent.json;
  `magpie provider add fake …`, `magpie serve`, `magpie qwenpaw
  magpie/fake/echo-1`; after a restart QwenPaw encrypted the key (ENC:)
  and `qwenpaw agents chat` answered "PAWPAW-OK from the fake upstream",
  its log "built agent … model=magpie/fake/echo-1"; the upstream saw
  /v1/chat/completions model echo-1 streamed, magpie's usage.jsonl
  agent qwenpaw status 200. A second connect and `magpie models` left
  the provider file unchanged. `magpie qwenpaw default` took
  active_model back out (the only diff in agent.json) and removed the
  provider; QwenPaw started clean after.
- gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows -tags nogui.
- Full suite on mote (go test -tags nogui -count=1 -timeout 45m ./...)
  at 9554883db on d714c4216: 84 packages ok, internal/gui red on
  TestSettingsSaveKeepsWhatItDoesNotSend only (SearchAll from
  b09349d17, red on main, #4514). Rebased onto 15066f84f (an appdir
  change among the four new commits): appdir, agentenv, agent,
  filememo, gateway ok again, gui the same #4514 red; vet darwin,
  linux and windows of agent, appdir, agentenv ok. Rebased again onto
  dd7442f28 (edit, provider and agent changes): edit, provider, agent,
  appdir, agentenv ok, vet linux and windows of agent ok. Rebased onto
  6a23d9d75 (606743831's registry-following agent variables, which
  QWENPAW_WORKING_DIR and QWENPAW_SECRET_DIR now follow as agentenv
  vars): appdir, edit, agentenv, agent ok, vet linux and windows ok.
  Rebased onto 61b536d78 (provider's model lists): agent, appdir ok.
- GUI on mote, the files this reaches (i18n-keys, gui-de, gui-ja,
  gui-zh-tw, agent-connect, agent-layout, agent-notice-lang, brand,
  builtins, desktop-lang, header-relang, icon-tile, icon-url):
  Chromium 103/104, WebKit 59/60, the one red each gui-ja's ja for
  removing an agent's only account (a7b47d57e, #4580). The whole GUI
  suite wasn't run: mote had three other sessions' whole GUI suites
  running (load ~130) and WSL one more.

Not tried: Windows, the macOS desktop app, QwenPaw in WSL wired from
Windows magpie, the ACP backend, QwenPaw's web console after connecting,
a real legacy ~/.copaw.
2026-11-01 05:00:36 +08:00
yetone 606743831e appdir: on Windows an agent's folder variable follows the registry, and a gone folder it names isn't made again (bm_rabbit on Discord)
bm_rabbit (0.1.2405, Windows x64, Pi 1.4.0) moved Pi's AgentDir from
F:\piData\.pi\agent to F:\HarnessData\Pi\.pi\agent, deleted the old one and
set the User variable PI_CODING_AGENT_DIR to the new path. Changing Pi's
model in magpie then made the deleted folder again with only models.json
and settings.json in it.

Cause: Windows gives a process its variables once, from the registry, and
never passes a changed User variable to one already running. magpie runs
for days in the tray, so appdir.Getenv("PI_CODING_AGENT_DIR") (piDir) kept
the old path, and edit's write did MkdirAll on it. Every agent folder
variable (CODEX_HOME, CLAUDE_CONFIG_DIR, ...) had the same problem.

Fix, where every agent folder is read (appdir.LookupEnv, follow.go): on
Windows a variable in agentenv.Vars that came from the registry (its value
in magpie's environment at start matched the registry's, unset in both
counts too) is read from HKCU\Environment, else HKLM's Session Manager
Environment, with %...% expanded, at most once a second, and set in
magpie's environment so the programs magpie starts get it too. A value
the launcher set itself, or one set inside magpie since (a test sandbox),
stands. The direct os.Getenv reads of agent variables go through appdir
now: claudetui's CLAUDE_CONFIG_DIR, sessions' CODEX_SQLITE_HOME and
PI_DESKTOP_DATA_DIR, cliupdate's GROK_HOME, omp's OMP_PROFILE/PI_PROFILE.

And edit's writeFile no longer makes a missing tree of folders that an
agent's variable names: when the folder the variable names is missing
and so is the folder above it (bm_rabbit's whole F:\piData was gone),
appdir.Gone returns a GoneError naming the variable and the folder. The
named folder itself is still made when its parent is there, as mkdir
would (a CODEX_HOME or ANTE_HOME set before the agent first ran; 12
internal/agent tests rely on it), and an agent's default folder is made
as before. TestAnteHome's ANTE_HOME was <tmp>/elsewhere/ante with
elsewhere missing; it now makes elsewhere first. Writes that call
os.MkdirAll themselves don't ask yet: #4634.

Pi's install-layout.json isn't Pi's: Pi 1.4.0's getAgentDir
(@earendil-works/pi-coding-agent dist/config.js) reads PI_CODING_AGENT_DIR,
else ~/.pi/agent, and no file in the package names install-layout.
magpie doesn't read it.

Tests: TestAgentVarFollowsTheRegistry, TestAgentVarAddedLaterFollows,
TestAgentVarSetByHandStands, TestRegistryReadAtMostEachFollowFor,
TestGoneNamedFolderIsNotMade (internal/appdir, a fake registry), and
TestWriteNeverMakesANamedFolderAgain (internal/edit).

Broken by hand: LookupEnv back on os.LookupEnv, TestAgentVarFollowsTheRegistry
and TestAgentVarAddedLaterFollows FAIL ("after the user moved it,
PI_CODING_AGENT_DIR = .../old, want .../new"); Gone's refusal turned off,
TestGoneNamedFolderIsNotMade and TestWriteNeverMakesANamedFolderAgain FAIL
("= <nil>, want a GoneError", "the folder was made again"); Gone refusing
whenever the named folder is missing, TestGoneNamedFolderIsNotMade FAILs
("a named folder whose parent exists: ..."). All put back, green.

Real Windows run on xiaomi-gpu, sandbox USERPROFILE/APPDATA/LOCALAPPDATA,
at this head: a probe built from this tree started with
PI_CODING_AGENT_DIR=<sb>\piData\.pi\agent in its environment and the User
registry; then the User variable was set to <sb>\HarnessData\Pi\.pi\agent
and <sb>\piData deleted, and agent.Find("pi").Apply("model", ...) ran in
the same process. Pi's dir and os.Getenv are the new folder,
settings.json written there, piData not made. With HarnessData deleted
too: "PI_CODING_AGENT_DIR names <sb>\HarnessData\Pi\.pi\agent, which
doesn't exist and neither does the folder above it: ...", not made. An
earlier run of the old code (LookupEnv on os.LookupEnv, no Gone) wrote
into the old folder and made it again: bm_rabbit's case. The User
variable was removed after; the box had none.

Full run at this change on d714c4216: on mote,
gofmt -l (nothing), go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., and go test -tags nogui -timeout 45m ./...:
83 ok, 2 red, each open and not this change's: internal/gui
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red alone on origin/main)
and TestColdTurnsTaken (#4510, warm-up ordering race, 0.00s), and
internal/cli TestLibraryMCPHub (#4140, TempDir cleanup; passes alone).
internal/appdir, internal/edit and internal/agent again alone: ok.
Rebased onto 76c130b29 (eight commits, edit's and appdir's among them;
file.go's imports merged by hand): gofmt -l (nothing), the three go vets,
and internal/appdir, internal/edit, internal/agent, internal/claudetui,
internal/sessions on mote: all ok. Not the whole suite again there.
Rebased again onto 88372a39d at push (six commits, none in appdir or
edit; dd7442f28 in internal/agent): go vet ./internal/..., internal/appdir
and internal/edit ok; internal/agent not run again at this head.
Windows (xiaomi-gpu, at d714c4216): internal/appdir, internal/edit, internal/claudetui
ok; internal/agent's 12 tests that make a named folder, TestGrok* and
TestPi* ok; internal/sessions red only in TestAgySessions and
TestAgyRowOnly, the same alone on origin/main (#4115).

Not tried: magpie's own GUI on Windows (the probe calls the same
agent.Apply the GUI's /api/set reaches); a REG_EXPAND_SZ value and a
Machine-only value on the real box (code path read, not run); bm_rabbit's
junction at C:\Users\Administrator\.pi.
2026-11-01 04:40:44 +08:00
yetone dd7442f283 agent: a look at the via-magpie options shares the kept list
viaMagpie handed every caller its own copy of the options list it keeps
per stamp, and a window poll asks for it from most agents' fields and
pickers. In a real-account sandbox (abr.sh, 20 polls of drift, state and
providers on v0.1.2463) those copies were 33.7 MB of slices.Clone, plus
~8 MB more on the way, of the 713 MB the polls allocated.

viaMagpieShared returns the kept list itself, clipped, so an append
makes the caller's own array. The 58 callers that only read it, or
append onto it, now take it; viaMagpie (a copy) stays for the ones that
change it.

TestKeptListSharedWithoutACopy checks that 20 shared looks return the
kept array, and that an append onto a shared look and a write into
get's copy leave the kept list as it was.

Run on mote at this tree:
- gofmt, go vet (darwin, GOOS=windows, GOOS=linux with gateway),
  go build ./...: ok.
- Broken by hand (shared returns slices.Clone): the test is red, "a
  shared look copies the kept list".
- go test -count=1 ./internal/agent: ok (480s).

Not run: internal/gateway and internal/gui packages on this tree.
2026-11-01 04:25:59 +08:00
yetone 544b91ca87 dsh: magpie's routes wait for a slow reply as long as the gateway does (tim on Discord)
tim's first "who are you" to gemini-3.8 through the third-party plugin
magpie-gemini-web 0.8.0 took minutes in dsh and ended in 499 ("the agent
canceled the request"). dsh hung up: llm-pi-ai gives a turn up after 5
minutes with no pi-ai event (DEFAULT_STREAM_IDLE_TIMEOUT_MS, every
dsh-llm-pi-ai from 0.1.5 to 0.2.2), and the gateway's ": keepalive"
comments (keepQueued, keepQuiet) are not events. The plugin serves one
request at a time (maxConcurrency 1), dsh's own session title goes to the
same route model in parallel, and the plugin's backend sends no byte
before its first token, so the turn's 5 minutes ran out in magpie's queue
and the backend while the gateway (10 minutes for headers) and the plugin
(240s per wait, then its own 504) were still waiting.

Every one of magpie's dsh routes (patch lists and deepseek-acp's
settings.yaml, all through dshPutProviders) now has streamIdleTimeoutMs:
600000 (dshIdleWait), the gateway's upstreamHeaderWait. A value already on
the route, set in dsh's Models page or by hand, stays. Codex's
comment-blind limit is still met in the gateway (agentQuietMost); dsh's is
a route setting. The plugin's own slowness is its maintainer's and is not
changed here.

Verified:
- New tests TestDshRoutesWaitAsLongAsTheGateway and
  TestDshRouteKeepsTheUsersIdleWait (internal/agent/dsh_idle_test.go),
  green on mote. Broken by hand: without the field the first fails
  ("route magpie waits 0ms for the next event, want 600000"); without the
  keep the second fails ("sync 1: the user's 120000 became 600000").
- Real dsh 0.2.1-rc.2 (headless, sandbox HOME/DSH_HOME, the route as
  magpie writes it, a fake Chat server on 127.0.0.1:3561 that answers
  after 8s): streamIdleTimeoutMs 3000 -> "TIMEOUT: pi-ai stream idle
  timeout after 3000ms"; 600000 -> "hello there", exit 0. With headers
  sent at once and ": keepalive" every second it still timed out at 3000,
  so comments don't feed the watchdog. dsh-llm-pi-ai 0.1.5-rc.3,
  0.1.7-rc.2, 0.2.0-rc.2 and 0.2.1-rc.5 (npm pack, read) all take the
  field per provider, max MAX_TIMER_DELAY_MS.
- gofmt -l clean. On mote: go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build -tags
  nogui, GOOS=windows go build: all ok.
- Full suite, go test -tags nogui -count=1 -timeout 45m ./..., on the
  Linux box (wsl-run, magpie-desktop; mote had two full suites running)
  at d714c4216 + this change: 83 packages ok; internal/agent red on
  TestInstalledVersion, TestGrokInstalled,
  TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir
  (#4033, #3548) and internal/gui on TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and TestColdTurnsTaken (#4510). The first five fail the same
  on origin/main 15066f84f run alone there; TestColdTurnsTaken passed
  alone on main and failed alone with this change (5 counts, gui only,
  which this change doesn't touch), as #4510 describes.
- After rebasing on 2597c9636, internal/agent again on the Linux box: the
  new tests pass; reds TestInstalledVersion, TestGrokInstalled,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI/qoder-cn,
  TestOmpDetectedWithPiDir, all the #4033 class (Qoder noted there).

Not tried: tim's own setup (the plugin is not run against a Google
account); a real 5-to-10-minute wait in dsh; Windows.
2026-11-01 04:23:05 +08:00
yetone 2597c96365 agent: Codex's config.toml is decoded once a read for a sync's own looks
A sync to Codex decoded the whole config.toml again for each thing it
checked: codexMultiAgentV2On, putThreadTables, codexEnableEfforts and
codexAsyncNow each ran toml.Unmarshal over the file. Codex writes a
[projects."…"] table for every folder it was opened in; the owner's
config is 1.5 MB with 10,932 tables, and with 10,000 such tables one
sync allocated 21 MB.

codexTopOf decodes only the top tables these look at (features,
model_providers, desktop, profile, profiles) and keeps the result in
filememo by the file's mod time and size, so a sync and the polls
after it share one decode until the file changes. A missing file is
an empty config, as before.

TestCodexSyncDecodesTheConfigOnce: 10,000 project tables, one sync
to settle, then five more; each must allocate under 12x the file and
leave config.toml unwritten. Now ~5 MB a sync. Red on the old code:
51,257 KB a sync over an 868 KB file, past the 10,421 KB bound.

Run at this head on mote: gofmt clean; go vet (darwin, GOOS=windows,
GOOS=linux) ok; go test -timeout 45m ./internal/agent
./internal/gateway ok.
2026-11-01 04:06:09 +08:00
yetone 019bfc951b gui: a page of accounts builds the agent list once, not once a row
accountLabel and the excluded-agents loop called agent.Find for each row,
and Find builds All() again each time: about 3,300 allocations a call.
Over 20 window polls that was 58 MB of the 1.4 GB a magpie allocated.
provider.Held keeps All() for the request that holds it (the gui's held
middleware holds every /api/ request), and agent.FindIn looks the name up
in that list. Outside a hold Held builds it as before, so a caller with
no request in hand gets the same answer.

TestAccountLabelsBuildTheAgentsOnce (sandbox HOME): outside a hold the
label's name and icon are the same; under Hold a row allocates 3 times
against 3302 to build every agent. Broken by hand on mote (agentNamed
back to agent.Find) it is red at 3305 a row.

Run on mote at this tree (on d714c4216): agent (846s) and provider
(459s) ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend
(#4514, red on main) and TestMainWindowCorners (#3949, macOS 27). vet ok
on darwin and windows (agent, provider, gui) and linux (agent, provider;
gui needs cgo there).
2026-11-01 03:49:03 +08:00
ggbdpq cdd470ce9f agent: opencode.json lists magpie's models in the order the user set
The models of magpie's provider in opencode.json were a
map[string]any, whose keys encoding/json marshals sorted: the order the
user dragged to on the Agents page reached magpieModels and died at the
last step, the file listing the models A to Z (#4575). A pure
re-ordering wasn't even written — syncJSONInOrder's sameOrder compared
two alphabetical lists and found them alike. The variants under each
model kept their order since #713 (orderedJSON); the models keep theirs
the same way now, and openCodeKept looks a model up in the ordered
block to put a variant of the user's on it.

Every config in OpenCode's shape moves with the one fix: OpenCode,
OpenChamber, Air, MiMo Code and DevEco Code (openCodeLike and the
openCodeKept calls in air.go and openchamber.go). Pi, Crush and Codex
list models in arrays and were never touched.

Run: TestOpenCodeModelsInOrder in internal/agent (written first) fails
on the unmodified code — the fresh block lands alphabetical and a
dragged order is never written — and passes with the fix. The
models-as-map assertions in TestInferredGroupImagesReachAgentCatalogs,
TestMiMoCodeCatalogNarrowedSeparately and
TestGroupModelsCarryTheirFirstMembersPrice read the ordered block now.
go test -tags nogui -count=1 ./internal/agent ok (150s) but for
TestMothX, which fails the same on unmodified main cac655c14 on this
machine (mothx_test.go:154) — pre-existing, not this fix's. gofmt
clean; go vet -tags nogui clean on darwin, linux and windows; go build
-tags nogui ./... ok on the three.

Generated-by: GLM-5.3-Flash (ZCode)

Broken by hand: with the agents.go hunks reverted,
TestOpenCodeModelsInOrder is red (written: [aaa/m1 relay/glm-4.6]).
Not changed: Cline's models.json is built from a map too (cline.go
clineModelsAt and clineKept). Filed as #4594.
2026-11-01 02:45:01 +08:00
yetone 2e9df9b1be agent: which of Codex's models magpie serves is kept while the catalog stays
codexInMagpie marks Codex's own models that magpie serves on the
user's ChatGPT account. Codex's options are asked per field of its
Drift on every drift poll, and each time it built Codex's whole
catalog (provider.CatalogFor) for these few names: 0.2 GB of the
2.6 GB a real config allocated over 20 polls.

The names are now kept in a stampedLists, as magpieModels and
viaMagpie are: built again when provider.StampNow moves, or a minute
after they were.

TestCodexServedKeptWhileCatalogStays: a signed-in account beside a
300-model relay; gpt-5.5 is marked served and the relay's model is
not, a kept answer takes under a twentieth of a build's bytes, and
the account's models picked since are followed at once. Red with the
set found each time ("a set already found took 9948425 bytes, finding
it 9954954").

Run on mote at this tree (0fe9f97c1 + this commit): go vet ./... for
darwin, windows and linux (internal/gui skipped on linux, wails cgo),
gofmt -l clean, go test -timeout 45m ./internal/agent (ok 402s) and
./internal/gateway (ok 963s).
2026-11-01 02:22:17 +08:00
yetone 6a900e0d04 gui: a poll of the Agents page no longer drops every cached model list
/api/state keeps the state it built in agents-state.json, written only
when the bytes change. They changed on every poll: a stale copy's start
is now less how long it has run, two clock reads apart, so it moved by
microseconds each time (on a real config, only
/agents[1]/staleCopies[i]/since differed between two polls). The file
was written through edit.WriteAtomic, whose write calls
filememo.Forget(). That bumps provider.StampNow, so every 15s poll threw
away each agent's model list and picker (magpieModels, viaMagpie) and
every provider's kept catalog, and the next look built them anew.

- StaleCopies' since is truncated to the second (the check against
  magpie's change still uses the exact time).
- keepState writes through steady.WriteFile (temp, flush, rename), which
  leaves filememo alone: nothing a request reads is built from this file.

Not changed: on Linux and WSL the process list gives a run time in whole
seconds (ps etime), so a copy's since can still move by a second between
polls there; macOS reads the exact start from sysctl.

Run on mote at 7428f3229 + this change:
- go test ./internal/agent ./internal/gui (-count=1 -timeout 45m):
  agent ok (280.8s). gui FAIL in two tests already red on main and
  filed: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK on macOS 27 (#3949).
- node --test agent-stale-copies.test.cjs: 0 failed.
- go vet (darwin), GOOS=windows go vet of both packages, GOOS=linux go
  vet ./internal/agent, gofmt -l: clean. A Linux vet of internal/gui
  needs gtk4 and webkitgtk-6.0, which neither mote's cross build nor the
  WSL box has.

Broken by hand: without the truncation TestStaleCopySinceSameEachLook
is red (since 08:20:11.5 then 08:20:11.500001); with filememo.Forget()
after the write TestKeptStateLeavesFilememo is red.
2026-11-01 01:28:58 +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
yetone 02ff0e908f agent: the Codex app's route opens config.toml to see it can be read, not reads it whole
codexAppRoute runs every 3s for as long as magpie does (the Codex app's
app-server watcher). It read the whole of Codex's config.toml with
os.ReadFile only to learn the file could be read; the keys it uses come
from filememo, which parses the file once per change. Codex keeps every
project's trust level in that file, and the owner's is 1.5 MB, so this
was 1.55 GB of the 33 GB a live magpie allocated in 53 minutes (heap
profile: KeepCodexAppOnItsProvider → codexAppStep → os.ReadFile). It is
now opened and closed: a file that can't be opened is still an unknown
route, a missing one still a known one.

Run on mote:
- TestCodexAppRouteReadsNoWholeConfig (new): a 1.6 MB config, 10 looks
  allocate under 1 MB; a config with mode 0 gives no route.
- Broken by hand: ReadFile put back, red (14.4 MB for 10 looks); the
  unreadable check dropped, red.
- go test -run CodexAppRoute ./internal/agent: ok.
- go test -count=1 -timeout 45m ./internal/agent ok (185.3s), at this tree rebased on 4a7d1c63a; gofmt -l clean; go vet ./internal/agent for darwin, linux and windows ok
2026-11-01 00:32:35 +08:00
yetone 3baf3b6dfd agent: every agent's magpie options are built once per change, not per Drift poll
viaMagpie is the half of every agent's model picker that magpie serves.
It built CatalogFor, the own and first accounts, and the fast and ultra
picks on every call. The window's /api/drift poll asks each agent's
fields for their options every 15s. In a live magpie's 53-minute heap
profile (v0.1.2404), Claude Code's options alone (claudeViaMagpie)
allocated 4.7 GB of 32.8 GB.

viaMagpie now keeps its list per agent and prefix, the same way
magpieModels does since v0.1.2422. It builds the list again when
provider.StampNow moves, and after a minute for what the stamp can't
see (an account another app signed in to). Each caller gets its own
copy. The two now share stampedLists[T].

Run (mote, at this tree):
- go test ./internal/agent: ok, 191.501s.
- TestViaMagpieKeptWhileCatalogStays, TestMagpieModelsKept... and
  TestIsMagpieKept...: ok.
- go vet ./internal/agent: darwin, linux and windows ok.

Broken by hand, TestViaMagpieKeptWhileCatalogStays goes red each time:
- never kept: FAIL;
- the stamp not compared: FAIL;
- the kept list handed out unshared: FAIL.

Real A/B: magpie web --gateway under the same sandbox HOME as
v0.1.2422's record, 200 GET /api/drift each. Before = v0.1.2422's tree.
The drift JSON is byte-identical.
- allocated under Drift: 2065 MB before, 1717 MB after.
- under viaMagpie: 367 MB before, under pprof's cut after.
- under CatalogFor: 538 MB before, 229 MB after.
- CPU: 1.95s before, 1.80s after.
Most of what is left under Drift in this sandbox is theInstalled's read
of each agent's config. It runs only for a magpie beside the installed
one (this sandbox's gateway port), not for the installed app.
2026-11-01 00:07:57 +08:00
yetone 854fc81619 agent: magpie's model list is built once per change, not per field of every Drift poll
The window asks /api/drift every 15s. Each agent's Drift checks its
fields through magpieValue -> f.Options -> magpieModels, and
magpieModels built the whole catalog every time: CatalogFor, the
prices, Labels and Vision's ranking (provider.Described -> seersRanked).
A live magpie's heap profile (v0.1.2404, 53 minutes) allocated 32.8 GB.
Drift accounts for 14.5 GB of it, and magpieModels for 9.7 GB. The
footprint peak of 882 MB rides on that garbage.

magpieModels now keeps the list it built for each agent. It builds the
list again when provider.StampNow moves: a provider, account, plugin or
setting saved, catalog.Touched, or providers.json, settings.json or the
catalog cache rewritten by another process. It also builds it again
after a minute, for what the stamp can't see. Each caller gets its own
copy (slices.Clone). A model's own lists are clipped, so an append in a
caller's copy can't write into the kept list.

Run (mote, at this tree):
- go test ./internal/agent: ok, 188.985s.
- TestMagpieModelsKeptWhileCatalogStays: ok.
- go vet: darwin and windows ok, for internal/agent and internal/gui.
  Linux vet of internal/gui fails in wails' cgo menu_linux.go
  ("undefined: pointer"); that is the cross-compile from darwin and not
  this change.
- go test ./internal/gui: three reds, each filed already and none in
  code this touches: TestSettingsSaveKeepsWhatItDoesNotSend (#4514),
  TestMainWindowCorners/macOS_26_SDK (#3949), TestColdTurnsTaken
  (#4510).

Broken by hand, the new test goes red each time:
- never kept: 422 vs 407 allocations;
- the stamp not compared: "a provider saved since is not listed";
- the kept list handed out unshared: FAIL.
Removing the Clip lines leaves the test green: its catalog's lists have
no spare capacity. The clip is a guard that wasn't shown to matter.

Real A/B: magpie web --gateway under a sandbox HOME with the owner's
providers, 200 GET /api/drift each. "old" is this tree with
magpieModelsFor = 0. The drift JSON is byte-identical.
- CPU: old 3.45s, new 1.99s.
- allocated under Drift: old 3098 MB, new 2063 MB.
- allocated under magpieModels: old 1049 MB, new 20 MB.
Not tried: the sandbox has no OAuth sign-ins, so subscription models
weren't in its catalog; the live catalog is larger.
viaMagpie (claudeViaMagpie, 4.7 GB live) still builds per call; that is
the next change.
2026-11-01 00:02:15 +08:00
yetone 49b8c64559 dsh: deepseek-acp gets magpie's route in settings.yaml, and the key store is owner-only
liby233 on Discord: dsh in an editor over ACP (deepseek-acp, CodeG, the
desktop app) listed only DeepSeek's own models. Checked against the real
packages from npm (deepseek-acp 0.9.0, dsh 0.2.1-rc.5): deepseek-acp
mounts FileSettings on $DSH_HOME/settings.yaml alone, never profiles/,
and loads the pi-ai plugin only when that file mentions "llm-pi-ai". Its
credentials-local store throws when .credentials.yaml is readable beyond
its owner ("run chmod 600"), so a 0644 store stops it from starting.

- settings.yaml gets llm-pi-ai.providers.magpie, built by the same code
  as the profiles' route (dshPutProviders), at 0600 when magpie creates
  it. It gets no agent-default-model of magpie's. The user's routes,
  other sections, comments, mode and the api they chose for magpie's
  route are kept. Disconnect takes only magpie's route out, and the
  section too when nothing else is left in it.
- dsh 0.2 renames settings.yaml to settings.yaml.imported (over the one
  before) at each full start and imports it into the profile. The
  serving round, Sync, Set and Unwire write it again. The user's own
  import from before magpie's first write is copied once to
  settings.yaml.imported.kept, so magpie's import never overwrites it.
- .credentials.yaml is made owner-only (go-rwx) on every write and every
  Sync, whoever made it 0644. In a WSL distro, a file written through
  \\wsl.localhost comes out 0644, so the chmod runs inside the distro:
  wsl.exe -d <distro> -e chmod go-rwx <path>. A failure is logged and
  doesn't fail the write.

Run:
- internal/agent on mote (ok) and its Dsh/WSL tests on Windows
  (xiaomi-gpu, ok); gofmt; go vet on darwin, GOOS=linux -tags nogui
  and GOOS=windows.
- The new tests (dsh_acp_test.go) were broken by hand, each turning red:
  dshSettingsAgain disabled, ownerOnly disabled, dshKeepImported
  disabled, and the round's call removed.
- Real runs on mote in a sandbox HOME (~/runs/realdsh-home), never a
  live ~/.dsh. After magpie's Pick, real deepseek-acp's session/new
  listed magpie::deepseek/pro and magpie::deepseek/flash; without
  settings.yaml it listed only DeepSeek's. With a 0644 store its boot
  failed with the credentials-local error, and it started once magpie
  had made the store 0600. `dsh --profile web --dump-config` shows
  agent-default-model magpie and the route. `dsh headless` ate
  settings.yaml into the headless profile, and magpie's round
  (dshWiredOnce) wrote it again, after which ACP listed magpie's models
  again.
- On magpie-desktop: `wsl.exe -d magpie-desktop -e chmod go-rwx` takes
  a file written through UNC from 644 to 600.

Not tried:
- magpie's own write into a real WSL distro end to end; only the
  command form above, and fakeWSL in tests.
- A WSL distro has no serving round, so after dsh eats settings.yaml
  there, it comes back only on magpie's next Sync or model pick.
- A dsh from before profiles (config.yaml only) is left as before.

Also: fakeWSL answers the chmod without recording it, since it is neither
a start nor a probe (TestWSLMoreAgentsStopped counts starts).
2026-10-31 22:00:28 +08:00
yetone 73a12e8bf6 wsl: a distro's agent folder that is a link is opened where it leads (#4502)
On Windows, adding a skill or switching RTK on for an agent in WSL failed
with `mkdir \\wsl.localhost\<distro>\root\.codex: Cannot create a file
when that file already exists` (linusxiong). In the distro ~/.codex is a
link to /mnt/c/Users/<user>/.codex. Through \\wsl.localhost Windows can't
follow a link the distro has: a mkdir of it says it exists, and nothing
below it can be made, written, read or listed. ggbdpq found and explained
the link (thanks); their patch, which takes that EEXIST as "there", wasn't
used: the writes below the link fail next (its test passed because a
symlink here is followed).

The fix, for every agent folder and every writer through \\wsl.localhost:
- The WSL probe asks `readlink -f` in the distro where each agent folder,
  its skills folder and the folders beside them lead (wslLinkPaths ->
  distro.Links; a $HOME that is itself through a link is left alone), and
  which drive each Windows mount is (win:/mnt/c C: -> distro.Drives).
- distro.open opens a path at or below a link where it leads: on a Windows
  drive, the drive's own path (C:\Users\<user>\.codex); elsewhere in the
  distro, through \\wsl.localhost again. native spells it back through
  the link, so the agent is told its own path.
- A link readlink couldn't resolve is never guessed at: distro.open
  errors, and the agent is unreached (Agent.Unreached: its notice says
  why; every field Set and Sync returns it).
- Writers: the agents' own files (place.join/place.open, every
  filepath.Join(at.home, ...) in internal/agent), the library's WSL
  targets (wslOpen/wslOpened; one "wsl" problem per agent and nothing
  written), RTK (rtkAt, rtkInstall checks agent.WSLOpen before its mkdir),
  the Sessions page's WSL reads (sessions.WSLHome.Open) and the Copilot
  CLI sign-in read (provider.CopilotWSLHomes -> CopilotWSLDirs).
- Not changed: magpie's image MCP server opens arbitrary paths an agent
  in WSL gives it the same way; filed as #4578. Links deeper than the
  probed paths (other than <agent dir>/skills) aren't resolved. A distro
  probed by an older magpie has no Links until probed again (each run).

Run:
- Real Windows box (xiaomi-gpu, distro magpie-desktop, sandbox
  /tmp/x4502/home with .codex -> /mnt/c/Users/yeton/runs/x4502-target/.codex,
  .claude -> /tmp/x4502/data/claude, .pi -> a missing folder), a throwaway
  Windows test running the real probe with that HOME: probe said
  link:.codex /mnt/c/..., link:.claude /tmp/x4502/data/claude, link:.pi,
  win:/mnt/c C:, win:/mnt/d D:. The old way, MkdirAll(\\wsl.localhost\
  magpie-desktop\tmp\x4502\home\.codex\skills\pdf) = "Cannot create a file
  when that file already exists" (the report's error). distro.open wrote
  SKILL.md to C:\Users\yeton\runs\x4502-target\.codex\skills\pdf and to
  \\wsl.localhost\magpie-desktop\tmp\x4502\data\claude\skills\pdf, both
  read back with cat in the distro through the links; .pi said "~/.pi in
  WSL magpie-desktop is a link magpie couldn't follow". Sandbox and target
  removed after.
- New tests with a fake distro whose ~/.codex and ~/.claude are links to
  /mnt/c/... that don't exist here, so, as through \\wsl.localhost,
  nothing below them can be made: TestWSLFolderIsALinkToC,
  TestWSLFolderLinkUnresolved, TestRTKWSLFolderIsALink,
  TestRTKWSLFolderLinkUnresolved (library); TestWSLProbeLinks (runs the
  probe script), TestWSLOpenThroughLinks, TestWSLAgentFolderIsALink
  (config and a Claude session read on C:), TestWSLAgentFolderLinkUnresolved
  (agent).
- Broken by hand: the library tests on the base (with a no-op
  FakeWSLDrives) fail with "mkdir .../home/me/.codex: file exists", the
  report's error; with ggbdpq's patch applied they still fail (the skill
  mkdir, and RTK's hook not written).
- mote: go build ./...; go vet of agent, library, sessions, provider for
  darwin, GOOS=windows (and linux for agent, library); gofmt -l clean;
  go test -timeout 45m ./internal/agent ./internal/library
  ./internal/sessions ./internal/provider: all ok.
- Windows (win-run): the same four packages. The new tests pass (the
  RTK ones skip: the fake distro runs sh). 32 tests are red, all already
  red at the base c63c2136b run on the same box, and filed (#4115, #2808:
  Hermes profiles, Codex keychain, Agy, desktop entries, ...); the Hermes
  ones fail alike on base and branch with -count=3.

- Rebased on origin/main 3ecc02b78 (it changed internal/agent): at this
  head on mote, go build ./..., go vet of the four packages for darwin,
  windows and linux, gofmt -l, go test ./internal/agent ./internal/library:
  ok.

Not tried: the full ./... suite; the GUI (no GUI change; the unreached
notice uses the existing Notice); a real Codex/Claude Code run against
the moved files in the distro.
2026-10-31 21:29:22 +08:00
yetone 3ecc02b78b agent: Claude Desktop is off magpie only when Desktop itself would be (dev_quj on X)
dev_quj on X: "magpie 一直提示Claude Desktop不经过magpie,我重启了依然还是
这个提示" — the Agents row said "已不经过 magpie:配置已变更" while
Desktop ran on magpie.

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

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

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

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

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

Not tried: Windows' Desktop (MSIX or classic) and a real gateway request
from Desktop; a signed-in claude.ai cookie (Desktop keeps "1p" then,
which magpie says only with the chooser on); dev_quj's own files, so
this is the class the report is in, not their proven trigger. No other
desktop agent reads a mode the same way; Codex/WorkBuddy checks unchanged.
2026-10-31 21:11:45 +08:00
yetone c63c2136b2 agent: with Claude Code's own models hidden, a tier's model keeps its /model row and the switch rewrites settings.json at once (#4548)
Two gaps in the previous commit's replaceBuiltInOptions:

- writePicker leaves out the row of a model a tier is on at an effort
  (#1616), since Claude Code shows it as that tier's row. With
  replaceBuiltInOptions Claude Code drops the tier rows along with its
  built-in lineup (2.1.316: only the Default row and the picker's own
  stay), so such a model was in /model nowhere. While the switch hides
  Claude Code's own models, every model keeps its row.
- SetOwnModelsHidden saved the setting without catalog.Touched, unlike
  SetHiddenModels, so flipping the switch in the GUI left Claude Code's
  settings.json as it was until some other change re-synced it.

Tests: TestClaudePickerLeavesOutATiersModelAtItsEffort gains the
replace case (Terra on Haiku at max is listed); TestOwnModelsSwitchTellsTheAgents
counts catalog.Changed per flip.

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: each half reverted alone -> TestClaudePickerLeavesOutATiersModelAtItsEffort and TestOwnModelsSwitchTellsTheAgents red.
2026-10-31 20:54:37 +08:00
ggbdpq 509d8e7d14 agent: a portable VS Code reads its User folder in its data folder
YOUIMARK's Windows has Scoop's VS Code 1.143, a portable build: magpie
showed the editor, but its Dir stayed %APPDATA%\Code\User, which doesn't
exist — code.cmd on PATH was detection enough — so the provider, models
and settings.json magpie wrote went where the build never reads.

Before: vscodeUserDir always took the OS's place for the User folder,
%APPDATA% on Windows; only detection ever looked at the editor itself,
by its launcher alone, so any portable build was found and then read
and written in a folder it doesn't use.

Now: a build whose launcher has a data folder beside it is portable, as
VS Code itself takes a build for portable by that folder alone — a zip's
own data folder, or Scoop's, whose apps\vscode\current\data is the
persisted one, current a junction into apps\vscode. Its User folder is
data\user-data\User there: found, wired, connected and disconnected
there. The launcher is found as detection finds it, and a Scoop shim
stands for the launcher the .shim beside it names, which proc.Unwrap
doesn't read. Zoo Code, which keeps its settings in VS Code's User
folder, is laid out by the same function and follows it. An installed
build's launcher has no data folder beside it, and keeps the OS's place;
so does a portable build before its first run, whose launcher alone is
still detection enough, its writes then making the folder where it
reads. VSCodium portable is left as it was: its data folder is named by
its product.json, which no report asks after.

This is the other half of the branch the Copilot-launcher fix came from
(taken along with 6f435677c, since reworked); it shares no code with
that one — this half is only where a portable build keeps its User
folder, not what magpie takes a copilot launcher for.

Run at this head (parent 841025836):
- New TestVSCodePortableUserDir: an installed build with the launcher on
  PATH keeps the OS's User folder; with the data folder beside the
  program the build's Dir is data\user-data\User, it is detected before
  its first run has made the folder, connecting writes magpie's group in
  the data folder's chatLanguageModels.json and disconnecting takes it
  out. New TestVSCodePortableScoopShim: the same through scoop's shims
  folder, the .shim naming the launcher in apps\vscode\current\bin, and
  a shim with no data folder beside the launcher it names staying an
  installed build. Both are red with vscodeUserDir taken back to the
  OS's place ("the portable build's User folder is .../Application
  Support/Code/User", "Scoop's portable VS Code reads ...") and green
  with the change.
- go test -tags nogui ./internal/agent -count=1: green but for
  TestMothX, which fails the same without this change — this machine's
  PATH has a real mothx (fnm), which the test's LookPath finds.
- gofmt -l clean; go vet ./internal/agent for darwin, linux and windows;
  go build ./... for darwin and windows, and for linux ./internal/agent
  (the repo's linux build fails in wails's own code on this machine
  without this change too).

Issue: #3260
Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: vscodeUserDir's portable branch off -> TestVSCodePortableUserDir and TestVSCodePortableScoopShim red. Checked against Scoop: extras/vscode.json puts appsscode
2026-10-31 20:54:37 +08:00
ggbdpq 2672ba429b agent: Claude Code's /model honors the own-models switch too (#4548)
The "show the agent's own models" switch filtered magpie's pickers
alone (agent.Picks, #1642): Claude Code's own /model rows stayed put,
because nothing magpie wrote for Claude Code looked at the switch —
while /model is fed by magpie all the same (modelPicker's rows are
writePicker's). raclen traced the whole chain (#4548).

writePicker now sets modelPicker.replaceBuiltInOptions (Claude Code's
own key: with it the /model picker shows only the listed rows) while
the switch is off, and drops the flag again when it is on, so the
whole picker is written either way. The Default row stays under both
settings: Claude Code keeps it as its own fallback.

Tests: TestClaudePickerOwnModelsSwitch writes a settings.json and
checks modelPicker carries the rows plus the flag with the switch
off, and the flag without it with the switch on.

Verification on the base 5d955a4d4, macOS arm64: agent package
-targets nogui; gofmt, vet on darwin/linux/windows and builds clean.
Claude Code's reading of the key is per its documented modelPicker
behavior (code.claude.com/docs, model-config); the Default-row
fallback shape is per the reporter's capture, not re-run here.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: the replaceBuiltInOptions line dropped -> TestClaudePickerOwnModelsSwitch red. Not tried: a real Claude Code /model with the switch flipped (2.1.316's handling of the flag was read from its binary).
2026-10-31 20:54:37 +08:00
yetone e2a65cbc9b dsh: a start on a found group's old id moves onto the id its route lists (zyh6036 on X)
zyh6036 on X: DeepSeek Harness Desktop showed no model after magpie
turned dsh on and the app restarted, while the profile's patch file was
full of magpie's gateway.

Cause: a dsh start (agent-default-model) magpie had set to a found
routing group keeps the id the group had then, group/auto-<slug>. Since
81a24cf8f the group is listed as auto/<model>, and that is the only id
magpie's routes list. dsh looks up the start by route and id, finds
nothing, and shows "Select model" with nothing picked. The owner's live
desktop profile was in this state: the start was
"group/auto-gpt-6-sol" and the route listed auto/gpt-6-sol.
renameFoundGroups never reached it, because it moves only values that
applied.json records, and there was no dsh record there.

Fix: dshStartOnItsRoute already moves a start onto the route its model
is on now. It now also moves a start whose id magpie no longer lists it
by (provider.PublicRef for a found group, provider.RenamedRef for a
renamed provider) onto the id the route lists. The effort and the other
keys in the entry stay. It runs on every route write, in every profile
(desktop, web, CLI) and in the home layer, so KeepDshWired repairs an
existing install within a round. The fix is not OS-specific.

Run at this head (rebased on bb5eb83c3), on mote (macOS) through mote-run:
- go test ./internal/agent ./internal/provider -count=1 -timeout 45m:
  ok (284s, 164s)
- go test ./internal/agent -run 'Dsh|FoundGroup|Drift|Keeps': ok
- GOOS=windows go vet ./...: ok
- GOOS=linux go vet ./internal/agent ./internal/provider: ok
  (a GOOS=linux vet of ./... from macOS stops in wails' cgo files)
- go vet ./internal/agent (darwin): ok
- gofmt -l: clean
The full suite was not run, so that another session's suite on mote
isn't held up (one full suite per machine). Only internal/agent changed.
The -run 'Dsh|...' subset ran before the rebase.

Broken by hand: with dsh.go at HEAD,
TestDshStartOnAFoundGroupsOldIdMovesOntoItsId fails, and the start
stays "group/auto-pro" in the web profile.

Real app: DeepSeek Harness 0.2.1-rc.5 on mote, each run in a sandbox
HOME and DSH_HOME:
- Fresh wiring shows magpie's models, whether the app was opened first
  or magpie wrote first.
- A copy of the owner's live desktop patch: every route is listed, but
  the seat reads "Select model".
- The same copy with the start as the fix writes it (auto/gpt-6-sol):
  the seat reads "GPT-6 Sol · routing group High", ticked in the picker.

Not tried:
- Running the fixed magpie binary itself against that copy. The unit
  test covers the magpie side.
- Windows' desktop app.
- Whether zyh6036's install was in this state. A store or key that
  doesn't resolve also empties the list (seen with no key at all), and
  their reply will say which.
2026-10-31 20:18:40 +08:00
yetone d6e1116380 codex: each end of the Codex app's app-server says why, and list flaps are guarded (#4550)
70d50254c (v0.1.2387) took the model list out of the route the Codex
app's app-server is ended on. The effort the app saves on each pick
went into the catalog, the next sync rewrote it, and the route's hash
of the catalog changed, so the app-server was ended every few minutes
and the ChatGPT app read that as a crash (goto_nozomi on Discord,
ggbdpq on #4550). This adds two things on top of that.

- codexAppStep logs each end with what made the app-server stale:
  "codex: ended the Codex app's app-server [pid] for the app to start
  another: <why>". The reason is the ChatGPT account switched, the
  route changed, or the used-up takeover. Before this a successful end
  logged nothing, so a reported crash couldn't be put down to magpie or
  to the app (ggbdpq asked for it on #4550).
- TestCodexAppRouteKeepsThroughListFlaps runs in a sandbox HOME
  through SyncCatalog. A relay's list drops a model and has it back,
  the catalog is re-ranked in another order with other descriptions,
  and the catalog is caught half-written. Each must leave the route as
  it was. 70d50254c's tests cover an effort pick and a rename.

Product call, as 70d50254c made it: a list change alone never restarts
the app-server, not even once Codex has been idle for a while. The
restart is what crashes ChatGPT when an MCP server is slow, and idle
time doesn't make it safe. The new list is read at the app's next
launch, or on the Agents row's Restart (StaleCopies). Where requests
go (model_provider, openai_base_url, the magpie table's base_url,
requires_openai_auth, the used-up takeover) still restarts it, as
TestCodexAppRouteFollowsConnectAndDisconnect and
TestCodexAppRouteFollowsOpenAIAuth hold.

Run (mote):
- go vet, GOOS=linux go vet and GOOS=windows go vet of ./internal/agent
  and ./internal/provider: clean.
- go test -count=1 -timeout 45m ./internal/agent ./internal/provider on
  e484b1e93: ok. Rebased onto 5cc2eea2f (dsh in internal/agent), then
  go vet and go test -count=1 -timeout 45m ./internal/agent again, and
  -run CodexApp ./internal/provider: ok.
- gofmt -l on both packages: nothing.

Broken by hand:
- TestCodexAppRouteKeepsThroughListFlaps at 70d50254c^ (the route
  still hashed the catalog) is red three ways: a model dropped (:119),
  another order (:141) and a half-written catalog (:147) each changed
  the route.
- With the used-up reason taken out of codexAppStep,
  TestCodexAppEndSaysWhy is red ("... start another: where Codex's
  config sends it changed", want "used up").

Not tried:
- The real ChatGPT/Codex app. Nothing here changes when the app-server
  is ended, only what is logged.
- The whole ./... suite and the GUI suite. Neither package touches the
  GUI.
- Whether goto_nozomi's crashes stop on v0.1.2387. #4550 stays open
  for them to say, with the new log line asked for if any crash is
  left.
2026-10-31 19:55:12 +08:00
yetone 5cc2eea2fe dsh: a dsh CLI that has booted no profile yet is wired in its web profile, not config.yaml (liby233)
liby233 on Discord: in WSL magpie wired dsh in ~/.dsh/config.yaml, and dsh
saw magpie's models only once they were written to its settings.yaml.
With no ~/.dsh/profiles, dshAt fell back to the "pre-0.1.5" config.yaml.
No dsh on npm reads that file. 0.0.1-rc.1 (the first), 0.0.1-rc.5,
0.1.0-rc.8, 0.1.1-rc.1/rc.2, 0.1.2-rc.1, 0.1.3-alpha.2 and 0.2.1-rc.5 all
boot $DSH_HOME/profiles/<name> (grepped from their npm tarballs). A dsh
makes no profile until one is first booted, so a fresh CLI install,
in a distro or not, was wired in a file that nothing reads.

- With no profile, and a dsh that is not from before profiles, magpie
  writes profiles/web/cordis.patch.yml as dsh's template, as it does
  for Desktop (#2279). dsh's initProfile adds package.json,
  pnpm-workspace.yaml and cordis.yml next to it and keeps the file.
- "Before profiles" is judged by the CLI's version where it is known
  (locally from its package.json; in a distro the WSL probe now asks
  dsh --version). Otherwise config.yaml is used only when it holds an
  entry that isn't magpie's. That keeps the legacy path for a genuinely
  old dsh.
- The sync carries a magpie model already wired in config.yaml (the
  reporter's state) into the profiles and drops magpie's entries from
  config.yaml. It does this whether or not dsh has since booted a bare
  web profile, and only where no profile has a model or wiring of its
  own.
- Disconnecting before dsh ever booted the web profile removes what
  magpie made, as for Desktop.

Tests: TestDshCLIWithNoProfileYet and TestDshConfigYamlCarriedToProfiles
(new), plus wslMore's dsh row, now profiles/web. All three are red on the
old dsh.go: "names .../.dsh/config.yaml, not the web profile's patch
list", and the web profile is left as dsh's bare template after the sync.
Tests pin dshVersion, so a dsh on the test machine decides nothing.

Run (go test -timeout 45m, logs teed and grepped):
- gofmt -l internal/agent: clean. go vet ./internal/agent on darwin,
  GOOS=linux and GOOS=windows (mote): ok.
- go test -run 'TestDsh|WSL' ./internal/agent: ok on mote (macOS),
  magpie-desktop (WSL Ubuntu 24.04, nogui) and xiaomi-gpu (Windows 11).
- Full suite `go test ./...` on mote at this change on origin/main
  8680ffa41: 82 packages ok; internal/gui red only in
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK (#3949), both filed before this and
  in code this change doesn't reach.
- Rebased again onto origin/main 70d50254c (it changed internal/agent's
  new_session_effort and rename_group tests). At this pushed head: vet
  (darwin, linux, windows) ok, and internal/agent, internal/cli ok;
  internal/gui has the same two reds and no others.
- Rebased once more onto e484b1e93, which touches internal/provider only.
  At that head (the pushed one): go build ./..., go vet internal/agent and
  internal/provider, and go test -run 'TestDsh|WSL' ./internal/agent all
  ok on mote.
- Real dsh 0.2.1-rc.5 from npm in magpie-desktop, in sandbox HOMEs under
  ~/dshprobe (never the live ~/.dsh), with this commit's CLI built there
  (nogui):
  A. Empty HOME, `magpie dsh magpie/relay/glm-4.6`: only
     profiles/web/cordis.patch.yml was written, holding llm-pi-ai's
     magpie route, agent-default-model and web-search-deepseek.
     `dsh --profile web --dump-config` shows llm-pi-ai baseURL
     127.0.0.1:3425/v1 and agent-default-model relay/glm-4.6. dsh added
     package.json, pnpm-workspace.yaml and cordis.yml and kept magpie's
     entries. `magpie dsh default` then left dsh's bare template.
  B. origin/main's CLI wired config.yaml (the reporter's state). The
     dump showed no magpie route. `dsh --profile web --dump-config`
     booted web, then this CLI's `magpie sync` moved the route and model
     into profiles/web and emptied config.yaml, and the dump showed them.
  C. Wired and never booted: `magpie dsh default` removed profiles/.
Not tried: the reporter's own machine and dsh version, a running
`dsh web` session picking the model up live, the desktop app, and a
pre-npm dsh that reads config.yaml (none could be found).
2026-10-31 19:50:39 +08:00
yetone 70d50254cb codex: a change to the model list alone no longer ends the Codex app's app-server
The Codex app crashed and relaunched every few minutes (indekkusu141209
on X, #4550: 08:06, 08:12, 08:26).

Cause. KeepCodexAppOnItsProvider ends the app's app-server whenever
codexAppRoute changes. Since ca8a6f346 (lucis0116 on X) the route held a
hash of the bytes in the catalog that model_catalog_json names. The
ChatGPT app takes an ended app-server as a crash. Those bytes change far
more often than where requests go:

- Each model's default_reasoning_level follows config.toml's
  model_reasoning_effort (codexcat.ModelDefault, Creat.wu on Discord).
- The Codex app writes that key on every effort pick, and on a switch to
  a model with other levels. So does magpie's settle() when a pick moves
  the effort.
- The next SyncCatalog, set off by things like a plugin token refresh or
  a providers.json save, rewrote the catalog. 3s later the route had
  changed, and the app-server was ended once idle.

The route doc's own promise, "nothing the Codex app writes itself is in
route", was broken through the catalog.

The repro was in a sandbox HOME, not the live ~/.codex. A throwaway
gateway test diffed CodexDesktopCatalog's bytes:
- Two passes with nothing changed: same bytes.
- A model pick: same bytes.
- models_cache.json refetched with a new fetched_at/etag: same bytes.
- model_reasoning_effort low -> high: different bytes.
The new agent tests below show the same for magpie-models.json, and the
old route moved with it.

Change. The route is where requests go, and only that:
model_provider, openai_base_url, magpie's base_url and
requires_openai_auth, and AppOut. model_catalog_json and the catalog's
content are out, and codexCatalogTag (codex_app_route.go) is gone. A
list-only change (a provider renamed, a model added, an effort picked)
restarts nothing. The app reads the new list at its next launch. The
Agents row already shows a Codex app on an older list, with its Restart
(StaleCopies). Its digest compares slugs and visibility, so an effort
pick doesn't flag it. No new UI.

The effort in the catalog is kept. It is the Creat.wu fix, and with the
restart decoupled, a rewrite of a file the app reads only at start costs
nothing.

Trade-off: a provider renamed or a model added in magpie shows in a
running Codex app only after it is reopened, or after the Agents row's
Restart. Before this commit that happened on its own, which was
lucis0116's ask.

Siblings, all read:
- RestartCodexApp (Agents row), RestartSwitchedCodexApp (switch notice,
  46aa7e6b8) and RestartCodexAppWhenIdle (uninstall) are user-started or
  a real route change. None reads the catalog. Unchanged.
- KeepCodexDaemonCurrent restarts the CLI's managed daemon only with no
  codex session on it, on the slug digest. That is not the desktop app.
  Unchanged.
- No other agent hashes its catalog into a restart.
- zhangjian94cn's fix/4243-codex-lifecycle-boundary takes away all of
  magpie's restarts. That goes further than this commit, and no code was
  taken from it. #4243 (aresxu8866-hue) asked for the catalog to count
  only when it is magpie's, which this commit supersedes.

Tests:
- TestCodexEffortPickKeepsTheAppRunning (new): the reporter's case. An
  effort saved as the app saves it, then SyncCatalog. The catalog
  changes and the route does not.
- TestCodexAppRouteIgnoresARename replaces
  TestCodexAppRouteFollowsTheCatalog, whose guarantee is now reversed.
- Broken by hand: both new tests run on the old codexAppRoute are red
  ("an effort picked in the Codex app changed its route", "a provider
  renamed changed the Codex app's route"). Green with the change.

Run at this head (5b0bb1349's tree, rebased on e90a635a9), on mote:
- go test -tags nogui -count=1 -timeout 45m ./internal/agent
  ./internal/provider: ok, ok. The same before the rebase.
- gofmt -l .: nothing.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./..., go build ./...: ok. That run was before the rebase; vet
  on agent and provider was run again after it.

Not run: the full go test ./... suite. Another session's full suite held
mote, and the owner's rule is to ship without holding for it; it follows
after the push. Not tried: a real ChatGPT/Codex desktop app. Nothing on
the ChatGPT side was changed or measured (the MCP handshake ggbdpq
traced). docs/subsystems/agent-wiring.md was updated.
2026-10-31 19:39:38 +08:00
JoeyWu-tech bec9df0888 sessions: a provider move leaves a thread a Codex has open (#3751)
#3751's second half; 67b12956 fixed the half about lengths. A Codex
thread moved to another provider, by the Sessions page's Move
(MoveCodexProvider, #887) or as Codex steps off magpie (bringBack's
MoveCodexThreads), has each of its rollouts written whole into a temp
file that then takes its place. The move took no Codex lock and left
alone only a thread written to in the last minute. A Codex that resumed
the thread (the app-server, as run below; a resumed TUI too, by Codex's
source) keeps its rollout open to append to for as long as it has the
thread, so what it wrote after a move went into the file the rename had
put aside: a turn the upstream answered was in neither the rollout nor
what Codex sent after its next resume.

moveCodexPaths now holds the thread as Codex holds one it writes to,
archives or deletes (rollout/src/writer_lock.rs, acquire; thread-store
holds it through a whole archive, unarchive or delete): under
thread-writer-locks/.coordination.lock it makes and locks
thread-writer-locks/<thread>.lock, then lets the coordination lock go
and keeps the thread's lock from before a file is copied to the trash
until the thread's row in the state database has moved. Letting go takes
the lock file away under the coordination lock, as Codex's guard does. A
Codex that resumes the thread meanwhile is turned away by Codex itself
("already has an active writer"), so the files and the row move together
and a rollback is written under no Codex. A thread a Codex has open is
left as it was: its files, their time and its row, with no copy kept.

Its error, "a Codex has the session open", is ErrActive too, so it goes
where a thread written to in the last minute goes: MoveCodexThreads
leaves it for its next call, and the Sessions page's reply marks it
active, so the page says "{title} is still being written to; close it in
Codex and try again in a minute" ("{n} sessions ..." for several), in
en, zh, zh-TW, ja and de. No new words and no GUI file changed: app.js
grows 0 bytes. There is no CLI for the move. The minute is the page's
own: codex exec lets the thread go as it exits (the interactive TUI
wasn't tried), but Codex 0.164.0's app-server keeps a thread loaded, and
held, until 30 minutes after it went idle with nothing showing it
(thread_unload_delay_secs, 1800 by default), or until it ends. So a
thread the Codex app has shown can be refused for up to half an hour
after it is closed there, or until the app quits. Those words are left
as they are (#3986).

A Codex home without thread-writer-locks (a Codex from before them)
has no lock to take, and its threads move as before, with the
last-minute check alone. None is made there: PortCodexRollouts reads a
home with one as one whose Codex holds its threads, and would then
rewrite rollouts under a Codex that doesn't. A lock folder that can't
be read, or a lock file that can't be opened, refuses the move with
its error. The coordination lock is waited for at most 10s
(filelock.Wait), under storeMu and mu as the row's 5s busy_timeout
already is; not had by then, the thread counts as held, as in
editRollout.

editRollout, the port's writer, isn't used: it publishes one file under
the coordination lock alone, while a thread's files (a revert's, a
packed twin) and its row move together, and its edit can't refuse a
longer id in a paginated rollout as 67b12956's rewriteCodexProvider
does. rewriteCodexProvider is unchanged, so the padding and that
refusal stay as they were.

A thread bringBack leaves keeps its row on magpie, so the next bringBack
picks it again (codexThreadsOn) and moves it once its Codex has let go:
it isn't left for good. bringBack runs at Disconnect and in Codex's
Sync, which SyncCatalog runs: at the GUI's start, after a provider,
plugin or model list is saved or fetched, and when the catalog is
fetched again (catalog.KeepFresh, at least daily in the GUI and in
magpie serve). Until then the thread stays on magpie, as one written to
in the last minute does now, so for up to about a day while magpie runs.
At a Disconnect magpie also restarts the Codex app's app-server
(KeepCodexAppOnItsProvider, every 3s), which lets the thread go; when
that comes after bringBack's move, the thread waits for the next Sync.
When Codex goes back to openai, or another id of magpie's length,
RelabelCodexThreads first writes a plain rollout's provider in place,
held or not; MoveCodexThreads meets a held thread there only for what
that skips, a packed rollout mostly. For an id of another length it
moves them all.

RelabelCodexThreads takes no lock either. It writes the id over in the
first line, in place, so a Codex appending to the file loses nothing:
tried below, the turn after it was kept and the row stayed as it wrote
it. It is left as it is.

The port's paragraph in docs/subsystems/gateway-routing.md, where
67b12956 put the move's lengths, says so, and so do the comments of
MoveCodexProvider, MoveCodexThreads and bringBack.

What was run (tree d652ce94, on origin/main 74dcf40a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestMoveCodexProviderLeavesAnOpenThread (new): a thread's writer lock
  held as a resumed Codex holds it. The Move is refused with ErrActive;
  the file, its time and the row are as they were, nothing is kept in
  the trash and no temp file is left. With the lock let go (its file
  left behind, as a Codex that ended leaves it), the Move goes through
  and the lock file is gone.
- TestMoveCodexProviderHoldsTheThread (new): looked at from a trigger
  on the row's update, as the Move writes the row, the thread's lock is
  held and the file names the new provider already; the lock file is
  gone after.
- TestMoveCodexThreadsLeavesAnOpenThread (new): two threads on magpie,
  one held. The other moves; the held one keeps its file and row, with
  no copy and no error, and the next call moves it once let go. A home
  without thread-writer-locks moves its thread as before, and gets
  none.
- The three with 74dcf40a's codex_provider.go: red, "err <nil>, want
  ErrActive", "as the row was written: no lock file", and both threads
  moved.
- -race -count=10, the three and every move and port test of
  internal/sessions (TestCodexProviderIn, TestMoveCodexProvider,
  TestMoveCodexProviderPacked, TestMoveCodexProviderKeepsBytePlaces,
  TestMoveCodexThreads, TestMoveCodexThreadsNone,
  TestPortCodexRollouts and its KeepsBytePlaces, LeavesAnOpenThread,
  LongerLine and RepairsForks, TestPortLineDropsClaudeBlocks,
  TestPortLineLeavesOthers): 16 tests, 10 runs each, ok. -race
  -count=3: internal/agent's TestCodexThreadsComeBackOffMagpie and
  TestCodexThreadsFollowMagpieIn (bringBack, bringOver) and
  internal/gateway's TestPortedCompactionReadsTheSame, ok.
- Broken by hand, each alone in a scratch worktree at this tree, the
  eight move tests run, each red:
  - no lock taken: all three new tests, as at 74dcf40a.
  - the row written for a thread left: both LeavesAnOpenThread tests
    ("its row moved to ..., its files didn't"), and MoveCodexThreads
    never finds the thread again ("after its Codex let go: [] <nil>").
  - the lock taken after the copy to the trash: both
    LeavesAnOpenThread tests ("a copy kept of a thread left as it
    was").
  - the lock let go after the files, before the row:
    TestMoveCodexProviderHoldsTheThread.
  - the error not ErrActive: TestMoveCodexProviderLeavesAnOpenThread
    ("err a Codex has the session open, want ErrActive") and
    TestMoveCodexThreadsLeavesAnOpenThread (the held thread's error
    returned, "thread ...: a Codex has the session open").
  - the lock file left when the move lets go: both
    TestMoveCodexProvider tests.
  - thread-writer-locks made in a home without one:
    TestMoveCodexThreadsLeavesAnOpenThread.
  The other move tests stayed green under each.
- Codex CLI 0.164.0, real, with gw-c's #3616 move-open harness: a
  sandbox HOME and CODEX_HOME, loopback only, a fake Responses
  upstream, and MoveCodexThreads from fake-provider to fake through a
  test binary built from each tree. Two turns on a thread T; a codex
  app-server resumes T (T's lock file appears in thread-writer-locks),
  waits 80s and has a turn; at 70s, the move.
  - 74dcf40a: the move moved T, file and row. The turn completed and
    the upstream got it, but the rollout has it 0 times, and Codex
    resuming T on fake sent turns 1 and 2 without it.
  - here: the move moved nothing, file and row on fake-provider. The
    turn is in the rollout (2 lines). With the app-server gone (its
    lock file gone) and the rollout a minute old, the move moved T
    (files 1, db 1), and thread-writer-locks had only
    .coordination.lock after it. Codex resuming T on fake sent turns 1
    and 2 and the turn the app-server had.
  Each tree ran twice: in the first runs the move after the app-server
  came within the minute after its turn, which left T here; the script
  now waits the minute out.
- Codex CLI 0.164.0, the same sandbox: with T's lock file made and
  flocked under the coordination lock by another process, as
  holdCodexThread does, codex exec resume T exits 1 with "thread/resume
  failed: thread ... already has an active writer" and sends nothing;
  once it is let go and the file taken away, the resume runs.
- Codex CLI 0.164.0, the move-open run with RelabelCodexThreads from
  fake to fak2 (one length) at 70s: T relabelled at once, the turn in
  the rollout (2 lines), the row still fak2 after it, and Codex
  resuming T on fak2 sent the turn.
- gofmt -l clean. tools/vetset.sh: go vet -tags nogui for linux,
  windows and darwin, go vet for windows, go build -tags nogui for
  linux and darwin, and go build for windows, exit 0 each; untagged
  linux vet and build exit 1 (no GTK or WebKitGTK dev packages on this
  box).
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 68 packages ok and 8 red, sessions ok; each red on the list of
  reds already filed: agent (#3141, #3398, #3641, and
  TestWSLColdPlaceOpensNothing, #3924), davsync TestSync (#3420), edit
  and testenv (umask 077, #3640), gateway
  TestPluginToldWhereTheAgentWorks (#3675), gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649), provider TestCodexAppServersOnHome (#3906), then "close of
  synctest channel from outside bubble" (#3632), tui
  TestTUIFetchesSubscriptionModels/agent (#3919)
- On origin/main 1a804859 with this commit cherry-picked (a scratch
  worktree, not this tree): go test ./internal/sessions ok; go test -run
  Codex ./internal/agent, only TestCodexDriftReached red (#3398)
Not run: the GUI tests, i18n-keys among them; no GUI file changed.

Not tried: Windows, where magpie's lock is LockFileEx on one byte and
Codex's on the whole file (as for the port), and macOS; the Codex app
itself, whose app-server was driven over stdio here as the app drives
one; a thread of a Codex in a WSL distro moved from Windows, where the
lock taken may not be the distro's; a file system without locks, where
the move is refused as held.

Review (yetone, at this commit on origin/main bb5e68cea, go1.26.8):
- Checked against Codex's codex-rs/rollout/src/writer_lock.rs: acquire
  takes thread-writer-locks/.coordination.lock, creates and try-locks
  <thread_id>.lock and lets coordination go; its guard's drop takes
  coordination again, closes the file, removes it and lets go. The move
  does the same, and leaves a home without the folder alone.
- On main, the three new tests red on macOS (mote): "err <nil>, want
  ErrActive", "as the row was written: no lock file", both threads
  moved. With this change, ok.
- Broken by hand, each red: letGo called at once (HoldsTheThread);
  os.Remove dropped ("lock file is left", both MoveCodexProvider
  tests); threadOpen's Is false (LeavesAnOpenThread x2); the lock
  folder always made (MoveCodexThreads, "thread-writer-locks made where
  Codex keeps none").
- macOS (mote): go test -tags nogui ./internal/sessions
  ./internal/filelock ./internal/agent ok; -race -count=10 -run
  'TestMoveCodex|TestPortCodex' ./internal/sessions ok (at d0a61b856);
  gofmt -l clean; go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows for sessions and agent ok.
- Windows (xiaomi-gpu, win-run) and Linux (WSL magpie-desktop,
  wsl-run): go test -run 'TestMoveCodex|TestPortCodex'
  ./internal/sessions ok (at d0a61b856).
Not tried by the review: a real Codex CLI or app holding a thread
during a move, on any system; a WSL distro's Codex moved from Windows.

At the pushed tree (rebased on origin/main 7e0fe83d4), macOS (mote):
gofmt clean; go vet darwin, GOOS=windows and GOOS=linux -tags nogui for
sessions ok; go test -tags nogui ./internal/sessions ./internal/agent
ok; -run Budget ./internal/gui ok.
2026-10-31 18:52:01 +08:00
yetone 140efc8f71 agent: Alma is told magpie's models call tools, so it sends native tools and DeepSeek's DSML text no longer shows
ethanchi on Discord, checked with real WorkBuddy turns: Alma showed raw
DeepSeek DSML tool-call text with a magpie model. Alma decides function
calling per model from models.dev by the id (electron/model-capabilities.ts).
For an id models.dev doesn't know, such as a routing group's name
("workbuddy-ai-DeepSeek") or a plugin's model, it found none, and
electron/server.ts wrapped the model in hermesToolMiddleware. That
middleware puts the tools in the prompt, so no native tools went out and
DeepSeek answered in DSML text. The only way round it was turning on Tool
Calling in Alma's Model Options.

Alma stores that switch as capabilityOverrides.functionCalling on the
provider's availableModels (StoredModelCapabilities in
electron/database-schema.ts, written by PUT /api/providers/:id/models,
updateProviderModels). resolveModelCapabilities ->
getModelCapabilitiesWithOverrides takes a set functionCalling over the
auto value, and both places that pick hermesToolMiddleware (server.ts and
tools/agentExecutor.ts) ask resolveModelCapabilities. Read from Alma's
source at 546528ac.

almaModels now puts functionCalling: true in the capabilityOverrides of
every model it lists. That is the same claim the gateway's /v1/models
makes for every chat model (toolsTold). The drawer-only entry for image
generation is not told. A functionCalling the model already has in Alma is
the user's own, since magpie never wrote one before, so it is kept, off as
well as on (almaUserFirst, in almaWithOverrides and almaSameModels), and
it doesn't make every Sync write again. A model whose overrides Alma lost
is told again.

Tests (internal/agent): TestAlmaToldTools is new. TestAlmaToldReasoning's
pinned overrides now carry functionCalling: true, and the user's
functionCalling: false is still kept there.

Broken by hand, each red, then restored:
- functionCalling line removed: TestAlmaToldTools "relay/glm-4.6:
  functionCalling <nil>, want true", TestAlmaToldReasoning red.
- user-first skip removed in almaWithOverrides: "user's off:
  functionCalling true".
- user-first skip removed in almaSameModels: "second sync wrote [PUT
  /api/providers/p1/models]".

Run on mote at 7aa67e9e5 + this change: gofmt -l (nothing), go vet
./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
go build, GOOS=linux go build -tags nogui, GOOS=windows go build: all ok.
go test -tags nogui -timeout 45m -count=1 ./...: 82 packages ok,
internal/agent and internal/gateway among them. One red: internal/gui
TestSettingsSaveKeepsWhatItDoesNotSend ("SearchAll: not sent by the
Settings page"). That is #4514, open since b09349d17's test fixture, with
yiqiui's patch on it. It is not touched here.
Rebased on 7b883cc61, where nothing new touches internal/agent: go build,
go vet ./internal/agent and go test -tags nogui ./internal/agent/ ok on
mote at the pushed head.

Not tried: a real Alma. The values come from Alma's source; the request
that reaches Alma goes through the fake Alma in alma_test.go. The user's
real Alma data was not touched. No GUI files changed, so no GUI suite was
run. A model that magpie told functionCalling: true keeps it if magpie
later stops listing it as calling tools. Today magpie says so for every
chat model, so that can't happen yet.
2026-10-31 18:33:03 +08:00
yetone 47173f593a sessions: a Codex thread left magpie keeps no reasoning OpenAI didn't seal
hentulong on X: after routing Codex through WorkBuddy and switching back,
Codex couldn't connect, and a fork said "Persisted response contains
hosted-tool, compaction, or unverifiable hidden reasoning state that
Rustponses cannot replay".

Cause: while Codex is routed through magpie to another vendor, the
reasoning items magpie hands it stay in the thread's rollout. After the
switch back Codex talks to chatgpt.com itself, and OpenAI refuses every
reasoning item it didn't seal. On the owner's real account:
- summary only, no encrypted_content: unsupported_persisted_item_context
  (the reporter's Rustponses error) on a previous_response_id
  continuation;
- with content (reasoning_text, what Codex 0.165 writes for DeepSeek via
  magpie): 400 array_above_max_length "Invalid 'input[5].content'";
- foreign encrypted_content: invalid_encrypted_content.
Codex treats each as fatal, so that thread and its forks fail while new
threads work. No stale config: Unwire/EndFailover drop openai_base_url.

Fix: when Codex is no longer routed or failing over (Unwire, quit,
uninstall and the periodic pass), PortCodexRolloutsLeft rewrites, in
threads begun on openai/magpie, every reasoning item (and every one in a
compacted line's replacement_history) whose encrypted_content isn't an
OpenAI Fernet token ("gAAAA") into type "magpie_reasoning", without id
and encrypted_content. Codex reads an unknown type as Other and never
sends it; magpie's sessions readers still show it. The edit keeps member
order and line length (same fitLine/lock path as the existing port),
has its own state entry, and starts at 2026-09-21. A survey of 150 live
rollouts found 340 of 340 OpenAI reasoning items in the gAAAA shape.

Run (mote, at f1d0c0bfd + this): go vet ./... for darwin, linux and
windows; go build for the three; go test -tags nogui -timeout 45m ./...:
every package ok but internal/gui, whose one red is
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll), open on main as #4514; gofmt -l clean.
Broken by hand: with the retire step off, and with Unwire passing false,
TestPortCodexRolloutsLeftRetiresUnsealedReasoning,
TestPortCodexRolloutsLeftKeepsItsOwnState and
TestCodexDisconnectRetiresMagpieReasoning go red.
Real Codex 0.165, sandbox CODEX_HOME, owner's account: a turn via magpie
with auto/deepseek-flash, then `codex exec resume` on gpt-6-sol direct
failed with array_above_max_length; after the left port the same resume
answered. The summary-only Rustponses refusal was reproduced with a
websocket probe against chatgpt.com and is retired by the same rule.

Not tried: the reporter's exact case in the interactive TUI (exec
resume doesn't warm up, so it never sends previous_response_id). A
thread Codex holds open keeps its in-memory history until reopened; a
switch not made through Unwire is caught by the periodic pass within
10 minutes.

Rebased after the full run onto 9551fadcb (5174c0970 GUI assets,
9551fadcb gateway/usage; no file here). At the pushed head:
go test -tags nogui -run Codex ./internal/sessions ./internal/agent ok,
go vet ./internal/sessions ./internal/agent ok.
2026-10-31 17:47:20 +08:00
yetone 5d955a4d4b tune: Codex can take the compaction advice in the background, its own limit kept (herman_hong)
herman_hong on Discord: Tuned for you advises Codex compact at ~120K.
A foreground compaction kept them waiting, so they had set 384K by hand.
Now that Codex compacts in the background, they want the advice there
and the 384K kept as the backstop.

Codex has this since 0.163.0 (checked in codex-rs at rust-v0.166.0, not
in 0.162.1): [features.async_compaction] enabled and
model_async_compact_threshold_percent, an integer share (1 to 100) of
the model's window, 65 by default. It is Stage::UnderDevelopment, runs
only with remote compaction v2 (which magpie already sets on its
provider), and starts none once the foreground limit is reached. magpie
already writes it from Settings' Background compaction (#2490), with
the version gate and the user's own keys kept. This drives that setting
from tune:

- agent: knob TuneAsync ("async_compact") on codex. TuneRead gives the
  share, TuneApply turns Background compaction on at it (stashing what
  Settings had the first time), and TuneUndo puts that back unless the
  user changed it since. The foreground limit (Long conversations, or
  the user's model_auto_compact_token_limit) is never touched. Async
  keys the user wrote in config.toml come first (codexAsyncOwn): the
  row says so and Apply errors. A table magpie wrote itself doesn't
  count as the user's.
- gui/tune.go: advice.async holds the advice as a share of the window,
  rounded down. With timed compactions it uses the token-cheapest
  window, since a background compaction keeps no one waiting. It is
  offered only when it would start before the foreground limit (the
  lesser of the limit now and 90% of the window). held lists Codexes
  too old for a share.
- context.js: the row gets a text button, "Use 120K in the background",
  whose tip gives the share and says the foreground limit stays. After
  Use a chip says so, with Undo background. A config.toml of the
  user's, or a Codex too old, gets a one-line caveat and no button.
  The too-old line is shared with Settings' row (codexHeld). No select,
  no layout change. zh, zh-TW, ja and de are in i18n.js.
- The core script budget goes up by 1,571 bytes for the row
  (core_budget_test.go says why). app.js is 278 bytes smaller.

Run (at this change on origin/main 6893cfbe3; rebased on d0a61b856,
whose new commits touch none of these files, and TestCoreScriptBudget,
TestTune*, TestCodexAsync* run again there: ok):
- gofmt -l: clean.
- mote-run go vet ./internal/agent ./internal/gui, plus GOOS=linux
  -tags nogui and GOOS=windows vet of both: ok.
- mote-run go test -count=1 -timeout 45m ./internal/agent
  ./internal/tune ./internal/provider: ok. ./internal/gui: the new
  tests and TestCoreScriptBudget pass. TestSettingsSaveKeepsWhatItDoes
  NotSend is red on clean origin/main too (#4514). Eleven AppKit window
  tests (TestMainWindowCorners, TestPanelCloseHidesIt, ...) were killed
  at their 30-40s on mote at load ~25; this change touches no window
  code.
- wsl-run node --test context-tune, codex-async-compact and i18n-keys:
  the new test passes in chromium and webkit, in all five languages,
  at 360 and 1100. It checks the label, the tip, the POST body
  {knob: async_compact, value: "30"}, the chip and Undo, the locked
  and held caveats, and no overflow. i18n-keys' "a plugin's words are
  its own" is red on main (#4524).

Broken by hand (each went red, then restored):
- codexAsyncOwn always "": TestTuneCodexAsyncOwn red in all 4 cases.
- asyncOurs ignoring the set share: TestTuneCodexAsync red (it would
  undo over the user's 50).
- codexAsyncAt keyed on WaitBest, and always ok: TestCodexAsyncAt red
  (timed cheapest, foreground, 90%).
- context.js posting without the knob: the GUI test red, knob
  "compact" where "async_compact" was wanted.

Not tried: a real Codex 0.163+ turn compacting in the background
through magpie, and a real account's /api/tune. When the models' windows
differ, the share comes from the advice's window, so the tokens are
approximate; the tip shows the share Codex gets.
2026-10-31 17:12:16 +08:00
yetone d83823d264 agent: a Claude Desktop Code tab session on WSL is told Desktop's window too (young02036)
young02036 on Discord: Claude Desktop 4.29.0 on Windows, a Code tab
session whose environment host is "WSL · Ubuntu", a magpie group of
Codex gpt-6.1-sol (500K) and Claude Opus 5.5 (1M) listed as
mythos-magpie-4247180078, and /context read "49.4k / 200k".

Cause: Desktop runs such a session on the distro's Claude Code, which
reads its user settings in the distro. Desktop 4.29.0's remote probe
reads them from `${CLAUDE_CONFIG_DIR:-$HOME/.claude}` there. Desktop sets
CLAUDE_CODE_MAX_CONTEXT_TOKENS only for Cowork (its bundle's one write of
it); a Code tab session gets the mythos-magpie id and no window. magpie
wrote Desktop's window, capabilities and Explore flag into Windows'
~/.claude/settings.json alone: desktopOn() was false for every
claude@wsl:<distro>. So the distro's Claude Code took the unknown id for
200K.

Fix: desktopOn() is true for a distro's Claude Code while this machine's
Desktop is on magpie (desktopSetsHere), so its Sync (desktopOnly when it
isn't on magpie itself, writeWindow when it is) writes the same values
into the distro's settings.json, and takes them out when Desktop leaves.
Turning Desktop on or off also syncs each running distro's Claude Code at
once; a stopped distro has no Sync (asleep) and is written on the first
catalog round after it starts.

Run:
- WSL (magpie-desktop, wsl-run), real Claude Code 2.1.289 in a sandbox
  HOME, `claude -p --model mythos-magpie-4247180078 /context`: no env in
  ~/.claude/settings.json gives "30.4k / 200k" and the unknown-model
  notice; CLAUDE_CODE_MAX_CONTEXT_TOKENS=500000 there gives "30.4k / 500k".
- New TestClaudeDesktopWSLContextWindow: a distro's settings.json gets
  1000000 and mythos-magpie capabilities with Desktop on, the user's
  model/theme kept, nothing before Desktop is on, all gone after it is off.
  mote and Windows (win-run) pass.
- Broken by hand: desktopOn returning false for a distro, the test is red
  ("the distro's window "", want glm's 1000000").
- win-run go test ./internal/agent -run 'TestClaudeDesktop|TestWSLClaude':
  only TestClaudeDesktopCarriesTheLanguage red, same at origin/main
  305c624ed on Windows alone (#4115).
- mote: go test -timeout 45m ./... at this tree (base 305c624ed):
  internal/agent ok (280s), 81 packages ok. Red, none touched here:
  internal/proc TestNoCommandBypassesProc (claudetui, #4491),
  internal/gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and the
  AppKit window tests killed at their deadlines on mote (#4125, #2645,
  #3949). GOOS=windows and GOOS=linux go vet ./internal/agent ok,
  gofmt clean.

Not tried: the real Desktop 4.29.0 on Windows with a WSL host session
end to end (the window read from the bundle and the distro's real Claude
Code, not a Desktop session); Claude Code 2.1.309 (the distro has
2.1.289). A session already open keeps the window it started with until
a new one starts.
2026-10-31 16:37:42 +08:00
yetone 41357f3935 codex: the ChatGPT desktop app on Linux is found, and a switch reaches it
pota on Discord: magpie switches the ChatGPT (Codex) desktop app's
account on macOS and Windows but not on Linux. OpenAI ships the app for
Linux since 08-11 (preview; learn.chatgpt.com/docs/linux/linux-app): a
deb, an rpm and an Arch package, which install /usr/lib/chatgpt. Its
app-server is /usr/lib/chatgpt/resources/codex ... app-server, run with
the user's HOME and no CODEX_HOME, so it reads ~/.codex like the CLI.
isCodexAppServer took only .app/Contents/ and Windows paths, so on Linux
nothing found the app: no "still signed in as" notice after a switch,
no restart of its app-server, and no version on the Agents row.

- provider: linuxCodexApp takes an absolute .../chatgpt/resources/codex
  as the app's own app-server (findCodexApp, CodexAppStale, the switch's
  restart all read it).
- agent: restartOnLinux; codexAppOpen knows on Linux whether the app is
  open (any /usr/lib/chatgpt/ChatGPT process, not its codex alone or
  another program's ChatGPT). desktopApps["codex"].linux reads the
  version from resources/linux-package-metadata.json, HasApp/AppVersion
  see it, and codexReaders counts the bundled codex's --version as a
  reader of Codex's config. version() no longer stops at an empty store
  read before the other sources.

Real run, WSL magpie-desktop (Ubuntu 24.04), OpenAI's chatgpt_amd64.deb
26.1027.30824 (bundled codex-cli 0.166.0-alpha.5.1) under Xvfb, sandbox
HOME, fake unsigned JWT accounts alice/bob (no real credentials), magpie
web on 127.0.0.1:3591:
- POST /api/login/switch alice: 200, auth.json alice; /api/providers
  then says codexApp "bob@example.com" (the stale notice).
- POST /api/codex/daemon/restart-app: 200 in ~3s; the old app-server
  ended (app log "Codex CLI process exited classifiedAsExpected=true
  code=0"), a new one started with the sandbox HOME, the notice cleared.
- /api/agents/cli: "codex":{"app":"26.1027.30824"}.
- The same run with linuxCodexApp reverted: no notice, restart-app 400,
  the app-server untouched (pota's case).

Run at 5b1709eee: go test -tags nogui -timeout 45m ./internal/agent
./internal/provider on mote, ok; gofmt -l clean; GOOS=linux go vet
-tags nogui and GOOS=windows go vet, ok; go build ./... ok. Full
go test -tags nogui -timeout 45m ./... on mote at cae01311c (the
earlier base; nothing under internal/agent, provider or proc changed
since): every package ok except two reds that are on main and filed,
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestNoCommandBypassesProc (#4491, now child_unix.go too). WSL
./internal/agent ./internal/provider: provider ok; agent red only in
TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI and
TestOmpDetectedWithPiDir, red the same alone at origin/main 5b1709eee
in WSL (#4033, #3548); the new Linux tests pass there.

Broken by hand: linuxCodexApp returning false turns TestFindCodexApp and
TestCodexAppOwnServer red; codexAppOpen's Linux case removed and
linuxVersion returning "" turn TestCodexLinuxAppOpen and
TestCodexLinuxAppVersion red; the old store early return turns
TestCodexLinuxAppVersion red; codexReaders' linux case removed turns
TestCodexLinuxAppReadsTheConfig red in WSL.

Not tried: the rpm and Arch packages (the Arch one has the same
usr/lib/chatgpt layout; the rpm's is assumed), a real ChatGPT account
(the app's own UI asks to sign in, since the fake tokens fail refresh),
and reopening the app when no app-server comes back (Windows only;
Linux says to quit and open it again, as macOS does). A switch made from
the CLI while magpie web runs elsewhere doesn't restart the app; the
notice says to, as on macOS.
2026-10-31 16:08:28 +08:00
yetone cae01311cf agent: Kimi Code 2.x's notice says to reopen Settings › Providers, not to restart
After magpie writes Kimi's config.toml, every Kimi was told "reads its
settings at start-up — restart open kimi sessions". That holds for the old
Python kimi-cli (~/.kimi). Kimi Code 2.x (~/.kimi-code, npm
@moonshot-ai/kimi-code) watches config.toml and reloads it, so an open
session takes the new models at once; only its web and desktop app's model
picker is read again when Settings › Providers is opened again. jiabubu
picked from that stale picker and got "Model \"magpie/...\" is not
configured in config.toml".

The notice now follows KimiDir's legacy flag: kimi-cli keeps the restart
advice word for word, and Kimi Code 2.x is told "reads this as it runs; in
its web or desktop app, reopen Settings › Providers or reload the page to
see new models". The same goes for Kimi in a WSL distro: wslKind gets an
optional restartAt, which Kimi's kind uses to pick its notice from the
distro's folder (a stopped distro reads as ~/.kimi-code, as kimiDir has it).
Both new strings are in NOTICES and translated in zh, zh-TW, ja and de.

Run (worktree at 027360021 + this commit, through mote-run / wsl-run):
- gofmt -l internal/agent: nothing. go vet ./internal/agent,
  GOOS=linux go vet -tags nogui ./internal/agent ./internal/gui,
  GOOS=windows go vet ./internal/agent ./internal/gui: ok.
- go test -count=1 -timeout 45m ./internal/agent: ok (157s), including the
  new TestKimiNoticeByKind and TestEveryNoticeIsTranslated.
- Broken by hand: with kimi.go and wsl.go reverted, TestKimiNoticeByKind
  fails for Kimi Code 2.x both here and in WSL (the restart advice).
- GUI (wsl-run): agent-notice-lang in WebKit 11/11 and Chromium 11/11.
  i18n-keys 3 of 4; "a plugin's words are its own" fails on "Unmarked"
  (plugins/routing vs internal/usage/search_calls_test.go), red on main,
  #4524.
- go test ./internal/gui (at 0407d69e8 + this change) failed only in
  TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514) and real-window
  AppKit tests killed at their deadline on mote (#4125, #2645); the same
  five of them, run at clean origin/main 027360021, fail the same way.

Not tried: a real Kimi Code app showing this notice in magpie's GUI. Kimi
Code 2.4.1's reload behaviour is from an earlier sandbox run.
2026-10-31 15:20:39 +08:00
yetone 0407d69e84 provider: a group of Kimi models keeps always_thinking, dynamic tools and its default effort
jiabubu on Discord (#feedback): one Kimi Code model put in a routing group
so it lists first lost "always thinking" and "dynamic tool loading" in Kimi
Code, which the same model straight from its provider has. buildGroupEntries
never set AlwaysThinks, DynamicTools or DefaultEffort on a group (the Entry
comment said "a group has none of them"), so kimiModelTables wrote the
group's table without always_thinking and dynamically_loaded_tools, and
default_effort fell back to high.

groupSharedKimi now gives a group each of the three when every member's
entry says the same, and none of it when one member doesn't or has no
entry: a group request can reach any member (rule targets are members too,
ruledEntry's of()), so Kimi Code must not shape a request for a member that
can't take it. The capability words are Kimi Code 2.4.1's own
(catalog-runtime.ts capabilityFromDeclared), already written for direct
models; kimi-cli still gets neither.

Tests: TestGroupSharesKimiFacts (provider: all share, one without, efforts
differ) and TestKimiCodePlanCapabilities now writes a one-member group
"top" (the reporter's case: always_thinking, dynamically_loaded_tools,
default_effort max) and a group "mix" with a relay model (neither word).

Run on mote (mote-run, sandbox HOME):
- At 83a630d69 (on fbb1b36d1): gofmt -l internal/provider internal/agent
  clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... ok; go test -tags nogui -count=1 -timeout 45m ./...: every
  package ok but internal/gui TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and internal/proc TestNoCommandBypassesProc (#4491). Both fail
  the same at origin/main 841326709, just fetched; neither touches this
  change.
- At the pushed head (rebased on 841326709): go test -count=1 -timeout 45m
  ./internal/provider ./internal/agent ./internal/catalog ok.

Broken by hand: without the groupSharedKimi call, both tests go red
(group/top loses always_thinking and dynamically_loaded_tools and gets
high). With "any member" instead of "every member", both go red
(group/mix and the mixed auto groups get the words).

Not tried: a real Kimi Code session picking the group (the words are the
ones real Kimi Code 2.4.1 already reads for direct models), Windows and
Linux test runs (vet only), nested groups.
2026-10-31 14:59:44 +08:00
yetone 1a2ce7b8ef agent: a model picked in Claude Code's /model beside a Claude main runs at its own window, not 200K
young02036 on Discord put Codex Plus gpt-6.1-sol (500K) and Claude opus 5.5 (1M) in one routing group, with Context set to the smallest member's (500K). Each model picked on its own showed its window. The group showed 200K.

Cause: with the main model one of Claude's own, marked [1m], magpie tells Claude Code no window. Anthropic runs that model at its own window, so claudeWindow is 0 and no CLAUDE_CODE_MAX_CONTEXT_TOKENS is written. writePicker still lists every magpie model and group in /model. Claude Code 2.1.314 runs an id it doesn't know as Claude's at that MAX, and with no MAX at its own 200K. So group/mix and w/gpt-6.1-sol picked there ran at 200K.

Fix: pickerApart takes desktopPlan's path when four things hold:
- the main is a Claude model or a group of them;
- claudeWindow is 0;
- /model offers a row that is unmarked;
- that row isn't Claude's and has a known window.
desktopPlan also counts the picker rows (pickerRefs). The top MAX is then the largest window, and each smaller row gets its own modelSettings.<id>.autoCompactWindow. A group gets its smallest member's window, the same as every other agent; under Full window that is 500K uncapped.

Every other main is as before. A told window still serves a /model pick, and a main of no known window keeps the last one. Codex, OpenCode, DSH, Pi and the rest already list the group at 500000: they read the catalog's Context, which for a group is its smallest member's.

Real Claude Code 2.1.314, in a sandbox HOME against a fake Anthropic server, with `-p --model X "/context"`:
- old layout (no MAX): group/mix 200k, w/gpt-6.1-sol 200k;
- new layout: group/mix 272k, gpt 272k, glm 204.8k, claude [1m] 1m;
- new layout without the group's entry (Full window): group/mix 500k.

- go test -tags nogui ./internal/agent/: ok (289s), on the base before the rebase (576b5dcbc)
- at 3e5aa1151, after the rebase: go test -tags nogui -run 'Window|Picker|Context|TierEffort|Budget' ./internal/agent/: ok
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok
- gofmt -l: clean
- full suite (go test -tags nogui -timeout 45m ./...) at 3e5aa1151: still running at push, per the ship-immediately rule; any red gets an issue

Broken by hand: with pickerApart's term forced false, TestPickerModelsTheirOwnWindow is red with 10 errors ("a Claude main: group/mix in /model compacts at ""; want "272000"", MAX "" want 1000000, and so on). Earlier versions of the trigger turned five existing tests red (TestClaudeContextWindow, TestClaudeDesktopContextWindow, TestClaudeTierEffort, TestTypedWindowReachesCodexAndClaudeCode, TestLargestMemberTypedWindow), so the trigger is limited to a Claude main.

Not tried:
- the interactive /model switch (only `-p --model`);
- the reporter's real accounts;
- confirmation from the reporter that the agent is Claude Code.

Left alone, filed as #4509: a /model pick smaller than a non-Claude main's told window runs on the main's window.
2026-10-31 10:11:07 +08:00