Commit Graph
7089 Commits
Author SHA1 Message Date
yetone c66cdbea97 update: a release file github.com won't serve comes through GitHub's API
On 2026-11-08 github.com answered 504 for every file of
yetone/magpie-releases (…/releases/download/<tag>/<file>) for hours, while
api.github.com/repos/yetone/magpie-releases/releases/assets/<id>, asked
with Accept: application/octet-stream, redirected to the same bytes.
Every self-update and the install script failed (kurutodenzeru, wjbdx,
isee1_1 on Discord). Retrying the same address (a46190e1f) can't help.
The site's feed was stuck at 0.1.3318 too: its SHA256SUMS read went to
the same address.

- internal/update: download() goes to the API route at the first busy
  status (5xx/429), or for the last try after connection errors. The
  feed's new per-asset `api` is used as it is; without it the address is
  looked up from the release's tag (apiroute.go). The file is checked
  exactly as before: the feed's SHA-256, and Stage's signing-team check on
  the Mac. A mirror the user set keeps precedence: through one, no API
  route is tried (its whole point is that GitHub isn't reachable). This is
  the one download every caller uses: the app's update, the CLI's
  `magpie update` and serve's auto-update.
- site/public/install.sh: when the feed's github.com URL fails and no
  mirror is set, it downloads through the feed's `api` (else looks it up
  with curl+sed, no jq), and checks the same SHA-256.
- site/worker.js: the feed lists `api` per asset. SHA256SUMS is read
  through the API when github.com fails. While it does, each file's `url`
  is usemagpie.ai/dl/<tag>/<file>, which 302s to the address GitHub's API
  gives (only *.githubusercontent.com or github.com, https), so an older
  magpie, which follows `url` only, updates too, still checked against the
  feed's SHA-256. That feed is cached 60s instead of 300s, so it goes
  back to github.com's URLs soon after github.com recovers.
- docs/reference.md: the API route, and that a mirror keeps precedence.

Run:
- mote: go test -tags nogui -count=1 ./internal/update (ok 20.3s).
- mote: node --test site/install.test.mjs site/worker.test.mjs
  site/stable.test.mjs: 76 pass.
- gofmt -l internal/update: clean. mote: GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet -tags nogui ./..., GOOS=windows go vet
  ./internal/update ./internal/cli ./internal/gui: clean.
- Real, on the Linux box (wsl-run, magpie-desktop) at 10:50Z: a nogui
  build stamped 0.1.3000, `magpie update` in a sandbox HOME
  (MAGPIE_ADDR=127.0.0.1:9). MAGPIE_UPDATE_FEED was a local feed whose
  magpie-cli-linux-amd64 url answered 504, with the real `api` of
  v0.1.3319 and the sha256 from the real SHA256SUMS. The download address
  was asked once and got 504. The file came through api.github.com, and
  the binary was replaced with exactly 89fff184… and reports 0.1.3319.
- Real: install.sh's apiroute sed against api.github.com's full
  v0.1.3319 description found the right asset id for 5 files
  (723602745 for magpie-cli-linux-amd64, the same as Go's lookup).
- Full suite: not run at push; it runs after.

Broken by hand:
- No switch to the API route in download(): 3 of the 4 new Go tests red
  ("504 Gateway Timeout, on every try").
- Mirror check and the octet-stream Accept removed:
  TestMirrorKeepsPrecedenceOverTheAPIRoute red, and
  TestDownloadGoesThroughTheAPIWhenGitHubIsBusy red (checksum: GitHub's
  JSON description instead of the file).
- worker: no API read of SHA256SUMS, no /dl location cache, and no check
  of the redirect's host: each red.
- install.sh: no API fallback, then no mirror guard: each new install
  test red.

Not tried:
- The real outage itself: github.com had recovered (302, slowly) by the
  real run, so the 504 was a local server's and the API route was real.
- An old magpie through the deployed /dl route against a failing
  github.com; it is covered by the worker test only.
- install.sh end to end against the real API (only its lookup); the Mac
  app's Stage through the API route (only the fake tests, which keep the
  signing-team check unchanged).
2026-11-08 18:52:32 +08:00
yetone a5c97cd83a plugins: a tool plugin's Hide from agents sits with Switch off and Remove
The button was on the tools line, pushed right with margin-left: auto, so
in a two-line row (x: "Tools for agents: x_search, x_read") it sat a line
below Switch off and Remove, which the row centres. It is now one of the
row's buttons (toolsFlip), before Options, Switch off and Remove, as a
text button like them.

