Commit Graph
2027 Commits
Author SHA1 Message Date
yetone e6cdeac9c6 proc: with no WSL distro registered, or after wsl.exe asks to be updated, magpie starts no wsl.exe (TraderX219 on X)
TraderX219 on Windows: while magpie ran, a console window "WSL 必须更新到
最新版本……按任意键安装" came up every 20 to 30 seconds. magpie asked
wsl.exe for its distros (the running list retries every 30s after a
failure), and Windows' inbox wsl.exe answers each run on a computer
without a current WSL package by starting `wsl.exe --update --confirm
--prompt-before-exit` in a console of its own.

proc.Command, CommandContext and ProbeContext are where every wsl.exe
magpie runs is made (agent's wslRun/wslExec, wslrun, claudetui, the
library's rtk and MCP checks, the gateway's TUI helper), so both gates
sit in wslOff beside #1264's ErrWSLOff:

- The registry is read first (HKCU\...\CurrentVersion\Lxss, one subkey
  with a DistributionName per distro). With the key there or gone and no
  distro in it, wsl.exe isn't started: ErrNoWSLDistro. agent's wslList
  and wslrun's running list read that as "no distros", not as a failure
  or a hang, so nothing is retried every 30s. It is read at every start,
  so a distro installed later is seen at once. A read that fails is
  unknown: wsl.exe is asked as before.
- When a run's output (UTF-16LE or UTF-8, stdout and stderr) says WSL
  must be updated or installed, proc.WSLSaid writes settings' wsl-update
  mark (atomic, like wsl-hung) and no magpie process starts wsl.exe for
  6h: ErrWSLNeedsUpdate. The mark holds the WSL package version (HKLM
  Lxss\MSI Version) and the registered distros; a change to either
  clears it. A refused listing is unknown, so wsl.seen, WSLKept values
  and links are kept, never removed.

docs/subsystems/agent-wiring.md describes both.

Run:
- mote: gofmt -l (clean); go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...; go build for darwin, linux (nogui),
  windows: all ok.
- mote: go test -count=1 of internal/proc, agent, wslrun, library,
  sessions, claudetui at base 191f3c0af: all ok.
- mote, full suite through suite.lock (go test -count=1 -timeout 45m
  ./...) at base 191f3c0af: 88 packages ok, none failed.
