Commit Graph
6530 Commits
Author SHA1 Message Date
yetone ea3d1c62e7 gateway, codexcat: Codex's image detail "original" goes as "high" to a relay's Responses API, and only DeepSeek's own API is told it takes it (qiu_eth)
qiu_eth on Discord, v0.1.2885: the Codex App on
opencode-go/deepseek-v4.1-flash got 400 "invalid image detail" / "this
feature is not yet supported by atlas" for every screenshot.

Where the values come from:
- input_modalities ["text","image"]: models.dev lists
  deepseek-v4.1-flash under opencode-go with input text and image, and
  841326709 (v0.1.2343) counts Go's media types as images. Go's own list
  says the same, so this stays.
- supports_image_detail_original true: codexcat set it on every model
  named deepseek-* on any provider (8acb0d3a7), copied from DeepSeek's
  own Codex setup for api.deepseek.com. A vendor rule had not been scoped
  to the vendor. Go serves this model on its Responses API (no npm in
  models.dev, so every API is open, 7c4a5d114), and Responses to
  Responses went as it came, so "original" reached Go and was refused.

The fix has two parts:
- codexcat sets supports_image_detail_original only for a model of
  DeepSeek's own provider (deepseek/…). The rest of DeepSeek's setup
  (shell_command, verbosity, summary, agents v2) still applies to every
  DeepSeek model.
- The gateway sends an input_image's detail "original" as "high" to any
  Responses API but OpenAI's (api.openai.com, chatgpt.com, Azure),
  DeepSeek's (api.deepseek.com) and a remote magpie, which decides for
  its own upstream. That covers the class: a Codex that already has the
  old catalog, a relay's GPT, and any other model whose catalog says
  original. Chat already did this (chatDetail). A body without "original"
  isn't parsed.

Checked against the class: other opencode-go models with images (Kimi,
GLM, MiniMax, Qwen) never had the flag, since it was DeepSeek-only, but
the gateway now covers them too. Nothing after v0.1.2885 had changed
this.

Run on mote (mote-run):
- go test ./internal/gateway ./internal/codexcat ./internal/catalog
  -count=1 -timeout 45m: all three ok (gateway 847s).
- gofmt -l: clean. GOOS=linux and GOOS=windows go vet of both packages: ok.

Broken by hand:
- With the gateway's rewrite turned off, TestOriginalDetailHighOnARelay
  is red: details ["original" "low" "original"], want ["high" "low"
  "high"].
- With codexcat back to `e.DetailOriginal = m.Images`,
  TestCodexCatalogDeepSeekAsDeepSeekSays is red:
  opencode-go/deepseek-v4.1-flash has supports_image_detail_original
  true.

Not tried: a real OpenCode Go request. The only Go key here answers 401
api_key_expired, so Go's 400 is the reporter's word, not reproduced,
and that Go takes "high" rests on the Responses spec, not on a run.
2026-11-05 11:45:44 +08:00
yetone 116f23c784 plugins: an agent plugin whose agent isn't on this computer says so, not "Adds Kimi to Agents" (zzZ)
zzZ (innerscw) on Discord: Kimi no longer shows in Agents, even with the
plugin installed. Nothing in magpie regressed. Kimi Code CLI (built-in
`kimi`, ~/.kimi-code) is found on main: installed with Kimi's own
install.sh in a sandbox HOME on mote, it is listed. The plugin is
@magpie-community/agent-kimi-desktop. Its agent's folder,
~/.config/magpie-kimi, is made by its adapter only once Kimi desktop's
Work runtime has written its config.json (bootstrap() in adapter.mjs).
Until then Detected() is false, so Agents lists no row for it. All the
while, the Plugins page said "Adds Kimi to Agents".

