Commit Graph
7089 Commits
Author SHA1 Message Date
ggbdpq 6b4a6dcd41 claudetui: the Bypass Permissions disclaimer is answered as the trust question is (#5042, luzhuang)
A claude magpie spawns runs --dangerously-skip-permissions: the flag is
on the bridge's own arguments, a user's claude may be a wrapper that
adds it, and an account's default mode may be Bypass Permissions. Where
no settings source the run reads has skipDangerousModePermissionPrompt,
Claude Code 2.1.295 blocks on its disclaimer — "❯ No, exit / Yes, I
accept, Enter to confirm" — and no one was there to answer it: each run
sat on the dialog for 45s (ReadyWait), ended, and the next run asked
again, so interactive requests failed in a loop (502 or a hung restart)
until magpie fell back to claude -p.

- the helper tells the disclaimer yes where TrustEnv says so, with the
  same ↓-until-"Yes"-then-Enter the trust question gets (its "No, exit"
  pairs the same, and a key sent as it is first drawn is lost the same
  way); Claude Code records the acceptance itself, and the next run is
  shown none of it.
- where TrustEnv isn't set — the account Claude Code is signed in to, in
  a caller's folder — the disclaimer is the user's to answer: the run
  ends at once saying so, not after 45s.
- a disclaimer left unanswered at a run's deadline is named as such
  ("asked to accept running in Bypass Permissions mode, not answered"),
  never "showed no prompt".

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

Reviewed and ported, narrowed: as written, the shim accepted the
disclaimer wherever TrustEnv was set, and the bridge sets TrustEnv for
magpie's own folder in the account Claude Code is signed in to
(configDir ""), as do the warmup and /usage runs. Accepting there makes
Claude Code write skipDangerousModePermissionPrompt into the user's own
~/.claude/settings.json, a consent for every run after that is the
user's to give. Now a separate claudetui.BypassEnv says yes, set only by
claudeBypassEnv for a tui run in an account folder of magpie's
(configDir != ""), at the bridge and both warmup sites; TrustEnv alone
ends the run at once with the "asks to accept" message. The subject's
"as the trust question is" holds for the keys sent, not for where.

On mote, with tui.go at the parent: TestShimAcceptsBypassDisclaimer FAIL
("the shim wrote 0 lines of 3 in 30s"), TestShimNeverPrints' bypass
cases FAIL ("neither answered nor ended in 30s"),
TestShimEndsAtItsCallersDeadline/bypass_disclaimer_unanswered FAIL
("showed no prompt"); green with the patch. Broken by hand: the gate
back on TrustEnv turns TestShimNeverPrints/bypass_disclaimer_with_the_
folder_trusted red, and claudeBypassEnv ignoring configDir turns
TestClaudeBypassOnlyInMagpiesAccountFolder red ("user's own account: got
[MAGPIE_CLAUDE_TUI_BYPASS=1]"). go test -timeout 45m ./internal/gateway
and ./internal/claudetui ok; GOOS=linux/windows/darwin go vet ok. Not
tried: a real Claude Code 2.1.295 showing the disclaimer under a saved
account (needs a wrapper adding the flag).

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:17 +08:00
ggbdpq 72abde0e0d steady: a served write reaps the stale temps earlier writes left beside the file (#4938)
What changed: steady.WriteFile, on a write that went through, removes
the temp files a crashed or failed write of the same file left beside
it - its own .<file>.<digits> shape and edit.WriteAtomic's
.<file>.<digits>.tmp alike, both old enough (10 minutes) to belong to
no write still going on, and only ones whose remainder is digits, so
another file's temps (.models.yml.bak.1.tmp is models.yml.bak's) stand.
edit.WriteAtomic reaps through the same function: one reaper, both
shapes, every folder magpie writes its own files in. Nothing reaped a
steady temp before - edit reaped only its own .tmp shape - so a
multi-instance start-up exiting mid-write (the reaping exists beside
each write, and nothing swept) left hundreds beside magpie's own files
over a run, and every O_EVTONLY descriptor the directory watcher holds
per file with them (#4938 Bug 1: 758 temps, 839 descriptors). A write
younger than the ten minutes stays, as another write may still be on
it; a stalled write that loses its temp here fails its rename and
leaves the file as it was.

Bug 2 beside this one is yetone's b295d1196 (v0.1.2785); Bug 3 stays
open.

Run:
- go test ./internal/steady -run TestWriteFileReapsStaleTemps -count=1
  RED before (the .123 and .789.tmp temps a write leaves behind stay),
  green after: this package's shape and edit's reaped, a younger one
  and another file's stay.
- go test ./internal/edit -count=1, ./internal/steady -count=1: ok.

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

Reviewed and ported: a follow-up to b295d1196 (Bug 2), not a duplicate.
On mote, with steady.go and edit/file.go at the parent:
TestWriteFileReapsStaleTemps FAIL (".quotas.json.123: stays true, want
false", ".quotas.json.789.tmp: stays true, want false"); green with the
patch. go test ./internal/steady ./internal/edit ok on mote and on
Windows (win-run); GOOS=linux/windows/darwin go vet -tags nogui ok.
Not reaped (siblings, not in this change): plugin-auth.json's
.tmp-<pid> temps and gemini_sigstore's .tmp-* shape. Bug 3 (CPU) stays
open. Not tried: a real multi-instance start-up on the reporter's Mac.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:17 +08:00
ggbdpq 38c3ba846f library: an edit made in the shared copy of a skill is taken into the library (#4958)
What changed: takeEdits reads the shared copy too - ~/.agents/skills
where no link could be made (Windows without the right to), the entry a
marked copy - as it reads an agent's copy: anything newer than the
copy's mark is an edit, the newest one taken unless the library changed
after it, losers kept aside. An agent whose own folder ~/.agents/skills
is has its copy read as it was; the shared scan only runs where no
target already covered that folder. syncShared, which sets a stale copy
aside before copying again, runs after, so the edit is in the library
and every other agent's copy first.

Run:
- go test ./internal/library -run TestEditInSharedCopyTaken -count=1
  RED before: the edit wasn't taken (the library's skill has no
  notes.md) and the shared entry lost it; green after.
- go test ./internal/library -count=1: ok (66s).
- gofmt, go vet -tags nogui (darwin/linux/windows), builds
  (darwin/linux/windows), the new test with -race: clean.

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

Reviewed and ported: differs from 1851ead1a, which handled an agent's
own copy; the shared ~/.agents/skills copy (Windows' marked copy where no
link can be made) was still overwritten by syncShared. On mote, with
skill_edits.go at the parent: TestEditInSharedCopyTaken FAIL ("the edit
in the shared copy wasn't taken into the library", "the shared entry
lost the edit"); green with the patch. go test ./internal/library ok on
mote, and TestEditInSharedCopyTaken ok on Windows (win-run, xiaomi-gpu).
GOOS=linux/windows/darwin go vet -tags nogui ok. Not tried: the real
GUI's "Put skills in ~/.agents/skills" on Windows with a real agent.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:17 +08:00
ggbdpq db9d6a6107 gateway: a working-directory line a turn quotes is no caller's word, and a --bare run's CWD: is read (#4940)
What changed: workPlace reads the folder in two layers, as
clientNamedWorkPlace does. The caller's own layer - its instructions and
its {role: "system"} messages - is read whole: Claude Code's
" - Primary working directory:", a --bare run's "CWD: /x", pi 1.1's
"Current working directory:", Codex's and pi's <cwd>, OpenCode's <env>.
A turn of the conversation is read only for the forms a caller states in
one - <cwd>, <env>, and Claude Code's <system-reminder>, which says a
folder it moved to; a line a user message quotes ("Primary working
directory: /x" alone on its line, WardLu's P3) no longer names the
folder for a group's rule by folder, nor goes to a plugin's provider as
its WorkDirHeader. The last said still goes, wherever it sits: an agent
that moved says so after. The forms are workdir.go's own, wrapper-scoped
as the routing face pinned them; the bridge's clientNamedWorkPlace is
untouched.

Run:
- go test ./internal/gateway -run 'TestWorkDirTurnQuote|TestWorkDirBareCWD|TestWorkDirMoveReminder|TestTellWorkPlaceTurnQuote' -count=1
  RED before (the quoted line named the folder; CWD: named none), green after.
- TestWorkDirOfEachAgent, TestWorkDirOpenCode, TestWorkDirLastSaidAndOnlyByTheAgent,
  TestRuleByFolder unchanged and green - the agents' own shapes and the
  move reminder keep working.
- gofmt, go vet -tags nogui (darwin/linux/windows), go build -tags nogui
  (darwin/linux/windows), the new tests with -race: clean.

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

Reviewed and ported: not superseded by b9a45f59e, which fixed the
bridge's clientNamedWorkPlace and named workDirIn as the sibling left.
On mote, with workdir.go and the docs at the parent: TestWorkDirTurnQuote
IsNotTheCallerWord FAIL ("a quoted line in a turn overrode the caller's
own: /Users/me/quoted"), TestWorkDirBareCWD FAIL ("a --bare run's CWD:
is not read"), TestTellWorkPlaceTurnQuote FAIL (the plugin is told
%2FUsers%2Fme%2Fquoted); green with the patch. go test -timeout 45m
./internal/gateway ok, GOOS=linux/windows/darwin go vet -tags nogui ok.
Fixed: workdir.go was not gofmt-clean (the piDir alignment); gofmt -w
applied. Not tried: a real agent's request through a group's rule by
folder.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:17 +08:00
ggbdpq e7948e2484 agent: a routing group with a Claude member tells Pi its cache keeps five minutes (#5037)
Pi's cacheWarming weighs a model by its promptCache and stops with
"cache lifetime unavailable" without one. magpie declared it only where
piPromptCache saw the entry's own api — anthropic-messages for a Claude,
openai-responses for a GPT — and a routing group has no api of its own
(a Messages-only group stays on Chat, allResponses), so auto/claude-*
went out with none and Pi never warmed the group's cache, while the
cache itself was there: on the Chat path the gateway marks its own
translation to a Claude member ephemeral for five minutes (addedMark).

So the group now derives the field from its members: one asked on
Anthropic's Messages by its own provider, and the entry declares the
five minutes the gateway's own marks keep. long stays out — the gateway
marks an hour only where a session's turns are often far apart, so it
isn't always true — and a subscription's Claude (asked through Claude
Code, which caches on its own) still declares none, as before. An
all-Responses group keeps what it had: its entry's own api answers.

Reviewed and ported: every line read against origin/main 1b0340fdb.
The added branch runs only for a native entry with no api, and only
when GroupFinder knows the id as a group; a Claude subscription member
answers Native "" and adds nothing, so its group stays as before. On
mote (mote-run): with agents.go put back to origin/main,
TestPiGroupPromptCache FAILs with "group/auto: promptCache <nil>, want
{short: 300}"; with the change, ok, and the rest of TestPi* ok. go vet
(darwin, linux, windows, -tags nogui): ok; gofmt -l clean.
The three packages (provider, agent, gateway) with all three ports: ok.
Not tried: a real Pi run warming a group's cache. A group whose
Anthropic-protocol member is not a Claude (a vendor's Messages
endpoint) also declares five minutes; the gateway marks those
requests ephemeral too.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:17 +08:00
ggbdpq 0d14aa4d08 gateway: a model the vendor lists after the codex picks were saved still reaches the desktop catalog (#5062)
What changed
- CodexNativePicked built its keep-set from p.Models, the account list
  frozen at the moment the user last picked - so a model the vendor
  began listing afterwards (gpt-6.1-terra, the reporter's case) was
  excluded from the desktop catalog the gateway writes for Codex
  Desktop's model_catalog_json, and the picker could not see it even
  though the gateway's own /v1/models served it. The keep-set now comes
  from p.Picks(): the picked ids stay picked, and anything the vendor
  lists since is kept beside them.

Run
- TestCodexDesktopCatalogKeepsNewlyListedBesidePicks on a3768cdd1-era
  product (reverted, tests kept): FAIL - the newly listed model was
  dropped from the catalog; with the fix: ok. gofmt clean; vet -tags
  nogui (provider+gateway) clean.

Reviewed and ported: every line read against origin/main 1b0340fdb.
Picks is what magpie's own catalog (/v1/models) serves for the codex
provider, so the desktop catalog and /v1/models now agree; a model the
user left out of a full list stays out (withNewlyListed). On mote
(mote-run): with codex_models.go put back to origin/main,
TestCodexDesktopCatalogKeepsNewlyListedBesidePicks FAILs with "the
account's own models beside the picks: [gpt-6-sol]"; with the change,
ok. The test's backend is httptest; no network. go vet (darwin, linux,
windows, -tags nogui) of the touched packages: ok; gofmt -l clean.
The three packages (provider, agent, gateway) with all three ports: ok.
Not tried: a real ChatGPT account and the Codex app's picker.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:17 +08:00
ggbdpq 8d94e3a38f codex: Ultra on GPT-6.1 Terra wherever it is served (#4909)
Codex's catalog (models-manager/models.json, as this machine's Codex kept
it in models_cache.json) now lists ultra on gpt-6.1-terra, alongside the
Sols, Astra and GPT-5.6 Terra; the Lunas still stop at max. magpie's list
of the models that offer it (#656) had no GPT-6.1 Terra, so one served by
another vendor (Copilot's, a key's, a relay's) was listed up to max only,
and Codex had no Ultra to pick on it — a thread pointed straight at the
vendor (CC Switch's config) sends its own effort and keeps Ultra, a
magpie-routed one was offered none. Now GPT-6.1 Terra is in the list: an
entry for it that reaches max gains ultra, in Codex's catalog and
/v1/models, and says multi_agent_version v2; a request's ultra still goes
to the model as max (fitEffort), as before.

TestUltraOnModelsThatOfferIt extends its table with gpt-6.1-terra (by the
id a vendor serves: relay/… too) and an entry for Copilot's, and fails on
the old code with OffersUltra("gpt-6.1-terra") = false and the entry left
at [none low medium high xhigh max] v2=false. go vet, builds (darwin,
GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 on the touched
packages pass.

Fixes #4909

Reviewed and ported: every line read against origin/main 1b0340fdb.
Codex 0.165.0's own bundled catalog (the binary's models.json) lists
gpt-6.1-terra with low..max and ultra, as it does gpt-6.1-sol, so the
list follows Codex's values. On mote (mote-run): with ultra.go put back
to origin/main, TestUltraOnModelsThatOfferIt FAILs with
OffersUltra("gpt-6.1-terra") = false and copilot/gpt-6.1-terra:
[none low medium high xhigh max] v2=false; with the change, ok.
go test -tags nogui -timeout 45m of internal/provider, internal/agent
and internal/gateway together with #5062 and #5037 (one run, logged): ok (provider 192s,
agent 463s, gateway 1041s). go vet -tags nogui of the three packages for darwin,
GOOS=linux and GOOS=windows: ok; gofmt -l clean.
Not tried: a real Copilot or relay GPT-6.1 Terra asked at ultra.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:17 +08:00
ggbdpq 8daab00a2e gateway: a completion call Antigravity's model wrote into its text goes out of the history, the answer it repeated staying (#5091)
What changed
- buildCodeAssistSent (internal/gateway/codeassist.go) hands an Antigravity
  request's history through dropPseudoCalls (internal/gateway/textcalls.go).
- dropPseudoCalls rewrites a model turn only when nothing structured is in
  it, a whole call written out in its text is there — of a tool the request
  offers, its arguments readable by the readers Chat replies already go
  through (<tool_call>'s JSON and pairs, an invoke with its parameters),
  closed — and the text after it says the call's result again, up to
  punctuation, spacing and case. The turn then goes upstream as that text
  without the call. msgs is not changed: a fallback builds from the same
  request.

Why
- #5091 (Phoenix12580): gemini-4-argon deep in a long session wrote the
  completion call it meant into its reply's text — the report's two-sided
  SSE capture shows every part Google returned is text, none a
  functionCall — so the client ran nothing and read the call's arguments
  as the answer's lead. The turn came back in the history as that text,
  and every later turn read its own wrapper back and wrote the next one
  the same way; clearing such turns from the history restored normal
  calls in the report's own controlled try.

Not changed
- A reply that carries its call as text still streams as it came: the
  report asks for no call read out of a live reply, and none is made.
- The gemini and vertex requests keep their histories as they came; the
  report is the Antigravity route.
- A wrapper the readers can't read — a call:default_api: whose arguments
  textArgs refuses, a shape with none of the marks, a call example inside
  a code fence — stays in the history; the report's conditions are kept
  to what can be checked.
- No receive-side counter is added: the reply's decoder has no logger of
  its own, and the shapes it reads are the report's own open question.

Run
- TestAntigravityPseudoCallOutOfHistory
  (internal/gateway/textcalls_pseudo_test.go): red before the change, the
  wrapper, the split-block and the invoke cases each failing with the call
  still in the turn, green after, and red again with the ag wiring taken
  back out of buildCodeAssistSent
- go test -tags nogui -count=1 -run 'TestAntigravityPseudoCallOutOfHistory|TestCodeAssist|TestTextCall|TestTextWritten' ./internal/gateway/: ok 5.016s
- go test -race -tags nogui -count=1 -run 'TestAntigravityPseudoCall|TestCodeAssistTextCalls|TestTextWrittenCall|TestTextCalls' ./internal/gateway/: ok 2.952s
- go test -tags nogui -count=1 -timeout 25m ./internal/gateway/: ok 600.353s
- gofmt -l internal/gateway/codeassist.go internal/gateway/textcalls.go
  internal/gateway/textcalls_pseudo_test.go: empty
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean
- go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok

Reviewed and ported (on origin/main 1b0340fdb, cherry-picked clean):
- Read: only the Antigravity envelope (ag) is rewritten, only model
  turns with no structured part, only a whole closed call of an offered
  tool whose result the text after it repeats; r.Messages is untouched,
  and the rewrite is the same on every request, so the history prefix
  stays stable. Nothing is added to the prompt.
- mote: TestAntigravityPseudoCallOutOfHistory green. With codeassist.go
  and textcalls.go put back to main it is red on the wrapper, the
  split-block and the invoke cases ("the pseudo call stayed in the
  turn sent to Antigravity: ...").
- mote: go test -tags nogui -timeout 45m ./internal/gateway ok (1009s);
  vet darwin/linux/windows ok; gofmt -l clean.
Not tried: a real Antigravity long session; the reporter's own
controlled replay is the evidence that clearing such turns helps.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:17 +08:00
ggbdpq 72e09cc019 catalog: a list's sora ids are video models, made at its OpenAI-shaped videos API (#4954)
What changed: a fetched model list keeps an id naming a video model the
way it keeps one that draws (FilmsID: sora-2, sora-2-pro). OpenAI's list
marks no kind, and textModel counts sora out of the chat models, so a
Sora model was never listed at all: the provider editor could not mark
it a video model, and startVideo answered 400 "can't make videos". A
sora id now reaches the list as Films - a video model of the provider,
asked at its OpenAI-shaped videos API, which the gateway already speaks
- and is still no chat model. The other video families keep the faces
their own APIs are asked on: Ark's Seedance at its tasks, a MiniMax
key's H3, and a model the user says makes videos (#1399).

Run:
- go test ./internal/gateway -run TestOpenAIKeySoraMakesVideos -count=1
  RED before (videomakers [] - the list carried no sora model), green
  after: sora-2 and sora-2-pro are the provider's video models, a video
  is started, polled and fetched at its /v1/videos, and neither id is
  among the chat models.
- TestCustomProviderMakesVideos, TestCustomProviderVideoNeedsTheListsWord,
  TestCustomProviderVideoTheUserMarks green, the last two with the
  fixture's unmarked model renamed to agnes-video-2.5-flash (#1399's own
  case): a name alone still makes no video model, even one with "video"
  in it.
- go test ./internal/catalog, the video family with -race, gofmt,
  go vet -tags nogui, builds (darwin, linux, windows): clean.

Reviewed and ported (on origin/main 1b0340fdb, cherry-picked clean;
main's Seedance-at-Ark commits 93060c98d and 5bd1aee63 cover Ark's
Domain/modalities faces only, and nothing on main lists sora):
- mote: TestOpenAIKeySoraMakesVideos, TestCustomProviderMakesVideos,
  TestCustomProviderVideoNeedsTheListsWord and
  TestCustomProviderVideoTheUserMarks green. With catalog.go and
  live.go put back to main, TestOpenAIKeySoraMakesVideos is red:
  "video_sora_test.go:70: videomakers []".
- The two existing tests' "sora-like-2" fixture is renamed to
  agnes-video-2.5-flash, since a sora id is now a video model by name;
  they still hold that a name alone makes no video model.
- mote: go test -tags nogui ./internal/catalog ok; -timeout 45m
  ./internal/gateway ok; vet darwin/linux/windows ok; gofmt -l clean.
Not tried: a real OpenAI key's Sora video (the upstream is httptest).

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:17 +08:00
ggbdpq cfadcde168 provider: a model list OpenCode's key is refused is asked again bare, so the picker says what the vendor serves (#4900)
What changed: OpenCode's model lists are public - the vendor answers its
/models without a key. When a provider's keyed ask of the list is
refused (an expired or wrong key), the same list is asked once more
without credentials, and what the vendor serves is saved as the
provider's list. The picker then shows the vendor's word instead of
falling back to the models.dev catalog, which files free rows under
opencode-go that Go doesn't serve (cat-jam-free, minimax-m3.1-flash-free,
step-5-preview-free, longcat-2.5-preview-free) while missing the free
rows it does (beam-free). The retry is kept to OpenCode's own hosts
(IsOpenCode): no other vendor's list is known to answer bare, and a
partial public list would stand in for the keyed one. Multi-key
providers, account (sign-in) lists and the add form's List are not
covered.

Reviewed and ported (on origin/main 1b0340fdb, cherry-picked clean;
the hunk now sits in fetchList, which fetch was split into since):
- mote: TestOpenCodeListAskedBareWhenTheKeyIsRefused and
  TestOpenCodeListNotAskedBareAtAnotherHost green. With models.go put
  back to main and the tests kept, the first is red:
  "the bare ask should have answered where the key was refused: no
  model list: https://opencode.ai/zen/go/v1/models: (Invalid API key)".
- mote: go test -tags nogui ./internal/provider ./internal/catalog ok;
  go test -tags nogui -timeout 45m ./internal/gateway ok (1009s); go vet
  (darwin), GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  provider, catalog and gateway ok; gofmt -l clean.
- Read: the bare retry follows any failed keyed ask, not only a 401/403
  (the list errors are untyped strings); a network failure costs one
  more ask and keeps the first error. Provider Test still probes each
  endpoint with the key, so an expired key is still shown red there.
Not tried: a real expired OpenCode Go key; the tests serve the vendor
from a stub transport, no network.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:16 +08:00
ggbdpq c2dd693dac gateway: a 451 censorship_blocked refusal asks the group's next member (#5089)
StepFun's safety filter refuses a request with HTTP 451 and an error
object saying {"type":"censorship_blocked"}. filterReasons, the map of
the words a vendor says its filter stopped the reply with, didn't know
the type, so policyRefusal didn't read the 451 as a refusal and
retryable has no 451 of its own: the status went to the agent as it
came, the group's next member unasked, and the try stood as a plain
failure of the account.

The same refusal said in a 200 stream's finish_reason would have been
one, as content_filter is. Now the type is in the map, and the refusal
goes to the next member the way any refusal the vendor names does:
nobody rests, as the filter refusing is about the request, not the
account.

Reviewed and ported: one filterReasons entry, vendor-neutral, and
nobody rests as before. On mote, -run 'Censorship': with the map entry
reverted, red: "TestCensorshipBlocked451FailsOver ... whole: 451" and
"TestCensorshipBlockedIsAPolicyRefusal ... policyRefusal: "", false";
green with it. Whole package: ok (906.6s). Not tried: a real 451 from
StepFun.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00
ggbdpq 2027bb5a6d gateway: a filter's finish code after the reply began asks the group's next member (#5075)
A vendor that answers with a canned refusal line as the content and has
its finish_reason "content_filter" follow (#5075: CodeArts's
deepseek-v4.1-flash, 10/10 on the same body, 47 tokens out, the line
byte-identical) was a try that stood as a success: the line had gone out
as content, so the scan's refusal paths were past, only refusedAfter was
marked, the group's next member was never asked, and a client that reads
finish reasons — Pi's and DeepSeek Harness's mapStopReason, Claude Code —
failed the whole turn on it. Another member of the same group answered
620 tokens.

refusalAfter now hands the try over (handOffAfter) when the refusal is
the vendor's own finish code (eventRefusal), the reply is passing, a
candidate stands behind it reading Chat chunks, and no call of the reply
has gone by: what of the write went by before the code goes out with the
reply, the code, its usage and [DONE] do not, and the next member's
chunks follow in the same stream, as a refusal after reasoning is
(handOver). The member isn't set aside: the request was refused, not the
account (#248). A refusal still held goes through the scan's own paths
(flow, handOver) as before; an error event mid-reply stays as it came
(#733); an Anthropic or Responses client's stream is numbered and what
of it has gone by is untracked, so its refusal keeps going as it came.

TestRefusalAfterThinkingAndTextStays becomes
TestRefusalAfterThinkingAndTextFailsOver: a Chat client is handed over
now, where it ended on the vendor's finish code before.

Fixes #5075

Reviewed and ported: composes with #2972 (passthrough holds the end,
the hold writer sees the error event). The hand-off is held to Chat
streams that sent no tool call (handsOff checks h.calls); that guard
had no test, so TestFilterFinishAfterACallStays is added here: a
content_filter finish after a tool_call stays with the first member
and the call reaches the client. On mote, -run
'Refusal|CannedRefusal|FilterFinish': with the non-test part reverted,
red: "TestCannedRefusalFinishFailsOver ... chat: 200" and
"TestRefusalAfterThinkingAndTextFailsOver ... 200 (a 1, b 0)"; with
the calls guard removed by hand, TestFilterFinishAfterACallStays red;
green with the patch. Whole package: ok (906.6s). Not tried: a real
vendor's canned refusal (CodeArts, qoder). The refusal text already
streamed stays in the client's stream before the next member's answer.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00
ggbdpq d45e74d89f gateway: a length cut that said nothing is not a completed reply (#2972)
What changed: a Chat reply cut at its length having said nothing — no
text and no call, only thinking, or nothing at all — fails at once, on
the translated paths and on the passthrough Chat→Chat relay, asked
again nowhere: the error in the client's own protocol, a group's next
member asked, nobody rested, and the same one not asked again after a
moment (the void fails the same every ask, as one that didn't stream
does). It fails only past a short probe's worth: a reply that spent no
more than cutVoidTokens, of a request capped at no more, is a probe's
answer — a title's cut is wanted, the response.incomplete it was
(#1466) — and goes as it came. A length cut that said something is
still the truncation it always was.

Why: qoder/dfmodel ended four replies of one dsh turn with 48,000
output tokens each, every one of them reasoning — out == reasoning
exactly each time, 192,000 tokens and 919 seconds for nothing — and dsh
speaks openai-completions while the qoder plugin serves Chat, so all
four were relayed as they came. The relay reads its end now: a stream's
tail is held from the chunk that says why it ended while nothing has
been said in it, and a void fails with the error event in its place, no
finish_reason the agent reads as "continue" having gone out. A reply
asked whole is written once it has ended, for the same verdict. On the
translated paths the check sits beside answersNothing (cutVoidAt,
cutVoid), and holds the end events as the empty reply's already are. The
verdict sits at the reply's end, so a streamed one costs no second read.

What the review asked, and where each landed:
- the reporter's own route: the passthrough Chat→Chat relay fails the
  void too, streamed (the error event and [DONE] instead of the finish)
  and whole (the error with the status)
- no in-place re-ask: the void's branch is the empty reply's error
  without the emptyRetries, and the same-one retries and the patience's
  rounds pass it by (cutVoidWords beside didNotStream in passing and
  busy), so the upstream is asked once — every test here holds the fix
  to that
- a deliberately small max_tokens is no void: the gate is spent past
  cutVoidTokens, or the request hadn't capped its reply small
  (probeTranslated asks 16, a title less than that)

The repo's own recorded ClinePass stream (16 tokens, all reasoning,
testdata/clinepass_stream.sse) is relayed as it was, on the relay and
translated alike.

Run:
- go test -tags nogui ./internal/gateway/... -count=1: ok
- go test -race -tags nogui ./internal/gateway/ -count=1 (the stream
  relays and holds among it): ok
- the five tests of chat_length_nothing_test.go red on the branch's
  parent, green here; TestClinePassUpstreamRecorded green before and
  after
- gofmt -l clean; go vet clean on darwin, linux, windows
- builds: darwin and windows ok; linux ok for internal/... but the wails
  v3 beta 24 module's own linux files (pre-existing, untouched here)

Fixes #2972

Reviewed and ported: rebased on 1b0340fdb, the three points of the
11-02 review checked against the code: the passthrough relay is
covered (holdTail on Chat streams, whole-body hold on Chat non-stream),
the void fails over instead of being asked again in place (passing()
and busy() skip cutVoidWords, emptyRetries does not see it), and the
1024-token floor keeps a small probe's cut (ClinePass's 16) relayed.
On mote, internal/gateway -run 'ChatLength': with the non-test part
reverted, red: "TestChatLengthVoidFailsAtOnce ... a void cut answered
200 after 1 calls, not the length-void error at once", and
TestChatLengthVoidFailsOnTheRelay and TestChatLengthVoidNeedsSize red
the same way; green with it. Whole package with the next two commits,
go test -timeout 45m ./internal/gateway/: ok (906.6s); go vet and
gofmt -l clean. Not tried: a real vendor's length-void reply, Windows
and Linux runs, the full ./... suite.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00
ggbdpq ae3c2ec4e9 fix(netproxy): the health check pings a silent connection after 10s, not 20 (#4936)
What changed
The HTTP/2 health check is the only probe of a connection whose path has
died silently, so a turn in flight on such a connection waits for the
next one: with PingAfter at 20s a first try read EOF came ~20.5s after it
was written (Antigravity through a local proxy whose tunnel a NAT or a
relay had dropped, yetone/magpie#4936), and magpie's own retry served at
once on a new connection. PingAfter is 10s now: finding a dead path costs
at most half of what it did, and the margin a body under uploadBytes
needs on a slow uplink — the budget PingAfter+PingWait, a ping queued
behind the body and answered only after its last byte (#3909) — still
covers 64KB at about 3KB/s.

Run
go test -tags nogui -count=1 ./internal/netproxy (a new test walks a turn
onto a connection whose path dies under it and watches it fail at the
health check, then a retry serve on a connection of its own; a second
locks the sizing)
go test -tags nogui -count=1 ./internal/... — TestMothX,
TestProxyCheckSaysAProxyPassedBy and TestHostToldTheGatewayAddress are
red alone on the parent commit too; TestCodexPoolSaysTheClientsVersion is
a known full-suite flake, green alone
go vet, gofmt, GOOS=linux GOARCH=amd64 go build, GOOS=windows
GOARCH=amd64 go build, go build on darwin.

Reviewed and ported: every line read against origin/main 1b0340fdb.
Bodies of uploadBytes (64KB) and over go over HTTP/1.1, so the
PingAfter+PingWait budget, 30s down to 20s, still covers what HTTP/2
carries at ~3.2KB/s. On mote: TestPingAfterSizesTheDeadPathDiscovery is
red with netproxy.go put back to 1b0340fdb ("PingAfter 20s; want 10s"),
green with it. TestRequestOnAHoledConnectionFailsAtThePing builds its own
transport with scaled timings, so it passes on the old code too: it
documents Go's HTTP/2 health check on a dead tunnel, not this value.
On mote at this tree: go test -tags nogui -count=1 -timeout 45m
./internal/gateway/ ./internal/netproxy/: ok (gateway 1025.9s, netproxy
5.3s); go vet -tags nogui of both packages for darwin, GOOS=linux and
GOOS=windows: clean; gofmt -l: clean.
Not tried: the reporter's Clash/Mihomo route to Antigravity. This halves
the stall on a dead pooled connection (~21.5s to ~11.5s); it doesn't stop
the first try landing on it.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00
ggbdpq f76b48ea09 gateway: a Chat finish of tool_calls with no call in the stream ends stop (#4944)
What changed: Hermes through magpie (stream=true, tools, deep
reasoning): a reply of text alone ended, on the reporter's upstream, on
a frame saying finish_reason "tool_calls" that no delta ever carried a
call for - the shape the reporter's bare call of the model ends its
real calls with ("delta":{"reasoning_content":null},
"finish_reason":"tool_calls","matched_stop":1); its text-only turns end
there too, and the client took every such turn for one whose calls were
dropped and re-prompted, three times a reply. The other gateway on the
same upstream said stop.

chatTidy's mend that ends a finish of tool_calls with no call left stop
(#1475) only ran for a choice some delta had carried a tool_calls key
for: the case "tool_calls" sat inside the t.called[choice] guard the
case "stop" needs, and a reply whose stream never carried the key
passed the misleading finish on. The switch now runs for every choice's
finish: a finish of tool_calls with no readable call ends stop whether
or not a delta carried the key, and the stop of a choice that made
calls still ends tool_calls. A legacy function_call a client may still
be reading (#4659) keeps a finish that says the turn ended in a call,
and a "function_call": null is still the contract's own nothing.

Whole replies are untouched: #1475's review narrowed chatWhole to a
finish whose call was dropped and pinned a whole reply that came with
no tool_calls at all as going as it came
(TestToolCallsFinishWithNoCallsStaysWhole); no report covers them.

Run: go test -tags nogui -count=1 ./internal/gateway: one red,
TestCodexPoolSaysTheClientsVersion, green on its own - the known
pre-existing red of this machine; the two new tests and the family
guards among the rest, ok. go test -tags nogui -count=1 -timeout 45m
./internal/...: 74 packages ok; the four failures are all red at the
parent 173b7e274 single-run too, none of this commit's own (TestMothX
in agent, TestProxyCheckSaysAProxyPassedBy in gui,
TestHostToldTheGatewayAddress in plugin, and the codex pool one above).
Red at the parent with chattidy.go from the parent and the tests kept:
TestChatNoCallToolCallsFinishEndsStop "calls map[], finish
"tool_calls"" and TestChatRelayLegacyCallFinish "finish "tool_calls"" -
the reported symptom; green again with the commit restored. gofmt -l:
clean. go vet -tags nogui ./...: clean. go build -tags nogui: darwin,
GOOS=linux, GOOS=windows: ok.

Reviewed and ported: every line read against origin/main 1b0340fdb
(chatTidy runs before textCallTidy, which sets tool_calls itself when it
makes calls from text, so a written call still ends tool_calls; a finish
line reaches the switch through needsTidy's "tool_calls" match). On mote:
TestChatNoCallToolCallsFinishEndsStop and TestChatRelayLegacyCallFinish
are red with chattidy.go put back to 1b0340fdb ('stream: calls map[]
finish "tool_calls"' and 'stream, function_call null and no call: finish
"tool_calls"'), green with it; the chattidy family (TestChatCallsEndToolCalls,
TestToolCallsFinish*, tidy/nameless/function_call tests) green.
On mote at this tree: go test -tags nogui -count=1 -timeout 45m
./internal/gateway/ ./internal/netproxy/: ok (gateway 1025.9s, netproxy
5.3s); go vet -tags nogui of both packages for darwin, GOOS=linux and
GOOS=windows: clean; gofmt -l: clean.
Not tried: a real Hermes against the reporter's upstream. Not covered:
the translated route (a Chat upstream's "tool_calls" finish with no call,
to an Anthropic or Responses client) still says tool_use; collector.finish
only mends stop to tool, not back.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00
yetone 2f59545d29 gateway: a key not given a group listing alone is listed the members it may use (luckymanjc)
luckymanjc on Discord (#general, 11-05): on a second computer, through
Remote magpie, his three Codex accounts offered GPT-6-Luna alone, with
the key his Remote magpie uses held to "Codex 的全部模型" (codex/*),
GPT-6-Luna and the accounts. His screenshot of that key's picker, on the
host, offered GPT-6-Luna alone under Codex too.

Cause: a routing group listing alone (Group.Unlists, "the group alone")
keeps its members out of Catalog(), so out of /v1/models and the key
picker (/api/caller-keys/models), as the group stands in for them there.
Since d1cdce130 (11-03) that holds for subscription models again. But a
group of the user's own is never a key's unless the key names it
(kautism's rule, groupAllowed), so a key held to codex/* was given
neither the group nor its members: only the Codex models no such group
named were left, Luna here. The picker read the same Catalog(), so there
was nothing else to tick.

Fix: the group stands in only where it is given.
- provider.GroupStandIns: the models groups listing alone keep out, with
  the groups' ids (groupsKeeping, which unlistedByGroups now reads; a
  provider kept for routing groups alone is not among them).
- gateway keyListed: for a key that may use none of the groups standing
  in for a model and may use the model, the model is listed beside its
  provider's others; the list's own picks still leave one out. Every key
  list goes through it: catalogFor (/v1/models and what it feeds, the
  remote magpie's fetch included), /v1/models/{id}, the key's page,
  Codex's catalog and spawn choices. A key that names the group gets the
  group in place of its members, as before. Unrestricted callers are
  unchanged: the group alone, as the option says.
- The key picker offers those models after their provider's.
It is the same for every provider a group can list alone, not Codex
alone. Docs: reference.md, gateway-routing.md.

Tests (mote):
- TestKeyNotGivenTheGroupIsListedItsMembers (gateway): Free + Pro Codex
  sandbox accounts, a group listing sol/astra/terra alone. Unrestricted
  list: group, no members. The reporter's key (codex/*, codex/gpt-6-luna,
  both accounts): every Codex model, no group. A key of one member: that
  one. A key naming the group: group, no members. A Remote magpie on the
  reporter's key fetches every Codex model. Red on the old code (sol,
  astra, terra missing), green now.
- TestCallerKeyModelsOfferGroupKept (gui): the picker offers the kept
  models, beside their provider's. Red on the old code, green now.
- Broken by hand: dropping the "a group standing in is given" check
  turns the key-naming-the-group case red.
- go vet provider, gateway, gui; go test ./internal/provider ok;
  ./internal/gui all ok but TestMainWindowCorners (#3949, AppKit titlebar on
  mote's macOS, untouched here); ./internal/gateway -run
  "Key|Codex|Model|Remote|Group|Catalog|Spawn|Unlist|Caller" ok.

Not tried: the reporter's own host (his groups are inferred from the
screenshot: only Luna left under Codex in the picker); two real magpie
apps on two machines; real Codex accounts.
2026-11-05 18:28:38 +08:00
yetone 51bdc985bc provider: a cap set on a window a plugin later sets aside still holds; WorkBuddy min 0.2.24 (ferock on Discord)
WorkBuddy 0.2.24 stops an account by a new "Total credits" window (the
plan's credits and the extra ones together) and sets "Credits" and
"Extra credits" aside, so the Routing page reads every account the same,
its plan's credits spent or not. Routing skipped every window set aside,
caps included, so a cap the user had set on "Credits" would have stopped
holding the account: magpie's change overriding the user's value.

Now a window set aside, not a pool's or one model's, rides in each
limit's pool (allowanceOf), as a pool's windows do, and holds the
account at a cap set on that window itself (WindowCaps.own), never at the
account's cap or a Codex credits hold, which never reached it before.
WithCapped marks such a window Capped with OwnCap, so the GUI shows the
mark and the "at its cap" note for it, counts no account cap on it
(windowCapOf), and offers its meter as a button only while it has a cap
of its own, to change or lift it; no new cap on a window set aside.
app.js grows 48 bytes, inside the core budget (no raise).

Run (mote): go test ./internal/provider (ok) and ./internal/gui
(TestCoreScriptBudget ok); window-cap, window-cap-pool and account-cap
GUI tests, both engines, 420/1100, five languages: 136 pass.
internal/gui's TestMainWindowCorners/macOS_26_SDK (#3949) and
i18n-keys "a plugin's words are its own" (#5327, #5332) are red the same
on origin/main a9b1877cf, files this change doesn't touch.
Broken by hand: allowanceOf without the set-aside loop,
TestAsideWindowKeepsItsOwnCap red ("the user's 50% cap on Credits, at
60%, no longer held: <nil>"); app.js without the meter's ownCap guard,
window-cap 20 of 80 red (the new test in every engine, width and
language).
Not tried: a real WorkBuddy account with a cap on Credits; the whole GUI
suite (the full Go suite runs after the tag).
2026-11-05 18:22:56 +08:00
yetone a9b1877cfc routing: a session's name stays when a later poll answers without it (#5365)
refreshOtherNames deleted a name the page had whenever a poll of
/api/gateway/session-titles came back without it, so a read that failed
or ran late (ZCode's database busy or slow, Flandern1211's report) put the
card back to its folder until a later poll named it again. An answer
without a name is unknown, not a session that lost its name: the page now
only takes new names in. 226fc8ea3 makes ZCode's poll fast; this is the
"names that vanish" half of #5365, which that commit leaves alone.

Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>

Run (mote, via mote-run):
- node --test internal/gui/tests/routing-session-name-kept.test.cjs
  (new; Chromium and WebKit, all five languages, 1100 and 420): 20 pass.
  With client.js at origin/main: red, the card reads "Claude Code ·
  work/zc" after a poll without the name.
- go test ./internal/gui (budgets, i18n guards): ok but
  TestMainWindowCorners/macOS_26_SDK, #3949.

- node --test on the 8 GUI files that fake session-titles
  (claude-subagent-tag, routing-by-key, -credits, -moved-why,
  -request-metrics, -session-folder, -session-title, -sessions) and
  i18n-keys: 185 pass, 1 fail, i18n-keys "a plugin's words are its own"
  on two words in files untouched here (#5332, #5327).

Not tried: the whole GUI suite (one routing file changed by four lines,
no new strings, no new API call).
2026-11-05 17:53:42 +08:00
yetone 52563d1cdf sessions: a ZCode name poll reads its sessions' messages for their stamp, as the listing does (#5365)
226fc8ea3 lists ZCode's sessions for Titles from their rows alone, with
size 0 and the row's time_updated as the file's stamp. Two things followed
from that stamp:

- ZCode writes a message without touching its session's row, so a session
  still under its default title, first read before its prompt was in, was
  never named by that prompt while only the Routing page polled.
- The cache kept size 0 and the row's time, where the Sessions page's
  listing (zcodeFiles) keeps the message count and the last message's
  time, so each read the session whole again after the other.

zcodeTitleStamps gives the sessions a poll asks for (their key wanted,
subagents under it too) the same count and last activity, from a
COUNT/MAX over each one's own messages by session_id, not the join over
every session's. A session whose messages can't be read keeps its row's
stamp, as before.

Co-authored-by: Flandern1211 <163982805+Flandern1211@users.noreply.github.com>

Run (mote, via mote-run):
- go test ./internal/sessions -run TestZCode -count=1 at 226fc8ea3 alone:
  TestZCodeTitlesSeeNewMessages red (after the prompt: "") and
  TestZCodeTitlesKeepTheListingsStamp red (kept size 0 mod
  1790496000000000000, listing has size 3 mod 1790496030000000000). With
  this change both green. On origin/main 1b0340fdb both pass (the poll
  read the join), while 226fc8ea3's TestZCodeSubagentTitlesByRequestID and
  TestZCodeTitlesWithoutMessageTable are red there.
- go test -timeout 45m ./internal/sessions ./internal/gui -count=1: sessions
  ok; gui ok but TestMainWindowCorners/macOS_26_SDK, #3949 (mote is
  macOS 27), untouched here.
- GOOS=linux and GOOS=windows go vet ./internal/sessions: ok. gofmt clean.

Not tried: a real ZCode database (none on this Mac or the Windows box);
the per-session COUNT/MAX is not timed against the reporter's 1 GB one.
It filters message by session_id, as parseOpenCode's own reads do.
2026-11-05 17:53:42 +08:00
Flandern1211 24e1a21095 sessions: list ZCode's rows, not its messages, for a title poll
Titles listed every agent's files, and zcodeFiles joins the message table to give each session its size and last activity. On a ZCode database of 1,022 sessions and about 1 GB of messages that join took ~20 s, while the Routing page asks again every 15 s: its cards showed the folder for a while, and a poll that came back empty dropped a name it had.

Titles now lists ZCode's sessions from their own rows (zcodeTitleFiles: id, parent, time_updated) and names them through the same assembleListed/parseOpenCode path as before. A ZCode subagent, which ocRoots files under its parent's key, is named from its own file's cached row when the key asked for matches no group.

Run:
- go test ./internal/sessions -run 'TestZCodeTitlesByRequestID|TestZCodeSubagentTitlesByRequestID|TestZCodeTitlesWithoutMessageTable|TestZCodeDefaultTitleFallsBackToFirstPrompt|TestSessionTitles|TestZCodeCalls' -count=1: ok.
- go test ./internal/gui -run TestSessionTitlesNameOtherAgents -count=1: ok.
- Broken by hand: with zcodeFiles (the message join) in place, TestZCodeTitlesWithoutMessageTable fails with an empty title; with the subagent fallback removed, TestZCodeSubagentTitlesByRequestID fails; with the sess_ alias removed, TestZCodeTitlesByRequestID fails.
- Real ZCode database on Windows: Titles for three live sessions went from 20.4 s to 780 ms cold and 74 ms warm; a ZCode and dsh poll took 80-160 ms.
- go build ./...: ok. The full sessions package has the same three Windows-only failures as before this change (TestAgySessions, TestAgyRowOnly, TestCCListingKeepsItsNames).
2026-11-05 17:53:42 +08:00
yetone d3a0be6dda provider: Google's verify link is the one Gemini CLI opens, read whole from any body (pppuuu)
pppuuu (Discord) tested an Antigravity model, got Google's 403 "Verify your
account to continue." with a link, and opening the link gave Google's own
"400. That's an error. The server cannot process the request because it
is malformed."

What magpie showed was checked first, and it was Google's validation_url
whole: a realistic VALIDATION_REQUIRED body (ErrorInfo metadata with
validation_url, validation_error_message, validation_url_link_text, a
google.rpc.Help detail, & written raw and as &) sent through the
Antigravity model test (TestAntigravityModelTest) and through the gateway
to an agent (TestVerifyLinkWhole) shows the URL with every parameter on
the old code too. Google's own Antigravity flow gives the same 400 to
many accounts (discuss.ai.google.dev 119780: cleared google.com cookies,
Chrome, or removing Antigravity from third-party access fixed it).

What differed from Google's own client, and is fixed here:
- Gemini CLI (classifyValidationRequiredError) opens the google.rpc.Help
  detail's link first, past a "Learn more" one, then the ErrorInfo's
  validation_link, then validation_url. magpie took validation_url first
  and never read validation_link. It now takes them in Gemini CLI's order.
- Metadata was read as map[string]string, so one non-string value made the
  whole body unreadable and the link was lost; values are read one by one.
- A message magpie already put the link in, passed on again as a JSON
  error body (a Remote magpie's, the gateway's), has & as &; the raw
  read stopped at the \ and found no link. It is read from the decoded
  words now.

Tests: TestVerificationLinkWhole and TestVerificationLinkAsGeminiCLI
(provider), TestVerifyLinkWhole and a verify case in
TestAntigravityModelTest (gateway).

Run on mote: go test -run 'TestVerification|TestAPIError' ./internal/provider
ok; go test -run 'TestAntigravityModelTest|TestVerify|Restricted'
./internal/gateway ok; go vet (darwin, linux, windows) of internal/provider
and go vet internal/gateway ok; go test ./internal/provider: ok (178s).
Broken by hand: with the old test.go, TestVerificationLinkWhole (escaped
read-back) and TestVerificationLinkAsGeminiCLI (Help link) are red; the
gateway cases pass on the old code too, which is the evidence the shown
link was already whole.
Not tried: a real account Google wants verified (none here), and
pppuuu's exact body and link, which aren't known; whether Google's Help
link and validation_url ever differ is not known.
2026-11-05 17:50:33 +08:00
yetone 1b0340fdbc provider: WorkBuddy's mover min is 0.2.23, which hides DeepSeek Harness's name
plugins 4912c608 (npm 0.2.23, checked --prefer-online): a "Hide DeepSeek Harness's name" switch, on by default, takes dsh's identity lines out of what goes to WorkBuddy (NancyTom18 on X, an account banned after use from dsh). keepMovedCurrent brings moved users up to it.

Run: go test ./internal/provider on mote at this tree, ok (219s); gofmt -l clean. Not tried: a real WorkBuddy account.
2026-11-05 17:37:22 +08:00
yetone 6d9fb7ef0f routing: a dsh request names the dsh session its first prompt was read from
changqiu4890 on Discord: Routing -> Requests showed dsh's requests with no
session id. dsh 0.2.1's pi-ai routes (openai-completions, anthropic), which
magpie configures, send no session header (pi-ai's session affinity is
withheld by dsh's compat gate), so a route had only its Conv, the hash of
its first user message. The Context page already found dsh's session by
that hash (dshConvs); the Routing page grouped by header session only.

pricedRoutes now gives a dsh route with no session of its own the dsh
session whose Convs hold its Conv (convOwners, shared with the Context
page's joinConvs), from an index rebuilt at most every 2s when a conv is
missing and every minute otherwise. Grouping and titles (dsh:<id>) follow.
A route with its own session, another agent's route, and a conv two
sessions share stay as they were.

Run (mote-run, this tree):
- go test -tags nogui ./internal/gui/ ./internal/sessions/: ok, ok
- TestRoutingDshRoutesNameTheirSession and TestContext*: ok
- GUI routing-sessions, routing-session-folder, routing-by-key, ctx-route,
  routing-day-window: Chromium 160/0, WebKit 80/0
- go vet darwin, linux (nogui), windows ./internal/gui; go build all three
- gofmt -l clean
Broken by hand: `r.Session = owners[k]` -> `_ = owners[k]`; the new test's
dsh chat and messages routes went red.
Not tried: a real dsh through magpie. A brand-new session's first request
shows no session until dsh writes its session file and the index refreshes.
The in-flight list (Active, concurrency endpoint) is unchanged.
2026-11-05 17:25:26 +08:00
yetone 4f624241f7 codex: the ChatGPT app left on "hit a snag" after an app-server restart is reopened when idle (#4550)
ysm119 on Discord: each Restart of Codex in magpie left the ChatGPT
desktop app on "ChatGPT 遇到了问题 / 请重试" till it was quit and opened
again. magpie ends the app's own app-server cleanly (code 0); a
signed-in ChatGPT 26.1021 then fails "Hosted AppServerManager identity
is not ready" on the one it starts, logs fatal_error_broadcasted and
shows the page. That is the app's bug; magpie now follows it up.

- provider/codex_app_crash.go: for 60s after every end magpie makes
  (the watcher's step, RestartCodexApp, RestartSwitchedCodexApp) the
  app's logs are read for a whole fatal_error_broadcasted line stamped
  after the end. On one, with no request through magpie since or in
  flight and no Codex turn opened since, the app is quit and opened
  once. Otherwise it is left as it is and logged. Where it can't be
  reopened (Linux, an app that didn't quit) the Agents row says
  "The Codex app hit an error · quit it and open it again" (appSnag)
  until the app-servers seen then are gone or the app is closed.
  Unreadable logs reopen nothing.
- agent/codex_app_crash.go: the logs as the app's file logger writes
  them (macOS ~/Library/Logs/com.openai.codex, Windows
  %LOCALAPPDATA%\Codex\Logs and the Store package's LocalCache, Linux
  $XDG_STATE_HOME/codex/logs; YYYY/MM/DD folders, tail-read, half
  lines dropped). The relaunch is the Agents row's: on macOS
  ChatGPT.app found by its bundle id, quit as ⌘Q does and opened once
  it has ended, never forced; on Windows codexAppReopen.
- GUI line in en, zh, zh-TW, ja, de; docs/subsystems/agent-wiring.md.

Run on mote (macOS) at this head on origin/main 08982805e:
- go vet ./internal/agent ./internal/provider ./internal/gui (darwin
  and GOOS=windows), GOOS=linux go vet ./internal/agent
  ./internal/provider; go build ./...; gofmt -l clean.
- go test ./internal/provider ok; go test -run
  'TestCodexApp|Restart|Reopen' ./internal/agent ok.
- go test ./internal/gui: red only in TestMainWindowCorners (#3949) and
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322), AppKit window tests
  red on mote's macOS 27 and filed before this change.
- win-run and wsl-run: go test -run TestCodexApp ./internal/agent
  ./internal/provider ok (the macOS relaunch test skips on Windows, as
  TestWorkBuddySidecarOutlivesQuitOnMac does, #4115).
- node --test codex-app-snag, codex-app-out, codex-app-back, i18n-keys,
  i18n-en-no-cjk: chromium and webkit, every language, 980 and 440px.
  i18n-keys' "a plugin's words are its own" stays red for "View routing"
  (#5327/#5332, red on main since 73c98ebc2); this change added a word
  there and took it out again.
- Core script budget: under it, not raised.

Broken by hand, each red then restored:
- codexAppCrashStep's call removed: 4 provider tests red.
- the watch not armed in RestartSwitchedCodexApp:
  TestCodexAppRestartsWatchForTheErrorPage red; in RestartCodexApp:
  TestCodexAppRowRestartWatchesForTheErrorPage red.
- the turn and request checks off: TestCodexAppInUseAfterItsErrorPageIsLeft red.
- the snag not set: TestCodexAppSnagSaidTillTheAppRestarts red.
- the stamp's >= since check dropped, or a half-written last line kept:
  TestCodexAppCrashedReadsItsOwnLogs red.
- a wrong Store package path: TestCodexAppCrashedReadsEachSystemsFolder red.

Not tried: a real signed-in ChatGPT app reaching the identity-not-ready
page, and a real quit and reopen of the user's ChatGPT.app (the relaunch
is tested with faked process listing, quit and open in a sandbox HOME).
The log line and folders are read from ChatGPT 26.1021's
file-based-logger and the reporters' logs; a later app that renames
them reopens nothing, as before this change.
2026-11-05 17:24:53 +08:00
yetone 08982805eb gui: spinners stand still under reduced motion instead of flickering
_yukirock on X (0.1.3036, macOS 27.3): spinners ran far too fast. The
reduced-motion rule cut every animation to .01ms but left endless ones
endless, so a spinner restarted every few microseconds and each frame
caught it at a random angle (seen frame by frame in the reporter's
video: the arc jumps 90-180 degrees per 60fps frame). It hits anyone
with the system's Reduce Motion, or magpie's own (Settings > General).

The rule now also sets animation-iteration-count: 1, so an endless
animation runs once, ends at once and shows its base style, as the
spinners that declare `animation: none` there already did (ag-up,
quota-refresh, saving). routing.css's busy spinner asked for a 2s turn
under reduced motion; the global !important rule always overrode it, and
it now stands still with the rest.

reduce-motion.test.cjs puts a sign-in spinner in the page and waits up to
1s for its animations to finish: they do while motion is reduced, and
never otherwise. (Counting running animations two frames on was red in
Chromium at the rebased head: a compositor animation can take longer to
start.)

Run on mote (Chromium and WebKit):
- reduce-motion plus every GUI file that reads animations under reduced
  motion (33 files, 1034 tests): 1011 pass, 23 fail. The failing four
  files (context-map, found-skill-pick-remove, mobile-web,
  tray-cell-click) fail the same on origin/main a732f3c49 run alone
  (24 vs 24, context-map's chromium 420px case flips language): filed as
  #3488, #4932, #5013, #3952, #5215.
- Broken by hand: the new test on the old app.css is red (spin 1 where 0).
- go test -tags nogui ./internal/gui: ok. gofmt -l clean.
At the pushed head: reduce-motion 6 of 6 runs green in both engines,
sync-spin green; the new test red on the old app.css (0 of 2).
Not tried: the real app with macOS Reduce Motion on.
2026-11-05 17:09:10 +08:00
yetone 965ae78e1e gateway: a routing group draws on its own image member, Codex's tool too
changqiu4890 on Discord: the group smart-split has three Codex CPA chat
models, DeepSeek-V4.1-Flash and Codex CPA's gpt-image-2.5, and dsh,
Codex and Pi are set to it. Image requests went to other providers'
image models.

Two causes in magpie:

- drawingTries tried every member of a group named for a drawing in the
  order chat routing plans them, so the chat members came first.
  group/smart-split drew on cpa/gpt-6-astra, which was asked as a chat
  for an image, before it reached the group's image member. A group
  with members that make the kind (drawsModel, or servesKind for
  video) is now tried on those members alone. The fallback between
  them stays as it was.
- Codex's image tool drew on the provider that served the turn, else
  on Settings' pick. A group's image member was never used: a turn on
  DeepSeek, or on the relay, drew with Settings' model or with the
  relay's other GPT Image. codexDrawingProvider now also returns the
  routing group the turn asked for. When that group draws (GroupDraws),
  the drawing goes to its image member through resolveDrawing, which
  keeps the member's provider.

The reporter's Routing screenshot also shows explicit requests from a
client magpie names "Mozilla": x0-15/gpt-image-2.5, codex/gpt-image-2.5,
and bare gpt-image-1 and gpt-image-1.5. magpie routes a request that
names a provider to that provider, and a bare id to the first provider
whose Drawers list it. Nothing in such a request links it to the agent's
group, so this commit leaves those requests alone.

Tests:
- TestMixedGroupDrawsOnItsImageMemberOnly (new): the reporter's group
  shape on fake upstreams, with another relay listing gpt-image-2.5
  first. Red before the fix (drew on cpa/gpt-6-astra), green after.
- TestCodexDrawingTakesItsGroupsImageMember (new): red with the group
  branch turned off by hand (drew on chat/gpt-image-2), green with it.
- TestMixedGroupMakesVideoOnItsVideoMemberOnly (new): a guard for the
  video sibling. It passes with the filter turned off as well, because
  video's mediaMembers already keeps only video members (KindGroup).

Run on mote (mote-run) at this tree:
- gofmt -l
- go vet ./internal/gateway on darwin, GOOS=linux -tags nogui and
  GOOS=windows
- go test -count=1 -run 'Group|Draw|Image|Video|Media' ./internal/gateway
- go test -count=1 -timeout 45m ./internal/gateway ./internal/provider

Not tried:
- a real Codex CPA relay or a real dsh session
- the image MCP's default for a non-Codex agent set to a group: the MCP
  call carries no link to the agent's chat route, so it still uses
  Settings' pick
- chat routing to a group's image member when the member's provider has
  no picks: the member's provider is still the pinned one, and this
  commit doesn't change it
2026-11-05 17:04:16 +08:00
yetone 331f201faf plugin: a cross-signed root copy in Windows' ROOT store no longer shadows Bun's own root (youyo.p_10001)
youyo.p_10001 (Discord #feedback, magpie 0.1.2993 windows/amd64, Bun
1.4.4, Clash Verge on 127.0.0.1:7897): every MiniMax plugin request to
agent.minimaxi.com failed "unable to get issuer certificate", while the
same chain verified outside the plugin host.

Cause: magpie hands Bun the user's Windows ROOT store as
NODE_EXTRA_CA_CERTS. Bun (BoringSSL) builds the chain up through the
first trusted certificate with the subject it wants, the extra file's
ahead of its own bundle, and stops when that one's issuer is missing.
A ROOT store holding USERTrust RSA's copy cross-signed by AAA
Certificate Services (agent.minimaxi.com's chain goes leaf, WoTrus DV,
USERTrust RSA) gave Bun that copy ahead of the self-signed root it
ships, and AAA is in neither. Node, curl and Schannel go on to the
self-signed one, so outside magpie it worked.

Fix: rootsFirst writes the self-signed roots first and keeps another
certificate only when its issuer is in the file too. Bun never ends a
chain on one that isn't self-signed (no partial chains), so one left
out could only stand in front of a root. NODE_USE_SYSTEM_CA=1 stays: the
system store Bun reads itself comes after its bundle and shadows
nothing (tried, below).

Also, for the next report like it:
- the host logs its network settings when it starts, and when the
  proxy (or the gateway's address) moves, old to new: the proxy without
  user and password (netproxy.Redact), NO_PROXY, NODE_EXTRA_CA_CERTS,
  NODE_USE_SYSTEM_CA, SSL_CERT_FILE/DIR (netLine);
- a fetch Bun refuses for the certificate keeps Bun's words and its
  code and cause, and adds "(UNABLE_TO_GET_ISSUER_CERT: the plugin
  host's TLS didn't verify agent.minimaxi.com's certificate chain
  against the roots it trusts)", so it doesn't read as the vendor's
  fault (throwTLS in host.js).

The plugin side, a China-site account call that can't reach
agent.minimaxi.com going once to agent.minimax.cn, is
opencode-minimax-auth 0.2.3 (magpie-community/plugins#757).

Run:
- Reproduced on xiaomi-gpu (Windows 11, Bun 1.4.2) with the real host
  and the real ROOT store: the real cross-signed USERTrust RSA (valid to
  2028) imported into LocalMachine\Root, then a scratch test through
  bunCommand (NODE_USE_SYSTEM_CA=1 included) fetching
  https://agent.minimaxi.com/: the file as before ->
  UNABLE_TO_GET_ISSUER_CERT, rootsFirst's -> 200. Certificate removed
  after (checked); without it both 200. Also as NODE_EXTRA_CA_CERTS
  alone: cross copy -> UNABLE_TO_GET_ISSUER_CERT; self-signed then cross
  -> 200; cross then self-signed -> UNABLE_TO_GET_ISSUER_CERT; cross with
  AAA either order -> 200. The cross copy in CurrentUser\CA with
  NODE_USE_SYSTEM_CA=1 -> 200 (no shadowing from the system store).
- New tests: TestRootsFirstPutsTheSelfSignedCopyAhead,
  TestBunGetsPastACrossSignedRootCopy (a synthetic cross chain through
  Bun), TestPluginTLSRefusalSaysWhose (through the fake plugin's fetch;
  Bun's message there is the reporter's "unable to get issuer
  certificate"), TestNetLineSaysNoSecret. Green on mote (macOS, Bun
  1.4.2) and on xiaomi-gpu via win-run, with the systemca tests beside
  them.
- Broken by hand on mote: rootsFile without rootsFirst ->
  TestBunGetsPastACrossSignedRootCopy/the_cross-signed_copy_first red;
  throwTLS rethrowing as is -> TestPluginTLSRefusalSaysWhose red
  ("err = unable to get issuer certificate").
- mote, at this tree: gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui, GOOS=windows go vet of internal/plugin ok; go test
  ./internal/plugin ok (111.7s). xiaomi-gpu: go test -run
  'Proxy|CA|TLS|Roots|NetLine|LAN|Network' ./internal/plugin ok.

Not tried: the reporter's own machine and store (what put the cross
copy in their ROOT store is a guess from the error; the host's new log
line will show NODE_EXTRA_CA_CERTS, and the file is in the cache's bun
folder); Bun 1.4.4 (the reporter's; 1.4.2 here); macOS keychain copies
(rootsFirst applies to systemRoots there too, untried with a real cross
copy); Linux takes the distribution's bundle as it is, unchanged.
2026-11-05 16:58:34 +08:00
yetone 97ccb90e88 routing: a group with no rule shows only the example rule's button, no paragraph under Rules (mr_coffee0083)
01a260af4 put a four-line paragraph under Rules in a group with no rule,
the whole setup for a thinking model and coding models spelled out. The
owner's UI rule: no secondary description the layout can carry. The
"Add an example rule" button stays, beside Add a rule and its ⓘ; the
rule it adds says what it is for in its own intent ("planning, design,
or a hard problem to think through"), to the group's last member.

- plugins/routing/client.js: rHint2 says only what holds the rules back
  (one model, routed by hand), as before 01a260af4.
- i18n.js: the paragraph's key out of zh, zh-TW, ja and de.
- routing-rule-example.test.cjs: the line under Rules is hidden while
  the button shows.

Run (wsl-run, magpie-desktop, Node 22, Playwright 1.62.0):
- routing-rule-example, i18n-keys, i18n-en-no-cjk: 27 of 28; the red is
  i18n-keys' "a plugin's words are its own" (#5327, the same on main).

Broken by hand: a "No rule yet" line put back under Rules for a group
with no rule: routing-rule-example 0 of 20, "no line under Rules".
Restored after.

Not tried: the real app window.
2026-11-05 16:35:38 +08:00
yetone a732f3c493 gateway: models of one API other than chat are grouped by id on their route (#5339)
XYenon (Discord) has the same embedding model at several providers and
asked why it isn't grouped the way chat models are. It wasn't even
listed: a fetched list dropped every embedding, rerank, speech and
transcription model, so "embed-1" on /v1/embeddings was a 404 unless a
hand-made group named it.

- catalog: a fetched list keeps those models, tagged with their API
  (Model.Serves, read from the id by ServesOf: rerank, embed/bge-,
  whisper/transcribe, tts-/-tts). Chat() and Live() leave them out, so
  agents' model lists, gateway keys and Routing's chat pickers never
  see them; LiveServing(id, kind) reads them. The live file says
  "kinded": true; a list fetched before this is fetched again once a
  run (autolist), with no schedule needed.
- provider: KindGroup(kind, ref) is made per request, never stored, so
  it is in neither Groups() nor Catalog(). Its id is
  auto-<kind>:<model> ("group/auto-embedding:embed-1"); its members are
  the providers that serve exactly that id for that API, in the order
  they were added, none off, decide-only, serving none, or with the
  model disabled.
- gateway: embeddings, rerank, speech, transcriptions and videos pick
  the group by route (mediaMembers): a bare id is a kind group when
  more than one provider serves it, the group's own id always; a
  hand-made group still works through offChatList. A group is of its
  own API: an embedding model's id on /v1/rerank is a 404.

Run at bd0f33828 + this change, on WSL magpie-desktop (mote was
running another session's full suite):
- go test -tags nogui -count=1 -timeout 45m ./internal/catalog
  ./internal/provider ./internal/gateway: ok, ok, ok (594s). The first
  run was red in three tests that held a fetched list to leaving its
  embedding model out (TestFetchArkMarksVideoModels,
  TestNvidiaModelScopeLiveList, TestTencentTokenHubList); they now hold
  it kept, tagged embedding, and out of catalog.Chat.
- 22 GUI files over the model lists and Routing pickers, both engines,
  every language (group-pick-drawers image-models-hide video-models-hide
  model-kind routing-kind agent-models agent-models-picker
  agent-model-groups agent-models-only-picked gateway-key-models
  gateway-key-groups group-from-model-add unlisted-models
  models-select-all-api provider-add-models provider-detect-models
  routing-rule-models panel-routing-pick fallback-group group-unlists
  settings-groups i18n-keys): 229 of 244 pass. The 15 reds are in six
  files that a control run of those six at bd0f33828 has red the same
  (14 of 56): #4389, #4964, #5332, #4616 and, new, #5357
  (routing-rule-models webkit 390). agent-models webkit zh's opacity
  0.998 was red here only, a fixed 250ms wait: #5358. No GUI asset is
  changed here; the GUI tests stub /api.
- on mote: TestProviderListBeforeSave (internal/gui; the add form's
  list keeps an embedding model out) and
  TestPiModelsAskedOnTheirNativeAPI (internal/agent), ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of catalog,
  provider and gateway on mote at this head, ok.

Rebased then on origin/main d620ff6b5 (one commit, internal/agent and
internal/sessions only), and b63b28958 (one mover min line) after; at
d620ff6b5 + this on mote: go build ./..., go vet
of catalog, provider, gateway, agent and sessions, go test
./internal/catalog and -run 'Kind|Fetch|Nvidia|Tencent|Serving' of
provider and gateway: ok.

Red on the old code: TestKindGroupsServeEachAPIByRoute (embed-1 404)
and TestVideoKindGroupByTheModelsID (404).
Broken by hand, each red, then restored:
- the fetch dropping serves != "" again: TestFetchKeepsModelsOfOtherAPIs;
- the once-a-run refetch forced off: TestKindlessListFetchedOnce;
- KindGroup's disabled-model check removed:
  TestKindGroupHoldsTheExactModel;
- LiveServing asked with "" (any kind): the rerank-by-embedding-id
  check gets 200 instead of 404.

Known gaps, not done here:
- The Routing group editor still offers only chat and image models, so
  a new hand-made group of different ids (bge-m3 / BAAI/bge-m3) can't
  pick kind models: #5352.
- A bare id whose every member is disabled is a 404, not a 403.
- Rerank, Qwen3-Embedding and bge models that sat among a provider's
  chat models before (textModel's words missed them) leave agents'
  lists now. A hand-made group naming one keeps serving.
- /v1/models lists no kind model; the Routing live view may show the
  raw kind id.
Not tried: real vendors' lists and routes; the full ./... suite at this
head (queued on mote after another session's run; reds get issues).
2026-11-05 16:22:31 +08:00
yetone b63b289589 provider: WorkBuddy's mover min is 0.2.22, extra credits keep the account going once the plan's are spent (ferock)
ferock on Discord (2026-11-05, WorkBuddy China): once an account's base
credits were used up magpie moved to another account, though WorkBuddy
goes on serving it on its extra credits. workbuddy 0.2.22
(magpie-community/plugins 36fc59a7) sets the plan's Credits window
aside once it is spent with extra credits left, and Extra credits stops
the account, for the extra credits only the detail lists carry too, as
the summary's own split already did. keepMovedCurrent brings every moved
user up to it.

npm: `npm view --prefer-online --registry https://registry.npmjs.org
@magpie-community/opencode-workbuddy-auth version` answered 0.2.22
before this commit (the publish run is red only on think-tags 0.1.1's
E404, plugins#180).

Run at this tree on mote: go test -timeout 45m ./internal/provider/ ok
(302.7s); gofmt -l clean.
Not tried: a real move to 0.2.22, or any real account with extra credits
(the China desktop sign-in here is refused 401 by the billing meter).
2026-11-05 16:20:56 +08:00
yetone d620ff6b54 codex: an old OpenAI thread follows Codex onto magpie by its row, and back at the Disconnect (Parry_Moody, Cyrus)
Parry_Moody and Cyrus on Discord: Codex on OpenAI through an API key
before magpie, and for two days the Codex app answered every older
conversation "继续聊天未成功: This chat uses openai, but your current
provider is magpie. Switch to openai to continue."

Cause, from Codex's source (rust-v0.167.0-alpha.3.1, same in 0.166.0):
every thread Codex 0.166 starts is paginated (history_mode 'paginated'
in its state-DB row), and for those thread-store read_thread takes the
provider from the row, never the rollout ("Paginated history may contain
only a suffix, so its display metadata lives in SQLite"). The app sends
thread/resume with modelProvider null (ChatGPT.app 26.1021, Kct in
app-shared), so the row alone decides, and load_for_resume refuses a row
other than the current provider. bringOver moved threads by rewriting
files: plain ones in place, packed ones only from the last 30 days and
128 MB a sync. An older or packed OpenAI thread kept an openai row.

Now sessions.RetagPagedCodexThreads moves every paginated thread on a
provider by its row alone: any age, packed or not, an id of any length,
no file read, written or copied. Each thread is held by its writer lock
(an open one stays: its writer would write the provider back), one
written to in the last minute waits, 200 rows a transaction. It runs
after the in-place relabel in bringOver, bringBack (so a Disconnect no
longer copies a whole paginated history to the trash), bringOfficial and
bringBeside, and giveBeside by ids (RetagPagedCodexThreadIDs). Legacy
threads keep the file path. The Sessions page lists a paginated thread
on its row's provider (codexPagedProviders, memoised on the DB and WAL
stamp), so it isn't offered a Move it had.

Run:
- real codex-cli 0.166.0 (npm latest) on mote in a sandbox CODEX_HOME,
  a fake Responses server: a thread started with OpenAI (API key,
  openai_base_url) is paginated, row openai; with model_provider magpie
  `codex exec resume` failed with exactly "This chat uses openai, but
  your current provider is magpie" (modelProviderMismatch). After
  magpie's RetagPagedCodexThreads on that home (a throwaway test calling
  it, not committed) it resumed and answered; the rollout still names
  openai. Reversed (magpie -> openai) with config back on OpenAI, it
  resumed again. The first retag try moved nothing: the rollout had been
  written <1 minute before, the ActiveWindow skip, as intended.
- mote: gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  for ./internal/sessions ./internal/agent; go test ./internal/sessions
  ./internal/agent: ok (sessions 20.1s, agent 194.4s) on mote, plus go vet on darwin, linux -tags nogui and windows

Broken by hand:
- RetagPagedCodexThreads returning nil (the old behaviour):
  TestCodexPagedThreadsFollowByRow red (250 packed 90-day-old threads
  "on openai, want magpie"), TestRetagPagedCodexThreads red.
- the writer-lock hold skipped: TestCodexPagedThreadsFollowByRow red,
  the open thread moved to magpie.

Not tried: the Codex app GUI itself (the app goes through the same
app-server thread/resume, whose modelProvider it sends null); Windows
and Linux runs (vet only). Codex rebuilds a row from its rollout when a
search listing reconciles it, which puts a retagged thread back on its
file's provider until the next sync; not seen, read from the source.
A legacy thread packed over 30 days still waits for Sessions' Move.
2026-11-05 16:11:14 +08:00
yetone bd0f338282 hermes: a Claude model goes on anthropic_messages, so cache_ttl 1h works; the user's api_mode stays (#5315)
cherish_onlyy (#5315): magpie wrote providers.magpie as chat_completions at
the gateway's /v1 for every model. On chat completions to a custom provider
Hermes sends no cache marks (anthropic_prompt_cache_policy gives
(False, False)), and the marks magpie adds for a Chat client last five
minutes, so prompt_caching.cache_ttl: 1h never reached the vendor. They set
api_mode: anthropic_messages and the gateway's root by hand and got 1h
writes; magpie's next sync or connect wrote chat_completions at /v1 back.

Hermes takes api_mode per providers entry, never per model
(_resolve_named_custom_runtime, hermes_cli/runtime_provider_custom.py;
aliases in config_providers.py's _API_MODE_ALIASES, transport read when
api_mode is absent). On anthropic_messages its adapter strips a trailing
/v1 and the SDK adds /v1/messages, and for a "claude" model on a
third-party gateway it puts its own system_and_3 marks at the configured
ttl (agent/prompt_caching.py, read at d914e233). So magpie now writes two
entries, as dsh already splits its routes:
- magpie: chat_completions at gw/v1, every model not on Messages;
- magpie-anthropic: anthropic_messages at gw (no /v1), the models whose
  native API is Anthropic's Messages and not Responses (hermesOnMessages).
model.provider follows the picked model (hermesRoute), in every profile;
a sync moves a Claude model magpie had set under "magpie" onto
magpie-anthropic, and drops that entry when no model is left for it.
Disconnect takes both out.

The user's own value: an api_mode or transport on one of magpie's entries
that isn't the one magpie writes there (by Hermes's aliases, so "openai"
is still magpie's chat) is the user's (hermesModeIn). It stays through
sync and pick, base_url follows it, and on "magpie" that entry then
serves every model and no magpie-anthropic is written, which is the
reporter's set-up exactly. magpie only ever wrote chat_completions into
providers.magpie, so nothing earlier is mistaken for the user's.

Tests:
- TestHermesClaudeGoesOnMessages: Claude on magpie-anthropic (mode, base
  without /v1, models), deepseek stays on magpie at /v1, Get/Check/Drift
  clean, a pick moves model.provider back, a bot profile too, Disconnect
  removes both entries from every profile.
- TestHermesSyncMovesClaudeOntoMessages: an existing connected config is
  moved on sync, and back when the provider goes chat-only.
- TestHermesKeepsTheUsersAPIMode: api_mode anthropic_messages at gw,
  transport: anthropic, codex_responses: each survives two syncs and
  two picks, base_url kept; api_mode: openai is still magpie's.
- internal/gateway TestHermesHourMarksReachTheVendor: a Hermes-shaped
  /v1/messages turn with 1h marks reaches the Anthropic upstream with
  every mark at 1h; the same turn on /v1/chat/completions goes at 5m.
  This one passes on the old code too: the gateway already passed the
  marks through; it guards that and records why the mode matters.

Run (mote-run, this tree):
- go test ./internal/agent/ -count=1 -timeout 45m: ok
- go test ./internal/gateway/ -run 'TestHermesHourMarksReachTheVendor|TestResponsesToClaudeMarksLastAnHour' -count=1: ok
- go vet ./internal/agent/ ./internal/gateway/, GOOS=linux and GOOS=windows: ok
- gofmt -l: clean
Broken by hand:
- hermesSplit returning (nil, false), the old one-entry behaviour:
  ClaudeGoesOnMessages, SyncMovesClaude and the openai-alias case fail.
- hermesModeIn never reporting the user's mode: all three
  KeepsTheUsersAPIMode cases fail at "sync".
Not tried:
- Hermes itself: it was not run (running it under a temp HERMES_HOME
  rewrites the live launcher); its behaviour is read from its source at
  d914e233. No real 1h cache write was measured against a vendor.
- Group models whose members are all Claude, and Claude Code sign-ins
  (no Native API), stay on chat_completions; GPT on codex_responses is
  #3080.
- Windows and Linux runs of the agent package (vet only).
2026-11-05 15:53:16 +08:00
yetone 465928bcce backup: the default backup folder says a reinstall takes it too; docs say how to keep magpie on another disk (two_2025.)
two_2025. on Discord asked to pick magpie's config folder: on Windows it
is on C:, and a system reinstall without a backup loses everything.
Two ways already exist and neither is said where the user looks:
automatic backups can go to any folder (Settings > Sync and backup >
Backup folder > Change...), but default to auto-backups inside magpie's
own folder, lost with it; and portable mode (a data folder beside
magpie.exe, internal/appdir) keeps everything on another disk. So no
new data-folder setting: moving the live folder would have to repoint
the library's links, agents' configs and a running gateway, and its
pointer would sit on C: and be lost on the same reinstall.

- AutoStatus reports inside: the backup folder is settings.Dir() or in
  it, letter case aside off Linux. The Backup folder row then says a
  reinstalled system or a lost disk takes these backups too, and to pick
  a folder on another disk or a cloud drive's (en, zh, zh-TW, ja, de).
  A folder picked elsewhere says nothing new.
- docs/start (en, zh, ja) #data-folder: pick a backup folder on another
  disk and restore from it after a reinstall, sync for the keys, or run
  portable from D:\magpie with a data folder beside magpie.exe.
- docs/subsystems/sync-backup.md names the field and the tests.

Run (mote, at this tree on origin/main 5db1b07ed):
- go test -count=1 ./internal/backup/ ./internal/gui/: backup ok; gui
  red only in TestMainWindowCorners/macOS_26_SDK (#3949, mote's macOS 27).
- node --test auto-backup, i18n-keys, i18n-en-no-cjk, sync-not-backup:
  49 of 50; the red is i18n-keys "a plugin's words are its own", red on
  main since 73c98ebc2 (#5327, #5332). auto-backup passes in Chromium and
  WebKit, 1100 and 420px, all five languages.
- node --test site/*.test.mjs: 84 of 84.
- GOOS=windows, GOOS=linux and native go vet ./internal/backup/; gofmt -l.
- Windows (win-run on xiaomi-gpu): go test ./internal/backup/ ok
  (TestAutoInsideMagpiesFolder with the upper-case path);
  ./internal/appdir/ red only in TestFoldersJoinedOnce (#4846, untouched).

Again at this commit, rebased on origin/main 435f04151 (mote): go test
./internal/backup/ ok; auto-backup.test.cjs 22 of 22 and i18n-en-no-cjk
ok.

Broken by hand: AutoStatus with inside always false makes
TestAutoInsideMagpiesFolder red ("default folder ... inside false");
the JS line dropped makes auto-backup.test.cjs red (webkit 1100px zh,
zh-TW).

Not tried: the real app on Windows with a backup folder on another
drive and a restore after a reinstall; a portable copy moved to D: from
an installed one (the docs restore a backup into a fresh portable copy
rather than copying the folder, whose library links point at the old
one). Full suite runs after the push.
2026-11-05 15:30:11 +08:00
yetone 435f041514 gateway: an account near its usage cap takes one turn at a time (dyzdyz010)
dyzdyz010 on Discord: two Claude Code accounts, each capped at 90% of its
five hours, Stop at the caps and Check usage near the cap on, and both
read 100%. Routing holds a capped account by its last reading. Turns sent
together (an agent's subagents, several agents) were each planned on the
same reading, so an account a point under its cap took every one of them,
and went as far past it as they used between them. Check usage near the
cap reads the usage again before planning, but every turn read the same
figure: each saw 89%.

- gateway (cap_near.go): within 5 points of a usage cap (carefulNear),
  an account takes one turn at a time. A turn that finds it busy goes to
  the next candidate first, the account moved behind them once; the last
  candidate waits for it. Once its turn comes capHeld judges it again, by
  what the reply before it said (codex.rate_limits, rate_limit_event), or
  by the usage read again when that reply said nothing (at most
  carefulWait). Held, it is passed over, or the agent gets the cap's 429
  when nobody is left. The cap is passed by one turn at most.
- A conversation kept on its account by Stays: Strict takes no turn there
  and goes on past the cap, as before. Neither does an account already
  held when its try begins, let in past its cap on purpose (a Codex reset
  spent for it, its credits).
- docs: gateway-routing.md's capHeld step, providers-accounts.md's cap
  sentence.

Run (wsl-run, magpie-desktop, Go 1.26.8):
- go test -tags nogui -run 'NearCap|FarFromCap' -v ./internal/gateway:
  the five new tests pass.
- go test -tags nogui -race -count=20 -run 'NearCap|FarFromCap'
  ./internal/gateway: ok.
- GOOS=linux go vet -tags nogui ./internal/gateway, GOOS=windows go vet
  ./internal/gateway: ok. gofmt -l: nothing.
- go test -tags nogui -timeout 30m -run
  'NearCap|FarFromCap|CodexNoCredits|Reset|Strict|Cap|Credits'
  ./internal/gateway: ok.
- go test -tags nogui -timeout 45m ./internal/gateway ./internal/provider,
  at this tree rebased on 248853225: ok (gateway 604.9s, provider 90.9s).
- at the pushed head, rebased on 5db1b07ed: the vets ok, and -run
  'NearCap|FarFromCap|CodexNoCredits|Reset|Strict|Cap|Credits|Group'
  ./internal/gateway ok.

Broken by hand (each restored after):
- the whole near-cap block off (`&& false`): TestNearCapTakesOneTurnAtATime
  red (acct-1 took all 4 turns), the two wait tests never saw a turn
  waiting, and TestNearCapClaudeAccountsTakeOneTurnEach red (both turns on
  the account near its cap, the spare never run).
- nearCapAgain a no-op: TestNearCapReadsAgainAfterASilentReply red
  (200, 200).
- capHeld's second look off: TestNearCapWaitsThenHolds and
  TestNearCapReadsAgainAfterASilentReply red.
- the first full run, before the strict exception, had
  TestStrictAffinityGoesPastTheCap red: the strict conversation got the
  cap's 429. The second, without the held-on-entry exception, had
  TestCodexNoCreditsSpendsAReset and
  TestCodexNoCreditsResetAfterTheLastRefusal red: the account a reset
  was just spent for was held again. Both fixed in this commit.
- An unrelated red in the first run,
  TestZCodeTrialRefusalRestsTheTrialAlone/trial_edge_block ("no plugin
  signs in to zcode"), passes alone and was green in the last run; filed
  as #5335.

Not tried: a real Claude or Codex account near its cap; plugin accounts
(their caps go through the same candidate loop, untested here). One turn
alone can still pass a cap by what it spends: an Opus turn on a Pro plan
can take several points of the five hours.
2026-11-05 15:16:13 +08:00
yetone 01a260af46 routing: a group with no rule says what a rule is for, with an example rule (mr_coffee0083)
mr_coffee0083 on Discord asked how to set up a group where one model
thinks and several others write code: the group editor's rules part
had no word on it and no example to start from.

- plugins/routing/client.js: a group of two models or more, not routed
  by hand, with no rule yet, says under Rules that every turn goes by
  the routing, and how one model thinks while others write code: the
  coding models in a group of their own added first, the thinking model
  after it, routed In order, and a rule sending planning and hard
  problems to the thinking model. "Add an example rule" beside "Add a
  rule" adds that rule, its intent filled in ("planning, design, or a
  hard problem to think through"), for the editor to finish. Neither
  shows once the group has a rule, or for one model, or routed by hand.
- i18n.js: the three strings in zh, zh-TW, ja and de, with each
  language's own word for In order.
- routing.css: the button wraps and reads in the accent colour, as the
  text buttons beside it.

Run (wsl-run, magpie-desktop, Node 22, Playwright 1.62.0):
- routing-rule-example.test.cjs (new): 20 of 20, chromium and webkit,
  en zh zh-TW ja de, at 1100 and 390 wide. The hint and button show,
  nothing is past the editor's side, pressing adds one rule to opus
  with the translated intent, Save posts it with the classifier Jev;
  after a reload a group of one model, or routed by hand, shows
  neither.
- the 16 i18n-*, routing-rule*, routing-rules-*, group-editor-* and
  routing-classifier* files: 190 of 221. The 31 reds are in
  i18n-keys (#5327, #5332), routing-rule-drag, routing-rule-models,
  routing-rule-remove and routing-rules-line (#4585, #5088, #3789,
  #4112, #4560). Those five files run alone, one at a time, at clean
  origin/main 9d143eaca: 24 reds there, 27 here, the same tests with
  different subtests each run.
- at the pushed head, rebased on 5db1b07ed (which changed
  routing/client.js): routing-rule-example 20 of 20; i18n-keys red
  only by #5327, the same as main.

Broken by hand: rTry never shown (hidden = true): the new test 0 of
20, "the example's button shows". Restored after.

Not tried: the real app window; mr_coffee0083's own groups.
2026-11-05 15:16:13 +08:00
yetone 5db1b07ed9 gui: the tray panel's Usage tab is drawn again in Settings' currency picked alone, and when its read came before the state (dLdgKyRd)
dLdgKyRd on Discord, v0.1.3025 on macOS: the menu-bar panel's Usage tab
said ≈$12.36 while the window's Usage page said ≈¥82.61 for the same day.

v0.1.2913 (2ba044aa6) made the Mac panel's page hear that it was hidden
and shown, so a reopen reads the state again. Nothing since changed that
path; its redraw never came. applyPrefs drew the panel's Usage tab again
only when the number units changed. A currency change called the Usage
page's costs hook, which redraws the page and Routing, not the panel's
tab, which keeps its own read. 2913's test picked ¥ and 万 / 亿 together,
so the units' redraw hid it. And the first applyPrefs (applyPrefs.painted
false) redrew nothing: the panel opened on its Usage tab reads its usage
beside /api/state, and when that read came first it drew $, which no
reopen, focus or quiet read of the same figures drew again.

applyPrefs now redraws the panel's Usage tab, when it has drawn, on any
change of currency, rate or units, the first settings included.

Tests: panel-units-follow.test.cjs gets "follows Settings' currency
picked alone": first open with ¥ set and /api/state answering 400ms after
the usage read; ¥ picked alone, then a reopen; $ picked again, then a
focus (Settings changed while the panel was open); and the panel opened
on Agents, ¥ picked, its Usage tab picked after. zh, en, zh-TW, ja, de, at
380px and 300px, Chromium and WebKit.

Run on mote (macOS 27.2), at this tree:
- node --test panel-units-follow (the new test 20/20 subtests, the 2913
  one 12/12), panel-usage, currency, number-units, window-visibility,
  i18n-en-no-cjk: 62/62, at the rebased head (parent a2f7ed2e8)
- go test -count=1 ./internal/gui/ (core and app.js budgets included,
  app.js 1,311,133 of 1,316,874): every test ok but
  TestMainWindowCorners/macOS_26_SDK, red alone at a2f7ed2e8 too (#3949)
- go vet ./internal/gui/, GOOS=linux go vet -tags nogui, GOOS=windows go
  vet: ok; gofmt -l: nothing
- every panel-*, usage-*, currency, number-units, window-visibility and
  i18n file before the rebase: 1462 of 1495; the 33 reds are in
  i18n-keys (#5327, #5332), usage-agents-hide and usage-fold (#2399) and
  usage-ledger (#5048), and the same four files are red alone on
  origin/main 2891ec7a7 (34 there)

Broken by hand: the new test against the old app.js (a copy of the
assets, MAGPIE_PANEL_UNITS_ASSETS): 0 of 10 in each engine, "first open,
the state after the usage" (≈$26.40); with the first-open part left out,
"reopened after ¥ was picked alone" red in zh and en. The tab part passes
on the old code too: it is a guard, not the bug.

Not tried: the real tray panel by hand on a Mac, nor on Windows or Linux;
dLdgKyRd's exact sequence (which of the paths they hit) isn't known.
2026-11-05 15:09:33 +08:00
yetone a2f7ed2e81 gateway: a hand-made group of embedding, rerank, speech, transcription or video models is served when its providers have picks
XYenon on Discord: a routing group of embedding models was a 404 on
/v1/embeddings. Picks are of chat models, so membersFound dropped every
member of a provider with picks as unpicked (#3911). 1d8658abc fixed this
for drawings with FindDrawingGroup. The sibling routes still used
FindGroup: retrieval (embeddings, rerank, speech, transcriptions and
translations, which all go through serveRetrieval) and /v1/videos.

provider.FindGroupAlso is FindGroup with an "also keep" test, and
FindDrawingGroup now wraps it. The gateway's mediaMembers keeps a member
that is not on its provider's chat list (offChatList), so a chat model the
user unticked stays out. mediaGroupFirst resolves the group's first such
member, because Resolve reads the agents' catalog and finds none of them.
The routing doc says the same.

Auto groups by kind (non-chat ids never reach autoGroups) are #5339 and
are not in this commit.

Run on mote:
- go test -count=1 -timeout 45m ./internal/gateway ./internal/provider:
  ok (gateway 823.6s, provider 180.0s)
- GOOS=linux and GOOS=windows go vet of the two packages: ok
- gofmt -l: clean
- No GUI file changed, so no GUI run.
- At the rebased head (on origin/main 2891ec7a7: 6 commits, balance_probe and
  others, none in group, retrieval or video code): go test -run
  'MediaGroup|VideoGroup|ImageGroup|Retrieval|Embedding|Speech|Transcri|Rerank|Group'
  ./internal/gateway ./internal/provider: ok; gofmt -l: clean

Red on the old code: with media_group.go removed and the three routes back
on FindGroup, TestMediaGroupOfProvidersWithChatPicks fails with 404 "magpie
knows no model "group/emb"" and TestVideoGroupOfProvidersWithChatPicks with
404 for "group/vid". In both, the members' providers have picks that don't
name the embedding/speech/video ids.

Broken by hand: offChatList made to return true lets the unticked chat
model in, and the test goes red ("a group of a chat model the user unticked
was asked: 400 ... chat-model is not an embedding model").

Not tried: a real vendor's embeddings or speech through a group (fakes
only), plugin-served embedding models, and the full suite (it runs after
the push).
2026-11-05 14:57:43 +08:00
yetone 2891ec7a7b docs: Trae / Trae CN through magpie, in the start page's FAQ (en, zh, ja)
A user (tz_188, Discord) confirmed Trae works with magpie this way:
the gateway's address in Trae's custom model settings, Share on local
network (局域网共享) turned on, and a gateway key as the API key. Trae keeps
custom models in the Trae account, server-side, so magpie can't set it up
in one click, and Trae may not reach 127.0.0.1. The FAQ entry (#trae)
says that, hedged as a user report, and links Remote magpie's #share.

Run: node --test site/*.test.mjs via mote-run at this tree, 84 of 84 ok.
(Run with -C site it is 83 of 84: the sponsors test reads ../README.md,
which -C site doesn't copy; not a red.) No Go test reads site/public/docs
(pluginrt's tree walk skips site/), so none was run.
Not tried: Trae itself; the steps are the reporter's, not reproduced here.
2026-11-05 14:55:06 +08:00
yetone 06508f2bf5 library: a stdio server that refuses home is checked again in a project folder (fff)
math_milian on Discord: fff-mcp worked in their agent, but Library → MCP
said "fff exited (1)". fff-mcp indexes the folder it starts in and
refuses a file system root or home ("Can not run certain FFF features in
a file system root or home directories"), exiting 1. magpie's check
starts every stdio server in home (#1727), where agents never start it;
they start it in their project.

When a local check exits, it now starts the server once more in an empty
project folder of its own (removed after). If it answers there:
- given to agents that start it themselves (no router, not Codex on
  magpie, or hub "direct"), the row shows its tools, and the tooltip says
  it exits in home, with what it said;
- run by magpie in home for agents (the MCP router, or Codex on magpie's
  RunPath), the row says "won't start in home" (why "home"), and its
  editor offers "Through the MCP router" to turn off, even with the router
  off, so each agent starts it in its project.
A server that exits in both places reads as before. WSL checks are
unchanged. healthKey (Go and client.js) now includes whether magpie runs
it in home, so a router change checks it again. startServer takes the
dir; the hub and the RunPath runner still pass home.

Run:
- go test -count=1 -timeout 30m ./internal/library on mote: ok (159s).
- TestCheckServerThatRefusesHome red on the old code: State error, Why
  exited, Code 1, with fff's text, the reporter's case.
- Real fff-mcp 0.11.0 (cargo-built on mote, sandbox HOME resolved through
  /private/var) via CheckServer: direct ok, 3 tools, Project; router on,
  Why home, Code 1.
- go vet ./internal/library ./internal/gui (darwin), GOOS=windows and
  GOOS=linux go vet ./internal/library on mote; gofmt -l clean.
- GUI on mote, Chromium + WebKit: mcp-home-health (new, every language,
  1100 and 390), library-mcp-health, mcp-hub-direct, library-mcp-hub,
  library-mcp-health-wsl, i18n-en-no-cjk, i18n-keys: 91 of 92 ok. The red
  is i18n-keys "a plugin's words are its own" on search_row_archive_test.go's
  "View routing", red on main since 73c98ebc2 (#5327, #5332).

Broken by hand: the new test run against the old mcp_check.go (red as
above).

Not tried: Windows and WSL runs; a real agent session through the router
or Codex's RunPath; the whole GUI suite.
2026-11-05 14:50:02 +08:00
yetone 24d315fa85 routing: the request list can be grouped By key, each gateway key's calls under its name
acezan (#help on Discord) asked to see API use on the Routing page the way
it shows each agent's, live and in the history. The list's group bar gets
a third button, By key, after By request and By session. It shows once
Settings has a gateway key (/api/caller-keys). Each head is the key's
current name (else the name the route kept, else its id), with its agents
dim beside it and the usual count, tokens, in progress and cost. Calls with
no key (from this computer, or kept before 75fb76186 named the key) go
under "No gateway key". A row's tooltip names its key too. The choice is
kept in localStorage (magpie.routingGroupBy), and the old
magpie.routingBySession still works. Text added in zh, zh-TW, ja and de.

click-scroll counted two group buttons and now counts three, with By key
hidden when there is no key. purpose-filter clicked .last() for By
session and now picks [data-by="session"].
reference.md and gateway-sessions.md describe By key and Route.CallerKey.

Run (WSL magpie-desktop: mote's disk is full, ld errno=28):
- routing-by-key.test.cjs: 20/20 in chromium and webkit, in en, zh,
  zh-TW, ja and de, at 1100 and 420. Red 20/20 with client.js and
  i18n.js at the parent (waits for By key).
- 254 Routing-related GUI files at concurrency 4. Every red was rerun
  serially, with this change and at origin/main 73c98ebc2.
  - Only purpose-filter and click-scroll were this change's; both are
    fixed above and green now.
  - The rest are red at main too, or flake there: #5045 call-headers,
    #4385 click-scroll wheel, #5049, #1745, #4689, #3402, #4623, #1937,
    #3773 idle-frame (10 frames, passes on rerun), plus routing-rule-*,
    zero-priced-free and others under #4121/#4400.
- Windows: go test ./internal/gui. Reds are #4115/#1827, plus
  TestPluginAgentMissingSaysSo and TestGatewayHeldByAContainer, red at
  main too and filed now as #5324.
Not tried: the real app, the whole GUI suite, the tray panel (no By key
there). A key renamed after a row was drawn shows its old name in that
row's tooltip until the row is drawn again.
2026-11-05 14:47:18 +08:00
yetone 5fe4c48df9 gateway: a route names the gateway key it came with, by id and name
The Routing page is to show each gateway key's requests as it shows each
agent's (acezan on Discord). A route kept the key's id only for
sessionLatest, unexported, so neither the trace nor the routing history
said it. Route.CallerKey and CallerKeyName are now in its JSON: the id and
the name the key had, never the secret. A request with no key names none,
and so does every route the history kept before this.

The trace is told to this computer alone (/v1/magpie/trace is loopback
only, /api/gateway/trace the GUI's), and /v1/magpie/route sends
sessionRouteOf's projection, which carries neither field.

Run (wsl-run, magpie-desktop; mote's disk was full, its link failed with
errno 28): go test -count=1 -run
'TestTraceNamesCallerKey|TestSessionRoute|TestCallerUsage|TestRejectedRequest'
./internal/gateway ok. Broken by hand: with trace.go, unrouted.go and
session_route.go back at c2b8814e7, TestTraceNamesCallerKey fails ("the
key's route doesn't name it").
2026-11-05 14:47:18 +08:00
yetone b95a78d43c gui: the editor says where magpie found a relay's balance, with Use
A relay added by hand with no Balance URL has its balance found by
magpie, but nothing in the window said so. A user who saw a wrong amount
couldn't tell it was a guess or where to put it right. Under the Balance
URL, in Advanced, the editor now shows "Found by magpie: <url> <field>"
with Use, which copies the query into the Balance URL and Balance field
to be changed. Check balance draws the line again from what it found,
and when it found nothing it says "No balance at /v1/usage or
/api/usage/token" instead of "No Balance URL to ask".

/api/providers carries balanceFound and balanceFoundField. The check's
reply carries looked, found and foundField. The line is in balfound.js,
loaded when the editor draws a relay's balance with no Balance URL. Its
one call and the check's text in app.js are paid for by three provider
editor comments cut down, so there is no raise: the core is 1,533,452,
350 under its budget. zh, zh-TW, ja and de are translated.

Run on mote:
- go test -count=1 -timeout 45m ./internal/gui: ok, except
  TestMainWindowCorners/macOS_26_SDK, mote's macOS 27 (#3949).
- GUI, both engines: balance-found (new, 900px and 420px, every
  language) 22/22. balance-url-first, balance-fix, balance-method,
  balance-field-default, key-balance-card and old-webkit: ok.
  i18n-keys: "a plugin's words are its own" is red (#5327), as on main.

Broken by hand: with the import taken out of app.js, balance-found is
0/11 in chromium.

Not tried: the whole GUI suite at this head (run after the push), and
the real app with a real relay.
2026-11-05 14:46:23 +08:00
yetone 464cc30f91 provider: a relay's found balance query is looked for again each day
A relay added by hand with no Balance URL has its balance found at
/v1/usage or /api/usage/token (248853225). What was found was kept until
magpie quit, so a relay that moved to other software went on being read
at a query that may now mean something else. A query found is now kept
24 hours and then looked for again. If the look finds nothing, the old
query stays when it turns the key away (401/403, so the card says the
relay refused the key instead of going) or the relay can't be reached.

BalanceFound tells the editor where the balance was found, so a wrong
amount can be put right (the GUI commit after this one).

Run on mote:
- gofmt -l: nothing.
- go vet, GOOS=linux go vet -tags nogui and GOOS=windows go vet of
  ./internal/provider and ./internal/gui: ok.
- go test -count=1 -timeout 45m ./internal/provider: ok.

Broken by hand:
- A found query kept for ever again: TestFoundBalanceLookedForAgain fails.
- The kept-on-refusal case taken out: TestFoundBalanceKeptWhenTheKeyIsRefused
  fails.

Not tried: a relay that really moved to other software.
2026-11-05 14:46:23 +08:00
yetone 2488532257 provider: a relay added by hand finds its balance where relays tell it
The same relay user had added yylx.io by hand: no Balance URL, so no
balance anywhere until they deleted it and imported it from the relay's
site, whose link names the query (小鱼 of yylx.io, WeChat, 11-05).

A provider added by hand, or from a relay's preset, with a key and no
Balance URL, at no host magpie knows a query for, is now asked at its
base's origin: /v1/usage (sub2api, $remaining), then /api/usage/token
(new-api, $data.total_available / 500000), with the key's own auth and
headers, as balanceRead asks. A 200 whose field reads is the query. It is
kept in memory per origins and key (the key hashed), and so is finding
none, for 6h (5 min when the relay can't be reached), so a poll asks once.
Nothing is written to providers.json. The card, Check balance and
`magpie provider show` (BalanceQuery) read the found URL; none found is
no card, and the editor's "No Balance URL to ask".

Never asked: a vendor's or local server's preset host (api.openai.com,
api.anthropic.com, api.deepseek.com…), this computer, opencode.ai and
api.cline.bot, a plan whose windows are its card. The subsystem page has
the row.

Run (mote, go1.26.8):
- go vet ./internal/provider; go test -count=1 ./internal/provider: ok.
- The new tests: a sub2api relay read at $10472.14 with /v1/usage asked
  3 times over the probe, a Balance and a card poll; a new-api relay found
  after /v1/usage's 404; a relay answering HTML 200 everywhere has no
  card and is asked twice in all over two polls; the hosts left alone.

Broken by hand: with the probe taken out of balanceRead, the three
HandAdded tests fail (balance "" false; a card with no balance).

Before this, TestOpenCodeZenSaysItTellsNoBalance caught the probe asking
opencode.ai for OpenCode Go and a custom inference provider; those hosts
are left out now.

Real use (mote, sandbox HOME holding only the owner's yylx.io provider,
copied with its key, removed after): `magpie provider yylx-hand` (no
preset) and `magpie provider yylx` (鱼鱼连线's preset, Global region)
both show "balance $19.97 from https://global.yylx.io/v1/usage
$remaining".

Not tried: a real new-api relay; a new-api relay that routes unknown /v1
paths to its upstream.
2026-11-05 14:19:28 +08:00
yetone e2aaf21f73 gui: a custom provider's Balance URL is asked above its balance token
A relay's user wanting their balance opened the editor and found
"Account balance" asking for a new-api System Access Token or a sub2api
JWT and user id, while the setting that worked (Balance URL
https://app.yylx.io/v1/usage, token left empty) sat at the foot of the
form under More endpoints (小鱼 of yylx.io, WeChat, 11-05).

The Balance URL and Balance field now sit right above Account balance in
Advanced (balSlot), and Advanced opens when a Balance URL is saved. The
token's hint says first to leave it empty, that most relays tell a key's
balance at the Balance URL above (sub2api's …/v1/usage, new-api's
…/api/usage/token), and only then what the token is for. zh, zh-TW, ja
and de have it. In Advanced's narrower column the method picker and URL
wrap, so the URL keeps at least 120px at 420px.

Run (mote, Playwright 1.62.0):
- balance-url-first (new), balance-fix, balance-method and the other
  balance-* files: 186/186 in Chromium and WebKit, at 900 and 420px,
  en/zh/zh-TW/ja/de.
- The whole GUI suite, cut short after 733 tests (it ran for hours
  beside other sessions): red only in account-eye chromium en/ja (#5052)
  and account-weight webkit ja 390 (#4644), both open and in files this
  change doesn't reach.
- i18n-keys: "a plugin's words are its own" red, the same on main
  (#5327).

TestCoreScriptBudget: the hint took the core 494 bytes over its budget;
five comments in the provider editor were cut (573 bytes), so it is 79
under, with no raise.
- go test ./internal/provider ./internal/gui ./internal/cli ./internal/tui
  at the rebased head: ok but internal/gui's TestMainWindowCorners on
  mote's macOS 27 (#3949, open) and the budget before the cut.

Broken by hand: balance-url-first on the old app.js fails at "a saved
Balance URL opens Advanced" (chromium).

Filed: #5336, Advanced is 46px too wide at 420px on main (the Rests
tick's label); the new test checks only the balance rows for it.

Not tried: the real app on Linux (WebKitGTK); no motion or new API here.
2026-11-05 14:19:28 +08:00
yetone 373cab2b08 provider: the Cursor mover's min is 0.2.41 (plugins#706)
cursor 0.2.41 (plugins#706, ooboqoo): a short session whose parent Run
waits on tool results no longer loses that step's usage. The later Run
of the conversation collects it, and it is counted once. Raising the
min makes keepMovedCurrent bring every moved Cursor user to it.

npm view --prefer-online @magpie-community/opencode-cursor-auth version
gave 0.2.41 before the change and again right before this commit.

Run on mote at this change on 294768599 (origin/main, unchanged at
push): go build ./... ok; GOOS=linux and GOOS=windows go vet
./internal/provider ok; go test -timeout 45m ./internal/provider ok
(139.9s). gofmt -l internal/provider is empty.
Not broken by hand: the change is a version string and its note.
Not tried: a real Cursor account through magpie on 0.2.41.
2026-11-05 14:19:12 +08:00
yetone 2947685999 claude: an interactive run's calls keep the conversation they answered when their line comes late
kay20475 on X (magpie 0.1.3005, local magpie -> shared server magpie ->
Claude subscription, interactive bridge): a Claude Code sub-agent's
requests on one account read 99%, 6%, 6%, 99% from the cache; the two 6%
requests were 169.1k each, 35s apart, about 3s long with a short reply.
That is the shape of Claude Code's AgentSummary: every ~30s it sends the
sub-agent's conversation with its last results and "Describe your most
recent action in 3-5 words", while the sub-agent's own run has already
taken those results.

Cause. Such a request finds no run waiting on its calls and should go on
in a branch of the sub-agent's run's session (branch). branch takes it
only when the conversation stored on the call's line (callLine.told)
matches the one before the reply. park stored that only on lines it
already had. The interactive mode streams a reply first and reads its
session lines from the file afterwards (118-162ms after the call). So the
run parked before noteLines had the call's line, and the line came in
with no conversation. The next park then gave it the next request's
conversation. branch returned nil, and every AgentSummary (and every
fork directive) was told the whole conversation in a new Claude Code,
pasted as one text block. A single block can't match the cache beyond
the tools and system prompt, so 6%, and the next summary missed the same
way because its tail differs.

Fix. park also keeps the conversation for each call the client was shown
(r.shown), as a line with no uuid yet. noteLines keeps it when the line
comes, and branch skips lines with no uuid.

Test: TestClaudeForkBranchesOffTheLeadsSession/interactive now has the
fake write the call's session line after the reply's stream, once the
result is handed over, so after the park, which is the real order.
Broken by hand: with this test and the old claude_subscription.go on
mote, it fails ("told it whole", want "branched at line-...").

Run on mote at this tree (base 4cb7159f1): gofmt -l clean; go vet
./internal/gateway on darwin, GOOS=linux and GOOS=windows ok; go test
-timeout 45m ./internal/gateway (679s) ./internal/claudetui
./internal/claudebridge all ok. The fork/side-question/cut tests
-count=3 ok. The full ./... suite and the GUI suite were not run (no
GUI or other-package change).
Rebased on 351844594 (GUI only since 4cb7159f1): go test -count=1 -run
'Claude|Fork|Branch|Subscription' ./internal/gateway ok (77s) on mote.

Not tried: a real Claude Code AgentSummary against a real account. The
reporter's requests are matched by shape only (size, timing, short
reply). Ruled out: the remote-magpie hop. The bridge doesn't key runs on
headers (only anthropic-beta for safeguards), so losing
x-claude-code-session-id can't move a turn off its run. Not fixed here: a
sub-agent loop with no plain reply, told anew in the interactive mode, is
still pasted as one text, so a new run for it reads only tools+system.
2026-11-05 14:05:54 +08:00
yetone 3518445947 gui: the self-remote notes are shorter, the core back under its budget
1826c4bd9 (This magpie, Use it anyway) left the core's scripts at
1,534,182 bytes once rebased over 5b9bfe407, over their 1,533,802
budget (TestCoreScriptBudget red on main). The two notes' English keys,
in app.js and as each language's key, are cut, and a comment goes; the
translations say the same. No budget raised.

Run (Linux WSL, at this tree on origin/main 4cb7159f1):
- go test -tags nogui -run 'Budget|I18n' ./internal/gui: ok.
- remote-self.test.cjs and i18n-*.test.cjs: 23 of 24; the red is
  i18n-keys "a plugin's words are its own" on plugins/usage's "View
  routing", which 73c98ebc2's search_row_archive_test.go says too, not
  this change.

Not tried: the whole GUI suite.
2026-11-05 14:01:09 +08:00
yetone 4cb7159f18 routing: a ChatGPT account whose usage can't be read is asked, not starved
peterpark8527 on Discord: 11 ChatGPT accounts under Use before expiry,
one never used. An account whose wham/usage reading fails (or names no
window, or is held by "When I ask") stayed not known for good:
Use before expiry counted it a fresh week (FreshPace, ~0.6/h), behind
every known week being spent; Smart put it after every known account.
NoteCodexLimits only updated accounts already read, so its replies'
x-codex-* headers never made it known. Its week, once started by
magpie's own turns or warm-up, lapsed unspent. A simulation of 11
accounts over 4 weeks (Pace, Poisson load 30/60/90%) had it at 141 of
~1200 used at 30% load, losing 3406, while every known account was used.

- provider: a reply that tells an unread account's week makes it known
  from that (usedCache.heard), kept over failed readings, until a good
  reading tells it; a 5h window alone still makes nothing up.
- gateway: a Codex account not known, weighed against one known, is
  Learns, like Claude's: asked first once so its reply tells its week,
  and again an hour after its last answer if that told nothing
  (codexAnswered, codexLearnAgain). Of accounts none known the order
  stands, so no week is started before it is needed.
- docs/reference.md: Smart and Use before expiry say so.

Ruled out (by design or not starving): an unstarted Codex week lasts
until its first request, so last is right for it; ties go by decayed
tokens, not a fixed order; a 5h-only account goes by its 5h pace
(ahead); rests are time-bound with probes.

Run:
- wsl-run go test -count=1 -timeout 45m ./internal/gateway
  ./internal/routes ./internal/provider ./internal/middleware: provider,
  routes, middleware ok; gateway had 3 reds (TestAccountProxy,
  TestCodexDrawMovesToNextAccount, TestWeeklyPace's five-hours case):
  accounts none known reordered by answers earlier tests left in
  codexAnswered. Fixed by the known-peer gate above; then wsl-run
  go test -count=1 -timeout 45m ./internal/gateway ./internal/routes:
  ok (809s). The none-known guard's u00 line was added after that run
  and run alone on Windows (win-run -run TestUnknownCodexAccountIsAsked
  ./internal/gateway, with the reds above: ok).
- win-run the two new tests on the old code (73c98ebc2, stand-ins for
  the new names): TestNoteCodexLimitsKnowsAnUnreadAccount and
  TestUnknownCodexAccountIsAsked red.
- win-run go vet ./internal/provider ./internal/gateway ./internal/routes:
  ok; wsl-run go vet of the same: ok. gofmt -l: clean.

Broken by hand: learns' codex case returning false turns
TestUnknownCodexAccountIsAsked red; Allowances not applying heard turns
TestNoteCodexLimitsKnowsAnUnreadAccount red ("the next failed reading
forgot what the reply told"); dropping the known-peer gate turns its
none-known case red ("u01@x.com first, not the first listed").

Not tried: real ChatGPT accounts; the reporter's actual cause is not
confirmed (asked for version, quota, status, plan). Other ways one
account goes unused (90%/98% tiers, rested, model list, group, off)
need their answers. mote was not used: its disk is full.
2026-11-05 13:27:32 +08:00
yetone 87c51cd6bb gui: a tap that comes let go before it is pressed clicks its control once (refeccd)
refeccd on Discord (magpie 0.1.3014, macOS 27.2 26B123): with Tap to click
on, a tap often does nothing, in the tray panel and the window, and almost
always inside a dialog, sheet or menu opened from the active window.

Cause: WebKit's WebViewImpl::nativeMouseEventHandler hands every mouse event
to NSTextInputContext handleEvent:completionHandler: while an editable
element has focus, and before WebKit ba0432f3f5 (2026-11-04, bug 329642,
"Dispatch mouse events to the page in the order sent to the input method",
rdar://102126328) each event was dispatched from its own completion handler.
Some input methods answer out of order, so a tap, whose down and up are a
few ms apart, reaches the page as mouseup then mousedown: no click, :active
stuck, and the next tap's mouseup pairs with the left press and clicks
where the two meet (the "second tap works" of the earlier reports). A
physical press is ~100ms long, so its order holds. Dialogs focus their
first field when they open and menus focus their search box, which is why
dialogs are almost always hit. macOS 27.2's system WebKit predates the fix.
Not proven on refeccd's machine: no real trackpad with an input method was
used; the order is reproduced, not observed there.

Change (app.js, the one capture-phase tap net every control goes through):
a press within 300ms and 12px of a release that had no press, and not let
go within 100ms, is such a tap (tapBack). Its control (the lost-click net's
selector) is clicked once after 100ms, and the trusted click the next
release pairs with it (detail > 0, so never a keyboard click) is dropped.
A release within the 100ms means the press was in order after all: nothing
is clicked by the page and the browser's click is kept. The segs press
tracker and the lost-click net ignore a tapBack press. Comments in app.js
were condensed to keep the core script budget (main was already 380 bytes
over it, #4526's test); no budget raised.

Not covered: an inverted tap on a dialog's backdrop doesn't close it
(backdropClick pairs pointerdown/up); nothing is clicked for it.

Run (mote, at this tree rebased on origin/main 9d143eaca):
- internal/gui/tests/tap-inverted.test.cjs (new): Chromium and WebKit, en,
  zh, zh-TW, ja, de, 1100 and 390 wide: 22/22 pass. Playwright's
  mouse.up then mouse.down gives the page that order with trusted events.
- The old app.js with the new test: 22/22 red at the first inverted tap
  (0 clicks).
- Broken by hand: the dropped paired click off -> red at the second tap
  (0 clicks where 1 expected; the click landed on .segs); the 100ms
  in-order cancel off -> red, a no-control press after a stray release
  lost its click.
- tap-*, click-scroll, segs-*, modal-*, menu-*, dialog-*, library-mcp-*,
  tray-cell-click, i18n-* GUI files; go test -run TestCoreScriptBudget
  ./internal/gui: 437 pass, 25 red. Every red is the same at origin/main
  9d143eaca, run there alone on mote (30 pass, 24 red in the four files;
  tray-cell-click chromium zh passed there once, red 4 of 4 in #5215):
  segs-press-redraw "clicks its new self once" (16, #4566),
  menu-input-scroll (4, #3402), tray-cell-click (4, #5215), i18n-keys
  "a plugin's words are its own" (1, filed as #5327).
  TestCoreScriptBudget ok.
- go test ./internal/gui: TestMainWindowCorners/macOS_26_SDK red, #3949
  (macOS 27, AppKit), not touched here.

Not tried: a real trackpad with Tap to click and a third-party input method
(Baidu, Sogou, WeType), the Wails app itself, the tray panel's NSPanel.
2026-11-05 13:26:17 +08:00