Commit Graph
1500 Commits
Author SHA1 Message Date
yetone 9162277b91 routing: Until used up stays on the next account once the first is used up (dzxx0496)
dzxx0496 on Discord: with free accounts one after another, the first used
up, requests went to the second; when the first renewed they went back to
it ("如果第一个恢复了,它又优先用第一个了"). No routing did what they asked:
In order and Smart both put the first back first.

A new routing, Until used up (drain, 用完再换): requests stay on one seat
until its quota is used up, then go on to the next in the list and stay
there. A seat counts as used up when its known allowance is at 100% or
it was refused for quota or credit (failQuota / failCredit, routes.Drained
called where the rest is recorded, so a failover inside one request moves
the pool too). A rate limit or other failure only passes it over while
it rests, as In order does. Each pool (a provider, a group/<id>) keeps its
own place; routes.Forget clears it.

Offered wherever a routing is picked: the provider editor, a group's row
menu and editor (app menu, no native select), the TUI, `magpie group set
<id> routing=drain` and a provider's routing=drain. Nothing defaults to
it, so no saved setting changes. SpentShareOf is 100 for it, as for In
order. Words in en, zh, zh-TW, ja and de (i18n.js and the routing
plugin's own), docs/subsystems and the site's start page (en, zh, ja).

Tests:
- internal/routes/drain_test.go: stays on the next when the first renews,
  through a rate limit, all used up, a seat gone, per pool, Forget,
  Drained after a renewal.
- internal/gateway/drain_test.go: a real request path with a fake upstream;
  k1 refused for quota, k2 takes over, k1 renews: drain stays on k2,
  In order goes back to k1. Red without the Drained hook (request 3 went
  to k1). A rate limit comes back to k1; drain is saved on a provider and
  a group.
- routing-drain.test.cjs: the Routing page's why and mode line in 5
  languages, 1100px and 420px, Chromium and WebKit; red on the old assets
  (20 of 20).
- routing-group-strategy, routing-save, builtins: the menu has 11 routings.

Run on mote (macOS) at origin/main 699ddf152 with this commit and its
two neighbours (nb5p chip, dzxx0496 renewal, dzxx0496 Until used up).
Pushed on b2145eac1, whose five commits since change app.css and app.js
only for a key row's chips; at the pushed tree gofmt, the gui, routes
and gateway vets (Linux nogui, Windows), TestCoreScriptBudget (core
1,532,891), the Drain Go tests and 11 GUI files (gateway-model-chip-
height, routing-drain, routing-renews-stay, routing-behind-why,
routing-group-strategy, routing-save, builtins, i18n-keys, gui-de,
gui-zh-tw, key-row-chips-fit) were run again: 190 of 190 ok.
- gofmt -l clean; GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./... and go vet ok.
- go test internal/routes, internal/gateway, internal/provider,
  internal/cli, internal/tui, plugins/rotation: ok; internal/gui's
  TestCoreScriptBudget ok (core 1,532,816 of 1,533,105).
- GUI: routing-*, builtins, gateway-model*, model-chip*, i18n-keys,
  gui-* and codex-credits-last in both engines: 2211 tests, 68 red,
  none new: model-chip-steady 20 (#4388), gui-ja's {agent} string
  (#4580), and 11 routing-* files under load (#4585, #3789, #3799).
  The same 11 files run alone at cdfdb62c6 were 32 of 116 red, and 26
  with the stack, the same tests but rule-remove, whose red languages
  vary run to run (9 cases, then 5). model-chip-steady was 20 of 20 red
  at cdfdb62c6 alone.
Earlier, at f811bf291 with the stack: go test -timeout 45m ./... had 82
packages ok, internal/gui red only on
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners/macOS_26_SDK (#3949). The whole GUI suite had 301
of 16930 red in 52 files. Those 52 files rerun had 272 red with the
stack and 276 at f811bf291 alone, the same tests.
2026-11-01 09:53:50 +08:00
yetone 699ddf1524 gateway: a Codex account can spend its credits only after every other account, key and fallback (gokoshiki on Discord)
gokoshiki wants a Codex subscription first, then an OpenAI API key, then
the subscription's credits. Until now an account at 100% that holds
credits either kept its place and spent them there (on) or was held
(off). This adds a third way per account, "last":

- settings: CodexCreditsLast []string, empty by default, so a setting
  saved before it keeps its order. provider.CodexCreditsLast,
  CodexCreditsMode and SetCodexCreditsMode(user, on|last|off);
  SetCodexCredits(on) still means "in its place" and clears last.
- gateway: candidate.creditsLast is true for such an account once a
  window for the model is used up and it is going on its credits (a
  call ChatGPT counts in no window stays in its place). restLast orders
  ready, then resting, then those, and marks Weighed.CreditsLast.
  restLast runs over the asides too, so such an account goes behind a
  provider's reserves (Accounts at once, 2c6b7c063) as well.
  lastBehind keeps In turn's next turn (after), a new conversation's
  spread (leastHeld) and a subagent's lead (readyForNew) from bringing
  it forward, and a kept conversation moves off it to one not on its
  credits (Affinity.Why "credits").
- CLI: magpie quota credits <account> [on|last|off]; alone it lists
  accounts set off and last.
- API: POST /api/settings/codex-credits takes {user, on, last?}.
- GUI: under a Codex account's Use credits, while on, a second switch
  "Only after every other account, key and fallback", in the Usage
  page's card and the tray panel's (both wrap it to its own line at 360
  to 900px), and the panel's folded brief says "On, after everything
  else". The Routing page's trace says why such an account is behind
  (aside, the kept conversation's why, the row tag). zh, zh-TW, ja, de.
  creditsButton and the new switch share creditsSwitch, and the Codex
  options' comments in app.js were cut, so the core budget holds with
  no raise (1,532,664 of 1,533,105).
- docs: reference.md (quota credits) and gateway-routing.md.

Tests:
- gateway: TestCodexCreditsLastAfterTheOthers (two accounts, In order:
  the one at 100% on its credits goes behind, the trace says so, and
  back in place when turned on), TestCodexCreditsLastAfterTheFallback
  (both accounts at 100% and set last: the API key the provider falls
  back to answers before either one's credits; with the credits in
  their place an account answers on them, as before),
  TestCodexCreditsLastNotKept (a kept conversation moves off it).
  All three red with creditsLast and lastBehind forced false.
- provider: TestCodexCreditsLastMode.
- gui: settings_keep_test carries CodexCreditsLast;
  tests/codex-credits-last.test.cjs (Chromium and WebKit, en zh zh-TW
  ja de; Usage at 900 and 440, the panel at 440 and 360, the folded
  brief, the Routing page's aside and why, every key in I18N). Red on
  the old assets (no .ar-credits-last).

Run at this change on origin/main c76bcaea7, on mote (pushed on fd70def82, whose
one commit since, fd70def82, changes only the Providers poll's Go
files in internal/gui):
gofmt clean; go vet of gateway, provider, gui, cli and settings ok;
their tests ok but internal/gui's #4514 and #3949, both on main. The
8 commits between d6aa9cdf6 and c76bcaea7 touch none of this
change's files.

Run at this change on origin/main d6aa9cdf6, Go 1.26.8:
- mote: gofmt -l clean; go vet ./..., and GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: ok. go test -count=1 -timeout 45m ./...:
  85 packages ok; internal/gui red only on TestSettingsSaveKeepsWhatIt
  DoesNotSend's SearchAll (#4514), TestMainWindowCorners (#3949) and
  TestColdTurnsTaken (#4510), all three on main. TestCoreScriptBudget
  passes.
- WSL magpie-desktop, Playwright 1.62.0, both engines: codex-credits*,
  i18n-keys, gui-ja, gui-zh-tw, panel-options-fold, provider-at-once and
  every routing-* file: 2127 tests, 2064 pass. Every codex-credits and
  codex-credits-last test passed (26). The red files (gui-ja, 19 routing
  files) run again at this tree and at d6aa9cdf6, alike: 200 tests, 61
  and 57 red. gui-ja is #4580; the routing reds are timeouts and
  waits, on both. The one file red at this tree only,
  routing-request-model (WebKit 420px "the model is cut"), is 5 of 5
  green alone at both, and with six copies at once red at both (29 and
  27 of 30 here, 28 and 27 of 30 at d6aa9cdf6): a fixed 150ms wait
  after a resize, filed as #4650. Nothing this change adds to Routing
  draws unless an account is set last (fixtures don't).
- Earlier, at 3564eb04b (this change on 7428f3229), WSL: the whole GUI
  suite beside two other sessions' suites, 16944 tests, 16496 pass;
  its 102 red files again at that head and at 7428f3229, 444 and 425
  red. The files red at the head only, run alone: view-open-wheel,
  usage-accounts, add-button, usage-ledger-open-settled 0 red;
  view-wheel-after-click, view-wheel-unheard and context-map (#3488)
  red alone at 7428f3229 too. mote, the credits and i18n files: 172 of
  174, the two #4580 and a click timeout in quota-curve at load 148
  (alone 30 of 30).

Not tried: a real ChatGPT account at 100% with credits beside a real
OpenAI key; the order is shown with the gateway's fake Codex backend.
2026-11-01 09:08:07 +08:00
yetone 2c6b7c0632 gateway, provider, gui: Accounts at once keeps the first N accounts taking requests, the others in reserve
01huadalang on Discord (#feedback 1566170404542742740): three ZCode
accounts used at once from one address got the address refused with a
405; two were served. They asked for one account to be used until it
runs out, then the next. Even under "In order", ZCode's maxConcurrency 3
spilled a full lane onto the next account (laneMate) and rests spread
the load, so every account was in use at once.

A provider's MaxAccounts (the editor's Advanced → "Accounts at once",
beside Concurrency; `magpie provider at-once <id> [n|off|default]`) is
how many of its accounts or keys take requests at the same time.
provider.AtOnce() is the user's own value, else what its plugin
declares (maxAccounts on the auth hook or package.json magpie, read by
host.js atOnceOf), else no limit; the user's 0 is no limit over the
plugin's. perKeyBarred keeps the first N in the user's own order
(rank), preferring ones not resting, and keepAtOnce puts the rest after
everything as asides with candidate.reserve (Weighed.Reserve). So in any
routing mode a reserve is asked only once the kept ones failed or rest,
and a kept one that rests gives its seat to the first reserve next time.
Guards: laneMate never spills onto a reserve; a full queue (laneErr)
drops the provider's reserves (dropReserves) and turns the request away
with the 429; session affinity moves a conversation off a reserve once
the kept ones can take it (affine "reserve"; Strict still holds).
Routing says "in reserve · {n} at once" on the row and why in the
request's story. zcode 0.1.40 (plugins 26864ec, on npm) declares 2, and
its mover min is raised to 0.1.40 two commits on.

Known leak, in docs/subsystems/gateway-routing.md: a failure that rests
nobody (a 5xx on one try) still passes that one request to the reserve,
as it does to any next candidate.

Tests: TestAtOnceKeepsFirstInUserOrder (every routing mode, a dragged
order, a resting key handing over its seat), TestAtOnceFullLaneWaitsForTheKept,
TestAtOnceReserveTakesOverAndGivesBack, provider TestAtOnce, plugin
host maxAccounts (hook and package.json), gui TestAtOnceSave, cli
TestAtOnceCmd, provider-at-once.test.cjs (both engines, five languages,
900 and 360px).

Broken by hand, each red then restored: laneMate's reserve guard
removed (FullLane times out); affine's reserve case removed
(ReserveTakesOver answers on k3); keepAtOnce disabled (all three red);
dropReserves disabled (FullLane gets no reply); the Routing row's
reserve branch removed (provider-at-once's Routing test red in all 10
engine/language runs).

Core budget: the field adds ~530 bytes to app.js; the neighbouring
editor comments are cut to fit, so TestCoreScriptBudget passes with no
raise.

Run on mote, Go 1.26.8:
- full suite, -timeout 45m, at a7d4c662d (on origin/main e4384fc3c):
  gofmt and vet clean; every package ok but internal/gui, whose reds are
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
  (#3949) and TestColdTurnsTaken (#4510), each red on that main too, and
  TestCoreScriptBudget, fixed by the comment cut above.
- at this tree on bbdd9eb55 (the pushed head less 51f2f22ce and
  73b957069, gateway and provider): gofmt, go vet (darwin, and
  linux and windows with -tags nogui), and internal/gateway, provider,
  gui, cli, plugin and settings: all ok but internal/gui's
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
  (#3949), both red on main; TestCoreScriptBudget passes
- at the pushed head (on 51f2f22ce): go vet of gateway and provider,
  and -run AtOnce|Nameless|ModelAPI|Reserve|FullLane over gateway,
  provider, gui and cli: ok
GUI, Playwright 1.62.0, both engines:
- the whole suite on Linux (WSL) at an earlier head; every red file run
  again at head and at main on mote, the same reds on both (filed:
  #4641 is new, the rest open already, e.g. #4600, #4461, #4082, #4210).
- at a7d4c662d on WSL: every editor-*, provider-* file, i18n-keys,
  gui-ja and seven routing files, 1185 pass, 34 red; all but four red
  on main e4384fc3c too (#4580, #3292, #4394 to #4397, #4600). The four:
  routing-many-keys (#4082) is red on main in two of three reruns as
  well; provider-gemini webkit ja's thumb (#4210) was red in 2 of 3 runs at head beside
  other files (318px off), 0 of 3 at main; alone, 4 of 4 green at both.
  The test reads the thumb 350ms after a click, a fixed wait (#4210,
  numbers added there).
- provider-at-once.test.cjs: green in both engines, five languages, at
  900 and 360px; editor-advanced-align 20 of 20 alone with the next
  commit.

Not tried: real ZCode accounts (none used, per the task) and a real 405,
so whether two at once always stays under ZCode's limit is the
reporter's finding; the user can set 1.
2026-11-01 07:39:08 +08:00
ggbdpq 5032d3ade7 gateway: a reasoning item magpie hands Codex with its text in it becomes one of its own, a summary and nothing sealed (#2855)
What changed

A Responses reasoning item that carries the model's reasoning as content
parts (reasoning_text) — another vendor's shape; OpenAI's own items carry
summaries — no longer reaches a client of magpie's as the upstream wrote
it. It is made over into the item magpie makes of any other upstream's
reasoning: its text (and its summaries) as one summary, an rs_ id, no
content and no seal — in a reply translated for the client
(magpieMadeReasoningRaw at the encoder's sealed item and the whole reply's
renderer) and in one relayed as it came (reasoningTidy, a passthrough
filter on Responses streams and whole replies, the item in
output_item.added/done and in response.completed's output). The
subsystems doc's rule is amended to say so.

Why

A Codex conversation that used OpenAI, went through magpie to DeepSeek,
then had magpie disconnected again, was stuck: every later turn, the
remote compact too, answered 400 "Invalid 'input[43].content': array too
long. Expected an array with maximum length 0, but got an array with
length 1 instead." The reporter's rollout forensics narrow it: the
DeepSeek phase had left 25 reasoning items, each with its text in content
parts and a 38-character encrypted_content of the vendor's own (not the
gAAAA the thread's own GPT-phase items carry, which have no content),
which Codex stores and replays to OpenAI. OpenAI takes a reasoning item
sent back only with its content empty (#1411) and cannot open another
vendor's seal, so such an item poisons the thread for OpenAI wherever it
was planted — and once Codex holds it, no retry of magpie's can strip it:
client keeps, and #2855 came with magpie out of the path entirely. A
Chat-API upstream's turn has always translated to an item of magpie's own
(an rs_ id and a summary, TestTranslatedChatReasoningCarriesNoContent
pins it); the items the reporter held are a Responses wire's own, which
both the translated and the relayed reply handed over as they came. What
magpie hands a client must be re-sendable to a strict Responses upstream:
the text is kept in the summary, so an upstream that wants its reasoning
back still gets it (withReasoningText), and magpie's own OpenAI
destinations keep the item out as they did (#1008, #1044, #1411).

Run

- TestForeignSealedReasoningGivenCodexCarriesNoContent (translated) and
  TestForeignSealedReasoningRelayedCarriesNoContent (relayed) fail on
  upstream/main with the issue's item handed over whole — content, empty
  summary and the vendor's seal in both output_item.done and
  response.completed — and pass with the change;
  TestTranslatedChatReasoningCarriesNoContent (a Chat upstream's
  reasoning, translated) is green without and with the change.
- Restoring the three product files alone to upstream/main (tests kept)
  fails the two again; restoring them back passes.
- Attaching content to the made item fails both again ("carries its
  text"), and dropping the made summary fails both ("carries no
  summary").
- go test -tags nogui -count=1 ./internal/gateway: ok 312.4s;
  -run 'TestTranslated|TestReasoning|TestSealed': ok 7.9s;
  go test -race -tags nogui -count=1 -run 'TestTranslated|TestReasoning':
  ok 9.4s. gofmt -l internal/gateway empty. go vet -tags nogui and
  go build -tags nogui -o /dev/null . on darwin, GOOS=linux and
  GOOS=windows: pass (a pre-existing cgo -Wenum-conversion warning in
  internal/gui/trayimage_darwin.go on darwin, untouched).

Not tried against real OpenAI or DeepSeek accounts; the reporter's
rollout reading is taken from the issue, not re-derived from a live
thread.

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

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 07:06:19 +08:00
yetoneandEdward4226 cbefb65987 gateway: a compaction summary answered 502 for ending short compacts locally too (#3526)
#3526's patch compacts locally when the summary ask ends short with an
error. The same cut can come back as a recorded 502 whose error says it
ended short (errEndedShort), with no error returned, and that still went
to the client as a 5xx. The local fallback now runs before the status
check, for both shapes (summaryEndedShort), and says why from the
recorded error. A 502 that says anything else still goes to the client
as it did. Edward4226 pointed at the 502 shape in the thread.

TestCodexCompactCutShapesCompactLocally covers a stream error, a 502
saying it ended short (compacts locally) and a 502 saying more (stays
502).

Landing record (yetone):
Run at the pushed batch head (tree a6b084d0b, on origin/main 616405061),
go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider and internal/plugin (this batch's
packages and those main changed since the full run): all ok. gofmt -l
clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags
nogui ./... clean. internal/gui on macOS (mote-run):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949), both red at main too.
- The full go test ./... -timeout 45m -count=1 ran one rebase earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2 (main then gained 5bfa9f076's
group stand-in, b19d08593, f856d381a and 616405061). It ran on Linux
(wsl-run): 82 packages ok. internal/agent has 4 reds, all red at
origin/main on that box as well: TestInstalledVersion,
TestGrokInstalled, TestOmpDetectedWithPiDir and
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, #3548). The root
package and internal/cli need gtk4 to build, so they ran on macOS
(mote-run): ok. TestColdTurnsTaken (#4510) was red there once. An
earlier full run at base d307aa648 was red once in
TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone at both
the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
Broken by hand: summaryEndedShort made to return false: the "HTTP 502"
subtest goes red; restored, green.
Not tried: a real ChatGPT summary ask answered 502.

#3526's patch compacts locally when the summary ask ends short with an
error. The same cut can come back as a recorded 502 whose error says it
ended short (errEndedShort), with no error returned, and that still went
to the client as a 5xx. The local fallback now runs before the status
check, for both shapes (summaryEndedShort), and says why from the
recorded error. A 502 that says anything else still goes to the client
as it did. Edward4226 pointed at the 502 shape in the thread.

TestCodexCompactCutShapesCompactLocally covers a stream error, a 502
saying it ended short (compacts locally) and a 502 saying more (stays
502).

Landing record (yetone):
Run at tree 7d7955eb9 (this batch on origin/main 3cfba2e37), go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider, internal/agent and internal/usage
(this batch's packages, plus those main changed since the full run): all
ok except internal/agent's TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, red at origin/main on that box too (#4033,
#3548). gofmt -l clean; go vet ./... (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./... clean. On macOS (mote-run), the
root package and internal/cli ok; internal/gui red in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
(#3949) and TestColdTurnsTaken (#4510), the first two red at main too.
- The full go test ./... -timeout 45m -count=1 ran two rebases earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2, on Linux (wsl-run): 82
packages ok, internal/agent's 4 reds as above, plus
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, red at main). The
root package, internal/cli and internal/gui need gtk4 to build, so they
ran on macOS as above. An earlier full run at base d307aa648 was red
once in TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone
at both the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
- Rebased after these runs onto origin/main c1457f2ee. Its two commits
since 3cfba2e37 (3f2faef62 gui, c1457f2ee agent) touch neither
internal/gateway nor internal/redact, nor any file this batch changes,
and were not run again here.
Broken by hand: summaryEndedShort made to return false: the "HTTP 502"
subtest goes red; restored, green.
Not tried: a real ChatGPT summary ask answered 502.

Co-authored-by: Edward4226 <234070868+Edward4226@users.noreply.github.com>
Co-authored-by: Edward4226 <234070868+Edward4226@users.noreply.github.com>
2026-11-01 06:38:01 +08:00
yetone 45385f0eed redact: a secret's field name masks only in a tool's arguments and result, with secrets on (#2946)
#2946's patch masked any JSON value whose field name looks like a
secret's (api_key, password, *_token) anywhere in a request body outside
tool definitions. That is an exemption, and a mask, keyed on a field's
name: it rewrote what the agent itself sends (mcp_servers'
authorization_token, a top-level api_key, metadata.session_token) as
well as the user's data. The name check now runs only where the user's
data sits in the protocol: a tool call's arguments (Anthropic tool_use
input, OpenAI arguments, Gemini functionCall args) and a tool's result
(Gemini functionResponse.response is added to the places scan reads),
and only with secrets masking on.

The Authorization/Cookie rule masked the word after the header name in
prose too ("Authorization: required for this route"). It now masks only
a value with a credential's shape: one token, or a scheme word and a
token, of 8 or more characters with a non-letter and not a ${VARIABLE};
or name=value cookie pairs.

Tests: TestMaskJSONNamedSecrets puts its values in tool_use input,
functionCall args and functionResponse response;
TestMaskJSONSecretNamesOnlyInToolArgs holds the agent's own fields as
written and nothing masked with secrets off; TestMaskAuthHeaders gains
prose rows (no mask) and a Cookie row.
docs/subsystems/gateway-routing.md says where the name check runs.

Landing record (yetone):
Run at the pushed batch head (tree a6b084d0b, on origin/main 616405061),
go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider and internal/plugin (this batch's
packages and those main changed since the full run): all ok. gofmt -l
clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags
nogui ./... clean. internal/gui on macOS (mote-run):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949), both red at main too.
- The full go test ./... -timeout 45m -count=1 ran one rebase earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2 (main then gained 5bfa9f076's
group stand-in, b19d08593, f856d381a and 616405061). It ran on Linux
(wsl-run): 82 packages ok. internal/agent has 4 reds, all red at
origin/main on that box as well: TestInstalledVersion,
TestGrokInstalled, TestOmpDetectedWithPiDir and
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, #3548). The root
package and internal/cli need gtk4 to build, so they ran on macOS
(mote-run): ok. TestColdTurnsTaken (#4510) was red there once. An
earlier full run at base d307aa648 was red once in
TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone at both
the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
Broken by hand: the name check's scope put back to everywhere but tool
definitions: TestMaskJSONSecretNamesOnlyInToolArgs goes red; headerValue
made to accept anything: TestMaskAuthHeaders' prose rows go red;
restored, green.
Not tried: a real agent's request through the gateway with masking on.

#2946's patch masked any JSON value whose field name looks like a
secret's (api_key, password, *_token) anywhere in a request body outside
tool definitions. That is an exemption, and a mask, keyed on a field's
name: it rewrote what the agent itself sends (mcp_servers'
authorization_token, a top-level api_key, metadata.session_token) as
well as the user's data. The name check now runs only where the user's
data sits in the protocol: a tool call's arguments (Anthropic tool_use
input, OpenAI arguments, Gemini functionCall args) and a tool's result
(Gemini functionResponse.response is added to the places scan reads),
and only with secrets masking on.

The Authorization/Cookie rule masked the word after the header name in
prose too ("Authorization: required for this route"). It now masks only
a value with a credential's shape: one token, or a scheme word and a
token, of 8 or more characters with a non-letter and not a ${VARIABLE};
or name=value cookie pairs.

Tests: TestMaskJSONNamedSecrets puts its values in tool_use input,
functionCall args and functionResponse response;
TestMaskJSONSecretNamesOnlyInToolArgs holds the agent's own fields as
written and nothing masked with secrets off; TestMaskAuthHeaders gains
prose rows (no mask) and a Cookie row.
docs/subsystems/gateway-routing.md says where the name check runs.

Landing record (yetone):
Run at tree 7d7955eb9 (this batch on origin/main 3cfba2e37), go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider, internal/agent and internal/usage
(this batch's packages, plus those main changed since the full run): all
ok except internal/agent's TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, red at origin/main on that box too (#4033,
#3548). gofmt -l clean; go vet ./... (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./... clean. On macOS (mote-run), the
root package and internal/cli ok; internal/gui red in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
(#3949) and TestColdTurnsTaken (#4510), the first two red at main too.
- The full go test ./... -timeout 45m -count=1 ran two rebases earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2, on Linux (wsl-run): 82
packages ok, internal/agent's 4 reds as above, plus
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, red at main). The
root package, internal/cli and internal/gui need gtk4 to build, so they
ran on macOS as above. An earlier full run at base d307aa648 was red
once in TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone
at both the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
- Rebased after these runs onto origin/main c1457f2ee. Its two commits
since 3cfba2e37 (3f2faef62 gui, c1457f2ee agent) touch neither
internal/gateway nor internal/redact, nor any file this batch changes,
and were not run again here.
Broken by hand: the name check's scope put back to everywhere but tool
definitions: TestMaskJSONSecretNamesOnlyInToolArgs goes red; headerValue
made to accept anything: TestMaskAuthHeaders' prose rows go red;
restored, green.
Not tried: a real agent's request through the gateway with masking on.
2026-11-01 06:38:01 +08:00
ggbdpq 78632d4b84 gateway: a Codex compaction cut short with no candidate left compacts locally (#3526, Edward4226)
A summary wanted whole whose stream every candidate broke off reached
codexCompact as an error none of its fallback conditions name: not a
404, not an unreadable item, not "Upstream request failed", not
"response protection is unavailable". The relay ends such a stream with
a response.failed event saying "the reply ended before it was complete"
(#2274), and with nobody left to fail over to, that error fell out of
the 404/protection family and went to Codex as a 502. Codex asked the
same huge summary over, three times, each paying for the whole
conversation, until compactFails answered 400 and held it: the
conversation could neither compact nor go on. That is the no-candidate
case #2274 left, after it made a cut summary fail over where there was
someone to fail over to.

The summary is magpie's own then, as when no model can be asked at all
(#866, #1008, #1270 end so). The summary as text isn't tried either:
the cut was in what the model wrote, not in what it was asked, and that
would be another ask of the same huge prompt. The words before the cut
are never taken: the local summary is built from the request's own
items. A summary that failed halfway, or ended incomplete — the output
limit's own event — is still told to Codex as it came and still counts
the guard; only the bare break-off turns local. 401, 403, 429 and
request-shape refusals are untouched.

Run: TestCodexCompactCutAloneCompactsLocally (new) is red on the parent
with the issue's 502 ("the reply ended before it was complete, so there
is no summary") and green here — 200, one magpie compaction holding the
local handoff, the cut stream's words in none of it, the last ask the
fake saw still the original summary request (no plain-text retry). The
#2274 tests keep their shape: TestCodexCompactCutSummaryFailsOver (a
whole fallback summary still wins) green unchanged;
TestCodexCompactCutSummaryIsNoSummary now covers the halfway and
incomplete shapes alone (the cut one moved to the new test);
TestCodexCompactKeepsFailingIsHeld holds on the incomplete shape, which
still fails and rests nobody. Ablation: only codex_backend.go put back
to the parent, tests kept — the new test is red again, restored, green.
go test -tags nogui -p 2 -count=1 ./internal/gateway: ok (350.8s).
Targeted TestCodexCompact with -race -count=2: ok. ./internal/usage:
ok. gofmt -l clean; go vet -tags nogui on darwin, linux and windows
clean; CGO_ENABLED=0 go build -tags nogui on all three ok.
docs/subsystems/gateway-routing.md says the new terminal state.

Refs #3526

Landing record (yetone):
Run at the pushed batch head (tree a6b084d0b, on origin/main 616405061),
go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider and internal/plugin (this batch's
packages and those main changed since the full run): all ok. gofmt -l
clean; go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags
nogui ./... clean. internal/gui on macOS (mote-run):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949), both red at main too.
- The full go test ./... -timeout 45m -count=1 ran one rebase earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2 (main then gained 5bfa9f076's
group stand-in, b19d08593, f856d381a and 616405061). It ran on Linux
(wsl-run): 82 packages ok. internal/agent has 4 reds, all red at
origin/main on that box as well: TestInstalledVersion,
TestGrokInstalled, TestOmpDetectedWithPiDir and
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, #3548). The root
package and internal/cli need gtk4 to build, so they ran on macOS
(mote-run): ok. TestColdTurnsTaken (#4510) was red there once. An
earlier full run at base d307aa648 was red once in
TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone at both
the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
Broken by hand: gua's ablation (codex_backend.go back to its parent: the
new test goes red). The 502 shape is broken by hand in this batch's
#3526 follow-up.
Not tried: a real Codex compaction whose every candidate is cut short;
the cut is the fake upstream's.

Landing record (yetone):
Run at tree 7d7955eb9 (this batch on origin/main 3cfba2e37), go1.26.8:
- go test -count=1 -timeout 45m on Linux (wsl-run) of internal/gateway,
internal/redact, internal/provider, internal/agent and internal/usage
(this batch's packages, plus those main changed since the full run): all
ok except internal/agent's TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, red at origin/main on that box too (#4033,
#3548). gofmt -l clean; go vet ./... (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./... clean. On macOS (mote-run), the
root package and internal/cli ok; internal/gui red in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
(#3949) and TestColdTurnsTaken (#4510), the first two red at main too.
- The full go test ./... -timeout 45m -count=1 ran two rebases earlier,
at tree 66a7a4c17 on origin/main 3a3bdb9f2, on Linux (wsl-run): 82
packages ok, internal/agent's 4 reds as above, plus
TestCopilotFolderFromAnIDEPluginIsNotTheCLI (#4033, red at main). The
root package, internal/cli and internal/gui need gtk4 to build, so they
ran on macOS as above. An earlier full run at base d307aa648 was red
once in TestUnroutedHeldReportSaved (#4300), which passes 5 of 5 alone
at both the head and main.
- Each landed patch's diff matches the head ggbdpq posted last on its
issue (patch-id).
- No GUI file is touched, so no GUI test file was run.
- Rebased after these runs onto origin/main c1457f2ee. Its two commits
since 3cfba2e37 (3f2faef62 gui, c1457f2ee agent) touch neither
internal/gateway nor internal/redact, nor any file this batch changes,
and were not run again here.
Broken by hand: gua's ablation (codex_backend.go back to its parent: the
new test goes red). The 502 shape is broken by hand in this batch's
#3526 follow-up.
Not tried: a real Codex compaction whose every candidate is cut short;
the cut is the fake upstream's.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:38:00 +08:00
yetone 3f2faef620 gui: the Providers page has its own Hide accounts switch
Routing's Hide accounts (账号打码) also masked the Providers page,
where nothing showed it was on or let you turn it off (Discord
#feedback, 1566189346665799752). The Providers page now has its own
switch beside its search box, placed and drawn like Routing's
(.rt-mask moved from routing.css to app.css), and each page follows
its own switch: Routing, Usage and the tray panel follow
magpie.maskEmails, Providers follows magpie.maskProviders.

The user's own choice is kept: when maskProviders was never stored,
it is seeded from maskEmails and written at once, so someone who had
masking on stays masked on both pages after the update, and someone
who turned it off stays unmasked. A switch with a stored choice is not
changed by Mask personal data's follow(); turning Mask personal data
on still masks both (hideAccounts.set(true, true), in app.js and
plugins/redact/page.js). show() asks hideAccounts.page() to re-mask
when the page in sight follows the other switch. No new strings: the
button reuses Routing's translated label and title. app.js
1,310,438, core under its budget, no raise.

Run:
- New internal/gui/tests/provider-mask.test.cjs, both engines, all
  5 languages, at 1000 and 420 wide, plus the touched window-mask,
  account-eye, privacy-hides-accounts, mask-emails,
  plugin-name-unmasked, masking-demo-unblurred: 134/134 on mote. At
  the rebased head (origin/main 573b21f4b) with gui-zh, gui-ja and
  i18n-keys: 140/141, the red is gui-ja's ja string from a7b47d57e
  (#4580), red on main.
- provider-mask on origin/main's assets: 60/60 red (no #pvMask).
- Broken by hand (chromium en), each red: cur() always Routing's
  switch ("Providers shows the account while its own switch is
  off"); the seed taken out (the upgrade on/off cases); show()'s
  page() call taken out.
- gofmt -l clean; go vet, GOOS=linux -tags nogui and GOOS=windows vet
  ok; the three builds ok; go test -tags nogui -timeout 45m ./... on
  mote at base 6712e367e: every package ok but internal/gui's
  TestSettingsSaveKeepsWhatItDoesNotSend, red on main too (#4514).
  At the rebased head: internal/gui's budget tests ok.
- Whole GUI suite on Linux (WSL magpie-desktop, concurrency 6, host at
  100% CPU), files a to l so far, the rest on mote: each red file was
  run alone at this head and at origin/main 6712e367e. Red alone at
  both, already filed: agent-panel-name-width (#4203), context-map
  webkit 420 (#3488), gateway-caller-keys (#3797), gateway-key-models
  (#4081), header-centre webkit ResizeObserver (#3479), key-replace
  webkit 420 (#4126), gui-ja (#4580). Red only under the whole run,
  green alone at this head: agent-plugin-agents (#4481), agent-prefs
  (#4552), allow-ips (#3699), api-key-theme (#3307), click-scroll,
  codex-predictions, currency (#3101), editor-advanced-align, fonts,
  gateway-key-limit, group-from-model-add, group-member-fast,
  group-member-off, group-morph, icon-url, inner-scroll-contain,
  keep-awake, lan-docker, ledger-hscroll, library-chip-fan,
  library-items, library-mcp-hub, library-mcp-tools, list-sort (the
  load class, #4400,
  #4471).

Not tried: the real desktop app's webview (Wails), and the GUI suite
on macOS beyond the files above.
2026-11-01 06:30:17 +08:00
a6de2a15ea gateway: an allowed_tools choice reaches the Grok plugin's fetch, end to end (#3153)
Follow-up to ggbdpq's grokShaped change: its test reads grokPluginBody
alone. skygunner's TestAllowedToolsReachesGrokPlugin (852182f6 on their
fork, from the #3153 thread) posts a /v1/responses request with an
allowed_tools choice through the gateway to the fake Grok plugin and
checks its fetch gets that object as sent, which is where the plugin
decides on x_search. Taken as written; provider-plugins.md names it.

Broken by hand: with internal/provider/grok.go at d307aa648 (before
the fix) it is red ("sent" with no tool_choice), green with it. The
plugin side was read in magpie-community/plugins at 26864ec (grok
0.2.3, the mover's min): rewrite decides x_search on the choice as it
came (null or "auto" only) and deletes an object whose type isn't in
TOOLS before Grok, so no min raise is needed.

Run at the pushed head on mote: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch.

Co-authored-by: vincent <webmaster@palmit.com.au>
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-01 06:21:39 +08:00
ggbdpq ca183561f7 gateway: an allowed_tools tool_choice reaches the Grok plugin (#3153)
grokShaped dropped a tool_choice object whose type isn't among grokTools
on the plugin's path too, the same as for the built-in: a Responses
request relayed to the Grok plugin in its own protocol reached the
plugin's fetch with no tool_choice, so with the X search option on (grok
0.2.0) the plugin added x_search over a client's allowed_tools and a
tool outside the allowed list went out. The plugin reads the choice and
leaves an unsupported one out before Grok itself (every version since
the TOOLS filter, the mover's min 0.1.18 among them), so grokPluginBody
now keeps such an object, as it keeps the lone "none" (#3110);
grokShaped's keepNone is forPlugin, since keeping is no longer only
about "none". The built-in, which is Grok's last stop, still drops it.

Run:
- gofmt -l on the changed files: clean
- go vet ./...: darwin and GOOS=windows clean; GOOS=linux vet needs
  -tags nogui (the GUI's wails doesn't vet without it), clean with it
- go build: darwin, GOOS=linux -tags nogui and GOOS=windows: ok
- go test -tags nogui ./internal/provider: ok 167.3s, no FAIL
- go test ./internal/gateway -run 'TestToolsOffWithoutTools|TestGrok': ok
- TestGrokPluginBodyKeepsUnsupportedToolChoice fails without the change
  ("plugin: tool_choice {Type: Mode: Tools:[]}"), passes with it; broken
  by hand, each way red then green on restore: deleting the choice
  whatever the path (plugin red), deleting only a supported type
  (built-in red)

Landed (yetone): the next commit adds the end-to-end test through the
gateway to the fake Grok plugin. Run at the pushed head on mote:
go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:21:39 +08:00
ggbdpq c26d16018f gateway: a plugin model that refuses temperature is asked without it, relayed or translated (#2492)
What changed: the plugin host carries a model's temperature where it is
said - the config model's temperature (Factory 0.1.31's configModels,
plugins#154), models.dev's own, or a models hook's model field - into
plugin.Model and pluginCatalog's catalog model, where
RejectsTemperature reads it as it reads a built-in's. A Chat or
Responses request relayed as it came to a model whose list refuses
temperature and top_p now leaves them out (passthrough), as the
translation of one (build) already did. A model nothing says so of
keeps what the client sent. OpenCode's capabilities.temperature is not
read: its false is what it reads a models.dev silence as, not a refusal
said.

Docs: the sampling row of gateway-routing, and provider-plugins' new
"A plugin model's sampling".

Run at ea3dee96 + this change, sandbox HOME:
go test -tags nogui -p 2 -run TestPluginModelRefusingTemperature
./internal/gateway/ - red at ea3dee96 without this change (the plugin's
fetch got temperature 0.7, top_p 0.9 relayed, temperature 0.7
translated; the model that says nothing keeps them), green with it;
ablation removed the four product files and went red the same way.
go test -tags nogui -p 2 -timeout 45m ./internal/gateway/ ok (291s);
go test -tags nogui -p 2 ./internal/plugin/ ok; -run
'TestRejectsTemperature|TestPluginModel|TestPluginCatalog|PluginParity|TestPlugin'
./internal/provider/ ok; -run
'TestSampling|TestUpstreamBytes|TestPassthrough|TestRelay'
./internal/gateway/ ok.
gofmt -l internal/ clean; go vet ./... (darwin, the
trayimage_darwin.go cgo warning as before), GOOS=linux go vet -tags
nogui ./... and GOOS=windows go vet ./... clean; go build and
GOOS=linux/windows go build ok.

Landed (yetone). Broken by hand on mote: with gateway.go, host.js,
internal/plugin/providers.go and internal/provider/plugins.go at
origin/main, TestPluginModelRefusingTemperature is red. passthrough
strips temperature and top_p for a provider whose catalog says
temperature false on Chat and Responses alike, the same rule build
applies. Run at the pushed head: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch.

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

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

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

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:21:39 +08:00
yetone 5bfa9f0762 gateway: a group's backup gives the conversation back once the member listed ahead of it is ready again (01huadalang on Discord)
01huadalang on Discord, after 76e4494db: Codex on several accounts in a
group with mimo2.6pro as the backup, Stays on Auto. Once Codex had quota
again, requests kept going to mimo.

The cause: when Codex couldn't answer, the turn fell over to mimo and the
session was stuck to mimo. On the next turns affine kept it there by
"cache", because only In order had a way back (backToFirst, Why "order").
A Smart group (and the other routings) never gave the conversation back to
the member ahead, however long Codex had been ready.

The fix: at the answer, the gateway records whether the member that
answered stood in for one listed ahead of it in the group: one that was
resting, or known all but used up (Used >= SpentShareOf). planGroup now
gives each candidate its member and its place in the group (placed), and
standsInFor reads the plan made before the tries. The flag is the stick's
stoodIn, inherited while the same who and model keep answering, and saved
in affinity.json (stoodIn). With Stays on Auto, a stick that stood in goes
back to the group's first member once that one is ready and not set aside
(backFromStandIn), with the new Why "back" and its Routing page line in
all five languages. A member put first on its merits (not a stand-in)
keeps its cache as before; Off, Session, Strict, Turn and In order keep
their own rules.

Not changed, by design: Smart and Least used count a key with unknown
usage (mimo) as unused, so with every Codex account at 90% or more of a
window a new session can go to mimo first. In order keeps a backup last;
the routing doc says so.

Tests (internal/gateway/group_stand_in_test.go, new):
- TestGroupBackupGivesTheConversationBack: smart auto with usage known
  and unknown go back ("back"); in order auto "order"; in turn and smart
  turn "new-turn"; smart off "off"; smart session, smart strict and in
  order session stay on mimo.
- TestGroupBackupStandingInWhileTheFirstIsBackAndBehind,
  TestGroupMemberPutFirstOnItsMeritsKeepsItsCache,
  TestGroupStandInStaysWithinATurn, TestGroupStandInSurvivesARestart.
- affinity_fallback_test's TestGroupMemberKeepsTheConversationOnceAnother
  IsBack pinned the old behaviour; it is now
  TestGroupMemberGivesTheConversationBackOnceTheOneAheadIsBack.
- routing-affinity-order.test.cjs gains the "back" line.

Run, all on mote:
- With the non-test changes stashed (old code): both smart auto cases,
  StandingInWhileTheFirstIsBackAndBehind, SurvivesARestart and
  GivesTheConversationBackOnceTheOneAheadIsBack are red. Green with the fix.
- Broken by hand, each red: the "back" case off (smart cases,
  StandingInWhileBehind); no inherit (StandingInWhileBehind); rest/spent
  check off (usage-known case, StandingInWhileBehind); stoodIn check
  dropped from the back case (PutFirstOnItsMerits); StoodIn not loaded
  (SurvivesARestart). A check of failed tries stayed green when turned
  off, since a failed try rests what failed, so it was removed.
- go test -tags nogui -count=1 -timeout 45m ./... at 80bcef18f + this:
  every package ok except internal/gui, whose two reds are red on
  origin/main d714c4216 too: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and TestColdTurnsTaken (#4510).
- Rebased on 5a56bc7d7: internal/gateway, internal/provider and
  internal/catalog ok; internal/gui has only the same two reds (#4514,
  #4510). Main then moved three provider-only commits; at the pushed
  parent f856d381a, internal/provider ok and internal/gateway -run
  'Group|Affinity|Fallback|Ordered|Strict|Rotating|Stick' ok.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gateway ok.
- GUI (Chromium and WebKit): routing-affinity-order, routing-js,
  i18n-keys, gui-zh-tw and gui-de pass; gui-ja's one red is #4580
  (a7b47d57e's string, not this one).
- Every routing-*.test.cjs file on mote (2050 tests, both engines, five
  languages) at load 140 to 200 from other sessions' suites: 35 red in 10
  files, all timeouts or moves under load. The same 10 files run alone,
  serially, at this head and at origin/main 41b5c0f19 are red in the same
  tests (27 and 30, differing only in which language flaked). All filed:
  #4585, #3789, #3096, #3094, #3799, #3412, #1804, #4560, #3593, #4082,
  #4627, #4628, #3954, #4629.

Not tried: no real Codex or MiMo account; the case was reproduced with a
fake upstream only. A stick saved before this change has no stoodIn, so a
conversation already stuck to the backup stays there until it goes cold
(5 minutes idle) or a new session starts.
2026-11-01 05:59:05 +08:00
yetone 5a56bc7d73 gateway: a CI job trades its OIDC token for a short-lived key (#4531)
xazaj on X asked for GitHub OIDC: a GitHub Actions job should get a
gateway key without a long-lived magpie key in the repository's secrets.

A rule (magpie gateway-key oidc add --key <id> --repo owner/name
[--ref …] [--environment …] [--claim k=v] [--ttl 1h] [--issuer URL]
[--audience a]; oidc list, oidc remove) names an issuer (GitHub Actions'
by default, any https issuer), an audience (magpie-<rule id> by default,
so a token asked for one rule opens no other, and the workflow needn't
know the gateway's address), claims (exact or path.Match globs) and the
gateway key the keys are issued under, which must be let issue. A GitHub
rule names the repository or its owner with no wildcard, or every
repository on GitHub could get in. No rule, no exchange.

POST /v1/magpie/keys/oidc with Authorization: Bearer <token> and an
optional {"ttl","models"} verifies the token (RS256 only, keys from the
issuer's discovery document's https jwks_uri, exp required, nbf/iat with
a minute's leeway, the rule's aud and claims, a jti traded once) and
issues a key through access.IssueKey under the rule's key, named
repo@ref (run N), living no longer than the rule. Everything issued keys
guarantee holds: bounded by the issuer's models and accounts, its spend
counted against the issuer, stopped when the issuer is turned off.

- A token is judged only against rules naming its iss, so it can't make
  magpie fetch from a URL of its choosing.
- Keys are cached an hour per issuer, read by one request at a time with
  no lock held across the fetch, asked again for an unknown kid at most
  every 10s, and kept while the issuer is down; with none ever read,
  nothing is let in.
- The route is lanGuard's one exemption from remoteKeyed (that exact
  path, POST, no gateway key): only while shared, past the allow list,
  and a refused token counts against tooManyAuthFails (429 past the
  burst). A read-only key is refused it.

The issue's open questions, decided: rules are generic from the start
(the GitHub repository rule applies to GitHub's issuer); rules are CLI
and file only for now (oidc-rules.json), no GUI.

Docs: docs/subsystems/gateway-routing.md (Trading an OIDC token for a
key, routes table) and site/public/docs remote in en, zh and ja, with
the workflow snippet.

Tests: TestOIDCTokenTradedForKey (no rule, a traded key that works on
chat with its TTL capped and its name, a model past the issuer, another
branch, no token, 51 bad tokens -> 429, issuer turned off, a token on a
model route, loopback, not shared -> 403); TestMatchEachCheck (14 bad
tokens, list aud, replay, the refusal naming the claims);
TestKeysCachedAndKept (8 concurrent tokens one fetch, rotation, a made-up
kid inside and past the gap, the issuer down 2h later, an unnamed issuer
never fetched); TestUnreadKeysLetNothingIn; TestAddRefuses;
TestGatewayKeyOIDCCLI; TestReadOnlyKeyEveryRoute with the new route.
A JWKS from an httptest TLS server, never the network.

Broken by hand, each red then restored: the signature check, the claims
match, the jti check, the exp check, the refetch gap, the GitHub scope
rule, the lanGuard exemption, the throttle and the TTL cap.

Run at this head (rebased on 6a7a690be), on mote: go test ./internal/oidc/...
./internal/cli (whole packages) and go test -run 'OIDC|ReadOnlyKeyEveryRoute|
KeysEndpoint|IssuedKey|AuthThrottle|Route' ./internal/gateway: ok; gofmt -l
clean. At the 13aa33eac base: go vet (darwin, GOOS=linux -tags nogui,
GOOS=windows): ok; node --test site/*.test.mjs: 63 pass.
Full suite (-tags nogui -timeout 45m ./...) on the Linux box at the
13aa33eac base, still running when this was pushed (mote had two other
sessions' suites at load 291); so far every package ok except
internal/agent's TestInstalledVersion, TestGrokInstalled,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI and TestOmpDetectedWithPiDir,
the WSL box's fake-binary reds filed as #4033 and #3548. The rest of the
run goes on #4531.

Not tried: a real GitHub Actions run against a shared magpie; a
connection open when an exchanged key expires.
2026-11-01 05:39:02 +08:00
yetone 93879515a0 agent: QwenPaw, each of its agents' active_model one of magpie's (pkh1585 on Discord)
pkh1585 asked for QwenPaw (AgentScope, github.com/agentscope-ai/QwenPaw)
on Discord. Read in its source, 2.2.2.post1, as data:

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

What magpie does now:

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

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

Not tried: Windows, the macOS desktop app, QwenPaw in WSL wired from
Windows magpie, the ACP backend, QwenPaw's web console after connecting,
a real legacy ~/.copaw.
2026-11-01 05:00:36 +08:00
yetone 9bb1efdde3 gateway: a reply names the model the agent asked for when it went out under another name (issennknight)
issennknight on Discord (#general): an agent asked for deepseek-v4.1-flash,
which goes out as deepseek-v4.1-flash-1017 (settings' ModelIDs). The vendor's
reply said -1017, magpie passed it back, and the agent warned that the model
didn't match.

Before, only MemberModel (#822) or X-Magpie-Response-Model: member rewrote a
reply's model, and only to the group member's id. Now the default is
nameAsked. When magpie sent the request under another name than the agent
asked for (a model's own id, a routing group, a provider/model id), the
reply names the asked model. That covers Chat and Anthropic `model`,
Responses `response.model` (created, in_progress, completed), Anthropic
`message.model` (message_start) and Gemini `modelVersion`, streamed and
whole, translated paths and plugins included: it all goes through serve's
one memberWriter. A vendor that sent back the wire name as asked keeps its
own name, a dated -20261017 too. Usage rows, recent calls and the Routing
page still record served = the vendor's name: the writer sits outside
captureResponseWriter. Claude Code, Claude Desktop and Codex get the asked
name (or the vendor's), never the member's id, as before.

Streams are rewritten one complete line at a time (memberLines). A run
with no "model" in it is written through as the same slice. Only a JSON
reply that has a target at decide time is held whole, which is what
MemberModel already did.

A JSON body that doesn't parse (a reply cut short) goes on as it came.
A request to a remote magpie now sends X-Magpie-Response-Model: vendor
(passOnCaller). That magpie names the vendor's model, as before, so this
one still records what served the call (TestRemoteMagpieGroupNotSwapped
went red without it).

Existing tests that held a native reply byte for byte now expect only
its model renamed to the asked id (namedAs in member_test.go):
passthrough_severed, stream_accounting, refusal, refusal_thinking,
thinking_signature and vertex. The archive keeps the reply as the
vendor sent it, under the vendor's name (archive_test).

Also dropped: the openai-model header code. serve never relays that header,
so the test for it could not pass.

Run (mote, at this head rebased on origin/main 15066f84f):
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok
  except internal/gui: TestSettingsSaveKeepsWhatItDoesNotSend (#4514,
  SearchAll from b09349d17) and TestColdTurnsTaken (#4510). Both are filed,
  and neither touches this change. Three other sessions' suites ran on
  mote at the same time.
  The first full run (base 80bcef18f) had internal/gateway red in 10
  tests: the byte-for-byte tests above, the remote-magpie served test and
  the truncated JSON body. Each one was fixed as described.
- Rebased on 544b91ca8 (no gateway files changed in between): go build ./...,
  go vet, then go test ./internal/gateway ./internal/settings
  ./internal/provider: all ok.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean (cgo warnings only); gofmt -l clean.
- go test -race -count=3 on the member and served tests: ok (122s).
- the 10 formerly red tests with TestReplyNames, TestGeminiReplyNames,
  TestMemberLine, TestMemberWriter and Masked, after the rebase: ok.

Red on the old code (the new tests over a git archive of the base):
- TestReplyNamesAskedModel: 36 subtests fail (own id, group and provider
  id, x 6 protocol paths, x streamed or not), e.g. `the reply names
  "deepseek-v4.1-flash-1017", want "deepseek-v4.1-flash"`.
- TestGeminiReplyNamesAskedModel: both subtests fail (modelVersion -1017).

Broken by hand: dropping `|| m.wire == m.asked` from target() fails
"as asked, dated" in 12 subtests.

Real use: Codex 0.165.0 (codex exec --json) under a sandbox HOME and
CODEX_HOME on mote. A fake Responses vendor always answered
deepseek-v4.1-flash-1017, and a tee between Codex and `magpie serve` logged
what Codex got. providers.json had d with deepseek-v4.1-flash and group
fast; settings.json had modelIDs d/deepseek-v4.1-flash ->
deepseek-v4.1-flash-1017.
- old build: the vendor was asked for -1017; Codex got "model":
  "deepseek-v4.1-flash-1017" in response.created, in_progress and completed,
  both for -m deepseek-v4.1-flash and for -m group/fast.
- new build: the vendor was still asked for -1017; Codex got
  "deepseek-v4.1-flash" and "group/fast"; the usage rows still say served
  deepseek-v4.1-flash-1017. Codex answered "pong" both times. Codex 0.165
  itself shows no warning for a body model either way (its "model
  rerouted" reads the openai-model header), so the agent behind the
  report's warning was not the one run.

Not tried: the reporter's own agent (not named) and Claude Code; the
Responses WebSocket path (responses_ws.go's own frames); a compressed
reply, which still goes through as it is; Antigravity's effort-variant
wire, where the wire differs from the asked name on purpose.
2026-11-01 04:51:17 +08:00
yetone 606743831e appdir: on Windows an agent's folder variable follows the registry, and a gone folder it names isn't made again (bm_rabbit on Discord)
bm_rabbit (0.1.2405, Windows x64, Pi 1.4.0) moved Pi's AgentDir from
F:\piData\.pi\agent to F:\HarnessData\Pi\.pi\agent, deleted the old one and
set the User variable PI_CODING_AGENT_DIR to the new path. Changing Pi's
model in magpie then made the deleted folder again with only models.json
and settings.json in it.

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

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

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

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

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

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

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

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

Not tried: magpie's own GUI on Windows (the probe calls the same
agent.Apply the GUI's /api/set reaches); a REG_EXPAND_SZ value and a
Machine-only value on the real box (code path read, not run); bm_rabbit's
junction at C:\Users\Administrator\.pi.
2026-11-01 04:40:44 +08:00
yetone 544b91ca87 dsh: magpie's routes wait for a slow reply as long as the gateway does (tim on Discord)
tim's first "who are you" to gemini-3.8 through the third-party plugin
magpie-gemini-web 0.8.0 took minutes in dsh and ended in 499 ("the agent
canceled the request"). dsh hung up: llm-pi-ai gives a turn up after 5
minutes with no pi-ai event (DEFAULT_STREAM_IDLE_TIMEOUT_MS, every
dsh-llm-pi-ai from 0.1.5 to 0.2.2), and the gateway's ": keepalive"
comments (keepQueued, keepQuiet) are not events. The plugin serves one
request at a time (maxConcurrency 1), dsh's own session title goes to the
same route model in parallel, and the plugin's backend sends no byte
before its first token, so the turn's 5 minutes ran out in magpie's queue
and the backend while the gateway (10 minutes for headers) and the plugin
(240s per wait, then its own 504) were still waiting.

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

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

Not tried: tim's own setup (the plugin is not run against a Google
account); a real 5-to-10-minute wait in dsh; Windows.
2026-11-01 04:23:05 +08:00
yetone 3182a66586 provider, gateway: OpenRouter's decision model picked with a variant (inception/mercury-decide:free) is a decision model, never sent to chat/completions
coeo91 on Discord (2026-10-31): inception/mercury-decide:free, picked by
hand into a group used as smart routing's decision model, failed with
"OpenRouter: inception/mercury-decide:free is a decisions model and
cannot be used with the chat/completions endpoint. Use the
/api/alpha/decisions endpoint instead."

Cause: magpie already reads OpenRouter's decision models from its own
list (/models?output_modalities=decisions: output_modalities
["decisions"], endpoints ["/api/alpha/decisions"]) and asks them at
/api/v1/systemone. That list names each model once, without variants,
so the hand-picked ":free" id was taken for a chat model. Its group was
a chat group and the classifier asked it in words on chat/completions.

Now a variant of a model OpenRouter's decisions list names (base id
before the last ":", OpenRouter providers only; Ollama's :tag stays a
name of its own) is a decision model (openRouterVariant):
- it is kept from agents' model lists, and its group is a decision
  group, asked at /api/v1/systemone (classifier, RouteDecider);
- an agent's chat naming it gets magpie's 400 "only decides", with
  OpenRouter not asked;
- count_tokens naming it, or its decision group, gets the same 400
  (count_tokens had no decision guard and forwarded upstream);
- test-models sends it the System One yes-or-no, and the provider
  editor marks it as a decision model (/api/providers deciders).

Not done: an /api/alpha/decisions client. OpenRouter's /api/v1/systemone
(what magpie uses) answered the same model the same way as the alpha
path in a real probe (200, identical System One shape), so the alpha
endpoint adds nothing but an alpha contract.

Real probe (owner's OpenRouter key, 2026-11-01): chat/completions with
inception/mercury-decide:free gives the reporter's 400 word for word;
/api/v1/systemone and /api/alpha/decisions give 200 for
inception/mercury-decide and 404 for :free ("This model is unavailable
for free... use this slug instead: inception/mercury-decide"). So
after this change the reporter's group is asked the right way, and
OpenRouter's own 404 says to pick the paid slug.

Tests (fixtures are OpenRouter's real list and answer bytes):
TestOpenRouterDecisionModelVariant (provider),
TestOpenRouterDecisionVariantNeverChats (gateway: classifier group asked
at /systemone, chat and count_tokens refused, OpenRouter asked once),
TestOpenRouterDecisionVariantPicker (gui). Each is red on the old code
(provider: "taken for a chat model"; gateway: the reporter's 400 as the
classifier's error; gui: deciders without the variant), checked at
0565c0bba and again after the rebase. With only gateway.go reverted,
count_tokens answered 200 {"input_tokens":0}.

Run:
- full `go test -tags nogui ./... -timeout 45m` on mote at 970931203
  (this change on 0565c0bba), log kept: every package ok except three
  reds that fail the same at 0565c0bba without this change or pass
  alone, each filed: TestBrowserExtensionOnlyFromItsOrigin (#4631),
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestColdTurnsTaken
  under the full run (#4510).
- gofmt -l, go vet, GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... at 970931203.
- after rebasing on f9ca3dd44: gofmt, GOOS=linux and GOOS=windows go vet
  ./internal/..., and go test ./internal/provider ./internal/gateway
  ./internal/gui ./internal/catalog -count=1 at 182d84f2b on mote:
  provider and catalog ok; gateway and gui red only in
  TestBrowserExtensionOnlyFromItsOrigin (#4631) and
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), as on main.
- An earlier WSL full run wedged in go test with no child for 30
  minutes beside two other sessions' GUI suites and was stopped; its
  internal/agent reds are WSL's binfmt (#4033, #3548).

GUI: app.js is unchanged; only /api/providers' deciders list gains a
hand-picked variant, which app.js already reads. The GUI suite was not
run; its decision tests run on fixtures.

Not covered: a custom (non-preset) provider at openrouter.ai has no
Decide base, so its decision models still go to chat/completions
(#4614): filling Decide by host could override a value the user cleared.

Not tried: the whole magpie path end to end with a real OpenRouter key
(the probe called OpenRouter directly).
2026-11-01 03:07:06 +08:00
yetone e6b595e1ab claude: Interactive only, a setting under which a model request never runs as claude -p (_yuchanns_ on X)
_yuchanns_ on X, on the interactive mode falling back to -p: for people
who stayed off magpie's Claude subscriptions because of -p, a fallback
is a time bomb. Settings › Models › Replies › Claude Code's interactive
mode now has three choices: Off (always -p), On (the default, falling
back to -p as before) and Interactive only.

With Interactive only (settings.ClaudeTUIOnly; ClaudePrintMode set too
wins):
- a run claudeTUI would make -p is not started; the request fails with
  the reason and the setting (claudeOnlyErr, claudeNotTUIWhy);
- the helper is handed MAGPIE_CLAUDE_TUI_ONLY=1 (claudetui.OnlyEnv,
  claudeCLI.tuiEnv). Where it would exec -p (no start, sign-in, first-run
  notes, untrusted folder, 45s timeout) it exits with the reason
  (fallBack in Run), and it ignores the broken mark;
- a helper that never answers initialize ends the turn with an error,
  not a -p retry, and `broken` isn't counted (claudeMachineWhy), so the
  next run tries the interactive mode again;
- the model test's and warm-up's "hi" (askClaude) runs through the
  helper (askClaudeTUI) in stream-json, its stdin closed at the first
  result. The helper command and env are built in one place now
  (tuiCommand, tuiEnv) for both.
Reading the plan's allowance (/usage) asks no model and stays -p; the
setting's text says so. Docs: claude-subscription-bridge.md.

Provider editor, on e8347401f's "Claude Code runs as" pill
(ClaudeMode.Only): with the interactive mode in use and no last
request, it says a request it can't take fails, and the card's foot says
nothing runs as -p. Where the interactive mode can't run, the pill names
Interactive only, never claude -p, the line says "Claude requests fail:
<why>", and Change in Settings goes to the row. A request refused this
way never ran, so it isn't noted as the last request (noteClaudeRun
comes after the refusal).

app.js: the Replies rows share one helper (segRow, which waitRow uses
too), so app.js is 530 bytes under main's with the third choice; no
budget raise.

Tests: TestClaudeTUIOnlyRefusesPrint, TestClaudeTUIOnlyHungHelperNoPrint,
TestClaudeTUIOnlyTellsHelper, TestAskClaudeTUIOnly (gateway);
TestShimOnlyNeverPrints (claudetui: fake fail/trust/login/notes each
exit with an error and no -p, a marked-broken run still interactive);
claude-tui-setting.test.cjs (three choices, Only saves claudeTUIOnly with
claudePrintMode false) and claude-mode.test.cjs (Only in use, and Only where it can't run).

Broken by hand, each red, then put back: the startRun gate off
(RefusesPrint 200); start()'s Only check off (HungHelper 502 without the
Only reason); tuiEnv's OnlyEnv off (TellsHelper); askClaude's branch off
(AskClaudeTUIOnly); the helper's fallBack ignoring only (4 subtests);
BrokenSince's `&& !only` gone ("marked broken"); the save without
claudeTUIOnly (16 of 16 setting tests) and claudemode.js's m.only
branches gone, rebuilt on e8347401f's file (10 of 10 Only tests,
Chromium).

Run on mote at e8347401f + this commit:
- at f1d6f4137 (main, after #4571's claude_cache.go) + this commit: go
  vet of gateway and gui ok, CoreScriptBudget|I18n ok, the gateway's
  TUI|Warm|Claude|AskClaude|Cache tests ok; the rest below at e8347401f
- gofmt -l clean; go vet and GOOS=windows go vet of claudetui, gateway,
  settings and gui ok; Linux vet (wsl-run, -tags nogui) ok
- go test ./internal/claudetui ./internal/settings ok; the gateway's
  TUI|Warm|Claude|AskClaude tests ok
- internal/gui CoreScriptBudget|I18n|Settings: ok but
  TestSettingsSaveKeepsWhatItDoesNotSend, SearchAll, red on main since
  b09349d17 (#4514)
- GUI (Chromium + WebKit, every language): claude-mode, claude-tui-setting
  and i18n-keys 94 of 94 at e8347401f; with the other Replies rows'
  files (claude-lean-prompt, member-model, loop-guard, refusal-retries,
  classify-timeout, image-timeout) 180 of 180 at 2e9df9b1b. Earlier
  segs-press-redraw's searchAllRow red is #4566, not this change.
Not tried: a real account under Interactive only (the fallback paths
are forced by the fake Claude Code); the full GUI suite (mote had
another session's full GUI suite and an agent+gateway suite going).
2026-11-01 02:53:08 +08:00
yetone e1aec53895 routing: each session sending at once has its own context window, named by its title (tjhhhh on Discord)
tjhhhh runs several agent sessions at once. The Routing page's context
window card followed whichever request came last, so it jumped from one
session's prompt to another's. The card still tells of the request it
picked. Under it, while two or more sessions are live, a strip now
shows one small block per session (renderCtxSessions):
- keyed as the card's line of prompts is (sessionKey, else the
  conversation);
- named by the agent's title for the session (sessionName), else its
  folder's last level, never a bare id;
- holding that session's newest reading through context.js's stack bar,
  exported as window.ctxStack.

A session is live while a request of it is under way, or while its
newest request is within 15 minutes of the newest overall. At most six
blocks show, newest session first. A block keeps its place while the
sessions take turns, because blocks are ordered by each session's first
request. The block the card tells of is lit (aria-pressed), and a click
on a block picks that session's newest request. The card's footer names
the session by its title too. New words are in every locale in
plugins/routing/i18n.js. The strip reuses the card's tokens: no select,
no coloured border, no gradient.

The strip sits under the card, not over it. Over it, the strip's first
appearance moved the card, and routing-ctx-still ("the cache kept its
place") went red in both engines. It is green at base ccc791231, and
green again with the strip under.

What was run (mote, through mote-run):
- New routing-ctx-sessions.test.cjs: two engines, en/zh/zh-TW/ja/de at
  1100 and 390px, plus one session alone and one with no title. Red on
  origin/main, since there is no strip there. Broken by hand: ordering
  blocks by newest request instead of first request turns the
  "keeps its place" check red. Green, 4 of 4 tests, at the final tree.
- routing-ctx-still: red with the strip over the card, green with it
  under (tests 391/392, both engines).
- Whole GUI suite, at the first version (strip over the card), under
  load 25 to 30 from other sessions: 16892 tests, 16595 pass, 297 fail
  in 49 files. That version's own red was routing-ctx-still (fixed
  above). Every other red file has an issue:
  - Filed before: agent-panel-name-width #4203, context-map #3488,
    gui-ja #4580, i18n-keys "Unmarked" #4524, header-centre #3479,
    key-replace #4126, menu-input-scroll #3402, mobile-web #3952,
    model-chip-steady #4388, models-works-only #4391, page-width-steady
    #4541, phone-connect-menu #3524, plugin-card-update #3079,
    plugin-move-unserved #4392, provider-fetch-again #3292,
    provider-levels-scroll #4394, provider-models-rest #4396,
    provider-picks-stay #4397, provider-typed #4461, recovered-file
    #4320, remote-magpie #4398, rest-try-now #2564, routing-row-swap
    #3799, routing-steady #3412, the routing rule-drag, rule-remove,
    rules-line and upstream files #4585 and #4494, s3-sync #3413,
    searcher-pick #4274, segs-press-redraw #4189 and #4566,
    usage-agents-hide #3414, warm-now #4322.
  - Filed with this commit: editor-advanced-align #4615,
    gateway-key-models #4616, group-found-skip #4617, images-codex-one
    #4618, import-row #4619, market-have #4620, model-copy-id #4621,
    nav-timeout #4622, number-units #4623, omarchy #4624, tencent-cloud
    #4625, usage-ledger #4626, routing-order-unknown #4627,
    routing-steps-cap #4628, routing-story-shrinks #4629.
- The files this change can reach (routing-*, context-*, i18n-keys,
  gui-ja), alone at concurrency 2 on the first version against base
  ccc791231: 54 fail on the head and 34 at the base. The only red that
  was on the head and not the base was routing-ctx-still. The rest were
  routing reds under load that show on both.
- The same files rerun with the strip under the card: 2331 tests,
  35 fail. routing-ctx-sessions and routing-ctx-still are green. Each
  red has an issue: context-map webkit 420px "two tiles overlap"
  (#3488, the same at base), gui-ja (#4580), i18n-keys "Unmarked"
  (#4524), routing-many-keys (#4082), routing-row-swap (#3799),
  routing-steady (#3412), routing-order-unknown (#4627),
  routing-steps-cap (#4628), routing-story-shrinks (#4629), and
  rule-drag, rule-remove, rules-line and upstream (#4585).
- TestCoreScriptBudget went red after the rebase: the core was over by
  266 bytes, which is the new stackBar helper in context.js. The budget
  was not raised. stackBar was written tighter and the comments around
  it cut, and context.js is now 1 byte under its size at origin/main.
- Rebased on origin/main 2e9df9b1b, on mote:
  - `go test ./internal/gui`: TestCoreScriptBudget passes. Two reds are
    already filed: TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red
    on main) and TestMainWindowCorners (#3949, macOS 27).
  - routing-ctx-*, context-*, i18n-keys and gui-ja: 337 tests, 8 fail.
    routing-ctx-sessions is 4/4, routing-ctx-still 2/2, and every
    context-* other than context-map is green. The reds are context-map
    "two tiles overlap" (webkit 420px in every language and chromium
    zh 420px, #3488), gui-ja (#4580) and i18n-keys "Unmarked" (#4524).
- Rebased again on origin/main e8347401f, which changes the core
  budget and fixes #4524. This is the pushed tree. TestCoreScriptBudget
  is ok, and routing-ctx-sessions, routing-ctx-still and i18n-keys pass
  44/44.

Not tried: a real gateway with several live agent sessions sending at
once (only the page's fixture feed was used), the Linux WebKitGTK app,
and the whole GUI suite at the final tree (only the files above,
which the change can reach).
2026-11-01 02:44:37 +08:00
yetone e40675cc19 middleware: onAccount can pass an account over for a request (bm_rabbit)
bm_rabbit (Discord) is building MOD_Probe, a middleware that tells
Codex accounts apart and needs to keep some requests off some of them.
onProvider could only change a try's body, never which account took
it.

A JS middleware may now export onAccount(account, ctx). The gateway
calls it before each try on a subscription account, at the top of the
candidate loop (accountSkipped). That is before anything of the try is
done: no Codex reset is spent, no body is built, nothing is sent.

account is {ref, provider, name, kind, model}. ref is 32 hex
characters: an HMAC-SHA256 of the middleware's name and the account's
agent, lower-cased user and plan. Its key is random, made once per
install in account-ref.key in magpie's config folder. It is written to
a temp file and linked into place, so it never writes over a key that
is there. The ref is the same on every request and after a restart,
and different for each middleware. The email can't be found from it
without the key. A key file that can't be read is never overwritten:
that process uses a key of its own and logs it.

{skip: true} passes the account over for this request. The next
candidate is asked, as past an account that can't be used. The call's
fallback gets a "passed over by middleware <name>" line, and the
account is not rested or held against. When the last candidate is
passed over, nothing is sent (no fail-open). The agent gets the
failure of a candidate asked before it, or, if there was none, the
usual 404 "none of <model>'s models is ready".

Anything else uses the account: undefined, {}, null, a throw, or going
past the 250ms limit. The last three count as failures. A key's try
asks no onAccount. ctx.account holds the same object for the hooks
after it on that try, and is taken away on a key's try. ownAsk clears
the Accounts runs with the Tried ones.

Note: the plan is part of the ref, so a plan change gives the account
a new ref.

Docs: docs/subsystems/gateway-middleware.md (runtime path step 4,
limits, fail open, verification), docs/reference.md,
docs/integrating.md, and site/public/docs/{,zh/,ja/}plugins.html (an
onAccount row in the hooks table). The Bun plugin host is unchanged:
middleware runs in moejs in the gateway, not in host.js.

Tests:
- internal/middleware TestOnAccount: the ref is stable across runs and
  a key reload; it differs between two middlewares, users, plans and
  kinds, and is the same when only case differs; no email or plan
  reaches the hook. {skip:true} names the middleware; undefined,
  {skip:false}, throw and null use the account (2 failures counted);
  ctx.account reaches onProvider; a key's try clears it.
- internal/middleware TestAccountRefKey: the key file is made at 0600,
  read back, never written over when unreadable, and no temp file is
  left behind.
- internal/gateway TestOnAccountSkipMovesToNextAccount: two Codex
  accounts, Ordered. The first is passed over, only acct-2 is sent
  the request, acct-1 doesn't rest, and the same holds on a second
  request.
- internal/gateway TestOnAccountSkipEveryAccount: every account passed
  over gives a 404 "…models is ready", nothing is sent, nobody rests.

Broken by hand, each on mote, each red, then restored:
- skip ignored in accountSkipped: both gateway tests red (acct-1
  reached; 200 instead of 404)
- fail open on the last candidate: SkipEveryAccount red (200)
- the skipped account rested: both gateway tests red (rests)
- a random key per ref: TestOnAccount (refs changed between requests)
  and TestAccountRefKey red
- the middleware name left out of the hash: TestOnAccount red (two
  middlewares told one ref)
- an unreadable key overwritten: TestAccountRefKey red

Run at this commit's tree (rebased on origin/main 6a900e0d0):
- gofmt -l: clean
- mote-run go vet -tags nogui ./internal/... ./plugins/...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok
- mote-run go test -tags nogui -count=1 -timeout 45m ./... (log kept
  whole): every package ok except three. internal/middleware's
  TestPointsLoadErrors was mine: its load-error text now names
  onAccount. The test is fixed in this commit, and the package and
  plugins/middleware were rerun ok at this tree. The other two are red
  on main and already filed: internal/cli TestLibraryMCPHub (#4140,
  TempDir cleanup) and internal/gui TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514, SearchAll from b09349d17)
- Rebased again on origin/main 20482d71f (it changed
  internal/gateway/affinity.go): mote-run go test -tags nogui -count=1
  ./internal/middleware ./internal/gateway ./plugins/middleware: all ok
  (gateway 846s)

Not tried: a real MOD_Probe against real Codex accounts. Not changed:
probe keys can still reach deactivated accounts (out of scope).
2026-11-01 02:19:26 +08:00
yetone 20482d71ff library: a skill by a name the library has from elsewhere goes in beside it
mora1n on Discord: anthropics/skills' skill-creator and openai/skills'
are two skills by one name, and only the first could be added; the
second was skipped as "another skill called skill-creator, left as it
is". The library keyed being had by name in every place that asked.

Now being had is decided by source (hadSkill): the same source under any
name here, or a skill with no source (taken in from an agent's folder)
by that name with the very same files. Another skill from GitHub or a
git repository whose name is taken goes in beside it as
<name>-<owner> (skill-creator-openai), then owner-repo, repo, a number,
at most 64 bytes (freeSkillName in skill_beside.go). The library's copy
of its SKILL.md gets that name in the front matter's top-level name:
line (nameSkill), so no agent sees two skills by one name; Skill.Called
keeps the name it came with, and the carried bundle carries it. Its hash
is of the renamed copy, and checks (GitHub and git) and updates compare
what they fetch renamed the same way (fetchedHash), so it doesn't read
as edited and an update keeps the name.

The class: probe (Candidate.Have now means this skill; Candidate.As is
the name it has or would get), installFrom (listed and unlisted folder
by that name), the new-skills check (no longer drops a skill because
its name is taken), the market's had check (by name only for a skill
with no repository: none or a folder), carry, the TUI's probe list and
the GUI's probe list ("adds as {name}" with why in its title, "In the
library as {name}"; zh, zh-TW, ja, de; the tag is cut short in its row).

Old data: nothing is renamed. A skill already in the library keeps its
name, folder, SKILL.md and agent links; library.json without "called"
reads as before. Only a skill added from now on can get another name.
Not changed: a folder of the user's own is linked as it is and its
SKILL.md can't be named apart, so one by a taken name is still skipped,
now saying to rename it in its SKILL.md; and an agent's own skills
folder still holds one skill per name (an agent's own skill by the
library's name is settled by Use library / Keep agent's as before).

Run (mote, at c6fd4b37c on origin/main 6a900e0d0, then rebased on
0fe9f97c1, which touches only claudetui, gui and provider):
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build ./..., go build -tags nogui:
  clean.
- go test -tags nogui -count=1 -timeout 45m ./...: 82 packages ok,
  internal/gui red only in TestSettingsSaveKeepsWhatItDoesNotSend
  (SearchAll, #4514, open on main, not this change).
- After the rebase: internal/library and internal/tui ok.
- GUI, both engines: skill-install-beside (new), every skill-*,
  library-*, found-skill-*, remove-found-*, mcp-*, i18n-keys, gui-ja,
  gui-de, gui-zh-tw, font-cascade, inner-scroll-contain, win-fonts:
  1427 tests, 1423 pass. The 4 reds fail the same at origin/main
  3baf3b6df run alone: gui-ja (#4580), i18n-keys "Unmarked" (#4524),
  library-row-remove chromium (#3099).

Red on the old code: the anthropics-then-openai install against
origin/main code fails with "the library already has another skill
called skill-creator, left as it is". Broken by hand: fetchedHash made
to hash the fetched files unrenamed turns
TestSameNameFromAnotherSourceGoesInBeside red (hash mismatch); the
.lib-pick > .lib-tag rule removed turns skill-install-beside red ("the
tag stays in its row") in both widths.

Not tried: real anthropics/skills and openai/skills installs in a
sandbox HOME (the tests serve both repositories' layouts as tarballs;
the fixtures put both at skills/skill-creator. The real openai/skills
keeps it under skills/.system, which a probe of the repository's top
doesn't walk into; that is how probing has been and isn't changed
here); Windows and Linux runs of the GUI.
2026-11-01 02:02:24 +08:00
yetone 76e4494dbd gateway: In turn passes over a provider's fallback while the provider is ready (01huadalang)
01huadalang on Discord (#feedback, 10-31): once the main provider has
quota again, requests keep going to the fallback model, which is only
meant for emergencies.

Cause: a provider routed In turn treated its fallback rows as more of
its own keys. A new turn went to the row after the last answerer
(after), which past the provider's last key is the fallback, and a new
conversation went to the row the fewest conversations held (leastHeld),
which is the fallback nobody is on. Both happened while every key of the
provider was ready. The session spread already skipped fallbacks
(readyForNew); rotate's after and leastHeld(ready=false) did not.

Fix: standsIn(order, i) marks a fallback row when the plan's first row
is the provider's own. after, leastHeld and readyForNew all skip it, so
a fallback takes a new turn or conversation only when nothing ahead of
it can. Within one turn (tool results) a conversation still stays on
whoever answered, because of sealed reasoning.

Stays: Strict is the user's own choice and is not changed. A
conversation it keeps on the fallback stays there. The trace now names
the provider's ready first row (Affinity.Main), and the Routing page
says why: the provider is ready again, Strict never moves a
conversation, and new conversations go to the provider (en, zh, zh-TW,
ja, de).

Tests (internal/gateway/affinity_fallback_paths_test.go):
- TestRotatingProviderKeepsItsFallbackForEmergencies (1 and 2 keys)
- TestFallbackGivesBackAcrossRoutings: auto, in turn, in turn+session,
  least used+session, stays turn, and a group fallback with auto, in
  turn and session
- TestStrictKeepsTheFallbackAndSaysTheMainIsReady
On the old code, the rotate provider's new turn went to spare-key (Why
new-turn), and in turn+session's new conversation went to the fallback
(Why first). Broken by hand: with after's standsIn removed and Strict's
Main dropped, the rotate test, the in-turn cases and the Strict test go
red. session_spread_test's fallback case pinned the old In turn pick;
it now expects k2.
GUI: routing-affinity-order has a "strict" case.

Run (via mote-run unless noted):
- go test -tags nogui -count=1 -timeout 45m ./... at b08f35fcc (this
  change on 7428f3229): every package ok except two reds, both filed
  and the same on main: internal/gui TestSettingsSaveKeepsWhatItDoesNotSend
  (SearchAll, #4514) and internal/usage TestRequestChunksFromDisk
  (TempDir cleanup, #4390).
- Rebased onto 0fe9f97c1, at this head: go test ./internal/gateway -run
  'Affinity|Rotat|Fallback|Strict|Spread|Turn|Stick|Lead|Order': ok;
  go vet -tags nogui ./internal/gateway: ok
- go vet ./internal/gateway; GOOS=linux and GOOS=windows go vet -tags
  nogui ./internal/gateway ./internal/gui: ok
- gofmt -l: clean
- GUI in WSL (wsl-run), routing-affinity-order, routing-affinity-cache-
  write and i18n-keys in chromium and webkit: 43 of 44. The red is
  i18n-keys' "Unmarked", the same on main (#4524).

Not tried: a real account. This was reproduced with fake upstreams only.
2026-11-01 01:59:59 +08:00
yetone 88a0262bf2 claudetui: Claude Code's first-run notes send the run to -p at once, not after 45s
A config folder whose onboarding isn't done (one only -p was run in,
given CLAUDE_CODE_OAUTH_TOKEN) has the interactive mode show "Security
notes: … Press Enter to continue". The helper knew the sign-in screen
but not this one, so it waited out ReadyWait (45s) before running -p.
Now firstRun is matched like signIn: the run is -p at once and the
start is marked broken. Agreeing to the notes is left to the user.

The match is on the screen's words with any space between them one
(strings.Fields): the real 2.1.316 screen didn't match a plain regexp,
since Claude Code draws some spaces by moving the cursor.

Run:
- mote: go test ./internal/claudetui -count=1 ok; go vet for darwin,
  windows, linux; gofmt clean.
- Broken by hand: with the case off, TestShimFallsBackToPrint/first-run
  notes goes red ("wrote 0 lines of 1 in 30s").
- Real, on xiaomi-gpu (Windows 11), Claude Code 2.1.316 (official dist,
  sha256 checked), a real subscription token, a fresh config folder:
  before, "showed no prompt in 45s" and -p at 48s; with the first regexp
  still 45s (the space case above); now "shows its first-run notes" and
  the -p answer at 7.9s and 16.9s (two runs), streamed.

Not tried: WSL with a fresh folder (same helper code path); macOS/Linux
native with a fresh folder.
2026-11-01 01:43:35 +08:00
yetone 645eb92f3f gateway: a refusal after shown thinking goes to the next fallback
yhwangl on X: a request whose content trips a vendor's safety filter
after the model streamed its thinking, before any answer, stopped there;
the group's next member was never asked, as it is when credit runs out.

When a model's reasoning is shown, a try passes on its first thinking
event, so a refusal after it was the agent's. Now, for a streamed
Anthropic, Chat or Responses request with another member still to ask
(handsOver), the try's events go out one by one (passOver) and a refusal
or refusal error before any text or tool call hands the request on
(handOver): Anthropic's open blocks are closed and the next member's
stream is spliced into the same reply (spliceAfter): its message_start
or response.created/in_progress/queued are dropped, block indexes or
output_index go after those sent, sequence_number goes on. Chat chunks
go as they come. Once text or a call has gone, a refusal stays the
agent's as before. With no other member nothing changes. A refusal is
about the request, so nobody is rested for it.

Zhipu's finish_reason "sensitive" and error 1301 (敏感), DashScope's
data_inspection_failed and Volcengine Ark's *SensitiveContentDetected
are now read as refusals too.

Not covered (#4604): Gemini clients; a Responses reasoning item handed
over gets no output_item.done and the next completed lists only its own
output; A's thinking signature stays in the reply; non-streamed requests.

Run (mote, worktree at base 3baf3b6df):
- go test -count=1 -timeout 45m ./internal/gateway/...: ok (597s)
- targeted -run 'TestRefusal|TestSensitive|TestThinking|TestDeepSeek|
  TestStreamEvent|TestHighRisk|Refus': ok
- gofmt -l internal/: clean; go vet ./internal/gateway; GOOS=linux go vet
  -tags nogui ./...; GOOS=windows go vet ./...: ok
Rebased on 8a410f35a (5 commits, Claude TUI files in internal/gateway):
go vet ./internal/gateway and the targeted run plus ClaudeTUI|
ClaudeSubscription tests ok at the pushed head.
Broken by hand: handsOver forced to false (the old behaviour):
TestRefusalAfterShownThinkingGoesToTheNext (every upstream x client
subtest: b never asked), TestRefusalHandedOverTwice and
TestDeepSeekRefusalHoldsATrustedMemberAgain red; reverted.
Not tried: a real GLM, DashScope or Ark account tripping its filter, and
a real Claude Code or Codex client reading the spliced stream; the tests
use fake upstreams with GLM's, DeepSeek's and Anthropic's event shapes.
2026-11-01 00:40:07 +08:00
yetone 8a410f35a2 claudetui: Claude Code's interactive mode streams its replies, through a preload that copies the main turn's stream
The owner: make a Claude subscription stream as it goes while Claude
Code runs in its interactive mode (TUI), on macOS, Windows and WSL.
Until now the helper read Claude Code's transcript, which has a message
only once it ends, so a reply came to the client whole.

Claude Code is a Bun program, and Bun loads a script named in
BUN_OPTIONS (--preload) before it. The helper writes tap.js to a folder
of its own and starts Claude Code with BUN_OPTIONS="--preload tap.js"
(after the user's own BUN_OPTIONS, but not a Windows one's for a Claude
Code in WSL, where both go through WSLENV). tap.js makes Bun.FetchSession
a subclass whose fetch is the real one's, so the request, its headers,
its connection and TLS are Claude Code's own. For a reply to a
request marked x-claude-code-request-class: main to /v1/messages that
is text/event-stream, it tees the body: Claude Code reads its copy as
before, and tap.js writes each event, as it comes, as a JSON line to
the file MAGPIE_CLAUDE_TAP names. It takes itself out of BUN_OPTIONS,
execArgv and the environment first, so nothing Claude Code runs
inherits it.

The helper reads that file and tells the events as -p's stream_event
lines, so the gateway reads them as it reads -p's. A transcript message
waits up to 1s for its stream to begin (then it's told whole, its late
stream left out); a turn's end waits for its streams to end; a stream
cut short ends with a message_stop and no message_delta, as -p ends
one. The bridge now keeps the streamed messages by id, since a whole
message can come during the next message's stream, and a client
tool_use shown from the stream isn't told again from the whole message.

On Windows, BUN_OPTIONS has no quoting, so a temp path with a space
takes its short name; one that still has whitespace gets no tap, and
replies come whole, as they do from a Claude Code that isn't Bun or
doesn't send through FetchSession (2.1.281 on Windows doesn't; 2.1.289
and 2.1.316 do).

Run:
- gofmt -l: clean. go vet on mote for darwin, GOOS=linux and
  GOOS=windows: 0.
- go test ./internal/claudetui ./internal/gateway on mote
  (-timeout 45m): ok, ok (gateway 654s).
- go test ./internal/claudetui with win-run (Windows 11) and wsl-run
  (magpie-desktop): ok, ok.
- macOS, real account (Claude Code 2.1.316, sandbox HOME, keychain
  token): a reply came as message_start, text deltas,
  content_block_stop, message_delta, message_stop, then the whole
  message, then the result; stderr clean, the tap's folder removed.
- Windows native, Claude Code 2.1.316 against a fake that sends an SSE
  event every 250ms (a user preload marking the request main, which
  also checks the user's BUN_OPTIONS is kept): the deltas came 250ms
  apart, before the whole message. The same with TEMP holding a space
  (short name).
- WSL magpie-desktop, Claude Code 2.1.289 run through wsl.exe from the
  Windows helper, the fake in WSL: the same.
- The scrub, on macOS and Windows: Claude Code's BUN_OPTIONS and
  execArgv have no tap, MAGPIE_CLAUDE_TAP is gone, --smol is kept.
- Rebased on origin/main 02ff0e908 (no file in common): on mote, vet
  for darwin, windows and linux nogui 0; go test ./internal/claudetui
  ok; -run 'CoreScriptBudget|I18n|Claude|Budget' ./internal/gui ok;
  -run Claude ./internal/gateway ok. In WSL claude-mode, account-weight,
  old-webkit and i18n-keys: 59 of 60, the one red i18n-keys' "Unmarked"
  (#4524).

Broken by hand: the told mark removed, TestClaudeTUIStreamedCallToldOnce
went red; streamed kept as the last id only, TestClaudeTUILateRowOfStreamed
went red; before() made a no-op, and settle's end loop removed, the tap
tests went red. Each was put back.

TestTapMessageWaitsForItsStream failed now and then on mote: the whole
message can be told once its stream has begun, before the rest of the
stream is read. It now checks what is promised: the stream begins
before the message, every event is told, and the result comes last
(-count=30 ok).

Not tried: a real account on Windows or in WSL (the keychain token
went missing mid-session; those runs used the fake, whose request
carries no x-claude-code-request-class since a custom base URL drops
it); a real turn of several messages with the client's tools; Claude
Code 2.1.281 on Windows, which doesn't stream and is told whole as
before.
2026-11-01 00:37:29 +08:00
yetone 535371c8f3 providers: a Claude subscription says whether it runs as Claude Code's interactive mode or claude -p, and why
The owner: the Claude Code provider page should say whether its runs go
through the TUI or the CLI, and what tells them apart and what each gains.

Under a Claude subscription's accounts a row now says "Running as
Claude Code's interactive mode (TUI)" (a green dot) or "Running as
claude -p (CLI)" with why: turned off in Settings, failed to start lately, Claude
Code in WSL whose home wasn't found, not installed, or a system with no
interactive mode. Under the TUI it says which requests still run as -p
(safeguards, a JSON schema, an image by URL, a first message over
400KB). "TUI or -p?" opens what each is: entrypoint cli, the plan
counting a request at about half; entrypoint sdk-cli, about twice.
"Change in Settings" opens Settings › Models at the interactive mode's
row. Only switch, which serves nothing, shows no row.

The mode comes from GET /api/claude/mode (gateway.ClaudeModeNow), read
as the editor opens and kept 30s, never in /api/providers' polls. Its
machine-wide reasons are claudeMachineWhy, which claudePrintWhy now
calls first, so the row and the gateway's own choice can't disagree.
The row is drawn by claudemode.js, which app.js loads with that first
read, so it weighs nothing on the core: after a rebase on origin/main
29d0ab39f the core was 1,541,482 bytes, over its 1,539,856, and the
budget isn't raised. "Runs as" became "Running as" so its keys don't
clash with a plugin's "Runs as" in i18n-keys.
A per-account WSL folder the probe can't read is still found only at
run time; the doc says so.

Run:
- go vet ./internal/gateway ./internal/gui (darwin), GOOS=windows, and
  GOOS=linux -tags nogui: 0.
- go test -run 'ClaudeTUI|ClaudeMachine|ClaudeSub' ./internal/gateway:
  ok (TestClaudeMachineWhy is new).
- After the rebase on 29d0ab39f, on mote: go test -run
  'CoreScriptBudget|I18n|Claude' ./internal/gui ok, the budget not
  raised; old-webkit.test.cjs lists claudemode.js with the other
  scripts app.js imports. Before the rebase, go test ./internal/gui: three reds that fail the
  same on origin/main ccc791231: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), TestMainWindowCorners (#3949), and i18n-keys' "Unmarked"
  (#4524).
- claude-mode.test.cjs in WSL (Chromium and WebKit, 1100 and 420, en,
  zh, ja, de): 48 of 48.
- The full GUI suite on mote (load ~30) had 301 reds in 49 files; each
  of those files was run again in WSL at this head (743 tests, 259 red)
  and at origin/main ccc791231 (259 red, the same tests; #4600). The
  one that held apart was account-weight at de web 390: the row puts
  the accounts a screen above By weight on a phone, and Playwright's
  click scrolled the chip back into view. The test now brings the chip
  into view before it measures, so it judges the click's own scrolling;
  account-weight and claude-mode, both engines: 50 of 50.
- After moving the row into claudemode.js: the 142 GUI files with a
  Claude Code agent, in WSL (Chromium and WebKit): 1392 tests, 8 WebKit
  reds in 7 files. Each of those files was run again alone at this head
  and at 29d0ab39f: the same kind of WebKit reds on both, which
  subtests changing from run to run (library-items, number-units,
  routing-rule-models, usage-heatmap, usage-ledger-chart). phone-rows'
  Routing click on .rt-day failed 1 of 4 runs at each (WebKit zh, ja,
  de); the Routing page draws no such row. Filed under #4600, #4471,
  #4112.
- Real use on xiaomi-gpu (Windows 11, sandbox HOME, Claude Code in WSL
  magpie-desktop): /api/claude/mode said {"tui":true,"wsl":true}; with
  the setting turned off through POST /api/settings,
  {"tui":false,"why":"off","wsl":true}; set back, TUI again.
- Rebased on origin/main 02ff0e908 (no file in common): on mote, vet
  for darwin, windows and linux nogui 0; go test ./internal/claudetui
  ok; -run 'CoreScriptBudget|I18n|Claude|Budget' ./internal/gui ok;
  -run Claude ./internal/gateway ok. In WSL claude-mode, account-weight,
  old-webkit and i18n-keys: 59 of 60, the one red i18n-keys' "Unmarked"
  (#4524).

Broken by hand: the editor draws twice before the read returns, and the
test's one-read check went red with two reads until the read in flight
was shared (claudeModeRead).
account-weight's check went red ("en 1000: a click scrolled") with the
chip's click made to scroll the editor 120px.

Not tried: the window on macOS with a real account (the row is the
same code as the web GUI's), and the "broken" reason with a real
failed start.
2026-11-01 00:37:29 +08:00
yetone 2cca111764 gateway: a 413 byte cap or an overflow tells Codex context_length_exceeded, so it compacts instead of reconnecting 5/5 (celestial_eagle_99230 on Discord)
A Codex user on a DeepSeek model kept getting "stream disconnected
before completion: 1017dp: 413 Request Entity Too Large: a web page,
not an API reply ... (request_too_large)" with "reconnecting 5/5".
The big body took the vendor past keepHeldAfter, so Codex's stream
had begun, and streamError sent response.failed with code
server_error. Codex (codex-api sse/responses_error.rs) reads any code
it doesn't know as Retryable, so it sent the same body five more
times. Each was refused the same way, and nothing compacted.
context_length_exceeded is the one code Codex stops on: it marks the
window full and compacts, and core compact.rs trims the oldest items
for as long as the compaction is refused too.

- streamError: a 413 on the Responses shape is code
  context_length_exceeded, for every Responses client. The text still
  says request_too_large for pi.
- failTo: Codex reads a 413 told by HTTP status as UnexpectedStatus,
  and a 400 context_length_exceeded as InvalidRequest
  (api_bridge.rs). Neither compacts. So when Codex (fromCodex, or
  Claude Code's Codex plugin) asked for a stream, a byte cap or an
  overflow goes to it in a stream even before one began
  (keptAlive.compactsInStream). A vendor's own overflow, released
  until now, goes this way too. Other clients keep the status they got
  before.
- Nothing changes for resting: a 413 still rests nobody, and a group
  still tries the next member first.

Tests: codex_byte_cap_test.go. It replays the reporter's nginx page
mid-stream and before the stream, plus a vendor overflow 400, and
checks a non-Codex client keeps its 413. Red on the old code:
TestCodexByteCapInStreamCompacts got "server_error" (the reporter's
exact text), and both TestCodexByteCapBeforeStreamCompacts cases got
a 413 or 400 JSON. TestStreamErrorByteCapInEveryShape now expects
context_length_exceeded for Responses.

Run on mote (mote-run, this tree): go test ./internal/gateway on the
byte-cap, stream-error, overflow, compact and Codex tests: ok. GOOS=linux
and GOOS=windows go vet ./internal/gateway: ok. gofmt -l: clean.
Full suite: mote-run go test -timeout 45m ./... at fb29cd30f plus this
change (before the gateway-routing.md paragraph, docs only): 82 packages
ok; internal/gui red in two tests this change doesn't reach, both filed:
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll not kept, #4514) and
TestMainWindowCorners/macOS_26_SDK (macOS 27 toolbar, #3949).

Not tried: a real Codex against a real 413 vendor. Codex's handling
was read from openai/codex main, not run. DeepSeek documents no
request-body byte limit, and whether 1017dp is DeepSeek's own API or
a relay in front of it is unknown.
2026-10-31 22:57:37 +08:00
yetone c30d3b7b63 plugin pages: a page the reader left is told, and let go after 10 minutes unless it keeps itself
A plugin's page kept its frame, with its scripts, timers and
connections, for as long as the window was open once it had been
looked at: show() only hid its view, and a frame in a hidden view isn't
hidden to itself (its visibilityState doesn't change), so a page
couldn't even pause on its own. Asked by the owner: is that by design?
Only the lazy first load was.

- The kernel's leave hook now reaches the page part: the page is told
  {event: "visibility", data: {visible}} as the reader leaves and comes
  back. The bridge has magpie.visible and magpie.onVisibility(fn); hello
  carries visible, for a page left before it said hello.
- A page left 10 minutes (IDLE_MS) has its frame removed and loads again
  when next opened. Back sooner, it is the same frame. Its hello timer is
  cleared, so nothing says it broke.
- magpie.page.keepAlive: true (plugin.PageSpec.KeepAlive, keepAlive in
  /api/plugin-pages) keeps a page however long, for one that works while
  no one looks at it. Anything but true is false, read as raw JSON so a
  wrong type never drops the package's page.
- plugin-runtime.md's page row says so.

Run on mote. The Go suite and most GUI files ran at this change on
557f51dbf. After rebasing onto 30cd39f19 (none of these files changed
upstream), the budgets, TestWindow* and the page GUI files ran again
at this tree:
- plugin-page-idle (new), plugin-page and plugin-panels, chromium and
  webkit: 14/14 at 557f51dbf. At the rebased tree, the first run was
  13/14: plugin-page's chromium "draws in its frame, shut in" was red
  once, and its assertion wasn't kept (#4589). After that: 42/42 over
  3 runs, then 16/16 chromium over 4.
- i18n-keys, plugin-actions, plugin-kinds-discover, plugin-kernel,
  plugin-replaced, plugin-proxy-page: 51/52. The red is i18n-keys'
  "Unmarked", the same on origin/main e0eb74987 (#4524).
- go test -timeout 45m ./...: every package ok except three reds, none in
  code touched here:
  - TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
    TestMainWindowCorners (#3949) fail the same on origin/main e0eb74987.
  - TestUnroutedHeldReportSaved (#4300) failed in the full run only.
    Alone, -count=5, it passes.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./..., gofmt -l: clean.

Broken by hand: with the leave hook taken out of the page part, the new
test is red in both engines.

Not tried: a real plugin page in the desktop app or WebKitGTK. The
IDLE_MS length (10 minutes) is a judgement, not measured.
2026-10-31 22:39:37 +08:00
yetone fb29cd30f9 tray: the Mac's menu bar figures are regular weight, a lone one in the menu bar's own font (qingnianxiaozhe on X)
Beside Surge's speeds and another app's stacked "0 KB/s", magpie's
"93% / 98%" read visibly bolder, and a lone "98%" too small and too
heavy, so the reporter kept it out of the menu bar. mpRowFont drew two
stacked rows in 9.5pt semibold and one row in 11pt medium, both since
ef4edf8c5 (the first drawn image, no owner call on the weight). Now:

- two rows: monospacedDigitSystemFont 10pt regular (was 9.5pt
  semibold); row gap unchanged (3.5pt), the block 17.6pt as Surge's;
- one row: monospacedDigitSystemFont at menuBarFont(0)'s size (13pt
  on macOS 27, was 11pt), regular (was medium);
- the letter-in-a-ring stand-in for a logo, the template tint and the
  light/dark colours are unchanged. Linux shows the figures as the
  tray's text label (the panel's font) and Windows' tray shows none,
  so neither has a font to change.

Measured in the reporter's q1: magpie's digits were Surge's height
(13px) with stems 1.30x as wide (2.80 vs 2.16px). Rendered at 2x the
stems go 2.47 -> 2.04px for two rows (medium was 2.14; regular is the
closer of the two to Surge and the other app).

TestTrayRowFont (new): two rows 9.5-10.5pt, weight trait <= medium,
digits of one width; one row the menu bar font's size, weight 0, one
width. Red on the old fonts by hand (9.5pt weight 0.30; 11pt weight
0.23 vs the menu bar's 13pt). gui-shell.md says the new sizes.

Run on mote at the pushed head (rebased on origin/main), through
mote-run: gofmt -l internal/gui (empty); go vet ./internal/gui/;
GOOS=linux go vet -tags nogui, GOOS=windows go vet (with and without
nogui) ./internal/gui/; go test -count=1 ./internal/gui/ and with
-tags nogui: all pass but TestSettingsSaveKeepsWhatItDoesNotSend
(#4514, SearchAll) and TestMainWindowCorners/macOS_26_SDK (#3949,
macOS 27), both filed and red on origin/main too; the nogui run also
met TestColdTurnsTaken (#4510, the turn warm-up's race: 1 of 5 red
alone, then a hang to the timeout, at load ~35). Every TestTray* test
passes, run again alone with -v.

Compared visually: a throwaway test rendered the image through
trayImagePNG at 24pt 2x, light and dark, before and after, for two
rows and one, plain and beside a logo, and a mixed pair; laid beside
the reporter's crop of Surge's figures.

Not tried: the live menu bar beside Surge and iStat Menus (no real
app run; renders only), a non-Retina screen, and the full Go suite
and GUI suite (the change is AppKit drawing in one package).
2026-10-31 22:29:48 +08:00
yetone 557f51dbf0 library: a skill linked into an app version the update deleted follows it to the current one (tjhhhh on Discord)
tjhhhh: ego lite keeps its skills in its framework's Versions/<v>. After
the app updated, the skill was in the new version's folder, the old folder
was gone, and magpie still linked the old one. dccfefdf7 (#2635) linked new
imports through the app's own steady link (~/.local/share/ego/ego-skills, or
Versions/Current), but a skill brought in before then links straight to the
resolved Versions/<old> path. tjhhhh's case is that old link: an import
made since dccfefdf7 already follows the update
(TestImportedSkillFollowsAppUpdate).

followMovedSkills (skill_moved.go) runs on every read of the Library page,
under the read's link memo, which is restarted when a link is mended. It
also runs as the first step of every sync. For each library skill that is
a link:
- Target gone, and its first missing part named like a version: link the
  same place under the folder's Current/current/latest link. With no such
  link, use the highest version beside it that has a SKILL.md there
  (1.10 after 1.9).
- Target in Versions/<v> while the bundle's Versions/Current links to
  another version with the same skill: link it through Current.
Source.Dir follows. Only the link is replaced (os.Remove of the link, then
dirLink, and the old link is put back if the new one can't be made). A
folder of the library's own, a link the user deleted that isn't a version
(still shown missing), and the app's old version folder are left alone.
docs/subsystems/library.md says so.

Run (all on mote via mote-run):
- New tests on ego lite's real layout (egoLite: framework Versions/<v>,
  Current, ~/.local/share/ego links): TestOldImportFollowsDeletedVersion
  (0.5.1.13 deleted, then 0.6.0.12, then the next update to 0.7.0.1 by
  itself, plus the agents' link through the library),
  TestOldImportFollowsVersionsCurrent (old kept, through Sync()),
  TestOldImportFollowsHighestVersion, TestMovedSkillsLeaveTheRest and
  TestVersionLess. All pass, as do dccfefdf7's three tests.
- Broken by hand: with followMovedSkills returning false at once, the
  three OldImport tests are red.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./...: clean. gofmt -l: nothing.
- Full go test -tags nogui -count=1 -timeout 45m ./... in a sandbox HOME:
  80 ok, 3 FAIL.
  - internal/library TestReadLooksAtEachFolderOnce was mine: the mend ran
    before the read's memo, so each skill link was looked at twice. Fixed
    (the memo starts first and restarts after a mend). The whole
    internal/library package then passed (75s).
  - internal/gui TestSettingsSaveKeepsWhatItDoesNotSend is red on
    origin/main 3ecc02b78 and ccc791231 alike (#4514, SearchAll).
  - internal/cli TestAgentFieldNameShowsIt failed once under load. It
    passes alone and in a whole internal/cli run, and its message was lost
    to my grep of the log (#4583).
  The full ./... was not run again after the memo fix.
- At the pushed head, rebased on a51776f9c (which changed internal/library
  too): go vet and the whole internal/library package ok (95s).

Not tried: tjhhhh's own machine and ego lite's real update (the layout is
the #2635 fixture, built from iomect's report). Windows junctions to a
deleted version (dirLink is the same call ImportSkill uses). An app that
renames the folder above the version is not followed: it stays missing.
2026-10-31 22:01:45 +08:00
yetone 2cfb8351d0 install.sh: a Linux desktop without WebKitGTK 4.1 has it installed through sudo, then gets the desktop app (shuhai)
shuhai on Discord, on f68ddca37's hint: "为什么不能帮用户直接装好?" On a
desktop without WebKitGTK 4.1 the installer put in the terminal build and
told the user to `sudo apt install libwebkit2gtk-4.1-0` and run it again.

Now, on a desktop without the libraries (and with --gui), when someone is
at the terminal, the script installs WebKitGTK 4.1 (GTK 3 comes with it)
with the distribution's package manager, says first in one line what and
why, and installs the desktop app:
- apt-get install -y libwebkit2gtk-4.1-0 (Debian/Ubuntu family), and when
  that fails, apt-get update and once more (lists missing or stale);
- dnf install -y webkit2gtk4.1 (Fedora/RHEL family);
- pacman -S --needed --noconfirm webkit2gtk-4.1 (Arch family; no -Sy, so
  no partial upgrade);
- zypper --non-interactive install libwebkit2gtk-4_1-0 (openSUSE).
Through sudo, which asks for the password itself; as root, without it.
"At the terminal" is /dev/tty opening (in a subshell, since a failed
redirection would end the script): curl | sh gives the script the pipe
for stdin, so every package command reads /dev/tty too, never the script.
No terminal, no sudo, the package manager missing, Void/Gentoo/another
distribution, or the install failing: the terminal build and the command,
as before, with "didn't work (see above)" when it was tried. --tui and
MAGPIE_CLI=1 install no package; a headless computer neither.
MAGPIE_TTY points the check at another file for the tests.
Docs: reference.md Install, README en/zh, docs start (en/zh/ja).

Run:
- sh -n, dash -n; shellcheck -s sh: only SC2010 at the uninstall's
  ls | grep, there before.
- site/install.test.mjs, 5 new tests (fake sudo, id and package managers;
  every distro's command, root without sudo, no tty, no sudo on PATH,
  Void, NixOS, a failing install, apt's update-and-retry, --gui, --tui,
  MAGPIE_CLI, headless): red on origin/main's install.sh (the 5 new fail,
  19 pass), green after. CI's site step (sh -n + node --test
  site/*.test.mjs) at this head, rebased on origin/main: 63/63 on mote
  (macOS sh) and 63/63 on magpie-desktop through wsl-run (/bin/sh = dash).
- Real installs in fresh containers (Docker on xiaomi-gpu, amd64), a user
  u with sudo, DISPLAY=:0, `cat install.sh | sh` (stdin a pipe), the
  terminal kept with setpriv (su -c starts a session without one),
  v0.1.2399/2400 from the real feed; then ldd (nothing missing),
  `magpie version`, and the package query:
  - Debian 12, sudo with a password, typed by expect at sudo's prompt,
    package lists deleted first: install failed "Unable to locate", apt-get
    update, retry ok, desktop app, libwebkit2gtk-4.1-0 installed;
  - Ubuntu 24.04 (NOPASSWD): libwebkit2gtk-4.1-0, desktop app;
  - Fedora 44, password via expect: webkit2gtk4.1, desktop app;
  - Arch (archlinux:latest): webkit2gtk-4.1 2.54.2, desktop app;
  - openSUSE Tumbleweed and Leap 15.6: libwebkit2gtk-4_1-0, desktop app;
  - Debian 12 as root: apt-get without sudo, desktop app;
  - Ubuntu 24.04 --gui: installed, desktop app; --tui: terminal build,
    nothing installed;
  - Debian 12 without -t (no terminal): terminal build + the apt line, no
    install tried; without sudo at a terminal: the same;
  - Ubuntu 20.04 (no WebKitGTK 4.1 in focal): install, update, retry all
    fail "Unable to locate", then the terminal build and the "didn't work
    (see above)" hint.

Not tried: a real desktop VM (the containers fake one with DISPLAY=:0);
the installed app wasn't opened, only `magpie version`. Void and Gentoo
stay hint-only (Gentoo would build WebKit from source). Debian 11 failed
in the container's own setup (archives unreachable), so focal stood in
for a distribution without 4.1. A held dpkg lock (unattended-upgrades)
would fail the install and fall back; not reproduced. On focal the hint
still names libwebkit2gtk-4.1-0, which focal lacks, as before.
2026-10-31 21:52:54 +08:00
yetone 7d11f7d428 gui: Rex opens sessions in a Rex session of magpie's own, with none, one or several open (#4565, StringKe)
StringKe tried b9e5bc6cb with the real Rex (server 0.0.1793131181,
Rex Beta 0.1.0) on v0.1.2391: it opened only when Rex had exactly one
session. Outside Rex, `rex run` with no -s exits 3 both for no session
and for several ("session target default is ambiguous"), and exit 3
means not found or ambiguous; magpie then ran `rex new <t> --label <t>`,
and `rex new` has no --label (exit 2). run's --label also names the
block, not the tab, and the CLI can't tell which session the app shows.

Now magpie keeps a Rex session of its own, labelled magpie. openInRex
lists sessions with `rex ls --json` and takes the one labelled exactly
magpie (else magpie in another case), by its full ID since labels can be
shared. It runs `rex run -s <id> --label=<t> --json -- /bin/sh -c ...`
and names the new tab with `rex window rename -s <id> -- <window_id> <t>`
from run's JSON. With no such session, or a 3 from run because it ended
since the list, it runs `rex new magpie --window=<t> -- /bin/sh -c ...`,
whose first tab is so named. Labels go as --flag=value and the rename's
positionals after --, so a title starting with "-" stays a title. Exit 4
still says to open Rex. rexRun now gives stdout only (for the JSON), and
rex's stderr comes back through ExitError for the message.
docs/reference.md's Session terminal paragraph says it.

Every flag was checked against the real rex CLI, not the report: the
snapshot build 0.0.1793420730-g6d0d9a (rex-darwin-arm64.zip from
blob.superlogical.com, sha256 checked against the release API) on mote,
in a sandbox HOME and XDG_RUNTIME_DIR, where rex autostarts a server of
its own. `rex new --help`, `run --help`, `window rename --help`; by hand
with 0, 1, 2 sessions and two labelled magpie/MAGPIE: no -s exits 3
"not found: no sessions" with 0 and "ambiguous" with 2; `new --label`
exits 2; `run -s <full id>` works with any number; `-s magpie` with two
so labelled exits 3 ambiguous; `rex new magpie --window=<t>` names the
first tab; rename sets the tab's label.

Tests: TestOpenInRex runs a fake rex modelled on those answers (target
by full ID or any-case label, 3 for not found and ambiguous alike, 2 for
new --label) with no session, one other, two others, magpie's among two
and two labelled magpie, opening twice each: one magpie session made,
then used, both tabs named. Also a session that ends between ls and run,
exit 4 and exit 1. TestOpenInRexReal runs the same cases against the real
rex when MAGPIE_TEST_REX names one (skipped otherwise), with a server of
its own that it kills and stops at the end.
TestDiscoverTerminalsOffersRex uses the fake with two sessions.

Ran, through mote-run at this tree rebased on origin/main f85a221c9:
- MAGPIE_TEST_REX=<real rex> go test -count=1 ./internal/gui: every test
  ok, TestOpenInRexReal included, except TestSettingsSaveKeepsWhatItDoes-
  NotSend (#4514) and TestMainWindowCorners/macOS_26_SDK (#3949), both
  red the same run alone on a detached origin/main f85a221c9.
- gofmt -l; go vet ./internal/gui; GOOS=linux -tags nogui and
  GOOS=windows go vet ./internal/gui and go build .: ok.
- No rex server or /tmp/rx* left after the tests.

Broke by hand, each red, then restored: the old openInRex (run with no
-s, then new --label): every TestOpenInRex case, the discovery test and
TestOpenInRexReal red ("unknown flag: --label"); the session lookup made
to find none: a second magpie session each time, red in the fake and
the real test; the window rename left out: tabs "Window <id>", red in
both.

Not tried: the Rex app itself (its download needs a Discord sign-in),
so whether Rex.app switches to the magpie session when a tab is added
from outside is not seen; nor whether an autostarted CLI server could
differ from the app's when the app is closed. Not the full go test ./...
(only internal/gui changed), no GUI Playwright run (no JS changed), not
run on Linux or Windows.
2026-10-31 21:38:56 +08:00
yetone 73a12e8bf6 wsl: a distro's agent folder that is a link is opened where it leads (#4502)
On Windows, adding a skill or switching RTK on for an agent in WSL failed
with `mkdir \\wsl.localhost\<distro>\root\.codex: Cannot create a file
when that file already exists` (linusxiong). In the distro ~/.codex is a
link to /mnt/c/Users/<user>/.codex. Through \\wsl.localhost Windows can't
follow a link the distro has: a mkdir of it says it exists, and nothing
below it can be made, written, read or listed. ggbdpq found and explained
the link (thanks); their patch, which takes that EEXIST as "there", wasn't
used: the writes below the link fail next (its test passed because a
symlink here is followed).

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

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

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

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

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

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

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

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

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

Not tried: Windows' Desktop (MSIX or classic) and a real gateway request
from Desktop; a signed-in claude.ai cookie (Desktop keeps "1p" then,
which magpie says only with the chooser on); dev_quj's own files, so
this is the class the report is in, not their proven trigger. No other
desktop agent reads a mode the same way; Codex/WorkBuddy checks unchanged.
2026-10-31 21:11:45 +08:00
yetone cac655c14f gateway: GET /v1/magpie/mcp lists magpie's own MCP servers that are on (ferock on Discord)
ferock on Discord: the community chat page's "use all of magpie's MCP
servers" gave a chat only the servers in library.json, never magpie's own
web search, image recognition or image generation. Nothing told an app
which of magpie's own servers are on, so the page couldn't add them.

GET /v1/magpie/mcp (OwnMCPPath, own_mcp.go) answers
{"servers":[{"name","title","path"}]} for the ones on now, each named
as its initialize names it: magpie-web-search while plugins/search serves
and something searches (canSearch), magpie-vision while a model sees
(seer: not Off), magpie-image while a model draws (drawer: not Off),
magpie-tools while plugins/tools serves and a plugin that is on gives a
tool (plugin.ToolsOn; a note that can't be read lists it). It holds no
secret, so a read-only gateway key may read it (readOnlyRoutes); it is
otherwise guarded as every /v1/magpie/* route is. It is in / "apis".
page-chat 0.1.7 (magpie-community/plugins) reads it in every route the
page takes its MCP list from (readMcp: the list, a chat's tools, a tool
call, the connection check). Documented in gateway-routing.md.

Run (mote, at e2a65cbc9 plus this change, before the rebase onto
2987f5e2b, which adds three commits in gateway/gui/provider that this
doesn't touch):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME: 81 packages
  ok; internal/gateway ok. Two reds, neither in code this touches, both
  filed: internal/gui TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll,
  #4514) and internal/update TestRelaunchOpenTriedAgain (#3881).
  The first run, at d6e111638, also had TestReadOnlyKeyEveryRoute red on
  the new route; it is in readOnlyRoutes now.
- At the pushed head (on 2987f5e2b): go vet ./internal/gateway and
  -run 'OwnMCP|ReadOnlyKey|ClientPath|ServingGates' ok.
- TestOwnMCP* (5 tests) red on the old code by hand: the route taken
  out, each answers 404.
- Real binary (go build -tags nogui, sandbox HOME, MAGPIE_ADDR
  127.0.0.1:3591, a fake vendor listing gpt-image-1 and gpt-4o): the list
  was magpie-image; tools/list on its path answered generate_image,
  generate_video, generation_result; with vision and imageGen "off" in
  settings.json the list was empty; a request with a foreign Origin got
  403.

Not tried: image recognition and web search listed by the real binary
(the fake vendor's gpt-4o wasn't known to see offline, and no search API
was set up; the unit tests cover both); a real vendor; the GUI (no GUI
change); Windows and Linux runs (vet only).
2026-10-31 20:37:19 +08:00
yetone e2a65cbc9b dsh: a start on a found group's old id moves onto the id its route lists (zyh6036 on X)
zyh6036 on X: DeepSeek Harness Desktop showed no model after magpie
turned dsh on and the app restarted, while the profile's patch file was
full of magpie's gateway.

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

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

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

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

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

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

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

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

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

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

Not tried:
- The real ChatGPT/Codex app. Nothing here changes when the app-server
  is ended, only what is logged.
- The whole ./... suite and the GUI suite. Neither package touches the
  GUI.
- Whether goto_nozomi's crashes stop on v0.1.2387. #4550 stays open
  for them to say, with the new log line asked for if any crash is
  left.
2026-10-31 19:55:12 +08:00
yetone e484b1e936 provider: an account Codex holds in another of its folders can be removed in magpie (charliepu)
charliepu on Discord (Windows), after v0.1.2385: the account that read no
allowance couldn't be removed. Remove answered "<email> is signed in to
Codex in C:\Users\charl\.codex-db-backup-20260803: sign it out there
(CODEX_HOME=... codex logout) to remove it". That folder is a backup no
Codex runs in. appdir.CodexHomes finds it by name (".codex*" holding an
auth.json), and rememberLogins read its account back at every look, so
forgetLogin refused rather than have it come back.

Now Remove forgets the account and sets that folder's sign-in aside in a
record of magpie's own (codex-homes-removed.json: the folder to a sha256
of its refresh token, or of its access token when it has none).
codexHomeLogins passes over a folder while it holds that sign-in. The
folder's files are left as they are: nothing in it is written, moved or
deleted. A sign-in made
in that folder again (Codex run there, a new token) isn't named by the
record, and is listed again with no step of the user's. With the record
unreadable, which sign-ins were removed is unknown, and no other folder's
account is read that time (accounts saved already stay listed).

Not done: treating ".codex-db-backup-*" folders as not Codex homes by
name. They are found by the same rule as ~/.codex-work, and their
sessions/ are still read for Sessions and usage as before; a name rule
would guess at what a user's folder is for. Removing is the user's own
answer, and works for any such folder.

Run at this head (origin/main 70d50254c plus this change; the doc line
added after):
- mote: go test -timeout 45m -count=1 ./internal/provider ./internal/appdir: ok (provider 142s;
  135s at the earlier base e90a635a9)
- mote: GOOS=windows and GOOS=linux go vet ./internal/provider: ok
- xiaomi-gpu (Windows 11, win-run): go test ./internal/provider -run
  'TestCodexHeldFolderAccountRemoved|TestCodexOtherHome|TestCodexHeldInOtherFolder':
  all four pass
- gofmt -l internal/provider: empty

Broken by hand, each red:
- logins.go as on main: TestCodexHeldFolderAccountRemoved fails with the
  "codex logout) to remove it" refusal, and so does
  TestCodexOtherHomeAccountReadsQuota (its last check pinned the refusal;
  it now expects the removal to go through).
- codexHomeLogins ignoring the record: "removed, then read back from the
  backup folder".
- an unreadable record read as empty: "with the record unreadable, the
  removed account came back".

docs/subsystems/providers-accounts.md's "Codex's other folders" row
said such an account couldn't be removed; it now says what Remove and
v0.1.2385's Sign in again do.

Not tried: the real app on Windows with a real backup folder (the test
runs on Windows with a sandbox HOME); a real account. No GUI change: the
row's Remove posts login/forget as before, which now goes through.
2026-10-31 19:42:52 +08:00
yetone 70d50254cb codex: a change to the model list alone no longer ends the Codex app's app-server
The Codex app crashed and relaunched every few minutes (indekkusu141209
on X, #4550: 08:06, 08:12, 08:26).

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

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

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

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

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

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

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

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

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

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

Not run: the full go test ./... suite. Another session's full suite held
mote, and the owner's rule is to ship without holding for it; it follows
after the push. Not tried: a real ChatGPT/Codex desktop app. Nothing on
the ChatGPT side was changed or measured (the MCP handshake ggbdpq
traced). docs/subsystems/agent-wiring.md was updated.
2026-10-31 19:39:38 +08:00
yetone b9e5bc6cb3 gui: Rex is a session terminal, opened through its rex CLI (#4565)
Rex (com.superlogical.rex) claims no .command file, so Launch Services
never listed it and `open -a` can't hand it a script (StringKe).
Sessions' terminal list now offers Rex when its CLI is found: a native
`rex` on PATH, or one inside a Rex*.app in /Applications or
~/Applications (Rex puts rex on PATH only in its own terminals). Perl's
Rex installs a script named rex too, so only a Mach-O or ELF program
counts. Resume, carry and an agent's Open then run
`rex run --label <title> -- /bin/sh -c '<command>; exec login shell'`:
no shell parses the label or the command on the way. With no session
to add a tab to (exit 3) it runs `rex new`; with Rex's server not
running (exit 4) the error says to open Rex. Rex is then brought
forward with `open -b`. The GUI already lists s.terminalApps, so no
JS changed. reference.md's Session terminal says it.

Parts 2 to 4 of #4565 (accounts run per account, OSC 7501 status,
folder mapping) build on #992, which isn't merged; not done here.

Ran, at this tree on origin/main e90a635a9, through mote-run:
- go test ./internal/gui -run 'TestFindRex|TestOpenInRex|
  TestDiscoverTerminals|TestTerminalOpenArgs|TestAgentOpen': ok.
  TestOpenInRex runs the real sh script with SHELL=/usr/bin/true and
  checks the command ran in its folder, and a label holding $(...) and
  quotes stays one argument.
- go vet ./...; GOOS=linux (-tags nogui) and GOOS=windows go vet and
  go build: ok (at the pre-rebase head; go vet ./... again rebased).
- Full suite, go test -tags nogui -timeout 45m ./..., at the
  pre-rebase head: every package ok but internal/gui, red on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red the same on
  origin/main e90a635a9) and TestColdTurnsTaken (#4510). Rebased,
  internal/gui and internal/provider whole again: red on #4514 only.

Broke by hand, each red, then restored: withRex taken out of
discovery (TestDiscoverTerminalsOffersRex); the exit-3 fallback to
rex new turned off (TestOpenInRex: "rex: Error: no session"); the
native-program check dropped for PATH (TestFindRex took the Perl
script).

Not tried: the real Rex app or rex binary. Its installer needs a
Discord sign-in, so the CLI was driven from Rex's docs only; whether
`rex run` with no -s from outside Rex targets the shown session or
exits 3 is not confirmed. Not run on Linux or Windows (Rex's Linux
build, and the tests skip on Windows). No GUI Playwright run, as no
JS changed.
2026-10-31 19:35:16 +08:00
yetone 01813c681a accounts: switch next takes accounts that are off too, as Use does (#4532)
`magpie accounts switch claude next` (v0.1.2376) took only accounts
switched On. An account the user signed in to themselves, picked up by
rememberLogins, starts off, so next said there was nothing to switch to
while the switch list and the GUI's Use took that same account
(StringKe). On is whether the gateway routes to an account beside the
one signed in, not whether the agent may be signed in to it, so
NextInOrder now takes every switchable account (no token, no home of
its own) that isn't the signed-in one and isn't spent, On or not.
NextLogin, the automatic switch when one is used up, still moves only
to accounts that are On; that is unchanged. reference.md and
providers-accounts.md say so.

Ran, at this tree on origin/main e90a635a9, through mote-run:
- go test ./internal/provider -run 'TestNext|TestSwitch': ok;
  TestNextTakesAccountsThatAreOff (codex and claude: accounts left
  off as picked up; next takes the first, then the second once the
  first is at 99; NextLogin doesn't move to an off one) and
  TestNextInOrder's new cases.
- go vet ./...; GOOS=linux (-tags nogui) and GOOS=windows go vet and
  go build: ok (at the pre-rebase head on 0379f2610; go vet ./...
  again at the rebased head).
- Full suite, go test -tags nogui -timeout 45m ./..., at the
  pre-rebase head: every package ok but internal/gui, red on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red the same on
  origin/main e90a635a9, run alone) and TestColdTurnsTaken (#4510,
  red only in full gui runs). After the rebase internal/provider and
  internal/gui ran whole again: provider ok, gui red on #4514 only.

Broke by hand: put the l.On filter back in NextInOrder.
TestNextInOrder and TestNextTakesAccountsThatAreOff went red ("codex
has no other account in magpie to switch to", wrong picks). Restored.

Not tried: a real Claude or Codex account, or the CLI command end to
end; the tests use sandbox fakes under a test HOME. Nothing here
touches ~/.claude or the Keychain.
2026-10-31 19:35:16 +08:00
JoeyWu-tech bec9df0888 sessions: a provider move leaves a thread a Codex has open (#3751)
#3751's second half; 67b12956 fixed the half about lengths. A Codex
thread moved to another provider, by the Sessions page's Move
(MoveCodexProvider, #887) or as Codex steps off magpie (bringBack's
MoveCodexThreads), has each of its rollouts written whole into a temp
file that then takes its place. The move took no Codex lock and left
alone only a thread written to in the last minute. A Codex that resumed
the thread (the app-server, as run below; a resumed TUI too, by Codex's
source) keeps its rollout open to append to for as long as it has the
thread, so what it wrote after a move went into the file the rename had
put aside: a turn the upstream answered was in neither the rollout nor
what Codex sent after its next resume.

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

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

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

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

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

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

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

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

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

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

At the pushed tree (rebased on origin/main 7e0fe83d4), macOS (mote):
gofmt clean; go vet darwin, GOOS=windows and GOOS=linux -tags nogui for
sessions ok; go test -tags nogui ./internal/sessions ./internal/agent
ok; -run Budget ./internal/gui ok.
2026-10-31 18:52:01 +08:00
yetone 7e0fe83d4b provider: Listed as works for signed-in accounts and plugins (zeewell on X)
zeewell asked to list SuperGrok's grok/grok-4.6@500k as grok-4.6, and
Cursor, Devin and WorkBuddy models (all plugins) under ids of their own.
v0.1.2345's "Listed as" took ids only for key/relay providers
(takesModelIDs was p.Account == nil).

Why the restriction was there: the wire rewrite (Settings.Wires) turns
the request body's model back into the own id, but some code reads the
model by the vendor's id before that and got the listed one:
- plugin model lookup (pluginModel: the plugin's APIs, tiers, prices);
- the Claude subscription run (--model given to Claude Code);
- Code Assist/Antigravity variant choice (codeAssistBody, SentNameOnIn);
- account plan lists (fallback's Account.Lists, effort Levels/Tiers,
  AccountServes);
- moveModelRefs refused a provider with no providers.json entry, which
  is every plugin and account provider until a pick is set.
Each now translates with OwnModelID / the provider's ModelIDs, so the
upstream request still carries the vendor's or plugin's own id. Only a
decide-only provider refuses an id. The GUI box already follows
TakesModelIDs, so no GUI file changed.

Tests (red on the old code, each fix reverted by hand one at a time):
- TestModelIDRefused, TestModelIDAtAnAccount (takesModelIDs,
  AccountServes, SentNameOnIn);
- TestLocalModelIDAtAPlugin (Bun fake plugin: /v1/models, upstream
  path, X-Plugin-Model, body, usage; red on pluginModel and on
  moveModelRefs);
- TestLocalModelIDAtAnAntigravityAccount (codeAssistBody);
- TestLocalModelIDAtAClaudeAccount (claude got --model my-sonnet);
- antigravity pool test (fallback Lists, Levels).

Run on mote: gofmt clean; go vet darwin/linux/windows ok; go test
-tags nogui -count=1 -timeout 45m on internal/provider, gateway, cli,
gui, settings, access, usage, plugin: all ok except internal/gui's
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll), red on main since
b09349d17 and filed as #4514. After rebasing on 140efc8f7 (nothing new
under provider/gateway) the ModelID/LocalModelID/Antigravity tests
ran again: ok.

Real accounts, sandbox HOME, dev build on 127.0.0.1:3486: magpie model
id set grok/grok-4.6@500k -> grok-4.6, grok/grok-4.5@500k -> g45big,
cursor/composer-2.5 -> my-composer, devin/swe-2 -> my-swe,
workbuddy/deepseek-v4.1-flash -> ds-flash. /v1/models listed the new
ids. Requests for grok/grok-4.6, grok/g45big, cursor/my-composer and
devin/my-swe each answered 200 "pong", served as the vendor's id
(grok-4.5-build for g45big); usage records the listed id as model.
Plugin tokens were not rotated (no diff with live).

Not tried: WorkBuddy's real request (its own sign-in answers 401,
unrelated); the GUI box not clicked; no full ./... suite, no GUI suite
(no GUI file touched).
2026-10-31 18:38:31 +08:00
yetone d8cf4f74f9 plugins: a plugin's package.json names its row with magpie.name (#4558, MYCF711)
A plugin installed from git whose package.json says
"magpie": { "name": "华为云 HUAWEI" } read as its dependency key
(magpie-officeace) on Settings → Plugins. Bun takes no non-ASCII key, so
a package outside the community's list had no way to show a readable
name. magpie.name was never read at all: #3608's route (MYCF711's branch
1cc33700) didn't reach main, so no release has it, git or npm.

plugin.InstalledName reads magpie.name from the installed package's own
package.json, beside magpie.icon (installedOwn, one parse for both): one
line of at most 80 bytes, no control or format characters (a bidi
override would show it as another name), else nothing. /api/plugins gives
each row it as ownName, and plugins.js's shownName takes it after the
community list's name and before the git package or the spec, so a
listed package is still named by the list. The row's page, the "is up to
date" status and every message that names the row (options, prefer, Update
all) go through shownName; a page plugin's sidebar tab takes it when the
page names no title (windowParts). It is never used to resolve a name and
never shown with the community badge. Not changed: the CLI's plugin list
(the dependency key, as the reporter expects), Discover's cards for
uninstalled GitHub/npm packages, and magpie.summary. Documented in
docs/reference.md and site/public/docs (en, zh, ja).

Run:
- mote: go test -timeout 45m ./internal/plugin/ ./internal/gui/ — plugin
  ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  the AppKit window tests killed at their deadline (TestPanelCloseHidesIt,
  TestPluginPageLoadsItsFilesInTheWindow, TestMainWindowCorners, …;
  #4125, #2645). The first three run the same red on origin/main 7aa67e9e5.
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  internal/plugin and internal/gui: clean. gofmt -l internal/: nothing.
- wsl-run (magpie-desktop): plugin-own-name.test.cjs, Chromium and
  WebKit, en/zh/zh-TW/ja/de at 980 and 420: 22/22. Every plugin*,
  plugins-*, agent-plugin*, account-plugin*, signin-paste-plugin,
  sidebar* and i18n-keys file (67): all green but i18n-keys "a plugin's words are its own" (#4524), plugin-card-update webkit en/zh (#3079) and plugin-github-filter webkit ja 420px (#4564, filed now), each red the same at origin/main 7aa67e9e5
- Rebased on origin/main 7b883cc61, mote: -run "Budget|OwnName|TestPluginsState|
  TestWindowParts" on internal/gui and internal/plugin: ok (core scripts
  under the budget, no raise).

Broken by hand:
- InstalledName returning "": TestPluginsStateGivesAGitPackagesOwnName red
  (ownName "", and the sidebar title magpie-officeace).
- shownName without e.ownName: plugin-own-name.test.cjs red, the row
  reads 'magpie-officeace'.

Not tried: the desktop window itself, and a real git repository with
magpie.name (the fixture is shaped from the reporter's installed
package.json: name magpie-officeace, version 0.2.4).
2026-10-31 18:30:39 +08:00
yetone 64cdb68035 accounts: import claude reads claude-swap's export (#4532)
StringKe (#4532) is moving from claude-swap (cswap 0.29.0) to magpie,
and `magpie accounts import claude` didn't read cswap's export. It does
now: parseLoginImport takes cswap's format-1 envelope ({version: 1,
swapVersion, encrypted, accounts: [...]}, read from cswap 0.29.0's
transfer.py) and cswapEntry reads each account's
credentials.claudeAiOauth and config.oauthAccount: email, account and
organization uuid, and the organization's name. The tokens are kept as
the file has them; magpie asks Anthropic nothing.

Refused, each with what to do: an encrypted export (decrypt with gpg -d
first), another format version, a Codex entry, and an API-key entry
(added as a key instead). An entry with no refresh token is accessOnly,
as for every other file. cswap's alias becomes the account's name in
magpie (importNames) when the account was added or updated, has no name
yet, and no other account is called that or signed in as it, so the
name stays a selector for one account (the previous commit's rule).

testdata/cswap_0.29.0_export.json is claude-swap 0.29.0's own `cswap
export` output, made from its source in a sandbox HOME in WSL with two
accounts and fake tokens (cswap's add step asked Anthropic once with
the fake refresh token, which it called dead; no real account was
involved).

Run (mote unless said):
- At this commit's tree (on origin/main 47173f593):
  gofmt -l clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows
  go vet ./... ok; go test -timeout 45m ./internal/provider (ok 100.7s),
  ./internal/cli (ok 31.8s), ./internal/gui: red on 11 real-window
  AppKit tests killed at their deadline on mote over ssh (#4125, #2645)
  and TestSettingsSaveKeepsWhatItDoesNotSend's SearchAll, red on main
  (#4514); none touches accounts.
- Rebased on origin/main 7aa67e9e5 (4 commits, none in accounts), then
  at the pushed tree: go test ./internal/provider (ok 163.5s),
  ./internal/cli (ok 55.8s), ./internal/gui -run 'Budget|I18n|Key'
  (ok), gofmt -l clean.
- TestImportCswapExport, TestImportCswapRefusals. Broken by hand, each
  red: no cswapEntry, no importNames, the taken-name check off (red on
  "the team seat took pro's name"), the encrypted check off, no
  organization name.
- CLI in a sandbox HOME in WSL: import of the fixture adds max@x.com and
  team@x.com, a second import says both are in magpie already, the alias
  "work" is team's name, `accounts forget claude work` picks it;
  `accounts import --help`, a missing file and an unknown agent each say
  what's wrong.
- On mote over ssh the same import added one account and failed the
  other on the Keychain ("Unable to obtain authorization", no GUI
  session there), and the failed one was still saved, so the second
  import called it "in magpie already". That's addLogin writing
  logins.json before signing Claude Code in, the same for every import
  and sign-in, not this change; not changed here.
- GUI: login-import in Chromium and WebKit on Linux (WSL), green.

Not tried: an export from a real cswap install with real accounts,
Claude Code running on an imported account, or cswap's encrypted export
decrypted and imported. A cswap account's plan (subscriptionType) isn't
carried: magpie reads it on the first usage read, as for CLIProxyAPI.
2026-10-31 18:22:02 +08:00
yetone a7b47d57ec accounts: removing the account Claude Code is signed in to switches it to another first (#4532)
StringKe (#4532): removing the signed-in Claude account was refused with
SignedInError, while Codex's switched away first. ForgetLogin now does
the same for Claude Code: nextOnForget picks another account (on first,
then one whose sign-in holds), SwitchLogin signs Claude Code in to it,
and only then is this one forgotten. If that switch fails, nothing is
removed and the error says why.

nextOnForget leaves out accounts Claude Code or Codex can't be signed in
to (switchable: not a setup-token account, not a Codex account held in
another folder). Claude Code is never signed out: when the account is
the only one it can be signed in to, it is kept, with
SignedInError{Only} (GUI code signed_in_only), which says to add another
account first or sign out in Claude Code. The GUI gives the signed-in
Claude row a Remove when another account it can use exists, and no
Remove or Sign out otherwise. Claude Code's own credential is never
deleted; forgetClaudeDir removes only the forgotten account's own
folder and its folder's Keychain item, and claudeHolders' check of
other records holding the same token is unchanged.

Tests: TestForgetLiveClaudeSwitchesFirst, TestForgetOnlyClaudeIsKept
(replacing TestClaudeInUseStillRefused, which held the old refusal);
codex-signout.test.cjs gets three Claude cases (Remove with another;
only + setup-token: no Remove, reason in zh/zh-TW/ja/de; the
signed_in_only refusal in en/zh).

Run (mote, sandbox HOME through the test helpers):
- go test ./internal/provider ./internal/cli, vet and gofmt at the
  stack head: in the next commit's body (one tree, same run).
- Broken by hand, each red: Claude not switched first
  (TestForgetLiveClaudeSwitchesFirst), Only left false, a setup-token
  account counted as another, nextOnForget unfiltered
  (TestForgetOnlyClaudeIsKept).
- GUI on Linux (WSL magpie-desktop), Chromium and WebKit: codex-signout,
  own-signin-remove, saved-signedout-remove, login-import, claude-signin,
  account-alias and i18n-keys all pass but i18n-keys' "a plugin's words
  are its own", red on main (#4524). On mote, codex-signout passed in
  Chromium; its WebKit launches were killed with mote at load ~25 under
  other sessions' suites (#4125), so WebKit's record is Linux's.

CLI in a sandbox HOME (WSL, file credentials): forget of the signed-in
account by its name switched Claude Code to the other (.claude.json then
says max@x.com); forget of the only one was refused with the message
above and left it signed in.

Not tried: a real Claude Code switch on removal with real accounts, or
in the CLI against a live ~/.claude (sandbox only).
2026-10-31 18:18:37 +08:00
yetone 149e763e9e accounts: a name you gave an account picks it wherever an email does (#4532)
StringKe (#4532): `magpie accounts switch claude work` failed when "work"
was the alias; accountNamed matched the email only.

provider.AccountByName resolves a name (magpie accounts alias) among an
agent's accounts. It refuses a name two accounts share, and a name that
is another account's email or email part, so a name never picks the wrong
account. It is used by:
- accountNamed: accounts switch/on/off/remove/alias/cap and the rest
  that take <email>;
- provider pool --accounts;
- accountRef (GUI and account-cap): the exact email first, then a name,
  so another account's alias never shadows an email;
- account-cap's display, through AccountRefOf (it filtered by email).

Run (mote, at this commit):
- go test -timeout 45m -count=1 ./internal/provider ./internal/cli: ok
  (104.9s, 33.2s).
- TestAccountsAliasPicksTheAccount, new: switch, alias, pool --accounts
  and account-cap by name; a shared name and another account's email
  refused. Red with each part removed by hand: the accountNamed call,
  pool's resolution, the clash check, the shared-name check, accountRef's
  name step.

Not run: the GUI suite (no GUI file changed); real accounts.
2026-10-31 18:18:37 +08:00
yetone 15b83901ac accounts: switch to the next account with room, or the one with the most left (#4532)
StringKe (#4532), comparing magpie with cswap 0.29.0: there was no "switch
to the next account", and when every account was past its line the
automatic switch stayed on the spent one, where cswap moves to the account
with the most room left.

- `magpie accounts switch <claude|codex> next` (provider.NextInOrder) takes
  the other accounts that are on in magpie, from the one after the account
  the agent is on, wrapping round: the first whose allowance is known and
  has room, else the one with the most room left, and says it is past its
  line. A saved Claude account not read yet is read first (readSpare), as
  the automatic switch's spares are. With no reading of any it refuses
  rather than guess; for any other agent it asks for the account by name.
- NextLogin (shared by Codex and Claude Code): when the account the agent
  is on is spent and every spare is past its line too, it moves to the
  spare with the most room left (roomLeft: the fullest stopping window's
  distance below the switch share, or the account's own cap when lower),
  when that has at least roomMargin (1 point) more than the one it is on,
  so two all but even accounts don't trade the agent each look. A held,
  failed or unknown reading is never moved to. One model's own window
  still counts for nothing, as before.
- docs: reference.md (the automatic switch and `next`; its "a Claude
  account magpie knows nothing of is not moved to" was stale since
  readSpare), providers-accounts.md's Used-up switch row, the en/zh/ja
  start pages' command table, `magpie help`.

Run (on mote, sandbox HOME through the packages' TestMain):
- go test -timeout 45m -count=1 ./internal/provider ./internal/cli: ok
  (144s, 44s), at this change's tree before the next commit's edits.
- TestNextLoginTakesTheMostRoomWhenAllArePast and TestNextInOrder, each
  over codex and claude with three accounts: green; red with the fallback
  taken out of NextLogin (the two "most room" cases, both agents) and with
  NextInOrder not starting after the signed-in account ("the one after
  it", both agents). The "none has more by the margin" case fails without
  roomMargin.
- Built the nogui binary and ran in a fresh sandbox HOME on mote:
  `accounts switch claude next --help` (prints the accounts help),
  `switch claude next` and `switch codex next` with no accounts ("has no
  other account that is on"), `switch gemini next` (asks for a name),
  `switch claude nxt` (no such account), `switch claude` (usage).
- gofmt -l clean. Cross-OS vet: run at the head of this stack.

Not tried: a real switch between real Claude or Codex accounts; the CLI
`next` with real saved accounts (the provider tests cover the choice).
2026-10-31 18:18:37 +08:00