- xiaomi-gpu (Windows 11, win-run): go test -count=1 ./internal/agent/...
  ./internal/proc/... ./internal/wslrun/...: proc and wslrun ok;
  agent has 25 reds, the same 25 by name on untouched origin/main
  191f3c0af. 24 were filed (#4115, #4786, #5068 and others);
  TestCodexOwnModelsFollowPicks wasn't, now #5605.
- xiaomi-gpu, read-only: TestWSLRegistryLive (MAGPIE_WSL_REGISTRY_LIVE=1)
  read the real Lxss key (magpie-fedora, Ubuntu, docker-desktop,
  magpie-3896, magpie-desktop; package 2.6.1.0) and ran `wsl.exe -l -q`
  (docker-desktop, magpie-fedora, Ubuntu, magpie-desktop): every listed
  distro is registered, so the gate never reads none while wsl.exe has
  some. magpie-3896 is registered in State 4 (uninstalling) and not
  listed, which only keeps wsl.exe being asked. No distro was stopped or
  changed.
- At the pushed head (rebased on f13d5f16f, which touches gateway and
  provider only), mote: go test of proc, wslrun, provider ok. agent's
  TestWSLMoreAgentsPick failed with "no space left on device" (mote's
  data volume was at 100%). Rerun: -count=3 -run 'TestWSLMoreAgents|WSL'
  ./internal/agent/ ok, and -run History ./internal/gateway/ ok. abe7b0063 (gateway) and
  e4fdf9ed3 (gui) landed after that run and were rebased onto unrun; they
  touch no file this change does.

Broken by hand, each red:
- registry check off: TestNoWSLDistroStartsNoWSL ("wsl.exe wasn't
  refused") and TestNoWSLDistroRunsNoWSL ("no distro registered read as
  wsl.exe failing").
- WSLSaid left out of agent's wslRun: TestWSLUpdateKeepsDistros ("wsl.exe
  -l -q was started: exit status 1").
- wslList's ErrNoWSLDistro as listed: TestNoWSLDistroRunsNoWSL.
- wslUpdateLately always false: TestWSLUpdateBacksOff ("wsl.exe run again
  after it asked for an update").

Not tried:
- The stub's window itself: xiaomi-gpu has a current WSL and distros, so
  it doesn't pop there. The fix wasn't run on the reporter's machine.
- The registry key missing (ErrNotExist) on a real Windows without WSL.
- The stub's real exit code and stdout: the update text is matched from
  the inbox wsl.exe's .mui strings (en, zh-CN) and the reporter's words.
- A wsl.exe that times out is not taken as asking for an update; the
  existing wsl-hung back-off still covers it.
2026-11-07 17:51:51 +08:00
yetone abe7b00631 gateway: a key+URL provider is sent the agent's own User-Agent by default, through a remote magpie too
nb5p runs a gateway of their own behind magpie and saw nearly every
request arrive as "magpie/<version>". The agent's User-Agent now goes
on as the agent sent it, wherever magpie isn't itself the client.

What each path sends now:
- Key+URL providers (official vendor keys and custom OpenAI/Anthropic
  compatible ones), on chat, Anthropic, Responses, Gemini,
  count_tokens, embeddings, images and videos: the agent's User-Agent,
  as sent. Before, this was the opt-in passUserAgent (#1851) and the
  default was magpie's. The opt-out is magpieUserAgent:
  `magpie provider set <id> user-agent=magpie`, or untick "Send the
  agent's own User-Agent" in the editor. passUserAgent is no longer a
  field, so a file that set it true reads the same as the new default.
  A provider someone turned back off after opting in can't be told
  apart from one never touched, and now sends the agent's too.
- When the agent sent no User-Agent, and on magpie's own requests
  (classifier magpie-router/1, vision, search, the image tool, model
  lists): magpie's, unchanged.
- A header.User-Agent the user set: still wins over both.
- Subscription accounts (Claude, Codex, Copilot, Google, ZCode…),
  plugins, and OpenCode/Cline/Kilo: unchanged. Their signing sets the
  official client's UA (provider.PassesUserAgent still refuses an
  Account or OwnClient).
- Claude Code and Codex header copies: unchanged.
- Remote magpie: the near magpie still asks as magpie/<v>, because the
  far end trusts X-Magpie-Agent/Via only from that. It now adds
  X-Magpie-User-Agent (passOnUA, on forwardOnce, embeddings, draw and
  video; the classifier's decision request names none). The far end
  takes it only from a magpie/ request (callerFrom) and strips it on
  arrival (withCaller). agentUA/callerUA then hand it to userAgentFor,
  so the far vendor sees the agent's. A client that writes the header
  itself, straight to a magpie, is ignored. magpie's own UAs are never
  relayed (magpiesOwn).

Vendor check: invalid-key requests with magpie/, claude-cli, a Chrome
UA and pi's went to Anthropic, OpenAI, Gemini, DeepSeek, Moonshot, Kimi
For Coding, Zhipu, OpenRouter, xAI, DashScope, MiniMax, Volcengine Ark,
Groq and Mistral. Every vendor gave the same auth error for every UA,
so no edge-level UA gating was seen. Kimi For Coding's agent allow-list
sits behind a valid key, which wasn't tried.

Run (mote):
- go test -run 'UserAgent|RemoteMagpie|ZCode|Blocked' ./internal/gateway: ok
- go test ./internal/provider ./internal/cli ./internal/gui: ok
- node --test provider-user-agent, provider-native-compaction and
  i18n-keys (chromium and webkit; en/zh/zh-TW/ja/de; 900 and 440 wide):
  123 of 124 pass. The red is i18n-keys "a plugin's words are its own"
  (plugins' words said in files this change doesn't touch), already
  filed as #5327/#5332, #5426 and #5482.
- gofmt -l clean; go vet; GOOS=linux -tags nogui and GOOS=windows vet:
  ok at the rebased head (on f13d5f16f). Targeted gateway, provider,
  cli and gui packages (UserAgent|RemoteMagpie|ZCode|Blocked|Budget)
  ok there too; whole packages ran at the pre-rebase base 4461957b9.

Broken by hand:
- PassesUserAgent back to opt-in: TestUserAgentPassedOn/default,
  TestUserAgentFor, TestRemoteMagpieRelaysUserAgent, TestPassesUserAgent
  and TestProviderUserAgentPair go red.
- agentUA's relay off, or passOnUA a no-op: TestRemoteMagpieRelaysUserAgent
  goes red; the far vendor is asked as magpie/dev.
- withCaller's Del(X-Magpie-User-Agent) removed: stays green. Nothing
  copies incoming headers to a vendor today, so the Del only guards
  against that.

Not tried: a real remote magpie on two machines, a real valid-key vendor
request, and nb5p's own gateway.

Reported-by: nb5p on Discord
2026-11-07 17:44:31 +08:00
yetone f13d5f16f4 history: today's plain file takes no room from the days before it
pruneHistory held every file in routing/ to historyBytes (200 MB),
today's plain .jsonl included. Today is never dropped, and its file is
written plain, about ten times what it is once gzipped (this Mac's
2026-11-06: 5,785 routes, 1.1 MB gzipped). On a busy gateway, today's
file took the room of the days before it, and every prune (the first
save after a start, then hourly) dropped the oldest days until it fit;
past 200 MB plain, it dropped every day but today. The Context tab then
listed only today's sessions, while Usage's Requests, read from the
ledger, kept them. The budget now holds the days that are over; today's
file is counted from the next day on, gzipped.

From linkaww's report: on their Docker magpie, after each nightly
update, Context lists only today's sessions while Requests keeps the
older ones. NOT confirmed as their cause. A real Docker run on
xiaomi-gpu (the image built from this tree, a named volume on /config,
a fake upstream in a second container) kept every session across
`docker restart` and across rm + run on the same volume, as the
documented update does; so did a sandbox chain (desktop magpie ->
remote magpie with a gateway key, the remote restarted). A plain
restart loses nothing; this budget is the one path found that drops
past days while the ledger keeps them. Their routing/ listing would
tell.

History already dropped is gone: the routing days are their only copy,
and the ledger keeps no prompt tokens or sessions to rebuild them from.

Run (mote, at 4461957b9 + this):
- TestHistoryTodayTakesNoRoomFromPastDays, new: red on the old
  history.go (kept [2026-09-30], want the three days before it too),
  green with the change.
- go test -run 'History|Route|Prune' ./internal/gateway: ok.
- go test -run Context ./internal/gui: ok.
- gofmt -l; GOOS=linux go vet -tags nogui and GOOS=windows go vet
  ./internal/gateway: clean.
Not tried: linkaww's own container and data; the full suite (run after
the tag, per the loop rules). Not changed: the remote-magpie hop passes
no x-claude-code-agent-id on, so a Claude Code subagent's calls through
it count as the main session's on the remote's Context tab; a separate
change.

Reported-by: linkaww on Discord
2026-11-07 17:30:06 +08:00
yetone 191f3c0af1 gateway: POST /v1/decisions goes to OpenAI, Azure OpenAI or another magpie
A Discord user's POST /v1/decisions was answered 404 ("magpie serves
/v1/chat/completions, ..."). It is OpenAI's Decisions API (gpt-6-luna):
one input, up to 400 questions, typed answers, input tokens billed only.

The shape was taken from openai-python (resources/decisions.py,
types/decision_create_params.py, types/decision.py, added in #4033 on
10-06) and the Decisions guide, not guessed: POST /v1/decisions, a JSON
body of model, input (a string or messages/items with input_text,
input_image as a data or http(s) URL, JSON parts; function and custom
tool calls and their outputs), questions (predicate / choice / score),
and optional prompt_cache_key, prompt_cache_options, safety_identifier.
The answer is {answers, model, usage}, not streamed; usage.input_tokens
includes input_tokens_details.cached_tokens and cache_write_tokens. The
Azure client sends it on the v1 API (/openai/v1/decisions), the model in
the body.

- decide (decisions.go) goes through serveRetrieval as embeddings and
  rerank do, body as sent with only model changed. So a disabled model,
  a key's models, accounts and spent limits, pause rules, keys/accounts
  of the provider, masking and the Routing page hold here as on every
  route.
- Only a provider canDecide takes is sent it: an OpenAI API key on
  api.openai.com, Azure OpenAI (IsAzure, at its OpenAIBase, so
  /openai/v1/decisions with api-key), or another magpie. Anyone else (a
  relay, a plugin, a ChatGPT sign-in) gets a 400 that says who serves
  it, checked in serveRetrieval's try loop beside the no-OpenAI-API
  check (refusingRetrieval), never the vendor's 404; a group moves on.
- A bare gpt-6-luna is a kind group "decision" (servesDecision), so a
  relay that lists the same id is never its member.
- Usage is recorded as "decisions" (countedRetrieval): input less the
  cached and cache-written tokens, those as CacheRead/CacheWrite, and
  no output, so gpt-6-luna's own models.dev rates price it as OpenAI
  bills ($0.10/1M input, cache read/write at their rates).
- /decisions joins the one-port client prefixes, another magpie's URL
  suffixes, the 404's route list and info's apis. The readonly, LAN
  and CORS guard tests list the route.
- native_endpoints is left alone: it names the chat APIs a model is
  relayed on (Cursor's names, a remote's API choice).
- docs: gateway-routing.md has a Decisions row; reference.md a section.

Run on mote at this tree (mote-run): gofmt -l clean; go vet of gateway
and provider; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet
./...; go build ./..., linux nogui and windows builds ok;
go test -count=1 -timeout 45m ./internal/gateway ./internal/provider
./internal/usage: ok (gateway 413s, provider 88s, usage 18s).

Red on the old code (e0930b1de, the new tests copied in): every
TestDecisions* is red with magpie's 404.
Broken by hand, each red: refuses always "" (the relay is sent it:
TestDecisionsRefusedWhereNotServed); the cache split not read
(Input 1200, CacheRead 0: TestDecisionsReachOpenAIAndAzure); canDecide
without the api.openai.com check (TestCanDecide, the relay sent it);
/v1/decisions out of the remote suffixes (TestRemoteMagpie).

Not tried: a real OpenAI Decisions request, or a real Azure resource.
Tests reach only httptest servers (OpenAI's host through the provider's
proxy).
2026-11-07 16:05:37 +08:00
yetone 325dc3ab32 claude-tui: a Claude Code that draws nothing is said with what it waits on, and its turn isn't waited out twice
sowhynot (v0.1.3222, macOS): every interactive run ended "Claude Code
showed no prompt in 45s: nothing on its screen (0 bytes read)", and the
bridge then started a new Claude Code told the whole conversation, which
waited out another 45s before the turn was answered 502.

Cause class: Claude Code blocks before its first draw on something it
waits for and writes nothing to the pty. Reproduced on mote with real
Claude Code 2.1.319 (npm latest) in a sandbox HOME: its read of the
"Claude Code" Keychain item is a synchronous `security
find-generic-password` with no time limit (its other Keychain reads have
2s/10s limits), so a Keychain waiting on an allow window or a locked
keychain gives exactly "0 bytes read" at 45s. Its network waits
(remote managed settings and policy limits, for a setup-token or team
account with --mcp-config) are bounded at ~30s and draw after, so they
don't give 0 bytes.

- claudetui: with 0 bytes read, the reason adds what Claude Code runs
  (its descendants from ps, longest first) and how much it holds; a
  Keychain read is named with its item and what to do. Other commands
  are named by program (and an interpreter's script) only, never their
  arguments. macOS and Linux; Windows says what it said before.
- gateway: a helper that ends saying why the interactive mode didn't
  come up is tuiNoStart, not tried again told the whole conversation,
  unless Claude Code ended itself before its prompt
  (claudetui.EndedEarly, the "No conversation found" case the retry is
  for).
- No early end on 0 bytes: a Keychain window may still be answered.
  No -p fallback: removed on purpose in e5f66f8a6, and -p waits on the
  same things.

Run (mote, at this tree on 05f6fd423; after the rebase onto 0978a6868, the new claudetui tests, TestShimNeverPrints, TestShimEndsAtItsCallersDeadline and -run TestClaudeTUI in gateway again: ok):
- go test -count=1 ./internal/claudetui/: ok
- go test -run 'TestClaudeTUI' ./internal/gateway/: ok
- go test -run 'TestClaude|TestSubscription' ./internal/gateway/: ok
- wsl-run (magpie-desktop): the new claudetui tests and
  TestShimEndsAtItsCallersDeadline: ok
- go vet darwin, GOOS=linux and GOOS=windows -tags nogui for
  claudetui and gateway: ok
- real Claude Code 2.1.319 under the rebuilt helper, sandbox HOME, a
  `security` on PATH that never answers: "...(0 bytes read); it waits on
  the macOS Keychain, whose `security find-generic-password` read of
  "Claude Code" hasn't answered in 33s: ..."

Broken by hand: with undrawn's result dropped,
TestShimSaysWhatAnUndrawnClaudeWaitsOn fails both cases; with the
gateway check off, TestClaudeTUINoPromptNotTriedAgain/no_prompt fails
"the helper started 2 times, want 1".

Not tried: a real Keychain allow window or a locked keychain, the
reporter's own machine (unconfirmed it is the Keychain; Gatekeeper or
endpoint software holding the exec fits the 51s too), a real Pro or
team account, Windows (no ps read there).

Reported-by: sowhynot
2026-11-07 15:17:47 +08:00
yetone 0978a68681 gateway: a ZCode trial entry's 3012 rests that entry, not the account
young02036 (Discord, 11-07): on an account with a GLM Coding Plan,
GLM-5.3-Flash-Trial answered 405 code 3012 (ZCode's risk control) while
the account's paid models worked. The plugin's 3012 words read as
failRestricted, which rested the whole account for two hours
(restrictedRest), so magpie stopped sending the paid models the account
still served. A -Trial entry goes to zcode.z.ai's Start Plan, and a dual
account's plain models to its GLM Coding Plan on api.z.ai, so the 3012
is zcode.z.ai's: zcodeTrialRestricted rests the entry alone (restID),
as zcodeTrialBlocked already does for the edge block page. On a
gift-only account the plain model goes to zcode.z.ai too, gets its own
3012 and rests the account, at the cost of that one more refused
request per rest. riskRefused still walls the provider's other accounts
off for the rest of the request.

TestZCodeTrialRefusalRestsTheTrialAlone: "trial risk control" now wants
the entry's rest and the account's GLM-5.3 served after it; new cases
"plain risk control" and "another vendor's risk control" want the
account's rest. docs/subsystems/gateway-routing.md says so.

Run (mote): go test -count=1 -run 'TestZCode|TestRisk|TestRestricted|TestMovedZCode'
./internal/gateway/ ok; gofmt -l clean; GOOS=linux and GOOS=windows go
vet ./internal/gateway/ ok.
Broken by hand: the routing.go check removed, trial_risk_control red
(rested "zcode@api key", want ".../GLM-5.3-Flash-Trial"), then restored.
Not tried: a real 3012 account (the reporter's); the full suite runs
after this push.

Reported-by: young02036
2026-11-07 15:13:03 +08:00
yetone 75d0fc3aca gui: on macOS 27 the main window keeps its toolbar, which no longer changes the corners (#3949)
TestMainWindowCorners/macOS_26_SDK was red in every run on mote
(macOS 27.2). The test was right and the code wrong: insetLights took
the main window's toolbar off whenever AppKit gives the program the
design of macOS 26 (designOf26), on the grounds that a toolbar gives a
window Finder's larger corners there. macOS 27 doesn't: a window with a
toolbar and one with a plain title bar both get 16pt corners (AppKit's
_cornerRadius and _cornerMask are the same for both, measured on mote
with a 26.2-SDK probe). So on 27 the toolbar went for nothing, and the
lights, the title bar's height, first presses and sheets were all held
in place by hand where the toolbar would have kept them itself.

insetLights now also asks toolbarRounder: the window's corner radius
held against a window of its style with no toolbar, never shown. The
toolbar is taken off only when it makes the corners larger (or when
AppKit doesn't tell the radius, as before). The test is unchanged
except its comments: it already checks, by measurement and not by OS
version, that the toolbar stays where it doesn't change the corners
and that the main window has a plain title bar's corners,
so on macOS 26 a toolbar kept wrongly is red too.
docs/subsystems/gui-shell.md says so.

Run (mote, macOS 27.2, arm64, at this tree on 05f6fd423):
- go test -count=1 -run 'TestMainWindowCorners$|TestMainWindowRightToLeft'
  -v ./internal/gui: both subtests and right-to-left pass; macOS 26 SDK
  now reads "toolbar kept true", corners 16/16/16, lights, 66pt title
  bar, presses and sheet the same as the toolbar window's.
- go test -count=1 ./internal/gui/...: ok (133s).
- gofmt -l . (empty), go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build: ok.

Broken by hand: toolbarRounder made to return YES (the old behaviour):
TestMainWindowCorners/macOS_26_SDK red at "a toolbar doesn't change the corners" on all three stages,
as in #3949. Restored.

Not tried: macOS 26 (no macOS 26 test machine; heavy runs stay off this
Mac), where toolbarRounder must still read 26pt against 16pt and take
the toolbar off; CI's macOS job runs macOS 15, which never reaches it.
No screenshot of the corners on mote (screencapture has no Screen
Recording permission over ssh); the corner mask was compared instead.
The full suite runs after the push.
2026-11-07 15:04:26 +08:00
5c5160c940 provider: a model's test asks the account or key routing sends it to (#4992)
On a provider with several accounts or keys whose models differ (a
magpie-newapi pool, a relay whose keys sit in different groups), "测试模型",
the right-click test and the provider's Test asked the first account or
key. A model that only another account serves failed (grok-4.7: 503 "no
available channel") while real requests were answered, because the
gateway's perKeyEvery passes over accounts and keys the user set not to
serve the model (AccountModels, #474) and accounts whose own list lacks
it. The test path had none of that.

Cause: the choice lived in the gateway only (perKeyEvery and accountsOn
in gateway/fallback.go), so the test had nothing to share. keySeeing
checked the key's list but not AccountModels.

Change:
- internal/provider/route_accounts.go: AccountsOn, AccountsFor and
  KeysFor are the routing choice. The code moved there from perKeyEvery
  and accountsOn, and the gateway's caps are passed in as a held func.
- gateway/fallback.go: perKeyEvery and accountsOn call it. They behave
  as before.
- test.go:
  - testOne (the model test and the right-click test) runs as
    AccountsFor's first account. A model barred on every account is
    not asked; it says so.
  - The provider's Test picks key and model together (testWith), then
    the account that serves the model (routedTo).
  - The log row names the account asked (loggedAs).
  - keySeeing and testModel take keys from KeysFor and AccountServes.
- detect.go: detectOne, a sibling, asks each model with keySeeing's key.
  Before, it asked the endpoint's first key.
- Not changed: AskSystemOne's decision model still asks the provider's
  own account.

Tests (internal/provider/test_account_route_test.go), on a two-account
fake plugin and a relay that answers one key:model:
- TestModelTestAsksTheAccountThatServesIt
- TestModelTestPassesAnAccountWhoseListLacksIt
- TestProviderTestAsksAnAccountThatServesItsModel
- TestModelTestUsesTheKeyServingIt
- TestModelTestBarredModelIsNotAsked
- TestDetectModelsUsesTheKeyServingIt

All six are red on origin/main e932cd258 (test file alone): "Bearer a@fake
/v1/responses" 503, sk-a asked m-b, and so on. All six are green after.

Run on mote:
- go test -count=1 -timeout 45m ./internal/provider ./internal/gateway: ok
  on e932cd258. After the rebase onto d9f63dfee: go vet, the whole of
  internal/provider, and internal/gateway -run
  "Fallback|PerKey|Account|Key|Cap|Spend", all ok.
- go vet, GOOS=linux -tags nogui go vet, GOOS=windows go vet for both
  packages; gofmt -l clean.
- node --test with the GUI files that test models (model-test-as,
  model-test-one, model-test-stop, model-test-why,
  test-models-key-hint): 60/60, Chromium and WebKit. They fake /api, so
  they don't reach this change.

Broken by hand:
- `|| true` on Lists in AccountsFor: TestModelTestPassesAnAccountWhoseListLacksIt
  and the gateway's TestCodexProviderListsEveryAccountsModels go red.
- The AccountServes case in KeysFor turned off:
  TestModelTestUsesTheKeyServingIt goes red. The gateway goes through
  the shared code.

Not tried:
- A real newapi pool or a real multi-account sign-in.
- Usage and spend caps are not applied to a test (held is nil).
- The Windows and Linux runs.
- The full suite was started on mote after the push, under suite.lock.

Reported-by: scutken
Co-authored-by: xiejiayu <scut_ken@qq.com>
Co-authored-by: Jackzigen <zigenhan@gmail.com>
2026-11-07 13:34:54 +08:00
yetone 32fc5809e1 agents: OpenMausBot gets magpie as an engine of its own, written as its own Claude endpoints are (a user on X)
A user on X asked for OpenMausBot (github.com/milind-soni/OpenMausBot,
read at 516ca75; released 0.1.145). Its bots run on engines from
`instances` in ~/.openmausbot/config.json ($OMB_DATA_DIR,
server/config.ts:713). Without this, a Claude bot reached magpie only
through ~/.claude/settings.json, and its picker listed Claude's static
models alone: OpenMausBot doesn't read the model from env
(readClaudeModelCatalog, claude.ts:296-316).

- openmausbot.go writes `instances.magpie` in the shape of OpenMausBot's
  own "Claude endpoint" (newClaudeEndpoint, claude-endpoints.ts:91-139):
  - driver claudeAgent, access custom
  - config.configDir is <data>/providers/magpie. Given that,
    OpenMausBot starts Claude Code with that CLAUDE_CONFIG_DIR and
    strips account keys the engine doesn't set (claudeEnvironment,
    claude.ts:111-136, 158-179), so the engine owns its routing.
  - requireApiKey
  - ANTHROPIC_BASE_URL, AUTH_TOKEN, API_KEY and MODEL point at the
    gateway
  - endpointModels holds magpie's models, kept to the ids
    CLAUDE_MODEL_ID accepts. One bad id makes OpenMausBot refuse the
    whole engine (claude.ts:636).
- A non-empty `instances` is the whole fleet (config.ts:1173). With
  none saved, magpie writes DEFAULT_FLEET (instance-fleets.ts) beside
  magpie, stashed as openmausbot.fleet. Off takes the fleet out again
  if the user hasn't changed it.
- What stays the user's: the engine's name, a model they picked from
  the list, their other env and an inherited `cli`.
- Check reports the base URL drifting away from the gateway.
- OpenMausBot reads config.json once at start (index.ts:780), and an
  engine edited in it writes back the fleet it holds
  (routes/instances.ts:132, config.ts:997-1012). So Set is refused
  while it runs (errOMBRunning), and the notice asks to quit it first,
  since Windows can't tell.
- ListOnly, ListsModels, OMB_DATA_DIR in agentenv. The icon is
  OpenMausBot's build/icon.svg (Apache-2.0).
- i18n in zh, zh-TW, ja and de. Docs: reference, agent-wiring, both
  READMEs.
- Codex bots use ~/.codex (codex.ts:373-386), which the Codex wiring
  already covers.
- The agent package's TestMain holds ombRunning false. An OpenMausBot
  open on the test machine refused every test that turns magpie on for
  each agent: my own sandbox OpenMausBot on mote turned
  TestSyncKeepsAnAddressOnAnotherMachine, TestListOnlyAgentsReadConnected
  and TestReverseProxyIsStillMagpie red. With a process named
  openmausbot running, they now pass. LiveAgent's, OpenPencil's and
  NewMax's running checks have the same hole and are left to #5587.

Run (all on mote):
- gofmt -l: clean
- go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows: ok
- go build for the same three targets: ok
- go test -tags nogui ./... -timeout 45m at e1453a168 (this change on
  origin/main 30ae0e3f9): 88 packages ok, none failed. Rebased after
  it onto e932cd258, which changes internal/library and adds one GUI
  test only. At the pushed head: go vet of internal/agent and
  internal/library, and go test of internal/agent, agentenv and
  appdir, all ok.
- GUI: the 71 files this change reaches, in chromium and webkit, every
  language they cover: agent-*, agents-*, i18n-*, icon-*, gui-de,
  gui-ja, gui-zh-tw, about-notices, deprecation-notice, header-relang,
  market-icon-corners. 1145 of 1146 pass. The one red is i18n-keys'
  "a plugin's words are its own" for plugins' "Use the library's",
  "No session ID" and "View routing", the same on main and filed
  (#5332, #5426, #5482). The whole GUI suite was started too and
  stopped at 369 ok, 0 failed: at ~5h on mote it runs after this push.

Real OpenMausBot: 0.1.145's arm64 app was run on mote, its own server
(ELECTRON_RUN_AS_NODE, Resources/server/index.js) with HOME and
OMB_DATA_DIR in a sandbox, on a free port, against a config.json
magpie's Set wrote. /api/instances listed 28 engines, among them
`magpie`: access custom, claudeEndpoint at http://127.0.0.1:3425, and
models relay/glm-4.6 and relay/gpt-5.5 in its picker, with the first as
default. It read "unavailable: `claude` CLI not found" only because the
sandbox PATH had no claude. The file was left as magpie wrote it.

Broken by hand:
- The fleet not written: TestOpenMausBotEngine red.
- The model-id filter taken out: TestOpenMausBotEngine and
  TestOpenMausBotKeepsTheUsers red ("relay/glm 4.6 (beta)"). Green
  before a bad id was added to the fixture, so one was added.

Not tried:
- A bot turn through Claude Code to a gateway. No claude CLI or
  account on mote.
- The desktop app's window, Linux and Windows builds.
- An OpenMausBot running while magpie writes. The refusal is
  unit-tested only.
2026-11-07 13:13:36 +08:00
yetone 82403f9f6d claude: /usage is read through -p, never the interactive mode, which opened idle accounts' 5-hour window (#5582)
Since v0.1.2635 (ccd746e03), when the interactive mode is on (the
default), magpie read the plan's allowance by starting the interactive
Claude Code in its helper and typing /usage there (claudeUsageTUI). The
interactive Claude Code 2.1.316 sends a model request as it starts,
before anything is typed. That is probeQuotaStatus: haiku, max_tokens 1,
content "quota". It sends it unless CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
is set, and that variable also keeps /usage from loading. The request
counts, so on an account with no 5-hour window it started one. The
reporter's reads came at magpie's start and when a window ended, and
each opened a window with warm-up off. Their counterexample (11-01,
v0.1.2433, before ccd746e03) read /usage through -p and opened nothing.

Recorded (sandbox HOME and CLAUDE_CONFIG_DIR, a fake sign-in, the real
Claude Code 2.1.316 behind a recording proxy that answers everything
itself, so no account was spent):
- magpie's interactive args and env, in a pty. At start, before /usage
  was typed:
  POST api.anthropic.com /v1/messages?beta=true
  {"model":"claude-haiku-4-5-20251001","max_tokens":1,
   "messages":[{"role":"user","content":"quota"}],...}
  then GET /api/oauth/usage once /usage was typed.
- The same with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1: no POST, but
  no /api/oauth/usage either, and the panel says "Failed to load usage
  data". This can't be the fix.
- `claude -p /usage` with claudeUsageArgs and claudeUsageEnv: no
  /v1/messages at all, only GET /api/oauth/usage (plus profile and
  bootstrap GETs). It printed "You are currently using your subscription
  to power your Claude Code usage" / "Current session: 13% used · resets
  Nov 7 at 4pm (Asia/Shanghai)" / "Current week (all models): 4% used ·
  ...". ccd746e03 said -p's /usage tells only the session's cost. In
  2.1.316's source that is only for a sign-in without a subscription or
  the user:profile scope, such as a setup-token, which provider never
  reads (errClaudeSetupToken), or an API key.

Fix: claudeUsage always runs `claude -p /usage`, with the interactive
mode on or off. claudeUsageTUI and claudeTUIUsageArgs are gone. This is
the one choke point (provider.UsageClaudeVia -> runClaudeUsage) for
every magpie read of Claude usage: the signed-in account's card,
saved accounts (readSavedClaudeUsage), the 8-day keep-alive, the
used-up switch's spare reads and refreshes. The other interactive
starts are the bridge's turns, the warm-up and the model test. Each one
sends a model request the user asked for, and each runs with
cleanClaudeEnv's CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1, so the
startup probe isn't added there. Not changed: claudetui still takes a
typed /usage, and magpie no longer sends it.

Docs: docs/subsystems/claude-subscription-bridge.md says why and
removes the wrong -p claim. The comments in claude_warmup.go, tui.go
and claude_usage_cli.go are updated to match.

Tests: TestClaudeUsageStartsNoInteractiveRun replaces
TestClaudeUsageTUIOn, TestClaudeUsageTUIWorksInMagpiesFolder and
TestClaudeUsageTUISaysItsDeadline. With the interactive mode on, it
checks that a read of the signed-in account and of a saved one starts
no helper, runs -p /usage, and leaves the traffic variable off. The
"usage" rows of TestClaudeOneOffTrustsMagpiesFolder and
TestClaudeOneOffFailureLogged are removed, since a /usage read is no
longer an interactive one-off run. Their "test" rows stay.

Run (mote, at this tree on origin/main 665b9aff1; after the rebase on 9e6687e3a, vet and claudetui plus gateway's ClaudeUsage|OneOff|Trust|TUI tests again: ok):
- gofmt -l internal/gateway internal/provider internal/claudetui: clean.
- go vet for darwin, and for linux and windows with -tags nogui:
  ./internal/gateway ./internal/provider ./internal/claudetui ok.
- On mote: go test -count=1 -timeout 45m ./internal/provider ./internal/claudetui: ok (114s, 110s);
  go test -run 'Claude|Usage|Warm|Trust|OneOff|TUI|Shim|Guard|Loop|Budget' ./internal/gateway: ok (89s).

Broken by hand: with HEAD's claude_warmup.go (its claudeTUIOn branch
back) and the new test, TestClaudeUsageStartsNoInteractiveRun went red:
"a /usage read started the interactive Claude Code: claude-tui-helper
.../claude -p --output-format stream-json --input-format stream-json ...".

Not tried: a real account's -p /usage on this build. The windows output
above comes from the recorder's fake usage reply, and the reporter's
v0.1.2433 readings came from -p. Not tried: an Enterprise account whose
usage reply leaves the windows out. -p then prints only the
subscription line, which reads as "temporarily unavailable" and keeps
the last reading, where the interactive panel had said no window has
started. Not run on Windows or in WSL. The -p read there is the same code
(claudeUsage); the interactive read had run on Windows too.
Not run: the full ./... suite (mote's suite.lock had four full runs
queued).
2026-11-07 11:52:30 +08:00
yetone 665b9aff12 gateway: a reply of several requests tells the last one's prompt, bills them all
Claude Code reads a reply's input, cache_creation and cache_read as how
full its conversation is. A reply more than one upstream request made
summed all three across them. In the bridge: Claude Code's own
ToolSearch/WebSearch going on into the answering message, a TUI message
written after its call was told (lateUsage), a cut stream's retry
(b42ff722). Each later request re-sends what the earlier one had, so the
reporter's TaskStop reply after a ToolSearch said cache_read 1,154,857
(577,009 + 577,848) and cache_creation 829 (253 + 576) for a ~577k
conversation, and Claude Code compacted early. 12 of their 30 replies
after ToolSearch were about 2x.

The translated route summed the same way across its tries (#5115): the
empty reply asked again (#667), a loop's re-ask (#1359), a cut reply's
continuation (#853), and search.go's web search rounds. The Anthropic
passthrough has no in-reply fold; each try is its own call.

Usage.after (claude_subscription.go) replaces plus at these joins: the
client is told the last request's input, cache writes and cache reads,
and every request's output and reasoning (all of it was streamed). The
earlier requests' prompts go in Deferred, which the ledger bills
(billed()) and no encoder tells. Usage.restart makes a later request's
prompt counts replace the earlier's, a zero too, so a later request that
reads nothing from the cache isn't told, or billed again, the earlier's
reads. Cache writes are last-only for the client as well: the later
request reads what the earlier wrote, so summed they count it twice.
ggbdpq's #5115 analysis named the translated route's case; no code of
theirs was used.

Tests (usage_last_prompt_test.go), on the reporter's numbers:
- TestClaudeOwnCallReplyTellsLastPrompt: bridge, told 6/576/577848,
  billed 8/829/1154857; and a second request that missed the cache.
- TestClaudeTUILateMessagePromptNotTold: interactive mode's late message.
- TestRetriedReplyTellsLastPrompt: Gemini three reasoning-only replies
  then an answer, Chat and Anthropic clients; ledger has all four.
- TestLaterTryZeroCacheReadNotTold: a continuation and a search round
  whose later request reads 0 from the cache.
Tests that pinned the summed client numbers now pin the last request's
and check the billed sum (CachePartialUpdateMatrix, Probe1717 zero split,
cut stream retry, own WebSearch, search rounds, StreamCutUsage renamed
TestStreamCutUsageTellsLastTry).

Run (mote, Go 1.26.8, -tags nogui):
- The new tests on origin/main ca77a9ea8: red, the client told
  8/829/1154857 (the report's numbers), prompt_tokens 2,000,000 for
  four 500k tries.
- Broken by hand: restart dropped -> TestClaudeCutStreamGoesOnInRetry
  and the cache-missed case red (reads billed twice); after() put back
  to plus -> 12 tests red; restart on the translated tries dropped ->
  TestLaterTryZeroCacheReadNotTold red (cache reads 200 billed, 111
  told). The last one was green before that test was added.
- go test ./internal/gateway/ whole: ok except
  TestClaudeInternalMessagesKeepCacheWrites, which pinned the sum and
  was updated after; that test with the usage, cache, search,
  continuation and TUI tests then ok (61.8s).
- go vet ./internal/gateway for darwin, linux and windows; gofmt clean.
- The full suite runs after the push (mote's suite lock held 3h+ by
  another session).

Not tried: a real Claude Code account or the real TUI, the reporter's
session, a real Gemini/translated provider, Windows or Linux runs of
the package.

Reported-by: sleepy_shibe (Discord)
2026-11-07 10:03:52 +08:00
yetone fd0cac2505 gateway: a full window of some models only rests that model (plugins#817)
A subscription account that fails with a window full rests until that
window renews (restAfter's "window" branch). The rest was always on the
account (restKey), whatever the window counted. Now, when every full
window that counts the model counts some models only (Allowance.Pooled,
the same reading a quota refusal already narrows by), the model rests
(restID), and its siblings in their own windows still answer. A full
window of the whole account rests the account as before.

zane668's ZCode Start Plan gift account: GLM-5.3's daily bucket was
spent, and the plugin passed its 200 "exceed quota limit" on as it came.
The gateway read that as a 502 that did not stream (failOther), the
window branch took GLM-5.3's full bucket, and the account rested ~22h.
GLM-5.3-Flash, with its own bucket 71% left and a weekend bucket unused,
was skipped by every group. zcode 0.1.53 now says that answer as a 429
(failQuota, which pooled already narrowed). This change is for any
plugin or built-in whose failure isn't worded as quota while a
per-model window is full.

Checked the reporter's reading before changing anything: spentUp runs
only on the forcedGift and freeGift paths, and the plain path returns
done(kept(res)). failure(502, "... did not stream: exceed quota limit")
is failOther. pooled is computed for failQuota only, and the window
branch set modelBackoff false and kept restKey.

TestScopedWindowFullRestsTheModelOnly builds the allowance through
PluginAllowanceForTest from the plugin's startUsage windows as the
report read them (GLM-5.3 100%, Flash 29%, the weekend bucket 0%):
- the 502 that did not stream rests GLM-5.3 alone till its reset, and
  Flash not;
- the plugin's new 429 1005 does too;
- with a whole-account plan window full as well, or alone, the account
  rests and Flash with it.
Not changed: the Codex out-of-credit branch's window. Its credits are
the account's.

Run at 93c258ef9 on mote: go vet ./internal/gateway ok; go test -run
'Rest|Window|Pool|Quota|Spent|Narrow|Renew|ZCode|Zcode|Backoff|Fail'
./internal/gateway ok (70.8s). Broken by hand: windowModel left out of
the restID condition, and the 502 subtest fails ("rests
zcode@me@zcode (model ""), want the model alone"). The 429 subtest
passes either way (pooled already covered it), as a guard.

Not tried: a live ZCode account with a spent bucket. The full suite
runs after the push.

Reported-by: zane668
2026-11-07 09:15:16 +08:00
yetone 8e350155b6 routing: a provider set to Use first goes ahead of the others Smart weighs it with
hzh_1119 on Discord: ChatGPT Pro and Business now come with monthly API
credit, and they want an OpenAI API key spent before the ChatGPT
subscription where both serve a model, the subscription taking over
after. Smart had no way to say so: an API key tells no allowance, so it
went after every account with room, in every model's found group
(auto/<model>). The only way round was a group set to In order with its
members dragged, one group at a time, which nothing pointed to.

A provider row's right-click has Use first (provider/usefirst,
provider.SetUseFirst, Provider.UseFirst, copied onto its accounts by
accountSettings, kept by the editor's Save). Its keys and accounts are
routes.Seat.Lead, and Smart (leadFirst) puts those not all but used up
ahead of every other seat, each side in Smart's own order. A resting one
is passed over as before, so a 429 insufficient_quota (out of credit) or
a failure moves the request on to the subscription. Off by default;
within one provider nothing changes. The Routing page says why the first
went first (Weighed.UseFirst, firstWhy) and doesn't call the one behind
it "renewing later" (behindWhy). The menu shows a tick when it is on.
Free quota by expiry orders its paid seats with Smart and so follows it;
other strategies don't read it. The core's script budget is met by
cutting three Providers-page comments in app.js, no raise.

Run (on mote via mote-run, at da548b454 = origin/main):
- go test ./internal/routes ./internal/provider: ok. ./internal/gui: ok
  but TestMainWindowCorners/macOS_26_SDK, red the same on a fresh
  origin/main da548b454 checkout (#3949, macOS 27).
- go test -run 'TestUseFirstLeadsTheGroup|TestRoutingGroups'
  ./internal/gateway: ok.
- node --test use-first.test.cjs (new: 40 cases, Chromium and WebKit,
  1100 and 420 wide, en zh zh-TW ja de) and provider-find.test.cjs
  (its menu now lists Use first): 52 pass.
- i18n-keys, i18n-en-no-cjk, routing-behind-why: pass but i18n-keys'
  "a plugin's words are its own", red the same on origin/main
  (#5327, #5426, #5482; none of its keys are this change's).
- GOOS=linux and GOOS=windows go vet -tags nogui ./...: ok. gofmt -l: none.

Broken by hand:
- Lead left out of weighRouted's seat: TestUseFirstLeadsTheGroup red
  (served from ksub with api set to Use first).
- Smart without leadFirst: TestSmartLeadFirst red
  ([plus pro api ...], want api first).
- firstWhy's Use first case off: use-first.test.cjs's Routing cases red
  in every language.

Not tried: a real ChatGPT account beside a real OpenAI key with API
credit; the 429 insufficient_quota fallthrough is from the fake
vendor's body (carriedQuotaBody). The full suite runs after the push.

Reported-by: hzh_1119
2026-11-07 07:15:40 +08:00
yetone 49f207c784 agents: DS Bot, wired in the DSH home it runs on
DS Bot (github.com/Fei2411/DS-Bot, Apache-2.0, dsbot.app) is a DSH plugin
and an Electron app built on it. The app ships its own DSH (0.2.2-rc.1 in
0.3.0) and runs it with DSH_HOME at a data folder of its own, booting the
profile ds-bot, and never reads ~/.dsh: magpie's dsh row didn't reach it.

It is a row of its own now, ds-bot (dsbot.go), wired by dsh's code on its
folder (dshOn, split out of dshAt): magpie's routes and start in
profiles/ds-bot/cordis.patch.yml, the key in that folder's .env and
.credentials.yaml. The folder is $DS_BOT_HOME, else locations.json's
dataDir in the app's userData ($DS_BOT_SHELL_DATA, else <config>/DS Bot,
or the legacy DeepSeek Bot), else ~/.ds-bot, as the app's first-run.mjs and
legacy.mjs choose it. A locations.json that can't be read or names no
folder is unknown: nothing is read or written. The routes there list the
models shown for DS Bot on the Agents page (dshListFor), and the serving
round fills a profile the app makes there as it does ~/.dsh's
(dshHomesRounds). Found by DS Bot.app (io.github.fei2411.dsbot) or its
Windows per-user install (guid from its electron-builder.yml). Three
notices, translated into zh, zh-TW, ja and de. DS_BOT_HOME and
DS_BOT_SHELL_DATA are in agentenv's sandbox list.

Run:
- go test ./internal/agent/ ./internal/agentenv/ ./internal/gui/
  ./internal/cli/ ./internal/appdir/ on mote: ok but
  internal/gui TestMainWindowCorners/macOS_26_SDK, red on mote's macOS 27
  whatever the change (#3949).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./... on mote: ok. gofmt -l: clean.
- node --test i18n-keys, i18n-en-no-cjk, agent-notice-lang (chromium), and
  agent-notice-lang in webkit: all pass but i18n-keys "a plugin's words
  are its own", red on main for three plugin words (#5332, #5426, #5482).
- Real DS Bot 0.3.0 (DS-Bot-0.3.0-mac-arm64.zip) on mote, all in a sandbox
  HOME with DS_BOT_HOME, DS_BOT_SHELL_DATA and DS_BOT_WORKSPACE under it:
  a magpie built from this tree (nogui), MAGPIE_ADDR 127.0.0.1:3572, a
  fake OpenAI upstream on 3571 added as a provider. `magpie ds-bot
  magpie/fake/m1` before the app was ever opened wrote the profile; the
  app's first start kept it (agent-default-model still magpie's) and added
  its own files beside it. Its Chief Bot offered "Magpie: m1 · fake, m2 ·
  fake"; picking m1 and sending "ping" over CDP went through magpie to the
  fake (POST /v1/chat/completions model m1, stream) and "pong from fake"
  showed. `magpie ds-bot default` then took every magpie entry out and the
  .env with it. Only my own pids (app, serve, fake) were stopped.

Broken by hand, each red, then put back:
- dsbot's desktopApps entry out: TestDsBotWired (not detected).
- dshListFor always "dsh": TestDsBotOwnModels.
- dshHomesRounds without DS Bot's home: TestDsBotProfileMadeWhileServing.
- a bad locations.json taken for ~/.ds-bot: TestDsBotDataFolder.
On the old code the tests don't build (no ds-bot row at all).

Not tried: the Windows app (install path and registry guid read from its
electron-builder.yml, not from an installed copy); Linux (its AppImage and
deb aren't looked for; the data folder its first start makes finds it);
a real vendor behind magpie; a default Bot model set in DS Bot (the notice
says it wins, per its models.js). Not done: usage gives DS Bot no
User-Agent of its own (its DSH's requests likely count as dsh's), and the
Sessions page doesn't read its data folder's sessions.

Reported-by: rnhung
2026-11-07 05:43:04 +08:00
yetone 9ed0f1fa49 agents: Claude Code's prompt cache lifetime is picked in its settings
Linka (Discord) asked to set Claude Code's prompt cache TTL from magpie.
Until now only Usage › Context's "Tuned for you" card wrote it, and that
card offers nothing when the value is already the cheapest it found.

Claude Code's opened row and settings sheet now have two rows under its
own Long conversations: "Prompt cache · main conversation" and "Prompt
cache · subagents". Each opens the app menu with Claude Code's default,
5 min and 1 hour. They write the keys the card writes, promptCacheTtl and
subagentPromptCacheTtl in Claude Code's settings.json
(agent.ClaudeCacheSet, POST /api/settings/claude-cache). Default takes
the key out. A pick is the user's own: it forgets the card's stash, so
the card's Undo leaves it. A variable that comes before the setting
(FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL,
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, in settings.json's env or
magpie's own) disables the row and names the variable, and the route
refuses it, so a value the user set by hand is never written over.

The names were checked in Claude Code 2.1.316's binary. Its resolver
checks FORCE_PROMPT_CACHING_5M, then the env var, then the setting
(enum "5m"/"1h"), then an agent's experimental.cacheTtl, then
ENABLE_PROMPT_CACHING_1H. With nothing set, the main conversation gets
1h on a subscription within its limits and subagents get 5m.

Run (mote, at this tree on 2ce44dc28):
- go test -count=1 -run 'TestClaudeCache|TestTune' ./internal/agent
  ./internal/gui: ok; go test ./internal/cli: ok (route parity).
- node --test claude-cache.test.cjs: 8/8 (Chromium and WebKit, en and
  zh, 900 and 420px), with agent-compact, i18n-*, gui-ja/zh-tw/de,
  old-webkit, agent-details-ready and context-tune: ok.
- Whole GUI suite on the Linux VM (wsl-run, concurrency 4), still
  running at commit: 74 files red there, mostly WebKitGTK. Of those
  only codex-memories-settings reaches Claude Code's settings: it
  counted Claude Code's rows as Long conversations alone, and now
  leaves out the two cache rows and checks they are there (18/18 on
  mote). desktop-subagent-model, account-eye, allow-ips and builtins
  pass alone on mote. codex-auto-reset (webkit de, #4790) and
  i18n-keys (#5327, #5332, #5426, #5482) fail the same way at
  origin/main f0620db63 on mote.
- go test ./internal/gui ./internal/agent ./internal/tune: agent and
  tune ok; gui red only in TestMainWindowCorners/macOS_26_SDK (#3949).
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build ./...: ok.

Broken by hand:
- Without forget, TestClaudeCacheSet fails ("the pick is the user's,
  not the card's").
- Without the lock check, it fails ("set under
  CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL").
- With default leaving the key, TestClaudeCacheSet and
  TestClaudeCacheRoute fail.
- Without the rows in agentcompact.js, claude-cache.test.cjs fails 8/8.
  Without the same-pick check, it fails on the extra post.
- The first GUI run was red in WebKit at 420px: Playwright's own
  scroll to an off-screen button was taken as the page scrolling. The
  test now wheels the rows into sight as a reader does, and checks they
  came into view.

Not tried: a real Claude Code session reading the picked value (only
the settings.json it reads was checked); the live ~/.claude was never
touched.

Reported-by: Linka
2026-11-07 05:16:53 +08:00
yetoneandmdwsk88 30a0bfe889 gateway, provider, cli: search APIs marked mix are asked together, their pages merged (#2845)
A search asked the search APIs in order and gave the model the first
one's pages. On #2845's 80-query benchmark no single API was best on
both sets. The deduplicated union of two or three APIs' pages scored
higher than the best single API and lost no query (60-query set: 108 to
114-117 of 120, sign test p <= 0.03).

Off by default. When two or more search APIs are marked mix
(SearchAPI.Mix), they are asked first, at once (askSearchAPIsTogether).
Each uses its own keys and timeouts, as when it is asked alone
(askSearchAPIKeys). Their pages go to the model in turn: each API's
first page in the saved order, then each one's second. A page an
earlier API already gave is left out by its address (pageKey). One
that fails or finds nothing leaves the others' pages. When none finds
anything, the APIs not mixed are asked in order. With fewer than two
mixed APIs on and ready, a search runs in order as before. No text
says which API found a page, so what a vendor sees reads as before.

MixSearchAPIs marks the vendors named (two or more, set up, each once)
and clears the rest; none clears all. SetSearchAPI keeps the mark, as
it keeps off, since Settings sends an edit without it. Backup copies
the whole entry, so the mark carries over. CLI: magpie search mix
<api>,<api>, magpie search mix off, and magpie search lists a mixed
one as mix. docs/subsystems/gateway-routing.md has a section on it.

Ported from mdwsk88's 2966cce77 and reviewed line by line. What
changed from it:
- The cap follows the search's count (#5545, the commit before this):
  searchMixMost is 2 x the count a search asks for, at most 20
  (searchHitsMost). The default stays 12 pages, as in the patch.
  TestSearchAPIsMixedCapped is a table over count settings and named
  counts.
- The CLI keeps both search count and search mix.
- No Settings toggle. The mode stays CLI-only, by the UI-restraint
  rule; the docs say so.

Run (mote-run):
- go test -count=1 -run "Search|Mix" ./internal/gateway/: ok; -race
  -run "TestSearchAPIsMixed|TestMixSearchAPIs": ok.
- go test ./internal/provider/ ./internal/backup/: ok; ./internal/cli/
  -run "TestSearchCLI|TestEveryRoute": ok.

Broken by hand: with apiSearch's mixed branch turned off,
TestSearchAPIsMixedAskedTogether fails (only the first API's pages)
and TestSearchAPIsMixedCapped fails ("count set 0, named 0: 6 pages,
want 12"). Restored, both pass.

Not tried: a real search with two vendors' live keys. The tests use
fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 4e0e8e7933 gateway, settings, gui, cli: the results a search is answered with can be set, 1 to 20 (#5545)
Claude Code's WebSearch and Codex's web_search never name a count, so
magpie answered every such search with searchHits, 6 pages (#5545,
mdwsk88: more pages for research-heavy work, fewer to save context).

settings.SearchCount holds the count. 0 means the default, 6
(SearchCountDefault), and the most is 20 (SearchCountMost), the most
Brave and Tavily return. Save refuses a value out of range, so nothing
is written. Settings.SearchPages reads it. The gateway's searchCount
falls back to it when a search names no count. The web_search MCP tool
still answers a named count with that count, and its schema's default
says the count set. It reaches every search API (Brave, Tavily, Exa,
You, the plugins' searchers), as a named count already did.

- Settings › Models › Web search: "Results per search", segments 3, 6,
  10, 15 and 20, plus a count set by hand in settings.json.
  POST /api/settings/search-count sets it alone. settingsapi.Apply
  keeps it as it keeps search-all, so a save of the Settings form
  doesn't put it back.
- CLI: magpie search count says the count; magpie search count <n>
  sets it; magpie search count default puts 6 back. A bad value is
  refused and nothing is written.
- docs/subsystems/gateway-routing.md says it.
- New strings are in zh, zh-TW, ja and de.

Run at this tree (mote-run, macOS):
- go test -count=1: internal/settings, settingsapi, cli, gateway
  (TestSearchMCPCount, TestSearchCountReachesEveryAPI,
  TestSearchCountSetting), and gui (TestSettingsSearchCountSetOnItsOwn, and
  TestSettingsSaveKeepsWhatItDoesNotSend with SearchCount set): ok.
  internal/gateway whole: ok with -timeout 45m (847s). internal/gui
  whole: ok but TestMainWindowCorners/macOS_26_SDK (#3949, mote is on
  macOS 27).
  The first cli run was red on TestEveryRouteHasACommandOrIsNamed:
  the new route had no CLI entry. cliForRoute maps it to search count
  now.
- Broken by hand: searchCount returning searchHits again makes
  TestSearchCountSetting fail ("set 11: a search naming no count asks
  for 6, want 11"). Restored, it passes.
- GUI: node --test --test-concurrency=4 over routing-*, usage-*,
  ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-*
  and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja
  and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55
  reds are in 12 files. i18n-keys' "a plugin's words are its own"
  names other files' strings (#5327, #5426, #5482). The other 11 files
  were run alone at dc49feca9 (this tree without either change) and at
  this tree: 52 and 51 reds, the same tests. The one apart is
  usage-focus-steady, which flakes (#3501). Each is filed: #5392,
  #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529.
  routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule
  taken out, its dot is the answered green rgb(24, 154, 88) and it
  fails. Restored, it passes.
- Not tried: a real Claude Code WebSearch through this tree with a live
  search API key. The tests use fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 8de63c8b5a gateway, usage, gui, otlp: a request its agent canceled is no failure (#2398)
An agent that cancels its request before it is answered is logged 499
"the agent canceled the request": a person stops the reply, or sends the
next message while it is coming and Claude Desktop cancels it and asks
again, or Codex takes a subagent's report (#2398). The gateway already
says nobody failed (no rest, no reroute: TestCanceledRequestRestsNobody),
but Record.Failed is a status >= 400 or an error, so every page counted
it as a failure: the Requests card's "N failed" and success share, its
Failed filter, the CSV's error column, the Routing page's "errors your
agent saw", the Context page's error rate, the failed colour in the
Requests list, Routing and Recent calls, and the OTLP export's error
status. A Claude Desktop session on 2026-10-27 had four, each a message
sent mid-reply; #2398 had 91 of a day's 92 failures.

usage.CanceledBy tells the agent's cancel (499 with AgentCanceled) from
magpie's own limit on a request it asked of itself, logged 499 too and
still a failure (#2318). The cancel is logged with an error type of its
own, agent_canceled (usage.CanceledErrType, set in failedWith), so the
record says what it was and nothing guesses it from a 499, as #2398
asked. Record.Canceled reads the type, and a record logged before it by
its status and message, so the old log reads the same with nothing
migrated. A middleware's usage rows carry the type, so a module can tell
the cancel from magpie's own limit, which its rows (no error text)
couldn't.

Record.Failed leaves the cancel out; Totals counts it apart (Canceled, in
count and plus); RetriedRequest and the first-token and speed sums ask
Answered, so a canceled request is timed nowhere, as before; Codex's
memory of the last model still skips it. Routes and Recent calls say
canceled (set as a route is done and as a day's history is read, so old
days read the same); the Routing totals and the Context page's errors
leave it out. Ledger rows say canceled, and the pages show it muted, in neither the
failed nor the answered colour: the Requests list and its detail ("499 ·
canceled"), the Requests card ("N canceled", the success share of the requests not
canceled), the overview tile, the Routing page (a "gone" outcome, no
speed) and Recent calls (muted). New strings are in zh, zh-TW, ja and de.

The OTLP export: the records the gateway gives its observers for a
request and its try carry the type too (canceledAs), and a root span's
error.type follows Record.Failed, so a canceled request's span and its
try's go with status code 499, no error and no error.type.
TestOTelWaterfallFailureAndCancellation's canceled case held two failed
spans (the try the vendor refused as the agent left is recorded canceled,
as the request is); it now holds neither failed, both 499 and no
error.type. That change to the test is the point of this one.

mdwsk88's patch (aea0027fd) ran its tests at e056779a, a3768cdd,
c86fa2a3 and fcc0daa2, broke each check by hand (each red), and sent
real Claude Desktop cancels through a nogui build with a stand-in
upstream and OTLP collector. Its full record is on aea0027fd. Since
58541e5b (#4866) Codex's own-sign-in relay logs Codex gone mid-reply as
499 through canceled() too, so it counts as canceled
(TestCodexGoneMidReplyIsNoFailure). drawing_route.go still reads a
canceled request as not served when it decides whether a picture's
next request may stay on its provider: that is routing, not a count.

Ported to origin/main 400b66ec3 on 2026-11-07, reviewed line by line.
Two siblings it left on the old rule, and a colour, now covered:
- usage.Row.Floor (the Claude Code speed floor) asked !Failed, so a
  canceled row, whose Failed is now false, told a floor: "3000 tokens
  in 4000 ms" for a reply no one waited for. It asks Answered now, as
  the speed and first-token sums do. TestAgentCanceledTellsNoFloor.
- The route-events feed (activityOf, #3387) told a canceled try and
  done route as failed. It leaves usage.CanceledBy out, and still
  counts magpie's own 499 limit. TestRouteEventsCanceledIsNoFailure.
- routing.css: a canceled Routing row ("rt-req gone") had the
  answered green dot. Its dot is muted now.
  routing-canceled-row.test.cjs checks the row, its dot and the errors
  stat in Chromium and WebKit, in en, zh, zh-TW, ja and de.

Run at this tree (mote-run, macOS):
- go test -count=1 internal/usage, usageapi, otlp, settings,
  settingsapi and cli: ok. internal/gateway: ok with -timeout 45m
  (847s; the default 10m ran out under load). internal/gui: ok but
  TestMainWindowCorners/macOS_26_SDK (#3949, mote is on macOS 27).
- Broken by hand: Floor on Failed again makes
  TestAgentCanceledTellsNoFloor fail ("a canceled row tells a speed
  floor: 3000 tokens in 4000 ms"). activityOf without CanceledBy makes
  TestRouteEventsCanceledIsNoFailure fail ("a done route its agent
  canceled is told failed"). Restored, both pass.
- GUI: node --test --test-concurrency=4 over routing-*, usage-*,
  ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-*
  and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja
  and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55
  reds are in 12 files. i18n-keys' "a plugin's words are its own"
  names other files' strings (#5327, #5426, #5482). The other 11 files
  were run alone at dc49feca9 (this tree without either change) and at
  this tree: 52 and 51 reds, the same tests. The one apart is
  usage-focus-steady, which flakes (#3501). Each is filed: #5392,
  #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529.
  routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule
  taken out, its dot is the answered green rgb(24, 154, 88) and it
  fails. Restored, it passes.
- Not tried: a real Claude Desktop cancel through this tree; Windows
  and Linux runs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 ff2a06c349 gui, tune: Tuned for you weighs a model magpie routes at its provider's price, not by its name (#3435)
Tune weighed a call's tokens by its model's name alone (tune.WeightsFor):
an id starting "claude" at Anthropic's ratios (read 0.1, write 1.25, an
hour's write 2), any other at generic ones (an hour's write at a
5-minute one's price). Claude Code is given magpie's models as
provider/model ids (copilot/claude-opus-5-5, anthropic/claude-opus-5-5),
which the name rule took for no Claude model. So a Claude model on an
Anthropic-billed provider was weighed with its hour costing no more than
5 minutes, and none was weighed at the price the usage pages count.

The replay now takes its weights from a tune.Weigh (CompactOpts.Weigh,
and CacheTTL's third argument), per stream; nil weighs as before. Tuned
for you passes pricedWeights: an id with a provider resolves as the
gateway resolves it (provider.Resolve after ClaudeRead) and is weighed
at that provider's EffectivePriceIn, so a Claude model on Copilot has
its hour at the 5-minute write Copilot bills (the previous commit) and
one on Anthropic at 2x. A model Claude Code named itself keeps its
maker's weights, as does a price with no cache read or write. The
compaction advice is weighed the same way. docs/subsystems/agent-wiring.md
says so.

Run on mote (go1.26.8, macOS) at 400b66ec3 plus the previous commit and
this one:
- go test ./internal/tune, and ./internal/gui -run Tune: ok.
- With pricedWeights weighing by the name alone (by hand),
  TestTuneWeighsRoutedCallsAtTheirProvidersPrice is red:
  "relay/claude-opus-5-5 weighs {Read:0.1 Write:1 Write1h:1 Out:8};
  want its price's" and "cache advice ... {Current:1h Best:1h ...};
  want 1h -> 5m".
Not tried: the Context tab in the app; the advice's numbers change, not
its layout or text. Claude Desktop's Code tab is still left out of Tuned
for you, though #3435 names it.

Reported-by: mdwsk88 (dawei on Discord)
Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 6ac1e04244 provider: a Claude model on Copilot has its 1-hour cache write priced as Copilot bills it, at the 5-minute write (#3435)
Copilot bills a cache write at one price however long it is kept. Its
copilot_usage counts a 1-hour write as the cache_write a 5-minute one
is, and GitHub's "Models and pricing for GitHub Copilot"
(docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing)
lists one "Cache write" price per Claude model, no 1-hour tier (Opus
5.5: input $4, cached input $0.20, cache write $5, output $20). magpie
gave every Claude model's list price Anthropic's 1-hour write, 2x input
(catalog.OneHourFor), so copilot/claude-opus-5.5 was priced at $8 per
million for an hour's write where Copilot bills $5: on the reporter's
request, $0.125456 against Copilot's own $0.078443.

A Copilot price (tariffOf, cacheWritesAlike) now has no 1-hour write of
its own, so an hour's write is billed as a 5-minute one
(catalog.Price.OneHour), its tiers alike, copied as they may be the
catalog's. This holds for a call read after Copilot was signed out too
(tariffOf's unknown-provider path, MakerPrice), which the reporter's
patch left at 2x. A price the user gave for a Copilot model keeps the
1-hour write they gave, and one they left out isn't filled with 2x input
(userPrice, so UserBasePriceIn reads it alike). Every other provider is
as before: Anthropic, Bedrock, Vertex and relays bill the hour at 2x, so
the rule is scoped to Copilot's id, not taken off every non-Anthropic
provider. Usage rows are priced as they are read (Record.CostAt), so
calls already recorded read at the new price too. docs/reference.md and
ModelPrice's comment say so.

Run on mote (go1.26.8, macOS) at 400b66ec3 plus this commit and the
next:
- go test -tags nogui ./internal/provider ./internal/tune
  ./internal/catalog: ok.
- TestCopilotOneHourCacheWriteAtItsWritePrice is red with models.go at
  400b66ec3 ("copilot/claude-opus-5.5 = {... CacheWrite1h:8 ...}").
  With the unknown-provider strip taken out by hand, its two new checks
  are red ("signed-out copilot/claude-opus-5.5 = {... CacheWrite1h:8
  ...}" and "BasePriceIn(copilot, claude-opus-5.5) with no Copilot ...").
Not tried: a live Copilot request; the figures are Copilot's own
copilot_usage for the reporter's request. A plugin that serves Copilot
(OpenCode's github-copilot auth) is priced as before; how it is billed
wasn't checked.

Reported-by: mdwsk88 (dawei on Discord)
Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
2026-11-07 04:03:00 +08:00
yetone 04d99d7cea gateway: a relayed MCP call is passed on as the key's check read it
mcpKeyGuard (d55881730) held a key given some tools of a relayed server
(/mcp/<name>, /mcp/run/<name>) by decoding the body with Go's
encoding/json, which matches keys in any case and keeps a key's last
value, then sent the server the original bytes, which it reads keys
as written. So {"method":"tools/call","params":{"name":"write",
"NAME":"read"}} was checked as read and ran write on the server; a
METHOD, Params or paramſ key, or a key given twice, did the same.

strictMCPBody now reads each message (and a batch) into maps: a key
that is one of the envelope's (jsonrpc, id, method, params, result,
error) or params' (name, arguments) in another case is a 400, a
tools/call whose params aren't an object or whose name isn't a string
is a 400, and the server is sent the body written again from what was
checked, so a key given twice reaches it once. magpie's own servers
and the hub act on what they parsed, so they were not open to this.

Run on mote at this tree (base 416305451):
- go vet ./internal/gateway, also GOOS=windows and GOOS=linux: ok
- go test -count=1 -timeout 45m ./internal/gateway ./internal/access:
  ok (gateway 730.8s)
- gofmt -l internal/gateway: clean
Broken by hand: checking with the old case-insensitive decode and
forwarding the original body turns TestKeyMCPRelayReadsOneWay red
(the server got the NAME body and ran write).
TestKeyMCPRun's check of the forwarded body now expects the re-encoded
form (keys sorted).
Not tried: a real remote MCP server signed in through /mcp/<name>;
the relays are covered with mcpauthtest's fake and a RunMCP stub.
2026-11-07 03:57:21 +08:00
yetone d55881730d gateway: a key can be held to some MCP servers and tools
wakaka on Discord (#help, 11-06) asked for gateway keys limited to some
MCP servers and tools, as keys already are to models (#882).

A key's MCP list (caller-keys.json "mcp") holds entries "server" (every
tool of it) or "server/tool"; "-" alone is no MCP server; an empty list
is every server, as before. A key issued under another is held to its
issuer's list too.

Every MCP route checks it:
- magpie's own servers (web search, vision, image, Magpie Browser, plugin
  tools) through serveMCP: initialize/tools/list/tools/call are refused
  or filtered per server and tool, and /v1/magpie/key-limits names "mcp";
- the Library hub ("magpie"): only the backing servers and tools the key
  may use are listed, and a call by name or by fallback is refused;
- /mcp/<name> and /mcp/run/<name>: the server is refused, tools/list is
  filtered in JSON and SSE replies, tools/call refused; a reply the
  filter can't read (an encoded body) is a 502, never passed through.

GUI: "MCP servers" in the key row's menu opens the app's own picker (no
native select) with All, No MCP server, each server and its tools (GET
/api/caller-keys/mcp lists magpie's own servers and the Library's). A
key held to some shows a badge saying which, that opens the same list;
a free key shows nothing more in its row, on hover either. A hover badge
was tried first: it pushed the row past 560px (gateway-caller-keys) and
squeezed the masked key under a drag at 420px (gateway-key-arrange).
CLI: magpie gateway-key mcp <id> github fs/read_file | none | all.
zh, zh-TW, ja, de strings; docs/reference.md and the gateway-routing and
library subsystem pages.

Not covered: a model's own built-in web search (a vendor tool, not MCP).

GET /api/caller-keys/mcp is named in the CLI parity test's notYet (its
list is what `magpie gateway-key mcp` takes; TestEveryRouteHasACommandOrIsNamed
caught it at the rebased head).

Run on mote (mote-run), at the pushed head:
- go test ./internal/access ./internal/cli ./internal/gui
  ./internal/library ./internal/gateway at a9c40186d (this change on
  2ce44dc28): ok except internal/gui's TestMainWindowCorners/macOS_26_SDK
  (#3949, the same message on macOS 27). After the rebase onto a9667daad
  (no file in common): TestCoreScriptBudget, TestCallerKey*,
  TestEveryRoute*, TestGatewayKey*, TestKeyMCP*, internal/access and
  go vet ./internal/... at d36f89224's tree: ok.
- gateway-caller-keys chromium en reads wider than 560px 4 of 6 runs
  alone on this branch and 4 of 6 on origin/main a9667daad: #3797,
  recorded there.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: clean; darwin, linux (nogui) and windows builds ok; gofmt -l
  clean.
- GUI: gateway-key-mcp.test.cjs in chromium and webkit, widths 1100 and
  420, en/zh/zh-TW/ja/de: 20/20. Every gateway-key*, gateway-keys* and
  i18n* file in both engines: ok except gateway-key-models en (red on
  origin/main ecc26a339 too, #4081/#5233) and i18n-keys "a plugin's words
  are its own" (red on main, #5332).
- The whole GUI suite (both engines, every language) with the hover
  badge: 91 reds in 25 files. Rerun alone on this branch and on
  origin/main 54dc257f1: only gateway-caller-keys (560px sideways),
  gateway-key-readonly, models-fold and models-select-all-api were red
  on the branch alone; the badge moved into the row menu for the first
  two. After it, every gateway-key*, gateway-caller-keys, gateway-card,
  gateway-connect-keys, api-key-theme and i18n* file passes in both
  engines, except i18n-keys "a plugin's words are its own" (red on main,
  #5332, none of the three strings are this change's) and 1 of 20
  models-select-all-api "the click scrolled" (#4389; models-fold is
  #4071). The rest are red on origin/main too and each has an issue:
  account-weight #4644, codex-auto-reset #2360, header-centre #3479,
  images-codex-one #4618, key-replace #4126, menu-input-scroll #3402,
  mobile-web #3952, model-chip-steady #4388, model-copy-id #4621,
  models-works-only #4391, nav-timeout #4787, omarchy #4624,
  page-width-steady #5013, phone-connect-menu #4706/#4707,
  plugin-move-unserved #4392.

Broken by hand, each went red: the serveMCP server gate, call check and
list filter, the own-server list filter and key-limits "mcp"
(TestKeyMCPOwnServer); hubTools, hubServersOf, the hubToolNamed
fallback and hubMCPRun (TestKeyMCPHub); /mcp/run (TestKeyMCPRun); the
/mcp/<name> guard and filter (TestKeyMCPProxy); the GUI's "No MCP
server" being exclusive (gateway-key-mcp).
gateway-key-readonly chromium 420 ja was red with the hover badge (the
sibling run, the whole suite and its rerun; green on origin/main) and
passes with the badge in the row menu.

Not tried: a real Library server through a live gateway, the hub with a
real agent, and running on Windows or Linux (vet and build only).

Reported-by: wakaka
2026-11-07 03:21:57 +08:00
yetone a9667daad5 codex: CC Switch's OpenAI mirror's threads follow OpenAI, and OpenAI's follow the mirror
Chris on Discord (the Codex app on a Mac): "Model provider mismatch.
This chat uses OpenAI, but your current provider is OpenAI. Switch to
OpenAI to continue." The Codex app names a provider by its table's
name. CC Switch's OpenAI mirror ([model_providers.custom], name
"OpenAI", requires_openai_auth, no base_url) is named OpenAI as the
built-in openai is, and Codex up to 0.167 resumes a thread only on the
provider id it is on now (app-server config_manager.rs load_for_resume
and check_thread_model_provider_for_input: ModelProviderMismatch;
0.168.0-alpha drops that check). magpie left the mirror out of every
thread move: bringBeside skipped it as the provider it took down,
lendOwn skipped it at the top, and bringOfficial took only
cc-switch-official. So a thread on the mirror stayed refused with Codex
on OpenAI beside magpie, and OpenAI's threads with Codex on the mirror.

Both are the ChatGPT account's threads, so they follow whichever of the
two Codex is on:
- bringOfficial moves every mirror table's threads to the provider
  Codex is on with magpie (openai or magpie), unless the mirror is at
  the top, a profile names it, or it is the provider magpie took down
  (stash codex.provider);
- bringBeside takes that one, recorded, and giveBeside gives its
  threads back at the Disconnect that puts the mirror back on top;
- lendOwn moves OpenAI's threads to a mirror at the top, and giveLent
  back once Codex is on OpenAI.
Existing threads: each sync moves them, "custom" in place (OpenAI's
length), a paginated one by its row, any age; others' ids the last 30
days with a copy kept, as before. Config.toml and the provider ids
magpie writes are unchanged.

Run: real codex 0.167.0 in a sandbox CODEX_HOME, `codex exec resume`
of a thread on custom with Codex on openai: "This chat uses custom, but
your current provider is openai" (modelProviderMismatch), resumed past
the check after the relabel to openai; the reverse (custom at the top,
thread on openai) refused the same way.
mote (go 1.26.8): go test -count=1 ./internal/agent/ ./internal/sessions/
ok (408s, 58s); go vet ./internal/agent/ native, GOOS=windows, GOOS=linux
ok; gofmt -l clean.
Broken by hand: the three old exclusions back, all three new tests red
(thread left on custom / on openai); bringOfficial without the stash
skip, TestCodexMirrorAtTopJoinsWithItsThreads red (the mirror's thread
left on openai after the Disconnect).
Not tried: the Codex desktop app itself (not on any test box), and
Chris's config.toml wasn't seen, so which way round his threads were is
inferred from the two ids that name "OpenAI". A thread on a mirror with
a profile naming it stays; after the Disconnect, OpenAI's own threads
stay on OpenAI as before.

Reported-by: Chris (Discord)
2026-11-07 03:00:10 +08:00
yetone 8cbaeecae9 providers: errors=pass sends a vendor's error to the agent as it came, asked once
ne9ko9 on Discord wants errors handled explicitly, not by inference, and
a mode that passes them straight through. A custom or API-key provider
(no account, an endpoint of its own, not a subscription) now takes
`passErrors` in its config: "magpie handles" (the default, unchanged) or
"Pass through". Nothing sets it but the user, and an edit that doesn't
send it keeps the saved value.

With it on, for that provider:
- no rewriting: on the client's own API, upstream's status,
  Content-Type and bytes go out (passError); on another API, the
  client's shape is built with the vendor's own type, message and raw
  code and param (a numeric code stays a number). Retry-After and
  *ratelimit* headers go with it;
- no too-long inference, no busy words, no 413 hint, no policy
  rewording (settle never runs: the try is passing);
- no gateway retry: forward()'s Retries loop, refit, firstWait, the
  loop's re-asks, reloop, empties retry and streamTranslated's
  cont.again all stop;
- no fallback and no rest: the candidate loop's one choke point,
  newHoldWriter(…, !pass && …), lets the try pass, so nothing after it
  is tried, and restAfterMarked answers By "off".
magpie's own file-id re-ask (dsRetryGone) still runs, as it fixes
magpie's own upload, not the vendor's answer.

CLI: `magpie provider set <id> errors=pass|magpie`; a bad value is
refused and keeps the old one; an account is refused. `provider show`
says "errors pass".
GUI: Edit → Advanced → Errors, a quiet app-menu picker (openProtoMenu,
no native select) with "magpie handles" and "Pass through", shown only
where takesPassErrors; zh, zh-TW, ja, de. It is drawn by passerrors.js,
imported when the editor draws the row (old-webkit's lazy list names
it), and app.js pays for its few lines by two comments cut, so app.js
is smaller than before and TestCoreScriptBudget's numbers are unchanged.

Tests:
- internal/gateway/pass_errors_test.go: TestPassErrorsAskedOnce (503,
  429, 404 with numeric codes, alone and as a group's first member:
  exact bytes and status, asked once, the second member never asked,
  no rest), TestPassErrorsNotInferred (a too-long 400 byte-for-byte),
  TestPassErrorsOtherAPI (Anthropic 403 code 20031 to a Chat client,
  streamed and not).
- internal/provider/pass_errors_test.go, internal/cli/errors_cli_test.go.
- internal/gui/tests/provider-pass-errors.test.cjs: every language,
  1100 and 420 wide, Chromium and WebKit.

Run, through mote-run at this commit:
- go test -count=1 -timeout 45m ./internal/gateway ./internal/provider
  ./internal/cli ./internal/gui (at the parent 19c45d5d4's tree): gateway,
  provider, cli ok; gui red only in TestMainWindowCorners/macOS_26_SDK,
  mote's macOS 27 (#3949). TestCoreScriptBudget ok.
- Rebased on 2f660ca86: go vet of the four packages, the PassErrors,
  Budget, SameAPI and Errors tests and provider-pass-errors (60/60)
  again at this commit: ok.
- GUI on mote: provider-pass-errors 60/60 (both engines), old-webkit
  and provider-pass-errors under BROWSER=webkit 36/36; i18n-keys red
  only in "a plugin's words are its own" (#5332, #5426, #5482).
- The whole GUI suite on Linux (wsl-run, magpie-desktop, --test-
  concurrency=4): 21188 of 21666, 478 red. The 15 provider-editor files
  among the reds (vertex-editor, zero-priced-free, provider-fetch-again,
  provider-picks-stay, model-chip-steady and ten more) were run at this
  commit and at origin/main 2f660ca86 without it: 128 of 236 red on
  both, the same tests. The rest are in files this commit doesn't
  reach.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: ok. gofmt -l clean.
- Full suite: run after the push under the suite lock.

Broken by hand: every PassesErrors() gate set to false: AskedOnce,
NotInferred and OtherAPI red (rewritten body, b asked, rested). The GUI
test on the old code: 0/60.

Not tried: a real vendor account or relay with errors=pass; Windows and
Linux hardware (vet only).

Reported-by: ne9ko9 (Discord)
2026-11-07 00:42:21 +08:00
yetone f9a88c4fbe wsl: a distro's Pi from fnm, mise or an npmrc prefix is found, past a Windows one on PATH
千里不再 on Discord: Pi installed in WSL wasn't detected. The WSL probe
runs `sh -lc`, which reads ~/.profile but not ~/.bashrc, where fnm's
installer puts its PATH, so `command -v pi` missed it and wslbin had no
fnm folder. A Pi not run yet has no ~/.pi either, so nothing found it
(and for fnm users who had run it, its version was lost). Also, WSL
appends Windows' PATH, so a Pi npm installed on Windows answered
`command -v pi` with a /mnt/c path; that stopped the `|| wslbin`
fallback and parseProbe then dropped it as a Windows command (#406), so
the distro's own Pi was hidden.

Now wslcmd takes `command -v` only when it isn't on a Windows drive
(/mnt/X or any drive /proc/mounts lists), else walks PATH past Windows
drives, else wslbin. wslbin gains the folders proc.UserBinDirs has here:
fnm (aliases/default, then the highest version; FNM_DIR,
~/.local/share/fnm, ~/.fnm), mise's installs (highest), ~/.npmrc's
prefix, ~/.npm/bin, cargo, deno, Homebrew. Every WSL kind goes through
it, not only Pi.

Run:
- mote: GOOS=windows/linux/darwin go vet ./internal/agent; go test
  -run "TestWSL|TestOmo|TestPi" ./internal/agent ok. gofmt -l clean.
- wsl-run (magpie-desktop, Ubuntu 24.04): same tests ok.
- Real WSL: in magpie-desktop, a scratch HOME with the real fnm
  installer, `fnm install 22`, `npm i -g @mariozechner/pi-coding-agent`
  (pi 0.73.1), never run. Old probe: no bin:pi. New probe:
  `bin:pi .../fnm/aliases/default/bin/pi`, `ver:pi 0.73.1`, pi@wsl
  listed; a fnm codex was found past a /mnt/c one. Real home still finds
  codex, pi and claude (3.9s). Through proc.CommandContext on Windows
  (win-run) with Detect agents in WSL on, the probe runs (#4872 gates
  only when it is off).

Broken by hand: origin/main's wsl.go with the new tests: all four
subtests of TestWSLProbeFindsNodeManagersBins and
TestWSLProbeLooksPastWindowsCommand red.

Not tried: the reporter's own install (method unknown; fnm with a
never-run Pi is the case reproduced). Asking bash -i for ~/.bashrc's
PATH was tried and dropped: under timeout(1) an interactive bash stops
itself (state T) on WSL and outlived its timeout.

Reported-by: 千里不再 (Discord)
2026-11-06 23:47:29 +08:00
yetone 1fd0bb9670 update: a download whose HTTP/2 transfer broke off tries again over HTTP/1.1
biubiu8802 on X (tweet 2118719081872540038): behind their proxy every
update failed with "download broke off, a network problem", while the
same proxy carried ordinary downloads. Confirmed in the code: download()
retried up to 5 times with Range, but each try went through
netproxy.Dispatch over HTTP/2 again; Dispatch moves a host to HTTP/1.1
only on a TLS record error (recordError: bad record MAC and kin), and
"unexpected EOF" or a stream reset is not one. So a proxy that cuts
HTTP/2 streams part way cut every try the same way.

- netproxy: OverHTTP1(ctx) sends every request under ctx through
  Dispatch's HTTP/1.1 copy (route.h1), kept through With.
  BrokeOff(err) says a transfer broke off (net.Error, unexpected EOF,
  HTTP/2 stream error / GOAWAY / lost connection, a reset; not a
  context that ended). AgainOverHTTP1 runs a download once more over
  HTTP/1.1 after such a failure.
- update: the tries after a broken one go over HTTP/1.1, and still
  resume with Range from the bytes kept.
- Siblings, the other big downloads through Dispatch's client: the
  masking model and pf-serve (pii.fetch, one more try over HTTP/1.1
  from what is on the .part file), Bun's zip (plugin getURLFrom),
  Claude Code's binary (claudecode.download) and the Grok CLI
  (grokDownload) each try once more over HTTP/1.1.
- docs/subsystems/providers-accounts.md names it.

Run (mote, Go 1.26.8, at this tree, base 80ae904c2 = origin/main fetched
just before push):
- TestDownloadBrokenOverHTTP2TriesHTTP1 (httptest TLS HTTP/2 server
  that resets each HTTP/2 stream after 100KB, serves HTTP/1.1 whole):
  red with the update.go line taken out, all six tries over HTTP/2
  ("stream error: ... INTERNAL_ERROR"); green after, asked
  ["HTTP/2.0 ", "HTTP/1.1 bytes=102400-"].
- TestOverHTTP1EveryHost, TestAgainOverHTTP1, TestBrokeOff: green.
- go test ./internal/netproxy ./internal/update ./internal/pii
  ./internal/claudecode ./internal/plugin ./internal/provider: ok.
- go test ./... -count=1 -timeout 45m: 86 ok, gateway 795s and agent
  303s ok; internal/gui red only on two AppKit tests already filed for
  mote's macOS 27: TestMainWindowCorners/macOS_26_SDK (#3949) and
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322). Nothing in gui is
  touched here.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of the touched
  packages clean.

Not tried: a real proxy that cuts HTTP/2 (the reporter's); the retry of
pii, Bun, Claude Code and Grok against a real host (unit-covered by
AgainOverHTTP1 only); Windows/Linux test runs.
2026-11-06 23:44:58 +08:00
yetone 80ae904c23 routing: routing groups get a page of their own, beside Routing
The owner asked for the groups to leave the Routing page (11-06): under
the live stage and every request they were a long scroll down, and New
group with them. The design was reviewed before this was built.

- New page, Routing groups (#view-groups), drawn by the routing plugin's
  same script (routingPage), so the editor, its dirty/discard and every
  group action are unchanged. Toolbar: filter, "N groups · M on",
  Templates, Import, Select, and New group as the filled button. The list
  is right under it, and a Settings section under the list holds Found
  groups (with Exclude providers…) and Names in agents' lists.
- No Export button: each group already has its own Copy to share.
- Routing keeps the live stage and the requests. A request's group opens
  the groups page at its row.
- The sidebar has a Routing groups tab right after Routing (from 1024
  points). The header's row has no room for one: at 860px the extra tab
  pushed the logo out (brand.test). There the tab is hidden, Routing's
  tab is lit for both pages (markNav), and Routing's head has a
  "Routing groups ›" button, hidden beside the sidebar.
- Every way in now goes to the groups page: the guide's Open routing
  groups, the panel's and the provider editor's Make a routing group
  (window/main?view=groups&newgroup=…). mainView still takes
  view=routing&newgroup from an older panel.
- Words: "Routing groups", "Open routing groups", "Once saved, make a
  group of them in Routing groups.", and the editor's names note now says
  the setting is under the list, in zh, zh-TW, ja and de. "Open Routing"
  stays for the Agents page's button.
- Docs: providers-accounts, gateway-routing, plugin-runtime, gui-shell
  and reference say "Routing groups page" where they mean the groups.
- Core budget: the core's scripts are 1,533,774 of 1,533,802, paid for
  by three show()/setGatewayMode comments cut in app.js. No raise.

Tests: routing-groups-page.test.cjs (new) covers the page in Chromium and
WebKit, en/zh/zh-TW/ja/de, at 1280, 640 (window) and 420 (web): no
groups on Routing, the tab or the head's button by width, the lit tab,
toolbar order, New group primary and in sight, list then Settings, no
sideways scroll, no native select, no left-border accent; a request's
group to its row; quotas redrawn with an open editor left alone. The
trace tests (routing-compact, -pause-folder, -rule-models, -folder) open
Routing, then show the groups; routing-editor-foot and
name-suffix-where-named scroll by wheel, as the scroll guard lets a
reader; builtins expects the groups tab beside the sidebar only.
Removed: routing-groups-jump (the head's "Routing groups ↓" that scrolled
down to them, gone with them), routing-pointer-pin and routing-steady
(the groups kept in place under requests streaming in above them: no
request is above them now). Their guarantee that what redraws leaves an
open editor and its typing alone is routing-groups-page's quotas case;
Routing's own lists keep their keepInView.

The groups page's jump: a request's group, or a pool's "Several keys"
chip, opened the groups page and scrolled the row to the centre, and the
next frame show()'s backAfterLoad put the page back where the reader
last left it, then brought the focused segment in by "nearest": in
WebKit the pool sat half under the window's foot (routing-mode-goes, 9
of its 10 WebKit cases). goRouting now jumps at once on a page it opens and
marks it arrived(). The wheel in routing-many-keys turns over the keys:
at the page's foot, now shorter, the mouse rested over the requests list
(.rt-reqs, overscroll-behavior: contain), which took every wheel up, and
the test stopped with 2 keys in sight. That is #4082's cause.
routing-days-fit's fixture has 12 requests, a day that fills the window,
since the day bar held needs room under it.

Run on mote (macOS 27, load 25 to 65), Playwright 1.62.0:
- Go: go vet, gofmt -l and go test ./... at the rebased head (650bf8412
  base) ok except TestMainWindowCorners (#3949); internal/gui again
  after the last edits: the same, TestCoreScriptBudget ok (1,533,773 of
  1,533,802, no raise).
- GUI, the 262 files a change here can reach, at the head and at the
  base: the reds at the head are the base's, with their issues:
  menu-input-scroll #3402, provider-mask #5109, context-fold and
  order-unknown (webkit) #3479, header-centre #3479, i18n-keys
  #5332/#5426/#5482, account-eye #5052/#4244, call-headers webkit de
  #5045, codex-predictions #2624, codex-auto-reset webkit de #4790,
  routing-* under load #5088, and zero-priced-free, last-page,
  reasoning-speed, routing-row-swap/-tag-whole/-story-shrinks/-steps-cap
  and routing-intent-entry, red at the base the same way.
- After the last edits: the 11 files with a way to the groups page or
  its scroll (group-*, routing-groups-page, routing-mode-goes,
  routing-groups-off, routing-provider-off, routing-many-keys,
  click-scroll), 175 of 176; the one red is routing-many-keys webkit's
  wire at the foot, red at the base in 8 of 12 (#5543). brand,
  gateway-mode-sessions, header-zoom-fit, header-centre,
  inner-scroll-contain and mobile-web: the same 11 reds at the head and
  the base (mobile-web compares with origin/main through git, which a
  mote-run copy hasn't).
- Rebased on ecc26a339, again: gofmt -l, go vet ./internal/gui and
  TestCoreScriptBudget ok; 10 GUI files (i18n-keys, routing-groups-page,
  routing-mode-goes, sidebar, brand, menu-first-second, library-bar-more,
  click-scroll, name-suffix-saved, unlisted-models) 211 of 212, the one
  red i18n-keys' "a plugin's words are its own", red the same at
  ecc26a339 (#5332/#5426/#5482).
- Broken by hand: without the groups page's CSS rule, brand and
  routing-groups-page go red (32 fails); with the old goRouting,
  routing-mode-goes is red in 9 of its 10 WebKit cases.

Not tried: the whole GUI suite on Linux (WSL magpie-desktop) at this
head; a run at an earlier head is under way and has the Linux reds
#4120/#4121 name. Not tried in the real macOS app, only Playwright's
WebKit.
2026-11-06 23:11:43 +08:00
yetoneandmdwsk88 dbaeaec124 claude-desktop: a model picked for two tiers is listed for the second too, so that tier isn't left empty (#5534)
Claude Desktop keys a profile's inferenceModels by name and reads one tier
off an entry: for each tier, the entry tagged with it (isFamilyDefault
first) names ANTHROPIC_DEFAULT_<TIER>_MODEL for the Code tab's Claude
Code (JNn/WNn in 4.16336's app.asar, FPn in 4.23118's). desktopTierOf
tags a model picked for two tiers with the first only, so the second had
no model. dawei picked copilot/claude-sonnet-5.5 for sonnet and haiku
(Copilot has no Haiku 5.5); Desktop spawned Claude Code with
ANTHROPIC_DEFAULT_HAIKU_MODEL empty, and its small tasks (WebFetch page
summaries) ran on the session's copilot/claude-opus-5.5 at 94-244 s each.

Now:
- desktopSharedTiers: each tier whose pick an earlier tier already has.
- DesktopInferenceModels lists such a model once more per later tier,
  after the rows (the first row, which a new session starts on, stays
  first), tagged with the tier and isFamilyDefault, with the row's 1M
  fields and its label plus " · <tier>".
- desktopTierAlias names it in the form claudeLooking gives the model
  under a number made of its id and the tier (magpie-<n>.anthropic.<model>,
  mythos-magpie-<n>, or anthropic/magpie-<n> for a model listed by its own
  id). aliased reads that number back to the model, so the gateway serves
  it as the pick (desktopTierAsked), and a session saved on it is still
  served after the picks change.
- desktopRunsAs (previous commit) gives it behavesAs where Claude Code
  doesn't know the id.
- agent: CLAUDE_CODE_MODEL_CAPABILITIES and the modelSettings budgets
  carry the extra ids too (gateway.DesktopTierAliases).
- docs/subsystems/gateway-routing.md and agent-wiring.md say so.

Not changed: /v1/models still tags one row per model (Desktop reads no
/v1/models while the list is written); the Providers page's Desktop
number is the first id's. Desktop's menu shows the extra entry
("Claude Sonnet 5.5 · Copilot · haiku"); the list has no hidden entries.

Ported from mdwsk88's desktop-tier-shared-pick (817edde09), reviewed line
by line. Added here: TestDesktopTierSharedPick's "every tier" (one model
for opus, sonnet, haiku and fable: three extra entries, every name
distinct, each tier tagged once, each id read back and its tool-less
small task served on the pick while the session is on another model)
and "own id" (a Claude model with no reasoning levels, listed by its own
id: the later tier is anthropic/magpie-<n> with behavesAs that model).

Run on mote (go1.26.8):
- TestDesktopTierSharedPick (4 subtests), TestDesktopGroupPickRunsAsItsModel,
  TestClaudeDesktopModelsSharedTier, TestClaudeCapabilitiesDesktopSharedTier:
  ok. Broken by hand, each red:
  - desktopSharedTiers looping over no tier (the old behaviour): all four
    subtests ("haiku has no entry"), and both agent tests;
  - aliased not reading a tier's number back: all four subtests
    ("magpie-2213721611.anthropic.claude-sonnet-5-5 read back as ...").
- go test -run 'Desktop|Claude|Alias|Tier' ./internal/gateway
  ./internal/agent: ok. go vet darwin, linux (-tags nogui), windows,
  go build ./...: ok. gofmt -l: nothing.
- Desktop's own code: the list this commit gives for opus m1, sonnet and
  haiku claude-sonnet-5-5, fable m1, run through JNn/WNn taken verbatim
  from Desktop 4.16336's app.asar in node: HAIKU =
  magpie-2213721611.anthropic.claude-sonnet-5-5, FABLE =
  mythos-magpie-7663130977, OPUS and SONNET as before. The same list
  without the extra entries (the old one): HAIKU and FABLE "".
Not tried: a real Claude Desktop reading the list and starting Claude
Code; the Playwright suites (no GUI file changed). The full suite runs
after the push.

Reported-by: dawei (Discord)
Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
2026-11-06 22:50:26 +08:00
yetoneandmdwsk88 428ec17a9d claude-desktop: a routing group picked for a tier runs as the Claude model leading it (behavesAs) (#5534)
A routing group is listed to Claude Desktop by its mythos-magpie-<n>,
never as the Claude model its first member is (claudeLooking), so the
Code tab's Claude Code doesn't know it by that id. A pick's
inferenceModels entry got behavesAs only when the pick wasn't a Claude
model (claudeModel), which a group led by one is: the entry had no
behavesAs, and Claude Code ran the tier with its generic prompt and
defaults (seen with auto/claude-sonnet-5-5 picked for haiku).

desktopRunsAs decides by the id the entry is listed by: nothing where
Claude Code knows a Claude model by that id (magpie-<n>.anthropic.<model>
or the model's own id), the Claude model the entry is where it is listed
by mythos-magpie-<n> or anthropic/magpie-<n>, else the tier's newest
Claude model, as before. DesktopBehavesAs follows, so Claude Code's
modelSettings tell the group its own window (claudeBudget.behaves).

Ported from mdwsk88's desktop-tier-shared-pick (eb802f763), reviewed line
by line, unchanged.

Run on mote (go1.26.8), at this commit and the next together:
- TestDesktopGroupPickRunsAsItsModel ok; with desktopRunsAs's mythos/alias
  branch taken out by hand it is red ("the group, shown as
  mythos-magpie-4305132155, runs as <nil>; want claude-sonnet-5-5"), as is
  the next commit's own-id subtest.
- go test -run 'Desktop|Claude|Alias|Tier' ./internal/gateway
  ./internal/agent: ok. go vet darwin, linux (-tags nogui), windows on
  both packages, go build ./...: ok. gofmt -l: nothing.

Reported-by: dawei (Discord)
Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
2026-11-06 22:50:10 +08:00
yetone 25b201eb67 library: the Skills and MCP headings keep Select and put the rest under ⋯
ryanpascal on Discord: the Library › Skills heading had too many
buttons, up to a dozen beside the sort. The heading now shows the sort,
Select, Clean up and Update n when they apply, and a ⋯ (the app's row
menu, openRowMenu) holding Check for updates, Update all, Group again,
Collapse all / Expand all, Turn all on, Turn all off, By agent, Manage
n in magpie and Remove all, in that order with separators. The MCP
servers heading does the same with Turn all on, Turn all off, By agent
and Remove all. A busy action stays in sight on the bar (Checking…,
Grouping…, Updating…), so the wait is seen. Each menu item is the old
button: its words, its title, greyed when it was, its click; Remove
all is red as it was. No new words: ⋯ is the core's "More".

barMore builds the menu from the buttons as they are when ⋯ is
pressed, so a count or a greyed state is never stale; a hidden button
is left out and the ⋯ itself is hidden when nothing is left.

The tests that pressed these buttons on the bar (by-agent, every-skill,
github-token, library-gone-agents, library-null-agents,
library-servers-bulk, remove-all-skills, skill-fold-all,
skill-git-source, skill-handover, skill-new-in-repo, skill-regroup)
now open ⋯ and press the item. docs/subsystems/library.md says where
the buttons are.

Run (mote, through mote-run):
- node --test library-bar-more.test.cjs: 22 pass (en, zh, zh-TW, ja,
  de at 420 and 1180 px, Chromium and WebKit): nothing moved is on the
  bar, ⋯'s label, one line at 1180, the menu's items and order in each
  language, the menu inside the window, a second ⋯ closes it, Turn all
  off's sheet, Check for updates posting once, the MCP heading's menu,
  no sideways scroll.
- the 12 updated files plus library-bar-more: 176 pass before the
  usage fix below, the 22 reds all library-bar-more's (its second ⋯
  click eaten, the cause fixed in the commit before this; then the
  wide window's tabs, which are the side nav's, fixed in the test).
- skill-manual, list-sort, skill-gone, skill-update-edited, skill-how,
  library-hooks, library-pick-remove, library-row-remove,
  menu-first-second, i18n-keys, i18n-en-no-cjk: 127 pass, 1 fail, the
  "a plugin's words are its own" red that origin/main fe61503e6 has
  (#5327, #5426, #5482).
- the whole GUI suite under the suite lock: 21630 tests, 21295 pass, 335 fail in 63
  files. Those 62 files (i18n-keys apart) again at fresh origin/main
  18a9a2d88 and at this head, concurrency 6: 308 fail at main, 291
  here, in the same files, each with an open issue (umbrella #5475).
  The five red only here (account-arrange, account-mask,
  codex-subagent-model, connect-snippet-shell, ledger-swipe), each
  failing different cases each run, pass 52 of 52 run alone here.

At the pushed head (rebased on origin/main 361da10ee, which brought
77bda84a6's folder Check for updates: its condition and title kept,
the button moved under ⋯ like the rest, and skill-new-in-repo's new
folder case opens ⋯), on mote: the 17 files above plus
skill-new-in-repo, 239 pass, 1 fail, the known i18n-keys red (#5332).

Broken by hand: HEAD's client.js and library.css (the old bar) put
back, library-bar-more red in all 22 cases ("a moved button is still
on the bar", 7 !== 0).

Not tried: the real app with the user's own library; the tray panel
has no Library; keyboard order through the menu beyond the first
item's focus (openRowMenu's, unchanged).

Reported-by: ryanpascal (Discord)
2026-11-06 22:27:09 +08:00
yetone adcb69107c library: a skill set to disable-model-invocation is marked Manual only
sunset3279 on Discord asked to see which skills set
disable-model-invocation: true in their SKILL.md, the ones Claude Code
runs only when the user types /name. parseMeta reads the field into
meta.Manual; the library's rows (SkillView.Manual) and the agents' own
(FoundSkill.Manual) carry it, and the page puts a quiet "Manual only"
tag after the name, its tooltip naming /name and the field. A front
matter that doesn't parse, or a value that isn't a bool, is not known
to be manual: no tag. Translated in zh, zh-TW, ja and de.

Run (mote, through mote-run):
- go test -run 'TestSkillManualFromFrontMatter|TestSkillsFromFolder|TestFoundInLibraryFolder' ./internal/library: ok
- node --test internal/gui/tests/skill-manual.test.cjs: 22 pass, 0 fail
  (en, zh, zh-TW, ja, de at 420 and 1180 px, Chromium and WebKit)
- go test ./internal/library: ok (692s)
- go vet ./internal/library for darwin, windows and linux (nogui): ok
- node --test i18n-keys and i18n-en-no-cjk: 7 pass, 1 fail. The fail is
  "a plugin's words are its own", the same three entries on origin/main
  fe61503e6 (#5327, #5426, #5482); none is a word of this change.

Broken by hand:
- the Manual assignments in sync.go and skills.go taken out:
  TestSkillManualFromFrontMatter red ("deploy: manual false, want
  true", "crlf: …", "release: {…Manual:false…}").
- the manualTag calls in client.js taken out: all 22 GUI cases red
  (null, want 'Manual only').
- an explicit error branch in parseMeta was tried and left out: the test
  passed with and without it, since yaml.v3 decodes nothing on a syntax
  error and leaves a wrong-typed field zero.

Not tried: the real app with the user's own skills; the TUI and CLI show
no mark. A long name clips its tag in a narrow window, as every name tag
in the row does (.row .name is nowrap; #5512); the test uses short names.

Reported-by: sunset3279 (Discord)
2026-11-06 22:22:20 +08:00
yetone 361da10ee9 web: the page's API answers its own origin only, not a page on another port or a sibling subdomain
With browser access on (Settings > Browser access, or magpie web), the
sign-in cookie magpie_web_<port> is SameSite=Lax, which a browser sends
with any same-site request: another port of 127.0.0.1 or of the LAN
address, or a sibling name behind the same reverse proxy. apiFramed
refused Origin null, frames and cross-site, but not same-site, and /api
decodes JSON from any Content-Type. So such a page could POST a stdio MCP
server to /api/library/servers/save (text/plain, no-cors) and start it
with /api/library/mcp/check: code run as the user.

webOwnPage (in webHandler, behind webGuard, /api/ only) now judges every
write (all methods but GET/HEAD/OPTIONS) with net/http's
CrossOriginProtection: Sec-Fetch-Site same-origin or none passes, any
other value is refused; from a browser without Sec-Fetch-Site, Origin must
be absent or name the request's Host (or MAGPIE_PUBLIC_URL, for a proxy
that rewrites Host). Any /api request, a GET too, whose Sec-Fetch-Site is
same-site or cross-site is refused, so no GET route with a side effect
(GET /api/import/{id} reads once and deletes) is another page's to call,
without auditing each one. A Sec-Fetch-Site same-origin with an Origin
that doesn't match the Host passes: the browser compared the origins
itself, and nginx's default proxy_set_header Host $proxy_host would
otherwise break every write behind it. The desktop window's /api is served
in-process over no port with no cookie, so it isn't wrapped and its
headers are unchanged. No Content-Type rule: every write the page makes
goes through api() as application/json, but multipart and text/plain are
both CORS-safelisted, so the rule would add nothing the origin check
doesn't already give.

Run on mote at 49c9491b7 + this commit; after the rebase onto e1eeeed73 (38 commits, none in web.go/pluginpage.go/api.go) gofmt, the three vets of internal/gui and -run TestWeb were run again: ok.
- TestWebAPIAnswersItsOwnPageOnly, through webServed (onePort ->
  AllowGuard -> webGuard -> webOwnPage) with the page's cookie and no
  gateway key. Refused: same-site Origin on another port, cross-port
  Origin without Sec-Fetch-Site, localhost on another port, the LAN
  address on another port (both), a sibling subdomain (both), cross-site,
  Origin null (both), no Origin with Sec-Fetch-Site same-site and
  cross-site, GETs from another port, a sibling and a cross-site link, a
  cross-port preflight. Allowed: the page's own origin (with and without
  Sec-Fetch-Site), on the LAN, behind a proxy keeping or rewriting the
  Host, MAGPIE_PUBLIC_URL with an old browser, Sec-Fetch-Site none, a
  non-browser client with the cookie.
- Real browsers: magpie web built from origin/main and from this commit
  (-tags nogui, sandbox HOME, MAGPIE_WEB_KEY), an attacker page on
  127.0.0.1:3497 / localhost:3497 running the no-cors text/plain POST.
  Old: the attacker's server was saved in Chromium and WebKit. New: not
  saved in either, logged "turned away ... Sec-Fetch-Site"; the page's
  own JSON write answered 200 in both.
- go test -tags nogui ./internal/gui -timeout 45m: ok
- gofmt -l: nothing; go vet ./internal/gui/... ./internal/cli/...,
  GOOS=windows go vet ./internal/gui/..., GOOS=linux go vet -tags nogui
  ./internal/gui/...: ok

Broken by hand: webOwnPage taken out of webHandler -> 29 cases red
("reached true, want reached false"). The read rule taken out -> the
three GETs and the preflight red. cop.Check skipped -> the 8 old-browser
cases red.

Not tried: the full ./... suite (the change is one handler in
internal/gui); the GUI Playwright suite (its pages mock /api with
page.route and never reach this server; the real-browser check above
stands in); a real reverse proxy; the Windows and Linux app pages; the
MAGPIE_DEV_UI dev server, which serves /api with no key and isn't
wrapped.
2026-11-06 22:17:04 +08:00
yetone e1eeeed734 browser: the extension's key connects Magpie Browser and nothing else; own needs this computer; a key turned off closes its browser
483b131ef wrote a full-access gateway key ("Magpie Browser") into the
extension zip in Downloads. Anyone with a copy of the zip could use every
model, MCP server and stat, and, with own = key == OwnBrowserKey(), could
connect from another machine as this computer's own browser and receive
this computer's agents' browser calls (page data out, prompt injection
in). A keyed WebSocket also stayed open after its key was turned off.

- access: Key.Browser / Identity.Browser. A browser key is also ReadOnly
  (so a magpie from before reads it as read-only) and never issues keys.
  access-key and issuer-key refuse it. ScopeBrowser(id) holds an existing
  key to the browser with the same secret; the sharing key is never
  scoped. Current(who) says whether a key Check took is still on by the
  same secret (Identity carries the secret's SHA-256, set on the legacy
  sharing-key fallback too, so a legacy caller's identity is the same
  before and after its migration).
- gateway readOnlyGuard, the one place every route passes after the key
  is known: a browser key gets 403 gateway_key_browser_only on every
  pattern except GET /v1/magpie/browser/extension.
- own: the key must be OwnBrowserKey() and the request local(r)
  (loopback peer, not proxied, not the page port).
- browserConn keeps its key's identity. call() refuses a connection whose
  key is no longer Current, and a 5s watcher closes it (1008).
- gui browserKey: a new key is made Browser; the recorded key is reused
  only once ScopeBrowser holds it.
- GUI key row: "Browser only" tag (zh, zh-TW, ja, de), no access toggle.
  CLI prints "browser" access. agent gatewayTakes skips a browser key.

Old data: an existing "Magpie Browser" key (OwnBrowserKey) is rescoped in
place, same id and secret, when the gateway starts (ScopeOwnBrowserKey)
and again on the next extension download. Installed extensions keep
connecting with no reinstall. Every copy of an old zip loses models, MCP,
stats and writes, and from another machine it is no longer this
computer's browser. A user who downgrades reads the key as read-only.
Keys a user made themselves are untouched.

Regression, filed as #5529: Magpie in Docker with the host's Chrome
reaches the container from 172.17.0.1, not loopback, so its agents no
longer get the host's browser as their own. #5529 proposes pairing in
its place. docs/reference.md and site docker pages (en, zh, ja) say so.

Docs: docs/subsystems/gateway-routing.md (browser key), library.md
(Download), docs/reference.md (Docker), site/public/docs{,/zh,/ja}/docker.html.

Run on mote at origin/main 2000ae439 + this change:
- gofmt -l internal cmd: empty.
- go vet darwin, GOOS=windows, GOOS=linux -tags nogui over access,
  gateway, gui, agent, cli: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ./internal/gui ./internal/access ./internal/library ./internal/agent
  ./internal/cli: all ok except access's
  TestLegacyLANFallbackBeforeMigration, red from this change (the legacy
  fallback had no secret sum). Fixed here, then ./internal/access in full:
  ok.
- GUI, 21 files (gateway-key-*, i18n-*, library-browser-*), chromium and
  webkit, every language: 332 of 334. The 2 reds fail the same on
  origin/main 6f5d48ea0 run alone: i18n-keys "a plugin's words are its
  own" (#5332, #5426, #5482) and gateway-key-models' 560px width check
  (#4081, commented).

Rebased onto 6f5d48ea0 (remote_prove: a new POST /v1/magpie/prove route
and edits to readonly.go and gateway.go, so not a -run rerun): gofmt -l
empty, vet on all three ok, go test -count=1 ./internal/gateway
./internal/access ok, ./internal/gui -run Browser ok. A browser key gets
403 on the prove route too (TestBrowserKeyEveryRoute walks every pattern).

Broken by hand, each red on mote:
- guard off: TestBrowserKeyEveryRoute (/v1/ 200, /v1/models read_only
  not browser_only).
- no migrate: TestBrowserKeyEveryRoute (/v1/models 200).
- own without local(r): TestOwnBrowserKeyIsThisComputers.
- no watcher: TestBrowserKeyOffClosesItsBrowser (stayed connected).
- no Current check in call(): TestBrowserKeyOffClosesItsBrowser.
- Current ignoring the secret: TestCurrent.
- gui reuse without ScopeBrowser / new key without Browser:
  TestBrowserExtensionDownload (both).

Not tried: a real Chrome with the real extension, a real Docker
container, a real old key in a live HOME, the TUI. No CLI test for the
"browser" access word. Tests reach no network (httptest, loopback only).
2026-11-06 22:11:02 +08:00
yetone 6f5d48ea0f remote magpie: a moved remote is looked for again, and is sent its key only after it proves it holds it
fe61503e6 had a Remote magpie whose address didn't dial look for it on
the old address's /24 and this computer's private /24s, and sent GET
/v1/models, signed with the provider's gateway key (Authorization,
x-api-key and the provider's own headers), to every address that took
the connection at the port. On a café's or hotel's network, or with the
other computer off, anything listening there got the key in clear and,
by answering {"data":[]}, became the provider: the failed request and
every later one went to it. 18a9a2d88 turned the look off.

Now an address that takes the connection is first asked to prove it
holds the key, with nothing keyed sent:

- B POSTs {"nonce": 32 random bytes hex, "key_id": sha256(key) hex} to
  /v1/magpie/prove (provider.RemoteProvePath), no key, no provider
  headers, no proxy, no redirects (proves in remote_moved.go).
- A (gateway's remote_prove.go) finds the enabled gateway key with that
  sha256 (access.ProveSecret: constant-time compares over every key,
  the legacy settings sharing key too, then Check, so an off, expired
  or orphaned issued key has none) and answers
  HMAC-SHA256(key, "magpie-prove-v1\n" nonce "\n" address), the address
  being the one the connection reached it at (http.LocalAddrContextKey);
  404 when no key matches. A host that relays B's nonce to A elsewhere
  gets a proof for A's address, which B, checking against the address it
  dialled with hmac.Equal, refuses.
- Only after that does isRemote ask /v1/models with the key, as before.
- The route goes through lanGuard like OIDC's trade (proveAsked: POST,
  exact path, no gateway key): from another machine only while shared,
  past the allow list and rebinding check; corsGuard still judges its
  Origin, the handler refuses anything fromBrowser, and an unknown id
  from another machine counts against tooManyAuthFails. readOnlyRoutes
  lists it (it carries no key and answers none).

seekAt is lanNeighbours again: the old /24 and this computer's own
private /24s, both behind the proof.

Not found, and so safe: a remote magpie from before this route (404), one
not shared (403), one reached through a port forward, NAT or a Docker
port (it sees another local address than the one dialled), and one behind
a proxy that needs the provider's headers. Each fails as before
fe61503e6 and the user types the new address.

Tests (local httptest servers only):
- TestRemoteMagpieKeyGoesToNoNeighbour, rewritten from 18a9a2d88's "no
  address looked at": four impostors that list 200 for anything (no
  proof route; a well-formed proof under another key; a garbled proof;
  one relaying B's ask to the real magpie and handing back its proof)
  are asked only the proof, never see the key or the provider's custom
  header, and aren't saved; then the real magpie, last in the list, is
  found and saved.
- TestRemoteProof: another key, nonce, address or port is another proof;
  an IPv4-mapped IPv6 address is the same address.
- TestRemoteProveAnswersOnlyTheKeysHolder (gateway): from another
  machine while shared, the key's holder answers the right HMAC and never
  the key; an unknown id and a key turned off get 404; Origin, a Mozilla
  User-Agent and Sec-Fetch-Mode are refused; not shared, 403.
- TestRemoteMagpieMovedIsFound now uses a real gateway key on A.

Run on mote at this tree (base 18a9a2d88):
- gofmt -l internal cmd: clean
- go vet ./internal/provider ./internal/gateway ./internal/access (darwin,
  with and without -tags nogui), GOOS=windows go vet, GOOS=linux go vet
  -tags nogui: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/gateway ./internal/access: provider ok (206s), access ok,
  gateway FAIL on TestUnroutedHeldReportSaved only ("(under way)"),
  the open #4300, a file this change doesn't touch; it passes alone
  with -count=3 on mote.

Rebased onto 2000ae439 (its gateway.go change, the Antigravity format
check in models(), sits beside this one's route line). Rerun on mote at
the rebased head: gofmt clean; the same four vets ok; go test -tags
nogui -count=1 -run 'RemoteMagpie|RemoteProof|RemoteProve|LANNeighbours|
Dialable|ReadOnlyKeyEveryRoute|OIDCToken|Antigravity|KeyPage' over the
three packages: ok. The full suite was not run again.

Broken by hand, each red:
- isRemote without the proves check: the impostor with no proof route
  is sent the key and the header, is saved, and the real magpie is never
  reached.
- RemoteProof without the address: the relaying impostor passes, is
  sent the key and saved; TestRemoteProof red too.

Not tried: a real look across two computers on a LAN (A on mote, B in
WSL as fe61503e6 did); a real Windows A; IPv6 link-local addresses (not
looked at). Residual: a user-chosen weak gateway key (8+ characters)
can be guessed offline by an impostor from its sha256; magpie's own keys
are 24 random bytes.

Push rejected once; rebased onto f4068ccc2 (proc only, none of this
change's files). Rerun on mote there: gofmt, the same vets and the -run
tests above: ok.
2026-11-06 21:32:55 +08:00
yetoneandvincent f4068ccc25 proc: with Detect agents in WSL off, no wsl.exe is started on any path (#4872)
With Settings' Detect agents in WSL off (noWSLAgents), every Claude
request still reached wsl.exe: wslReady (wslClaudeStandIn,
wslCodexStandIn) and wslClaudeClassifier listed the running distros
without asking wslLooks, the gate #1264 put on wslAgents, wslHomes and
WSLRunning. wslrun's Up, In and running weren't gated either (only
Find was). On a computer without WSL, Windows' inbox wsl.exe answers
each ask with a window offering to install WSL, one per request.

The fix is at the one choke point every command magpie starts goes
through (TestNoCommandBypassesProc): proc.Command and CommandContext
(and so ProbeContext, wslrun.Tool.Command/Probe, the Claude TUI
helper's ConPTY start, which checks cmd.Err) refuse wsl.exe by any
name or path (wsl, WSL.EXE, C:\Windows\System32\wsl.exe) with
proc.ErrWSLOff while the setting is off, as a probe of an app's own
program is refused. The paths that reach it: agent's wslRun/wslExec
(lists, probes, links, chmod, reach), wslrun.Run/Find/In/Up/Stop,
library's cmdvars, mcp_wsl, mcp_check and rtk_wsl, claudetui's
wslread, the gateway's Claude Code in WSL. The settings read is
settings.Shared() and only for a wsl name. Not gated: the Sessions
page's resume line for a WSL session (a string a terminal runs on the
user's click), whose sessions aren't listed with detection off.
skygunner/vincent's stand-in fix is kept as well, so the stand-in and
classifier return before taking wsl's lock or recording a failed list.

Run:
- mote-run: go vet ./internal/proc ./internal/agent ./internal/wslrun;
  GOOS=windows go vet of proc, agent, wslrun, claudetui, library,
  gateway; GOOS=linux go vet of proc, agent, wslrun, claudetui: clean.
  go test -count=1 ./internal/proc ./internal/wslrun ./internal/claudetui:
  ok; -run 'WSL|Wsl|Dsh' ./internal/agent ./internal/library
  ./internal/sessions: ok. gofmt -l: nothing.
- win-run on xiaomi-gpu (Windows 11, real wsl.exe present): the four new
  tests plus TestWSLDetectionOff, TestWSLClaudeStandIn,
  TestWSLCodexStandIn, TestNoCommandBypassesProc: ok; -v shows each new
  test PASS; go test ./internal/proc ./internal/wslrun whole: ok.
  TestWSLRunnerRefusedWhenOff runs agent's real wslRun there.

Broken by hand (wslOff's check made `if false && …`, agent/wsl.go at
origin/main, new tests kept), on mote: TestWSLOffStartsNoWSL red for
every name and maker, TestRunRefusedWhenOff "Run ran wsl.exe: exit
status 1", TestWSLRunnerRefusedWhenOff red, TestWSLStandInAsksNothing
WhenOff red with three "-l --running -q" asks.

Not tried: the reporter's own Windows without WSL (the install window
itself); the full suite runs after the push under the suite lock.

Reported-by: 陌离 (Discord)
Co-authored-by: vincent <vincent@users.noreply.github.com>
2026-11-06 21:28:24 +08:00
yetone 2000ae4398 antigravity: each model's window reaches the app through its catalog; the notice names what a gateway turns off (YujunT46308)
YujunT46308 on X: wired through magpie, Antigravity 2.29.0 showed a
200K window for every model, and after a restart it lost /boost,
/teamwork, /plugin and /generative_ui.

The window. The app's backend (Resources/bin/language_server) resolves
models from models.list, then models.listSource (a remote catalog,
fetched with the gateway key), then <url>/v1/models, then its built-in
catalog. From /v1/models it reads the id alone; a model its catalog
doesn't know gets its family's defaults, maxTokens 200000. No field of
the OpenAI list (context_window, context_length, max_input_tokens) is
read. magpie now points models.listSource at
<gateway>/v1/models?format=antigravity, which answers {"list": [...]}
in the app's own fields (modelId, displayName, maxTokens,
maxOutputTokens, supportsImages, supportsThinking) for the models the
key may use. A field magpie doesn't know is left out. The user's own
listSource is stashed with their gateway and put back; Sync adds the
catalog to a file wired before, at the gateway's current address.
The picker now shows magpie's names, so NoNames is off for it.

The Google features. Not fixable on this route: on a gateway the app
uses no Google sign-in and its backend calls neither cloud_code_endpoint
nor api_server_url (headless run below), and Google's docs say a gateway
and a Google Account can't be used at once. The experiments and
commands Google's servers turn on for a signed-in account are off while
it is on magpie. No key in settings.json keeps both. The notice shown on
connecting (GUI toast, CLI) now names what is lost and that turning it
off gives it back, in en, zh, zh-TW, ja, de.

Run (mote, at this head unless said):
- go test -tags nogui ./internal/agent ./internal/gateway -run Antigravity:
  ok. Broken by hand: the listSource writes taken out ->
  TestAntigravityGateway, TestAntigravityCatalogSource,
  TestAntigravitySyncAddsCatalog red; the ?format branch taken out ->
  TestAntigravityCatalog red.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: ok.
- GUI (Chromium and WebKit): i18n-keys, i18n-en-no-cjk,
  agent-notice-lang, about-notices, gui-de, gui-ja, gui-zh-tw,
  name-suffix-no-names at the pre-rebase tree (only i18n.js differs in
  the GUI): all pass except i18n-keys "a plugin's words are its own",
  red the same on origin/main 18a9a2d88 (#5332, #5426, #5482).
- Real: the real Antigravity 2.29.0 language_server, headless, in a
  sandbox HOME, against magpie built from this tree (sandbox HOME, port
  3600) with a fake OpenAI vendor whose model has a 1048576 window.
  `magpie antigravity magpie/up/big-ctx` wrote listSource; the backend
  logged "Resolving models from Tier 2 (Remote catalog listSource)",
  GetAvailableModels gave maxTokens 1048576, maxOutputTokens 65536 and
  the label "big-ctx · up". A streamed chat with the app's key and UA
  went through magpie. Turning it off left the file as it was ({}).
- Full go test -tags nogui -timeout 45m ./...: queued behind mote's
  suite lock at push time; its result is recorded after the push.

Not tried: the Antigravity GUI app itself (only its backend, headless),
and a chat sent from the app's own composer.
2026-11-06 21:21:34 +08:00
yetone 18a9a2d883 remote magpie: a remote that can't be reached is not looked for on the network, which sent its key to every neighbour
fe61503e6 had a Remote magpie whose address didn't dial look for it on the
old address's /24 and this computer's own private /24s. It sent GET
/v1/models, signed with the provider's gateway key (Authorization and
x-api-key, plus custom headers), to every address that took a connection
at the port, and saved the first that listed 200. On a café's or hotel's
network, or with the other computer just off, anyone listening at :3425
got the other magpie's key in clear. By answering {"data":[]} they
became the provider, so the failed request and every later one (prompts,
files) went to them, and they could hand back tool calls.

seekAt now looks nowhere. A remote that can't be reached fails as it did
before fe61503e6, and the user types the new address. lanNeighbours stays
for the real fix, in which an address proves it holds the key before the
key is sent to it (being written now). Tests still look where SeekHere
says. The providers-accounts page says the look is off and why.

Run on mote at this tree (base 06c4582cc): gofmt -l internal/provider
clean; go vet ./internal/provider; go test -tags nogui -count=1 -run
'RemoteMagpie|Neighbour|Moved' ./internal/provider ./internal/gateway ok.

Broken by hand: seekAt = lanNeighbours again turns
TestRemoteMagpieKeyGoesToNoNeighbour red (506 addresses looked at for
192.168.77.20).

Not tried: the full suite, or Windows and Linux beyond what this one-line
change needs.
2026-11-06 21:06:48 +08:00
yetone 06c4582cca remote magpie: a list changed on the other magpie reaches this one's agents at once
KaCli (Discord) runs two magpies: the server's is the gateway, and the
local one has it as a Remote magpie and writes its models into dsh. A
route or group changed on the server reached the local dsh only on the
next 10-minute fetch (#2135's RemoteMagpieEvery). The server knows when
its list changes (filememo), so it now says so.

- Server: GET /v1/models with X-Magpie-List-Wait: <secs> and
  If-None-Match answers the list with an ETag once it differs from that
  tag. It answers 304 at the end of the wait (at most 50s, under a
  proxy's 60s) or as the gateway stops. The list is looked at again on
  each magpie write and on each change another process makes to its
  files (filememo.Written). It is the list's own route, so the key,
  lanGuard, corsGuard and a key's models judge it as before. The wait is
  exempt from holdCatalog, and each look holds the catalog for itself.
  Without the header the answer is the same as before, with no ETag.
- Client: KeepRemoteListsFollowed (started beside KeepListsFresh) keeps
  one long-poll per Remote magpie. On a new tag it fetches the list
  through the same RefetchTaking, so catalog.Touched rewrites the
  agents' configs. A magpie from before answers at once with no ETag; it
  is left to the 10m schedule and asked again after an hour. A Remote
  magpie whose user set its list to "off" is not followed. The schedule
  stays as the fallback.

Run (on mote, through mote-run):
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build ./..., GOOS=linux -tags nogui and
  GOOS=windows builds: all ok.
- go test -tags nogui -count=1 ./internal/gateway ./internal/provider
  ./internal/catalog ./internal/filememo: all ok (gateway 863s, provider 152s, catalog, filememo).
- After the rebase on 650bf8412 (11 files changed under gateway and
  provider since): go vet of both, go build ./..., and -run
  "ModelsWait|RemoteMagpie|ListsFresh|HoldCatalog|Models" of both: ok.
- Two real magpies (this build, `serve`, sandbox HOMEs, 127.0.0.1:3561
  server and :3562 local, a gateway key, dsh profile web wired to
  office/up/m1). `magpie group add kacli-fast` on the server put
  office/group/kacli-fast in the local cordis.patch.yml in 1.14s
  (log: "office: its list changed there, fetched again: 3 models"). 130s
  idle after it: no further fetch.
  Control: origin/main on both, nothing in 37s. origin/main server, this
  local: nothing in 37s, logged once "doesn't wait ... fetched on its
  schedule", asked once.

Broken by hand, each red:
- Without the dispatch to the wait: TestModelsWaitTagged,
  AnswersAChange, EndsWithTheGateway.
- Without the filememo.Written wake: TestModelsWaitAnswersAChange
  (answered after 5.0s, at the others timer).
- Without RefetchTaking in the follower: TestRemoteMagpieListFollowed.
- Without the RefreshInterval > 0 check: TestRemoteMagpieOffNotFollowed
  (asked 3 times).
- Removing the holdCatalog exemption is caught by no test: a held
  catalog is still dropped on a write (heldFreshLocked), so the change is
  seen. It is kept so a 50s hold doesn't pin the build, as with a
  WebSocket.

Not tried: across two real computers on a LAN, or behind a reverse
proxy (only loopback with a key, and the LAN/no-key, foreign Origin and
Origin null refusals in TestModelsWaitGuardedAsTheList). Not tried on
Windows or Linux. Agents other than dsh weren't checked, though they go
through the same catalog.Touched sync.

Reported-by: KaCli (Discord)
2026-11-06 20:57:55 +08:00
yetone 650bf84128 docker: a daily tag that moves once a day, for Renovate
magpie releases many times a day, and YaoFur on X runs the image with
Renovate, which opened a PR on every tag ("改成每天凌晨更新一次").
Releases stay as fast as they are. ghcr.io/yetone/magpie:daily is new:
.github/workflows/docker-daily.yml points it at :latest's image once a
day, at 20:00 UTC (04:00 in China), by digest, as docker-stable.yml does
for :stable. It never builds, and touches no other tag; a click on Run
workflow moves it too. A Renovate user follows daily with its digest
pinned and gets at most one PR a day; stable is still there for one a
week.

The docs name it: the Tags row and the Updates line of the Docker page in
en, zh and ja, and the Docker section of docs/reference.md.
site/docker-tags.test.mjs holds that the three languages name the same
floating tags with daily among them, that a workflow writes each tag the
docs name, and that daily has one daily schedule, copies latest and
builds nothing.

The desktop app is unchanged: it already checks every 6 hours by
default, and Settings > About offers Check every 24 h and the Stable
channel (one a week).

Run (mote): node --test site/*.test.mjs, 90 of 90 ok; without the
workflow and the docs, two of docker-tags' three tests are red.
actionlint on docker-daily.yml and docker-stable.yml: clean. No Go file
changed; go test ./... -timeout 45m runs on the Linux box (wsl-run) at
this tree, since mote had another session's full suite running.
Not tried: the workflow itself before this push; it is run once with
workflow_dispatch right after it.
2026-11-06 20:52:29 +08:00
yetone 1f439ecc5e gateway keys: a limit can count only some models or providers (zola_xynb)
zola_xynb on X asked for a cap per model or per provider under one
gateway key. A key limit can now name models (access.Limit.Models,
"<provider>/<model>" or "<provider>/*"), so one key can have, for
example, a month of $20 on openai/* next to a month for the whole key.
Limits without models still cover the whole key, as before.

- budget: sums are kept per window and scope, and count a ledger row only
  when its provider/model matches (any of the model's ids). reserve holds
  a request to a scoped limit only when the model it names is served
  there. windowsOf keeps every scope's sums, so the ledger is not read
  again on each request.
- gateway: keyLimited puts the key's spent scopes on the caller
  (withSpent), count_tokens included. A direct request for a spent model
  gets a 429 with Retry-After and no X-Magpie-Limit-Reset, so a remote
  magpie rests only that model. A routing group, a provider's fallback
  and embedding/image/video/decision groups skip spent members
  (groupKeeps, allowedCandidates) and get a 429 only when none is left.
  System One, count_tokens and magpie's own calls for the key are held
  too. Model lists are unchanged. A refusal turned away before routing
  now records its ErrType in the ledger.
- CLI: magpie gateway-key limit <id> add month --cost 20 --model openai/*
  (--model repeatable, --models a,b).
- GUI: the key limit editor has a Models field that opens the app menu
  (multi-pick: All models, every model of a provider, each model). It has
  no <select> and no new screen. The badge, line and tabs name the models.
  Strings are in every language.
- docs: reference.md and subsystems/gateway-routing.md.

Run at d52725d32 (this change on 4ef47b3f4), on mote:
- go test ./... -timeout 45m, under the shared lock, with the log kept
  whole: every package ok except three reds outside this change. None of
  the three touches what changed:
  - TestClosedBeforeSentEveryTimeSaysWhy (#5031, passes alone 3/3)
  - TestMainWindowCorners/macOS_26_SDK (#3949, red alone on macOS 27)
  - TestMoveToPlugin TempDir cleanup (filed #5524, passes alone 2/2)
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., go build ./...: ok. gofmt -l: nothing.
- GUI, chromium + webkit: gateway-key-*.test.cjs, gateway-keys-*,
  i18n-keys, i18n-en-no-cjk and usage-remote-key-limits passed 244/246.
  The new gateway-key-model-limit runs in every language at 1100 and
  420px. The two reds also fail on origin/main 3cbb7e042:
  - gateway-key-models en at 560px (#4081, #4616, #5233)
  - i18n-keys "a plugin's words are its own" (#5327, #5332, #5426, #5482)

Broken by hand; each one turned the named tests red:
- groupKeeps' spent skip removed: ItsModelsAlone and MediaGroups.
- modelAllowed's spent check removed: ItsModelsAlone and AFallback.
- withSpent on count_tokens removed: ItsModelsAlone.
- the scoped refusal sending X-Magpie-Limit-Reset: ItsModelsAlone and
  SystemOne.
- sums counting every model: ItsModelsAlone, TestScopedLimitCountsItsModels
  and TestScopedBesideTheWholeKey.
- embeddings' keyGroupRefusal back to keyModelRefusal: MediaGroups.
- the turned-away row's ErrType dropped: ItsModelsAlone.
- keyHolds not holding for Spent: ItsModelsAlone, AFallback and
  MediaGroups.
- decide.go's 429 back to a 403 stayed green. keyLimited's reserve
  refuses a direct decider first, so that line is a second guard.

Not tried:
- a real vendor account or a real remote magpie.
- the Codex backend path and a video group: they go through the same
  keyLimited/groupKeeps code, but no test of their own.
- the whole GUI suite: only the files above.
- Windows and Linux test runs: vet only.
2026-11-06 20:47:21 +08:00
yetone 3cbb7e0429 plugin host: a plugin's redirect to another origin is sent none of its key headers (#5508)
Bun follows any redirect anywhere and, on a hop to another origin, drops
only Authorization and Cookie. Checked on Bun 1.4.2 before the change:
x-api-key, x-goog-api-key and a custom header reached a second local
server on each of 301, 302, 303, 307 and 308. So a vendor (or anything
answering at its URL) that redirected elsewhere got a plugin's key
headers, and an https vendor's redirect to http was followed.

host.js now applies provider.KeepsCredentials' rule (c57a5f7f5) at the
one place every plugin fetch leaves, `sent`:
- `followed` sends each hop with redirect "manual" and follows a 3xx
  itself only to the first request's origin (scheme, host, port), or
  http to https on the same host and default ports (`sameOrigin`, a
  port of provider.SameOrigin), at most 10 ("stopped after 10
  redirects", as Go's). Any other 3xx is given back to the plugin as it
  came, Location included.
- A bare request (no body, only accept/user-agent-like headers,
  BARE_HEADERS) still follows a redirect anywhere, as a download handed
  to a CDN does; it carries nothing of the plugin's.
- 301/302 on POST and 303 become GET with the body and its headers
  dropped; 307/308 send the body again, and a stream body that can't be
  sent twice makes the 3xx the answer.
- A fetch asked with redirect "manual" or "error" (mimo, cursor,
  gcp-ai and others do) goes out as it was asked.

Paths this covers, all of which reach globalThis.fetch and so `sent`:
- the gateway's request to a plugin account: Provider.do → the
  account's transport → plugin.Fetch → host "fetch" → fetchAs → the
  loader's fetch, or the host's fetch when the loader has none. A 3xx
  the host gives back reaches the caller as the vendor sent it.
- plugin.Fetch from the check-ins (MiniMax, Qoder, Trae, WorkBuddy) and
  the models/usage/check/decide reads through plugins.go.
- the plugin's own hooks: sign-in authorize/callback, models, usage,
  checkin, chat.headers, gateway request hooks, and pi.js's extensions
  (its watchFetch wraps the host's fetch).
- proxied ones: a provider's or account's own proxy (via / init.proxy),
  magpie's global proxy, the SOCKS bridge (netproxy.ForBun) and the LAN
  direct rule. Each hop is sent by `hop` (the old `sent`), so each picks
  its own proxy for its own host.
Not covered, filed as #5520: Bun.fetch (read-only and non-configurable
in Bun 1.4.2, so it can't be wrapped; no community plugin calls it), and
a library on node:http that follows redirects itself. node:http,
node:http2 and WebSocket follow none. The Go side needs nothing more:
Provider.do already hands a plugin account's request to its transport,
which doesn't follow.

Docs: provider-plugins.md (the rule, what isn't covered, the test) and
gateway-routing.md's list of what follows KeepsCredentials.

Test: TestPluginRedirectKeepsTheKeyAtItsOrigin (internal/plugin) drives
a real host with the fake plugin, sending x-api-key, x-goog-api-key, a
cookie, x-own and the loader's Authorization: 307 and 302 to a second
local server are the answer and that server gets nothing; an https
vendor's 307 to http on its own host and port is the answer; a
same-origin 307 is followed with every header and its body; a 303 is a
GET without Content-Type; a loop stops after 10; the usage hook's bare
GET follows a 302 elsewhere.

Broken by hand, on mote:
- `sent` passing every fetch to `hop` (Bun's follow): red. away307 and
  away302 answered 200 {"stolen":true}, and the other server got
  x-api-key, x-goog-api-key and x-own (not Authorization or Cookie:
  Bun's own drop).
- sameOrigin ignoring the scheme, and bare() always false: red. The
  https vendor's redirect to http was followed (400 "Client sent an
  HTTP request to an HTTPS server"), and the bare usage GET got the
  302's body instead of "cdn".
Restored, green.

Run on mote at this tree on origin/main 77bda84a6 (the docs' #5520
reference added after; no code changed since): gofmt -l clean; go vet
./..., GOOS=windows go vet ./... and GOOS=linux go vet -tags nogui ./...
clean. go test -tags nogui -count=1 -timeout 45m ./internal/plugin
./internal/gateway ./internal/provider: all ok (144s, 852s, 163s), no
red. No host.js node tests exist. The full ./... suite was not run.

Not tried: a real vendor's redirect (none known to redirect its API
elsewhere), an http to https upgrade on default ports (the test can't
bind 80/443), redirect "manual"/"error" from a plugin in a test (the
fake plugin's loader doesn't set one; the code passes such a fetch to
`hop` untouched), and Windows/Linux runs of the new test.

Rebased on 483b131ef (483b131ef browser, 6302f88bf sessions;
neither touches this change's files). At the rebased head, on mote:
gofmt -l clean, go vet (darwin, GOOS=windows, GOOS=linux -tags nogui)
ok, go test -tags nogui -count=1 -run TestPluginRedirect
./internal/plugin ok. The three package runs above were at 77bda84a6.
2026-11-06 20:16:44 +08:00
yetone 483b131ef0 browser: magpie in Docker uses the host's own browser, through a key the page hands out
noahhrreion ran magpie in a container and its Magpie Browser never
connected. The host's Chrome dials ws://127.0.0.1:3425/v1/magpie/browser/
extension, which reaches the container from the bridge (172.17.0.1). That
is not loopback, so the gateway refused it (403). The browser MCP also
refused every caller from elsewhere, and the hub marked the browser
HereOnly. The extension's folder under the container's HOME can't be
loaded by the host's browser either.

Nothing is opened to the network without a key:

- The extension takes a gateway key: its popup has a Gateway key field,
  and config.js carries KEY (extension 0.1.7). From another computer the
  extension connects only with ?key= of a gateway key that is on, and
  only from the extension's own Origin (checked first). Loopback is
  unchanged, and a page's origin, null, a keyless call or a rebound Host
  are all still refused (TestBrowserExtensionOnlyFromItsOrigin).
- A browser that connects with a key belongs to that key. Sessions are
  tagged key:<id>/... (browserOwner, keyedSession), and a remote caller's
  session is forced to its own key's whatever it names. The relay filters
  every lookup (forSession, all, choose) through browserConn.serves. The
  browser MCP admits a remote caller only with a gateway key; a web page
  is refused as before.
- The key the page makes is recorded as this magpie's own browser's: its
  id goes in settings.Dir()/browser-key, written temp-and-rename. This
  goes by where the key came from, not by its name. A browser connecting
  with it serves this computer's sessions too, so agents inside the
  container use it as they would one on loopback. A record that can't be
  read names no key, so no keyed browser is this computer's.
- Router: magpie mcp browser is HubServer.Keyed. A visitor from
  elsewhere gets it only with a key (HubVisitor.Key), and hubCall names
  its session key:<id>/..., so it reaches only that key's browser.
- GUI: a page whose browser can't reach magpie's folders (InContainer, or
  a page from another computer) is "away". The Magpie Browser sheet's
  button then reads Download the extension. It does a POST to
  /api/library/browser/extension with the page's origin, which answers a
  zip pointed at that origin (3430 passes the gateway's routes on) and
  holding the recorded key's secret. The key is made the first time and
  reused while it is on. The steps (unzip, chrome://extensions, Developer
  mode, Load unpacked) are shown in every language. It is a POST so that
  a link from another site can't mint a key.
- Docs: reference.md (Docker), subsystems/library.md and mcp-router.md,
  and site docker.html in en, zh and ja.

Run, at this tree rebased on origin/main 6302f88bf, on mote:
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., and darwin, linux and windows builds:
  clean, all ok
- go test -tags nogui -run 'Browser|Hub|OwnBrowser' ./internal/gateway/,
  and the whole of internal/library, internal/gui and internal/browserext:
  ok (gateway 2.4s, library 166s, gui 104s, browserext 0.3s)
- GUI tests library-browser-away (new: every language, Chromium and
  WebKit, 1100 and 420 wide), library-browser-setup, library-browser-ask,
  i18n-keys and i18n-en-no-cjk: 115 pass. One red, i18n-keys "a plugin's words are its own", is for three
  strings this change doesn't touch and is already filed (#5332, #5426,
  #5482)

Real use, in Docker Desktop on xiaomi-gpu (Windows 11): this tree's
Dockerfile image, run as `web --addr 0.0.0.0:3430` with 3425 and 3430
published to the host's localhost. The host's Node and Playwright Chromium:
- signed in to the page, which says away:true;
- downloaded the zip (GATEWAY "ws://localhost:3530" and a KEY), twice,
  getting the same key both times;
- a keyless /mcp/magpie/browser call from the host got 401;
- loaded the unzipped extension with --load-extension. The container's log
  says "Magpie Browser 0.1.7 connected with gateway key 12d2702a…" and
  /api/library/browser says connected:true;
- an MCP client on the host with that key listed b1 (Chrome 151), opened
  http://localhost:3531/ (served on the host) and read "hello from the
  host";
- a second gateway key made in the container got "isn't connected with
  this gateway key";
- a curl inside the container to 127.0.0.1:3425/mcp/magpie/browser with no
  key listed the host browser's tabs, the host page included.

Broken by hand, each red:
- forSession left unfiltered;
- a remote session not forced to its key;
- no Origin check on a keyed connect;
- hubCall not prefixing the session;
- Keyed given to a visitor with no key;
- the old MCP guard;
- browserKey not reusing the key;
- the away peer check removed;
- serves("") without own (TestOwnBrowserKeyIsThisComputers,
  TestOwnBrowserKeyUnreadable);
- OwnBrowserKey reading the wrong file (the gateway tests and
  TestBrowserExtensionDownload).

Not tried:
- the reporter's own setup (their compose file and Chrome);
- a real agent's MCP client calling the browser from the host. Node's
  fetch sends Sec-Fetch-Mode: cors, which fromBrowser counts as a web page
  and refuses. The e2e used node's http instead. Whether an agent's MCP
  client built on fetch is hit by this is not checked; filed as #5522.
- Edge, Brave and Firefox;
- a remote page over https/wss through a proxy.

What the user does: update magpie and publish 3425 and 3430. In the web
UI open Library -> Magpie Browser -> Download the extension, unzip it and
Load unpacked in chrome://extensions. An extension 0.1.7 already loaded
can take the address and key in its popup instead.

Reported-by: noahhrreion (Discord)
2026-11-06 20:06:15 +08:00
yetone 77bda84a6f library: a check offers the skills a git repository or folder added since
refeccd (Discord): skills added from a repository or a folder only had
the existing ones updated; ones the source added later never reached
the library. GitHub sources already had this (findNew); git repositories
on other hosts and folders on this machine did not, and a folder install
didn't even remember the folder it came from.

- git: when ls-remote gives the ref a head, findNewGit reads the fetch
  the check shares and offers skills under newBase that the library
  doesn't have and hasn't offered. Once per head while its finds are
  kept (gitLooked). The address is kept as the library has it (.git and
  all), so an Add lands on the same repo@ref key.
- folder: an install from a folder now records "folder:<path>" in
  SeenSkills (offered), which is how the library knows where to look
  again. findNewFolder reads it as Add from folder does and skips a
  folder the library links, has offered, or has a skill by that name of.
- A check never adds or writes a skill: each is offered with Add and
  Ignore, as GitHub's are. A skill the user removed or set aside isn't
  offered again, and a folder edit is never written over.
- View.CheckFolders shows Check for updates with only linked skills and
  makes checkDue true; its title says it looks in folders too. A find's
  row shows its folder (pathLink) or git address. The old head note
  ("on GitHub beside skills you have…") is gone; the new title is in all
  five languages.
- docs/subsystems/library.md says so.

Old data: a folder added before this kept no folder: key, so it is
looked in only after the user adds from that folder once more (the
picker then lists the new skills, and the install records the folder).

Run (mote, at fcc0daa23 plus this change):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...; go build ./... and the CGO_ENABLED=0
  nogui build: ok.
- go test ./internal/library: ok. go test ./internal/gui: ok except
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322) and
  TestMainWindowCorners (#3949), both red the same on origin/main
  19c45d5d4 run alone.
- GUI, both engines: every library-*, skill-*, github-token,
  plugin-check-*, plugin-git, i18n-keys, i18n-en-no-cjk, gui-de,
  gui-ja, gui-zh-tw file: 1526 of 1529. Reds: i18n-keys "a plugin's
  words are its own" (#5332, #5426, #5482, red on origin/main) and
  skill-where "the switch scrolls nothing", flaky on origin/main
  19c45d5d4 too (1, 0 and 2 reds in three runs; noted on #5154).
  skill-new-in-repo's new folder case runs en and zh at 860 and 440px.

At the pushed head (rebased on origin/main 94d4866b5), again on mote:
go vet of internal/library and internal/gui, go test ./internal/library
ok, internal/gui's Budget/Size tests ok, skill-new-in-repo 4 of 4 and
i18n-keys with only the known red above.

Broken by hand: with the git branch of CheckSkills and lookInFolders
off, TestCheckSkillsFindsNewInGitRepo and TestCheckSkillsFindsNewInFolder
fail ("new: []"); with offered() not recording the picker's shown
skills, both fail offering what the picker showed ([review], [xlsx]).

Not tried: a real GitLab or intranet repository (the test uses a local
file:// bare repo with the real git); the CLI and TUI, which don't list
new skills; the Windows and Linux boxes.

Reported-by: refeccd (Discord)
2026-11-06 19:50:40 +08:00
yetone 7d196b6797 gateway: what a proxy says of the caller reaches no vendor, ChatGPT backend or MCP server
Behind Tailscale Serve, a Cloudflare Tunnel or another reverse proxy,
the request magpie gets carries what the proxy says of the caller:
Tailscale-User-Login, -Name and -Profile-Pic (the user's email, name
and picture), True-Client-IP, X-Forwarded-*, Cf-*. The native route
dropped X-Forwarded-*, Forwarded, Cf-*, X-Real-Ip and Via, but not
True-Client-IP or any Tailscale-*, even though lanGuard itself reads
True-Client-IP and Tailscale-User-Login as forwarded
(forwardHeaders). The Codex passthrough and relay to the ChatGPT
backend (copyHeaders) and the MCP proxy dropped none of them.

proxyIdentity names them once: every forwardHeaders entry; any
X-Forwarded-*, Cf-* and Tailscale-*; Forwarded, Via, X-Real-Ip,
True-Client-Ip, X-Client-Ip and X-Original-Forwarded-For.
nativeHeaderDropped, copyHeaders and the MCP proxy's header loop all
skip them. The caller's other headers still go on. Checked and left
as they are: a provider's PassHeaders (names the user chose), Codex's
allow-listed codexHeader, the Codex websocket's headers and passOnCaller.

Tests: TestNativeAnyDropsProxyIdentity (native route, under
MAGPIE_TRUST_PROXY) and TestPassthroughDropsProxyIdentity (Codex relay
through copyHeaders, and /mcp/<server>). Each sends twelve identity
headers and checks that none arrive and that X-Custom still does.

Broken by hand: with native.go, codex_backend.go and mcp.go at their
parent, both tests are red. The native vendor was told True-Client-IP
and the three Tailscale-User-* headers. The ChatGPT backend and the
MCP server were told all twelve.

Run on mote at the pushed head 883690a0b (this commit and the one before,
on origin/main 9a0aab32c): gofmt -l clean, go vet, GOOS=windows go vet
and GOOS=linux -tags nogui go vet all clean. go test ./... -timeout 45m
-count=1: 84 packages ok, including internal/gateway. 3 red, each filed
and none in this change's path:
- TestMainWindowCorners/macOS_26_SDK (gui, macOS 27, #3949)
- TestRenewLoginsKeepsClaudeReading (provider, #5481). It is red 3 of 3
  at the base 49c9491b7 without either commit.
- TestHostEndedEndsWhatItsPluginStarted/own_end (plugin, a 30s wait in
  a full run; passes 3 of 3 alone at this head, #5515)
Rebased then onto origin/main 303a31dd6 (which fixed #5481) and run
again at that tree: gofmt and the three vets clean, and internal/gateway,
internal/provider, internal/plugin and internal/netproxy all ok.
Rebased on 19c45d5d4, which changes gateway.go (kept_error), Codex's
usage_limit_reached, Cursor's mover min, sessions and the GUI; ran
gofmt, go vet ./internal/..., GOOS=windows go vet of gateway and
provider, and go test ./internal/gateway ./internal/provider: both ok.
Rebased on 94d4866b5, which changes only internal/sessions; ran gofmt,
go vet of gateway, provider and sessions, and this change's own tests
(-run Redirect|DropsProxyIdentity|SameOrigin|Keyed): ok.
Rebased on cd77c725d, which changes only internal/provider's check-in;
ran gofmt, go vet of gateway and provider, and this change's own
tests again: ok.
Not tried: a real Tailscale Serve or Cloudflare Tunnel in front of
magpie.
2026-11-06 19:50:19 +08:00
yetone c57a5f7f58 gateway: a vendor's redirect to another origin is sent no provider key
Go's http.Client follows up to 10 redirects to any host, https to http
included, and on a hop to another domain drops only Authorization,
Cookie and WWW-Authenticate. So a vendor (or anything answering at its
URL) that redirected elsewhere got x-api-key, x-goog-api-key, api-key
and a provider's own headers sent there; Authorization too when only
the port differed, and all of them in the clear on an https to http
hop on the same host.

The class is fixed where the requests leave:
- provider.KeepsCredentials is a CheckRedirect that follows a redirect
  only to the request's own origin (scheme, host, port; or http to
  https on the same host and default ports), at most 10, and gives any
  other 3xx back as the answer (http.ErrUseLastResponse).
- provider.Keyed(c) is a copy of c with c's own CheckRedirect, then
  KeepsCredentials. Provider.do, the choke point of every p.Do, sends
  through it, and every http.DefaultClient.Do in internal/provider that
  carries a credential is Keyed(http.DefaultClient).Do. A copy per
  call, since netproxy.Install sets the default client's transport at
  run time. Left alone: Grok's public download, Antigravity's version
  URL and cline.go's unsigned read.
- the gateway's client (s.client, every vendor call), the Codex relay's
  and the Codex websocket's take KeepsCredentials, and so does
  chatgpt_api's siwcClient.

The native route needs nothing more: the vendor's 3xx comes back to
the caller as it came, Location included, and the caller decides.
Translated routes don't follow either, rather than following with
credentials stripped: it is the rule search_api.go had already (#1580),
no vendor magpie speaks to was found redirecting its API to another
origin, a stripped request elsewhere would only fail with a confusing
401, and the vendor-URL downloads (video, images) are fetched unsigned
through vendorClient, so they are not affected.

Tests: TestRedirectKeepsTheKeyAtItsOrigin (307 and 302 elsewhere with
Authorization, x-api-key, x-goog-api-key, api-key and a custom header;
a same-origin redirect followed with every key; three clients),
TestRedirectNeverDowngrades (an https vendor's redirect to http on its
own host and port), TestSameOrigin, TestKeyedKeepsTheClientsRule,
TestNativeRedirectKeepsTheKey (Anthropic and Gemini providers with an
own header) and TestChatRedirectKeepsTheKey.

Broken by hand: with Provider.do back on client.Do and s.client
without CheckRedirect, the thief got every key header, /away answered
200, the https vendor's /plain was followed (400 from the TLS port
spoken to in http), the native route's claudeish and gem answered the
thief's {"stolen":true} with Authorization, X-Api-Key and
X-Relay-Secret sent there, and the chat route sent Api-Key,
Authorization and X-Relay-Secret to it. TestSameOrigin and
TestKeyedKeepsTheClientsRule don't depend on the wiring and passed.

Run on mote at the pushed head 883690a0b (this commit and the next,
on origin/main 9a0aab32c): gofmt -l clean, go vet, GOOS=windows go vet
and GOOS=linux -tags nogui go vet all clean. go test ./... -timeout 45m
-count=1: 84 packages ok, including internal/gateway. 3 red, each filed
and none in this change's path:
- TestMainWindowCorners/macOS_26_SDK (gui, macOS 27, #3949)
- TestRenewLoginsKeepsClaudeReading (provider, #5481). It is red 3 of 3
  at the base 49c9491b7 without either commit.
- TestHostEndedEndsWhatItsPluginStarted/own_end (plugin, a 30s wait in
  a full run; passes 3 of 3 alone at this head, #5515)
This commit alone, at its first base 49c9491b7, ran the same way with
TestUnroutedHeldReportSaved (gateway, #4300) red besides.
Rebased then onto origin/main 303a31dd6 (which fixed #5481) and run
again at that tree: gofmt and the three vets clean, and internal/gateway,
internal/provider, internal/plugin and internal/netproxy all ok.
Rebased on 19c45d5d4, which changes gateway.go (kept_error), Codex's
usage_limit_reached, Cursor's mover min, sessions and the GUI; ran
gofmt, go vet ./internal/..., GOOS=windows go vet of gateway and
provider, and go test ./internal/gateway ./internal/provider: both ok.
Rebased on 94d4866b5, which changes only internal/sessions; ran gofmt,
go vet of gateway, provider and sessions, and this change's own tests
(-run Redirect|DropsProxyIdentity|SameOrigin|Keyed): ok.
Rebased on cd77c725d, which changes only internal/provider's check-in;
ran gofmt, go vet of gateway and provider, and this change's own
tests again: ok.
Not tried: a real vendor's redirect (none found that does), and the
plugin host's fetch (host.js; Bun follows redirects by default), which
is filed as #5508.
2026-11-06 19:50:18 +08:00
yetone cd77c725d2 check-in: a plugin's failed with a later until waits for it (plugins#503, plugins#793)
A plugin's check-in can answer failed with an until hours away: ZCode
rate limits a claim read, and its plugin (plugins#793) says when to ask
again. magpie asked any failed again after 30 minutes whatever the until
said, the half hour that kept the limit on (#503: "gift plans to claim:
Too Many Requests" 180 times over four days). A review probe on
origin/main 19c45d5d4 saw a failed with until 6h out asked at 31 minutes
and at 2 hours.

Now heldUntil holds a failed whose until is later than its own retry
until that time, at most 24 hours after the failure (checkinHoldMax), so
a wrong far-off until can't stop check-ins for good. Every path that
schedules a check-in follows it:
- settled: the loop doesn't ask before it, across the Beijing day's turn
  too; a press (soon) still asks at once.
- the recheck branch (ZCode, Qoder) counts a held failure as waiting,
  where it was otherwise asked again every 30 minutes.
- the loop's wake time (wbCheckinLoop.again) is the until, not 30
  minutes on.
A failed with no until keeps the 30-minute retry (offline failures their
minute ladder), and one with an until sooner than the retry is asked at
the until, as before. The GUI and TUI show no time for the next ask
("magpie tries again later"), so nothing there changed.
docs/subsystems/provider-plugins.md says it.

Run (mote, through mote-run):
- go test -count=1 -timeout 30m ./internal/provider/ ./internal/tui/
  ./internal/cli/: ok (193.7s, 17.1s, 76.6s).
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  ./internal/provider/: ok. gofmt -l: nothing.
- The full suite runs after the push, through the suite lock.

Broken by hand (new tests TestPluginCheckinFailedWaitsForUntil,
TestPluginCheckinFailedUntilBounded):
- the old settled/checkin.go/tick: red, "loop at +31m0s: asked again
  (2 asks), until ..." for zcode and a plain plugin, and the far until
  case asked at +31m.
- the recheck branch without the held failure: zcode red at +31m.
- the old wake time: "the loop wakes at 14:30, want the until 20:00".
- no 24h cap: "at +24h0m0s: not asked again".
Restored: ok.

Not tried: a real ZCode account rate limited with until; the plugin's
own backoff (plugins#793) still holds off for older magpie.

Reported-by: kongbai01203 (plugins#503)
2026-11-06 19:48:21 +08:00
yetone 19c45d5d4e gateway: a vendor's error on the client's own API keeps its status, type, code and fields
ne9ko9 on Discord: an error from a vendor that speaks the client's own
API was rebuilt from its status. writeVendorError (via writeErrorSaid)
set the type from the status, kept only a string code and param, and
dropped every field magpie doesn't know (a numeric code, request_id,
extra). That happened in the native relay's error branch (gateway.go),
passthrough, translate's and streamTranslated's.

Now writeVendorErrorFrom checks the upstream's error shape. When it is
the client's own (Chat/Responses to Chat/Responses, Anthropic to
Anthropic, Gemini to Gemini) and the body is a JSON error object with a
string message, the vendor's status, Content-Type and bytes go to the
client, except error.message. Only the message is magpie's: the
provider's name before the vendor's words, as before. A describer
asking for another model, the Claude sign-in's rewording
(claude_signin.go) and the agent read which provider said it there, so
taking the name out broke them. The message also carries a note where
magpie has one (an account's Explain, a region, the wrong endpoint), a
busy relay said so (saysBusy) and a 413's byte-limit hint. A prompt too
long for the model (tooLong) is said as the client's API says it: status
400 and type/code, or Gemini's code/status, so the agent compacts.
setErrorField splices each change in place, so every other byte is the
vendor's. A non-JSON body, or one from another API, is rebuilt as
before. For the vendor's message untouched too, the next commit's
errors=pass sends the body byte-for-byte.

Tests (internal/gateway/kept_error_test.go):
- TestSameAPIErrorKeptAsSent: literal bodies with numeric codes
  (1214, 20031) and extra fields (extra, details, request_id, param) on
  Chat, Anthropic (403) and Responses. Exact bytes and status.
- TestSameAPIOverflowKeepsTheRest: a Zhipu-like 1261 overflow keeps
  extra and request_id, with code context_length_exceeded.
- TestOtherAPIErrorRebuilt: an Anthropic client to a Chat vendor.
- TestSetErrorField.

Run:
- Broken by hand: the new gateway tests copied onto origin/main
  c6b7bbedf (worktree errpass-old) went red on the old code: code null,
  type taken from the status, extra/details/request_id lost.
- At this commit, through mote-run: go test -count=1 -timeout 45m
  ./internal/gateway ./internal/provider ./internal/cli: ok (gateway 940s,
  provider 193s, cli 104s), at base fcc0daa23. Rebased on 559bf71e9
  (Codex's usage_limit_reached reply in passthrough's error branch,
  kept before this one): go vet ./internal/gateway and the error tests
  above plus CodexOut/ClaudeSignIn/NotAnAPIReply/VerifyRefusal/
  NoDescriber/ChatRelayRefusal again at this commit: ok.
- gofmt -l clean. go vet, GOOS=linux -tags nogui and GOOS=windows go
  vet of ./...: ok.
- Full suite: after the push, at the head with the next commit, under
  the suite lock.

Not tried: a real vendor's error through a live agent; Gemini's
same-shape path has no test of its own.

Reported-by: ne9ko9 (Discord)
2026-11-06 19:28:54 +08:00
yetone 251cce2059 usage: a click on All N accounts folds that provider's accounts under it (justfreefall on X)
justfreefall on X (CODEX (2), "既然已经有汇总信息了,能不能出个按钮把下面两个折叠?"):
the All N accounts strip already sums the accounts, so its accounts can go.
The strip gets the per-account card's own chevron (quota-acct-fold, aria-expanded,
Fold/Unfold title, no new strings). A click on the strip or the chevron, or
Enter/Space on the chevron, folds that provider's account cards in the Usage
page and in the tray panel's Allowances; again unfolds. Default open. Kept per
provider in localStorage magpie.usageAllFolded beside the other view choices,
and a storage event redraws the other window. The head's "Show ..." button
stays in its room, hidden and inert, so the strip does not move under the
pointer. A menu-bar cell that asks for one folded account unfolds them first
(focusQuotaCard). quotaall.js reads the choice on first use, so loading it
touches no app.js global (usage-merge runs it in a bare vm).

Core script budget: not raised. app.js +35 bytes, met by shortening comments.

Run (mote, macOS 27, unless said):
- go test -tags nogui ./internal/gui/: ok at the rebased head (130s); Budget
  tests again after the last edit: ok. gofmt -l: clean.
- usage-all-fold.test.cjs (new): 10/10, chromium + webkit x en zh zh-TW ja de,
  window 440x520 and panel 360x760. Broken by hand: with main's assets it is
  red (no .quota-all-fold).
- usage-merge, usage-all-fold, tray-cell-click, quota-caption-contrast, old-webkit
  after the last edit: all ok except tray-cell-click 4/4, red the same at
  origin/main fcc0daa23 (#5215).
- Usage/quota files alone, base fcc0daa23 vs this: usage-fold ("several accounts",
  "17 subscriptions"), usage-agents-hide, usage-compact-counts, usage-ledger
  Requests red the same on both (32 each); usage-merge was red only here
  (kept is not defined) and is fixed above.
- i18n-keys "a plugin's words are its own": red the same on base (#5332).
- account-eye webkit "Usage card's eye" on WSL: base 9/10 red, this 5/10 (#5052, #4244).
- click-scroll webkit "a wheel the page hears of after its scroll": red on base too (WSL).
- Whole GUI suite on WSL (concurrency 8) before the usage-merge fix: ~40 reds
  outside usage (Connect, Copilot GHE, gateway keys, groups, skills, routing
  headers, plugins), the class #5475 records on main; each usage/quota/panel
  red was rerun against base above.
Not run: go test ./..., cross-OS vet (assets and one .cjs only); the real app.
2026-11-06 19:27:42 +08:00
yetone 37c1bc043b agent: a group whose members all serve Responses, one best there, is asked on Responses
zyh6036 on X: several subscriptions that all serve the Responses API were
asked on Chat once they were put in a routing group. Pi, OmO, omp, StepCode,
droid, dsh, Hermes, Grok CLI and the live agents ask each model on the one
API catalog.Model.APIs names, and a group had Responses only when every
member's Native was Responses (allResponses, #1594). A relay that serves
Chat and Responses, best on Chat (no Base URL API given, not OpenAI's own
host), counts as Chat there, so one such member put the whole group on
Chat, and the gateway then translated Chat to Responses for the ChatGPT,
Copilot GPT or Responses-relay members. Found groups (auto-<slug>) hit this
without the user doing anything: a new relay that also lists gpt-5.5 moved
auto/gpt-5.5 from openai-responses to Chat (pi_api_test shows it).

provider.GroupAPI now gives Responses when one member is best on Responses
and every other takes a Responses request as it is (Responses among the
APIs it relays), or translates every request anyway (a Claude Code
subscription). So no member is translated that Chat would have relayed,
and the ones best on Responses are relayed, not translated from Chat. The
gateway already relays a /v1/responses request to each member that serves
it (usable), so nothing changes there.

Mixed groups: a member that Responses doesn't reach (a Chat-only key, a
Messages-only Claude) keeps the group on Chat, where that member is
relayed; picking Responses there would translate it on every turn. A
Messages-only group stays on Chat as before (#1594's reason: a Claude
member's thinking is known by its own model id, not the group's).

An agent plugin's connect is told a group's native_endpoints now
(provider.GroupEndpoints: the APIs every member relays), where it had
none. /v1/models still leaves them out for a group:
TestRemoteMagpieNativeAPI holds that a remote magpie sends a group's
request on in the client's API for the other side to pick per member.

No setting added: the group's API follows from its members.

Run (mote, through mote-run):
- go test ./... -timeout 45m at 65780f04f on 49c9491b7, under the shared
  lock: every package ok except three reds, all filed and not in this
  change's path: internal/gateway TestBurstTellsNoSpeed/
  responses_from_chat_burst (passes 3 of 3 alone; #2719, commented),
  internal/gui TestMainWindowCorners/macOS_26_SDK (#3949), internal/provider
  TestRenewLoginsKeepsClaudeReading (red alone too; #5481, on main).
- After rebasing on fcc0daa23: go test ./internal/agent ./internal/catalog,
  ./internal/provider -run 'TestGroupAPI|TestNative|Group',
  ./internal/gateway -run 'Group|RemoteMagpie'; go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...; gofmt -l
  empty.
- Broken by hand: GroupAPI put back to "every member best on Responses":
  TestGroupAPI red (one best there plus one serving it too; the same
  second), TestPiModelsAskedOnTheirNativeAPI red (group/subs, and
  auto/gpt-5.5 once a Chat-first relay serves gpt-5.5).
- New: TestGroupAPI (provider), TestGroupOfResponsesServersRelaysOnResponses
  (gateway: the Chat-first member is asked on /responses, relayed).

Not tried: the reporter's own providers (not known: which subscriptions,
which agent); a real Pi or dsh run against a real mixed-API group; the GUI
(unchanged).
2026-11-06 19:07:15 +08:00
yetone 64b563cee8 gateway: the MCP router keeps Magpie Browser, the image server and other routers to this computer
A gateway key from another computer (LAN, tunnel, or a proxy here) or a
web page could reach, through /mcp/magpie/hub, servers that act as this
computer's user:

- Magpie Browser, which /mcp/magpie/browser itself refuses to such a
  caller, so a LAN key could drive the user's signed-in browser;
- magpie's image server, which draws with this magpie's own token, past
  the key's model, account and spend holds;
- another magpie's router, which passes calls on to its own browser.

These are now HereOnly (keepsSession or isSelf in the library) and are
neither listed nor run for an away caller. The check sits both in the
gateway (hubServersOf, hubTools) and in the library (visitorServers,
Call), so a call by name is refused too. A held key (nativeHeld) from
another computer also no longer gets programs run here (stdio commands,
plugins), only HTTP servers elsewhere. Local callers are unchanged. The
mcp-router subsystem page says both rules.

Run on mote (macOS 27) at this tree, base 49c9491b7:
- gofmt -l internal: clean
- go vet: darwin; GOOS=windows; GOOS=linux -tags nogui (gateway, library)
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ./internal/library ./internal/gui ./internal/provider: gateway, library
  and gui ok. In provider, TestRenewLoginsKeepsClaudeReading fails
  (#5481, a fixed-date fixture, red on main and taken by another
  session).

Rebased on fe61503e6 (gateway.go, remote_moved_test.go changed):
gofmt, go vet, and go test -run 'Hub|RemoteMoved|Moved' in gateway and
library ok at the pushed tree.

Broken by hand: making Gives always true turns both
TestHubKeepsThisComputersOwnServersHere tests red (the browser and image
are listed and run for 192.0.2.7). Taking the library's Call check out
leaves the library test red on a call by name.

Not tried: a real LAN client against a live magpie. Windows and Linux
were vetted, not tested.
2026-11-06 18:36:04 +08:00