agent: OpenMausBot gets magpie's models back, and a Restart for a list it hasn't read

maxleebeta (Discord #feedback, 11-08) picked Antigravity's models in
magpie, and OpenMausBot's model search didn't find them. magpie wrote them
correctly: a sandbox with an Antigravity sign-in lists
antigravity/gemini-3.8-flash[1m] and the others in config.json. OpenMausBot
loses them in three ways, each reproduced on the real app:

- it reads config.json once, at start, so a list magpie writes while it
  runs never reaches its picker;
- a change to any engine in its Settings writes back every engine as it
  held them since it started, so magpie's newer list is replaced by the
  old one;
- an edit of magpie's engine there (updateClaudeEndpoint) keeps only the
  model picked.

Nothing in magpie wrote the list again: a sync runs on a catalog change,
or when magpie starts.

- KeepOpenMausBotListed (gateway.WhileServing, every 30s) writes magpie's
  list again when the file lists other models (ombListStale). The model
  picked in OpenMausBot (ANTHROPIC_MODEL) and its other engines stay. It
  isn't a Check drift: that reads as unwired, and a port change rewires
  only agents without one.
- OpenMausBot gets a Restart on its Agents row (restartApps: OpenMausBot.app,
  OpenMausBot.exe; appReads: ombPart = gateway, first model, list, not the
  key), so one running on an older list is offered a reopen. Its own save
  of the same engine after it starts doesn't count.

The same gap in NewMax, LiveAgent, OpenPencil, OpenBot, Pencil and ZCode
is #5662.

Run (mote, at this tree rebased on origin/main 00198b26e; 06324e99e,
rebased onto since, changes comments and docs only):
- go test ./internal/agent ./internal/cli ./internal/claudecode . : ok
- go vet ./internal/agent ./internal/cli on darwin, GOOS=linux -tags
  nogui and GOOS=windows: ok; gofmt -l: clean
- TestOpenMausBotListWrittenAgain and TestOpenMausBotRestartOnMac, new
- Broken by hand: ombListStale always false turns
  TestOpenMausBotListWrittenAgain red (written back, edited there, the
  loop); dropping restartApps' entry turns TestOpenMausBotRestartOnMac
  and TestRestartAppsOnWindows red.
- Real OpenMausBot 0.1.145 on mote (the app's server under
  ELECTRON_RUN_AS_NODE, sandbox HOME and OMB_DATA_DIR, own port):
  /api/instances kept the start list after a model was added to the
  file; an icon PATCH on its other engine wrote the old list back over
  it; PATCH /api/instances/magpie/claude-endpoint left ["relay/gpt-5.5"].

Not tried: the full go test ./... (mote's suite.lock had six full runs
queued); the Restart on a real Windows OpenMausBot (OpenMausBot.exe is
electron-builder's default name, not seen on the box); magpie's own
keep loop against the real app (the tests cover the file it writes).

Reported-by: maxleebeta (Discord)
This commit is contained in:
yetone
2026-11-08 10:55:49 +08:00
parent 06324e99e8
commit cdf734757a
6 changed files with 342 additions and 12 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ something else shows up as drift.
| Disconnect and preview | `Disconnect` runs `Unwire`, then returns each field still on magpie to its default. Last it runs `Restore`: Pi and its kin (`piLike`: Pi, OmO, Prime Agent; and MothX, its one `settings.json`) copy `settings.json` and `models.json` aside (`*.before-magpie`, `beforeMagpie`) before magpie's first write, and put that copy back byte for byte where what Disconnect left is the same JSON; a file that wasn't there goes again when only empty objects are left in it. `DisconnectPreview` runs the real Disconnect on a copy under a temporary home, in a subprocess (`DryRunArg`), and diffs the files. The preview is never a second account of what Disconnect does. | [`applied.go`](../../internal/agent/applied.go), [`preview.go`](../../internal/agent/preview.go) |
| Uninstall | `magpie uninstall` and Settings › About › Uninstall magpie take magpie off this computer, because deleting magpie's folders by hand left Codex's `openai_base_url` on a gateway that was gone, and every turn failed with a 502 (Jevik_AI on X). `Run` goes in this order. `System` removes the service, opening at login, the Start menu shortcut, `magpie://` links and the privacy model's helper. `Agents` ends Codex's account failover, runs each connected agent's `Disconnect`, or its offline disconnect for a closed app, so the restore keeps what the user changed by hand since. It then takes Codex's leftovers (`TakeCodexLeftovers`): an `openai_base_url` at magpie's gateway, or magpie as Codex's provider, goes by the gates a Disconnect uses even when magpie's notes are gone and Codex reads as not connected (#3866); magpie's provider table stays for the threads that name it. It then ports Codex's rollouts and restarts the Codex app's app-server. `Data` deletes magpie's folders, but keeps the Library while it holds skills, servers or hooks. The executable stays where the user put it. The CLI refuses while another magpie runs, and asks first unless given `--yes`. The app runs `System` and `Agents` from `POST /api/uninstall`. If anything failed, nothing else is removed. Otherwise `POST /api/uninstall/finish` starts a detached `magpie uninstall --data-after <pid>`, which deletes the files once the app has quit, since WebView2 holds its folder open until then. magpie web refuses both routes (`TestUninstall*`, `uninstall-settings.test.cjs`). Every line magpie writes into a TOML, YAML or env config has a `# magpie:` note above it saying how to undo it, so a config left behind still names magpie (`edit.Mark`, `TestMarkedLinesEveryAgent`). | [`uninstall.go`](../../internal/uninstall/uninstall.go), [`uninstall_cli.go`](../../internal/cli/uninstall_cli.go), [`gui/uninstall.go`](../../internal/gui/uninstall.go) |
| Keeping configs current | `Reseat` moves agents off a model magpie no longer serves (#200). `OnGateway` and `Rewire` write the new gateway address into every connected agent when the port changes. `Source` and `Stale` say what an unconnected agent runs on, and whether running copies still use the old list. For Codex that is where its config sends it and which models its lists hold (`listedModels`, slug and visibility), not every byte of each entry: the Codex app's list carries the ChatGPT backend's entries as sent, asked for each hour, and a rewrite with the same models told the user to reopen the app several times a day (Qyburn3 on X). A digest an older magpie stashed over the same files is kept (`readsBefore`). | [`reseat.go`](../../internal/agent/reseat.go), [`rewire.go`](../../internal/agent/rewire.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Restarting a desktop app | Claude Desktop and WorkBuddy (WorkBuddy AI on macOS) read magpie's settings only as they start (微雨南山 and stones on Discord). `AppBehind` names one running here that started more than a second before magpie last changed what it reads (`changedAt`, which puts a change no file's time shows, such as Claude Desktop's gateway model list, at when it is first seen); only for an agent connected in magpie or disconnected in it. The row's Restart asks first in magpie's own dialog (`confirmRestart`), then `POST /api/agents/restart/{id}` runs `RestartApp`. On macOS (`restartApps`, the bundle found by id under `appFolders`, its `CFBundleExecutable` matched in `pgrep`) it quits as ⌘Q does and waits for every process of the bundle (`reopenBundle`), but a script run on the app's own executable (`runsScript`: a `.js` argument or an absolute path as its first argument), which the running check skips too. WorkBuddy starts its sidecar (`sidecar-entry.js`) and its `codebuddy` CLIs that way, detached; the sidecar outlives a quit, so counting it kept the row behind after every restart and made Restart wait it out and never open the app (Northes on Discord, 11-04, #3700). On Windows the same check reads each process's command line (`proc.CommandLine`); one still open after `appQuitWait` (a "Save?" question) is left as it is and not opened again (`noticeRestartStillOpen`). On Windows (`claude.exe` under `AnthropicClaude` or its Store package, `WorkBuddy.exe` outside the WorkBuddy AI folder) its processes are asked to close (`taskkill` without `/F`); one that has hidden every window and still runs after `appTrayGrace` (1s) is in the tray and has its tree ended at once (`waitClosed`, `winShown`: Claude Desktop hides its window in ~0.6s and keeps all its processes, so waiting the whole `appCloseWait` made a Restart ~12s where quitting by hand takes ~2s, CyberCaius on Discord, 10-29); one still showing a window (a question) gets `appCloseWait` before it is ended, and it is opened again through its Store id or Squirrel's stub. The Codex app's own Restart (`ReopenCodexApp`) asks first too, then ends only the app-server that app runs for itself (`provider.RestartCodexApp`: under its bundle, never a `--listen` one), as a switch does; the app starts another and keeps its window. Quitting and opening it, as before, opened a new window (yoshi037070 on Discord, 10-27). Codex on Windows, WorkBuddy AI on Windows and Linux aren't restarted: their process names aren't known. | [`apprestart.go`](../../internal/agent/apprestart.go), [`apprestart_windows.go`](../../internal/agent/apprestart_windows.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Restarting a desktop app | Claude Desktop, WorkBuddy (WorkBuddy AI on macOS) and OpenMausBot read magpie's settings only as they start (微雨南山 and stones on Discord). `AppBehind` names one running here that started more than a second before magpie last changed what it reads (`changedAt`, which puts a change no file's time shows, such as Claude Desktop's gateway model list, at when it is first seen); only for an agent connected in magpie or disconnected in it. The row's Restart asks first in magpie's own dialog (`confirmRestart`), then `POST /api/agents/restart/{id}` runs `RestartApp`. On macOS (`restartApps`, the bundle found by id under `appFolders`, its `CFBundleExecutable` matched in `pgrep`) it quits as ⌘Q does and waits for every process of the bundle (`reopenBundle`), but a script run on the app's own executable (`runsScript`: a `.js` argument or an absolute path as its first argument), which the running check skips too. WorkBuddy starts its sidecar (`sidecar-entry.js`) and its `codebuddy` CLIs that way, detached; the sidecar outlives a quit, so counting it kept the row behind after every restart and made Restart wait it out and never open the app (Northes on Discord, 11-04, #3700). On Windows the same check reads each process's command line (`proc.CommandLine`); one still open after `appQuitWait` (a "Save?" question) is left as it is and not opened again (`noticeRestartStillOpen`). On Windows (`claude.exe` under `AnthropicClaude` or its Store package, `WorkBuddy.exe` outside the WorkBuddy AI folder) its processes are asked to close (`taskkill` without `/F`); one that has hidden every window and still runs after `appTrayGrace` (1s) is in the tray and has its tree ended at once (`waitClosed`, `winShown`: Claude Desktop hides its window in ~0.6s and keeps all its processes, so waiting the whole `appCloseWait` made a Restart ~12s where quitting by hand takes ~2s, CyberCaius on Discord, 10-29); one still showing a window (a question) gets `appCloseWait` before it is ended, and it is opened again through its Store id or Squirrel's stub. The Codex app's own Restart (`ReopenCodexApp`) asks first too, then ends only the app-server that app runs for itself (`provider.RestartCodexApp`: under its bundle, never a `--listen` one), as a switch does; the app starts another and keeps its window. Quitting and opening it, as before, opened a new window (yoshi037070 on Discord, 10-27). Codex on Windows, WorkBuddy AI on Windows and Linux aren't restarted: their process names aren't known. | [`apprestart.go`](../../internal/agent/apprestart.go), [`apprestart_windows.go`](../../internal/agent/apprestart_windows.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Codex background compaction | Long conversations' Codex background compaction, in Codex's opened row on the Agents page (`CodexAsyncCompact`, `CodexAsyncCompactPercent`, #2490) writes `[features.async_compaction]` `enabled = true` and `model_async_compact_threshold_percent` (Codex 0.163 reads it only in that table) into each Codex config magpie routes, on every `Sync`. The table is written only when every Codex that reads the config is 0.163.0-alpha.8 or later (`codexReaders`: the CLI on PATH, the Mac app's bundled `codex-cli/codex-package.json`, the Windows Store app and an editor's `openai.chatgpt` extension, whose versions aren't known, a WSL distro's CLI): an older Codex takes every unknown `[features]` entry for a bool and won't load a config with the table ("invalid type: map, expected a boolean"). Otherwise, or with no Codex found, magpie writes the bare `[features]` `async_compaction = true`, which every Codex loads, and no threshold; a table magpie wrote before is taken out on the next `Sync`, and Settings' row names the Codex that held it (`CodexAsyncHeld`). Codex starts a background compaction only on a provider whose `capabilities.remote_compaction` is `"v2"`, which it gives OpenAI and Azure alone, so `[model_providers.magpie]` gets `capabilities = { remote_compaction = "v2" }` too, also when the user turned the feature on by hand (#2493); `putProvider` carries the table's capabilities over when it writes it again. What magpie wrote is in the stash under `codex.async`: a value the user set, or changed since, is never written over and stays when the switch goes off; a bare `async_compaction = true` the stash doesn't name as magpie's (`bool`), an inline or dotted table is the user's as written. | [`codex_async.go`](../../internal/agent/codex_async.go) |
| Codex windows | Each magpie model's entry in Codex's catalog (`codexcat.entriesAt`, and `listedEntry` for a relay's own entry) says the model's whole window as `context_window`, which Codex shows (95% of it) as the conversation's context. Where Codex compacts goes in the entry's `auto_compact_token_limit`: the threshold set on the model or its provider, else Long conversations' (`settings.Working`, 272K by default), only when that is below the window; Full window writes none. A model whose window magpie doesn't know (a relay listing none, one models.dev lacks) gets no `context_window` and still the threshold as `auto_compact_token_limit` (Long conversations' Compact at, 272K by default; a relay's own entry only a user-set one, under its own window and limit): Codex compacts at no point on an entry with neither, and after the vendor's "too long" every turn errors again until a manual /compact (jiangguochao666 on X, 11-01; reproduced with real Codex 0.165 and a relay refusing past 100K, compacted at 80K after the fix). `TestCodexCompactsWithNoKnownWindow`. A vendor that lists a larger window than it takes is not caught: Codex compacts on that window's 90%, or the threshold. Codex 0.165 compacts at the lesser of it and 90% of the window, and a `model_auto_compact_token_limit` the user put in config.toml comes before it, as a `model_context_window` there replaces every model's window (Codex then compacts at 90% of it). Long conversations' row in Codex's opened card names either one, top-level or in the profile config.toml picks (`agent.CodexCompactHeld`, sent to the page as one line by `codexKeysText`), and Take it out deletes them (`DropCodexCompactHolds`); magpie never deletes them on its own, as the value is the user's (zgjfjfl on Discord, 10-31: 128000 there, 544K in Long conversations). No threshold above a model's window moves Codex either, which then compacts at 90% of it: the row names the model Codex's config runs (`agent.CodexModel`, the picked profile's first) and the window magpie tells Codex for it, when Long conversations doesn't come below it and no threshold is set on the model or its provider (`codexWindowUnder` in internal/gui/api.go; the reporter's model was a relay's gpt-6-A). `TestCodexCompactHeldNamedAndTakenOut`, `TestCodexWindowUnderLongConversations`, codex-compact-held.test.cjs. Until 10-30 the threshold went in `context_window` with the window as `max_context_window`, so a 1M model showed 258K in Codex (01huadalang on Discord); `max_context_window` stays a field magpie owns so `Keep` doesn't carry an old catalog's over. Codex's own models (`codex/`) keep their entry's window. `Tag` carries `catalogFormat`, so a Codex holding a list in the old shape asks again. `TestCodexCatalogCompactAt`, `TestCodexWindowShownCompactApart`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
| An agent's own Long conversations | Codex, Claude Code and Grok Build (`settings.CompactAgents`) can each have a Long conversations of their own over the one for every agent (molianyin4227 on Discord: models differ, so one size fits none): `settings.AgentCompacts[agent]` holds Compact at (`At`, 0 for the working window) or Full window (`Full`), and `Settings.ForAgent(agent)` lays it over `CompactAt`/`FullContext` for that agent's readers alone (`codexcat.entriesAt`, `codexListed`, `claudeIn`'s `writeCompact` and `desktopPlan`, `grokModelTables`, the route list's `buildModels`, Codex's window line and Tuned for you). A threshold set on a model or its provider still comes first. An agent with none follows the value for every agent, so an agent without the key (any agent outside the three) gets nothing new written. Set by `provider.SetAgentCompact` (`POST /api/settings/agent-compact` `{agent, own, full, at}`; `own` false takes it away), shown as a row under Long conversations in the agent's opened row and its sheet ("Long conversations in <agent>": Every agent, Compact at, Full window), drawn by `agentcompact.js`, which app.js imports when the agent's settings hold Long conversations. Tuned for you's Use on an agent with its own value changes that one and stashes it under `tune.long.compact.<agent>`. In a terminal, `magpie model compact <codex|claude|grok> [every|off|<size>]` (`agentCompact`, `TestModelCompactAgentCmd`). Not covered: t3code's route list reads the value for every agent. `TestSetAgentCompact`, `TestCodexCatalogCompactAt`, `TestGrokWindowFollowsLongConversations`, `TestClaudeCompactAt`, `TestTuneAgentOwnLong`, agent-compact.test.cjs. | [`settings.go`](../../internal/settings/settings.go), [`compact.go`](../../internal/provider/compact.go), [`agentcompact.js`](../../internal/gui/assets/agentcompact.js) |
@@ -122,7 +122,7 @@ something else shows up as drift.
- Claude Code's auto mode review (`CLAUDE_CODE_AUTO_MODE_SERVER`, `claudeReviewEnv` in [`claude.go`](../../internal/agent/claude.go)) is written `"0"` while Claude Code is routed through magpie and none of the models it can reach there is one Anthropic reviews (`claudeReviewed`, by `gateway.AutoModeReviewable`: a model `AutoModeReviewed` that is asked on the Messages API; a Claude model a provider serves only on Chat or Responses, or one set to be asked on another API, is translated, carries no `safeguards` and counts for nothing, nexnull on Discord, `TestClaudeReviewedOnlyWhereMessagesReachClaude`): those it is shown (and Claude Desktop's while Desktop is on magpie), a shown group's members, those providers' fallbacks, and the models it is set to, each judged on the provider (or group, or fallback) it resolves to, as the gateway judges its requests, so a Claude model on Copilot or Kiro alone writes `"0"` and a name magpie doesn't know is judged by the name (`TestClaudeReviewedJudgesTheSetModelWhereItGoes`). Off, it classifies locally from the start, as it does anyway behind a gateway that doesn't answer, without the "isn't eligible because your requests go through 127.0.0.1:3425" notice (1EFLOPS on X). Where Anthropic has turned the local classifier off for the account (2.1.312 and later, [gateway routing](gateway-routing.md)), there is no check either way: off, 2.1.314 says it has "no check of its own to use instead"; on, it names the gateway; each action the check would judge asks for approval. Any reviewed model leaves it unset, since `/model` can take the session there; a model hidden from Claude Code doesn't count. It is rewritten on every model set and `Sync`, so adding a Claude provider turns the review back on. magpie's value is kept apart in the stash (`claude.auto_mode_server`), a user's own is left alone, and it goes when Claude Code is taken off magpie (`desktopOnly`, `unroute`). T3 Code's magpie instance, which runs Claude Code on the gateway through its own environment, carries the same `"0"` there by the models it lists (`t3InstanceJSON` in [`t3code.go`](../../internal/agent/t3code.go)); a value in the user's `~/.claude` settings comes after it.
- Claude Code's tool search (`ENABLE_TOOL_SEARCH`, `claudeSearchEnv` in [`claude.go`](../../internal/agent/claude.go)) is written `"true"` while Claude Code is routed through magpie. On, MCP tools are named in a reminder and loaded by `ToolSearch` when the model needs them, not sent whole on every request. Claude Code before 2.1.304 keeps it off behind an `ANTHROPIC_BASE_URL` other than Anthropic's, so the MCP router's tools all went on each request (cybercaius on Discord: 245 tools, 124K tokens of a 341K context; 2.1.290 through a sandbox gateway sent 242,346 bytes of tools, 27,443 with it on); 2.1.304 and later turn it on there themselves, and `"true"` also keeps it on in a conversation begun without it. The gateway carries deferred tools to every upstream (`Tool.Deferred`, `withoutDeferredTools`). magpie's value is kept apart in the stash (`claude.tool_search`); a value the user set, an empty one too, is theirs; it goes when Claude Code is taken off magpie (`desktopOnly`, `unroute`; `TestClaudeToolSearchOn`). T3 Code's magpie instance carries `"true"` in its environment unless the user gave it a value there (`TestT3CodeToolSearchOn`).
- Claude Desktop's Code tab gets tool search only with Desktop's own `toolSearchEnabled` policy on (3p only, off by default). Off, Desktop 2.7032 (`Ztr` "off") starts Claude Code with `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, and Claude Code (2.1.312, 2.1.316: `oae` returns "standard") then keeps tool search off whatever `ENABLE_TOOL_SEARCH` says, so every MCP tool went whole on each request (bigcat1800 on Discord: 13 MCP servers, ~162K tokens; a sandbox CLI with 60 MCP tools sent 83 tools, 205KB). On, with the gateway provider and a bundled Claude Code of 2.1.247 or later, Desktop hands the CLI `ENABLE_TOOL_SEARCH=force` as a managed setting and the same CLI sent 13 tools, MCP ones behind `ToolSearch`, 56KB, asking only `tool-search-tool-2025-10-19` of the betas. magpie's profile gets `toolSearchEnabled: true` once, on a switch on and from Sync, as `claudeAiImport` is (`desktopSeedToolSearch`, `desktopSeedOnce`, mark `claude-desktop.tool-search`): a value the user set, false too, or took away since, stays theirs (`TestClaudeDesktopTurnsOnToolSearch`). A profile the user applied for magpie's gateway (`desktopAppliedGateway`) is not written.
- OpenMausBot (`openmausbot.go`) runs each bot on an engine from `instances` in `~/.openmausbot/config.json` (`$OMB_DATA_DIR`, `server/config.ts` in its source). magpie writes the `magpie` engine as OpenMausBot's own Claude endpoint (`newClaudeEndpoint`, `claude-endpoints.ts`): driver `claudeAgent`, access `custom`, `config.configDir` under `providers/magpie` so OpenMausBot starts Claude Code with its own `CLAUDE_CONFIG_DIR` and strips account keys the engine doesn't set (`claudeEnvironment`, `claude.ts`), `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` at the gateway, and magpie's models as `config.endpointModels`, kept to the ids OpenMausBot's `CLAUDE_MODEL_ID` accepts (one bad id makes it refuse the whole engine). A non-empty `instances` is the whole fleet, so with none saved magpie writes OpenMausBot's `DEFAULT_FLEET` beside it (`ombFleet`, stashed as `openmausbot.fleet`) and takes it out again on off if the user hasn't changed it (`TestOpenMausBotFleetChanged`). The name, a model picked from the list, other env and a `cli` are the user's. OpenMausBot reads the file once at start and writes back the fleet it holds whenever an engine is edited in it, so the switch is refused while it runs (`errOMBRunning`; not checked on Windows) and the notice asks to quit it first. Codex bots use `~/.codex`, which magpie's Codex wiring already covers.
- OpenMausBot (`openmausbot.go`) runs each bot on an engine from `instances` in `~/.openmausbot/config.json` (`$OMB_DATA_DIR`, `server/config.ts` in its source). magpie writes the `magpie` engine as OpenMausBot's own Claude endpoint (`newClaudeEndpoint`, `claude-endpoints.ts`): driver `claudeAgent`, access `custom`, `config.configDir` under `providers/magpie` so OpenMausBot starts Claude Code with its own `CLAUDE_CONFIG_DIR` and strips account keys the engine doesn't set (`claudeEnvironment`, `claude.ts`), `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` at the gateway, and magpie's models as `config.endpointModels`, kept to the ids OpenMausBot's `CLAUDE_MODEL_ID` accepts (one bad id makes it refuse the whole engine). A non-empty `instances` is the whole fleet, so with none saved magpie writes OpenMausBot's `DEFAULT_FLEET` beside it (`ombFleet`, stashed as `openmausbot.fleet`) and takes it out again on off if the user hasn't changed it (`TestOpenMausBotFleetChanged`). The name, a model picked from the list, other env and a `cli` are the user's. OpenMausBot reads the file once at start and writes back the fleet it holds whenever an engine is edited in it, so the switch is refused while it runs (`errOMBRunning`; not checked on Windows) and the notice asks to quit it first. That write-back, and an edit of magpie's engine there (`updateClaudeEndpoint` keeps only the model picked and its tiers), leave `endpointModels` without models picked in magpie, and no catalog change follows to sync it again: while magpie serves, `KeepOpenMausBotListed` runs the sync every 30 seconds when the saved list differs from magpie's (`ombListStale`; maxleebeta on Discord, 11-08: Antigravity's models missing from its search). A copy started before magpie's last change to the engine (`ombPart`: the gateway, the first model and the list) offers the row's Restart (`restartApps`, `OpenMausBot.app` and `OpenMausBot.exe`). Codex bots use `~/.codex`, which magpie's Codex wiring already covers.
- T3 Code runs a thread on the harness of the provider instance its model is picked under, so magpie writes two instances (karissasel_ on X: only Claude Code could be picked). `magpie` runs Claude Code, as above. `magpie-codex` ("magpie · Codex", `t3CodexJSON` in [`t3code.go`](../../internal/agent/t3code.go)) runs Codex: its `config.launchArgs`, which T3 hands to `codex app-server` and the `-c` pairs of to `codex exec`, are Codex's own overrides, making `magpie` its `model_provider` (the same table `codex.go` writes) and `magpie-codex-models.json`, written beside settings.json from `codexcat`, its `model_catalog_json`. Each value is quoted for T3's `tokenizeCliArgs` (`t3Arg`; `TestT3CodeCodexInstance` reads them back with a port of it). `~/.codex/config.toml` is not written, and a `binaryPath` or `homePath` the user gave T3's own `codex` instance is carried over. The name, on/off and unknown keys are the user's; the launch args and catalog are magpie's, and Check says when the launch args no longer reach the gateway (`t3CodexOff`). An older Claude-only wiring gets the Codex instance on its next Sync once; one the user removed stays removed (`t3code.codex` in the stash) until magpie is turned on for T3 again (`TestT3CodeCodexInstanceAddedOnce`).
- Claude Code takes one window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, `claudeContextEnv` in [`claude.go`](../../internal/agent/claude.go)) for every model it doesn't know. Claude Code alone on magpie is told its main model's (`claudeWindow`), and a model picked in its `/model` (magpie's `modelPicker`) runs at that one value. Beside a main that is one of Claude's own models (or a group of them), with no tier that isn't, nothing is told, so a model picked there ran at Claude Code's own 200K: a routing group of a 500K GPT and a 1M Claude did (young02036 on Discord). Then (`pickerApart`) the `/model` rows (`pickerRefs`) count as tiers do in the layout below. While Claude Desktop is on magpie too, its Code tab runs Claude Code on the same `~/.claude/settings.json` with every model Desktop lists, so magpie tells it the largest window of those and of Claude Code's own models (its main, tiers and `/model` rows), and holds each model below it to its own with `modelSettings.<id>.autoCompactWindow` (`claudePlan` in [`claude_budget.go`](../../internal/agent/claude_budget.go), #2025: the least held a 1M model to 131K). A model handed by a `[1m]` id (Desktop's under `DesktopLongest`, or Claude Code's own) counts by its 1M too, so it still runs at 1M when Claude Code stops taking the id for 1M (the 1M beta turned away once, `CLAUDE_CODE_DISABLE_1M_CONTEXT`); left out, a 1M model beside a 272K GPT was told 272K (dumplings on Discord). Claude Code 2.1.296 matches that key by the id it was handed, lowercased and without `[1m]`; it comes before the top-level `autoCompactWindow`, which serves a model without one. `CLAUDE_CODE_AUTO_COMPACT_WINDOW` would take precedence over both, so in this mode magpie's working window goes in the top-level `autoCompactWindow` instead, and an entry is written only where a model's window or its own threshold differs from what it would run at without one. magpie's entries and top-level value are stashed (`claude.model_budgets`, `claude.compact_default`) and go when Desktop leaves magpie; the user's own entries, top-level value and variables stay, a user's entry past its model's window (or `auto`) holds the largest to that window, and with a `CLAUDE_CODE_AUTO_COMPACT_WINDOW` of the user's the least window is told as before. A Code tab session whose environment host is WSL runs on the distro's Claude Code, which reads `${CLAUDE_CONFIG_DIR:-$HOME/.claude}` there (Desktop 4.29.0's remote probe) and not Windows' file, so each `claude@wsl:<distro>` is told the same while Windows' Desktop is on magpie (`desktopOn`), on magpie itself or not; it read 200K for a 500K group before (young02036 on Discord).
- Claude Code is told what each of magpie's models can do in `CLAUDE_CODE_MODEL_CAPABILITIES` (`claudeCapsEnv`, `claudeCapabilities` in [`claude.go`](../../internal/agent/claude.go)): `<model>=effort[,xhigh_effort][,max_effort]` for those it is shown, and, while Claude Desktop is on magpie, for Desktop's `mythos-magpie-<number>` ids its Code tab hands it. A Claude model Claude Code knows gets no more than Claude Code gives it (Opus and Sonnet 4.6: no xhigh), and one with no known levels isn't named. A model that reaches max without xhigh (GLM-5.3 at low/high/max, DeepSeek V4 at high/max) is said to have xhigh too: the gateway runs xhigh at max for it (`fitEffort`), and Claude Code 2.1.299 turns Ultracode down without `xhigh_effort` ("Ultracode isn't available on …"), which in Desktop is the Ultracode level and dynamic workflows (leesunrise2364 on Discord; `TestClaudeModelCapabilities`). A value of the user's is left alone.
+21 -9
View File
@@ -16,10 +16,11 @@ import (
"github.com/yetone/magpie/internal/provider"
)
// Claude Desktop and WorkBuddy read what magpie writes for them as they
// start (微雨南山 and stones on Discord, 10-24: a provider added showed up
// there only after a restart). Claude Desktop asks the gateway for its
// models once, at start. WorkBuddy 5.6's app.asar watches models.json only
// Claude Desktop, WorkBuddy and OpenMausBot read what magpie writes for
// them as they start (微雨南山 and stones on Discord, 10-24: a provider
// added showed up there only after a restart; maxleebeta, 11-08: a model
// picked for OpenMausBot wasn't in its search). Claude Desktop asks the
// gateway for its models once, at start. WorkBuddy 5.6's app.asar watches models.json only
// when the file was there at start, and the watch is on the file itself,
// so a rewrite by rename leaves it watching the old one. While such an app
// runs on what it read before magpie's last change, its Agents row offers
@@ -43,13 +44,15 @@ var claudeDesktopApp = desktopApp{id: "com.anthropic.claudefordesktop", names: [
// restartApps are the agents whose desktop app the Agents row restarts.
// macOS: Claude.app, WorkBuddy.app and WorkBuddy AI.app (both run an
// executable named Electron). Windows: Claude Desktop is claude.exe, from
// Squirrel's %LOCALAPPDATA%\AnthropicClaude (a claude.exe stub beside
// app-<version>\claude.exe) or its MSIX (desktopdir's Claude_… and
// AnthropicPBC.Claude_…), never Claude Code's claude.exe elsewhere;
// executable named Electron) and OpenMausBot.app. Windows: Claude
// Desktop is claude.exe, from Squirrel's %LOCALAPPDATA%\AnthropicClaude
// (a claude.exe stub beside app-<version>\claude.exe) or its MSIX
// (desktopdir's Claude_… and AnthropicPBC.Claude_…), never Claude
// Code's claude.exe elsewhere;
// WorkBuddy is C:\Program Files\WorkBuddy\WorkBuddy.exe (5.6.2, seen on
// the Windows box). WorkBuddy AI's Windows build wasn't to hand, so it has
// no Restart there. None of them ships a Linux app.
// no Restart there. Only OpenMausBot ships a Linux app; magpie doesn't
// restart it there.
var restartApps = map[string]restartable{
"claude-desktop": {mac: claudeDesktopApp, winExe: "claude.exe", win: func(image string) bool {
return winBase(image, "claude.exe") && (winHas(image, `\AnthropicClaude\`) || winHas(image, `\WindowsApps\Claude_`) || winHas(image, `\WindowsApps\AnthropicPBC.Claude_`))
@@ -58,6 +61,12 @@ var restartApps = map[string]restartable{
return winBase(image, "WorkBuddy.exe") && !winHas(image, `WorkBuddy AI`) && !winHas(image, `WorkBuddy-AI`)
}},
"workbuddy-ai": {mac: workbuddyAIApp},
// OpenMausBot reads its engines, magpie's models among them, once at
// start (openmausbot.go); its Windows build is electron-builder's
// per-user NSIS, OpenMausBot.exe under Programs\openmausbot
"openmausbot": {mac: ombApp, winExe: "OpenMausBot.exe", win: func(image string) bool {
return winBase(image, "OpenMausBot.exe")
}},
}
func winBase(image, name string) bool {
@@ -307,6 +316,7 @@ func (a *Agent) AppBehind() *AppRun {
// at start, and that part. Claude Desktop: deploymentMode, the profile
// applied and magpie's profile (or the user's for magpie's gateway), with the models the gateway lists it.
// WorkBuddy: magpie's models in its models.json (workbuddyPart).
// OpenMausBot: magpie's engine in its config.json (ombPart).
func (a *Agent) appReads() (files []string, reads func() string) {
switch a.ID {
case "claude-desktop":
@@ -351,6 +361,8 @@ func (a *Agent) appReads() (files []string, reads func() string) {
}
case "workbuddy", "workbuddy-ai":
return []string{a.Path}, func() string { return workbuddyPart(a.Path) }
case "openmausbot":
return []string{a.Path}, func() string { return ombPart(a.Path) }
}
return nil, nil
}
+2
View File
@@ -310,6 +310,8 @@ func TestRestartAppsOnWindows(t *testing.T) {
{"workbuddy", `C:\Program Files\WorkBuddy\WorkBuddy.exe`, true},
{"workbuddy", `C:\Program Files\WorkBuddy AI\WorkBuddy.exe`, false},
{"workbuddy", `C:\Program Files\WorkBuddy\resources\cli\codebuddy.exe`, false},
{"openmausbot", `C:\Users\u\AppData\Local\Programs\openmausbot\OpenMausBot.exe`, true},
{"openmausbot", `C:\Users\u\AppData\Local\Programs\openmausbot\resources\app.asar.unpacked\node_modules\@anthropic-ai\claude-code\bin\claude.exe`, false},
}
for _, c := range cases {
if got := restartApps[c.id].win(c.image); got != c.want {
+92 -1
View File
@@ -35,19 +35,25 @@ package agent
// engines, as it holds it, when the user changes one in its Settings
// (routes/instances.ts: replaceInstances). So a change is refused while it
// runs, where magpie can tell; a sync writes anyway, as one OpenMausBot
// writes over is written again by the next.
// writes over is written again by the next, or within half a minute by
// KeepOpenMausBotListed. One running on an older list than the file's
// offers a Restart on its Agents row (apprestart.go), which reads it.
import (
"context"
"encoding/json"
"errors"
"log"
"os"
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"time"
"github.com/yetone/magpie/internal/appdir"
"github.com/yetone/magpie/internal/beat"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/provider"
@@ -318,6 +324,91 @@ func ombMerged(path, dir, gw string) any {
return mergeTheirs(have, w, []string{"environment"})
}
// ombSaved is the models magpie's engine at path lists in OpenMausBot's
// picker, as the file has them.
func ombSaved(path string) []string {
raw, _ := edit.GetJSON(path, ombInstance+".config.endpointModels")
var have []string
json.Unmarshal([]byte(raw), &have)
return have
}
// ombPart is what OpenMausBot reads of magpie's engine at path when it
// starts, for a Restart while it runs on an older one (AppBehind): the
// gateway, the model first picked and the models listed, not the key.
func ombPart(path string) string {
url, _ := edit.GetJSON(path, ombInstance+".environment.ANTHROPIC_BASE_URL")
model, _ := edit.GetJSON(path, ombInstance+".environment.ANTHROPIC_MODEL")
return url + "\n" + model + "\n" + strings.Join(ombSaved(path), "\n")
}
// ombListStale says magpie's engine at path lists other models than magpie
// does for OpenMausBot. A sync rewrites the list when magpie's changes, but
// OpenMausBot writes back the one it held since it started when the user
// changes an engine in it, and an edit of magpie's engine there keeps the
// model picked alone (claude-endpoints.ts's updateClaudeEndpoint): either
// leaves the picker, and its search, without models picked in magpie
// (maxleebeta, 11-08: Antigravity's weren't found), and no catalog change
// follows to write the list again.
//
// It is not a Check drift: that reads as unwired, and a port change
// rewires only agents without one.
func ombListStale(path string) bool {
want := ombModels()
if len(want) == 0 {
return false
}
have := ombSaved(path)
if len(have) != len(want) {
return true
}
for _, m := range want {
if !slices.Contains(have, m) {
return true
}
}
return false
}
// ombKeepEvery is how often KeepOpenMausBotListed looks.
const ombKeepEvery = 30 * time.Second
// KeepOpenMausBotListed writes magpie's models into OpenMausBot's engine
// again, while the gateway serves, when OpenMausBot wrote a list over
// them (ombListStale). The model picked in it stays.
func KeepOpenMausBotListed(ctx context.Context) { keepOMBListed(ctx, ombKeepEvery) }
// keepOMBListed is KeepOpenMausBotListed at an interval the tests can
// shorten; a failure is said once, not every round.
func keepOMBListed(ctx context.Context, every time.Duration) {
said := ""
for {
msg := ""
if err := ombListedOnce(); err != nil {
msg = err.Error()
}
if msg != "" && msg != said {
log.Print("OpenMausBot: ", msg)
}
said = msg
select {
case <-ctx.Done():
return
case <-beat.Next(every):
}
}
}
// ombListedOnce is one round of KeepOpenMausBotListed.
func ombListedOnce() error {
home, _ := homes()
a := openMausBot(home)
if !a.Wired() || !ombListStale(a.Path) {
return nil
}
return synced(a.Sync)
}
// ombWire writes magpie's engine into OpenMausBot's config.json at path,
// with the default fleet beside it when the file saves no engines.
func ombWire(path, dir, gw string) error {
+222
View File
@@ -2,6 +2,7 @@ package agent
import (
"bytes"
"context"
"encoding/json"
"os"
"path/filepath"
@@ -9,7 +10,9 @@ import (
"slices"
"strings"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/provider"
@@ -391,3 +394,222 @@ func TestOpenMausBotProcess(t *testing.T) {
}
}
}
// ombAntigravity signs magpie in to Antigravity with the reporter's
// models (maxleebeta on Discord, 11-08): Gemini 3.8 Flash's two efforts,
// one 1M family model, and two Claude models.
func ombAntigravity(t *testing.T) {
t.Helper()
cfg := filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "magpie")
writeFile(t, filepath.Join(cfg, "logins.json"), `[{"agent":"antigravity","user":"u@example.com","seen":"2026-09-25T08:45:36Z","on":true,"auth":{"refresh_token":"r","access_token":"a","expiry_date":99999999999999}}]`)
if err := catalog.SaveLive("antigravity", "", []catalog.Model{
{ID: "gemini-3.8-flash-high", Name: "Gemini 3.8 Flash (High)", Images: true, Context: 1048576},
{ID: "gemini-3.8-flash-low", Name: "Gemini 3.8 Flash (Low)", Images: true, Context: 1048576},
{ID: "claude-sonnet-4-6-thinking", Name: "Claude Sonnet 4.6 (Thinking)", Images: true},
{ID: "claude-opus-4-6-thinking", Name: "Claude Opus 4.6 (Thinking)", Images: true},
}); err != nil {
t.Fatal(err)
}
}
// ombSaves writes magpie's engine at path as OpenMausBot saves its fleet,
// JSON.stringify(cfg, null, 2), with engine in magpie's place.
func ombSaves(t *testing.T, path string, engine json.RawMessage) {
t.Helper()
var file map[string]any
if err := json.Unmarshal([]byte(readFile(path)), &file); err != nil {
t.Fatal(err)
}
var e any
if err := json.Unmarshal(engine, &e); err != nil {
t.Fatal(err)
}
file["instances"].(map[string]any)[magpieID] = e
b, _ := json.MarshalIndent(file, "", " ")
writeFile(t, path, string(b))
}
// The models picked in magpie stay in OpenMausBot's picker, and so in its
// search (maxleebeta on Discord, 11-08: "3.8" found nothing). OpenMausBot
// writes back the engine it read at start when an engine is changed in
// its Settings, and an edit of magpie's engine there keeps only the model
// picked; no catalog change follows, so before KeepOpenMausBotListed
// nothing wrote magpie's list again.
func TestOpenMausBotListWrittenAgain(t *testing.T) {
home := syncHome(t)
stashHome(t)
ombRelay(t)
a := openMausBot(home)
path := a.Path
// the round reads $HOME, stashHome's now: point it at this file
t.Setenv("OMB_DATA_DIR", filepath.Dir(path))
writeFile(t, path, `{"instances":{"claude":{"driver":"claudeAgent"}}}`)
if err := a.Field("provider").Set(magpieID); err != nil {
t.Fatal(err)
}
// the engine as OpenMausBot read it when it started, the user's model
// picked in it
var held map[string]any
json.Unmarshal(ombRead(t, path)[magpieID], &held)
held["environment"].(map[string]any)["ANTHROPIC_MODEL"] = "relay/gpt-5.5"
heldRaw, _ := json.Marshal(held)
ombAntigravity(t)
if err := a.Sync(); err != nil {
t.Fatal(err)
}
const gemini = "antigravity/gemini-3.8-flash[1m]"
if !slices.Contains(ombSaved(path), gemini) {
t.Fatalf("magpie's sync didn't list Antigravity's models: %q", ombSaved(path))
}
full := ombSaved(path)
for _, c := range []struct {
name string
engine json.RawMessage
}{
// the fleet it held, written back over magpie's list
{"written back", heldRaw},
// Edit endpoint in its Settings: endpointModels is the model alone
{"edited there", func() json.RawMessage {
var e map[string]any
json.Unmarshal(heldRaw, &e)
e["config"].(map[string]any)["endpointModels"] = []string{"relay/gpt-5.5"}
b, _ := json.Marshal(e)
return b
}()},
} {
t.Run(c.name, func(t *testing.T) {
ombSaves(t, path, c.engine)
if slices.Contains(ombSaved(path), gemini) {
t.Fatal("the stale engine lists Gemini 3.8 Flash; the test proves nothing")
}
if err := ombListedOnce(); err != nil {
t.Fatal(err)
}
if got := ombSaved(path); !slices.Equal(got, full) {
t.Fatalf("listed %q, want magpie's %q", got, full)
}
e := ombFormat(t, ombRead(t, path)[magpieID])
if e.Environment["ANTHROPIC_MODEL"] != "relay/gpt-5.5" {
t.Fatalf("the model picked in OpenMausBot was replaced: %q", e.Environment["ANTHROPIC_MODEL"])
}
if _, ok := ombRead(t, path)["claude"]; !ok {
t.Fatal("OpenMausBot's other engine is gone")
}
})
}
// a round with the list as magpie's writes nothing
old := time.Now().Add(-time.Hour).Truncate(time.Second)
os.Chtimes(path, old, old)
before := readFile(path)
if err := ombListedOnce(); err != nil {
t.Fatal(err)
}
if st, _ := os.Stat(path); !st.ModTime().Equal(old) || readFile(path) != before {
t.Fatal("a round rewrote a list already magpie's")
}
// while magpie serves, the loop writes it again
ombSaves(t, path, heldRaw)
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() { keepOMBListed(ctx, 10*time.Millisecond); close(done) }()
for end := time.Now().Add(10 * time.Second); !slices.Equal(ombSaved(path), full); time.Sleep(5 * time.Millisecond) {
if time.Now().After(end) {
cancel()
<-done
t.Fatalf("not written again while serving: %q", ombSaved(path))
}
}
cancel()
<-done
// off in magpie: OpenMausBot's file is left as it is
if err := a.Field("provider").Set(""); err != nil {
t.Fatal(err)
}
after := readFile(path)
if err := ombListedOnce(); err != nil {
t.Fatal(err)
}
if readFile(path) != after {
t.Fatalf("a round wrote an engine magpie was taken out of:\n%s", readFile(path))
}
}
// OpenMausBot running on the list it read before magpie last changed its
// engine offers the row's Restart, and its own save of the same engine
// after it started doesn't.
func TestOpenMausBotRestartOnMac(t *testing.T) {
home := restartSandbox(t)
ombRelay(t)
apps := filepath.Join(home, "Applications")
bundle := macApp(t, apps, "OpenMausBot.app", "com.openmausbot.app", "OpenMausBot")
restartOnMac = true
appFolders = func() []string { return []string{apps} }
alive, up := false, time.Hour
running = func(pat string) []runningProc {
ps := []runningProc{
{up, bundle + "/Contents/MacOS/OpenMausBot"},
{up, bundle + "/Contents/Frameworks/OpenMausBot Helper (Renderer).app/Contents/MacOS/OpenMausBot Helper (Renderer) --type=renderer"},
// its server, a script on the app's own executable
{0, bundle + "/Contents/MacOS/OpenMausBot " + bundle + "/Contents/Resources/server/index.js"},
}
var out []runningProc
for _, p := range ps {
if alive && regexp.MustCompile(pat).MatchString(p.cmd) {
out = append(out, p)
}
}
return out
}
a := openMausBot(home)
writeFile(t, a.Path, `{"instances":{"claude":{"driver":"claudeAgent"}}}`)
if err := a.Field("provider").Set(magpieID); err != nil {
t.Fatal(err)
}
wrote := time.Now().Add(-30 * time.Minute)
os.Chtimes(a.Path, wrote, wrote)
alive = true
if a.AppBehind() == nil {
t.Fatal("no Restart for OpenMausBot started an hour before magpie wrote its engine")
}
var did []string
appQuit = func(_ context.Context, b string) error { did = append(did, "quit "+b); alive = false; return nil }
appOpen = func(_ context.Context, b string) error { did = append(did, "open "+b); alive, up = true, 0; return nil }
if err := a.RestartApp(context.Background()); err != nil {
t.Fatal(err)
}
if want := []string{"quit " + bundle, "open " + bundle}; !slices.Equal(did, want) {
t.Fatalf("did %q, want %q", did, want)
}
if a.AppBehind() != nil {
t.Fatal("still offered after the restart")
}
// it saves its fleet a few seconds after it started: no change of magpie's
up = 10 * time.Second
ombSaves(t, a.Path, ombRead(t, a.Path)[magpieID])
at := time.Now().Add(-6 * time.Second)
os.Chtimes(a.Path, at, at)
if got := a.AppBehind(); got != nil {
t.Fatalf("OpenMausBot's own save after its start read as magpie's change: behind since %v", got.Since)
}
// a model magpie adds is one it hasn't read
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6", "gpt-5.5", "glm-5"}}); err != nil {
t.Fatal(err)
}
if err := a.Sync(); err != nil {
t.Fatal(err)
}
if !slices.Contains(ombSaved(a.Path), "relay/glm-5") {
t.Fatalf("not synced: %q", ombSaved(a.Path))
}
if a.AppBehind() == nil {
t.Fatal("no Restart after magpie added a model OpenMausBot started without")
}
}
+3
View File
@@ -447,6 +447,9 @@ func run(args []string) error {
// and Cursor Private Inference's variables, which the Mac's launchd
// forgets at a restart, for the gateway's address now
gateway.WhileServing = append(gateway.WhileServing, agent.KeepCursorLocalEnv)
// and magpie's models in OpenMausBot's engine, which OpenMausBot
// writes back as it held them when an engine is changed in it
gateway.WhileServing = append(gateway.WhileServing, agent.KeepOpenMausBotListed)
// and Claude Science's daemon, which a restart of the computer ends,
// started on the gateway again while it is connected
gateway.WhileServing = append(gateway.WhileServing, agent.KeepClaudeScience)