Run (mote): plugin-tools 22/22, both engines, en/zh/zh-TW/ja/de, 980 and
420; its new check that every row button shares one centre line fails on
the old plugins.js/css (red in every language). plugin*.test.cjs,
i18n-keys, old-webkit, library-mcp-tool*: 1134 pass, 6 red:
plugin-move-unserved's "Try again" x4 is red on unchanged 8fa3c60f8 too
(#4410); i18n-keys "a plugin's words are its own" is red on 8fa3c60f8
(#5332, #5482); plugin-panels chromium timed out once under load and
passed when run again.
Not tried: the real app with the x plugin installed.
2026-11-08 18:45:50 +08:00
yetone 8bba91e65a cli: GET /api/context/session is the window's own (TestEveryRouteHasACommandOrIsNamed)
f418edffc added the route for a session's context, request by request,
in its detail view, beside /api/context/reply, and left the parity test
red on main. It is named W like reply.

Run on mote: go test -run 'TestEveryRouteHasACommandOrIsNamed|Import'
./internal/cli ok; the full ./internal/cli run at the parent was red on
exactly this route.
2026-11-08 18:37:41 +08:00
yetone b0926e81a2 import: a link can say where its key's balance is read (balance=, balance_path=, balance_method=)
A relay's "Add to magpie" link can now name the URL that tells a key its
balance, where the amount sits in the reply, and GET or POST. magpie
takes it only on the host of one of the link's own base URLs, over
https, with no userinfo or fragment, so a link can't send the key
anywhere its requests don't already go; anything else refuses the whole
link. balance_path or balance_method without balance is an error. No
header or token is taken from a link: an account-wide token is worth
more than a key, and a URL stays in browser history.

- provider.ParseImport: linkBalance checks and sets BalanceURL,
  BalancePath and BalanceMethod.
- CLI: the import preview shows the balance URL and doesn't ask it
  before yes (showProviderAsking).
- GUI: the import dialog shows method, URL and field (.imp-bal).
- Docs: docs/import in en, zh and ja (table rows, a note on headers,
  the builder's three fields with the same host check, a security
  bullet); docs/reference.md's parameter table.

Run on mote at this tree (rebased on 8fa3c60f8):
- go test -count=1 ./internal/provider ./internal/gui: ok
  (TestParseImportBalance, TestCoreScriptBudget in it).
- go test ./internal/cli: ok but TestEveryRouteHasACommandOrIsNamed,
  red on main since f418edffc (GET /api/context/session); fixed in the
  next commit, and ok there with -run 'TestEveryRoute…|Import'
  (TestImportPreviewAsksNoBalance).
- GUI import-link-balance, import-link-gemini, i18n-keys: 43/44. The
  red is i18n-keys "a plugin's words are its own", the same three
  strings on an origin/main 8fa3c60f8 copy (#5327, #5426, #5482).
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of provider,
  cli, gui: ok. gofmt -l: clean.

Not tried: a real link with balance= imported into the app and read
against a real relay's balance endpoint.
2026-11-08 18:37:41 +08:00
yetone 8fa3c60f80 claude: an interactive run takes many images between words (#5654)
Chapin2018's message of nineteen images between words (the issue's
script, Claude Code 2.1.319, claude-fable-5-1) ended the interactive
helper "after 13s (exit status 1)" and the client got a 502, while -p
answered. The cause is how the helper saw a paste taken. It looked for
"[Image #N]" and "[Pasted text #N" only in what Claude Code drew after
the paste. Once the prompt runs past a row, Claude Code draws it again
only where it changed and moves the cursor past cells that are already
right. After the 33rd piece the drawing held "\r\x1b[16C\x1b[1B3": one
digit of "[Image #33]". The helper waited out pasteWait (10s) and ended.
Text marks came out in part too ("[Pasted t xt #16"), so several word
pieces each sat out their own 10s before that. There is no limit in
Claude Code's TUI: the same paste is on its screen whole, so no -p
fallback is needed.

Each check now also reads the prompt as the 200x50 screen grid shows
it: the rows between its last two rules, words one space apart (a mark
can wrap onto the next row). The mark that ends it counts (lastMark),
an image's [Image #N] or a whole [Pasted text #N +k lines], numbered
past the piece before, and so do words the prompt ends with. The
stream check stays first.

Run:
- Real, macOS arm64, this Mac, sandbox HOME and CLAUDE_CONFIG_DIR
  (token by env, nothing rotated, DISABLE_AUTOUPDATER=1), the issue's
  script unchanged, --images 19, Claude Code 2.1.319:
  - origin/main a46190e1f: exit 1 after ~32s, stderr as reported.
    2.1.316 failed the same way. -p: success, 5.8s.
  - This change: exit 0 in 5.3 to 12.1s on 5 runs, subtype success.
    The transcript's user row has all 19 image blocks and the words in
    order, and the model answered. The script's answer_ok stays false
    because the helper's result line has no "result" text (-p's does).
    The gateway reads the assistant events, not that field.
- TestShimSeesPastesOnAPromptDrawnInPart feeds the real run's bytes
  (testdata/paste-images-2.1.319.bin, folder name replaced at the same
  length). Each of the 33 pastes must be seen taken.
- Broken by hand: drop the prompt checks from imageTaken and textTaken
  and it goes red on text 12, text 22 and image 33, the pieces whose
  marks were drawn in part.
- WSL magpie-desktop (Ubuntu 24.04 amd64, go1.26.8), because mote is
  down:
  - gofmt -l . is clean.
  - go vet -tags nogui ./... and GOOS=windows go vet ./... pass. Plain
    vet there lacks gtk4 headers.
  - go test ./internal/claudetui/ is ok (120s).
  - The darwin build used for the real runs above.

Not tried: Linux arm64 (the reporter's system) with a real account, the
gateway's /v1/messages path end to end with 19 images, and the full
suite (not run at push).

Refs #5654: kept open for the reporter to confirm.

Reported-by: Chapin2018
2026-11-08 18:24:16 +08:00
yetone f418edffc3 sessions: a session's details show how full its context was, request by request
liang_yongxiang on Discord: Routing tells how full one request's context
window was; does Sessions have the same, each turn's share?

A session's details on the Sessions page (and in Usage's Sessions list,
which draws the same details) get a Context line when the gateway sent
calls of it (s.via): the Context tab's spark of its prompts, request by
request against its window, and the fullest one's share beside it, toned
as the tab tones it. A point's tip says "Request 2: 80K of 200K (40%)" (the
tab's spark says it too now, where the window is known); a point clicked
opens that request in Routing with its card. A session the gateway never
saw asks nothing; one it kept no prompt of shows no line.

The data is the routing history the Context tab already reads. A new
GET /api/context/session?agent=&id=&from=&to= reads only the days from the
session's first to its last (30 at most), through the tab's per-day cache
(daysRecsLocked, split out of contextRecsLocked, so the tab's cached days
are not evicted), and keeps that one session (contextOfRecsFor), with up
to 1000 of its requests. The tab keeps the latest 80 sessions and would
leave an older one out. Subagent and side calls are left out as the tab
leaves them out; the same id under another agent is that agent's.

The line's code is in plugins/usage/page.js (sessCtxLine). context.js only
exports spark and health, and pays for its tip by cutting comments, so
the core's scripts are 10 bytes under main's, no budget raise.

Run at this head (rebased on e215d335a), on WSL (magpie-desktop, Linux;
mote rebooted mid-run):
- gofmt -l clean; go test -tags nogui -run
  'TestContextSessionLine|TestCoreScriptBudget|TestContext' ./internal/gui/: ok
  (also ok on mote at this head).
- node --test sessions-context-line (new: Chromium and WebKit, en zh zh-TW
  ja de, 1100 and 420 wide) and context-window: 44 of 44.
Run on mote before the rebase, at 627fd1a3b:
- the whole internal/gui package: its one red, TestCoreScriptBudget
  (1,536,110 > 1,533,802), is why the line moved into the plugin.
- sessions-context-line: 20 of 20.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- i18n-keys: "a plugin's words are its own" red, the same on origin/main
  e215d335a (#5327, #5332, #5426, #5482); the new strings pass its other
  checks.

Broken by hand:
- the one-session filter dropped: TestContextSessionLine red ("its
  requests' prompts: [21000]", another session's line).
- the tip back to "Request {n}: {tokens} tokens": sessions-context-line red
  in de ("Anfrage 2: 80K Token" for "Anfrage 2: 80K von 200K (40%)").
- the details line turned off: sessions-context-line red in en and zh.

Not tried: the whole GUI suite (it was running under mote's suite lock
when mote rebooted; not run at push); a real magpie with real routing history (the GUI test stubs
/api/context/session; the Go test reads real history files in a sandbox
config); the Linux app's WebKitGTK.

Reported-by: liang_yongxiang (Discord)
2026-11-08 18:13:30 +08:00
yetone a46190e1f5 update: a busy download host (502, 503, 504, 500, 429) is tried again
The owner's About page: "0.1.3316 下载失败 · download
magpie-darwin-arm64.zip: 504 Gateway Timeout". Only a connection that
broke was tried again; any status but 200/206 failed the download at
once, though a 504 from GitHub's asset host (or a mirror's) is its edge
timing out, and the next ask usually goes through. Such a reply is now
a NetError: download asks again after each of retryWaits (2s to 30s),
over HTTP/1.1 and keeping what came, as for a dropped connection. When
every try is busy it says "download <file>: 504 Gateway Timeout, on
every try", and the About row says the download broke off, a network
problem, with Check to try again. A 404 or 403 is still asked once.

Run (mote): go test ./internal/update ok; -run Update|Download|Mirror
in internal/gui and internal/cli ok; GOOS=linux and windows go vet
./internal/update ok; gofmt clean.
Broken by hand: with the busy case off, TestDownloadRetriesABusyHost
fails at the first 504 and TestDownloadBusyEveryTryAndMissingOnce sees
1 try of 6.
Not tried: a real 504 from GitHub; the host's answer is faked.
2026-11-08 17:54:36 +08:00
yetone e215d335a6 gateway: a gateway key can cap its requests at once; the rest wait their turn
young02036 on Discord: a provider can be given a concurrency, so why
can't a gateway key? A key now has an optional MaxConcurrency, from 1
to 1000. Left unset (every key today), nothing changes.

- access: Key and Change get MaxConcurrency, and Identity carries it, the
  issuer's cap included. The concurrency-key action refuses a value
  below 0 or above 1000.
- gateway (key_slots.go): every route that asks a model is held to the
  key's cap, however the request came (loopback, LAN, a Remote magpie, a
  Responses socket's turn). One request too many waits in the key's
  queue in arrival order. It shows as "slot" in Active, and its wait goes
  into the try's Queued. A request whose agent goes away while it waits
  leaves the queue and sends nothing. A stream holds its slot until it
  ends. serve's routes (chat, responses, messages, ollama, gemini, the
  Codex backend) wait inside the try, after keepQueued, so a streaming
  agent gets keepalives while it waits. The other model routes (images,
  embeddings, rerank, audio, videos, search, decisions, native) wait
  before their handler runs. forward and codexUpstreamOn take the slot
  too, so nothing reaches a vendor without one. A key issued under
  another waits for its own slot, then for its issuer's.
  /v1/magpie/concurrency lists each capped key under "keys", and counts
  its waiters in "waiting". A key's limit (key_limit) reports the cap.
  Not held, as a provider's MaxConcurrency doesn't hold them: GET,
  HEAD, OPTIONS, count_tokens, :countTokens and MCP.
  TestKeySlotEveryRoute fails when a route is judged neither held nor
  free.
- cli: magpie gateway-key concurrency <id> [<n>|off]. It refuses 0, a
  negative, over 1000, a fraction, a word, --help or an extra argument
  with its usage.
- gui: the key row gets a badge in the provider concurrency badge's
  style. It opens the app's menu with No limit, 1/2/3/5/10 and Other…,
  and Other… takes a number typed in place. A value that isn't a whole
  number up to 1000 is refused and nothing is sent. Browser and
  read-only keys have no badge. Strings are in en, zh, zh-TW, ja and
  de. An unset badge, which a hover shows, gives way before the masked
  key (flex-shrink 8). Without that, at 420px in en and de, the extra
  badge squeezed the key until its copy button slid under the pointer
  that came to drag the row, and gateway-key-arrange went red.
- docs/subsystems/gateway-routing.md describes it.

Run (on mote, at this tree on origin/main 0f8c3d867; rebased onto 627fd1a3b,
which touches none of these files, and the budgets were run again):
- go test -timeout 45m ./internal/access ./internal/gateway ./internal/cli
  ./internal/gui: access, gateway (839s) and cli ok. gui had one red,
  TestGatewayModeStatsNameTheGatewaySessions, run at 00:40 PST: its
  record an hour back falls on yesterday in a day's first hour. It
  passes from 01:09, so it is unrelated; filed as #5690. The Budget/Size
  tests were run again after the CSS change: ok.
- gofmt -l: clean. go vet for darwin, plus GOOS=linux and GOOS=windows
  (-tags nogui), on those packages: ok.
- GUI (node --test, Chromium and WebKit, 1100 and 420 wide, en, zh,
  zh-TW, ja and de): every file that loads the gateway keys (59) plus
  i18n-keys and i18n-en-no-cjk. The reds left are the same on
  origin/main and already filed: gateway-key-models en (#5233, #4081),
  i18n-keys "a plugin's words are its own" (#5332), phone-connect-menu
  at 420 (#4706, #4707). After the flex-shrink fix:
  gateway-connect-keys, gateway-key-arrange, -concurrency, -mcp,
  -own-rotate and -quotas passed 104/104 in both engines, against
  84/84 on base.
- The tests:
  - TestKeyConcurrency, over LAN with cap 2: 2 of 3 requests reach the
    vendor and the third is shown as "slot". Another key isn't held. A
    cancelled waiter leaves the queue and never reaches the vendor. The
    third goes once one ends, every lane is given back, and its Queued
    is at least 40ms.
  - TestKeyConcurrencyKeepsStreamAlive: a waiting stream gets 200 and
    keepalives.
  - TestKeyConcurrencyEager: on embeddings an issued key waits on its
    parent's lane, a cancelled waiter leaves, never more than 1 runs at
    once, and a GET takes no slot.
- A real `serve` in a sandbox HOME (built from this tree, MAGPIE_ADDR
  127.0.0.1:38612) against a fake slow SSE upstream. Steps: `provider
  add fake url=…`, `gateway-key add`, `gateway-key concurrency <id> 1`,
  then three concurrent keyed streams. /v1/magpie/concurrency showed the
  key at busy 1, waiting 2, limit 1 (two in "slot"). The upstream's
  most at once was 1, and it saw 3 requests one after another (200s at
  1.9s, 3.7s and 5.5s, each with [DONE]). Afterwards "keys" was empty.
  `concurrency <id> 2000` exited 1 with its usage.

Broken by hand (each went red, then restored):
- keySlot returns nil: TestKeyConcurrency ("timed out waiting for c
  queued") and KeepsStreamAlive.
- The issuer's lane skipped: TestKeyConcurrencyEager.
- The eager take skipped: TestKeyConcurrencyEager.
- The CLI's bounds check removed: "accepted [concurrency id 0]".
- The GUI's bounds check removed: gateway-key-concurrency.
- Without the flex-shrink line: gateway-key-arrange chromium/webkit en
  and de 420px.

Not tried / not done:
- Full suite not run at push (neither `go test ./...` nor the whole GUI
  suite).
- Not tried with a real vendor account or a second computer on the LAN.
  The LAN path is covered by TestKeyConcurrency's lanServer.
- The key's badge shows the cap, not live running or waiting counts.
  /v1/magpie/concurrency has those.

Reported-by: young02036 (Discord)
2026-11-08 17:52:09 +08:00
yetone 627fd1a3b7 claude: a turn Claude Code ends with no answer is a 502 saying why, not a 200 with content null
steven_4422 (Discord) sent 18 PNG frames as image_url parts to
claude/claude-sonnet-5-5 in a Chat request, not streamed, and got 200
with {"message":{"content":null},"finish_reason":"stop"} and zero
usage; 17 were answered. Whatever ended Claude Code's turn, the bridge
took an end with nothing said as the answer:

- a run that exits with a request waiting and nothing begun (the
  interactive helper at its deadline, or failing to send the message,
  exits 1 with the reason on stderr) closed the segment empty;
- a turn whose result came with no message, or only a <synthetic> one
  of Claude Code's own words, left the segment open to be closed empty
  by the exit or the run's timeout;
- relay finished a reply whose events ended with neither a KStop nor a
  KError: the collector's empty result went as a 200, a stream ended
  as a finished reply.

Now readOutput ends such a turn with a 502 carrying Claude Code's own
words, else its result's, else "said nothing of why"; the exit
goroutine emits "Claude Code ended before it answered" with its exit
and stderr; relay turns an unended reply into a 502 (whole) or an
error event (stream) in every protocol. A 5xx lets another account
take over, as other bridge failures do.

Claude Code itself (2.1.316, read from its binary and run on mote
against a fake Messages API) has no image-count limit: it passed 18,
24 and 40 images through, by -p and by the interactive helper, and
turns the API's refusal of an image into an is_error result, already
a 4xx/5xx here. So 18+ images are passed through, and what refused or
dropped the reporter's turn is upstream of magpie; the client now gets
its reason instead of an empty answer.

Run (mote, at this head, rebased on 0f8c3d867):
- go test -tags nogui -race -count=1 -timeout 45m ./internal/gateway/
  ./internal/claudetui/: ok (gateway 1607s,
  claudetui 131s), no races.
- GOOS=linux and GOOS=windows go vet of both packages: ok; gofmt -l clean.
- Full suite: not run at push.

Broken by hand: with claude_subscription.go at its parent and the new
tests kept, all 36 TestClaudeSilentTurnFails cases and all 4
TestRelayUnendedReplyFails cases are red: the exit variant, not
streamed, gives the reporter's body byte for byte (200, content null,
zero usage); streamed, a 502 with no reason; the result and synthetic
variants hang until the test's 20s deadline.

Not tried: a real Claude account at 18+ images (no credentials on
mote, and the Keychain is off-limits), so the upstream reason for the
reporter's turn is unknown; the interactive mode through the gateway
against real Claude Code (the helper alone was run with 18 and 40
images against a fake API).

Reported-by: steven_4422 (Discord)
2026-11-08 17:05:09 +08:00
yetone 0f8c3d8672 claude: a deferred built-in the bridge's model calls reaches the client as WebFetch, not mcp__magpie__WebFetch
Claude Code with tool search on leaves WebFetch, WebSearch, CronCreate and
the other deferred built-ins out of tools until a ToolSearch loads them.
The run's model, offered the client's tools as mcp__magpie__<name>, called
mcp__magpie__WebFetch, and toolStart handed that over whole: the 11-02
fix for an unloaded magpie MCP tool (packinggoods) kept the full name for
every cut name the client hadn't declared. The client answered "No such
tool available: mcp__magpie__WebFetch", the model retried, and
status lines such as claude-hud showed a "magpie" MCP failure.

toolStart now keeps the prefix only when the cut name has the router's
form, <server>__<tool> (magpieServerTool): the client names magpie's MCP
tools mcp__magpie__<server>__<tool>, and its built-ins (WebFetch,
WebSearch, CronCreate, CronDelete, CronList, NotebookEdit, Monitor,
TaskStop, SendMessage, EnterWorktree, ExitWorktree: the deferred list of
a real Claude Code session) have no __ and no prefix. A sibling the same
line got wrong: another MCP server's deferred tool, called as
mcp__magpie__mcp__linear__get_issue, is handed over as
mcp__linear__get_issue, the client's name (it was handed over whole too).
toolStart is the one place a called name is mapped back for the client:
streamed and whole messages and the interactive mode's early call
(r.onCall) all go through it; mcpCall's declaredName serves offered
tools only, and the history's names (bridgeName) are unchanged.

Run (on mote, at this tree):
- go test ./internal/gateway -count=1 -timeout 45m: ok
- gofmt -l: nothing; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok; go build: ok
Broken by hand: magpieServerTool returning true (the old behaviour)
turns TestClaudeBridgeHandsOverAnUnloadedMagpieTool red on the new
WebFetch and mcp__linear__ cases ("handed a call of
mcp__magpie__WebFetch, want WebFetch").
Not tried: a real Claude Code client with tool search on (the reporter's
Windows setup); a deferred tool the run's model calls by the bare client
name (WebFetch) is still the run's Claude Code's to answer and isn't
handed over. A client MCP server of its own named "magpie" with a tool
lacking __ would now be cut; magpie's router names every tool
<server>__<tool>.
Rebased on eadc6cdb9 (GUI routing files only); at the pushed head
go test ./internal/gateway -run 'TestClaudeBridge|TestClaudeToolChoice|
BridgeToolName': ok.
Full suite: not run at push.

Reported-by: steven_4422 (Discord)
2026-11-08 16:05:42 +08:00
yetone eadc6cdb96 routing: a request with a named gateway key is drawn as that key
acezan (Discord) sent the Routing flow for an Antigravity group: a
script's requests showed only "Python-urllib", the caller's
User-Agent, on the left node. The request should be named by the
gateway key it came with.

The trace and history routes already carry callerKey (the key's id)
and callerKeyName, never the secret. The stage now groups callers by
agent plus key, so two keys behind one User-Agent are two nodes, each
in its own colour. A keyed node reads the key's name as Gateway keys
lists it now, else the name the route kept. A request with no key
keeps the agent's name, as before. The agent's icon stays, and the
tooltip names the key and then the agent. No new labels.

Siblings:
- The request rows' swatch, wire hue, the play dots and the replay
  marks follow the same caller, and "Sent by" names the key.
- The tray panel's stage and its .pr-who rows name the key the same
  way. The panel doesn't read /api/caller-keys, so it shows the name
  the route kept; a key renamed later shows its old name there until
  the next request.
- Usage already shows "agent · key name" on ledger rows and has its
  own key split. Unchanged.
- The By-key and By-session group heads and the story prose ("X asked
  for...") are unchanged.

Run on mote at 1aabc66fd + this commit:
- New internal/gui/tests/routing-caller-key-node.test.cjs: 11/11 in
  chromium and 11/11 in webkit. It covers en, zh, zh-TW, ja and de at
  1100 and 420, plus the tray panel.
- With routing-by-key, agents-apart, agent-hue-not-red, fifth-agent
  and panel-routing: 46/46 in each engine.
- go test: TestKeptRoutesNameTheirCallerKey (new), TestCoreScriptBudget
  and TestTraceNamesCallerKey ok. gofmt -l is clean. go vet passes on
  internal/gui and internal/gateway for darwin, linux (-tags nogui) and
  windows.
- Every routing-*, panel-routing* and click-scroll file at the previous
  base 15918265e + this change, under load (60 to 100):
  - chromium: 1546/1554.
  - webkit: 1542/1554.
  The reds are in routing-intent-entry (#5392), routing-row-swap
  (#3799), routing-context-fold (#5586) and routing-story-shrinks
  (#3954). They are red the same way when run alone at origin/main
  15918265e, without this change. ctx-sessions and many-keys went red
  only in the parallel run and passed alone.

Broken by hand:
- With client.js from origin/main, the new GUI test is 0/11 red.
- TestKeptRoutesNameTheirCallerKey passes on the old code too, because
  the Go side already carried both fields. It guards history keeping
  them: with callerKeyName's JSON tag set to "-", it goes red.

Not tried: a real request with a named key through a live gateway. The
fixtures are faked trace routes. Full suite: not run at push.

Reported-by: acezan (Discord)
2026-11-08 15:54:52 +08:00
yetone 1aabc66fd1 gateway: /v1/models answers its ETag, and 304 to a client that has the list already
clyzhicore (Discord) runs a server magpie as the gateway and a local magpie
that takes its /v1/models and writes the models into dsh. They asked for
an ETag or a list you can wait on, so the local side knows a change at
once and a dead connection costs little. The wait is there since
06c4582cc (v0.1.3172: X-Magpie-List-Wait with If-None-Match, and the
Remote magpie follower). What was missing, and is added here:

- A plain GET /v1/models (no wait header) is answered with the same ETag
  a wait answers (listTag of the bytes this caller gets), Cache-Control
  private, no-cache, and 304 with no body, at once, when If-None-Match
  names it (strong or W/, in a comma list, or *). A tag it doesn't name,
  or none, is answered the list as before, same bytes. A refused list
  (400) stays untagged. Any client (a script, curl, another tool) can
  now poll cheaply.
- A wait's answer, 200 or 304, says in X-Magpie-List-Wait how many
  seconds it held. A plain answer doesn't.
- The follower (waitRemoteList) takes a 304 that comes sooner than
  followQuick (5s) without that header as a magpie that doesn't wait.
  This guards the change above: a proxy that drops X-Magpie-List-Wait
  would now get a tagged plain list and an instant 304, and the follower
  would ask every followGap (1s). It now leaves such a magpie to its
  schedule and asks again after followOldAgain (1h), as for one from
  before the wait. Servers from 06c4582cc on hold each wait to its end
  (50s), so their 304s pass.

Compatibility: an old server (no ETag) is still left to the schedule,
as TestRemoteMagpieOldListNotFollowed checks. An old client never sends
If-None-Match without the wait header and gets the same bytes plus an
ETag. The GUI doesn't read the gateway's /v1/models through Wails (whose
304 on WebView2 is a 505, gui/api.go writeJSONSame), so that doesn't
apply.

Hidden models (their second ask) already exist and are not changed: a
provider's "Only through routing groups" (Provider.Unlisted, `magpie
provider listed <id> no`) and a group's listed=no (Group.Unlists, `magpie
group set ... listed=no`, CLI only) keep models out of /v1/models while
groups still route to them.

docs/subsystems/gateway-routing.md says the above.

Run (on mote, through mote-run, first at 04ed05733):
- gofmt -l on the changed packages: clean.
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet
  ./...; go build ., GOOS=linux -tags nogui, GOOS=windows: all ok.
- go test -tags nogui -race -count=1 -timeout 90m ./internal/gateway:
  ok 2145s, no DATA RACE (mote at load ~100-130).
- go test -tags nogui -count=1 -timeout 45m ./internal/provider: ok 126s.
- After rebasing onto origin/main (5 commits, none in these files):
  gofmt -l clean; go vet (darwin, linux nogui, windows) of both
  packages ok; -race -run "ModelsWait|ModelsList|RemoteMagpie": gateway
  ok 12.5s, provider ok 4.8s.

Broken by hand, each red:
- models() back to listModels (no tag on the plain list):
  TestModelsListConditional ("ETag \"\"") and TestModelsWaitTagged ("a
  plain list: 200, ETag \"\"").
- tagNamed never matching: TestModelsListConditional (200 with the body
  for each of the tag, W/, a list and *).
- No X-Magpie-List-Wait on a wait's answers: TestModelsWaitTagged ("a
  wait's list says it held \"\"", same for its 304).
- The followQuick check off: TestRemoteMagpieStrippedWaitNotAskedOver
  ("asked 28 times in 300ms, want 2").

Not tried: two real magpies, or a real reverse proxy that drops the
header (the stripped case is a fake in the test). Not run on Windows or
Linux. The full suite (go test ./...) and the GUI suite: not run at push.
Following a provider added as a plain OpenAI-compatible endpoint (not the
Remote magpie type) is not done: its list URL comes from fetchOne's
several bases, and it still goes by its #2135 schedule.

Reported-by: clyzhicore (Discord)
2026-11-08 15:45:57 +08:00
yetone 15918265e3 zcode mover: min 0.1.57, the busy hold's answer arms no quota rest
plugins#859 (zxy20250120) merged as 93dacd738: an in-flight Start Plan
request answered by the busy hold's own 429 was counted as a spent gift,
so a -Trial model (or free first) rested in `blocked` for a minute with
quota left. 0.1.57 marks that answer and both gift paths skip it.

npm view --prefer-online --registry https://registry.npmjs.org
@magpie-community/opencode-zcode-auth version: 0.1.57 at landing.

Run on mote: go test -run 'Mover|Moved|Migrat|ZCode|Zcode'
./internal/provider ok; gofmt -l clean. Full suite: not run at push.
The plugin change itself was run in the PR review (bun test packages/zcode
236/0, red on main's index.mjs).
2026-11-08 15:37:01 +08:00
yetone 2fe4e9c70c pii: a GPU the driver reset under an idle pf-serve is loaded again on the GPU, not left on the CPU
kongbai01203 (plugins#853): after ~12 minutes idle the Vulkan pf-serve
exited 3 (vk::DeviceLostError) and Privacy Filter then said "GPU error,
running on CPU" until the GPU was tried again.

Cause: the driver's, not ours. pf-serve sits blocked on stdin while idle
and the idle unload only takes a free turn, so there is no race of ours
with a GPU call; the driver lost or reset the device under it, and the
next GPU call threw (an uncaught vk::DeviceLostError ends in abort, exit
3 on MinGW). magpie then counted one death on the GPU as a lost GPU.

Now one that dies on the GPU is started again on the GPU: a new
pf-serve gets a new device. Only a second death (or hang) in a row on the
GPU moves it to the CPU, until gpuRetryAfter. Status says gpuReset when
the error is a device lost, and gpuAgain when the GPU is tried again;
Settings > Privacy says "On, on the CPU until 14:38: the graphics driver
reset the GPU (device lost)" (and "until {time}" on a GPU failure), in
en, zh, zh-TW, ja and de.

Not changed: the model's size. Privacy Filter has q8 (1.64GB) and f16
only, no smaller quant; AstrLink Guard (39MB) is the small choice.
Its ~1.8GB private on the CPU goes with pf-v4 (mmap, 691a10446), whose
pin is another session's work; on Vulkan the ~1.9GB is the driver's.

Run (mote, through mote-run):
- gofmt -l, go vet (darwin, linux, windows), go test -count=1
  ./internal/pii ./internal/gui ./internal/masking: ok
- GUI: privacy-model, i18n-keys, i18n-en-no-cjk, masking-records in
  chromium and webkit (privacy-model at 1100 and 640, every language):
  219 of 224, then privacy-model 104 of 104 after zh-TW's expected time
  was made 下午02:38 (hhmm's zh-TW form). The one other red is i18n-keys
  "a plugin's words are its own", red on main and filed (#5332, #5426,
  #5482); this change adds no plugin words.
At this head, rebased on 8f6298fb5: gofmt, go vet and go test
./internal/pii ok; privacy-model and i18n-en-no-cjk 108 of 108 in
chromium and webkit.
Rebased after on 37df73b1b (key balances; the one file it shares,
i18n.js, holds other keys there), not run again.
Broken by hand: serve.go put back to HEAD's: TestGPUDeviceLostReloadsOnGPU,
TestGPUDeathMovesToCPU and TestLostGPUTriedAgain red (starts [gpu CPU]).
app.js put back to HEAD's: the new privacy-model test 10 of 10 red
(chromium).
Not tried: a real device lost on a GPU (it can't be forced here); a
crash in pf_free's teardown at idle unload (harmless: end() ignores the
exit status; a fix needs a native change and a new pf tag).
Full suite: not run at push.

Reported-by: kongbai01203
2026-11-08 15:35:59 +08:00
yetone 37df73b1bb balance: a key holds several credits that expire, each added and removed on its own
tenacious_eagle_96548 (Discord, 11-08) has two promotional credits on one
key, one ending tomorrow and one the day after. v0.1.3305 kept one grant
per key, and its form showed the date only after Enter or a blur, with no
button to confirm.

- OwnBalance.Expiring is now a list (`expirings`, up to 20). Spending
  goes to the grant that ends soonest first (ties by when it was typed),
  and each grant drops out at its day. A write prunes ended grants.
- The pill and the menu say "Expires in N days" per grant, amber from 7
  days. The menu has a Remove item per grant, "Add credit that
  expires…" and "No credit that expires" to clear them all.
- The form shows the amount and the last day together, the day filled in
  30 days ahead, with an Add button; Enter adds, Escape cancels, a bad
  amount or a past day is refused in place. The app's own menu, no
  native select, no stripes. A pill with two or more grants wraps at a
  grant on a narrow row (a class, not :has(), for Safari before 15.4).
- CLI: `--expiring amount@day` can be given several times, `--expiring
  off` clears all, `--expiring-remove [amount@]day` removes one. --help
  prints usage; a day that isn't a date, or is past, is refused.
- /api/provider/keyexpiring adds `{expiring:{amount,until}}`, removes
  `{expiring:{at,until},remove:true}`, clears `{expiring:null}`.

Old data: a v0.1.3305 single `expiring` grant is read as the first grant
and saved as `expirings` on the next write, for every user. An older
magpie reading the new file sees no grants (the balance itself stays).

Run on mote at 1d5b5dc2d plus this change:
- go test -run 'Budget|Balance|Expir|KeyOwn' ./internal/gui
  ./internal/provider ./internal/cli: ok (TestCoreScriptBudget passes,
  not raised). gofmt -l clean. GOOS=linux go vet -tags nogui and
  GOOS=windows go vet on provider, cli, gui: ok.
- GUI (Chromium + WebKit, 900/400px, en zh zh-TW ja de):
  key-balance-expiring, key-own-balance, key-balance-card,
  key-row-steady, key-row-chips-fit, account-rows-fit, old-webkit,
  i18n-en-no-cjk, balance-parts, balance-quota-left: 203/203. A broader
  run (key-*, balance-*, i18n-keys, panel-balance-order) had reds that
  are red on origin/main 04ed05733 too: i18n-keys "a plugin's words are
  its own" (#5332, #5482, #5426) and key-replace WebKit 420px (#4126).
- Real app on mote, sandbox HOME, `serve --web`: the CLI set ¥40 plus
  ¥5 to tomorrow and ¥8 to the day after and printed about ¥53.00 left;
  providers.json has `expirings`. --help, `5@yesterday` and removing a
  credit the key doesn't have each answered as above. In Chromium (en)
  and WebKit (zh) at 900 and 400px: the pill, the menu, the form (day
  2026-12-07), Add ¥3 by Enter, then Remove ¥3 from the menu, each
  checked by text and screenshot.

After a rebase on 437580535, on mote: the same go test
-run (TestCoreScriptBudget included): ok; key-balance-expiring,
old-webkit, key-own-balance: 46/46. Rebased again on 8f6298fb5 (Go
only, no asset changed): the go test -run plus Signin: ok.

Broken by hand, each went red: sorting grants by when typed
(TestTypedBalanceGrantsSoonestFirst); no migration in UnmarshalJSON
(TestTypedBalanceOneGrantMigrated); no Enter handler (GUI en 900); no
wrap rule (GUI en 400, row past the window's edge); Remove sending the
first grant (GUI, at/until mismatch).

Not tried: Full suite: not run at push. No real vendor account (the
grants are typed by the user). The Linux and Windows desktop apps.

Reported-by: tenacious_eagle_96548 (Discord)
2026-11-08 15:27:14 +08:00
yetone 8f6298fb5e providers: a notification when an account in use has to be signed in again, and before a Claude sign-in ends
steven_4422 asked on Discord whether magpie warns when a Claude Code
login is close to expiring or has expired. It didn't, outside the app:
a sign-in that Anthropic, OpenAI, GitHub or a plugin's vendor refused
showed only on the account's row (Sign-in required, Sign in again) and
on the provider row's Signed out pill, and nothing warned before a
Claude sign-in ended. The system notifications covered only usage,
balance, reset, masking and task-done alerts.

What Claude's tokens carry (read from Claude Code 2.1.316): the access
token refreshes itself, but claudeAiOauth.refreshTokenExpiresAt ends the
sign-in. Claude Code sets it from refresh_token_expires_in, or to 30 days
from the sign-in, keeps it over a refresh that sends none, says "Your
login expires in N days · run /login to renew" from 3 days before, and
treats a sign-in past it as none. It skips the warning when the access
token outlasts that end by more than the 3 days.

- provider.WatchSignIns looks a minute after start and then every two
  minutes. It reads only magpie's own files and asks no vendor. It
  covers every account in use of every subscription that is on.
- An account is told of when its row says Sign in again, by the
  Providers page's own test (needsSignIn mirrors renderAccounts): any
  mark on a Claude, Copilot or plugin account, and on another built-in
  (Codex revoked, a refresh that failed, ChatGPT API) a mark that
  signInGone matches.
- A Claude account is also told of 3 days before refreshTokenExpiresAt,
  by Claude Code's rule (claudeSignInEnds).
- Each alert goes out once: a lapse until the account is usable again,
  an end until it moves. The marks are kept in signin-alerts.json, so a
  restart doesn't repeat them, and an unreadable file tells nothing.
- The GUI sends the alert as "<Name> · <user>" with "Signed out — click
  to sign in again" or "Sign-in ends in N days — click to sign in
  again", in en, zh, zh-TW, ja and de. A click opens that provider's
  editor (?view=providers&edit=<id>), where the account's Sign in again
  is. A Linux dismissal still opens nothing (#2513).

Run on mote in a sandbox HOME, on this change over 04ed05733. It was rebased
onto 437580535 after the run, which changes only a gateway test:
- gofmt -l: clean.
- go vet ./...: ok.
- GOOS=linux go vet -tags nogui ./...: ok.
- GOOS=windows go vet ./...: ok.
- go build .: ok.
- go test -count=1 -timeout 45m ./internal/provider ./internal/gui:
  ok internal/provider 163.7s, ok internal/gui 162.2s.

Broken by hand, each red and then restored:
- Gone left false, which is the old code where nothing was told:
  TestSignInAlertClaudeSignedOut is red ("alerts …: []").
- The refreshTokenExpiresAt read turned off:
  TestSignInAlertClaudeEnding is red.
- The once-only mark dropped: TestSignInAlertClaudeSignedOut and
  TestDueSignIns are red ("told again").
- A click on a sign-in alert opening Usage:
  TestSignInAlertOpensItsProvider is red on darwin, windows and linux.

Not tried:
- A real notification on any OS.
- A real Claude account near its refreshTokenExpiresAt.
- A real revoked Codex, Copilot or plugin sign-in end to end.
- The GUI page is unchanged, so no Playwright run.
- Full suite: not run at push.

Reported-by: steven_4422 (Discord)
2026-11-08 15:19:03 +08:00
yetoneandggbdpq 4375805354 gateway tests: the long plugin reader's deadline follows the reply's progress, not the wall clock (#3286)
TestPluginStreamLongActiveReader went red under -race on macOS CI
(run 42449115269 at 691a10446, 75.54s): "SSE read after 38977536
content bytes: context deadline exceeded (Client.Timeout ...)". The
test's client carried a fixed 75s Client.Timeout over the whole
request, and the reply it reads is paced at 2.5MiB/s, so 40MB takes
16s on an idle machine and whatever a loaded -race runner makes of it
otherwise. The reader was still reading when the deadline cut it.

Change (test only):
- pluginReplyGateway's client has no total deadline. pluginReplyComplete
  arms a 60s idle guard (context.WithCancelCause) that progress resets:
  a frame the fake vendor wrote, an SSE event with content reaching the
  client, or, for a JSON reply, a read with more than whitespace in it.
  A reply that stops part way is red with "nothing moved for 1m0s"
  beside the read error.
- Wire bytes alone are not progress. ggbdpq's patch on the issue (the
  base of this change) reset the guard on any read with bytes; with that
  rule and the vendor's writes, broken by hand (credit never given back),
  the test was still waiting at 168s, because the gateway's ": keepalive"
  lines (every 15s, for up to 5 minutes) kept resetting it.
- TestPluginStreamLargeReplies runs through the same guard;
  TestPluginStreamStalledClientKeepsOtherRequestsMoving's second request
  keeps its own 3s context.
- The test's comment no longer speaks of a stall window: the host's
  credit window replaced it, and the test now says so.

Timing assumptions left: 60s with no progress anywhere is a stall
(progress arrives every few ms at the slowest pace here), and the
12s floor on elapsed is held by the reader's own pacing (16s minimum).

Run on mote (go1.26.8), base 1d5b5dc2d:
- Reproduced by capping the reader at 512KiB/s (1<<19) on the old
  code: red at 75.18s, "SSE event after 38723584 content bytes:
  unexpected end of JSON input" (the 75s deadline cut a line).
- The same cap on this change: ok, 81.45s, all 41943040 content bytes
  (vendor done after 72s).
- Broken by hand, host.credit a no-op: red at 65.43s, "SSE read after
  491520 content bytes: nothing moved for 1m0s".
- Broken by hand, the body given up 10s after its first read (the old
  stall window, ignoring progress): red at 10.19s, "SSE error after
  18219008 content bytes: ... the consumer stalled past the window".
- go test -race -count=1 ./internal/gateway: ok (1805s).
- gofmt -l internal/gateway: clean; GOOS=linux and GOOS=windows go vet
  ./internal/gateway: ok.
- Full suite: not run at push.

Fixes #3286

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-08 15:11:41 +08:00
yetone 04ed05733e codex: a refresh of Codex's sign-in never writes its account back over a switch
darwish4021 on Discord (macOS, Codex app, 11-08): after 56f095604 the
Codex app "quit abnormally and switched my account".

codexTokenRenewing read auth.json, sent the refresh (a network round
trip, up to 30s), and then wrote the refreshed sign-in back
unconditionally. If Codex was signed in to another account in between,
the write switched Codex back to the account it had been switched off.
Two things could do that:
- magpie's own switch (switchSavedLogin: the auto-switch off a spent
  account, or the user's own). It took savedTokenMu but not codexMu,
  and only renewSaved holds savedTokenMu. The usage reads, warm-up,
  resets and acct.sign refresh under codexMu alone. The switch also
  saved the replaced account into logins.json with the refresh token
  that refresh was spending, so it was signed out on its next use.
- the Codex app's own sign-in, or a sign-out.

The fix:
- codexTokenRenewing reads the store again before writing. It writes
  only while the store still holds the refresh token that refresh
  started from. Otherwise it logs "the sign-in in <dir> changed while
  <account> was being refreshed" and leaves the store alone. The fresh
  access token still serves the request in hand.
- switchSavedLogin takes codexMu for Codex, after savedTokenMu and
  before loginsMu, the order renewSaved already uses. A switch then
  waits for a refresh in progress, and saves the replaced account with
  the refresh token that refresh got.

Test: TestCodexRefreshNeverUndoesASwitch has two subtests. In one,
the Codex app signs in to another account mid-refresh. In the other,
magpie switches mid-refresh.

Run at this head on mote:
- the new test with TestCodexLogins and TestCodexSignInGone, -count=3:
  ok;
- go test -timeout 45m ./internal/provider ./internal/agent: ok;
- go vet for darwin, linux and windows: ok;
- gofmt -l: clean.

Broken by hand, on mote:
- Both halves reverted: both subtests red ("Codex is signed in to
  r-work-2 after the refresh").
- Only the codexMu in switchSavedLogin reverted: the magpie subtest is
  red, because the replaced account was saved with the spent refresh
  token.

Full suite: not run at push.

Not tried:
- the reporter's own machine, version and accounts;
- the real Codex app going through a switch with this build.

The reporter's "projects cleared" is not explained by this change. The
app's projects live in state_5.sqlite (the projects and project_roots
tables), and their SQL is not scoped by account. magpie writes only
threads.model_provider there.
2026-11-08 14:37:31 +08:00
yetone 1d5b5dc2da gui: the panel's visibility test takes only a hiding for a hiding (#5322)
Cause: on mote (macOS 27.2) WebKit's own document.hidden stayed true from
the page's load to the end of the run, the panel shown or not, and WebKit
fired no visibilitychange of its own (logged every 2ms in an instrumented
copy of the test). The test page dispatches visibilitychange from the
shown signal too, as app.js does; there it read hidden=true with the mark
just taken off, so it wrote marked=false play="running" as the hiding's
record and fetched /hidden. That stale /hidden sat in the host's channel,
so the panel's second round (Escape) showed the window again before its
hidden signal reached the page, and reported the stale record. The log of
a red run shows "got /hidden, show" in round 2 with no hidden signal
before it. The product is not at fault: the hidden signal reaches the
page on both of Wails' hides, and the page is paused while hidden.

Fix: the test page counts a visibilitychange as a hiding only outside the
shown signal's own dispatch.

Ran (mote, macOS 27.2, through mote-run):
- old test, -run TestPanelHiddenByWailsMarksPageOutOfSight -count=20:
  3 of 20 red with the issue's exact message.
- fixed, both visibility tests -count=20: ok, twice (the second at this
  commit's tree).
- go test ./internal/gui -count=1: ok (117.7s).
- gofmt -l internal/gui: clean.

Broken by hand, with the fix:
- WindowLostFocus no longer ExecJS's the hidden signal: 3 of 3 red
  ("timed out waiting for the page to see itself hidden").
- Escape's binding a plain w.Hide(): 3 of 3 red, the same.

Not tried: the full go test ./... — mote's suite lock had six suites
queued ahead; it is queued, and its result goes on #5322. Not tried on a
Mac with the panel really on screen (CI's runner and mote only).

Fixes #5322
2026-11-08 14:13:34 +08:00
yetone c3a9574de4 gui: a key's row keeps its controls shown and stays put under the pointer
tenacious_eagle_96548 (Discord, #general): in a provider's editor a key's
row showed its controls only under the pointer, so it kept growing and
shrinking, and moving away to fill in something else collapsed it.

Cause: app.css (#841) gave a key's unset controls (No limit at once, No
spend cap, Set balance, Switch off, Remove) no room off the pointer. A
hover made the row wrap from 38px to 59px and pushed the rows below
down. With Set balance open and typed into, moving the pointer to the
Name field collapsed the other pills, and the field moved 158px right
and 25px up under the caret (real magpie web, sandbox HOME on mote).

Fix: the list is drawn only in the provider's editor, where every key is
there to be set, so a key's row now shows every control, laid out the
same under the pointer as off it, as a phone's already did. The name and
the masked key stay whole; what doesn't fit beside them goes under the
row's first line. The "held" class that kept a clicked row open is gone
with what it worked around. Subscription accounts' rows (opacity only,
no shift), grips and the ⋯ menu are unchanged.

New key-row-steady.test.cjs: chromium and webkit, en/zh/zh-TW/ja/de, app
560/1000px and tab 420/1000px. Every control is shown off the pointer,
nothing in any row moves with the pointer over any row, and a balance
being typed keeps its place, caret and "100" when the pointer goes to the
Name field. key-row-chips-fit's "one line when not hovered" became "laid
out the same hovered or not"; stale hover comments updated in
key-own-balance, key-spend-cap, key-switch, key-gemini and key-plan.

Run (mote, through mote-run, at this head on origin/main c736906b1):
- go test ./internal/gui -run Budget: ok. gofmt -l internal/gui: clean.
- GUI key-*.test.cjs (44 files, both engines): 457 pass, 5 red:
  key-replace webkit 420px "Change key puts the new value" in all five
  languages, red the same on origin/main c736906b1 (#4126, ebody holds).
- key-row-steady: 40/40.
- Real app: rows 58/59/59px with the pointer off and over each row; the
  balance field's rect unchanged and focused after the pointer left.

Broken by hand: with origin/main's app.css and app.js, key-row-steady and
key-row-chips-fit failed 80 of 100 ("Set balance is hidden off the
pointer", "no proto shown"); with those visibility checks taken out,
"the pointer over k1 moved k1's row" 15 of 15. The 420px tab passed
either way (a phone already showed everything). A first cut let the
masked key shrink: key-weight-fit at 900px went red ("its masked key is
cut"), fixed here by keeping it whole.

Not run at push: the full Go suite and the full GUI suite (queued on
mote behind other sessions' suites under suite.lock; reds go to issues).
Not tried: Linux WebKitGTK and Windows WebView2 apps (CSS only, no new
API or motion).

Sibling left alone: a gateway key's unset quotas badge takes room only
under the pointer on the Gateway page (#5676).

Reported-by: tenacious_eagle_96548
2026-11-08 14:11:10 +08:00
yetone c736906b17 providers: part of a key's typed balance may expire on a day
tenacious_eagle_96548 (Discord, #general): some vendors split a balance
into money that stays and credit good until a date. A key's balance typed
by hand can now carry that part (`expiring`: {amount, until, at}, in the
balance's currency, until = the last day it counts).

- Spending order: the expiring part is spent first, as DeepSeek spends
  its granted balance before money topped up. It takes the spend from its
  `at` up to its end (midnight after `until`, local time) or now; only
  what it took after `From` comes off the rest, so a refill or typing the
  balance again doesn't count it twice.
- Left is the whole balance. From its end the remainder counts no more,
  and unspent credit is gone.
- Typing the balance again keeps the part in the same currency and drops
  it in the other, where its amount would mean another sum.
- A balance saved before has no part and reads exactly as it did
  (TestTypedBalanceSavedBeforeExpiring).
- Set from the pill's menu: "Credit that expires…" asks the amount, then
  the last day (a day gone by, or the other currency's sign, refused);
  "No credit that expires" takes it off. GUI route provider/keyexpiring;
  CLI `magpie provider key-balance <id> <key> --expiring amount@yyyy-mm-dd|off`.
- Shown: the pill "≈$100.00 left · $30.00 expires in 30 days", the Usage
  page and panel line "Expires in 30 days ≈$30.00", amber from 7 days;
  TUI and `magpie quota` "($30.00 until Dec 7)". New strings in zh,
  zh-TW, ja and de.

Run (mote):
- go test of internal/provider, internal/gui, internal/cli (with
  TestCoreScriptBudget: the days' lines in app.js are paid for by five
  balance comments cut there, no raise; core 1,533,559 of 1,533,802); the new tests
  again with TZ=UTC and TZ=Pacific/Kiritimati (every clock held);
  gofmt -l clean; GOOS=linux and GOOS=windows go vet of those packages.
- GUI: key-balance-expiring.test.cjs 20/20 (chromium and webkit, 400px,
  en/zh/zh-TW/ja/de), with every balance-*, key-*, i18n-* file: 768
  pass, 6 red, each red the same alone on origin/main 691a10446:
  i18n-keys "a plugin's words are its own" (#5327) and key-replace's
  five webkit 420px cases (#4126, numbers added there).
- A real sandbox (own HOME, -tags nogui binary, ports 3591/3592): set
  $70 + $30 until +30d and ¥40 + ¥5 for +3d through the CLI, then
  through the pill's menu in the real page (¥8 for +6d, then removed);
  a past date shows the part no longer counting; retyping in USD dropped
  the CNY part; `magpie quota` shows the split. No page errors.

Broken by hand, each red:
- Go (TestTypedBalanceExpires): part not spent first; end taken in UTC
  (red under Kiritimati); part kept after its end; part kept across a
  currency change.
- GUI (key-balance-expiring): no soon class; soon only from 2 days; a
  past day accepted; the other currency's sign accepted.

Not tried: a real vendor's spend priced against the part; the GUI on
Windows or Linux. The full Go and GUI suites were queued on mote's
suite lock behind other sessions' and had not run when this was pushed.

Reported-by: tenacious_eagle_96548
2026-11-08 13:39:32 +08:00
yetone 691a10446e native: pf-serve on the CPU maps the model instead of reading it into its own memory
magpie-community/plugins#853 (kongbai01203, Windows, 0.1.3295): the
first request that needs Privacy Filter started pf-serve, which held
1.82 GB of private memory until it was ended for idling.

On the CPU, privacy-filter.cpp opened the GGUF with no_alloc=false, so
ggml read all 1.6 GB of weights into a malloc'd buffer: private memory,
commit charge, written to the page file under pressure. Measured on
pf-v3's Windows pf-serve on xiaomi-gpu: 1,749 MB private after load,
1,822 MB after a 20 KB text, the reporter's number. The rest is the
graph's buffers (~200-270 MB).

patches/weights-paged.patch (applied after weights-once, by name) opens
the GGUF for metadata only on the CPU too, maps the file read-only
(mmap PROT_READ / MapViewOfFile FILE_MAP_READ) and points each tensor
at its bytes there, with bounds checked against the file's size. The
weights are the file's pages: read in as used, never part of the
commit charge, and dropped under pressure without being written
anywhere. The GPU paths (Metal, Vulkan) are unchanged. The bytes the
graph reads are the same, so the results are too.

Run, with the branch's CI build (pf/mmap, run 42448144708) against
pf-v3's release, the real q8 model and a 261 B to 78 KB text:
- Windows (xiaomi-gpu), pf-serve on the CPU: private 1,749 -> 200 MB
  after load, 1,822 -> 273 MB after the long texts; working set 1,809
  -> 1,363 MB (file pages, only what was read). pf-serve-base the
  same. Every span, offset and score hashed: identical to pf-v3 for
  pf-serve, pf-serve-base and pf-serve-vulkan. Vulkan on the Radeon
  8060S unchanged (~1.9 GB private, the driver's).
- macOS (mote, M5 Pro), PF_DEVICE=cpu: physical footprint 1.7-1.8 GB
  -> 209-303 MB; spans identical. Metal unchanged.
- Linux (WSL magpie-desktop): RssAnon 1,822 -> 276 MB.
The next commit pins pf-v4, built from this one, and adds the test that
is red on pf-v3 and green on it on all three systems.

Not tried: a machine under real memory pressure; a model file replaced
under a running pf-serve (magpie never does: it is renamed into place
once and Remove stops pf-serve first).

Reported-by: kongbai01203
2026-11-08 13:01:26 +08:00
yetone 5a27348058 providers: a key's balance picks its currency beside the field, the number kept
Changing a key's balance from $ to ¥ meant clearing the balance, switching
Settings' currency, then typing it again (a bare number kept the old
balance's currency). The balance field now has a currency button beside it
(USD/CNY, the app's menu, not a native select). It starts at the balance's
own currency, else Settings' one, which stays the default for new
balances. Picking keeps the typed number and posts nothing; Enter or
leaving the field saves, and the pill then reads ≈¥40.00 left. A typed ¥
or $ flips the button as you type. Nothing is reinterpreted: Settings'
currency still never touches a saved balance, and usage and cost displays
are unchanged. No server or API change; keybalance.js is lazy-loaded, so
app.js and the core budget are untouched.

Run (mote):
- key-own-balance.test.cjs: 20 of 20 ok (chromium + webkit, narrow width,
  every language), with new cases: $40 → CNY picked → Enter posts
  {balance:40,currency:"cny"}; ¥100 → Escape posts nothing; → USD, Tab
  away posts {balance:100}; no row runs past the window.
- Whole GUI suite (earlier run at this change): every file ok except
  i18n-keys "a plugin's words are its own", red on main already and filed
  (#5327, #5332, #5426, #5482).
- Real GUI, sandbox HOME on mote (go build -tags nogui, ports 3591/3592):
  typed 40 → ≈$40.00 left; Enter balance…, picked CNY, field kept 40,
  Enter → ≈¥40.00 left, no page errors; `magpie provider key-balance`
  read ¥40.00 typed. Screenshots taken.

Broken by hand: the old keybalance.js against the new test times out
waiting for the currency button; dropping the blur guard (saving when
focus moves to the button) makes the menu pick time out because the field
saved and redrew under it (chromium and webkit). Both red, restored.

Not run to the end: the full Go and GUI suites are queued under
suite.lock on mote behind ~20 other sessions' suites (~/runs/bc-suite);
no Go file changed. Not tried: the real desktop window, WebKitGTK on
Linux, Windows.

Reported-by: tenacious_eagle_96548
2026-11-08 12:54:13 +08:00
yetone 5849b47ca0 provider: Grok's mover min is 0.2.6 (plugins#852)
opencode-grok-auth 0.2.6 (plugins ae5188363, lxyer) asks Grok again
when a Responses stream is cut before its first byte. It tries up to
three times, before the answer is returned, so a 429 or 401 on a retry
comes back as itself. Once a byte has arrived, the stream goes on as it
comes, reasoning included. A later cut just ends the stream, and magpie
closes it as a whole response.failed (29bfd5dc8, v0.1.3298). The
plugin no longer writes a response.created or response.failed of its
own: those frames had no sequence_number, and Grok Build failed the
turn on them. An upstream response.failed or error goes on as it came.

npm has 0.2.6: `npm view --prefer-online
@magpie-community/opencode-grok-auth time` gives
2026-11-08T04:50:00Z. The publish run's npm job is red only for
middleware-think-tags 0.1.2 (E404, plugins#180). grok 0.2.6 was
published in that run.

Run on mote at this tree: gofmt -l is clean; go vet
./internal/provider on darwin, linux nogui and windows; go test
./internal/provider: ok (119s).

The plugin's side was run at 463afb79 on mote. Its package tests: 107
pass. The repo-root bun test: 6878 pass, 0 fail. check.mjs grok: ok.
Breaking the retry by hand turned the tests red. The real chain was
Grok Build 1.0.67 and 1.0.77, then magpie eef99e4bb, then the plugin,
then a fake upstream that cuts before the first byte, after
response.created and after text. Every cut was read and retried, with
no "missing field". A retry's 429 reached magpie as a 429, and a vendor
response.failed showed its own message. The plugins merge body has the
details.

Not tried: a live Grok stream cut by the real vendor.
2026-11-08 12:53:45 +08:00
yetone eef99e4bbe redact: a value on both Masked words and Never mask is masked; Never mask still beats the user's rules
TakaNaShi_ShiKi on X asked for a way to keep a value from being masked.
That exists already: Settings › Privacy › When a value is found ›
Never mask (RedactAllow, Options.Allow, since b00c82acf), and a click
on a masked value in a request's masking record adds it there
(/api/masking/allow). It is applied in apply() to every span, whichever
finder found it: magpie's rules, the user's rules, the local model and
known values. Nothing new is wired for it here.

What was undecided was the order between it and the user's own lists.
apply() let a Never mask value go even when the same value was one of
the user's Masked words, and an allowed value hid a masked word inside
it (Masked word "kelvarn", Never mask "team.inbox@kelvarn.io": the
word went out). The value menu already refuses Never mask on a Masked
word ("One of your Masked words"), but the settings list doesn't.

Decided: of two things the user asked for, the one that keeps a value
from the vendor wins. A Masked word is masked even when Never mask
lists it, and a Masked word inside a value Never mask lets go is
masked. Never mask still wins over every finder, the user's own rules
included: a value named there is the exception to the user's pattern
(rule PROJ-\d{4}, Never mask PROJ-0001: PROJ-0001 goes as written,
PROJ-0002 is masked). Matching is unchanged: a whole value, any case.
A user with a value on both lists before this sees it masked from the
next request on.

Test: TestMaskedWordsWinOverAllow (new). Broken by hand (apply()
restored): FAIL "a value on both lists went as written: \"deploy on
build-01, mail team.inbox@kelvarn.io, …\"" and "a masked word inside an
allowed value". Restored: ok. TestAllowLetsAValueGo still passes.

Run (mote-run, at eb7ce732a): gofmt -l internal/redact (empty), go vet
./internal/redact/, go test -count=1 ./internal/redact/... ok.
Not tried: a running magpie; no GUI change, so no GUI run in this
commit.

docs/subsystems/gateway-routing.md says the order beside Never mask.
2026-11-08 11:49:18 +08:00
yetone 2d90c7c565 redact: a hex number (0x and up to 16 hex digits) goes as written, whatever the local model takes it for
TakaNaShi_ShiKi on X: in reverse-engineering notes, an address written
as inline code, `0x004EA5E0`, went to the vendor as {{SECRET_6kkmmxxd}},
and the vendor's model lost the data it was asked about.

Which finder took it: no rule. With Secrets and Personal on and every
kind on, the rules alone mask none of the values in the new test (the
"by the rules" checks in TestHexNumberGoesAsWritten). The local model
did. Asked for real (Privacy Filter and AstrLink Guard from this Mac's
cache, copied to mote, MAGPIE_EVAL_CACHE), on a notes table:
  Privacy Filter: secret 0.679 on 0x0058C210 (beside "密钥表")
  AstrLink Guard: secret 0.625 on the same
  Privacy Filter, "The license check is at `0x004EA5E0`; the key table
  at `0x0058C210`.": account_number 1.000 and 0.995 on both
  Privacy Filter, "key: 0x004EA5E0": secret 0.992
modelFits let them through: hexRe, which holds back a bare hex run
unless a key's name is right before it, asks lower case and no 0x, and
numberLike reads 0x004EA5E0 as a number, so ACCOUNT took it too. That
is the sibling, with the real model's evidence; PHONE did not take one
in the fake-model test, and decimal numbers already have their own
checks (numberNamedSecret), so nothing wider is changed.

Now modelTakes takes no value of any kind that is 0x or 0X and 1 to
16 hex digits (hexLiteral, a 64-bit value: an address, a constant, a
flag). No cue is asked, unlike a bare hex run: the function at an
address is often named for a key (DecryptKey: 0x004EA5E0), and
secretCued would read that as "key:". A longer 0x value (a 64-digit
private key, a 128-bit 0x+32) is masked as before.

Tests:
- TestHexNumberGoesAsWritten (new): the reporter-shaped table row, a
  cued address, 0X upper case, 0xFFFFFFFFFFFFFFFF, a 64-bit x64dbg
  base; none masked by the rules, nor as secret, account_number or
  private_phone from the model; 0x+64 and 0x+32 still masked.
- TestMaskEval: cases hex-addresses and hex-addresses-en, with the real
  models' recordings added (only these two entries; the rest of the
  recordings were left as committed, since re-recording on mote moved
  other cases' scores slightly).
- Broken by hand: the hexLiteral check taken out of modelTakes.
  TestHexNumberGoesAsWritten FAILs with eight masks
  ("0x004EA5E0" as secret: masked "...`{{SECRET_7bm7qoxm}}`...", as
  account_number "{{ACCOUNT_rcgox2br}}", 0xFFFFFFFFFFFFFFFF and
  0x00007ff6a1b20000 as secret), and TestMaskEval/privacy-filter FAILs
  with 'hex-addresses: "0x0058C210" was masked, and should go as
  written' and both hex-addresses-en values. Restored: both pass.

Run (mote-run, at base 4ab1191bc): gofmt -l internal/redact (empty),
go vet ./internal/redact/, go test -count=1 ./internal/redact/... ok.
Not tried: the reporter's own text (not posted in full); a running
magpie with the model on.

docs/subsystems/gateway-routing.md says it beside the EVM address rule.
2026-11-08 11:48:50 +08:00
yetone 9a92fd099b claude: a long auto mode classifier keeps its cache marks as claude -p (#5585, #5655)
With Claude Code's interactive mode on, the classifier was pasted into a
new run each call with none of its marks: Claude Code marks only the last
block of what it is pasted, and the classifier's tail changes every call,
so each call read only Claude Code's own prompt and wrote the whole
transcript again (126K and 132K a call at 1h's 2x in iamnil's rows).
Desktop's header-less classifier lost its marks at parse time
(e5f66f8a6); an opted-in one lost them when pasted.

There is no honest way to make the interactive Claude Code put a mark
mid-message: rewriting its body in tap.js would make the request unlike
Claude Code's and can pass the four-mark limit. So a classifier whose
marks keep 64KB or more of history (marksPrintAt, keptByPrint) runs as
claude -p, which keeps the marks (DISABLE_PROMPT_CACHING, the client's
marks in the first message, the tail through CLAUDE_CODE_EXTRA_BODY).
-p counts about 2x a token; with S Claude Code's prompt, M the marked
transcript and D the new part, interactive ~ 0.1S + 2M a call and -p ~
2(0.1(S+M) + 2D), which meet at M ~ 15-20K tokens. A shorter classifier
and every other request stay interactive; claudePrint names it
"cache-marks". No entrypoint, system prompt or identity text changes.

Run:
- TestClaudeTUIClassifierKeepsLongMarksAsPrint (with and without the
  header; a short classifier as control) is red with keptByPrint forced
  false (the old routing) and green with the fix.
- On mote at 70c10074c: go test -tags nogui -run
  'Claude|Classifier|AutoMode|Cache' ./internal/gateway ok; go vet
  ./internal/gateway for darwin, linux and windows ok; gofmt clean.
- Real account (one Max account, sandbox HOME, its keychain item copied
  to the sandbox's service name and deleted after; port 3481; Claude
  Code 2.1.316; claude-haiku-4-5), two classifier-shaped calls sharing a
  ~244KB prefix, interactive mode on:
    before (4ab1191bc): call 1 read 0 wrote 49,838; call 2 read 0 wrote 49,865
    after:              call 1 read 0 wrote 49,763; call 2 read 49,748 wrote 42
  The gateway logged both after-runs as claude -p with the reason.

Not tried: Claude Desktop's real classifier (the body was built to its
shape), Sonnet, Windows/WSL. Full suite not run at push; queued on mote
under the suite lock.

Reported-by: jerrychoi
Reported-by: iamnil (Discord)
2026-11-08 11:39:44 +08:00
yetone d0ce551344 providers: a browser editor keeps its place through a refetch
In a browser (web mode) WebKit gave the editor's redrawn body its scroll
bar a frame late; with "Model settings" a word shorter than the old
label, the foot wrapped differently, the body grew 48px and a place kept
at the bottom was clamped (provider-fetch-holds, webkit zh 420px, red at
the stack's head only). The body keeps its bar in a browser too, as it
already did in the Windows and Linux apps.

Broken by hand: without the rule provider-fetch-holds is red in webkit
zh 420px; with it provider-fetch-holds and model-api-preset pass 16 of
16 on mote.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: the macOS app (its body has no bar rule; unchanged).

Reported-by: axelburks (Discord)
2026-11-08 11:28:55 +08:00
yetone 7880a00ac6 models: a model of a key's provider can be asked on System One
axelburks on Discord: a relay serves its decision model under a name of
its own (an Ark endpoint id). A key's provider with a System One URL
beside a conversation URL can set a model's API to decide (System One
in Model settings' API row, its chip's right-click, or `magpie model
api <pid/model> decide`). The model is then a decision model there:
asked on System One by its own name, offered to routing groups, kept
out of the conversation models, and a turn for it is refused with 400
before the vendor is asked. Auto gives it back. A provider with no
System One URL, with that URL alone, an account, a remote magpie and
Vertex refuse it, saying why. Chat routing (apisAmong) ignores decide.

Broken by hand: removing the decideSet check in DecidesModel turns
TestModelSetToSystemOneIsADecisionModel and
TestModelSetToSystemOneAskedThere red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real relay's System One endpoint; fake vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone 7a6211d047 providers: a model's own headers, in Model settings
axelburks on Discord: a vendor routes one model by a header of its own.
A key's provider (built-in or custom) can give each model headers
(settings.ModelHeaders["pid/model"]). They go on that provider's
requests for that model alone, after the provider's headers and after
auth: a name both have is sent once, as the model's, so a user's value
is never overridden by the provider's or magpie's key header. The
gateway names the model (provider.WithModel) on every route that asks
one: chat on each API, translated and streamed, count_tokens, System
One's decision, embeddings, images, videos and the model test. A
fallback provider serving the same model id gets its own headers only.
Accounts and plugins carry their sign-in's headers and take none.

The editor's "Name, price and reasoning level" panel is now "Model
settings" (every language), with + Add header per model, staged and
made with the Save; Restore default takes them away.
The rows being typed are kept out of the draft's
compare, so an untouched editor still closes without asking.

Broken by hand: dropping WithModel from gateway.go turns
TestModelHeadersReachTheirModelOnEveryRoute red; dropping the provider
id check in modelOf turns TestModelHeadersStayWithTheirProvider red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real vendor that routes by header (Ark); fake vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone ae58ec9b44 providers: a key's provider can have its model list off
axelburks on Discord: Ark's pay-as-you-go list names models that can't
be asked for, and each one is asked by an endpoint id the user made. A
key's provider can now have its list off (Provider.ListOff): nothing
asks its vendor for a list (Fetch, Refetch, List, RefreshLists, a test,
a new key's prefill, a resting key's probe), a list fetched before and
models.dev's are not read, and only the ids added by hand are served.
The editor shows it as "Fetch the model list", ticked by default;
unticked, Fetch models and Forget go. A save that doesn't name listOff
keeps it. CLI: `magpie provider set <id> list=off`. Accounts and plugins
list as their sign-in does, so they don't take it.

Broken by hand: ListAsks returning false for a list-off provider turns
TestListOffAsksNoListAndServesTheIDsAdded red; dropping the keep in the
save turns TestProviderSaveListOff red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real Ark account; the switch was checked against fake
vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone 4ab1191bc9 routing: Routing groups opened from Routing lead back to it
Since Routing groups became a page of their own, a group chip on a
request (or Routing's "Routing groups ›") switched to the groups page
with nothing leading back. Without the sidebar the only way out was the
tab bar, and the request you came from was gone from view.

The groups toolbar now starts with "‹ Routing" (gBack). It goes back to
Routing through window.show, so a dirty draft is still asked about, and
focus returns to the chip or button the page was opened from. Esc does
the same, except while an editor, Import, Select or a modal is open, or
focus is in a text field. With the sidebar the back control shows only
when the page was opened from Routing (.rt-gfrom); from the sidebar's own
Groups tab the page is top level and has none. No other drill-in page in
app.js binds Cmd-[, so neither does this. The label follows the language
on every draw. No new layout, no accent stripe.

Run (mote, playwright 1.62.0):
- routing-groups-back.test.cjs (new): 30/30, Chromium and WebKit x
  en/zh/zh-TW/ja/de x 1280 window, 640 window, 420 web. Red on
  origin/main's assets (MAGPIE_ROUTING_ASSETS): no visible .rt-gback.
- Broken by hand: Escape handler off -> red (chromium en 1280); the
  side-nav hide rule off -> red (webkit en 1280, "no back from the
  sidebar's own tab").
- Every routing*, sidebar*, group-*, i18n-keys, i18n-en-no-cjk,
  old-webkit and settings-groups file at 2d66e9f23 (main 0fc3455e2 +
  this): 3548 tests, 3526 pass, 22 red. The same files at origin/main
  cdf734757 alone: the same 18 red, all filed: i18n-keys (#5332, #5426,
  #5482), routing-intent-entry 8/8 (#5392), routing-context-fold webkit
  (#5586), routing-row-swap (#3799), routing-story-shrinks webkit
  (#3954). The other 4 (routing-busy chromium zh, routing-many-keys
  chromium en, routing-pace-expiry chromium de, routing-rule-drag webkit
  ja) passed whole, with routing-groups-back, at this commit on
  cdf734757 (70/70); filed #5665, #5664, seen in #4082, #3789.
- Whole GUI suite and ./...: queued on mote, not run at push; results to
  follow.

Reported-by: unscientific9 (Discord)
2026-11-08 11:04:43 +08:00
yetone 29bfd5dc8b gateway: a Responses stream magpie ends is a whole response.failed (plugins#852)
When a Responses stream ended short or was cut, passthrough wrote a
response.failed with only object, status and error. Grok Build reads
the Responses stream through async-openai's types. Their Response needs
id, created_at, model, object, output and status, and the event needs
sequence_number. So a Grok plugin stream cut by the vendor ended in
"serialization error: missing field `created_at`" instead of the error
(lxyer's report behind plugins#852).

Now passthrough writes a whole response.failed:
- usageSniffer keeps the stream's response id, created_at and the next
  sequence_number;
- if responsesTextCalls renumbered the events on the way out, the
  failure follows the last number the client got;
- id, created_at, model and the error are filled in.
Before any event there is a fresh resp_ id and the time now.
The Chat and Gemini failures are unchanged. The translator paths
already end through responsesEncoder, which writes a whole response,
and nothing else writes a Responses streamFailure.

Run:
- On mote, at this tree: gofmt -l; go vet ./... on darwin, linux nogui
  and windows; builds for all three; go test -tags nogui -timeout 45m
  ./...: 87 packages ok, one red,
  TestCancelledSignInEndsItsFetch in internal/plugin, which this change
  doesn't reach (open as #5264). That run was at the base 0fc3455e2.
  Rebased on 00198b26e (#5655, gateway): gofmt -l, vet on all three
  systems and go test ./internal/gateway again: ok. Rebased again on
  cdf734757 (automode text, OpenMausBot): vet, build and
  -run 'StreamFailure|AutoMode|Automode|Anthropic' ./internal/gateway ok.
- Red on the old code (the tests at 0fc3455e2's gateway.go and
  sniff.go): TestResponsesStreamFailureIsAWholeResponse ("no
  sequence_number", "response.created_at missing") and
  TestResponsesStreamFailureBeforeAnyEvent.
- Real Grok Build 1.0.67 on mote (`grok -p`, api_backend responses)
  against a fake server replaying each ending:
  - the old frame: "missing field 'created_at'";
  - a whole response without sequence_number: "missing field
    'sequence_number'";
  - the new frame, after text, after response.created, and bare: read,
    and retried as server_error, with no serde error.

Not tried: Grok Build 1.0.77 (the reporter's), and a live Grok stream
cut by the vendor.
2026-11-08 11:03:09 +08:00
yetone cdf734757a agent: OpenMausBot gets magpie's models back, and a Restart for a list it hasn't read
maxleebeta (Discord #feedback, 11-08) picked Antigravity's models in
magpie, and OpenMausBot's model search didn't find them. magpie wrote them
correctly: a sandbox with an Antigravity sign-in lists
antigravity/gemini-3.8-flash[1m] and the others in config.json. OpenMausBot
loses them in three ways, each reproduced on the real app:

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

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

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

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

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

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

Reported-by: maxleebeta (Discord)
2026-11-08 10:55:49 +08:00
yetone 06324e99e8 automode: say that Claude Code may have no local check behind a gateway
chenxiang0010 saw "Auto mode can't check actions in this session ...
your requests go through 127.0.0.1:3425, which doesn't pass it
through". magpie's comments and the gateway-routing and agent-wiring
pages said that Claude Code, finding no safeguard_results, classifies
locally. Claude Code 2.1.312 to 2.1.316 (read from their bundles) turn
that local classifier off behind a non-Anthropic base URL when
Anthropic's per-account flag tengu_bright_dragonfly is "all"
(PA(), bbt(): auto_mode_side_calls_retired, localClassifierSwitchedOff).
A call with no server verdict then gets "No classifier runs for this
session", and each action the check would judge asks for approval.
2.1.314 adds the text for CLAUDE_CODE_AUTO_MODE_SERVER=0: "Claude Code
no longer has a check of its own to use instead".

So on a route only Anthropic doesn't answer (another vendor's model,
another subscription's Claude, a translated route, a relay that drops
the fields), auto mode has no check at all for such an account. magpie
can't answer one on Anthropic's behalf. The reviewed routes (Anthropic's
API, a relay passing the fields, the Claude subscription bridge) still
carry the beta, safeguards and safeguard_results as before. Comments and
docs only, no change in behaviour.

Not changed: answering 400 naming safeguards on an unreviewed route, as
Claude Code's gateway spec allows. It sets a refused latch for the
session, so a later /model to a reviewed Claude stays unchecked, while
the strip loses nothing.

Run: gofmt -l internal (clean); go vet -tags nogui ./internal/gateway
./internal/agent on mote (ok).
Not tried: a real Claude Code run, since the flag is Anthropic's per
account and the reporter's route is unknown.

Reported-by: chenxiang0010 (Discord)
2026-11-08 10:55:10 +08:00
yetone 00198b26e0 gateway: a session's side call goes on the account its main conversation is on (#5655)
With two Claude accounts, Claude Desktop's own Sonnet calls beside an
Opus chat (desktop-beside), and Claude Code's auto mode classifier, ran
on account B while the chat was on A. Each model's conversation is kept
under its own scope (p.ID/model), so the side call was routed as a
session of its own: leastHeld, or Smart's order once its cache was cold,
put it on the account the fewest others held, and B's 5 hours drained on
calls the user never made there.

Decided (product call delegated): one session goes on one account. The
user picked one, the vendor sees one client, and the cost is one cache
write of the side call where the session goes on reading it.

withSession (affinity.go) puts first, for a request whose session a
header names, the key or account of that session's largest conversation
under another model's scope (answered within heldFor, at least
cacheWorth kept, larger than this one's own). It acts for Why first,
gone, cold, no-cache, cache and session; never mid-turn, under Strict,
for a subagent (withLead), past a rest, reserve, credits or a fallback
routing put first, nor to an account that isn't readyForNew. The trace
says Why "lead" with LeadModel, and the Routing page says "Put on
{first}, where this session's {model} is: one session goes on one
account." in en, zh, zh-TW, ja and de. docs/subsystems/gateway-routing.md
says the same.

Not fixed here: the classifier's ~110-130K cache write per call. That one
is ours too: in Claude Code's interactive mode the bridge pastes the
classifier's transcript as one block without the client's marks
(claudetui userPieces, clientCache.pasted), so only the fixed prefix
(Claude Code's system plus the appended rules, the 68,925) is read and
the rest is written again on every call. The cause and a candidate fix
are on #5585. It changes what a real Claude Code sends and can't be
checked without a real account.

Run (mote, through mote-run), at this head (aeeeed54a's tree, origin/main
0fc3455e2 unchanged after a fresh fetch):
- go test ./internal/gateway ./internal/gui -count=1 -timeout 45m: ok (964s, 157s).
- TestSessionSide*, TestGroupAccountsHoldEveryRoute,
  TestPluginFactoryStandardOnlyCaps, TestWholeSession*, TestBusyModel*,
  TestInOrderKeeps* -count=2: ok.
- gofmt -l: clean. go vet ./internal/gateway for darwin, linux, windows: ok.
- node --test routing-affinity-lead (new), routing-affinity-order,
  routing-affinity-cache-write, i18n-keys, i18n-en-no-cjk: 67/68
  (Chromium + WebKit, 1100 and 420, en/zh/zh-TW/ja/de). The one red is
  i18n-keys "a plugin's words are its own", red on main for strings this
  change doesn't touch (#5327/#5332, #5426, #5482).
- The first package run of this change failed TestGroupAccountsHoldEveryRoute
  and TestPluginFactoryStandardOnlyCaps/auto (both green at 0fc3455e2):
  without a session header the id is the opening's hash, so two
  conversations that opened with "hi" were one session, and a main with
  nothing cached led. Both are excluded now, each with a subtest.
- The full go test ./... under the suite lock was queued behind four
  other sessions' suites and had not started when this was pushed.

Broken by hand, each red: the withSession call removed (both new tests;
"the session's m2 call went to k2 while its chat is on k1"); the named
session check removed (no session named); the cacheWorth bar removed
(main holds no cache, and TestPluginFactoryStandardOnlyCaps).

Not tried: real Claude accounts, real Claude Desktop. A session already
split before this release moves its side call at the side call's next
turn, writing its cache once on the main's account.

Reported-by: jerrychoi
Reported-by: iamnil (Discord)
2026-11-08 10:40:22 +08:00
yetone 0fc3455e2a providers: a key's typed balance may be in yuan and refill each month or week
tenacious_eagle_96548 asked, after v0.1.3281's typed balance, to type it
in RMB and to have it refill (e.g. $10 a month, on the 1st).

- A balance may be typed in yuan ("¥100", "100元", or a bare number while
  Settings shows costs in CNY). What magpie counts spent stays in USD and
  is turned into yuan at fx.Known(): the rate internal/fx last fetched
  (cached 12h, fetched again in the background, never on a request).
  fx.Known never returns fx.Fallback, so with no rate fetched and
  something spent, what is left is unknown (left null; the card says
  why), not a guess.
- An optional refill: monthly on day 1-31 (past a month's end, its last
  day) or weekly on a weekday, at midnight in the user's local time.
  Nothing is stored on a refill: the spend counts from the last boundary
  after the balance was typed. Typing the amount again keeps the refill.
- GUI: the pill's menu gains Refills each month… (a day, in place),
  Refills each week… (the app's menu of weekdays) and Never refills;
  provider/keybalancerefill; keyownbalance takes currency cny. CLI:
  magpie provider key-balance <id> <key> [usd|¥cny|off]
  [--refill monthly[:day]|weekly[:mon…sun]|off]. Strings in zh, zh-TW,
  ja, de. docs/subsystems/providers-accounts.md updated.

Run on mote at this tree (base origin/main 350599a0f):
- go test -tags nogui -count=1 -timeout 45m ./internal/fx ./internal/provider
  ./internal/cli ./internal/gui ./internal/usage: all ok (suite lock).
- GOOS=linux go vet -tags nogui ./... ok; GOOS=windows go vet ./... ok;
  gofmt -l clean.
- key-own-balance.test.cjs 20/20 (chromium + webkit, en zh zh-TW ja de,
  900 and 400px): yuan typed posts currency cny, monthly day (40
  refused), weekly Friday, never. i18n-keys, i18n-en-no-cjk, old-webkit ok.
- Broken by hand, each red: Known returning Fallback
  (TestKnownIsNeverAGuess); refill days taken in UTC
  (TestTypedBalanceRefills, TestRefillDays); refill dropped on retype
  (TestTypedBalanceRefills).
- Full GUI suite still running at push: 3502 ok, 6 red so far, none in a
  file this touches: webkit By weight; webkit de 1100/420 Codex resets
  used by themselves; chromium en named caller keys; chromium zh-TW 420
  a key's several limits; webkit en gateway key held to its models.
  They are run on origin/main next and filed if red there.

Not tried: a live rate fetch (tests stay offline), the real app window,
WebKitGTK.

Reported-by: tenacious_eagle_96548 (Discord)
2026-11-08 09:03:00 +08:00
yetone 350599a0f1 gateway: a held request's route is done before its 504 goes (#4200)
TestUnroutedRequestShownThenAnswered went red on ubuntu CI under -race
at d4a6e9315: the client had the 504, and the held request's route
still said Done:false, Status:0. Cause: giveUp wrote the answer
(heldWriter.answer) and only then marked the route done, with its
status, error and, after writeHeld, its report's name. A client that
reads the 504 and looks at the Routing page at once (or the GUI's next
poll) could find the request still routing and naming no report. Not a
test-only race.

The class: giveUp is the only path that answers for a held request
(checkMost and checkUnknown both end there). answer is split in two:
claim takes the reply under heldWriter.mu (false if the handler began
one; the handler's writes go nowhere from then), and send writes it.
giveUp now writes the report before taking f.mu again (out of f.mu,
it is a file), claims the writer, marks the route Done/Status/Error/
Millis/Held in one update, and only then sends, all under f.mu as
before so the handler can't return between claim and send. A report
written for a request routed or answered meanwhile is removed. The
#4300 order (report taken before the answer) is kept.

heldAnswered (the tests' hook once the 504 is out) is an
atomic.Pointer now: with the route final before the answer, a test can
end while its giveUp still runs, and -race caught the plain var read
against the test's cleanup. TestUnroutedRequestShownThenAnswered holds
giveUp in that hook until it has read the route, so a route ended after
the answer is seen undone every time; it also checks the route names its
report as it is answered. The subsystem page says the route is final
before the answer.

Run (mote, Go 1.26.8, at base 44b762d50):
- Old giveUp, new test: go test -tags nogui -race -count=5 -run
  'TestUnroutedRequestShownThenAnswered$' ./internal/gateway: 5 of 5
  red, "the held request's route: ... Done:false Status:0" (the issue's
  text).
- This change: the same test -race -count=50: ok.
- Broken by hand (the route update moved back after send and the hook):
  -count=5, 5 of 5 red at unrouted_test.go:420.
- go test -tags nogui -race -count=3 -run 'Unrouted|Held'
  ./internal/gateway: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway (under
  suite.lock): ok (801s).
- go vet -tags nogui ./internal/gateway; GOOS=linux and GOOS=windows go
  vet -tags nogui ./...: clean. gofmt -l: clean.
- Rebased on origin/main 1cb3dc435 (internal/pii only): go test -tags
  nogui -race -count=3 -run 'Unrouted|Held' ./internal/gateway: ok.
Not tried: a real held request in the app; the full ./... suite.

Fixes #4200
2026-11-08 07:20:19 +08:00
yetone 1cb3dc435a pii: a GPU pf-serve that died says why, not "read |0: file already closed" (#3741)
TestGPUDeathMovesToCPU went red on macOS CI at 778b8e075 with GPUError
"read |0: file already closed". pf-serve's stdout came from
cmd.StdoutPipe, and the goroutine that waits for pf-serve called
cmd.Wait, which closes that pipe's read end once the process exits. When
pf-serve died answering (a lost GPU) and Wait won the race with the read,
the read got os.ErrClosed instead of EOF; reader.fail takes only EOF for
a death, so the raw pipe error became the reason. Users saw it too:
Settings' privacy-filter status showed "file already closed" as why the
GPU was lost, and any answer pf-serve wrote just before exiting could be
dropped with the pipe.

Fix: stdout is magpie's own os.Pipe. pf-serve gets the write end, which
magpie closes after Start, so a read after the exit sees EOF and the
answer or death message is read whole; kill and end close the read end.
A beforeRead seam lets TestGPUDeathReadAfterExit read only after the GPU
pf-serve has exited and been waited for, so the ordering is red without
the fix every time.

Run on mote at this tree (based on 778b8e075):
- go test -race -count=20 -timeout 45m ./internal/pii/...: ok (pii
  1578s). The first try at the default 10m timed out mid-run in
  TestIdleServeEnds (1s in, no hang in the stacks): count=20 under race
  is longer than 10m.
- go test -timeout 45m ./internal/pii/... ./internal/gateway/...: ok
  (gateway 810s).
- gofmt -l internal/pii: empty; GOOS=linux go vet -tags nogui ./...: ok;
  GOOS=windows go vet ./...: ok; go vet ./internal/pii/...: ok.

Broken by hand:
- Old code with a 300ms pause before the read: TestGPUDeathMovesToCPU
  red with the CI's exact "GPUError:read |0: file already closed".
  With the fix and the same pause: green 3 of 3.
- Fix kept but the read end closed right after cmd.Wait (what
  StdoutPipe did): TestGPUDeathMovesToCPU and TestGPUDeathReadAfterExit
  both red with that message.

The issue's four ubuntu tests (TestWarm, TestFindJoinsTextsAndMapsBack,
TestServeStartsWithoutResidencyHeartbeat, TestGPUDeathMovesToCPU's
starts) had another cause, fixed in c84f859dd; ubuntu is green at
778b8e075.

Not tried: a real GPU death on a real pf-serve; the fake's death is
the same exit-after-stderr.

Fixes #3741
2026-11-08 06:51:03 +08:00
yetone 44b762d505 browser: Cancel on Chrome's bar stops typing that outlived its call
3379ebc42 lets browser_type answer while a long text is still being typed,
and kept the tab attached by calling attach() every 10s. A user who pressed
Cancel on Chrome's "is debugging this browser" bar to stop the agent could
have it put back: when the 10s tick landed in a pause between keys, attach()
re-attached the debugger, cleared stoppedByUser, and the typing went on
into the page against the user's stop.

- cdp.js hold() keeps an attachment on (puts off the let-go) and never
  attaches again; a tab let go or stopped by the user stays so. The typing
  job's timer calls it instead of attach().
- human.type stops before the next key once the user stopped the tab.
- ready() reports USER_STOPPED before a typing failure the stop caused,
  and browser_dialog, which attached without ready(), says it too instead
  of attaching again.
- Extension 0.1.9.

Run (mote, at this tree on 3379ebc42):
- go test ./internal/browserext/: ok. TestCancelStopsTypingThatOutlivedItsCall
  drives cdp.js and human.js in node with a stub chrome.debugger.
- Broken by hand: hold() calling attach() again → red "hold went on after
  the user's Cancel"; without human.type's check → red "the typing went on
  with the stop set: finished".
- MAGPIE_BROWSER_CHROME=Chromium 1248, go test -run TestBrowser
  ./internal/gateway/: ok (202s).
- gofmt -l, go vet ./internal/browserext/: clean.

Not tried: pressing Cancel on the real bar in a headful Chrome (the bar
can't be clicked from a test).
2026-11-08 06:10:40 +08:00
yetone 3379ebc423 browser: let a tab go 20s after its last call, CDP as Claude in Chrome uses it, input a person sends
Discord again took Magpie Browser for a bot. This lines the extension
up with Claude in Chrome 1.0.105 (fcoeoabgfenejglbffodgkkbkcdhcgfn), read
from its assets/mcpPermissions-*.js, and with what a real mouse and
keyboard send:

- A tab is let go 20s after the last call in it ends (Claude's qC=2e4),
  not 5 minutes after it was last attached. Before it goes, focus
  emulation is turned off, as Claude's detachDebugger does. A page behind
  the user's tab no longer goes on for minutes saying it has focus while
  its window reports 0x0. A tab no call used is left on its clock, so
  another session's calls don't hold it; typing that goes on after its
  call keeps its tab (re-armed every 10s) and lets it go when it ends.
- Attach turns on Page, Network (the page can't see it; settle needs it)
  and Runtime only where it was already (a dev host or browser_console),
  then focus emulation once. DOM.enable and Accessibility.enable are gone:
  Claude turns neither on, nothing listened to their events, and the
  calls magpie makes (getFullAXTree, resolveNode, getContentQuads, ...)
  work without them.
- A pressed button has pressure 0.5 (was 0; Claude sends force 0.5 when
  buttons != 0). Shift, Control, Alt and Meta have location 1 (left), as
  a real keyboard's; Claude passes the key's location too.
- No nativeVirtualKeyCode: it took the Windows code, and on macOS it is
  read as a Mac key code. Claude doesn't send it.
- Long text keeps a person's pace (~165ms a character, quickened only
  past 4 minutes) instead of fitting 35s, which reached 20+ characters a
  second. browser_type answers after 40s with how far it got; the typing
  goes on, and the tab's next call waits for it (BUSY after 60s).
- manifest 0.1.8.

Run on mote, headful Chrome for Testing (MAGPIE_BROWSER_HEADFUL=1):
go test ./internal/gateway -run TestBrowser -v: all 27 pass, among them
the new TestBrowserLetsATabGoAfterItsCalls (23.7s; the page's own
document.hasFocus() is on during calls and off within 15-45s after),
TestBrowserTypesALongTextAtAPersonsPace (66s, <= 9 chars/s, Enter after
the whole text) and TestBrowserActsLikeAPerson (pressure 0.5, Shift
location 1). Snapshots, frames from other sites, uploads and drags pass
without DOM/Accessibility enabled.

Broken by hand: IDLE_MS back to 5 minutes, TestBrowserLetsATabGoAfterItsCalls
is red ("still has emulated focus 45s after the last call"). Without force 0.5
on a click, TestBrowserActsLikeAPerson is red ("pressure 0: a mouse's is
0.5"); without location 1 on human.js's Shift, red ("location 0"),
once the test checks every Shift down, not only the last, which came
from keys.js's Shift+Enter.

go vet (darwin, windows, linux) ./internal/gateway ./internal/browserext:
ok. go test ./internal/browserext ./internal/gateway -timeout 45m
(headless): ok, gateway 866s.

Not tried: a real Discord account. Per the 11-08 limit nothing scripted
touches it. Not fixed: a background tab's outerWidth/outerHeight/screenX
are 0 while focus is emulated (Claude in Chrome has the same; the device
metrics override broke availHeight), and a page's own window.open from
the agent's tab still comes to the front for a moment.
2026-11-08 05:59:31 +08:00
yetone d4a6e9315b gateway: a new connection closed before Go wrote a byte of the request goes again, though Go says only "EOF" (#5519)
TestClosedBeforeSentIsSentAgain failed on CI's race run (b77400826) and
in a full suite on mote with `Post "https://127.0.0.1:…": EOF`. It is a
product gap, not the test's timing: the same happens to a user whose
proxy or TUN closes a new connection right after the TLS handshake while
the machine is busy.

Cause, read from Go 1.26.8's net/http transport: the issue's guess (the
8 MiB write had begun) is the other way round. Once the write goroutine
starts the body, any write failure is kept as the request's error
(doBodyCopy's bodyReadError, then mapRoundTripError's req.err), so
replayable sees a write error and sends again. A bare "EOF" comes only
when the reader sees the close and closes the connection before the
write goroutine has picked the request up at all (writeLoop takes
closech): nothing was written, WroteRequest never fires, and Go turns
nothingWrittenError{transportReadFromServerError{EOF}} into io.EOF. Go
doesn't retry on a new connection, and closedBeforeSent took only write
errors, so the turn failed as a 502 counted against the account.

replayable now also sends again on a new HTTP/1.1 connection that ended
with "EOF" or a read error (a reset) while the request's write had not
finished: no WroteRequest without an error (httptrace). Once Go has
written the whole request the same end may follow a vendor that read it,
and that is never sent again, as before.

Tests: TestEndedBeforeWriteBeganIsSentAgain gives replayable what Go's
transport gives it on that path (GotConn new, no WroteRequest, io.EOF or
a read reset) twice, then an answer. A real transport can't be held at
that point from outside net/http (a held connection write already counts
as a body write error), so the order is injected with a fake transport,
not left to the scheduler. TestEndedAfterWriteIsNotSentAgain gives it a
whole write then EOF. TestClosedAfterSentIsNotSentAgain now also ends the
real TLS connection cleanly (EOF) after reading the whole 8 MiB request,
besides the reset.

Run (all on mote via mote-run, at this tree on 778b8e075):
- Before the fix (upstream_transport.go at 778b8e075, new tests in):
  TestEndedBeforeWriteBeganIsSentAgain red 3 of 3 with the issue's error,
  `Post "https://127.0.0.1:1/backend-api/codex/responses": EOF`.
- go test -race -count=50 -run 'TestClosed|TestEnded' ./internal/gateway/:
  ok.
- go test -timeout 45m -count=1 ./internal/gateway/...: ok (internal/gateway 859s; exit 0)
- gofmt -l .: clean. go vet ./internal/gateway/, GOOS=linux go vet -tags
  nogui ./..., GOOS=windows go vet ./...: ok.

Broken by hand: without `wrote.Load() ||` (an EOF resent whatever was
written), TestEndedAfterWriteIsNotSentAgain goes red (err nil, the request
sent again) and TestClosedAfterSentIsNotSentAgain goes red for both the
reset and the clean end (3 connections, called unsent), 3 of 3. With
endedUnwritten taken out (the old code), TestEndedBeforeWriteBeganIsSentAgain
goes red as above.

Measured, not injected: 1,200 real closes after the handshake on mote,
with -race, -cpu 1,2,4 and 20 busy loops beside them, gave write errors
and one "server closed idle connection", no bare EOF; the race is rare,
as on CI.

Not tried: a real TUN proxy.

Fixes #5519
2026-11-08 05:56:59 +08:00
yetone 778b8e0753 provider: Kiro's mover needs opencode-kiro-auth 0.1.32, which waits out a 429 throttle as the Kiro IDE does
onemezao on Discord: a "hi" answered, and the next message straight
after was Kiro's 429 USER_REQUEST_RATE_EXCEEDED, while the Kiro IDE on
the same account took two in a row (plugins#842, plugins#848). The IDE
gets the same throttles but tries again, 3 tries after 1s and 2s or
Kiro's retryAfterMilliseconds; the plugin sent the first 429 straight
back with Retry-After 30s. 0.1.32 (plugins 966cf717) retries the way
the IDE does. Raising min makes keepMovedCurrent update every moved
user's plugin.

Run: npm view --prefer-online --registry https://registry.npmjs.org
@magpie-community/opencode-kiro-auth version = 0.1.32 at landing;
mote-run go test -run 'Kiro|Mover|Moved' ./internal/provider/ ok;
gofmt -l clean. The plugin's own record is in its commit (package 157
pass, plugins root 6867 pass 0 fail).

Broken by hand: in the plugin (5 tests red with the retry off); nothing
here beyond the version string.

Not tried: a real throttled Kiro account; none was at hand.

Reported-by: onemezao (Discord)
2026-11-08 04:59:59 +08:00
yetone 2b08ccc838 routing: the story says why by the keys Smart sorted by (#5646)
The Routing page explained Smart's order from each window's raw reset
(Weighed.Renews), while the gateway sorts by Allowance.Renewal (a credit
pack's end when it runs out before the reset) and breaks hour ties by
Allowance.Lapse. So a WorkBuddy account whose pack ends in 3 days was said
to "renew within the same hour, so the order given stays". The trace now
carries both keys (Weighed.Soon, Weighed.Lapse); renewsBy, cmpRenews,
firstWhy and behindWhy compare them, with two new story lines (credits
expire before the other renews; same hour but its credits expire sooner)
and a row note, in en, zh, zh-TW, ja and de. "Kept in order" is said only
when every key ties. A route from before soon falls back to renews and
restarts. The other keys Smart reads (tier, unreached, learns, balance,
use first) were already in the trace.

Two accounts with one name: logoed() gave only the first its icon. Each
later occurrence of the name now gets the next same-named member's own
icon, so "louis and louis" shows WorkBuddy's and Zhipu's.

Run (mote, via mote-run):
- go test ./internal/gateway -count=1 -timeout 45m: ok (1010s), before the
  rebase onto 0b4cda048 (no gateway trace/routing change between).
- go test ./internal/gui: ok. gofmt -l: clean. GOOS=windows go vet ./...
  and GOOS=linux go vet -tags nogui ./...: ok.
- After the rebase: TestTraceCarriesSmartSortKeys, TestSmartSpends*, and
  node --test of routing-story-credits-expire (62/62, Chromium + WebKit,
  en/zh/zh-TW/ja/de, 1100 and 420), routing-behind-why and every GUI file
  that was red in the full run below.
- Full routing-*.test.cjs + i18n-*.test.cjs at concurrency 4 before the
  rebase: 2955/2978. Rerun at concurrency 1 after it, 18 stay red, and the
  same 18 are red on a plain origin/main b77400826 copy on mote: i18n-keys
  (#5332, #5426), routing-intent-entry (#5392), routing-row-swap (#3799),
  routing-story-shrinks WebKit (#3954), routing-context-fold WebKit (#5586).
  routing-many-keys, routing-order-unknown and routing-steps-cap passed in
  the rerun.

Broken by hand, each red: no Soon in weighed() (Go), no Lapse (Go),
renewsBy ignoring soon (GUI pack case), no lapse tie-break in cmpRenews
(GUI shows the reporter's "保持原顺序"), logoed with one icon only.

Not tried: a real WorkBuddy account's trace; the real Linux app. Two
same-named members of one provider still show the same icon.

Fixes #5646
Reported-by: louisgreen0726
2026-11-08 04:06:22 +08:00
yetone b77400826a usage: the Overview read again keeps its cards and its place, and shows it is reading
jiabubu on Discord: a refresh of the Usage page's Overview showed nothing
while it read, flashed the page and dropped cards for a moment, and
pressing Usage again while on the Overview flashed it or moved its scroll.

- Pressing Usage again (show() calls the plugin's open, loadUsage(true))
  put the skeleton up, which hid the sections, collapsed the page and
  clamped its scrollTop. loadUsage now puts the skeleton up only for a
  first read or another period or zone (usageFor/usageKey); a page that
  already shows that read reads again quietly through refreshUsage, so
  nothing is blanked and the scroll stays.
- The refresh beside the period turns while such a read is out
  (#usageReload.reading, after 200ms), and while every card is read
  (loadQuotas) each card's refresh turns (#subscriptionUsage.reading,
  quotaReading in page.js). A card's own busy turn is left to its own
  animation (:not(.busy)). No turning under reduced motion.
- renderQuotas draws the cards again in one go, as their reset
  countdowns need, but now keeps their logo nodes (keepIcons), and the
  Overview's lists do too: a logo made afresh blinked out while its
  picture loaded.
- app.js stays in its budget: a three-line comment in renderQuotas cut
  to one. Core 1,533,507 of 1,533,802 before the rebase on 0b4cda048.

Tests:
- New usage-quiet-refresh.test.cjs: Usage pressed again at the top,
  halfway and at the foot, with the read held: no skeleton, chart not
  hidden, scrollTop the same, the refresh turning, then the same figure,
  row and logo nodes; and Refresh with the allowances held: every card
  stays, each card's refresh is shown and turning, the logos kept.
  Chromium and WebKit, en and zh, 1180 and 560px. Red on the old assets
  (8 of 8 per part: "nothing blanked while it reads ['skeleton','chart
  hidden']", "the cards' logos are the ones drawn before: false,false,
  false"), green on the new.
- usage-quota-head.test.cjs waited for the skeleton on Agents -> Usage;
  it now waits for the quiet read (the page kept, the refresh turning).
- usage-stale-answer.test.cjs lifts loadUsage out of page.js; it now
  lifts usageFor/usageKey with it and stubs the page's loading state.

Run on mote (mote-run), at the rebased head 344cdcde3: go test -run
TestCoreScriptBudget ./internal/gui ok; gofmt -l clean; the nine usage,
quota and panel files above plus panel-fit-tabs, panel-usage and
panel-quota-refresh: 140 of 140. Before the rebase (at d32a7a70c's base,
same change less the stale-answer stub): go test ./internal/gui ok apart
from TestSettingsSaveKeepsWhatItDoesNotSend, fixed on main by c7c05dcf2;
GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... clean;
every GUI file named usage, quota, allowance, click-scroll, sidebar or
last-page (129 files, 1880 tests): red only in files red on main too or
filed: usage-agents-hide (#2276, #3414, red at d32a7a70c alone),
usage-fold (#3415, red at d32a7a70c alone), usage-ledger's Requests
(#5048), and usage-compact-counts' zh-TW 420px tip under load (#5648,
30 of 30 alone); usage-stale-answer's reds there are fixed here (11 of
11).

Not tried: the whole GUI suite (1,274 files; mote at load 60 to 80
from other sessions), the real app and WebKitGTK, languages beyond en
and zh in the new test (no new strings), and the other pages' re-open
by probe (Sessions, Library, Gateway and Masking were read: none puts a
skeleton up over a page already drawn).

Reported-by: jiabubu (Discord)
2026-11-08 03:57:04 +08:00
yetone 0b4cda048c gui: the tray panel shrinks back to a short tab, gliding there
The tray panel was held at its tallest tab's height (#124): fit()
measured every tab and asked for the largest. Once Routing or Usage had
been opened, Agents sat over empty room under its rows until the panel
was let go (refeccd on Discord, macOS). fit() now lays every tab out
the same way and asks for the height of the tab showing (Agents when
none is set), so the panel shrinks as well as grows. #124's complaint
was the panel jumping bigger on a tab switch, so a tab picked glides
the edge there instead (TAB_GLIDE: 240ms on app.css's --ease-out, as
.nav-hl; a jump under reduced motion). Content fits inside a tab
(rows unrolling, Allowances landing) are unchanged.

Siblings: the Go side already shrinks on every OS. FitPanel takes the
height asked, panelFrame clamps it to panelMin/panelMax/the screen, and
glidePanel animates the Mac's frame with its top under the menu bar and
steps Windows/Linux by the tray icon. All three take their height from
this one fit(), so nothing there changed. The web host has no panel.

panel-fit-tabs.test.cjs gets "the tray panel shrinks back to a short
tab": two agents and Routing's eight requests, Agents -> Routing ->
Agents, with reduced motion and without. Agents' height is asked
again, and the tab's fit carries ms=240 and the ease (none under
reduced motion). Its Routing-skeleton check now picks the Routing tab
first, as that is the tab whose height it is about. panel-usage's
assertion is now the showing tab's height, not the tallest.

Run on mote (mote-run). At this commit, rebased on d32a7a70c: gofmt -l
internal/gui nothing; go test -tags nogui ./internal/gui ok (sandbox
HOME); panel-fit-tabs, panel-usage, panel-fit-order, panel-fold 40/40.
Earlier, at the same change on c7c05dcf2:
- new test on origin/main's app.js: 10 of 10 red, Chromium and WebKit
  x en/zh/zh-TW/ja/de: "reduce: Routing asked no taller a panel than
  two agents: 163 629" (the short tab asked the tallest's 629)
- with the change: panel-fit-tabs + panel-usage 24/24 ok (both
  engines, five languages); again at the rebased head with i18n-keys:
  27/28, the one red is i18n-keys' "a plugin's words are its own",
  filed as #5332, #5426, #5482
- the 46 GUI files that read /api/window/fit (at d32a7a70c, before
  the rebase; the change is the same): 1182/1186. Reds, none in the
  panel: images-codex-one (Settings window; red alone on origin/main
  d32a7a70c too, #4618, commented) and view-open-wheel's "wheels
  unheard, usage, en, 1000px" in WebKit (window only, no panel page,
  where fit() returns at once; #4132)
- gofmt -l internal/gui: nothing; go vet, GOOS=linux go vet -tags
  nogui, GOOS=windows go vet ./internal/gui: ok
- go test -tags nogui ./internal/gui (sandbox HOME, pinned caches): ok
  (before trimming, TestCoreScriptBudget was 346 bytes over; the
  comments were cut, the budget not raised)

Not tried: the real app's panel on the Mac, Windows or Linux (no
desktop session driven); the whole GUI suite (mote's suite.lock queue
was full); go test ./... .

Reported-by: refeccd (Discord)
2026-11-08 03:41:23 +08:00
yetone d32a7a70cb remote magpie: once magpie updates, the Remote magpies it uses update too
nnlrl_75403 on Discord: a magpie used as another's Remote magpie stayed on
its old version after the local one updated, and had to be updated by
hand on the other computer. Now nothing needs setting up:

- provider.KeepRemotesUpdated (started by the app's updater and by
  magpie serve) runs UpdateRemotes 30 s after start and hourly. A
  released build with automatic updates on reads each Remote magpie's
  version (GET /v1) and, when it is older, asks it through
  POST /v1/magpie/update?version=<v> with the provider's key, at most
  once in six hours per version. Off here, or a dev build: nothing asked.
- The remote updates as its own automatic update would: the app
  downloads and restarts once idle (updater.updateAsked → download,
  waitIdle); magpie serve puts the latest in where it runs from, one at
  a time, never elevated, and serveFollow restarts into it. Automatic
  updates or downloads off there: it answers "off" and stays.
- A copy that can't replace itself says why: a container (docker pull
  ghcr.io/yetone/magpie:latest), a package manager's (its command), a
  folder it can't write, a build from source. A magpie from before the
  route answers 404 ("too old"), a read-only or held key is "refused".
  The provider's row on the Providers page adds a short status to its
  line ("updating to v…" for 30 min, or "can't update itself" etc.),
  with the reason and the command in its tooltip. en/zh/zh-TW/ja/de.
- The route replaces the program, so it takes the Codex reset's
  admission: another machine only while shared, never a browser page,
  an enabled key with full access from loopback too (401 without one),
  read-only 403 gateway_key_read_only, held 403 gateway_key_held. It is
  in readOnlyRefused and the CORS route list.

App.js stays under TestCoreScriptBudget by cutting two comments; the
budget is not raised.

Run (on mote, at the tree committed here):
- gofmt -l internal/: clean. go vet of gateway, gui, cli, provider for
  darwin, GOOS=linux and GOOS=windows: ok.
- go test -count=1 ./internal/gui ./internal/cli ./internal/provider
  ./internal/gateway: gui and cli ok but for #5644's two settings tests
  (red on main since 6b7ee4a98, owned); provider and gateway were
  still running at the push, and go in the full run after it.
- Rebased on origin/main c7c05dcf2, again: gofmt, vet, the new tests,
  ReadOnlyKeyEveryRoute, CORS, TestCoreScriptBudget (not raised) and
  both GUI files 32 of 32: ok.
- New: TestRemoteUpdateNeedsAFullKey (no key from loopback, Origin null,
  an app scheme, *.localhost, a rebound Host, a foreign page with and
  without the full key, another machine with none or a wrong key,
  read-only and held keys, then not shared; the updater is never
  called until a full key asks, from LAN and loopback),
  TestRemoteMagpieAskedToFollow (UpdateRemotes against a real gateway:
  dev build, same and newer remote, NoAutoUpdate here, asked once per
  version, container answer kept, read-only key refused, a 404 magpie
  "old"), TestUpdateAskedByAnotherMagpie, TestRemoteUpdateNote,
  TestServeUpdateAsked.
- GUI: remote-update.test.cjs (new) and remote-self.test.cjs, Chromium
  and WebKit, 1100 and 420 wide, en/zh/ja/de: 32 of 32 ok, with every
  key checked in zh, zh-TW, ja and de. i18n-en-no-cjk ok. i18n-keys'
  "a plugin's words are its own" is red, the same on origin/main
  f8525323d (#5327/#5332, #5426, #5482); its other cases ok.

Broken by hand, each red, then put back: the handler's key check
(loopback without a key got 200 updating), its held-key check, the
route itself (404 = the old code), asking a remote that is current,
ignoring NoAutoUpdate here, asking again for the same version, the
app ignoring automatic updates off, the app never waiting to restart,
serve's single flight (2 downloads), serve's container answer.
The handler's own Origin and not-shared checks stay green when removed:
corsGuard and lanGuard refuse those first; they are kept as the Codex
reset keeps them.

Not tried: a real update of a real remote (a Docker magpie and an app
on another Mac) end to end; Windows and Linux runs of the new tests
(vet only); the full suite (run after the push).

Reported-by: nnlrl_75403
2026-11-08 03:13:15 +08:00
yetone ee8f4de36c routing: the story's ResizeObserver waits a frame, so a wrapping Smart header isn't a loop in WebKit (#5639)
3b541a7f3's longer Smart explanation wraps to more lines at 420px. The story's
ResizeObserver called holdStory, which sets the story's min-height, inside its
own callback, and WebKit reported "ResizeObserver loop completed with
undelivered notifications" as a pageerror. routing-order-unknown went red in
webkit en and ja at 420px. The callback now does its work on the next
animation frame, the same fix #3164 made for the other observers in this file.

Run on mote:
- routing-order-unknown, both engines: 10/10 green, de included. Before this
  change, webkit en and ja at 420px were red.
- GUI rerun of routing-*, panel-routing* and gui-ja/de/zh-TW in both engines:
  2927 pass, 20 fail. Every red is filed and fails the same at 3b541a7f3~1, or
  passes alone at both heads:
  - routing-context-fold webkit (#5586, a different observer);
  - routing-intent-entry (#5392);
  - row-swap (#3799);
  - story-shrinks (#3954/#4629);
  - routing-credits zh-TW, under load (#5161, commented);
  - routing-pulse-composited webkit light, under load (#5647, new).
- internal/gui Go package: ok.

Not changed: routing-context-fold's own observer (#5586).

Refs #5639
2026-11-08 03:12:27 +08:00
yetone 4c1b84aca5 gateway: a proxy's 502 page to a request of 4 MB or more is a byte cap, said as a 413
chenxiang0010 (Discord, v0.1.3265): a Claude Code session on an
OpenAI-compatible relay ("ultrafast", deepseek-v4.1-flash-1017-ultrafast[1m],
effort max) grew to an 8.2 MB request. The relay's nginx answered it with
its own "502 Bad Gateway" page (150 B down). magpie passed that on as a
502, Claude Code asked the same body again (attempt 4/9 …), and every
`claude --resume` of the session met the same page. The two windows'
sessions were not mixed: the logs show different session ids, and the
other window's turns were 313 KB and served.

Why 8.2 MB: no duplication was found in the Anthropic → Chat translation
(buildChat puts a tool result's images once, replays reasoning_content
once); the transcript itself is that large. fastjson's escaping of < > &
adds a few percent on code-heavy text, not a multiple.

Now refitOverCap also reads as a byte-cap refusal (pageOverSize) a 413,
500, 502, 503, 504 or 520-524 whose body is a web page or empty, to a
request of 4 MiB or more. As with a vendor's own byte-cap words:
- older images are left out and it is asked again when that brings it
  under; otherwise
- it is said as a 413 request_too_large: "<provider> answered a web page
  … ; a proxy in front of it answers so for a request larger than it
  takes (HTTP 502: the request is 8.2 MB …)", with the existing hint to
  /compact. A 413 goes to the route's next member, rests nobody, and
  Claude Code doesn't ask it again unchanged.
A page is only a guess at a cap, so it isn't learned for the provider's
later requests. A small request's page stays the 502 it was. The body
is fitted for the size check only after the status and page are known,
so other errors cost nothing more.

Run (mote; package run at base 60cb1bd9e, rebased onto c7c05dcf2, which changes no internal/gateway file; the -run set again at the rebased head: ok):
- go test ./internal/gateway -run 'BigBodyProxyPage|PageOverSize|ByteCap|
  PayloadTooLarge|OverByteCap|CompactTooLarge': ok
- go test ./internal/gateway -count=1 -timeout 45m: ok (1012s)
- go vet ./internal/gateway, GOOS=linux and GOOS=windows: ok; gofmt -l: none
Broken by hand: pageOverSize always false. TestBigBodyProxyPageIsByteCap
(all 4: nginx/empty page, streamed or not) goes red with the reporter's
own error, "1017dp: 502 Bad Gateway: a web page, not an API reply:
“502 Bad Gateway”", and TestPageOverSize's true rows go red.
TestBigBodyProxyPageTriesAnotherMember passes on the old code too (a 502
already fell over); it guards that the 413 keeps doing so.
Not tried: the reporter's relay itself, or a real 8 MB Claude Code
session; the full suite runs after the push.

Reported-by: chenxiang0010 on Discord
2026-11-08 03:10:47 +08:00
yetone c7c05dcf2b settings: the routing groups' defaults are kept through a Settings save and known to be saved by the Routing page's own route
6b7ee4a98 added groupSink, groupFirstToken and groupPatience to settings
and to settingsapi.Keys. Two guards went red on main (#5644):

- TestSettingsSaveKeepsWhatItDoesNotSend wants every setting the Settings
  page doesn't send set in the test and kept by POST /api/settings. Merge
  already keeps the three (6b7ee4a98 added that); the test never set
  them, so it couldn't check it. It sets them now (true, 30, 120), as it
  does BusyLoad.
- TestSettingsCLISetsWhatTheWindowSaves wants every key `magpie settings`
  sets to be one a page sends POST /api/settings. The Routing groups
  page saves these three through POST /api/groups/defaults
  (settings.SetGroupDefaults), and the page itself names `magpie
  settings set` as the other way to set them. The CLI path is real, so
  the keys stay in settingsapi.Keys. The test now has ownRoute: a key a
  page saves through a route of its own, with the call and the body key
  it sends it as, and it fails when no page's call sends that key any
  more, or when ownRoute names a key the CLI can't set.

Siblings: 6b7ee4a98 added no other settings key. provider.Group's new
NoSink and FirstTokenWait have no CLI side to miss: `magpie group set`
has no sink, first-token or patience option before or after it.

Run on mote at origin/main f8525323d:
- Before the change, the two tests: red with the 3+3 lines of #5644.
  After: ok.
- Broken by hand: Merge not keeping groupPatience made
  TestSettingsSaveKeepsWhatItDoesNotSend red ("GroupPatience: 0 ... was
  120"); client.js's groups/defaults call without patience made
  TestSettingsCLISetsWhatTheWindowSaves red. Restored.
- Real CLI, a built magpie in a sandbox HOME: `settings set` groupPatience
  120, groupSink true, groupFirstToken 45 were saved to settings.json and
  listed; groupPatience 999 was refused with nothing changed.
- go test -tags nogui ./internal/cli ./internal/gui: ok.
- gofmt -l: clean. GOOS=linux go vet -tags nogui ./... and GOOS=windows
  go vet ./...: clean.

Not run: the full suite and the GUI (Playwright) suite; no page script
changed.

Fixes #5644
2026-11-08 03:02:54 +08:00