/api/plugins's agent now has missing, looks (where magpie looks, ~ for
home) and notice (the plugin's own notice) when the agent isn't found.
The row's line says "Kimi isn't in Agents: magpie doesn't find it in
~/.config/magpie-kimi", followed by the plugin's notice ("请先打开 Kimi…").
It wraps, in muted colour, since it is not a failure. In zh, zh-TW, ja
and de as well. A found agent's row is unchanged, as are fixtures with
no `missing`.

Run on mote (mote-run):
- go test ./internal/gui -run 'TestPluginAgent|TestCoreScriptBudget|I18n|Words': ok.
- node --test plugin-agent, i18n-keys, i18n-en-no-cjk: 30 pass, Chromium
  and WebKit, en/zh/zh-TW/ja/de, at 980 and 420.
- go test ./internal/gui ./internal/agent -count=1 -timeout 45m:
  internal/agent ok; internal/gui red only in TestMainWindowCorners
  (macOS 27, #3949).
- node --test every *plugin*.test.cjs: 1126 of 1130 pass. The 4 reds are
  plugin-move-unserved's "Try again takes the models unticked", red the
  same on origin/main 47d583939 run alone on mote (#4410).
- The core script budget: 1,530,183 + this change, under 1,533,802, with
  no raise.

Broken by hand:
- With pluginAgentOf back to the old code, TestPluginAgentMissingSaysSo is
  red ("Missing:false Looks: Notice:").
- With plugins.js back to the old code, plugin-agent is red with "Adds Kimi
  to Agents" / "把 Kimi 加到 Agent 页".

Not tried: a real Kimi desktop install. It is on neither this Mac nor mote.
2026-11-05 11:45:44 +08:00
yetone 10f1e97883 search: a GLM Coding Plan searches its own models with the plan's web search MCP
young02036 on Discord asked for the GLM Coding Plan's Web Search MCP in
magpie's web search. The plan's key is given for that server, so magpie
now asks it with the provider's own key, with nothing to set up: a
Streamable HTTP session at <host>/api/mcp/web_search_prime/mcp
(open.bigmodel.cn or api.z.ai, docs.bigmodel.cn/cn/coding-plan/mcp/
search-mcp-server and docs.z.ai/devpack/mcp/search-mcp-server), the key
as a Bearer, initialize, one tools/call of webSearchPrime with
{"search_query"}, then the session's DELETE.

- provider.ZhipuCodingSearch: only a provider or key on the plan's
  /api/coding/paas/v4 (Zhipu's or Z.ai's host, or the zhipu/zai preset).
  A pay-as-you-go key isn't served by the server and never asks it.
  ZhipuSearches reads p.Keys itself, since KeysOn is counted per list and
  searchesOwn runs on every request. ZhipuSearchKeys lists the plan's
  keys, which are asked in turn.
- searchesOwn/ownSearch: the plan's own models search there first, as
  with Kimi Code and WorkBuddy, and fall to magpie's searcher and the
  search APIs when it fails. This happens only while Settings names no
  searcher (glmSearches): a searcher the user named still searches for
  every model, which is a value the user set.
- It is not offered as a searcher for other providers' models. A plan
  with the Responses base (/api/v1) already searches natively there
  (searchHosts, #660), and making it a no-model service would change the
  searcher those users have now.
- The reply's text is read as a list of results, a list in a JSON
  string, or a list under search_result/results/items/data. isError, or
  words with no results, is an error with the key masked. The query is
  masked as Settings > Privacy says (maskedQuery). Each ask is a request
  log row (logOwnSearch).
- No GUI change: the setting has no switch, the same as WorkBuddy's.
- docs/subsystems/gateway-routing.md has a section on it, and the
  searchesOwn lists there and in plugin-runtime.md name it.

Run (mote, at this tree):
- go test -count=1 ./internal/provider ./internal/settings
- go test -count=1 -run 'Search|GLM|Zhipu|Kimi|LoopGuard|Docs|Guard|WorkBuddy'
  ./internal/gateway: ok
- GOOS=linux and GOOS=windows go vet ./internal/gateway ./internal/provider:
  ok
- gofmt -l: clean

The tests use a fake server only and never reach the network:
- TestGLMCodingPlanSearchesForItsModels: Claude Code's literal WebSearch
  request to a plan's model. The fake gives an event-stream reply with
  a progress notification before the result, and a double-stringified
  result. Then a refusal, an unnamed versus a named searcher beside a
  search API, and a pay-as-you-go key.
- TestReadGLMSearch: each reply shape, and prose.
- TestZhipuCodingSearchAddress: hosts, presets, a plan key beside a
  pay-as-you-go one, a key that's off.

Broken by hand:
- With the old searchesOwn/ownSearch, TestGLMCodingPlanSearchesForItsModels
  is red: the model had no search, 400 "no search tool".
- With glmSearches ignoring a named searcher, the test is red at the
  named-searcher step: the MCP was asked and the named searcher wasn't.

Not tried:
- No real GLM Coding Plan key was available, so nothing was sent to the
  real open.bigmodel.cn or api.z.ai server. The docs give neither the
  tool's argument names nor its reply's shape. search_query and the
  result fields come from Zhipu's Web Search API and a third-party npm
  wrapper (web-search-zaimcp 0.1.2). If the real reply differs, a search
  falls to magpie's other searcher or the search APIs and says why.
- The plan's MCP quota, and how a spent quota is worded.
- A GUI hint in Settings > Web search.
2026-11-05 11:44:31 +08:00
yetone 2260390a01 gateway: a Gemini thought signature goes back only to the provider that gave it
mimi001234 on Discord: Pi (openai-completions) on auto/gemini-4-argon, a
group of google-vertex and google-aistudio-paid. Vertex AI served turns
1 to 14 and signed its calls; on turn 15 it answered 429, the group moved
to AI Studio, and magpie replayed Vertex AI's signatures from
gemini-signatures/. AI Studio answered every try with 400 "Corrupted
thought signature." A signature is the issuing backend's, and only it
takes one.

- The provider that gave a signature is noted beside it,
  gemini-signatures/<key>.by (noteSigner, written through temp and
  rename), wherever a reply is read: decoderFor (every translated path:
  Chat, Anthropic and Responses clients, plugins, search, continuations)
  and sigTidy (a Chat relay, and a Gemini client's reply relayed as it
  came, now only read, in native mode).
- Every request is fitted to its provider: ownSignatures in
  forwardTranslated, chatCallSignatures and geminiBodySignatures in
  passthrough. Another provider's signature goes as Google's documented
  skip_thought_signature_validator on a call, and not at all on text. A
  signature of no known provider (ids from before this change, a note
  that couldn't be written) goes as before.
- A 400 "Invalid/Corrupted thought signature" (signatureRefused) is asked
  again once without signatures at any upstream Gemini's signatures
  reach (signaturesReach), relayed too, not only Vertex AI translated;
  it rests no account (restAfterMarked) and lets a group go on to its
  next member (shapeRefused).

The signer is the provider id, not the account: two accounts of one
provider share signatures as before.

Run on mote (mote-run), the targeted run and vets at this change on origin/main 0e55a7593:
- go test ./internal/gateway -run 'Signature|Signer|Vertex|Gemini|Corrupted': ok
- go test -timeout 45m ./internal/gateway: ok (876s), at this change on
  bf60ea596; the only commit since, 47d583939, touches internal/library
- gofmt -l internal/: clean; go vet ./...; GOOS=linux go vet -tags nogui
  ./...; GOOS=windows go vet ./...; go build ./...: ok

Red on the old code (origin/main 0e55a7593 with the new test file):
TestSignatureGoesOnlyToItsSigner (turn 3: 400 "AI Studio: ... Corrupted
thought signature."), TestCorruptedSignatureTriedWithout and
TestCorruptedSignatureNotTheAccount (rested "backoff" 60s).
Broken by hand on the new code:
- chatCallSignatures without the foreignSignature check:
  TestSignatureGoesOnlyToItsSigner red (AI Studio asked twice: refused,
  then the retry).
- ownSignatures in forwardTranslated commented out:
  TestSignatureGoesOnlyToItsSignerTranslated red the same way.
- the passthrough retry turned off: TestCorruptedSignatureTriedWithout
  red with the 400.

Not tried: real Vertex AI and AI Studio accounts; a Gemini client's
request relayed to Vertex AI end to end (TestGeminiBodyKeepsOnlyItsOwn
covers the body and the noting only); Code Assist relays, whose replies
are not noted, so their signatures count as of no known provider.
2026-11-05 11:42:53 +08:00
yetone 47d5839397 library: sync and backup files carry the hooks
VincentChan on Discord (v0.1.3005) said part of the Library doesn't reach
his other computer through sync. Checked kind by kind what the library part
of a bundle carries: instructions (each set's text, a linked set's file text,
the agents ticked, each agent's own addition), MCP servers, skills and
subagents all go. Hooks didn't: library.Bundle had no field for them, so a
hook made on one computer never reached the other, by WebDAV/S3/GitHub sync
or a backup file.

- library.Bundle.Hooks (*[]*Hook): name, description, event, matcher,
  command, timeout, agents ticked. Collect always sets it, empty too.
  Applied.Hooks (the entries magpie wrote into each agent here) stays out:
  each computer writes them on the sync Put runs, beside the user's own
  hooks, and records its own entries, so an entry the user edited there
  stays theirs.
- Put replaces the hooks with the bundle's, so one taken out on one
  computer goes from the others. A nil list (a bundle from a magpie before
  this) keeps this computer's.
- check refuses a hook with no name, no command, or named twice. The event
  and agents are carried as they come: an event a newer magpie knows is a
  problem on the agent here, not a refused library.
- davsync: an empty list hashes as before the field, so upgrading with no
  hooks syncs nothing.
- The CLI's backup line counts hooks; the GUI's sync/export/import ticks
  say "instructions, MCP servers, skills, hooks and subagents" in every
  language.
- library.md and sync-backup.md updated, and they now name what stays
  this computer's own: projects, skill groups, CopySkills/SkillHow,
  SharedSkills, MCPHub.

Instructions: two sandbox computers through the fake DAV server carried a
named set and a change to it, a set linked to ~/.agents/AGENTS.md and a
hand edit of that file, both computers having their own text first, an
agent's own addition, and an agent installed after the first sync. All
reached the second computer's CLAUDE.md/AGENTS.md (exploration tests, not
kept). So no instructions change here; what VincentChan saw is not
reproduced yet.

Run (worktree at 0e55a7593; origin/main bf60ea596's two commits touch
none of these files):
- mote: go test -tags nogui ./internal/backup ./internal/davsync
  ./internal/cli ./internal/library ok; go vet -tags nogui for darwin,
  GOOS=linux and GOOS=windows on the four packages ok; gofmt -l clean;
  go test ./internal/gui -run 'TestCoreScriptBudget|Words|I18n|Builtins' ok
- GUI (wsl-run, Linux): i18n-keys, github-sync, s3-sync, sync-*,
  webdav-settings-refresh, library-backups-top, gui-de, gui-ja, gui-zh-tw:
  187/187

Broken by hand: with Collect not setting Hooks, Put ignoring them and the
hash not dropping an empty list (the old code), TestCarryHooks,
TestCarryOldBundleKeepsHooks, TestCarryNewerHooks,
TestBackupFileCarriesHooks, TestSyncHooks and TestNoHooksHashAsBefore
went red.

Not tried: a real WebDAV/S3/GitHub remote between two real computers;
Windows and Linux runs of the Go packages.
2026-11-05 11:29:20 +08:00
yetone bf60ea5968 routing: an earlier account's overload reads overloaded, not quota used up (danzi002)
danzi002 on Discord (v0.1.3005): a Codex request's row read "529 · 额度用尽"
(quota used up) while its detail said ChatGPT's 529
service_unavailable_error server_is_overloaded, on an account with its
allowance left. The account was not rested as spent: an overload is
failOther, rested a moment at most (vendorOverloaded). The words came
from the row. When the last account left is out of its allowance after
an earlier one failed otherwise, Codex is told the earlier failure
(Try.Earlier), and the route takes that one's status, but the row paired
that status with the last try's own fail, quota.

The route now records the kind of the failure the agent was told
(Route.Fail, from toldFail: overloaded for a 529 or a 5xx that says
overloaded, the prompt turned away, else failure's reading), at both
places serve tells an earlier try's failure: Try.Earlier, and every
account after it passed over by a middleware. The Routing page and the
panel's request rows (endWord) say that kind when it is there.
"servers overloaded" is a new word for the row only (en, zh, zh-TW, ja, de),
never a rest's Why.

Run (mote, through mote-run; rebased on origin/main 234903cb2, the
first three lines and the i18n/GUI line below run again there):
- go test -tags nogui -count=1 -run 'TestToldOverloadIsNotQuota|TestToldFailKinds|TestCodexCapacityNotLabelledUsageLimit' ./internal/gateway: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway: ok (764s, before the rebase on 234903cb2)
- gofmt -l internal/gateway: clean; go vet -tags nogui ./internal/gateway,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok
- node --test routing-told-overload (new; Chromium and WebKit, en zh
  zh-TW ja de, 1100 and 420px) and routing-went-on: 40 of 40
- node --test i18n-keys i18n-en-no-cjk routing-told-overload routing-went-on: 48 of 48
- node --test routing-*.test.cjs panel-routing*.test.cjs i18n-*.test.cjs:
  2673 of 2704. One red was mine: i18n-keys, the plugin word
  "overloaded" is also a Go string (affinity.go), so the word is now
  "servers overloaded". The other reds are in routing-levels, -many-keys,
  -order-unknown, -row-swap, -rule-drag, -rule-remove, -rules-line,
  -steady, -steps-cap and -story-shrinks: rerun alone, 26 of 124 red here,
  and 24 of 96 red on origin/main 0e55a7593 (mote at load ~25), already
  filed (#5088, #4932 and others)

Broken by hand:
- the two t.Fail = toldFail(other) updates removed:
  TestToldOverloadIsNotQuota red ("the route says the agent was told a
  "" failure, want "overloaded": its row reads 529 · quota")
- endWord back to last.fail: routing-told-overload red in every engine
  and language

Not tried: a real ChatGPT 529 overload (can't be caused on demand), so
the reporter's own path is inferred: several ChatGPT accounts, the last
out of its allowance. The middleware passed-over site has no test of its
own; it uses the same toldFail. The whole GUI suite and the full
go test ./... were not run before the push; the full suite runs after.
2026-11-05 11:13:43 +08:00
yetone 234903cb23 cli: magpie model api sets the API a model is asked on, as the editor's picker does (yew_fence_931206)
A relay with many models behind one key can now have each model's API
set from a script, not only in the provider editor's Names, prices &
levels ("API this model is asked on"):

  magpie model api <provider/model>... chat|responses|anthropic|gemini|auto
  magpie model api <provider/model>... --reset      (auto)
  magpie model api <provider/model>                 what it is asked on
  magpie model apis [<provider>]                    the settings; with a
                                                    provider, every model

It saves through provider.SetModelPrefs, the editor's Save, into
settings' modelAPIs, so a running gateway reads it on the next request
and the agents' model lists are told once. Choices are those the editor
offers (modelAPIs in app.js): the APIs the provider has a URL for, when
it has two or more; Vertex AI none. --help anywhere prints the usage. A
flag in place of a model, an unknown API, a model the provider doesn't
list, or an API it has no URL for is refused; several models are all
checked before any is written. A saved setting for a model the vendor
no longer lists can still be reset. Documented in docs/reference.md
("The API a model is asked on") and the gateway-routing page.

Run (mote, via mote-run, at this tree on 0e55a7593):
- go test -count=1 ./internal/cli/: ok (46.7s)
- TestModelAPICmd, TestModelAPIReachesTheRunningGateway: PASS. The
  second starts gateway.New().Handler() first, asks relay/mixed (chat
  completions), sets anthropic through the CLI, and the next request
  goes to /v1/messages; after --reset back to chat.
- gofmt -l: nothing; go vet, GOOS=linux go vet -tags nogui,
  GOOS=windows go vet of ./internal/cli; go build, GOOS=linux build
  -tags nogui, GOOS=windows build: ok.

Broken by hand:
- the model/api(s) cases taken out of modelCmd: both tests FAIL
  (unknown command "apis" / "api").
- each model written as it is checked instead of all checked first:
  TestModelAPICmd FAIL "a refused command wrote:
  map[relay/claude-y:anthropic relay/gpt-x:chat relay/mixed:chat]".

Not tried: a real relay account; the reporter's provider. The full
suite runs after the push.
2026-11-05 11:05:38 +08:00
yetone 0e55a75936 remote magpie: a request that goes round magpies pointing at each other stops after 8, and a remote that is this magpie lists its models once
Follows c2c991a5b (cdredfox's two magpies each the other's remote).
hanslin1666 (Discord) has the sibling: device B uses device A through
a Remote magpie provider, and S3 sync carried that provider to A too,
so A has a Remote magpie pointing at itself. Sync carries every
provider (backup.Collect, provider.Mirror), a Remote magpie included.

Two holes c2c991a5b left:
- A remote that is this magpie lists this magpie's own models through
  this one alone ([self]); c2c991a5b kept any via of only self, so
  rem/own/m1, rem/rem/own/m1, ... still grew a level a fetch until
  MaxVia. A via naming this magpie is now taken only when it is
  exactly [self]: the remote's own models, once (what the gateway's
  in-process remote tests need, and what hanslin1666 sees today).
- Nothing stopped a request at request time: a list fetched from a
  magpie older than magpie_via, or one cached before the update,
  could still route round. Each request magpie passes to a Remote
  magpie now says how many magpies it went through (X-Magpie-Hops:
  the count it came with + 1, 1 for an agent's own); one that arrives
  having passed catalog.MaxVia (8) is answered 508 Loop Detected with
  what to turn off, before any vendor or remote is asked. The count is
  read only from a magpie's request (its User-Agent, which needs the
  key anyway), and taken off every request as it arrives, so no vendor
  is sent it. It goes on every path that already passes the caller on
  (passOnCaller: chat, decide, draw, embeddings, video).

Run (mote, at this tree on c2c991a5b):
- go test -timeout 45m ./internal/catalog ./internal/provider
  ./internal/gateway -count=1 on Linux (wsl-run, magpie-desktop):
  catalog ok, gateway ok (590s), provider red only in
  TestClaudeAccountServesModelsListedSinceItsFetch, #3174, which this
  doesn't touch.
- go vet, GOOS=linux and GOOS=windows go vet of catalog and gateway
  (mote): ok. gofmt -l clean.
- The full suite at c2c991a5b (mote, -timeout 45m ./...): 86 packages
  ok, internal/gui red only in TestMainWindowCorners (#3949).

Broken by hand:
- the via rule back to c2c991a5b's: TestFetchLeavesOutWhatCameFromHere
  red (rem/own/m2 through [self self] taken).
- no hops set in passOnCaller and no check in withCaller:
  TestRemoteMagpieRequestLoopStops red (the remote told [ ] passes,
  200 not 508 at 8, the vendor asked).

Not tried:
- hanslin1666's or cdredfox's own machines.
- Paths to a remote that don't go through passOnCaller (the Codex
  socket and native passthrough) don't count hops; a loop through
  them is still cut by the lists.
- Hiding a Remote magpie that is this magpie, or keeping it out of
  sync on the machine it names: not done here (a third machine that
  syncs may want it); it now costs one extra local pass per request
  to it, and its models show twice.
2026-11-05 10:52:06 +08:00
yetone 1fd02d33ce agentplug: an agent plugin can pick the model its agent starts on in a second file (str_, PiG)
str_ on Discord (#help, v0.1.3005): PiG's row on the Agents page only
switched the model list on, where Pi's picks the model it starts on.
PiG, like Pi, keeps its providers in ~/.pig/agent/models.json and the
model a session starts on in settings.json (defaultProvider,
defaultModel; PiG's docs/site/docs/settings.md, startup_model.go). An
agent plugin could name a model key only in the one file connect
writes, so agent-pig 0.1.0 had to be connect-only.

An agent's descriptor can now say `startup: {config, format, model,
keys}`: the other file, the key that holds the model (the id without
magpie's prefix) and keys written beside it. With it the row gets a
model field as a built-in's does. Picking one of magpie's writes
connect's keys into config and the model and keys into startup.config,
each key kept aside as before; a model of magpie's picked in the agent
itself still reads as magpie's; a model of the user's own picked there
while magpie's provider is listed counts as connected (Beside), not
drift, and is kept on disconnect. Sync rewrites the list and leaves the
startup model where it is. Off, or `magpie <id> default` with the plugin
gone (RestoreGone), puts both files back. startup without connect, beside
agent.model, in config's own file, or naming the model key among keys
is refused. An older magpie ignores the field, so agent-pig 0.1.1
(plugins repo) stays connect-only there. Every other agent plugin
already names its model in its own config; pig is the only
connect-only one.

Run (mote):
- go test -count=1 ./internal/agentplug/: ok
- go test -count=1 -run 'TestPlugged|TestPlugin|TestRestoreGone|TestAgent'
  ./internal/agent/: ok
- go vet, GOOS=linux and GOOS=windows go vet of both packages; gofmt -l
  clean
- the four TestPluggedStartup* tests on the old code: red (the row had
  a provider field and only listed models)
- real PiG 0.5.3 (darwin-arm64 release, SHA256SUMS checked) in a sandbox
  HOME, models.json written by agent-pig 0.1.1's own connect and
  settings.json as startup writes it, against a fake OpenAI server:
  `pig -p` sent model deepseek/flash with the gateway key. With an
  enabledModels scope that leaves it out, PiG started on the scope's
  first model (said in the plugin's README).

Broken by hand: no startRestore in Unwire (TestPluggedStartupModel and
OwnPickKept red); no Beside (OwnPickKept red, "wired false").

Not tried: the GUI and the TUI with the real row (app.js unchanged; the
row is the model field every built-in has), Windows and Linux runs of
PiG, a real magpie gateway in front of PiG, a real vendor model.
2026-11-05 10:46:46 +08:00
yetone c2c991a5b3 remote magpie: two magpies each the other's remote no longer list each other's models back without end
cdredfox (Discord) saw 100-200% CPU while magpie used a remote magpie
over Tailscale, gone with the remote off. Their providers mask anyway
and their agent asks auto/ ids, so the earlier unmasked-group lead
doesn't explain it. What does: when A and B are each other's remote,
A's /v1/models (to another magpie) lists rem/<B's models>, B fetches it
as back/rem/..., lists that back to A, and so on: one level deeper on
every 10-minute fetch, without end. Each level is another member of
the found auto/ group and another route round the two machines, masked
again on each pass. On mote, two sandbox magpies in that setup went
from A: [auto/m1 own/m1 rem/auto/m1 rem/up/m1 rem/back/own/m1] to
[... rem/back/rem/back/own/m1, rem/back/rem/auto/m1 ...] after one
more scheduled fetch, and B had back/rem/back/own/m1. A request on the
loop route (rem/back/own/m1) cost A 1.07s CPU over 10 turns against
0.69s for own/m1.

The list a magpie gives another magpie now names, as magpie_via, the
magpies each model passes through, itself last. Each process has a
random id (catalog.Self). A fetched list leaves out a model whose via
has this magpie and another one (it left here and came back), or more
than 8 magpies. A remote that is this magpie itself (via only this id,
as the in-process tests set up) is kept. A magpie older than this sends
no via, and its list is taken as before: both machines need the update.
Stamped on every list a magpie gives: models(), its deciders, and the
drawer and video lists. A routing group's via is its members'
together, so A's auto/m1 holding B's auto/m1 (which holds A's) is left
out at B, and requests no longer go A -> B -> A through groups.
What a user of A loses: B's own auto/ group of a model when it holds
A's model (it reaches A again); B's own models stay listed at A one by
one, and A's group of the model holds them. The cached list keeps Via, so a model a remote served
through others keeps its path in this magpie's list too.

Run (mote, at this tree on 6abacd46c = origin/main):
- go test -timeout 45m ./internal/catalog ./internal/provider
  ./internal/gateway -count=1: ok (catalog 0.7s, provider 120s,
  gateway 670s).
- go vet those three; GOOS=linux and GOOS=windows go vet: ok. gofmt -l
  clean.
- Two sandbox magpies (CLI, nogui build) each the other's remote:
  after two scheduled fetches (18:14, 18:24/18:25) A lists auto/m1,
  own/m1, rem/up/m1 and B auto/m1, up/m1, back/own/m1, each fetch
  taking 1 model; the old build in the same setup went 3 -> 5 models
  on B's second fetch and kept growing (rem/back/rem/back/own/m1).
- go test ./internal/gateway again after the group change: ok (715s).

Broken by hand:
- the loops check in live.go off: TestFetchLeavesOutWhatCameFromHere
  red (back/own/m1 with [self peer] and a 9-magpie model taken), and
  TestRemoteMagpieListLoopsNoMore red (the remote's back/own/m1 taken).
- models() without the magpie_via line: TestRemoteMagpieListLoopsNoMore
  red (own/m1 and rem/up/m1 listed through []).
- viaOf giving a group nil: red (auto/m1 listed through [self], not
  [peer self]).

Not tried:
- cdredfox's own two machines; it isn't confirmed yet that their remote
  also has this machine as its remote. If it doesn't, this isn't their
  cause.
- A loop through a magpie older than this one (no via: still grows
  until both are updated).
- The full suite (runs once after the push).
2026-11-05 10:26:14 +08:00
yetone 1ae48d7f4d gui: Antigravity's accounts say the app keeps its own sign-in
Greatrobbort on X (2118158946896932928): picking a preferred Antigravity
account, or smart routing, didn't change the account the Antigravity app
itself uses. It never does: magpie keeps Antigravity's tokens in its own
logins.json and serves only requests that go through it. But the editor
said "Antigravity signs in to the first", "Sign Antigravity in to this
account" and "Antigravity is now signed in as …", as it does for Claude
Code and Codex, whose own sign-in magpie does move.

Antigravity is now `own` in SUBS, so those texts say the gateway uses the
account, and with Routing on the hint adds "Only requests through magpie
use them; Antigravity itself stays signed in as it is." (zh, zh-TW, ja,
de).

Run on mote (macOS 27), at this head's tree:
- go test ./internal/gui -run Budget: ok
- accounts-own-signin (new), accounts-switch-alone, i18n-keys,
  i18n-en-no-cjk, agent-switch-accounts, panel-switch-accounts,
  routing-accounts-narrow, Chromium and WebKit: 106 pass, 0 fail
- the 19 other GUI files naming antigravity: 247 pass, 4 fail, all in
  usage-fold, which fails the same 4 alone at origin/main 6abacd46c
  (#3415, commented)
Broken by hand: without `own` on Antigravity, accounts-own-signin is
red 10 of 10 (Chromium).
Not tried: the real app with a real Antigravity account.
2026-11-05 10:23:24 +08:00
yetone 6abacd46c3 update: an Intel magpie under Rosetta updates to the Apple silicon build
cdredfox on Discord saw magpie at 150% of a core. Their goroutine dump
shows AstrLink Guard running in Go (guard.geluRow) in a darwin/amd64
build on an 8-core Mac. That is the Intel build under Rosetta: no
CoreML, and Go's kernels are translated, several times slower than
Apple silicon's build. AppAsset and BinaryAsset named runtime.GOARCH,
so every update fetched the Intel build again, with no way off it.

- internal/rosetta: Translated (sysctl.proc_translated), moved out of
  pii so the updater reads the same thing. pii's translated is now that
  var; its tests still replace it.
- update: arch() is arm64 for darwin/amd64 under Rosetta. AppAsset and
  BinaryAsset (the darwin CLI) use it. goos/goarch/translated are vars
  that tests set.
  Checked before switching: Stage downloads the zip, ditto unpacks it,
  sameSigner wants the same team, and Install renames it over the
  bundle. Nothing there reads the architecture, and the CLI's
  InstallBinary is a rename too. An arm64 build runs natively on every
  Mac that runs Rosetta.
- pii: Status.Rosetta, set on AstrLink Guard's Now() only. Privacy
  Filter's pf-serve is already Apple silicon's there (target).
- GUI: Settings > Privacy's local model line, while AstrLink Guard runs
  under Rosetta, says "On, slowly under Rosetta: the next update
  installs magpie for Apple silicon" in place of "On, on the CPU". It
  is the same one sub-line, with no new element. en/zh/zh-TW/ja/de.

Not done, as decided: skipping tool outputs for the model, or capping
its cores.

Run (on mote unless named):
- go test -count=1 ./internal/update ./internal/rosetta ./internal/pii:
  ok. On WSL magpie-desktop: the same three, plus go vet of them, ok.
  On Windows (xiaomi-gpu): -run "Rosetta|Asset|GuardNow" on update and
  pii, ok.
- go vet ./... (darwin) and CGO_ENABLED=0 GOOS=windows go vet ./...: ok.
  A Linux cross vet needs cgo for Wails, and WSL has no gtk4, so Linux
  vet covered the changed packages only. gofmt -l: clean.
- node --test privacy-model, i18n-keys, i18n-en-no-cjk (chromium +
  webkit, 5 languages, 1100/640px): 91 of 92. The new rosetta case
  passed in every engine, language and width. The one red is "a
  download is cancelled" (chromium). It passes alone, 1/1 at origin/main
  8eb219354 and 2/2 with this change. Filed as #5292 (wheelTo/viewOf
  return "" after a reload).
- go test -run "Budget|I18n|Lang" ./internal/gui: ok. Core scripts are
  1,530,017, under 1,533,802; no raise.

Broken by hand:
- arch() always the build's: TestRosettaUpdatesToAppleSilicon red (4
  cases), and TestRosettaStagesAppleSiliconsApp red, with Intel's
  2.0-amd64 app installed.
- No Rosetta in guardModel.Now(): TestGuardNowSaysRosetta red.
- The app.js line off: privacy-model's rosetta case red ("On, on the
  CPU").

Not tried:
- A real Rosetta process. mote has no Rosetta (no oahd); an x86_64 test
  binary built there didn't start. The translated check is the sysctl
  pii has used since the pf-serve fix, but this commit never saw it
  return 1.
- A real update from an Intel release to an arm64 one. The stage test
  swaps ad-hoc signed fake bundles through the real
  Stage/sameSigner/Install.
2026-11-05 08:25:53 +08:00
yetone 681a472cab agent: a Codex thread started during the takeover comes back to OpenAI once it is quiet, not hours later (nb5p on Discord)
nb5p on Discord (v0.1.3001, Codex app): after Send greyed out, Retry in
Codex did nothing. The model picker and Send spun, the same dialog came
back a few seconds later, and the model field read "model unavailable".

With the ChatGPT account Codex is signed in to used up, magpie makes
itself Codex's provider (codex.out), so a turn sent then starts a thread
saved with model_provider "magpie". When the account has room again,
Sync puts Codex back on OpenAI, and its deferred bringBack moves magpie's
threads to OpenAI. It skips a thread written to in the last minute,
which is the one the user was in, and leaves it "for the next Sync".
Nothing schedules one, though: Sync runs on a catalog change, which can
be hours away. The app then can't resume that thread on the provider it
is now on ("This chat uses magpie, but your current provider is
openai", the string still in the Codex the app bundles), so each Retry
failed the same way.

bringBack now asks whether a thread is still on magpie because it was
being written to (sessions.CodexThreadsBusyOn: the state databases' rows
on magpie whose rollout changed within ActiveWindow). If one is, it asks
for one more Sync after ActiveWindow+5s. Only one wait is pending at a
time.

docs/subsystems/agent-wiring.md says so beside bringBack.

Test: TestCodexTakeoverThreadComesBackOnceQuiet. The takeover is on, and
a thread on magpie is written to now. The account comes back, and the
thread stays on magpie while it is written to. A later Sync is asked
for, and that Sync, with the thread quiet, moves it to openai. No other
Sync is asked for after that.

Broken by hand: with the bringBack hook turned off (`if false && ...`),
it fails with "no later Sync asked for" (5.3s). Restored, it passes.

Run on mote at this tree (base 8eb219354, origin/main fetched, nothing
new):
- the new test with -race -count=3: ok;
- go vet ./internal/agent ./internal/sessions for darwin, for linux
  -tags nogui and for windows: clean;
- go build ./...: ok;
- gofmt -l: clean;
- go test ./internal/agent ./internal/sessions: ok.
The full suite at the pushed head is in the report.

Not tried: the real Codex app at the moment an account runs out and
comes back. The resume failure is read from the Codex source and the
string in the app's bundled codex, not seen live. A thread the app keeps
writing to for minutes on end waits one more round each time; that case
was not timed. Nor was a thread the app keeps open with its writer lock
held after it goes quiet: MoveCodexThreads refuses that one too, and
CodexThreadsBusyOn looks at the time only, so no further Sync is asked
for it.
2026-11-05 08:23:05 +08:00
yetone 8eb2193540 agent: Codex's own models are drawn by their names in its picker, as every other list's are (nb5p on Discord)
nb5p's screenshot of the Agents page: Codex's model picker drew each of
Codex's own models by its slug (gpt-6-astra · 经 magpie · GPT-6-Astra in
grey). Every other list in magpie, magpie's catalog included, draws the
model's name. options() gives a model its name only as the grey note;
Codex's own were the one list built straight from it, and on magpie API or
with magpie Codex's provider the label was set to the slug outright.

codexNamed gives each of Codex's own models its name (the display_name
Codex lists it by) as the label, for the picker of this machine's Codex
and of a WSL distro's (wsl.go, both of its lists), and the magpie-API
branch no longer writes the slug over it. The value is the slug, as
before: what Codex is set to and sends is unchanged (codex/gpt-… on
magpie API, gpt-… otherwise). The Codex app's own picker was not the
cause: magpie's catalog file already gives it the names.

Test: TestCodexOwnModelsNamedInPicker (beside the ChatGPT sign-in, and
magpie the provider) checks each own model is labelled by its name and
valued by its slug. TestCodexAPIKeepsMagpieOnOwnModel and
TestCodexProviderOwnModelSaysItsPath now check the name too.

Run on mote at this tree: go test ./internal/agent ok (176s); go vet for
darwin, linux -tags nogui and windows on internal/agent; go build ./...;
gofmt -l clean.
Broken by hand: codexNamed left without the label, all three tests red
("gpt-6-astra is offered as "" ... want it named "GPT-6-Astra"").
Not tried: the GUI suite (no GUI file changed; the picker already draws
a label when there is one), a real Codex in WSL.
2026-11-05 08:14:57 +08:00
yetone 3d0d790606 codex: the Codex app left on an account that runs out is restarted onto the one Codex is signed in to (nb5p on Discord)
nb5p has two ChatGPT accounts in magpie, B first. The Codex app showed A,
and once A ran out Send was grey for every model, magpie's and another
provider's too.

Cause: magpie's switch back to the first account (or to the account
Codex is kept signed in to) leaves the Codex app's app-server running
unless "Restart the Codex app to follow" is on. The app-server keeps the
account it started on (CodexAppStale), so the app stayed on A while
auth.json said B. magpie read only B, which had room, so nothing moved,
magpie never took over, and the app-server was never restarted: the app
greyed Send on A's allowed false for good.

Fix: on each full look of KeepOnAnAccountWithRoom,
restartCodexAppLeftOnSpent reads the account the app is left on, and
once that is held (codexHeld) marks a spent switch (codexAppSwitched
true), which codexAppStep restarts past the RestartApp tick, as a switch
off a used-up account already does. Once per app-server left.

Run (mote, at this tree):
- go test ./internal/provider -count=1: ok
- TestCodexAppLeftOnASpentAccountIsRestarted: user switches to A, magpie
  switches back to B and leaves the app running, A still has room
  (nothing ended), A runs out with B's room (app-server 7 ended), next
  look (not ended again).
Broken by hand:
- codexAppSwitched(true, false) commented out: red, "ended [], want the
  app-server left on the used-up account".
- the once-per-app-server check off: red, "restarted again: [7]".
Not tried: the real Codex app on a real account running out; the call
in KeepOnAnAccountWithRoom's loop is covered by reading, not by a test.
2026-11-05 07:51:09 +08:00
yetone dabb5722f8 claude: Claude Code routed through magpie stays signed in where the user put it when that account is spent
oreoft on Discord has two Claude accounts: A, the main one, whose sign-in
carries their claude.ai connectors (MCP), and B, a quota account. A's
allowance was used up. They set A first and signed in, B second, and
"跑着跑着" B came first again and became Claude Code's sign-in, and the
MCP broke. They set it back more than ten times.

Cause: the used-up switch (#208). KeepOnAnAccountWithRoom looks at
Claude Code's sign-in every minute or five; A is spent, so NextLogin
returns B and SwitchWhenSpent rewrites Claude Code's live credential to
B. The GUI's list puts the account in use first (loginsInOrder), so B
"moves to first". Each time the user signed A in again, the next look
moved it back.

Decision: when Claude Code's settings send its requests to magpie's
gateway (ANTHROPIC_BASE_URL is the gateway, whether it signs in with
magpie's key or keeps its claude.ai sign-in), NextLogin never moves its
sign-in off a spent account. The gateway already routes every request
to an account with room (it skips spent ones on its own), so moving the
sign-in served nothing and only took away what the user signed in as.
This keeps the user's choice and needs no setting.

Still switching, unchanged:
- not routed (Claude Code asks Anthropic as its own sign-in): the switch
  is the only thing that keeps it working (#208);
- "Only switch Claude Code's sign-in" (SwitchOnly): the gateway serves
  none of those accounts, so switching is all magpie is asked to do;
- the move back to the first account / the kept account
  (returnsToFirst, KeepLoginAs), which go toward the user's choice;
- `magpie accounts switch claude next` and the GUI's own switch.
- Codex is left as it is: the Codex app stops sending once its own
  account is out, so it needs the sign-in moved.

ClaudeThroughMagpie is a provider hook the agent package sets
(claudeRouted, the same check claudeIn's "routed" uses), like
CodexAppRoute.

Run (all on mote via mote-run):
- new TestClaudeRoutedThroughMagpieKeepsItsSignIn (sandbox HOME: A
  spent, B with room; routed: three looks, no switch, credential still
  A's; SwitchOnly: switches to B; not routed: switches to B) with
  TestClaudeSwitchedWhenSpent, TestClaudeSwitchOnly*, TestKeepLoginAs*,
  TestNextLogin*, TestClaudeSwitch*, TestNextInOrder, TestCodexDrain*:
  ok. New TestClaudeThroughMagpieReadsItsSettings (agent): ok.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build; GOOS=linux go build -tags nogui;
  GOOS=windows go build: ok.
Broken by hand: with the NextLogin gate turned off ("if false && ..."),
TestClaudeRoutedThroughMagpieKeepsItsSignIn FAILs at line 80, "Claude
Code routed through magpie was signed in to b@example.com".
Not tried: real Claude accounts and a real Claude Code with claude.ai
connectors; Windows and Linux boxes. Full suite runs after the push.
A sign-in already moved to B stays on B until the user switches back
once.
2026-11-05 06:43:51 +08:00
yetone 4164edce60 gui: a one-tone dark or light logo is drawn in the text colour, so Open Design's shows in dark mode (chen2652)
chen2652 (Discord #help) reported that Open Design's icon is almost invisible
in dark mode, with no browser dark-mode extension on. The icon is the plugin's
own picture, open-design.ai/favicon.svg: a single fill, #26251E, drawn as an
<img> on the dark card (#232327).

Now icon() judges each picture once, after the picture's own load, so lazy
loading is kept (#909). The result is cached per src. If every opaque pixel
of a picture is one tone (the range of each channel is at most 24), and that
tone is near-black (every channel at most 72) or near-white (every channel at
least 224), the picture is replaced by maskSpan, the way a mono logo is drawn:
a mask in the text colour. This holds on any ground, Omarchy's themes
included. It covers user pictures (file:), plugin pictures, and bundled
-color and PNG icons.

Audit: every bundled picture icon, plus the plugin registry's pictures, was
measured in CIELAB against #232327 and #fff. Two were invisible in dark mode:
Open Design's plugin picture and bundled voyage-color.svg (#012E33, in the
provider icon picker). Both are now masks. Multi-tone and tiled logos stay as
they are (pipellm, zcode, mothx, deepinfra and others: low contrast in places
but readable). Mono icons were masks already.

Test: icon-one-tone.test.cjs, with the real favicon bytes in fixtures/.
- It draws every picture logo on the dark and the light card and measures,
  on a screenshot, how much of each stands apart from the ground.
- It opens Open Design's Installed row on the Plugins page and checks that it
  is a mask in the icon's text colour and visible in both themes: 5
  languages, 980px and 420px, Chromium and WebKit.
icon-url and icon-url-saved served a plain black square as the fetched
picture. That square is one tone, so it is now a mask. Their fixture is now a
coloured tile, like the letter icons the server makes (favicon.go).

Run (on mote unless named):
- icon-one-tone: 48/48. The 14 icon/theme GUI files (icon-tile,
  plugin-own-icon, mono-icon-redraw, plugin-registry-icon,
  models-add-and-icons, market-icon-corners, request-provider-icon,
  routing-client-icons, routing-log-icons, tray-logos, api-key-theme,
  icon-url, icon-url-saved, icon-one-tone): green in both engines.
- go test ./internal/gui -run 'Budget|I18n|Asset', gofmt -l,
  GOOS=linux go vet -tags nogui and GOOS=windows go vet of ./internal/gui:
  all clean, and no size budget was raised.
- A whole GUI suite on Linux (WSL) was cut off when the SSH connection to
  xiaomi-gpu dropped, after about 9,160 passes and 277 reds:
  - 40 of the reds were icon-url and icon-url-saved (fixed above).
  - The rest were in 75 other files. Those 75 files were run on mote with
    this change and at origin/main 76f00399c: 196 reds with the change and
    208 at main, in the same files.
  - The one file red only with the change, copilot-ghe (webkit zh,
    "route.fulfill: Target page ... has been closed"), is #1949's teardown
    race and passes 6/6 alone.
  - Every file red at main already has an open issue except
    redact-words-list, filed as #5288 and fixed by a18ff505b before this
    rebase.
- At the pushed head (a18ff505b + this commit): the budget/vet/gofmt checks
  above, the 14 icon files, redact-words-list and copilot-ghe, rerun.

Broken by hand: with both toneCheck(img) calls commented out,
icon-one-tone fails 46 of 48. voyage-color shows 0.0% ink in dark, and the
Open Design row stays an <img>. Before and after screenshots of the row in
both themes were taken from the same test.

Not tried: the real desktop app (Wails, WebKitGTK) and a real install of the
Open Design plugin. The page was driven with the API faked and the real
favicon bytes. The whole GUI suite has not had a complete run.
2026-11-05 06:11:49 +08:00
yetone a18ff505ba gui tests: redact-words-list measures the drawn controls, not the closed Import box's (acmilan_ follow-up)
v0.1.2964 (eeecd4150) added an Import… box to the word lists. Closed, its
textarea and buttons are hidden and have no box, so "every row fits the
page" read their zero rects as past the edge: red 20/20 in the whole GUI
run on mote. The test now checks only controls with client rects.

Run on mote at origin/main 76f00399c with this change:
node --test --test-concurrency=3 internal/gui/tests/redact-*.test.cjs,
186/186 ok (Chromium and WebKit, narrow widths, every language).
Broken by hand: the check still fails when a drawn control is pushed past
the list's edge.
Not tried: the whole GUI suite again (the earlier run was cut short when
the mote connection dropped).
2026-11-05 05:39:39 +08:00
yetone 76f00399c5 redact: a ping between two pieces of a placeholder no longer leaves it in the agent's arguments (#5287)
The Writer holds an event whose text ends in part of a placeholder and
joins it with the next piece. A keepalive event in between (Anthropic's
ping, Responses' response.in_progress or response.queued) made it write
the held piece as it was. The rest of the placeholder came in the next
piece, and neither piece could be restored. A slow model writing a masked
value through Claude Code's Write/Edit put {{SECRET_…}} or a stray { on
disk. magpie-community/plugins#738 committed two German texts as
{{SECRET_5dz6uy27}} and {{SECRET_2zh6t2jw}}.

Keepalive events now go out ahead of the held piece, which stays held for
its continuation. This covers every route that restores through
redact.Writer (Anthropic, Responses, Codex backend, plugins). Chat's
keepalive is a comment, which was already passed through (#2402), and
Gemini has none.

Run on mote at fe6533ad8 (= origin/main when pushed):
- go test ./internal/redact ./internal/masking: ok.
- go test ./internal/gateway -run 'Keepalive|Masked|Mask|Redact|Ping|Quiet|Restore|Placeholder': ok.
- GOOS=linux and GOOS=windows go vet of internal/redact and internal/gateway: ok.
- gofmt -l: clean.

Broken by hand: with writer.go back at main, both new tests are red.
- TestWriterHeldAcrossKeepalive: "anthropic ping cut at 49", a stray {.
- TestMaskedToolArgsSplitAroundPing: the agent's partial_json is
  {"content":"mail {{EMAIL_asf2pa5q}}"}.

Not tried:
- The false positive itself. None of the regex rules mask plausible German
  texts for these strings (Mask and MaskJSON with Secrets+Personal), so it
  was most likely the local model. That wasn't run, and the PR's German is
  unknown.
- A real Anthropic or Codex session.
- Placeholders the vendor sends back after a magpie restart. Values are
  kept in memory only, and that is unchanged.
- The full suite runs after the push.
2026-11-05 05:13:24 +08:00
yetone fe6533ad8b claudetui: Claude Code's exit is recorded once its last words are read (#5283)
The shim closed `exited` as soon as cmd.Wait returned, which can be
before the PTY reader has read what Claude Code wrote just before it
ended. Every "Claude Code ended ..." error then carried an empty screen
in place of the reason it gave, which is what TestShimNeverPrints/
failed_start saw on a loaded ubuntu CI runner (run 41899504898):
"ended before it showed its prompt (exit status 3): " with no
"something went wrong". The shim's own stderr line is meant; the test
checks the reason is in it.

Now the exit goes through shim.ended: on Unix it waits for read to end
(the master reads EIO once the last slave writer is gone), on Windows,
whose pseudo console stays open, until reading has gone quiet for 250ms
after its first bytes; two seconds at most either way, for a terminal a
child of Claude Code keeps open.

Run:
- Red before: with a 200ms sleep injected at the top of read(), the old
  code failed failed_start 5 of 5 on Linux (wsl-run, magpie-desktop)
  with CI's exact message; with the fix and the same injection, 50 of 50
  green. Without injection the old code passed 300 of 300 there (an
  idle machine never loses the race).
- New TestShimEndedAfterLastWordsRead (a reader given the last words
  300ms late, terminal ending and staying open). Broken by hand (ended
  records at once): red on both subtests; restored: green 20 of 20 with
  TestShimNeverPrints on Linux.
- internal/claudetui: Linux (wsl-run) -count=3 ok; macOS (mote-run)
  -race -count=2 ok; Windows (win-run) -count=2: only
  TestShimFirstMessageWaitsForTools red, the same at origin/main
  49e382735 without this change (#4810, commented).
- go vet ./internal/claudetui with GOOS darwin, linux, windows (mote).
- gofmt -l clean.

Not tried: a real Claude Code ending before its prompt (only the fake);
the Windows quiet rule on a really slow ConPTY reader.
2026-11-05 04:54:38 +08:00
yetone 49e382735f claude: a side question after a run's first reply of words branches by the reply's id
sleepy_shibe (Discord #feedback, magpie 0.1.2948, Claude Code 2.1.318,
claude-opus-5-5, macOS, interactive mode): when the last turn's reply
was words only, the turn after a prompt suggestion found no run
("claude: no run waits for this turn: its run ended 0s ago: the
interactive Claude Code can't go on with this turn") and a new Claude
Code was told the whole conversation as a transcript. With a tool call
in the turn it branched. 3 sessions, 7 times.

Cause (the reporter's reading, checked in a test): the interactive mode
streams a reply and the bridge hears its session line only later, from
the file. resume saves run.lastLine as the turn's backLine. A run's
first reply of words has no line heard yet, so backLine, behindLine and
the shelf's behindLine were empty while behindMsg (from message_start)
held the reply's id. branchAt returned nil at `at == ""` with no log,
and the run was let go. With a tool call, the run waited on the call and
heard the call's line first, so there was a line to cut at (8ac5f98e).
A run after a branch is a new run, so every first reply of words after
one hit it.

Fix, every path that cuts behind a side question:
- branchAt cuts with the reply's id alone when no line was heard.
- cutReply takes an empty uuid with a msg and cuts after the reply's
  last main-thread line; cutSessionAt's empty-uuid check moves to its
  uuid callers (cutSessionWhere does the polling).
- unshelve's search for a session behind a side question accepts a
  behindMsg alone, and cutBehind cuts by cutReply when either is set.
- cutReply waits for the reply's lines up to cutWait before falling
  back to the uuid's line. Before, a run that had heard an earlier
  turn's line cut after it at once when the new reply's lines weren't
  written yet, dropping the last turn.

Tests:
- TestClaudeInteractiveSideQuestionAfterAFirstReplyOfWordsKeepsTheReply:
  the fake writes the reply's line late; first turn words only, the
  suggestion, then "now commit it". The next turn must resume a copy of
  the run's own session (U1 and A1), told only the new turn. On
  origin/main ed7aeb052 it is red and logs the reporter's exact line.
- TestClaudeShelvedSideQuestionAfterAFirstReplyOfWordsKeepsTheReply:
  the same run let go past idleMost; the shelved session (behindLine
  empty, behindMsg set) is found and cut.
- TestClaudeCutReplyWaitsForTheReplysLines, and two id-only cases plus
  two error cases in TestClaudeCutReplyKeepsTheWholeReply.

Broken by hand, each red then restored: branchAt's old guard (the
interactive test), unshelve's old condition and cutBehind's old route
(the shelved test each), cutReply falling back to the uuid without
waiting (the wait test).

Run (mote, at this tree on origin/main ed7aeb052):
- go test -tags nogui -count=3 -run 'TestClaudeCutReply|TestClaudeShelved...|
  TestClaudeInteractiveSideQuestion|TestClaudeCutSession' ./internal/gateway/: ok
- go test -tags nogui -count=1 -timeout 45m ./...: ok, 87 packages, no
  FAIL (gateway 770s, claudetui 75s); log kept whole.
- go vet -tags nogui ./internal/gateway/, GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build ./..., GOOS=linux go build
  -tags nogui ./..., GOOS=windows go build ./...: ok
- gofmt -l: clean

Not tried: a real interactive Claude Code 2.1.318 with a real account;
the fake reproduces the timing (the reply's row heard after the stream
ended), not the real TUI. A reply split into several rows whose later
rows are not yet written when the cut runs would still be cut short
(as before this change); not seen.
2026-11-05 04:23:56 +08:00
yetone ed7aeb052f plugins: a package that declares magpie.agent is an agent, with a main or without (plugins#737)
miaocell's magpie-agent-deva ships a Bun module as its main beside its
moejs agent file (deva.agent.js), because the agent needs a runtime. The
market's GitHub list decided the kind by whether a main was there, so it
listed the package under Providers, and the Installed row wore a Provider
chip and a provider logo though the module serves no provider.

Now readTagged gives Kind "agent" to any package that declares
magpie.agent; middleware, page and hooks still need no main to be that
kind. The file looked for in the repository is still the module Bun
loads (its main), or the agent file when there is no main. The Installed
row of an agent plugin wears Provider only when its module serves a
provider, and its logo is the agent glyph unless it does. The moejs
descriptor contract is unchanged. The community registry.json already
gives kimi-desktop and reasonix-desktop (both with a main) kind agent;
the plugins repo's check now fails an agent package listed as any other
kind.

Docs: docs/reference.md, docs/subsystems/provider-plugins.md, and
site/public/docs plugins.html in en, zh and ja say an agent that needs a
runtime keeps its agent file and adds a Bun main, and is listed as an
agent either way.

Run (on mote, at this head rebased on b047cfe73):
- TestTaggedAgentWithMain (new; the reporter's real package.json,
  index.mjs and deva.agent.js in testdata): go test -run
  'Tagged|PkgEntry|Readme|GitHub' ./internal/plugin ok. Red with
  github.go at its parent: kind "".
- plugin-agent.test.cjs (new rows: an agent with a main and no
  provider, one switched off, one that serves a provider), chromium and
  webkit, en, zh, zh-TW, ja, de: ok. Red at origin/main b047cfe73: the
  deva row's chips were [Agent, Provider].
- Every plugin*.test.cjs plus i18n-keys, both engines: 1090 of 1094 ok.
  The 4 reds are plugin-move-unserved "Try again takes the models
  unticked" (Model 1 folded behind "Show the other 29"), red the same
  at origin/main b047cfe73; filed as #4410.
- gofmt -l, go vet ./internal/plugin ./internal/gui, GOOS=linux and
  GOOS=windows go vet ./internal/plugin, go test -run 'Budget|I18n'
  ./internal/gui (TestCoreScriptBudget, budget not raised): ok.

Not tried: installing magpie-agent-deva from the real GitHub list in a
running app (the list is read from the test server); Windows and Linux
runs of the GUI tests.
2026-11-05 03:54:41 +08:00
yetone b047cfe73c gateway: TestCRTidyTwentyFourMBLine bounds the bytes searched and allocated, not the wall clock (#5282)
The test is the relay hot path's bill for one 24 MB SSE line in 32 KB
reads. It had an 8s wall-clock bar. On main CI's Race step, beside heavy
shards, one_call_mended took 16.9s on ubuntu and 10.7s on macOS. Alone
under -race on mote it takes 4.4s. The bar measured the machine, and it
also missed one of the regressions it was there for: a copy of the held
bytes on every read took 0.37s.

crTidy now counts the bytes it searches for a line's end or the escape
(looked, one add per write and per region). The test bounds two things
the code controls, each against the line's size:
- bytes searched, at most 3x. Measured: 2x with no escape, 3x mended.
- bytes allocated (runtime.MemStats), at most 8x with no escape and
  40x mended. Measured: 5.4x (append grows the held line a quarter at
  a time), and mended 27x, 32x under -race (decoded into maps and said
  again).

Broken by hand, on mote:
- searching the whole held buffer for a line's end on each read (the
  quadratic read from yetone's review of #4256): 9.7 GB searched, red
  in both subtests.
- copying what is held on each read: 9.7 GB and 10.2 GB allocated, red
  in both subtests. The old 8s bar passed it at 0.37s and 0.77s.
Restored, green.

Run on mote at this head:
- go test -race -count=3 -run TestCRTidyTwentyFourMBLine ./internal/gateway:
  ok. mended takes 4.4s, no escape 0.19s.
- go test -race -run 'CR|Glm|GLM|Tidy' ./internal/gateway: ok.
- go vet ./internal/gateway on darwin, GOOS=linux and GOOS=windows: ok.
  gofmt -l: clean.

Not tried: a regression that searches without going through the
counted sites. The count bounds only what passes them. The allocation
bound still catches one that copies.
2026-11-05 03:41:57 +08:00
yetone 1f53537996 gateway: the 516 MB generated-images test has largeBodyRoom under -race (#5281)
TestCodexGeneratedImagesPastOldLimit is about the body limit, not the
unrouted cut. Its 516 MB turn is scanned and parsed a few times before
routing. Without -race that takes ~3s against the 30s cut. Under -race
it took 34s on main CI's Race step, and 14 to 17s on mote after
e710160df and 24a68018e. The race detector instruments every byte of
the three remaining parses. This is the same case as #3957, which gave
the 64 MB body tests largeBodyRoom.

largeBodyRoom lifts the cut under -race only. Without -race the 30s
cut stays, so a slower pre-routing scan still fails the test there.

Run on mote: go test -race -run 'TestCodexGeneratedImagesPastOldLimit|
...' ./internal/gateway ok (114.9s, see 24a68018e). Without -race the
test passes with the cut in place (post 3.0 to 3.1s).

Not tried: the test on CI's race shards before this push.
2026-11-05 03:37:43 +08:00
yetone 24a68018e8 gateway: a held body's member is not checked again byte by byte when it is decoded alone (#5281)
heldLongOf remembers that a held request body is valid, and where its
top-level members are, by the body's data pointer, so only a whole body
matches it. A Responses request's input (a chat's messages) is then
decoded alone by each of its readers. The first decode of each checked
all of it again: inspectPrompt's goroutine and factsOf (the folder's
reader) do it at the same time, both before the hash memo knows the
slice. For TestCodexGeneratedImagesPastOldLimit's 516 MB turn that was
two more full jsonCheck scans before routing. Under -race each byte of
those scans calls into the race runtime, so they were a large part of
the 34s that got the turn a 504 on main CI.

heldMember says whether a slice is exactly the value of a top-level
member of a held body found valid (binary search over its member spans).
A part of a valid value split at its members is valid itself, so
jsonValid and longBody skip the byte-by-byte check for it. A slice that
only lies inside a member, or is cut short, is checked as before.

Run on mote:
- new TestDecodeJSONHeldMemberNotCheckedAgain: decodes a held body, then
  its input three times as a string and as items plus jsonValid(input).
  It expects the body checked once and the input never, and a cut input
  checked once and refused. Red with heldMember turned off by hand
  ("checked 1 times and its input 1, want 1 and 0"), green on the fix.
- TestCodexGeneratedImagesPastOldLimit's post timed under -race on mote,
  load 42 to 80, old and new interleaved: old 20.9/18.8/17.4s, new
  (with e710160df) 16.7/13.9/14.3s. Without -race: old 3.20/3.27/3.31s,
  new 3.05/3.13/3.14s.
- go test -race -run 'TestCodexGeneratedImagesPastOldLimit|TestRequestBody|
  TestDecodeJSON|TestJSONValid|Held|TestReadSized|LargeBody|OldLimit'
  ./internal/gateway: ok 114.9s.
- go vet ./internal/gateway on darwin, GOOS=linux and GOOS=windows: ok.
  gofmt -l: clean.

What is left of the time under -race is mostly three full parses of the
turn (stoppedToolLoop, factsOf, promptOf). Each is race-instrumented per
byte. Those are not changed here. Found by wall-clock sampling of
goroutine stacks in the test; a Go CPU profile on darwin shows them only
as runtime._ExternalCode.

Not tried: a real Codex client sending a 516 MB turn.
2026-11-05 03:37:36 +08:00
yetone e710160df1 gateway: a request body a little over a doubling is not copied whole again for its last bytes (#5281)
readSized grows its slice by doubling up to the declared length. A body
just over a power of two was read into 1+2+...+512 MB and then copied
whole into a final 516 MB slice for its last 4 MB: about 1.5 GB
allocated and copied outside the body's wait, which counts toward the
30s unrouted cut. TestCodexGeneratedImagesPastOldLimit sends such a
516 MB turn and was answered 504 on main CI's Race step (34s).

Now, once the declared length is within a quarter of the next doubling,
the slice grows straight to it. The worst case over all lengths goes
from 3x the body allocated to 2.6x (computed over every length up to
600 MB in 16 KB steps). A body shorter than it said is still capped by
what it declared.

Run on mote:
- new TestRequestBodyNotCopiedForItsLastBytes (4 MB + 64 KB in 64 KB
  reads, at most twice its size allocated): red on the old code,
  11600416 bytes for 4259840; green on the fix.
- go test -race -run 'TestCodexGeneratedImagesPastOldLimit|TestRequestBody|
  TestDecodeJSON|TestJSONValid|Held|TestReadSized|LargeBody|OldLimit'
  ./internal/gateway: ok 114.9s, with this commit and the two after it.
- go vet ./internal/gateway on darwin, GOOS=linux and GOOS=windows: ok.
  gofmt -l: clean.
- The full suite and race shards are recorded in the last commit of
  this set.

Not tried: a real Codex client sending a 516 MB turn.
2026-11-05 03:37:20 +08:00
yetone 5ee9a18747 gateway: magpie's own summary ask keeps its status, so a compaction over the byte cap is summed up locally (#4862)
codexCompact asks a summary through the gateway's own handler (wantsWhole)
and reads a 413 as its cue to fit the conversation, then to sum it up
without a model. That ask was treated like a client's turn:

- with Codex's User-Agent, compactsInStream sent it a 200 and the 413 as
  the stream's error, so codexCompact saw no 413 and answered 502 "so
  there is no summary" for every compaction over the vendor's cap;
- with any UA, once the fitting tries took past keepHeldAfter (3s: a 40
  MB upload asked four times, a slow link, -race on CI) keepAlive sent a
  200 and a comment first, and the 413 after it came the same way.

keptAlive.whole (set from wantsWhole) now gets neither a keepalive nor
the in-stream 413. Codex's own turns are unchanged.

9a51d644d (the 4-minute summary limit) is not the cause: the 502 comes
from the status, not the deadline.

Run at this head (mote, mote-run):
- go test -count=3 -run 'TestCompactionOverByteCap' ./internal/gateway ok
- the compaction/keepalive tests -count=2 ok (225s); -race of
  TestCompactionOverByteCap* ok (121s)
- gofmt -l clean

Broken by hand: on the old code TestCompactionOverByteCapSlowFitting
failed 3/3 (502 at ~1.8s); the codex-UA subtest of
TestCompactionOverByteCapEveryTime failed 3/3. Reverting the
compactsInStream half alone turns the codex subtests red; reverting the
keepAlive half alone turns the plain SlowFitting case red.

Not tried: a real Codex compaction over a vendor's byte cap with a real
account; the full suite runs once for this batch (recorded on the last
commit).
2026-11-05 03:07:43 +08:00
yetone f24829636a gateway: a plugin's Gemini model is never asked ending with the model's turn (plugins#734)
A test, no code change. plugins#734 says the plugin path (gcp-ai,
@ai-sdk/google) skips the gateway's Gemini history rules. It doesn't: a
plugin's @ai-sdk/google model is spoken to on CodeAssist
(pluginProtocol), built by buildCodeAssistSent and unwrapped by
pluginFetch, so the trailing-model user turn and the
functionResponse/text split reach it. TestPluginGeminiNeverAskedEndingWithModel
holds that end to end through the fake plugin with FAKE-style
@ai-sdk/google model fake-gemini and a vendor answering as Vertex does
(vertexTurnsAway): Codex compaction after the model's reply, a Codex
turn ending with the assistant's message, and #1533's request on
Codex's path and /v1/responses, each asked once and never refused.

Run on mote (mote-run): go vet ./internal/gateway; go test -run
'EndingWithModel|NeverEndWithModel|ToolResponseTurnHoldsNoText|LocalModelIDAtAPlugin'
./internal/gateway ok.
Broken by hand: with the trailing-model guard in buildCodeAssistSent
turned off the test fails (vendor refused, a retry got past it); with the
functionResponse/text split turned off it fails on both #1533 cases.
Not run: the full suite (test-only change in one package).
The plugin side got the same rules as defense in depth in
magpie-community/plugins 5112465c (gcp-ai 0.2.1).
2026-11-05 01:46:28 +08:00
yetone 099d2b4612 agents: Codex back on ChatGPT after the reset says to restart its app, with a Restart
A bug report by mail (11-04): after the ChatGPT allowance reset, Codex
was back on its account, but the Codex app still showed no account and
no usage. The app's app-server was the one it started while magpie
served Codex, and the app reads account/read only as that starts. With
"Restart the Codex app when magpie switches its account back" off (the
default, #4550), codexAppStep leaves it running, and nothing said so;
the takeover's hover even said "It all comes back on its own at the
reset". On Windows StaleCopies lists only the daemon, so no hint showed
there either.

- provider: codexAppStep remembers the app-servers it left running when
  magpie gave Codex its account back (c.out && !out, not magpie's own
  account switch, which codexAppLeft already says). CodexAppBack() is
  true till they are gone (rechecked every 30s; a failed listing keeps
  it), a route change clears it, and RestartSwitchedCodexApp clears it.
- gui: /api/state's Codex row carries appBack (not for a WSL Codex).
  The Agents row says "Back on ChatGPT · restart the Codex app to see its
  account" with a Restart, and the row opened says why, with the same
  Restart; it posts codex/daemon/restart-app, as the Providers page's
  "still signed in as" Restart does. The takeover text now says the
  account and usage come back once the app-server restarts, and that
  this row offers it.
- i18n: zh, zh-TW, ja, de for every new and changed string.

Run (on mote unless named; rebased on origin/main d892dd6a2, then 8b902e287 (checkin only; vet and CodexApp/Checkin tests ok there), the gui budget/i18n Go tests, CodexApp and i18n-keys, codex-app-back, codex-app-out ran again at this head: ok, 148 of 148):
- go test ./internal/provider -run CodexApp: ok; also ok on Windows
  (win-run) and Linux (wsl-run, with go vet ./internal/provider).
- go test ./internal/gui: one red, TestMainWindowCorners/macOS_26_SDK,
  which is #3949 (macOS 27 on mote), nothing else.
- GOOS=windows go vet ./internal/provider ./internal/gui: ok. Linux vet
  of internal/gui needs gtk4/webkitgtk dev packages the WSL distro
  lacks, so it was not run.
- gofmt -l internal/: nothing.
- GUI: every codex-*, agent*, ag-* and i18n* file (86 files), both
  engines: 1484 of 1486. The two reds are codex-auto-reset webkit de
  1100/420, red the same alone at origin/main e0ee9265e; #4790 (noted
  there that macOS has it too). The new codex-app-back.test.cjs: 20 of
  20, every language, both engines, 980 and 440 px, line and row opened.
- Broken by hand: leftBack forced false, TestCodexAppBackSaidTillItRestarts
  went red ("the app left on the takeover's app-server isn't said");
  restored.

Not tried: a real Codex app through a real reset; the state machine is
driven with stubbed app-server listings.
2026-11-05 01:45:17 +08:00
yetone 8b902e2879 checkin: a ZCode or Qoder captcha stands for the day, not asked again every 30 minutes (plugins#503)
ZCode's check-in is rechecked (pluginRechecks, 430005726): the loop
asked again 30 minutes after every answer, a captcha included. A
captcha answer means the plugin's claim got 3007 and the plan has to be
claimed in the ZCode app; asked again, the plugin GETs the feed and
POSTs the same claim, and ZCode answers 3007 again. MiniFullC's log
(plugins#503) has an account asked six more times after its captcha in
one evening, followed by 3012 on two accounts. The plugin itself
already says captcha stands for the day (its RECHECK comment); magpie
overrode it.

Now, under a recheck, a captcha or own-app answer (both wait on the
user in the vendor's app) is settled for the day for the loop. A press
still asks at once, and the next Beijing day asks again. inactive,
ineligible, done and claimed are rechecked as before, so a plan dropped
into the feed later in the day is still found. The provider-plugins
page now names ZCode among the rechecking plugins, which it left out.

Run on mote: go test ./internal/provider/ ok (120s); go vet for
darwin, linux and windows ok; gofmt clean.
Broken by hand: with the old recheck line, the new
TestPluginCheckinRecheckLeavesCaptcha is red in all four subtests
(zcode and qoder, captcha and own-app: asked again at 22:47).
Not tried: a real ZCode account (none here); the full suite runs after
the push.
2026-11-05 01:43:41 +08:00
yetone d892dd6a22 gateway: a Claude conversation keeps the folder it named first when its caller moves
EricWvi on X (Claude Code -> local magpie -> a magpie on a server -> a
Claude subscription): the cache read flipped between under 10% and over
90%, each drop on a turn whose folder had changed (.../frontend, then
.../frontend/src). Claude Code 2.1.316 says a cd as a later
"# Environment update" message, "Primary working directory: /y (was /x)".

clientNamedWorkPlace took the last folder named, so a run started again
for the conversation (saved session resumed, branch, replay) got a
different prefix than its first run:
- a caller elsewhere: envTurnsNote names the folder, so append.md changed;
- a caller on this computer: the run worked in the new folder, whose
  session project doesn't hold the saved session, so --resume was lost
  and the whole conversation was told again.
Either way the whole conversation was written to the cache again.

Now the first text that names a folder decides it (within that text, its
last line, so "said twice" in one system prompt keeps its meaning). The
move still reaches the model in the conversation as the caller said it.
No text is added to the prompt; the note's wording is unchanged.

The reporter's per-turn flips on a v0.1.2879 server are the earlier
safeguards restart (git_state.cwd in safeguardsKept), fixed by 59c130603
in v0.1.2882 while the tap is live.

Run (mote, via mote-run, at this tree):
- go test -tags nogui ./internal/gateway -run 'TestClaude|TestWorkDir'
  -count=1: ok (114.9s)
- go test -tags nogui ./internal/gateway -count=1 -timeout 45m: ok (778.6s, mote at load ~45)
- go vet -tags nogui ./... ; GOOS=linux and GOOS=windows go vet
  ./internal/gateway: ok (cgo deprecation warnings only)
- gofmt -l internal/gateway: clean
Broken by hand: without the `if dir != ""` guard,
TestClaudeTUIConversationKeepsItsFolderWhenTheCallerMoves is red in both
subtests (caller elsewhere: append.md names .../frontend/src; caller on
this computer: --resume of another session, not s<pid>).
Not tried: a real Claude Code cd against a real remote magpie and
subscription; whether a model told the first folder in envTurnsNote after
a move misreads the environment update (not measured).
2026-11-05 01:37:56 +08:00
yetone e0ee9265ef gui: TestClosingWindowMarksPageOutOfSight reads hidden as app.js does and waits for the page (#4924)
The test page read document.hidden from WebKit, which app.js never does:
app.js makes hidden and visibilityState follow magpie's signal (#4293).
WebKit turns an ordered-out window's document.hidden on in its own time
and fires no visibilitychange of its own, so the page recorded the hiding
only if WebKit's value was already true when magpie's signal (an async
ExecJS after orderOut) arrived. When it wasn't, nothing was recorded, the
window was shown again after a fixed 500ms, and the host waited 8s for a
report that could never come: "timed out waiting for the page's hidden
report", as on macOS CI at 4a9cfb52e and in a full run on mote.

A probe on mote showed WebKit reporting hidden=true for this page from the
start, before the window was ever ordered out, so there the old test
passed on WebKit's value, not on magpie's signal.

The page now overrides hidden and visibilityState the way app.js does,
and says when it has seen itself hidden; the window is shown again only
after that (a wait on state, 15s bound), not after a fixed pause. The
runAppKit bound is 2 minutes to cover its waits. app.js is unchanged.

Run on mote (macOS) at this tree:
- Injected WebKit reporting visible when the signal arrives (hidden and
  visibilityState pinned to visible in the page): old test red on both
  tests with "timed out waiting for the page's hidden report"; new test
  green.
- hideWebview's signal broken by hand (pageHiddenJSOn returns ""): new
  test red on both, "timed out waiting for the page to see itself hidden".
- No injection: green, -count=3.
- go vet ./internal/gui: ok; gofmt -l: clean.
- go test -count=1 ./internal/gui: only TestMainWindowCorners red, the
  separate #3949, which #4924's body names as well.
Not tried: a 1.5s busy page or a 300ms-late orderOut as the injection;
neither turned the old test red on mote, since WebKit says hidden there
throughout. A CI macOS runner itself.
2026-11-05 01:37:29 +08:00
yetone 9a51d644d6 gateway: a compaction's summary late past 4 minutes is magpie's own, sent before Codex gives up (#5275)
hayden4608 on Discord (#5275, asked as urgent): Codex Desktop compacting a
~108k-token conversation on volcengine/deepseek-v4.1-flash. The ~3.1MB
summary request was still being written to Ark at 299s (TryNet Send
~299s, no first byte), Codex gave up at 300s (499), and only then did
magpie log "the reply ended before it was complete; compacting locally".
That local summary went to a request nobody was reading, and
compactFails.done cleared the conversation's count as if it had worked.
Codex sent the same history again, three times, 300s each, and the
conversation never got shorter.

- codexCompact gives the summary compactWithin (4 minutes, a minute
  short of Codex's 300s stream idle timeout, as agentQuietMost). Past it
  the vendor is no longer waited on (the ask's context ends with a
  sideTimedOut cause, so the usage log says "magpie stopped waiting: its
  compaction summary had no answer in 4m0s", not the agent canceling),
  and magpie's own summary (localSummary, saying "no summary came in
  4m0s") goes to Codex while it still waits. Checked after the first
  ask, the ask as plain text, and the as-text ask after tool calls, so
  a late first ask is never followed by another ask of the same body.
- A compaction Codex left before it was answered is counted a failure
  (499, "Codex left before the summary reached it") and nothing is
  written; done() is no longer called for it. After compactFailsMost in
  a row, the next is held with a 400 at once instead of another 300s.

Why the upload was slow: not shown to be magpie's. From here a 3.1MB
whitespace-padded chat request to ark.cn-beijing.volces.com/api/v3 was
read whole in ~1.5s by curl over HTTP/2 and HTTP/1.1, and Go's client
with vendorTransport's settings (HTTP/2, ping health) wrote it in 0.89s
(HTTP/1.1 0.17s) from mote. The reporter's ~10KB/s, and their own 4MiB
control not finishing in 40s by any route, point at the uplink or the
Shadowrocket TUN in their path. Not tried through a TUN.

Run (mote): TestCodexCompactLateSummaryCompactsLocallyInTime and
TestCodexCompactLeftBeforeAnsweredStillCounts green with the fix;
both red on the old code (the first: no answer before the client's 10s; the
second: a completed compaction written to a Codex that left, and the next
not held). go test -run Compact ./internal/gateway ok; go vet of
internal/gateway for darwin, linux and windows ok; gofmt clean.
Full suite: run after the push (go test -timeout 45m ./... on mote, log
teed), result on #5275.

Not tried: a real Codex Desktop session against a slow uplink; a
reporter-side stream_idle_timeout_ms shorter than 4 minutes (then Codex
still leaves first, and the count holds the conversation after 3).
2026-11-05 01:26:12 +08:00
yetone c3ba2cc933 gateway: TestUnroutedProgressingUploadOutlastsMost gives the handler's time between reads room (#5274)
The zstd subtest went red on macOS CI at 4a9cfb52e: "held 1s before
routing, its body still arriving (256.1 KB of 256.1 KB, the last 100ms
ago); in body 500ms; stopped with 408". Only time spent in a wire read
(waitedBody.Read) earns upload credit; the handler's own time between
reads (decoding, being scheduled again) counts toward unroutedMost. On
mote that time is under 2ms, but a loaded runner spent about 1s of it,
past the test's 1s unroutedMost, so the hold stopped the upload with 408.

The test now holds most at 3s and waits most+most/2 for the hold to end
by itself, well under the 6s (gzip) to 8s the wire bytes earn. The
production rule is unchanged: a stalled handler is still not an upload.

Run on mote (macOS) at this tree:
- Injected one 1.2s stall after the first wire read, outside the body
  wait: old test red on all 4 subtests ("in body 0s", 408); new test
  green on all 4.
- Injected 3.5s: new test red on all 4, so the bound is where the
  comment says.
- Credit broken by hand (earned := 0): new test red on all 4.
- No injection: green, ~4.5s a subtest.
- go test -race -count=2 -run '^TestUnrouted' ./internal/gateway: ok
  (65.8s). gofmt -l and go vet ./internal/gateway: clean.
Not tried: Linux or Windows runs (the test has no OS branch); the full
suite (run once after this batch).
2026-11-05 01:20:51 +08:00
yetone 83137bcbe9 sessions: TestCCListingKeepsItsNames counts the names' allocations, not Linux's stats (#4925)
Red on ubuntu CI at 4a9cfb52e (run 41865226839) and on the Linux box
alone: "listing 3000 unchanged files took 12159 allocations", bar 3n =
9000.

Cause: dirent.Stats reads a folder's stats in one call on macOS
(getattrlistbulk) and has no such call elsewhere, so on Linux statFiles
stats each file alone through statOne (os.Stat), two allocations a
file: 6000 for the test's 3000 files. The names are kept the same on
both systems. A probe of the second listing (not committed) gave Linux
12115 allocations, 6110 with statOne answered without allocating, and
macOS 6128 and 6124; one os.Stat is 2 allocations on each. The 3n bar
was set on macOS and charged Linux's stats to the names.

Change (test only): the measured listing's statOne is answered from a
table of os.Stat read before it, so what is counted is the listing's
own work on every system. The bar is unchanged.

What was run, at this tree on origin/main fd85c0a1e:
- Linux (wsl-run, magpie-desktop, go1.26.8, -tags nogui): the old
  test red, 12159 allocations. The new test ok. The new test with
  ccNames.of never taking the last listing's names (broken by hand):
  red, 12159.
- macOS (mote): the new test ok; with the names broken by hand red,
  12198.
- go test -count=3 ./internal/sessions: ok on Linux (-tags nogui) and
  macOS. gofmt -l clean; go vet, GOOS=linux go vet -tags nogui,
  GOOS=windows go vet of internal/sessions: clean.
Not tried: Windows (no bulk stat there either, so it would have been
red the same way; Windows CI only compiles tests).
Not changed: Linux still pays os.Stat's two allocations a session file
each poll; that cost is the system's stat, not this test's guarantee.
2026-11-05 01:08:08 +08:00
yetone 775630dac9 usage: the compaction picker says each window against the setting now
hayden4608 on Discord (#feedback): "上下文压缩阈值建议这里应该以当前选中的为
基准更直观 而不是以最省token的为基准". Usage › Context's "Other window…"
menu said every value's tokens past the leanest, so the window one had
set (ticked in the menu) read "+N tokens" like any other, and choosing
between them meant subtracting two notes in one's head. The reader
picks away from the setting in use, so that is the baseline now:

- each value says "−N tokens (−x%)" or "+N tokens (+x%)" against the
  setting now's own point on the curve (the replay's cost at the current
  value when the curve has no point there);
- the setting itself says "Your setting now";
- "Fewest tokens" stays, beside the leanest value's numbers (timed: the
  cheapest, as before), so where the minimum is is still shown;
- the menu head says it: "Compact at · against the setting now, from
  your calls of the range".

The chart and the "{pct} fewer tokens" line already compare with the
setting now and are unchanged. New strings in zh, zh-TW, ja and de; the
old head's key is replaced. docs/subsystems/agent-wiring.md says the new
baseline.

context-tune.test.cjs: the menu notes in every language at 360 and
1100 wide, against 300K set (−150M/−11% at 250K, −420M/−30% plus
Fewest at 160K, "Your setting now" at 300K), and again after 250K is
put in (250K is the setting, 300K +150M/+12%); the timed case against
120K set (100K −90M/−9% plus Fewest, 240K −20M/−2%).

Run on mote (mote-run), this tree before the rebase:
- context-tune: 120/120 chromium, 120/120 webkit
- i18n-keys 4/4 and compact-one-value 6/6 in each engine
- go test -run 'Budget|Script|Asset|I18n|Lang' ./internal/gui: ok

Broken by hand: the old context.js under the new test fails 20
subtests in chromium (both menu tests, every language and width).

Not tried: the real app with a real replay; the full GUI suite and
go test ./... (run after the push).
2026-11-05 01:06:30 +08:00
yetone ab5191f8d7 provider: Zed's mover min is 0.1.18, which names each request's thread (plugins#731)
zed 0.1.18 (magpie-community/plugins@3920b745, on npm) sends thread_id
and prompt_id in CompletionBody as Zed's editor does, so a conversation
is one thread to Zed's cloud, not a new one per request. Yezike-yyy's
Gemini 4 Argon conversation read no cache on 11 requests of 180k-230k
input tokens. keepMovedCurrent brings every moved Zed user up to it.

Run (mote): go test -timeout 30m ./internal/provider/ ok; gofmt -l clean.
`npm view --prefer-online --registry https://registry.npmjs.org
@magpie-community/opencode-zed-auth version` said 0.1.18 before this.
Not tried: no Zed account, so whether Zed's cloud caches Argon on
thread_id is not known; the reporter is asked to retest.
2026-11-05 01:00:28 +08:00
yetone 676b143175 gateway: a model refused for the user's region is asked once more, then the agent is told Google's restriction on that model (#5182)
taoxiaoxin (#5182) runs magpie v0.1.2738 with the built-in Antigravity
provider, calling it with curl. antigravity/gemini-3.8-flash (upstream
gemini-3.8-flash-tiered) answers 400 "User location is not supported
for the API use.", while claude-sonnet-4-6 and claude-opus-4-6-thinking
on the same accounts answer 200. The refusal is per model and comes
from where the user is. A new connection doesn't help, and v0.1.2982
still asked every account and then retried the last two more times.

- gateway.go: regionAsked counts region refusals per provider and
  model within a request. The first one goes on as v0.1.2982 does: the
  next account, or the same one again, on a new connection, which
  covers ggdayup's stale-edge case. On a second refusal, the provider's
  other accounts aren't asked that model (notMates), the last one isn't
  retried (protected), and another provider or model left is asked. Nobody
  rests (restAfterMarked, v0.1.2982).
- fallback.go: regionNote and explained. The agent gets the vendor's
  words plus: "Google doesn't serve <model> to requests from the region
  this one left from: a regional restriction on the model, not on the
  account, so no account rests for it and the provider's other models
  may still answer. Use another provider for <model>, or give the
  provider a proxy in a region Google serves (its Proxy setting)". It is
  added at the four places that word a failed reply through
  Provider.Explain (translated stream and non-stream, pass-through,
  count_tokens). It still goes out as the 400 that SDKs don't retry.
- docs/subsystems/gateway-routing.md: the bullet says this.

Tests:
- TestRegionRefusalOfTheModelEndsAfterOneMoreAsk: one and three
  accounts, stream and not, every ask refused. Exactly 2 asks, then a
  400 that carries Google's words and the note. No account rests and no
  usage is re-read.
- TestRegionNote: Google's and OpenAI's wordings. Nothing is added for
  another 400, or for a 200 that quotes the words.

Run on mote (mote-run):
- go test -count=1 -run Region ./internal/gateway/: ok, every #5182
  test from c32b820a9 included.
- go test -race -count=3 -run 'Region|Antigravity|Fallback|Group'
  ./internal/gateway/: ok (519.7s)
- go vet ./internal/gateway/ for darwin, linux (-tags nogui) and
  windows, and go build ./... for all three: all clean
- gofmt -l: clean.
- The full suite at c32b820a9 (v0.1.2982), go test -timeout 45m ./...:
  every package ok except internal/gui TestMainWindowCorners/
  macOS_26_SDK, which is #3949, open and red on mote's macOS 27. This
  commit doesn't touch internal/gui.

Broken by hand, each with a real FAIL and then restored:
- the second refusal's cut removed: the 1-account case asks 3 times,
  and the 3-account case asks u1 u2 u3 u3 u3, which is the reporter's
  behaviour.
- regionNote left out of explained: the agent gets Google's words
  alone, and every subtest is red.

Not tried: a real Antigravity account in a region Google refuses
gemini-3.8-flash to. That the reporter's Claude models answer from the
same place comes from their report, not from a run here.
2026-11-05 00:59:11 +08:00
yinwu01 fd85c0a1e9 gateway: a test's memory root reads nothing of the machine it runs on (#5118)
TestCodexBodyLimitFromMemory's "unknown" case is red on every Linux
machine with more than 8 GiB: ubuntu CI ("unknown: 998 MiB" in the Test
job at 0a5dc40ab), the Linux box under WSL ("unknown: 1994 MiB") and
this one ("unknown: 2048 MiB"). The case points memLimit at an empty
root with memGOOS "linux". codexBodyLimit, bodyRoomSize and
claudeRunBudget fall back to proc.MemTotal() whenever memGOOS is this
system's, which held for a test's root too, so on Linux the fixture
read the test machine's own memory. Elsewhere the GOOS differs: macOS
CI at 0a5dc40ab doesn't fail this test (its job is red on others).

The three now fall back only when memOwn: memGOOS is this system's and
memRoot is "/", the only root magpie itself sets. The magpie binary
behaves as before; a test's root no longer reaches the machine's
memory.

What was run (tree 039a3044, on origin/main 43849d51, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestAFixtureRootIsNotThisComputer (new): an empty root naming this
  computer's GOOS leaves bodyRoomSize, claudeRunBudget and
  codexBodyLimit at their unknown values. With memOwn put back to the
  GOOS check alone: red on all three ("body room 16111 MiB (a
  thirty-second of 515578 MiB (the computer's memory)), want none",
  "run budget 64447 MiB (...), want the unknown 4096 MiB", "Codex turn
  limit 2048 MiB, want 512 MiB"), and TestCodexBodyLimitFromMemory
  "unknown: 2048 MiB". With claude_rss.go's fallback alone put back as
  it was, only the run budget. With the change, with
  TestCodexBodyLimitFromMemory, TestBodyRoomSize,
  TestClaudeRunBudgetScalesWithMemory, TestClaudeMemRuns* and
  TestClaudeRunsMost*: -count=3 21 of 21 ok, and -race -count=3 21 of
  21 ok.
- gofmt -l clean. go vet -tags nogui for linux and windows, go vet for
  windows, go build -tags nogui for linux and darwin and go build for
  windows: exit 0 each. GOOS=darwin go vet -tags nogui: exit 1 at
  internal/gui/traywindows_darwin_test.go (trayImagePNG is darwin &&
  cgo, and a cross vet has no cgo), the same at origin/main 43849d51.
  go vet and go build without the tag on linux: exit 1 (no libsoup-3.0
  or gio-unix-2.0 pkg-config here).
- go test -tags nogui -count=1 -timeout 45m ./... (Bun 1.4.2): 84
  packages ok, gateway among them; red in three, each red the same run
  alone at origin/main 43849d51: sessions' TestCCListingKeepsItsNames
  (#4925), agent's TestDshACPSettingsGetTheRoute (this box's umask 077,
  #5238), provider's TestOpenCodeProjectIs225s and
  TestOpenCodeEnvironmentIs225s (an empty /tmp/.git on this box,
  #5239).

Not tried: a Mac or Windows. There the new test should be red on the
old code too, as the fallback took that machine's memory the same way;
it was run only here.

Reviewed and landed by yetone at origin/main d17a0b3ca (patch hash
639baff3... checked against the one posted on #5118). CI went red on
this at 4a9cfb52e (run 41865226839, ubuntu). Run at this tree:
- Linux (wsl-run, magpie-desktop, go1.26.8, -tags nogui): with memOwn
  put back to `memGOOS == runtime.GOOS` alone, TestCodexBodyLimitFromMemory
  "unknown: 1994 MiB" and TestAFixtureRootIsNotThisComputer red on all
  three readers (body room 997 MiB, run budget 3989 MiB, Codex turn
  limit 1994 MiB). With the change, the memory tests (TestCodexBodyLimit-
  FromMemory, TestAFixtureRootIsNotThisComputer, TestBodyRoomSize,
  TestClaudeRunBudgetScalesWithMemory, TestClaudeMemRuns*,
  TestClaudeRunsMost*): ok.
- macOS (mote): with memOwn put back, TestAFixtureRootIsNotThisComputer
  red on all three (2048/8192/2048 MiB from mote's 64 GiB);
  TestCodexBodyLimitFromMemory passes there either way (memGOOS
  "linux" differs). With the change, the same set -race: ok.
- gofmt -l, go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  (internal/gateway), go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: clean on mote.
Not tried: Windows; the full suite (run once after this batch).
2026-11-05 00:57:55 +08:00
yetone 79477604a5 providers: a plugin option that says placement "top" sits under the accounts, above Routing (#5269)
mycf_711 (#5269): WorkBuddy Pro's plugin-level "panel" switch was drawn in
Plugin options, under the whole model list, so it took a scroll every time.
An option in auth.options may now say `placement: "top"`: the provider's
editor draws those in a Plugin options block right under the accounts,
above Routing, and the rest under the models as before. The note that the
plugin reads them goes with the first block. host.js keeps placement only
when it is "top" (anything else is left out, so the option goes under the
models), and plugin.Option carries it to /api/providers. A plugin that says
no placement is drawn exactly as before, and an older magpie ignores the
field. Documented in docs/subsystems/provider-plugins.md and
docs/reference.md.

Run (mote, through mote-run):
- new internal/gui/tests/plugin-option-placement.test.cjs: chromium 31/31,
  webkit 31/31 (1100 and 420 wide, en/zh/zh-TW/ja/de; mixed, top only,
  none or an unknown placement; the top switch posted on Save).
- plugin-options.test.cjs 11/11 and plugin-option-words.test.cjs 21/21,
  i18n-keys 4/4, each in chromium and webkit.
- go test ./internal/plugin ok (TestPluginOptions checks "top" kept and
  "sidebar" left out); go test -run Budget|Script|Asset ./internal/gui ok.
- gofmt -l internal/plugin empty; go vet ./internal/plugin ./internal/gui
  ./internal/cli, GOOS=linux -tags nogui and GOOS=windows vet of
  internal/plugin ok.

Broken by hand:
- app.js put back to its parent: the placement test fails "mixed" and
  "top" in both engines (blocks under the models), "none" still passes.
- host.js's placement line removed: TestPluginOptions fails
  "second = {... Placement:}".

Not tried: a real WorkBuddy Pro plugin (Gitee, private) with the field;
the full go test ./... and the whole GUI suite run after the next commit.
2026-11-05 00:55:36 +08:00
yetone d17a0b3ca0 usage: opening the Usage page no longer stutters (_hii11 on Discord)
_hii11 (Discord #general): switching sidebar pages stutters a little,
most of all on Usage. The click that opened Usage built every allowance
card and curve twice, the first time inside the click:

- renderUsageLoading drew the cards again although the read of the
  allowances that goes with every load (loadQuotas) draws them once it
  answers. Cards already drawn now stay until then.
- every card's draw parsed each history line's readings (up to 6000 a
  window, 45 days) three times. quotaPoints parses a line once for each
  read of the history (loadQuotaHist puts a new quotaHist), and the
  recorded cycles are found once for those points.

The UI is the same; nothing new moves.

Measured on mote, headless Chromium, 1280x820, a busy user's data (10
accounts, 45 days of history, 30 days of usage), Usage clicked 4 times,
frames dropped in the 900ms after the click:
- CPU x1: before 4/4/1/1 (worst gap 50ms), after 1/1/0/1 (33ms)
- CPU x4: before 43/37/33/32, after 32/17/20/19; the click's own task
  ~250ms before, ~70-85ms after; click handling in the trace 303ms -> 89ms.
Agents and Providers switches were 0-1 dropped before and after.

Run (mote):
- usage-open-light.test.cjs (new), Chromium and WebKit, en/zh/zh-TW/ja/de:
  green. Red on the old assets: 17292 dates parsed again per redraw; with
  only page.js put back by hand, the cards are rebuilt inside the click.
- the 195 GUI files that touch the Usage page or its cards, both engines:
  3243 of 3295 pass. Each red file was then run alone on this change and
  on origin/main 4a9cfb52e: the same reds on main, all filed already:
  tray-cell-click #5215, usage-agents-hide #2276, usage-fold #3415,
  context-map #3488, codex-auto-reset (webkit de) #4790, usage-ledger
  Requests #5048. account-eye's '' for 'none' is #5052 (on main too;
  4 of 4 green here alone). plugin-checkin passed alone on both.
- quota-curve.test.cjs both engines green; TestCoreScriptBudget passes.

Not tried: the real app at 60fps (ffmpeg), WebKitGTK on Linux, Windows
WebView2, the reporter's own data.
2026-11-05 00:41:16 +08:00
yetone 2d04fe73dd gateway: Antigravity's tool enums go without a blank value (#5235)
Google's Schema proto refuses a blank enum value, so a tool whose enum
holds "" turned every tool-bearing Antigravity turn away with 400
"enum[N]: cannot be empty". Portainer's StatusMessage.operationStatus
(enum ["processing","warning","error",""] under allOf) did it for
ikunbots' dsh session, reported on X.

plainSchema now leaves blank (whitespace-only) values out of a string
enum, and leaves the enum out when nothing else is in it; a blank const
gives no enum. A number in an enum still drops it whole, as before.

Run (mote): go test ./internal/gateway -run
'PlainSchema|Antigravity|CodeAssist|GeminiSchema' ok;
TestPlainSchemaDropsBlankEnumValues red on origin/main's codeassist.go
(the "" went through), green with this. gofmt clean.
Not tried: a real Antigravity request with the reporter's Portainer
tools. Not changed: Vertex's chat path (geminiSchemaShapes), which
relays JSON Schema enums as they come; whether Vertex refuses a blank
value too is unknown.
2026-11-05 00:37:01 +08:00
yetone c32b820a91 gateway: a "User location is not supported" refusal rests no account, and the next try goes on a new connection (#5182)
ggdayup (#5182): Antigravity answered 400 "User location is not
supported for the API use." on one kept-alive connection. magpie asked
every account after it on that same connection, each was refused the
same and rested, and the agent got a 400, while a new connection about
12s later was answered. The refusal is about the edge the connection
reached, not about the account.

- routing.go: restAfterMarked returns Rest{By: "off", Until: now} for
  regionRefused, as for zdr and offline, so no account rests and no
  failure is counted.
- upstream_transport.go: regionFresh wraps each of upstreamTransport's
  three transports (any, draws, uploads), so every request through
  s.client is covered. It reads the first 8KB of each reply with
  status >= 400. When those match regionWords, closing the body calls
  CloseIdleConnections, and a pending flag calls it again before the
  next request. That flag covers an HTTP/2 connection that still
  carried another stream when the body closed.
- fallback.go: passing() asks the last candidate again (lastRetries,
  after retryPause), on a new connection, so a user with one account
  is helped too.
- docs/subsystems/gateway-routing.md: a bullet saying all of this,
  including what it doesn't cover.

Tests (region_fresh_test.go, with a fake TLS edge that refuses every
request on the first connection it sees and answers on any other):
- TestRegionRefusalDropsItsConnection uses the real New() client,
  over h2 and h1. After a region 400 the next request goes on a new
  connection and gets 200. A plain 400 INVALID_ARGUMENT keeps its
  connection.
- TestAntigravityRegionRefusalAsksTheNextOnANewConnection: two
  accounts. The second is asked on a new connection and answers, no
  account rests, and Tries[0].Rest.By is "off".
- TestAntigravityRegionRefusalAsksTheLastAgain: one account. It is
  asked again on a new connection and answers.
- TestRegionRefusalRestsNoAccount: Google's and Antigravity's
  wordings, two turns each. Both accounts are asked both times, with
  no rest, no failure counted and no usage re-read. A 500 still rests
  the account.
- TestGroupFailsOverARegionRefusal (#1621) now asserts By "off" and
  no rest.

Run on mote (mote-run):
- go test -count=1 -run 'Region' ./internal/gateway/: ok.
- go test -race -count=3 -run 'Region' ./internal/gateway/: ok (16.5s).
- go vet ./internal/gateway/ for darwin, linux (-tags nogui) and
  windows, and go build ./... for all three: all ok.
- gofmt -l: clean.
- Full suite: run after the push, see #5182.

Broken by hand, one at a time, each with a real FAIL and then
restored:
- regionFresh not wrapping the body: DropsItsConnection h2 and h1
  region, AsksTheNext and AsksTheLast are red (the second request goes
  on the refused connection, and the turn gets 400).
- restAfterMarked's early return removed: AsksTheNext and RestsNoAccount
  are red (By backoff, Failures 1).
- passing()'s region case removed: AsksTheLast is red (the turn gets
  400).

Not tried: a real Antigravity account in a refused region. Nothing here
can reproduce Google's per-edge refusal. Not covered: an HTTP/2
connection busy with another stream at that moment outlives the close
until it is idle. The close also drops other vendors' idle connections,
which costs one handshake each. A user who really is in a refused
region now gets the refusal about 3s later, after the last candidate's
retries.
2026-11-05 00:28:06 +08:00
yetone 18726b9fb6 statusline: a held key is told how to see its line, ?format=json, and /v1/magpie/limit says what holds a key (steven_4422)
steven_4422 (Discord, #feedback): POST /v1/magpie/statusline answered 403
gateway_key_held to a key held to Claude's models, while GET
/v1/magpie/limit told the same key {"limited": false}. They asked for the
line scoped to what the key may use, /limit to agree, and a JSON line for
claude-hud's external usage snapshot.

The scoped view already exists (#2216): the status line goes through
scopeQuotas like the quotas routes, so a held key its owner turns Quotas
on for (Gateway -> Gateway keys, or `magpie gateway-key quotas <id> on`)
is told the accounts it may use of each provider whose every model it may
use, and nothing else. Its 403 never said so. Decision: the switch stays
the gate for every held key, budget, models or accounts alike. What holds
a key says nothing of whether its holder is the owner or a friend (#1981
was a friend's budget key seeing every account's email), and only the
owner knows that, so a model- or account-held key is not told quotas by
default either. The every-model rule of #2216 stays.

- scopeQuotas' refusal (heldQuotasOff) names the switch and what it then
  tells. heldRefused, for the routes the switch doesn't open
  (concurrency, trace, a card outside the scope, writeCards' told-none),
  is unchanged.
- GET /v1/magpie/limit tells a held key heldTo (budget, models,
  accounts), models, quotas and, with it on, quotaProviders (the
  providers newQuotaScope tells it). No account is named. `limited`
  keeps its meaning (the budget) for remote magpies that read it.
- ?format=json on the status line: {"text", "model", "accounts"}, the
  cards the line shows in /v1/magpie/quotas?kept=1's shape (windows'
  used, resetsAt), through the same scope.
- Docs: reference.md, integrating.md, gateway-routing.md; site docker
  and remote pages in en, zh, ja.

Run at this head (4a9cfb52e + this), on mote:
- gofmt -l clean; go vet, GOOS=windows go vet, GOOS=linux go vet -tags
  nogui on internal/gateway: clean.
- go test -run 'TestStatusline|TestHeldKey|TestRemoteMagpieShowsHeldKey|KeyLimit'
  ./internal/gateway: ok.
- TestStatuslineHeldKeyScope (new): this computer and a key held to
  nothing see alpha One, alpha Two and beta; a key held to alpha/* sees
  alpha's two; one held to alpha's Two sees Two alone; one held to
  alpha/m1 sees nothing; the same through ?format=json; Quotas off is
  403 gateway_key_held naming the switch, as text and JSON; /limit's
  heldTo, quotas and quotaProviders for each, and no account id.
Broken by hand, each red: the scope dropped from the handler (every
held key saw every card, text and JSON); /limit's held block skipped;
scopeQuotas back on heldRefused.
Not run before the push: the full suite (mote had three full suites of
other sessions running at load ~70; it runs after, per the rules). Not
tried: a real Claude Code or claude-hud on another computer, a real
Claude account behind a held key, Windows and Linux test runs.
2026-11-05 00:24:13 +08:00
yetone 4a9cfb52e5 usage: a plugin account told by its balance alone is drawn over time
corddis_114 on Discord: SenseTime Raccoon's (商汤小浣熊) usage card had no
trend chart like the other cards. The Raccoon plugin tells a "Credits"
window when its bills add up to the balance, and only `balance: "N
credits"` with no window when they don't. A window's share is kept in
quota-history.json and drawn; a balance was kept (balance-history.json,
balanceTrend) only for API keys' balance cards, from KeyBalances. A
subscription or plugin card's balance was never recorded, so such a card
had no curve at all.

noteCardHistory, called where SubscriptionUsage and a card's refresh
note a read, keeps each window's share as before and, for a card with a
balance and no windows, its balance, and sets the card's balanceTrend, so
the Usage page draws "Balance over time" for it as for a key. A card with
windows keeps its windows' curve alone (its balance isn't recorded). The
keep-alive's keepCardRead is unchanged (Claude cards have windows).

Run (mote, at 8e97e26d6 + this change; after the rebase on 7661a0aa7,
the TestBalance|TestQuotaHist|TestPluginUsage run again ok):
- go test -count=1 ./internal/provider/ ok (166s); go vet for darwin,
  linux and windows on internal/provider ok; gofmt -l clean.
- node --test internal/gui/tests/balance-curve.test.cjs: 6/6, chromium
  and webkit, en and zh; a Raccoon-shaped card (user, plan, windows [],
  "5900 credits", three points) draws its curve.
Broken by hand: noteCardHistory without its noteBalanceHistory call:
TestBalanceOnlyCardHasTrend red ("wallet's trend = <nil>").
Not tried: a real Raccoon account (none here); which branch corddis's
account takes is not known. An account on the window branch already
had a curve. Full suite and GUI suite not run before push.
2026-11-05 00:14:14 +08:00
yetone 7661a0aa72 provider: Fetch models ticks each key's own models, the first key's too (young02036)
young02036 on Discord (#feedback, v0.1.2965): "点击供应商的获取模型,给这个
供应商的所有账号默认勾选上可用模型,和新增账号之后默认勾选上可用模型这个功能
好像失效了".

Cause: no later change broke it; the two commits that built it each left
keys out. 0431793db (v0.1.2674) gives a key its own list only when it is
added beside others and its list is short, and says "the keys it had keep
their lists". 1a67ca614 (v0.1.2942) carries on each Fetch only what a key's
list gained and lost, and only for a key that already had a list of its
own ("a key serving every model still does"). So every key on All models
stayed there through every Fetch: the provider's first key, keys added
before per-key lists, and a key whose list wasn't read in the 8s when it
was added. In the reporter's setup that is the key the provider was made
with, so the feature reads as gone.

Fix (refreshKeyModels): a key on All models whose fetched list leaves out
a model the provider's other keys list is given that list. A key whose
list has every model stays on All models, so later additions still reach
it; a lone key stays too. Keys with lists of their own work as before
(un-ticks and ticks kept).

The user's choice is never overridden: a key the user set to All models
(`accountmodels` with none, the picker's All models) is now remembered in
Provider.AccountModelsAll and left alone by Fetch. The editor's save keeps
it, a key replaced in place moves it (moveKeyed), accountSettings and
clone carry it, normalize drops a mark for a key that has a list.
Not covered: a key set back to All models before this release has no mark
and is narrowed once to its own list on the next Fetch; the user can
press All models again and it stays.

Tests:
- TestFetchTicksEachKeysListOnAllModels: keys saved with no lists are
  ticked on Fetch; a key set to All models before and after stays so
  through two fetches; an un-tick survives; a key whose list failed stays
  All models and gets its list once it reads.
- TestFetchLeavesALoneKeyOnAllModels.
- internal/gui TestFetchModelsTicksEveryKeysModels through the real
  routes: provider/save, provider/models, keys/add, accountmodels, the
  editor's save, against an httptest relay with a list per key.
- TestFetchRefreshesEachKeysModels and TestNewKeyTakesItsOwnModels pinned
  the old rule (sk-b / sk-old left on All models); they now expect the
  key's own list.

Broken by hand (mote): the old `was == nil -> continue` put back: the
new provider test, the GUI test (sk-a, the first key: [] want
[m1 m2 m3 m4]) and the two updated tests go red. The AccountModelsAll
check removed: sk-c/sk-d set to All models get narrowed, red. The editor
save not keeping AccountModelsAll: the GUI test's sk-c red.

Run (mote, at this tree): gofmt -l clean; go vet of the touched packages,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... ok;
go test -tags nogui -count=1 -timeout 45m ./internal/provider ./internal/gui
./internal/cli ./internal/gateway ./internal/tui: all ok (provider 223s,
gui 138s, cli 106s, gateway 797s, tui 26s).
GUI: account-models, account-models-available, account-refresh,
gateway-key-models, gateway-key-models-redraw (each in Chromium and
WebKit, as the files run): 94 of 94 pass.

Rebased on origin/main 8e97e26d6 (google.go, migrate_zcode.go): ./internal/provider
run again at this head, ok (157s).

Not tried: a real relay with per-group keys; Windows and Linux test runs
(nothing OS-specific changed). No app.js change.
2026-11-05 00:11:02 +08:00
yetone 8e97e26d67 providers: WorkBuddy's sign-in warns that Tencent may ban the account first
NancyTom on X (11-04): WorkBuddy accounts used from DeepSeek Harness
through magpie were banned, the international build's (WorkBuddy AI)
most; repliers saw the same. Changing DSH's prompt isn't a fix: the
plugin already rewords DSH's opener and moves the system prompt into
the first user turn (REFUSED.md), and the bans came anyway. So magpie
says it before an account is added, as it does for Claude, Zed, Qoder,
Factory, MiMo and Command Code.

- app.js: WorkBuddy and WorkBuddy AI carry risk with WORKBUDDY_RISK.
  A moved subscription (every user's now) gets it through subOf, so
  the plugin's sign-in waits behind "Sign in anyway" too.
- i18n.js: zh, zh-TW, ja, de.
- CLI: `magpie accounts add workbuddy|workbuddy-ai` asks the same
  (provider.WorkBuddyRisk, the window's words; a GUI test checks the
  two are equal).
- Core script budget: no raise; the SUBS header comment was cut down.

Run (mote, at 823e7c250 + this change):
- node --test workbuddy-risk (new), i18n-keys, i18n-en-no-cjk,
  commandcode-risk, zed-sub, claude-risk, qoder-cn-tile: 51 pass, 0 fail,
  chromium and webkit, en and zh.
- 83 GUI files matching add-|sub|risk|workbuddy|plugin-sign|move|
  deprecat|signin|i18n: 1166 pass, 20 fail at load ~60. Alone:
  signin-closes-sheet passes; found-skill-pick-remove (#5013),
  plugin-move-unserved (#4410) and routing-rule-remove (#5088) red
  alone the same way on a fresh origin/main e3ed21c7a (18 fail there).
- go test ./internal/cli ./internal/provider ok; -run Budget
  ./internal/gui ok; go vet cli+provider darwin and windows, provider
  linux ok (cli's linux vet needs GTK's cgo, not on mote or WSL).
- gofmt -l clean.
- Rebased on 9d0c9b41e (app.js changed under it, #5139): -run
  Budget|Risk ./internal/gui ./internal/cli ./internal/provider ok, and
  workbuddy-risk, i18n-keys, i18n-en-no-cjk, qoder-cn-tile, claude-risk
  39 pass, 0 fail at the pushed head.

Broken by hand: risk taken off both entries, workbuddy-risk went pass 1,
fail 14 (the built-in tiles and the moved plugin's sign-in each asked
the backend at once); the text-equality case stayed green, as it should.

Not run: the whole GUI suite (another session's full GUI suite was on
mote). Not tried: a real WorkBuddy sign-in; nothing here touches the
plugin or what is sent to Tencent.
2026-11-04 23:58:53 +08:00
yetone 9d0c9b41ea serve: follow an update put in where it runs from; a replaced magpie.real is magpie
acezan on Discord (Linux 5.15, 0.1.2959 to 0.1.2960): `magpie web` as a
system unit updated /root/.local/bin/magpie.real, and the user unit's
`magpie serve` (`magpie daemon install`) ran on for good from "magpie.real
(deleted)". The panel said an older magpie served the gateway, and its
"close it here" then said the port holder "isn't magpie" and left it.

Why serve stayed old: the app and `magpie web` follow the program they
started from (gui's followReplaced) and restart into an update; plain
`magpie serve` had no such look, and answered `magpie update`'s restart
ask (gateway.RestartPath) "unsupported". Nothing else can restart it
reliably: a system unit doesn't reach the user's `systemctl --user`, and
on a Mac the launch agent's serve (#4335) is the same serve. So serve now
looks itself (internal/cli/serve_follow.go): every 5s it checks its
program with update.Replaced; once replaced, it waits until the gateway
is idle (nothing in flight, 10s since the last end, as gui's idle rule;
after an hour, nothing in flight is enough), ends the plugin hosts and
runs the new program in its own place (update.Reexec: exec in place on
Unix, same PID, so systemd and launchd keep tracking it; a new process
on Windows). The restart ask now answers restarting/waiting/current. A
build that isn't a release never does it.

Why "not magpie": proc.IsMagpie judged the file name, and "magpie.real"
(the program the installer's wrapper script runs) didn't match. It now
trims ".real". And proc.RunsMagpie, used by the takeover and the port
check, also reads Go's build info of the running program (on Linux
through /proc/<pid>/exe, which still reads after the file is replaced)
and calls it magpie when its main package is github.com/yetone/magpie.
A process that isn't magpie is still never ended (the existing
"other-server" case passes unchanged).

Tests, each red on the old code:
- cli TestServeRestartsIntoAnUpdate: a copy of the test binary named
  magpie.real runs `serve` on a free port; a script renamed over it is
  run in its place with the same pid and args, and the old port stops
  answering. Old code: "serve ran on as the old version" after 40s.
- cli TestServeFollowWaitsForIdle: current / waiting / tool-chain gap /
  waitMost with a request in flight / idle / non-release.
- gui TestGatewayFixQuitsAReplacedMagpieReal: a fake older gateway named
  magpie.real, its file removed after start, is quit and the gateway
  served here. Old code: {OK:false Reason:not-magpie}, acezan's case.
- proc TestIsMagpie magpie.real case; TestRunsMagpieByItsBuild: a copy
  named server.real, its file removed, is told by its build (Linux
  /proc/<pid>/exe), and is not magpie with the real main path.

Run: the targeted tests above on Linux (wsl-run, magpie-desktop, -tags
nogui) and macOS (mote-run), all pass. Broken by hand on Linux: dropped
the ".real" trim, made RunsMagpie only IsMagpie, and set serve's follow
to nil; all four new tests went red (output above), restored after.
gofmt -l clean; go vet (darwin, GOOS=linux -tags nogui, GOOS=windows)
and builds on mote.

Not tried: a real systemd user unit or launch agent with a real update;
the Windows restart path (Reexec starts a new process) beyond vet; the
macOS TCC part of #4335 (this restarts the launch agent's serve into the
new bundle path only if that path is where it started from). #4335 stays
open, and ggbdpq's daemon.RestartReplaced patch there is not applied.
2026-11-04 23:55:14 +08:00
yetone e3ed21c7a2 provider: the ZCode mover's min is 0.1.50 (plugins#729)
zcode 0.1.50 reads a daily claim answered with code 1004 as the account
not being eligible for that plan now, and asks again in half an hour,
instead of reporting a failed claim (kongbai01203). Raising the min lets
keepMovedCurrent bring every moved user's plugin up to it.

npm view @magpie-community/opencode-zcode-auth version --prefer-online
(registry.npmjs.org) answered 0.1.50 before the change and again at
landing.

Run on mote (mote-run) at this tree, rebased on 0a6cccc3f (provider
 tests and vet run again after the rebase, ok in 198s):
- go test -timeout 45m ./internal/provider/: ok (133s)
- go test -run 'ZCode|Zcode|Moved|Mover' ./internal/gateway/: ok
- go vet ./internal/provider/ with GOOS=linux, GOOS=windows and darwin: ok
- gofmt -l internal/provider: clean

Not broken by hand: the change is the version string and its note; no
test pins the zcode min. Not tried: a real moved account updating to
0.1.50, and the full suite (runs after the tag).
2026-11-04 23:38:01 +08:00
yetone 0a6cccc3ff groups: a found group the user changed takes in a new provider with its model
Kxsg79bEYFP4 on X: magpie found auto/deepseek-v4.1-flash over two
providers, the user changed the group, then added a third provider (a
plugin's) with the model, and it never joined.

Cause: SaveGroup stores a changed found group under its auto-… id with
the members it had then, and buildGroupsIn skips the found group of
that id ("the user changed it: theirs now"). Nothing recorded which of
the found models the user had taken out, so a stored group could only
stay frozen. Plugin providers, id spelling and a one-time creation were
ruled out: a plugin's models are in providerEntries like any provider's,
and the found group itself has all three.

Fix: SaveGroup stores Group.Seen for an auto-… id: the models magpie
found in it by that save plus those the user names. Reading a changed
found group (joined) appends the found members it neither names nor has
seen, after the user's own. A model the user took out was seen and stays
out (magpie's default never overrides the user's value); a provider kept
out of found groups (AutoGroupSkip) doesn't join; with found groups off
nothing joins. Seen follows a provider's rename/SetModelID
(mapModelRefs) and a fold, and ShareGroup leaves it behind. A group
changed before this (no Seen) takes in nothing, since nothing says what
the user took out; its next save sees what is found then, and providers
added after that join. docs/subsystems/providers-accounts.md says so.

Tests: TestChangedFoundGroupTakesInANewProvider (join, order, routed by
FindGroup, the user's name/routing kept, taken out stays out before and
after joining, rename, skip, share), TestChangedFoundGroupFromBefore-
KeepsItsMembers (old stored group), TestChangedFoundGroupTakesInA-
PluginProvider (the reporter's surface: the fake plugin under real Bun).

Run on mote at base f280b12e5 plus this change:
- gofmt -l: clean
- GOOS=windows go vet ./...: ok; GOOS=linux go vet -tags nogui ./...: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/provider/
  ./internal/cli/ ./internal/gui/ ./internal/tui/ ./internal/agent/
  ./internal/gateway/: all ok (provider 214s, cli 86s, gui 127s, tui 23s,
  agent 372s, gateway 876s)

Broken by hand (each red, then restored):
- joined returning g unchanged (the old behaviour): all three new tests red
- dropping the Seen check and the legacy no-Seen guard: c came back at
  once, and the pre-Seen group took c in
- not mapping Seen in mapModelRefs: c came back as cee/… after Rename
- not clearing Seen in ShareGroup: the shared text carried it

Not tried: a real magpie with the reporter's providers; the GUI suite
(app.js is unchanged, /api/groups only gains a "seen" field); an editor
opened before a provider was added and saved after it treats that
provider as taken out.
2026-11-04 23:28:23 +08:00