Commit Graph
8780 Commits
Author SHA1 Message Date
yetone e4e9eb0928 usage: a ZCode call to a provider added by hand at magpie's address is not a local session's (jiangshangmuyun on X)
The Usage page listed one ZCode call as "new-provider · 本地会话" among the
gateway's own rows for the same Trae CN DeepSeek calls. The reporter has one
ZCode window and routes everything through magpie.

Cause: the user added magpie to ZCode by hand as a provider of their own
("new-provider", base URL magpie's gateway), not through magpie's connect,
which writes the id "magpie". ZCode records that id beside each reply, and
readZCodeCalls left out only "magpie"/"dial" (ocGatewayProvider). Its calls
were read from ZCode's database as well as logged by the gateway, and only
hidden again where pairing by session, tokens and end time matched; a call
whose counts didn't agree was listed twice as a "local session".

Fix: zcodeGateway also takes any provider whose base URL, in ZCode's
config.json or provider_config.json, is this machine (loopback, localhost,
0.0.0.0, one of its own addresses) on the gateway's port (MAGPIE_ADDR or the
saved port). Such calls are left out before pairing, as "magpie" ones are.
zcode's call parse version is 4, so cached shards are read again. Like
workbuddyGateway it reads the configuration as it is now. The label itself
is unchanged: a call that did go straight to a vendor is still a local
session's.

Siblings filed, not changed: OpenCode/MiMo (ocGatewayProvider), Pi
(piGateway) and dsh still match the gateway by provider name only (#7193).

Go run on mote at this change on base 9bf5848c1, rebased onto e2e8ea253
(no internal/sessions, usage or GUI file changed between): go test -count=1 ./internal/sessions
./internal/usage ./internal/usageapi (ok); GOOS=darwin/linux/windows go vet of
those packages (clean); gofmt -l clean. Broken by hand: with ocGatewayProvider
back in readZCodeCalls, TestZCodeHandAddedGatewayProvider is red ("a call to a
provider at the gateway's address was read as a local session's").
GUI (no GUI file changed, so as a check of the Usage page that shows these
rows): every usage-*, session-identity and i18n-* file, chromium and webkit,
each language they cover, on mote under load ~40: 1670 of 1777 pass. The 107
reds are in 12 usage files (usage-agents-hide, usage-chart-line,
usage-speed-all-models, usage-upload, usage-ledger and 7 more) and fail the
same at origin/main e2e8ea253 without this change (107 of 308 in those files,
same tests). Filed: #2276, #5834, #6003, #6743, #6790, #6975.
Not tried: the reporter's real ZCode database and config (this computer has
no ZCode); why that one call's tokens didn't pair (no data); the full Go suite.
2026-11-19 17:39:35 +08:00
yetone 992f88d634 usage: a stand-in reading says why the read behind it failed
@tmr11235 on X (tweet 2123334817991520577, magpie v0.1.4520): agy-cli's
card showed "截至 2026/11/15 14:19:19,暂时无法获取最新额度" days later,
with nothing to say why. keepLast stands the last good reading in for a
read that fails with a passing error (timeout, 429, 5xx, network) and
dropped that error, so a stand-in that lasted four days read the same as
one a minute old. The reading now carries the error as readError
(SubscriptionQuota, and Quota for `magpie quota --json` and the gateway
report), and asOfText puts it after the date: "… 暂时无法获取最新额度 ·
agy usage query timed out." A deferred read (not asked) has none, and
the short "As of" line on cards stays short. Every provider's stand-in
gets it, not only agy-cli's.

Run (mote, at origin/main 9bf5848c1 + this commit; again after rebasing
onto c01988e43: vet, the provider/gui quota and budget tests, usage-card-refresh
and i18n-keys, 50 pass):
- gofmt -l clean. go test -count=1 -timeout 45m on internal/provider,
  gui, cli, tui, usage, agent: ok. internal/gateway: one red,
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, filed as #7117 on
  origin/main before this (an OpenCode env-block test, not quotas); the
  doneHold fake's "close of closed channel" log is #6690/#6505.
- GUI: usage-card-refresh, account-every-reset, balance-parts,
  claude-usage-asked, panel-quota-refresh, i18n-keys: 94 pass, 0 fail
  (chromium + webkit, every language).
- GOOS=linux/windows go vet ./internal/provider/ (after rebase).
- Broken by hand: without the keepLast line, TestQuotaDeferredReadIsNotFailure
  fails (readError = "", want "connection refused"); without the
  asOfText change, usage-card-refresh fails ("a failed read hid why").

Not tried: the reporter's own failing read (which error it is); a real
GUI with a stand-in card (the fixture page only).
2026-11-19 17:38:05 +08:00
yetone c01988e439 routing: a group's Small context first sends a request to the smallest window that holds it
yg6888 on X (tweet 2123308968848379920): in a group routed Smart, Cursor
Plus's Composer and Grok 4.7 were never used. Not a bug: Smart orders by
allowance tier, then soonest renewal, then listed order, and never weighs
the context window, so the 1M members listed ahead always answered. The
small ones were only ever reached as a fallback.

Smart itself is unchanged; changing its order would move every Smart
user's traffic. A group gets a new routing instead, `fit` (Small context
first; 小上下文优先, 小上下文優先, 小さいコンテキスト優先, Kleiner
Kontext zuerst):

- routes.SmallFirst takes Smart's order and sorts it stably by band (a
  provider set to be used first, the rest with room, the all but used up)
  and then by window, the smaller known first, an unknown one last.
- Its strategy sets ByWindow, so weighRouted fills Seat.Window from
  windowIn (the provider's own Contexts, else the catalog's).
- roomy already leaves out every member the request is estimated past, so
  the first left is the smallest that holds it: a small model is never
  asked for a request too long for it, and keeps its last-resort place as
  under every routing.
- The trace's rows carry `context`; the Routing page says "its 200K
  context window is the smallest that holds this request".
- A group's only: provider.normalize already drops it from a provider and
  the CLI refuses it there. GUI menu, hint, why-lines, TUI and CLI
  (`routing=fit`, small-first) carry it; docs/reference.md, the
  gateway-routing and plugin-runtime pages and the en/zh/ja start pages
  say it, with the search index rebuilt (via docs-index.mjs; #7065).

Run first at the tree rebased on origin/main 6e5882109, then at this
head's (on 856423806; search index rebuilt; gateway/routes vet, routes, rotation, ./internal/gui,
the gateway's new tests and routing-small-first, routing-group-strategy
and i18n-keys 42/42 again), mote over its
cores with another session's full suite on it and mica's disk full, so on
the Linux box (wsl-run) and the Windows box:
- go test -tags nogui ./internal/routes ./internal/cli ./internal/tui
  ./plugins/rotation ./internal/gateway -count=1 -timeout 45m: all ok but
  gateway, whose one red was this commit's own new test asserting a single
  group while an auto group for the shared model exists; fixed (FindGroup
  "group/g") and the window/strategy tests rerun ok, both new ones pass.
  ./internal/provider ok (its only FAIL was the stale search index, since
  rebuilt). ./internal/gui -run Budget ok.
- Broken by hand: SmallFirst returning Smart's order makes
  TestSmallFirstOrdersByWindow and the gateway test red ("a short request
  went to big first"); dropping fit from SaveGroup's whitelist makes the
  gateway test red ("the group didn't keep Small context first").
- GUI (Chromium + WebKit, en zh zh-TW ja de): routing-small-first,
  routing-group-strategy, i18n-keys, routing-cheapest-first,
  routing-free-expiring 112/112 before and after the rebase;
  every routing*, group* and builtins* file (253): 4139 of 4198, the 59
  reds in 11 files that fail the same at origin/main 239da9991 run alone
  (57; routing-many-keys moves between languages each run), all filed:
  #7016, #7097, #6520, #5049, #6512, #4711, #3954, #3799, #4082.
- Windows: CGO_ENABLED=0 go vet -tags nogui ./internal/... ./plugins/...
  ok. gofmt -l clean.

Not tried: the full `go test ./...` and darwin vet (mote busy, mica out
of disk); a real Cursor/Grok account in a group (the window comes from
the same windowIn roomy already trusts). Seen on the way: a recovered
"close of closed channel" in continuation_test.go's doneHold fake, no
test failed from it.
2026-11-19 17:34:30 +08:00
yetone 8564238065 remote magpie: a model is asked on the API the remote asks it on best (OoopsHh on X)
With another magpie as the provider, Pi's models.json had only codex/*
on openai-responses; an OpenAI key's openai/* and a routing group's
auto/* went on openai-completions, and effort max was turned away there
while Responses takes it.

Cause: the remote's /v1/models gives native_endpoints, every API the
model goes on as it is, in its provider's speaking order (Chat first),
and nothing for a routing group. Here Provider.Native took the first one
the remote magpie provider speaks: Chat, for every model but a ChatGPT
sign-in's (listed on /v1/responses alone). The remote's own choice
(Native: ResponsesFirst or the Base URL's API; a group's GroupAPI) was
lost on the wire.

Now the remote's list (X-Magpie-Drawers) says magpie_prefers, the path
it asks the model on best (provider.PreferredEndpoint). The local magpie
keeps it as catalog.Model.Prefers and Native takes it first for a remote
magpie (RemotePrefers), so every agent wired one API per model (Pi, omp,
droid, dsh, grok, hermes, liveagent through catalog.Model.APIs) asks it
there, and the gateway's usable translates another API's request to it
once instead of to Chat. A user's own API set on the model still wins;
a remote from before says nothing and stays as it was.

Not changed: a Chat request a client sends itself for such a model is
still relayed as Chat to the remote, which decides as it does for its
own clients.

Run (mote, at this tree):
- TestRemoteMagpiePrefersResponses (gateway: two magpies on one
  gateway, a fake vendor that turns away reasoning_effort max on Chat)
  and TestPiAsksARemoteMagpiesModelWhereItPrefers (agent): green; both
  red with the RemotePrefers check in Native and usable turned off
  (openai/* and group/auto on chat, Pi's api nil, a Messages request
  relayed as Chat).
- Two real magpie serve processes in sandbox HOMEs, a fake vendor, an
  OpenAI key there with its Base URL given as Responses, a group auto
  and the first magpie as the second's Remote magpie: Pi's models.json
  has office/openai/gpt-6.2-astra and office/group/auto on
  openai-responses with max, and /v1/responses effort max reaches the
  vendor's /v1/responses for both. The same script at the base commit
  wrote both with no api (the provider's openai-completions).
- At base 9bf5848c1: go test ./internal/catalog ./internal/provider
  ./internal/agent ./internal/cli: ok. ./internal/gateway: two reds,
  neither this change's. TestKeptBodyIsOnlyItsCallers is fixed on main
  by e2e8ea253 and passes at this head. TestOpenCodeGoOwnFreeModel-
  GetsNothingOfOpenCodes is red the same on origin/main 975799a06, 3 of
  3 (#7117). gofmt -l: nothing. go vet, GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: ok.
- At this head, rebased on 975799a06: the tests above, plus the TestPi,
  TestRemoteMagpie, Native, Prefers, Unique and TestKeptBody runs of
  gateway, agent, catalog and provider: ok.

Not tried: the whole gateway package at this head, the full ./... suite (mote stayed at load 30+ with other
sessions' runs, mica's disk is full), a real OpenAI key, and the
vendor's own Chat refusal of max, which a fake stands in for. Pi
itself was not run; its models.json was read.
2026-11-19 17:28:26 +08:00
yetone e2e8ea253b gateway tests: a flipped byte in the kept-body test is one that changes the body
TestKeptBodyIsOnlyItsCallers flipped the byte at the middle of a dcz body
and expected a 400. Which byte that is depends on the package's .go files
newAgentChat reads as the conversation, and with plugin_credits_last_test.go
added the middle byte fell on bits zstd doesn't read: the body decoded to the
same request, matched its digest and was rightly passed on (200, reached 2,
3 of 3 on mote; 0 of 3 on origin/main 9bf5848c1 without the new file). The
case now takes the first byte from the middle on whose flip changes what it
decodes to.

Run: go test -count=3 -run TestKeptBodyIsOnlyItsCallers ./internal/gateway
on mote, ok.

At the stack's head (tree 5e30adbc6) on mote: GOOS=linux go vet -tags
nogui ./... and GOOS=windows go vet ./... ok; go test -timeout 45m
./internal/gateway ./internal/provider ./internal/plugin ./internal/routes:
provider, plugin, routes ok; gateway red only on
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, red on origin/main
9bf5848c1 too (#7117).
2026-11-19 17:26:38 +08:00
yetone 504db2206e kiro: the docs say what the Routing page shows, and the min names the ACTIVE, outlasting trial
The ported change said the Routing page shows "on credits · after the
others"; nothing in the GUI renders Weighed.CreditsLast, so the docs now
say the mark is read by affinity only. The plugin (0.1.41, review
follow-up on plugins#1352) says credits only while an ACTIVE bonus has
credits left that outlast the month's reset; the docs and the mover's
note say so.
2026-11-19 17:25:39 +08:00
StringKE 5a83f0ae6c gateway: a plugin's account on its trial credits is asked after the accounts with plan credits left
A plugin window may say credits: used up, the account goes on past it on credits its vendor spends after the window's. Kiro spends a month's plan credits before a trial's, and the plan's are lost at the month's reset while a trial's last a year, so such an account goes after the provider's accounts with room and before those used up, under every routing but Pick account by hand.

Ported from StringKe's branch (StringKe/magpie kiro-trial-last, 23e084262;
yetone/magpie#7179, with plugins#1352, kiro 0.1.41). Kiro's billing docs
say "Kiro uses your plan credits first, then your trial credits" and that
trial credits last 12 months. Opt-in per plugin window (credits), so a key
or a Codex account routes as before: creditsLast and CodexCreditsFirst
stay Codex-only, behindOthers moves only plugin: accounts, and no other
plugin package sends credits. The Kiro mover's min goes to 0.1.41, on npm
(gitHead 0ae116db1).

Run at this stack's head on mote: go test -timeout 45m ./... with go vet
./...: every package ok but internal/gateway, red on
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (red 3 of 3 alone on
origin/main 9bf5848c1 too, #7117) and TestKeptBodyIsOnlyItsCallers (fixed
two commits on, a test reading the package's own sources). Broken by
hand: with behindOthers taken out of weigh, TestPluginCreditsAfterTheOthers
goes red.
2026-11-19 17:25:39 +08:00
yetone 975799a069 gui: Settings' search finds what the words are about (canlee886 on X)
canlee886 (X, 2123329450502938656) searched Settings for "可访问性",
"监控" and "自动选择模型" and each said no setting matched: "缺少搜索时
的智能联想". The search only found settings whose text had every word.

What it does now, all in finder.js, in the page, nothing sent anywhere:
- A table of ~30 concepts, each with the words a reader may type in
  en, zh, zh-TW, ja and de (accessibility, monitoring, picking a model
  by itself, theme, proxy, notifications, startup, privacy, LAN, cost,
  quota, hotkey, ...), leading to the English names of the settings it
  covers (a setting's English is its data-en in every language). Those
  settings are listed with the ones that have the words themselves,
  for rows, built-ins and other pages' places alike.
- When nothing has the words: a long run of Chinese or Japanese is read
  by its two-character words ("文字大小调整" finds Text size), and a
  Latin word over 3 letters may be one edit off ("currancy").
- When no setting has the words themselves but some are related, the
  line over the parts says "Settings related to “…”" (start-aligned,
  in every language) instead of "No setting matches".
- The finders count first (setFeatsFind/elseFind take a dry flag), so
  a search renders once and the view's MutationObserver doesn't loop.

Not done, on purpose: pinyin (a large table, and readers type Chinese
through an IME), a recent-searches list and "did you mean" chips (a
layout that jumps on focus; the owner has said no to UI churn).

Run (WSL magpie-desktop: mote's load was 26 to 34 on 18 cores, mica's
disk is full):
- settings-search-related.test.cjs (new), Chromium and WebKit, en, zh,
  zh-TW, ja, de at 560x420, plus magpie web at 390x760: 16 of 16.
  Against origin/main 9bf5848c1's assets (SEARCH_ASSETS): 0 of 16, "無
  障礙"/"accessibility"/"barrierefreiheit" show no Text size.
- 37 nearby GUI files (settings-*, search-*, find-*, i18n*, menu-scroll,
  click-scroll, builtins): 636 pass, 34 fail. The six files with reds,
  run again at origin/main 9bf5848c1 and at the change: builtins,
  click-scroll, menu-scroll and settings-update-source are red the same
  at both (#4120, #4471, #1550); search-key-list/search-keys time out
  on one subtest a run, a different one each time, at the change only,
  and touch no Settings search: filed as #7194.
- At the rebased head (239da9991): settings-search-related,
  settings-search, settings-search-reach, find-anywhere and i18n-keys,
  64 of 64; go test ./internal/gui (TestCoreScriptBudget and the rest)
  on Windows (xiaomi-gpu), since WSL has no gtk4: TestCoreScriptBudget and
  the i18n checks pass; 10 Windows reds, none in assets, all filed
  (#6068: TestLodyImportHandoff's %AppData%, TestUpdateThatWontStart,
  TestGatewayHeldByAContainer, ...; #7112 TestSetPortServes...).
- Broken by hand: the base-assets run above.

Not tried: the whole GUI suite (WSL and mote were busy with other
sessions' suites; mica has no disk), the real app (only Playwright's
engines, not WebKitGTK or WKWebView; no motion was added).
2026-11-19 17:21:45 +08:00
yetone 239da9991d provider: Factory's mover takes opencode-factory-auth 0.1.50
dsh (DeepSeek Harness) on Factory got "This request was blocked by
Factory's usage policy check" (content_policy_rejected) on its first turn
(a1pha1nthefog on X). It wasn't its prompt or skills. Since 2026-11-18
Factory refuses a request that declares a tool under certain exact names,
and dsh declares bash, read, write, edit, glob and grep. 0.1.50 declares
such tools under droid's own names (Execute, Read, Create, Edit, Glob, Grep,
Task), or suffixed, and gives the agent its own names back in every reply
(magpie-community/plugins bb849910, porting heggria's #1314).
keepMovedCurrent updates every moved user to it.

npm view --registry=https://registry.npmjs.org --prefer-online
@magpie-community/opencode-factory-auth version gives 0.1.50
(published 2026-11-19T09:02:51Z); its tarball has tool-names.mjs.

Run (mote, at origin/main 9bf5848c1 plus this change): gofmt -l
internal/provider is clean; go vet ./internal/provider; go test -timeout
45m ./internal/provider is ok (164s). The plugin's own run is in its commit:
the plugins suite is 9112 pass and 0 fail, and real dsh 0.2.1 ran a bash call
through the plugin against a fake Factory that refuses the names.

Not tried: a real Factory account. None is here, so Factory's answer to the
renamed request was not seen; dannykkg reported #1314's renames accepted
with a real account (#6994).
2026-11-19 17:03:24 +08:00
yetone 9bf5848c1f gateway: a Kubernetes rolling update runs two pods on one volume safely
@justforlxz on X asked for a RollingUpdate (maxSurge 1, maxUnavailable
0) with no request dropped. The docs said strategy: Recreate, because
the work only the serving magpie may do (renewing sign-ins, check-ins,
moves, plugin updates, WhileServing) was kept to one magpie only by the
gateway's port: a second couldn't bind it. Two pods each bind their own
network namespace, so in an overlap both did it, and two renewals of
one refresh token can spend it (a single-use token rotates).

Design: both pods answer requests at once (each refresh and file write
is already locked across processes: filelock, host.js lockRenew); the
serving work is held to whichever gateway holds gateway.serving.lock
(flock on the config folder, serving.go). The new pod retries every
second and takes the work over as the old pod's gateway ends (its drain
lets go first). A file system without locks is read as no other magpie,
as before.

Pods share the volume but not a pid namespace (both run magpie as pid
1), so the locks that judged a holder by its pid now judge it by host:
- host.js lockRenew records host (hostname + pid namespace); a lock of
  another host is stale by age only, never by "pid 1 is alive here".
- lockMoves (migrate.go) the same.
- gateway.json records Host; forgetListening removes only its own, so
  the old pod's end no longer removes the new pod's file (same pid,
  same Started second was enough before).
- temp and run-mark names get a random part (writeDurable, Claude run
  marks, gateway.json's temp file).

While draining (SIGTERM), every reply says Connection: close, on the
gateway and on magpie web's page port, so an agent that kept its
connection to the old pod alive dials the Service again for its next
request. Without it, the real rollout below had one broken pipe per
kept-alive connection, ~5.8s after each SIGTERM, when the drain's end
closed them.

Docs (en/zh/ja docker, reference.md): RollingUpdate maxSurge 1 /
maxUnavailable 0, the readiness probe, a required podAffinity on
kubernetes.io/hostname (a ReadWriteOnce volume mounts on one node), and
one Recreate update from a version before this one, whose old pod
doesn't take the lock.

Run:
- Real overlap, podman 4.9.3 in WSL magpie-desktop: three pods
  (pa -> pb -> pc) on one volume, each its own container (pid 1, own
  hostname and network), a Service proxy over a readiness-probed
  endpoint list (1s probe, endpoint removed 1s after SIGTERM as
  kube-proxy does), 12 agents streaming 3s SSE turns through it, half
  keeping connections alive, no retries. Before Connection: close: 226
  ok, 10 failed (broken pipe, kept-alive). After: 209 ok, 0 failed;
  second run 207 ok, 0 failed. Each new pod logged "another magpie serves", then
  "let go" as the old pod's gateway ended; gateway.json named the last
  pod.
- Broken by hand, each red then green: TestServingWorkWaitsForTheOther-
  Magpie, TestServingWaitEndsWithItsGateway, TestForgetListeningKeeps-
  AnotherPods, TestMoveLockOfAnotherPod, TestRenewLockOfAnotherPodIs-
  WaitedFor, TestDrainingRepliesCloseTheirConnection,
  TestPagePortClosesWhileDraining.
- Full suite, go test -count=1 -timeout 45m ./..., at 85305a82d (this
  change on 2926b7bef): macOS on mote, 102 packages ok; Linux
  (-tags nogui) in WSL magpie-desktop, 101 ok. Reds:
  - TestAuthLockWaitDoesNotFreezeTheHost, both: this change's
    writeDurable called randomUUID, which the test's sandbox of host.js
    doesn't give. It now names the temp file with Math.random; plugin
    then ok on mote and on Linux.
  - Not this change, filed: TestCappedIsSmall (Linux, #5975),
    TestRequestStateKeptAcrossACatalogFetchedAgain (Linux, #6572),
    TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (macOS, #7117).
  - Not a red, filed: the macOS log has a recovered "http: panic
    serving ...: close of closed channel" in the doneHold test fake
    (continuation_test.go:781); no test failed on it. It is #6505
    (also filed as #6339 and #6690).
- go vet ./..., GOOS=linux -tags nogui and GOOS=windows go vet ./... ok
  on mote; go vet -tags nogui ./... ok on Linux; gofmt -l clean.
- At the pushed head (rebased on 6e5882109), on mote: go vet (macOS,
  GOOS=linux -tags nogui, GOOS=windows) of gateway, gui, plugin and
  provider ok; go test -count=1 of gui, plugin, provider ok, gateway
  ok but #7117's TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes;
  site node --test 135 pass, 0 fail.
- New tests on Windows (win-run): gateway, provider, plugin, gui ok.

Not tried: a real Kubernetes cluster and kube-proxy (the podman harness
stands in for both); a real OAuth plugin's renewal across two pods (the
plugin test uses a fake vendor); an RWX/NFS volume's locks. A stream
that began before SIGTERM and outlasts the drain's 20s still ends with
the old pod. Pods exit 2 on SIGTERM as pid 1 (before this change too).
2026-11-19 16:20:34 +08:00
yetone 6e58821092 provider: WorkBuddy's mover min is 0.2.37, kimi-k3.1-pro's call-only turn
opencode-workbuddy-auth 0.2.37 sends kimi-k3.1-pro (and -highspeed) an
assistant turn with tool_calls and no text with one space as its content.
The model answered such a turn 400 "Invalid request parameters", so dsh,
which records a call-only turn as "content": null, failed on it from the
first tool call on (Gloria335056 on X; the same model on QwenWork,
plugins #1213). keepMovedCurrent brings every moved user's plugin up.

npm view --prefer-online: 0.2.37 is latest.
2026-11-19 15:46:39 +08:00
yetone 72f7c1f41a agents: Nowledge Mem's own AI runs on magpie (xiaomaomiloulou on X)
Nowledge Mem asks for "选择一个 AI" on its first page and in Settings >
AI, and Mem 0.10 has a provider type of magpie's own. Picking a magpie
model for the new agent nowledge-mem now sets it up from magpie:

- Mem keeps its providers in remote_llm.json with each key encrypted, so
  the file is only read. Changes go through its backend (nmem-server,
  127.0.0.1:14242, $NMEM_API_URL when it names this computer), as its
  Settings and `nmem config provider` do: POST /remote-llm/config saves
  provider "magpie" at the gateway's /v1 with agentKey("nowledge-mem")
  and the model, which makes it active and turns the AI on.
- Mem puts temperature, max_tokens and timeout back to its defaults
  when a save leaves them out, so every save sends the provider's own.
- What Mem had is stashed once: the active provider, whether the AI was
  on, and a "magpie" provider the user made, which keeps its key and
  gets its model, base and parameters back. Stepping out activates the
  provider Mem had (unless one was picked in Mem since), removes
  magpie's provider and turns the AI off again if it was off.
- Mem has to run to change it (errMemDown); a sync moves the base only
  when the gateway's port moved. Detected by its config folder or the
  installed app (co.nowledge.mem.desktop). Icon from its icon.icns.

Run (mote):
- go test -count=1 -run 'NowledgeMem|TestEveryAgent|TestListOnly|TestSync|Desktop'
  ./internal/agent ./internal/library ./internal/agentenv ok; -run Icon
  ./internal/gui ok.
- GUI: icon-one-tone, icon-tile, routing-client-icons, i18n-keys in
  Chromium and WebKit, 58 of 59; the red is icon-tile's dim-color, red
  on origin/main since 2649d5d72 (#6759), not this icon.
- Real Nowledge Mem 0.10.121 (free tier) in a sandbox HOME on mote, its
  nmem-server on its own port behind a logging proxy, and a sandbox
  magpie (go build of this tree) with a fake OpenAI vendor:
  `magpie nowledge-mem fakeoa/fake-model` made magpie Mem's active
  provider at the sandbox gateway; Mem's own `nmem config provider test`
  answered "Connection OK — magpie/fakeoa/fake-model", the vendor got
  the request, and `magpie usage` counted it under Nowledge Mem.
  `magpie nowledge-mem default` put openai_compatible/u2 back as active,
  removed magpie's provider, and Mem's test passed on it again.
- That run found NMEM_API_URL dropped as "not an absolute path";
  NotPaths has it now (the AGY sibling is the commit before).

- On 681f2ee7f, then rebased onto 6af38c0ee (internal/gui providers
  only, none of these packages): gofmt -l clean; go vet, GOOS=linux
  and GOOS=windows go vet of ./internal/agent ./internal/agentenv
  ./internal/library ok; the tests above again ok.
- Not run: the full go test ./... suite. mote had another session's full
  suite running and mica's disk is full (323 MB free); it runs on mote
  once that one ends, and a red gets its own issue and fix.

Broken by hand: without the check that magpie's provider is still the
active one, TestNowledgeMemKeepsALaterPick is red; without re-sending
temperature, or sending a key over the user's own magpie provider,
TestNowledgeMemKeepsTheUsersMagpie is red; with NMEM_API_URL out of
NotPaths, TestNowledgeMemOnlyOnThisComputer is red.

Not tried: Mem's window itself (the run used its API and CLI), magpie's
GUI connect row clicked, Windows and Linux (config folder per OS is
from Mem's source, not a real install), a paid Mem plan.
2026-11-19 15:44:48 +08:00
yetone f63549b5ca agentenv: an address variable is not a folder (AGY_LLM_GATEWAY_URL)
Every name in agentenv.Vars that isn't in NotPaths is taken for a
folder, and appdir passes over one that isn't an absolute path. So
AGY_LLM_GATEWAY_URL=http://... had magpie print "ignoring
AGY_LLM_GATEWAY_URL: not an absolute path" at every start. Found while
pointing a sandbox magpie at a sandbox Nowledge Mem through
NMEM_API_URL, which magpie dropped the same way.

TestAddressesAreNotPaths fails when a Vars name ending in _URL or _ADDR
is not in NotPaths.

Run (mote): go test -count=1 ./internal/agentenv ./internal/appdir ok.
Broken by hand: without the NotPaths entry, TestAddressesAreNotPaths is
red on AGY_LLM_GATEWAY_URL.
Not tried: a real Antigravity started with AGY_LLM_GATEWAY_URL set.
2026-11-19 15:44:35 +08:00
yetone 6af38c0eeb providers: a resting key's row says what its vendor answered (@YsiCing on X)
@YsiCing on X ("用 oai api 经常遇到额度不足情况,实际账号额度还是有很多的")
showed one API key's row in the provider editor (sk-s…igYA, any
protocol, all models): "暂停使用 · 400 余额不足 · 13:37 恢复 · 立即重试",
posted at 13:12, so a first-rung creditRest of 30 minutes. Nothing on
the row said what the vendor answered, and the screenshot names no
provider, agent or error text.

Cause of the missing words: 82b45888a gave every Rest the vendor's words
(Rest.Error), and 63dc359fb showed them on a subscription account's row
(accountRests passes Error and By), but the key rows of an API-key
provider are filled in providerJSON from gateway.RestOf with
Why/Status/Until/Key/Probed/Rate only, so restLineOf's .key-rest-said
was never drawn for a key. A key's row now carries Error and By as an
account's does.

Not changed, and why: failure() reads a 400 as out of credit when its
words match creditWords (balance, credit, billing, payment, 余额, 充值 …),
which is right for Anthropic's 400 "credit balance is too low",
DashScope's 400 Arrearage and SuperMagic's 400 积分不足 (#4095). The
screenshot has no vendor words, so which 400 this relay sent, and
whether creditWords read it wrongly, is unknown; changing the
classifier on a guess would break those. It is not a rate limit called
out of credit: a 429 shows as 429, and OpenAI's 429 rate_limit_exceeded
(minuteRate) and insufficient_quota (credit) are already told apart.
With the words now on the row, the reporter's next refusal says what
the vendor answered.

Tests:
- TestKeyRestSaysVendorWords (new, internal/gui): a fake upstream
  answers both keys of an API-key provider 400 with an OpenAI-shaped
  credit error through a real gateway.New() (both keys are asked); the
  key it rests carries the words in /api/providers' KeyList. The last
  key left isn't rested on a 400 (quotaStatus is 429/402 only,
  ff930886a), so the test asks for at least one. Red on origin/main's
  providers.go (Error ""), green after.
- TestKeysImportAndRest: its stubbed key rest carries Error and By, and
  checks they reach the row. Red on the old providers.go.
- key-import.test.cjs: a new case, "a resting key says what its vendor
  answered", draws .key-rest-said with the words on the resting key
  only. A case of its own: the taller row moved "Paste several" into
  #6416's scroll red.

Run on WSL magpie-desktop, at origin/main 7f11dfc77 plus this change and
again after the rebase onto 344253c4e (vet, internal/gui ok in 83.7s,
key-import the same 12/16 and 6/8)
(wsl-run; mote was at load 24-31 with two full suites, and mica's disk
had 157MB free, so its full run failed to build: no space left):
- gofmt -l internal/gui: clean. go vet -tags nogui ./internal/gui and
  GOOS=windows go vet ./internal/gui: ok.
- go test -tags nogui -count=1 ./internal/gui: ok (117.6s).
- go test -tags nogui -count=1 ./internal/gateway ./internal/provider:
  ok (982s, 117s), at the same base before the test-only edits.
- key-import.test.cjs, Chromium and WebKit, en and zh: 12/16 and 6/8
  pass; the new case passes in all four. The reds are "Paste several
  takes many keys at once" in every engine and language, red the same
  with this commit's fixture left out. That is #6416 (now seen in
  WebKit and on Linux too; noted there).
- Red by hand: origin/main's providers.go with these tests,
  TestKeyRestSaysVendorWords and TestKeysImportAndRest fail (Error "",
  By "").
Not run: the full go test ./... (no machine had room) and the whole GUI
suite (the change is in providers.go's JSON; app.js is unchanged). Not
tried with the reporter's relay, whose 400 text the screenshot doesn't
show.
2026-11-19 15:39:48 +08:00
yetone 681f2ee7f0 templates: a cheaper small model beside a near flagship is the cheap one (@qinzhidaoa on X)
The reporter's DeepSeek provider has deepseek-v4.1-flash and
deepseek-v4-pro, and the Routing groups page greyed out "Hard to strong,
easy to cheap" and "Cheap first" with "Needs a model cheap beside
DeepSeek-V4-Pro". Both prices are known (models.dev's DeepSeek, as the
bundled catalog has it: V4 Pro $1.98 out, V4.1 Flash $0.60 through its
canonical id), so it was not a missing price. cheapest() took a model as
cheap only at a quarter of the strongest's price or less, and Flash is
3.3 times less. Sonnet beside Haiku (3x) and Gemini Pro beside Flash
(~3.4x) failed the same way.

Now a model is cheap at a quarter of the price, or when it costs less and
its id says small (flash, mini, haiku...) where the strongest's doesn't.
A model that costs as much, or one cheaper with no small id at under a
quarter, is still not taken. With no price on either side, the size
words already decided, unchanged.

Prices for the new ids do reach the templates: deepseek-v4.1-flash is
priced 0.60 at its maker (maker=true) through models.dev's deepseek-flash
canonical, logged by the new test.

Run (mote):
- TestTemplatesCheapBesideACloseFlagship reproduces with the reporter's
  ids (deepseek-v4.1-flash, deepseek-v4-pro on the DeepSeek preset) and
  models.dev's DeepSeek entries from the bundled catalog, written as the
  test's catalog (testdata/models-dev-deepseek-2026-11-10.json). On the
  old cheapest() it is red: smart and thrifty need "cheap" of "DeepSeek V4
  Pro", members [], and Haiku beside Sonnet, Gemini Flash beside Pro, red
  the same. Green with the change; the other template tests pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: ok.
- go test -tags nogui -timeout 45m ./... at 56b3f0780 (this change on
  593ea437d): 103 packages ok, internal/gateway red on
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes alone, which is red
  alone on a just-fetched origin/main 6a46bad34 too and is filed as #7117.
- After the rebase on 6a46bad34: go test -tags nogui ./internal/provider
  ./internal/gui: both ok. On 344253c4e (this head's parent, a Codex
  change in internal/provider): ./internal/provider ok again.

Not run: the GUI suite. No GUI file changed: the page shows the
template's Need as the API gives it, and no API or layout changed. Not
tried in the reporter's real app with a real DeepSeek key.
2026-11-19 15:35:54 +08:00
yetone 344253c4e2 provider: Codex's Ultra on every GPT Sol, Astra and Terra by family, GPT-6.2 Sol and Astra too
forkhouhou on X: on a relay, gpt-6.2-sol and gpt-6.2-astra stopped at max
in Codex while gpt-6-astra and gpt-6.1-terra had ultra. OffersUltra read a
hand list (ultraModels), so each new model lacked Ultra until someone
added it (#4909 did 6.1 Terra); 6.2 was never added.

openai/codex's models-manager/models.json (6c0cee502, "Add GPT-6.2 Sol
and Astra to model catalogs (#62106)") lists ultra on every Sol, Astra
and Terra from GPT-5.6 to 6.2, and on no Luna, GPT-5.5 or older. So the
rule is now the family: catalog.FamilyOf names gpt-sol, gpt-astra or
gpt-terra with a version. It is asked of every spelling the catalog
matches through a new catalog.IsOneLike (found/lookupIn moved onto a
getter, their map forms unchanged), so a provider prefix, :official,
[A], a dated suffix and gpt-6-1-sol keep working, and -fast, -pro and
Luna stay out.

Ultra still goes upstream as the entry's multi_agent_reasoning_effort
or max (fitEffort), and turns Codex's V2 subagents proactive. It
changes no sandbox or approval.

Run:
- Red on the old code (mote): OffersUltra false for gpt-6.2-sol,
  gpt-6.2-astra, relay/gpt-6.2-astra, gpt-6.2-sol-2026-11-17 and
  gpt-6.3-terra; copilot/gpt-6.2-astra's entry stopped at max with
  v2=false. Green after.
- Sandbox HOME e2e (mote, -tags nogui, fake relay, never live
  configs): old code: relay/gpt-6.2-sol and -astra low..max, no v2, in
  /v1/models, /v1/codex/models, `magpie models` and
  ~/.codex/magpie-models.json. New: low..max,ultra with
  multi_agent_version v2 in all four; gpt-6.1-sol unchanged (ultra),
  gpt-6-luna unchanged (none). config.toml's enabled-reasoning-efforts
  has ultra. A POST with effort ultra reached the relay as
  reasoning_effort max.
- GUI: `magpie web` on that sandbox HOME, read with Playwright
  Chromium: /api/state's Codex effort and subagent effort fields on
  relay/gpt-6.2-sol offer low..max,ultra. No GUI code changed.
- Full suite, `go test -tags nogui -timeout 45m ./...` on mote at
  ad3a8b1d3 (this change on 593ea437d): 103 packages ok, one red,
  internal/gateway's TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes.
  It is red 3 of 3 on origin/main 6a46bad34 without this change, and
  filed as #7117. (A first run on mica tested nothing: its disk was
  full.) Rebased on 6a46bad34 (three commits in usage, gateway's Gemini
  billing line and the GUI's Settings search), then at the pushed head:
  internal/provider, internal/catalog and internal/codexcat ok, and
  internal/gateway -run 'Ultra|Effort' ok.
- go vet darwin, GOOS=linux, GOOS=windows on provider and catalog: ok.
  gofmt -l: clean.

Not tried: a real relay or Copilot account sending GPT-6.2 at ultra;
real Codex picking Ultra on it (Codex 0.165 here predates 6.2).
2026-11-19 15:31:25 +08:00
yetone 6a46bad344 gui: Settings' search finds settings on every page, ⌘K opens it (canlee886 on X)
canlee886 asked for a search that reaches a setting by keyword even
when it lives outside Settings, such as routing group strategy and
members. Settings' search now lists, under its own results, hits from
the other pages, each under that page's name: Routing groups (a group
by name, its strategy, its members), Providers (the editor's fields,
e.g. Proxy, per provider), Agents, Library and Usage. Open goes to that
page and row (a group's editor at the field, a provider's editor with
the field lit) without scrolling anything the user didn't ask for.
⌘K / Ctrl+K, or the header's new magnifier, opens the search from any
page.

- The finder is a lazy module, finder.js (like provlinks.js), loaded on
  the first search. app.js only calls it, so TestCoreScriptBudget's
  budget is unchanged: core 1272271 (310 under), app 1087580 (668
  under), at fe038cfac rebased on 7f11dfc77.
- The routing plugin exposes routingFind and routingOpenGroup for its
  groups.
- The magnifier is the header's first thing to go when room runs short
  (a new "spare" stage before "tight"), so the brand still shows at 860px
  in the Windows window (brand.test.cjs went red without it). ⌘K and
  Settings' own box still reach the search there.
- No native select, no accents. Rows reuse the settings-search look.

Guard: find-anywhere.test.cjs, in Chromium and WebKit, in en, zh, zh-TW,
ja and de at 560x420 (with the magnifier at 1100), and on magpie web
at phone width. It types a group's name, "strategy" and Proxy, checks
the pages listed, opens each, and checks the landing row is in view
with no overflow. Red on the base (an archive of 88b65d758 plus the
test): both engines time out, with no results from other pages.

What was run, and where:
- WSL magpie-desktop (xiaomi-gpu), at fe038cfac (rebased on 7f11dfc77):
  gofmt -l clean; go vet -tags gtk3, GOOS=linux go vet -tags nogui and
  GOOS=windows go vet for ./internal/gui/... ok. go test -tags gtk3
  ./internal/gui: only TestClipboardReadBack red, the same on the base
  (#7073, #7074). GUI files find-anywhere, brand, settings-search,
  settings-search-reach, header-zoom-fit, header-centre, header-presets,
  header-relang, click-scroll, text-size, group-editor-fits,
  group-editor-align, i18n-keys and menu-scroll: 181 pass, 29 fail.
  The reds are webkit click-scroll (#4385), webkit header-centre
  (#3479), menu-scroll in both engines (#1550) and webkit text-size
  (#1866), all red the same on the base run.
- WSL magpie-desktop, before the rebase (on 88b65d758): the whole GUI
  suite, 29497 tests, 28180 pass, 1317 fail. find-anywhere was green in
  both engines. Comparing by name against a base run over the 418 tests
  both covered: 13 ok to red and 13 red to ok, all noise except brand's
  "the logo and name in the header", fixed by the spare stage above. A
  near-file run then had the same reds on mine and the base, plus
  group-editor-selected (#5049, #6876), and the guard red only on the
  base.
- mica: go vet before the rebase was ok. go test and the GUI suite there
  hit ENOSPC (disk full from other runs); the 8 tests it broke passed
  alone. That's why the suites moved to WSL.

Not tried: the real desktop app (only the GUI suite's pages), and
Windows' own webview.
2026-11-19 15:05:57 +08:00
yetone 7f11dfc77f gateway: a Gemini CLI sign-in goes without Claude Code's billing line, so Gemini's cache reads its prefix
Reported on X by @niyezaimenglima: Claude Code on a Gemini model through
magpie showed a cache hit rate of 0.

Cause: Claude Code's first system line, x-anthropic-billing-header, carries
a cch= that changes every turn (#1600). On a Gemini CLI sign-in (Code
Assist, Account.Agent "gemini") magpie kept that line at the head of
systemInstruction, so no two turns shared a prefix and Gemini's implicit
cache never matched. dropsBillingLine now drops it there. forwardTranslated
also built the Code Assist body from req instead of sent, so a dropped line
went out anyway; it builds from sent now, as buildFor does.

Scoped to that one route:
- The built-in Antigravity account's cloak already removes the line, and
  its refusal check (#666) judges the system as written. Unchanged.
- The antigravity, agy-cli and zed plugin cloaks cut the line to its end,
  and Claude Code's identity sentence (joined onto the same line) goes with
  it. Cutting only the fields in magpie, as a first version of this did,
  left "You are Claude Code..." on line 1, and a real Antigravity plugin
  account answered its 429 refusal (400 to Claude Code). Plugins keep the
  line.
- Other vendors: unchanged (dropsBillingLine's non-Code-Assist branch is as
  before).

Measured on a real Antigravity plugin account (sandbox HOME, copied
credentials, antigravity/gemini-3.8-flash-low, three Claude Code-shaped
turns, ~8.3k tokens):
- old code: turn 1 cache_read 0, turns 2 and 3 read 6238/6278 (in ~2084).
- a per-turn changing line near the head of the system (what Gemini CLI's
  kept billing line is): cache_read 0/0/0, in 8297/8331/8381. This is the
  reporter's 0.
- new code on the plugin route, stream and non-stream: 6248/6242/6274, so
  the route is unchanged; usage.jsonl matches the response.
- history in the first user message instead of the system: 6246/6288, so
  conversation content is cached too. The last ~2k tokens are never cached
  (Gemini's chunking).

Tests (both red on the old billing_line.go):
- TestBillingLineLeftOutForCodeAssist: a Gemini CLI login end to end, two
  turns with different cch; neither GenerateContent body has the line and
  systemInstruction is the same in both.
- TestBillingLineCodeAssistOthers: Antigravity built-in and an Antigravity
  plugin keep the line; Gemini CLI drops it.

Run:
- Full suite, go test -timeout 45m ./..., on mote at 72e6f9542 (this change
  on 593ea437d): every package ok except internal/gateway, whose only red is
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, #7117, red on
  origin/main too (3 of 3 alone). mica's disk was full (1.2G), so its run
  tested nothing and was discarded.
- Rebased onto 2926b7bef (one commit, usage-record Wire field, no overlap):
  go test ./internal/gateway -run 'BillingLine|CodeAssist|Antigravity|Gemini'
  ok on mote; GOOS=linux and GOOS=windows go vet ./internal/gateway ok;
  gofmt -l clean.

Not tried: a real Gemini CLI account (Google refuses personal Code Assist
sign-ins here), so the Gemini CLI numbers stand in through the per-turn
line above; an AI Studio API key (that route already drops the line,
whether Google reports cached_tokens there is unverified). Not changed: the
agy-cli plugin runs the local agy CLI with its own session and compaction,
and reports agy's cachedReadTokens; that is agy's or the plugin's.
2026-11-19 14:52:25 +08:00
yetone 2926b7beff usage, routing: the model id a request went out under is kept and shown
daoche_wuzui on X asked how magpie serves Antigravity and whether a
request goes out under a suffixed model: nothing showed the id actually
sent. Antigravity's plugin turns gemini-3.7-flash at high effort into
gemini-3.7-flash-high, and a relay's upstream name (ModelWires) renames
a model too; the ledger and Routing showed only the routed model.

- A plugin's reply may carry X-Magpie-Sent-Model
  (provider.SentModelHeader). forward() reads it from plugin providers
  only (a non-plugin's header is ignored) and deletes it, so it never
  reaches the agent. Without it, provider.SentNameOnIn (the upstream
  name, or Antigravity's variant) is used.
- wireName keeps the id only when it differs from the model. It goes in
  usage.Record.Wire (`wire`, omitempty), the trace's Try.Wire, the
  ledger cache and a last CSV column, sent_model (docs/reference.md).
- Usage › Requests: the Sent cell and the detail show the sent id when
  there is one, with "model → sent id" on hover. Routing: a try sent
  under another id gets one aside line, "Sent to the vendor as {model}"
  (zh, zh-TW, ja, de).
- Antigravity's mover min is 0.2.4: plugins 67fb1258 sets the header on
  every reply (stream, whole and errors); its tgz is on the plugins
  repo's dist branch.

Run at this head (ef997d186 + this), on mote:
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gateway, red only in TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes,
  red 5 of 5 alone at origin/main ef997d186 too (#7117, taken).
- GUI: the 46 files that reach the Usage ledger, Routing's tries and
  i18n (i18n-*, ledger-*, usage-ledger-*, routing-try-fixed, sent-model
  and the files that read the Sent cell or an aside): 230 ok; red only
  aside-native (#6212) and usage-ledger-chart's remembered metric
  (#6790), both red the same way at origin/main ef997d186. The whole
  GUI suite (1609 files) was still running at push; its reds so far are
  in account-arrange and the Codex lone-capped-account files.
- sent-model.test.cjs: 10/10, Chromium and WebKit, en zh zh-TW ja de.
- Plugin: bun test packages/antigravity 136 pass, check.mjs ok.

Rebased onto 593ea437d (three gateway/routing commits) before the push,
then again: gofmt; vet of gateway, usage and provider for darwin, linux
and windows; the new tests with the gateway's Wire, Ultrafast and Prefix
tests; sent-model and i18n-keys (14 pass): ok.

Broken by hand, each red:
- no noteWireModel call: TestPluginSentModelIsKept;
- the IsPlugin check removed: the spoofed-header case;
- no SentNameOnIn fallback: TestUpstreamNameSentIsKept;
- an id equal to the model kept: both tests;
- the old GUI assets: every sent-model case; the old usage page.js
  alone: the Sent cell assertion;
- the plugin's old index.mjs: its new test (31 pass, 1 fail).

Not tried: a real Antigravity account (the plugin's header was tested
with its fake vendor only).
2026-11-19 14:45:14 +08:00
yetone 593ea437d8 gateway: a Codex conversation's prefix is sent the same on every request
@m0eaki on X: LobeHub's Codex 0.169 on magpie, the prompt cache holding
only through the base instructions, the skills_instructions message
differing from turn to turn. Codex 0.169 puts its skills, permissions,
deferred tools and <model_catalog> in one developer message, and magpie
writes that message again when it widens the catalog with the models a
subagent may be put on (spawnAgentModels), so it is the one place magpie
could change it.

TestCodexPrefixSameOnEveryRequest posts Codex 0.169.0's request with
LobeHub's app-server headers through the whole handler: a turn's request
twice, the next turn, after a restart and 20 times over on fresh servers,
with two providers and a routing group in the catalog, and checks every
input item up to the new ones is the same bytes upstream. It passes:
magpie's widening is already stable, and magpie never writes or reorders
<skills_instructions> itself. Nothing in magpie is changed.

What does vary is Codex's own: run in a sandbox CODEX_HOME
(workspace-write), Codex 0.169.0 writes the working folder into the same
message's writable roots, so a host that starts turns in different
folders changes it. Codex's skills block itself was the same bytes across
fresh processes (0.165.0, 0.169.0).

Broken by hand: shuffling spawnChoices' list turns the test red at "the
same request again: input[1] differs".

Run (mica, mica-run):
- go test -count=1 -timeout 45m ./... at 3869aee3b with this commit: 99
  packages ok, 5 red, none in code this commit touches:
  - internal/agent TestWSLAgentFolderIsALink (#7150)
  - internal/dirent watch tests, five of them (#7031)
  - internal/gateway TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes
    (#7117, red on origin/main)
  - internal/gui TestGatewayModeListsNoOwnSessions (#7064)
  - internal/sessions timed out at 45m (2700.7s), and again run alone
    (2701.5s, TestStatsMidnight at the deadline); noted on #5451
- rebased on origin/main ef997d186: go vet
  ./internal/gateway ok; go test -count=1 -timeout 45m ./internal/gateway
  (1172s): only #7117 red, TestCodexPrefixSameOnEveryRequest and the
  TestSpawnAgent* tests pass.
- rebased again on origin/main ddc78405c (this push's parent, two
  gateway commits on): TestCodexPrefixSameOnEveryRequest and
  TestSpawnAgent* ok.
- gofmt -l over every tracked .go file: clean.

Not tried: a real LobeHub conversation through magpie. The reporter's two
captured item-2 texts would show which line changes.
2026-11-19 14:21:43 +08:00
yetone ddc78405cf gateway: a magpie's /v1/models offers Ultrafast where its accounts do
OoopsHh on X: a magpie in Docker could pick Ultrafast on a model, but
another magpie that has it as its Remote magpie provider was offered
Fast alone on that model. The remote's list takes its service tiers from
provider.CodexTiers through codexcat.Entries, and CodexTiers only ever
added "priority". Ultrafast came only from Codex's own catalog, which a
magpie with no Codex beside it (Docker) does not have, and the codexcat
branches for Fast and OwnTier models dropped any tier m.Tiers added.

- CodexTiersWith adds "ultrafast" after Fast where provider.UltraOn says
  the key or account offers it (an OpenAI key's Ultrafast models, a
  provider added by its address on OpenAI's Ultrafast models, a Codex
  account whose live list has it), and on a group where a member does.
  UltraModels is read at most once a list, and only after a model
  already shows Fast.
- codexcat keeps those tiers (withTiers) and names "ultrafast"
  "Ultrafast" when Codex's own catalog doesn't.
- The asking side already sends ultrafast to a Remote magpie
  (RemoteTiers), and the remote already asks a member without it for
  priority (tierMate). Both ends need this version: the remote to list
  it, the local one to read it.

A provider added by its address serving gpt-6.1-sol now lists
Ultrafast in /v1/models, /v1/codex/models and magpie-models.json, as its
editor's CanUltra already said; TestModelsListTiersForEveryClient,
TestRemoteMagpieOffersItsTiers and TestCodexCatalogTiersReachDisk
expect it.

Tests:
- TestRemoteMagpieOffersUltrafast: a relay's gpt-6.2-sol and a group of
  it list "priority ultrafast"; a Remote magpie provider reading that
  list has CanUltra on both, and an ultrafast ask through it reaches the
  vendor as ultrafast. Red on 7d5db0f29 (tiers "priority" alone, no
  CanUltra).
- TestOpenAIKeyUltrafast: an OpenAI key's /v1/models lists ultrafast on
  gpt-6-astra and not on gpt-6-sol, and its trace's order says Ultra
  on the pick (Weighed.Ultra, previous commit).
- tui, codexcat, provider and agent, and gateway's
  'Tier|Ultra|Remote|Fast|Codex' tests: ok on mote.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./... and the three builds: ok on mica. gofmt -l clean.

Full suite (both commits; go test -count=1 -timeout 45m ./... on mica,
load ~30 on 12 cores): 99 packages ok. Reds, each filed and none in
code this touches:
- agent TestWSLAgentFolderIsALink (#7150, ~1 in 6 on main);
- dirent's five watch tests (#7031, a busy Mac);
- gateway TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117, red
  on origin/main);
- gui TestGatewayModeListsNoOwnSessions (#7064);
- sessions timed out at 45m in TestWSLAntigravityLinkedHomeOnce under
  that load (#5451). Run alone with -timeout 90m: ok in 2925s on mica,
  ok in 62s on mote (origin/main 3869aee3b: ok in 54s on mote), so the
  time is mica's, not this change's.

The full suite ran on the base 3869aee3b. After a rebase onto ef997d186
(no files in common), at this head on mote: go build ./..., the three
go vets, tui, codexcat, provider, agent, gui's Budget/Group/Fast/Ultra
tests and gateway's Tier/Ultra/Remote/Fast/Codex tests ok;
group-member-fast, routing-ultra-row, routing-service-tier, gui-de,
gui-ja, gui-zh-tw and i18n-* 50 of 51 (gui-ja's "Gets copies" string,
#7144, on main).
2026-11-19 14:02:17 +08:00
yetoneandggbdpq c1934262ab routing: a group member sent Ultrafast says Ultrafast, not fast
OoopsHh on X: with Ultrafast picked on a routing group's member, the
group list's card still said "· fast". The Routing page's summaries
(the card's member line, the member menus' notes and the route view's
tag) read Group.Fast alone. They now say Ultrafast where the group sends
the member so and an account offers it (memberJSON.Ultra), as the
editor's speed button and `magpie group` already did. The TUI's group
view did the same and now says Ultrafast too. The route trace's Weighed
gains Ultra so the route view's tag can tell the two apart (#7095).

Fixes #6881 and #7095 (paul-tian). ggbdpq took #6881 and posted a
patch on it; its TUI test and the Codex GPT-6-Astra fixture are ported
here with credit.

Siblings checked: `magpie group` (groups_cli.go) and the Agents page
(agentspeed.js) and search tags (fastTag) already said Ultrafast; the
tray has no group speed summary.

Tests:
- group-member-fast.test.cjs: a group "Astra" with an Ultrafast member;
  its card says "gpt-6.2-sol · Ultrafast" / "· 极速" (en, zh; Chromium,
  WebKit). Red on 7d5db0f29 (4 of 4: "Relay gpt-6.2-sol · fast").
  The same card now also holds #6881's Codex gpt-6-astra member
  (ggbdpq's fixture) and checks it reads Ultrafast, not fast.
- routing-ultra-row.test.cjs (new, #7095): the route view tags a member
  sent Ultrafast "Ultrafast" with its own title, and one sent fast
  "fast"; every language, Chromium and WebKit. Red on 7d5db0f29 (10 of
  10: both tagged "fast").
- TestGroupMemberUltrafastShown (tui) and ggbdpq's
  TestGroupMemberUltraShown (a Codex gpt-6-astra member; a member set
  fast alone still says fast): both red on 7d5db0f29.
- routing-service-tier.test.cjs: 20 of 20 green.
- GUI run of the group-*, routing-*, panel-routing, fast-*,
  codex-service-tier, picker-speeds, agent-speed, i18n-*, gui-de/ja/zh-tw
  and header-relang files on mote: 4295 tests, 84 red in 10 files. The
  10 files then run at this head and at origin/main 3869aee3b on mote:
  the same 84 reds on both, each filed: fast-pick/fast-ultra #6201,
  group-editor-selected #5049, gui-ja #7144, routing-pin-away #6512,
  routing-provider-off and routing-rows-fit #7016, routing-row-swap
  #3799, routing-signin #6520, routing-story-shrinks #3954.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-19 13:51:20 +08:00
yetone ef997d186c serve: a SIGTERM finishes the requests in flight, for Kubernetes rolling updates
@justforlxz on X runs magpie in Kubernetes and every update cut the
requests in flight. A SIGTERM ended the gateway like Ctrl+C: the
listener closed at once and Shutdown cut what was left after 2s, an
agent's stream included, with no unready phase for the Service to see.

Now a SIGTERM to `magpie serve`, `magpie web` or `serve --web`:
- GET / answers 503 {"draining":true} at once, so `magpie healthcheck`
  (the image's HEALTHCHECK, and the readiness probe the docs give) fails
  and the pod leaves its Service's endpoints;
- in a pod (KUBERNETES_SERVICE_HOST) it keeps accepting for 5s while
  that reaches kube-proxy and the ingress, then stops accepting;
- the requests in flight, streams included, get up to MAGPIE_DRAIN to
  finish: unset, 20s in a pod (k8s' default grace is 30s, with room to
  save after) and 7s elsewhere (docker stop and Compose kill at 10s,
  and a drain past that would lose the state saved at the end);
  seconds or a Go duration; 0 ends after 2s as before; an unreadable
  value logs and uses the default. magpie web's page port (which
  serves /v1 too) shuts down within the same grace.
Ctrl+C and SIGHUP end as before. Nothing to configure.

A request still answering at the end of any drain was logged as "cut"
but kept running, its upstream call too, until the process exited:
Shutdown doesn't close active connections. The gateway now closes them
after a failed Shutdown, so a gateway restarted in-process (the GUI's
restart, a test) leaves nothing holding the provider catalog
(holdCatalog). TestDrainEndsAtItsGrace's cut request, still in flight
after it returned, made the next test, TestGrokGetsAgentMessageAsUser,
read migrations.json through that hold and fail in a full gateway run
on WSL; the test now waits for it to end, and without the Close that
wait fails at 30s.

PID 1: the image's ENTRYPOINT is exec form, so magpie is PID 1 and gets
the SIGTERM itself (it calls signal.Notify). As PID 1 it exits 2 rather
than 143 after the drain, the same on the old code.

/config shared by two pods (a RollingUpdate overlap) is not verified
safe: files are flock'd and written by rename, but the serving magpie's
sign-in renewal, plugin sign-in renewal and check-ins would run in both.
The docs say one pod per volume with strategy: Recreate (an RWO volume
on another node also stalls a RollingUpdate). Requests sent between the
old pod's end and the new one's start are refused; the drain covers what
was in flight.

Docs: a Kubernetes section (Deployment with an exec readiness probe,
terminationGracePeriodSeconds, Recreate, the RWO note) and a
MAGPIE_DRAIN row on docker.html in en, zh and ja; docs/reference.md's
Docker section; site index regenerated.

Run:
- TestDrainedGatewayFinishesItsStream, TestDrainEndsAtItsGrace,
  TestHandedOverGatewayFinishesItsStream, TestReadOnlyKeyEveryRoute,
  TestDrainGrace, TestDrainOnSignal and the cli Signal tests: ok (mica).
- Broken by hand: without Drain's grace in drainFor,
  TestDrainedGatewayFinishesItsStream fails "the gateway ended with a
  stream in flight".
- Real binary (before the 7s default, which applies outside a pod
  only, and the Close), sandbox HOME, fake SSE upstream streaming 10s, SIGTERM
  at +2s, KUBERNETES_SERVICE_HOST set, magpie as PID 1 in its own pid
  namespace (unshare) on Linux (WSL magpie-desktop), serve and web:
  new: healthcheck fails while draining, a new request 1s after SIGTERM
  200, the stream completes at +10s, exit at +11s. origin/main: the new
  request is refused, the stream is cut at +4s after 4 chunks. Also
  serve on macOS (mica): same, exit status 143.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build: ok (mica), before the 7s default
  and the Close.
- Full suite, go test -count=1 -timeout 45m ./..., on Linux (WSL
  magpie-desktop; mote and mica were each running another session's
  suite) at the first version of this change on 2051dfc23: every
  package ok except root, internal/cli and internal/gui, which can't
  build there (no gtk4/webkitgtk-6.0 dev packages), and
  internal/gateway, red on TestGrokGetsAgentMessageAsUser (the hold
  above, fixed here). The doneHold "close of closed channel" panic in
  the log is #6339/#6505/#6690, not this change.
- After the fixes: internal/gateway and internal/provider whole on WSL
  ok (1075s, 156s); root, internal/cli, internal/gui on mote ok.
- At this head, rebased on 1c9c359f9: internal/cli whole and the drain,
  handover, Codex tool and Grok gateway tests ok (mote); go vet of
  gateway/cli/gui, GOOS=windows the same, GOOS=linux -tags nogui of
  gateway/cli ok (mote).

Not tried: the real Docker image build and a real Kubernetes cluster
(no Docker daemon on mote, mica or WSL; Docker Desktop on xiaomi-gpu is
not running).
2026-11-19 13:04:38 +08:00
yetone 1c9c359f9d gui: Usage cards keep their place as they come in (liuzhengdong99 on X)
liuzhengdong99 on X: 用量界面每张卡片取数的时间不一致,导致卡片渲染时高度一直
跳动——滑到上面看某张卡片,视图会被拽回下面. The allowance cards come in
at different times: each vendor's read (the page asks again every 1.5s
while X-Magpie-Reading says a read is under way), then the curves'
history. Every answer redraws the cards (renderQuotas), and packUsage
grows the ones above the card being read. Nothing kept that card in
place: the view's scroll guard (keepInView) only knew elements by node,
and the cards are new nodes on each draw, so the browser's anchoring was
the only thing holding them. It anchored on nodes that were being
replaced, and the reader ended up dragged down.

Fix:
- The Overview keeps the card being read in place: the highest card (or
  part of the page under the cards) that starts in sight, found again by
  its data-key after a redraw (keepInView's new `only` mode with pinnedAt),
  and followed after every packUsage (followPin). The browser's own
  anchoring stays on while nothing is kept: at the page's top, on
  another tab, and while the cards are dragged or moved by keys (unpin,
  so a dropped card lands where its slot showed).
- Placeholders from the last known height: each card's height drawn in
  full is kept by its key (localStorage magpie.usageCardTall, 1s
  debounce, 200 keys at most). A card still waiting on its read or its
  curve (usageWaiting: quotasReading, the new flag loadQuotas sets, or
  no history answer yet) is packed and held at least that tall, in the
  column count the cards were last whole in at that width. On the next
  start, no card in sight moves.
- loadQuotaHist counts its first answer even when it is empty, so a
  user with no history isn't left waiting (found by usage-pack: the
  cards held their first packing at 560px).

No new animation, nothing scrolls the page on its own (click-scroll
passes), and the layout is unchanged once the cards are in.

Run (mica, Playwright 1.62.0, Chromium + WebKit):
- usage-cards-steady.test.cjs (new): 20 tests, all 5 languages, 1100px
  and 420px. On the old assets (MAGPIE_ASSETS) it was red 8 of 8 in en
  and ja. With the hold disabled, the second visit goes red.
- At ee079814b + this change (then rebased onto 1c29e2c7d, which changes
  only app.css, redact.css and a new contrast test; script budgets
  measured again, unchanged): go test ./internal/gui/ (budgets included),
  gofmt, and usage-pack, usage-cards-steady, usage-drag, usage-arrange,
  click-scroll and i18n-keys: go ok (300s), 64 of 64 GUI tests pass.
- Every usage-*, quota-*, view-*, account-arrange, click-scroll,
  i18n-keys and gui-de/ja/zh-TW file (151 files), run before the empty-history fix and the last
  rebase, head vs origin/main.
  No red at head is new. The reds that are also on base: account-arrange
  (#6010), quota-count-wrap (#3404), quota-curve (#6789),
  quota-refresh-order (#6180), quota-credits (#6807), usage-ledger
  (#5048, #6003), routing-* (#7016), gui-ja (#7144),
  view-trackpad-coast (#4724), view-wheel-unheard (#5158), plus the
  whole-suite reds in #6975 and #6934. usage-pack and usage-drag went
  red at head along the way and are fixed here.

Not tried: the real app (WebKitGTK on Linux, WebView2 on Windows,
WKWebView on macOS) and the full GUI suite.
2026-11-19 13:01:23 +08:00
yetone 1c29e2c7dd gui: dark quiet text at 4.5:1, the masking count in the app's own numbers (CHENGJIAHEGOXIS on X)
CHENGJIAHEGOXIS on X: the masking card's big number was a thin, tall
face ("瘦长的比较别扭"), and some text in dark mode was very dark: Library
› MCP's project help under 项目服务器.

The masking count (.msk-num, redact.css) drops its own SF Pro Display at
weight 100 for the interface's font at 600 and -.035em, as .si-pct b and
.kpi b have; its 52px and line-height stay, so the card's layout doesn't
move.

The help is .lib-aside, drawn in --faint. The dark theme's --faint was
#56565f: 2.39:1 on --bg, 2.16:1 on --card. It and --muted are raised in
both dark blocks and the dark panel's:
  --faint #56565f -> #90909a (panel #7c7c87 -> #90909a)
    on --bg 2.39 -> 5.49, --card 2.16 -> 4.95, --card-2 2.26 -> 5.19,
    menu (--pop-bg) 2.07 -> 4.76, panel bg 2.34 -> 5.38, panel card
    2.08 -> 4.77
  --muted #8b8b94 -> #9c9ca6 (the panel's own value already)
    on --bg 5.14 -> 6.38, --card 4.64 -> 5.76, menu 4.46 -> 5.54,
    --pill 4.05 -> 5.03
fg-2 > muted > faint is kept. With a picture behind the page (84% veil,
appearance.go), --faint holds 4.5:1 up to a mid-grey #808080 picture
(4.52); a picture brighter than that under the words can't keep 4.5:1
for any grey quieter than --fg-2 without a heavier veil, which is left
as it is. .effort-ends loses its .8 opacity over --muted. The light
theme's --faint (1.95:1 on white) needs both light steps moved
together: #7153.

New test dim-text-contrast.test.cjs, Chromium and WebKit: the dark
--faint and --muted at 4.5:1 on every dark ground in the window and the
panel, with the steps kept; Library › MCP's two .lib-aside lines at
4.5:1 on the dark page, with no picture, #262626 and #808080 behind it,
in zh/en/zh-TW/ja/de at 1100 and 420 (web), no sideways scroll; the
masking count's weight and family the same as .si-pct b's and .kpi b's,
its tracking no tighter, fitting its card in dark and light, every
language, 1100 and 420.

Run (mote, through mote-run):
- old code: dim-text-contrast red 6 of 6 (--faint rgb(86,86,95) on
  --bg reads at 2.39:1; weight 100, the app's big numbers 600).
- this commit's tree (on ee079814b): dim-text-contrast,
  quota-caption-contrast, i18n-keys: 12 of 12 ok; go test ./internal/gui
  -run 'Budget|Appearance|Scheme' ok; gofmt -l clean. go test
  ./internal/gui (whole package) ok at the pre-rebase head.
- whole GUI suite (make test-ui, concurrency 4) at the pre-rebase head:
  31 files red besides this one, the same files red alone at
  origin/main ee079814b (526 pass / 210 fail there vs 537 / 205 here),
  recorded on #6975. dim-text-contrast's one red there read the help
  mid-fade-in (2.19:1 through an ancestor's opacity); it now waits for
  every box over the words to be opaque, and is green after.
- screenshots before/after in Chromium and WebKit (Library › MCP dark,
  plain and with a picture; masking dark and light).

Not tried: the real app and WebKitGTK; a picture brighter than #808080;
the light theme (#7153).
2026-11-19 13:00:39 +08:00
yetone ee079814ba provider: Factory's mover takes opencode-factory-auth 0.1.49
0.1.48's per-conversation session didn't stop Factory's 400 "Invalid
model ID in request body" on gemini-4-hydrogen (marovole on X): it still
came on requests of 0.6 to 1.6 MB, every retry alike, while smaller ones
went through. magpie's gateway sends a Gemini body with its keys sorted,
so the plugin sent the model after the contents, a long session's
megabytes. droid 1.14.0 always sends it first. 0.1.49 sends the fields
in droid's order, model first (magpie-community/plugins ec1c675f).
keepMovedCurrent updates every moved user to it.

npm view --registry=https://registry.npmjs.org --prefer-online
@magpie-community/opencode-factory-auth version gives 0.1.49
(published 2026-11-19T04:18:41Z).

Run (the Linux box, magpie-desktop, through wsl-run, since mote and mica
each had a full suite running): gofmt -l internal/provider is clean;
go vet ./internal/provider; go test -timeout 45m ./internal/provider is
ok (179s at origin/main 3869aee3b, 127s again at this head after the
rebase onto 426a707a1, which changed internal/provider). The plugin's own run is in its commit: the plugins suite has
9060 pass and 0 fail, and the new order test is red on 0.1.48.

Not tried: a real Factory account. None is here, and Factory answers a
request without one with 403 before it reads the body, so the cause is
inferred from the failing requests' pattern and droid's body, not
reproduced against Factory itself.
2026-11-19 12:25:40 +08:00
yetone 426a707a19 library: each subagent is kept in a Markdown file to edit, or one of the user's own in a git repo (JonahFu on X)
JonahFu asked on X (tweet 2123236872940073039) for each subagent's
local path in Library > Subagents, to edit it with an LLM, or to keep a
subagent in a git repository.

Each subagent of the library (not a plugin's) is now kept on this
computer in <library>/subagents/<name>.md as well, in Claude Code's
shape (name, description, model, skills, mcpServers, the prompt), or in
a file of the user's own set under the editor's Advanced (folded unless
one is set), in a repository say:

- FileHash is what the file said when magpie last wrote or took it in.
  An edit there (by hand, by an agent, a git pull) is taken in at the
  next sync and before a change made on the page, and every ticked
  agent gets it. While magpie runs, KeepLinked's loop syncs when a
  file's hash differs, once per edit.
- An edit that can't be read as a subagent (no front matter, another
  name, no prompt) is left as it is, the agents keep what it said
  before, and the editor says why. magpie writes a file only when it is
  missing, or still as magpie left it; never the user's edit.
- A file of the user's own that is there already is what the subagent
  says (a bad one refuses the save). It must be an absolute .md path,
  not a folder, not inside the library, not one another subagent uses,
  and not a file magpie writes for an agent.
- Rename and remove take the library's own file only while it is as
  magpie wrote it; the user's own file always stays.
- File and FileHash are this computer's: Collect leaves them out, Put
  keeps this computer's.

The editor shows the path (click reveals it, Copy copies it), a line
that edits there reach the agents, and the error when one wasn't taken
in. i18n in zh, zh-TW, ja and de.

docs/subsystems/library.md: a row for the subagent's own file and its
tests.

Run at the tree before 2051dfc23 (a Pi market change in
pimarket.go and plugin/market.go only) came onto origin/main:
- mote-run: gofmt -l none; GOOS=linux and GOOS=windows go vet -tags
  nogui ./... and go vet ./...: ok. go test -timeout 45m ./...: every
  package ok, internal/library 504s, except known reds not touched here:
  internal/cli TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr,
  TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr and
  TestUpdateFindsAMagpieThatWroteNoRecord (#6471, #6223: a real gateway
  on mote's 127.0.0.1:3425), internal/gateway
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117).
  mote and mica were both over their cores; the suite went to mote.
- mica-run: node --test library-subagents, library-rules,
  library-commands, i18n-keys, i18n-en-no-cjk (Chromium and WebKit,
  420 and 1100 wide, en zh zh-TW ja de): 44 of 44. Before that, every
  library-*, lib-*, nav-* and i18n* file (95 files, 2071 tests): red
  only in library-commands (its tab-order assert, fixed in the previous
  commit) and library-open-again's 1100px cases, red the same alone at
  base 14b6b9555 (#6751).
- Red on the old code: TestSubagentFileFollowed and
  TestSubagentFileUnreadable went red with the follow step skipped and
  the hash check dropped; library-subagents.test.cjs is red against the
  previous commit's client.js.
- Real use: a sandbox HOME magpie on mica (fake claude on PATH) wrote
  ~/.config/magpie/library/subagents/reviewer.md; an edit there with a
  new description and prompt reached ~/.claude/agents/reviewer.md and
  library.json on the next `library sync`; an edit with no front matter
  was left as written and Claude Code's file kept the old text.
- After rebasing on 2051dfc23, mica-run: go vet ./internal/library
  ./internal/plugin and go test -timeout 45m ./internal/library: ok.
Not tried: a real Claude Code or other agent editing the file, a real
git pull into a repository file while magpie runs (KeepLinked's loop is
covered by TestSubagentOwnFile only), Windows and Linux.
2026-11-19 12:20:02 +08:00
yetone 3132fa1cd9 library: Rules, a folder of rules given to Claude Code, Cline and Kiro CLI (JonahFu on X)
JonahFu asked on X (tweet 2123237371739316685) for Claude's rules
folder in the Library. A new Rules tab keeps rules once and gives each
to the agents ticked for it, in the folder each reads by itself:

- Claude Code: <claude dir>/rules/<name>.md. `paths` is the only
  front matter key it reads (code.claude.com/docs/en/memory). Checked
  on real 2.1.327 in a sandbox: it reads every .md under the folder,
  loads one without paths at launch, and one with paths when
  Read/Write/Edit touches a matching file.
- Cline: <cline dir>/rules (CLINE_DIR, else ~/.cline). Cline 3.0.70
  reads every rule always and has no paths key, so a rule with paths
  isn't written for it; the agent gets a problem and the editor says
  why under the paths.
- Kiro CLI: ~/.kiro/steering, `inclusion: fileMatch` +
  `fileMatchPattern` for paths, else always. A rule named "agents" is
  refused there (it would be AGENTS.md on a disk that ignores case).
- Not listed: Cursor (user rules live in its settings; .cursor/rules is
  per project), Codex (its rules are execpolicy), Droid (command
  permissions), Gemini CLI, Qwen Code and OpenCode (no rules folder).

A body starting with --- gets an empty front matter first. Files are
recorded with their hash in Applied.Rules through the same
syncOwnFiles as subagents and slash commands: a file of the user's own
by that name, or one magpie wrote that the user edited, is never
written over or taken away. Bundles (backup, WebDAV) carry rules; a
bundle from an older magpie leaves this computer's alone. The editor
lists each agent's file to reveal. No CLI yet.

docs/subsystems/library.md: a Rules row and its tests.

Run (mica-run, at this tree):
- go vet -tags nogui ./internal/library ./internal/gui ./internal/davsync
  ./internal/cli: ok. gofmt -l: none.
- go test -tags nogui -timeout 45m ./internal/library ./internal/davsync:
  ok (TestRulesEachAgentsFile, TestRulesKeptToTheirPaths,
  TestRulesLeaveTheUsersFiles, TestRuleCheck, TestRulesCarried).
- node --test library-rules, library-subagents, library-commands,
  library-hooks, library-loading, library-groups, i18n-keys,
  i18n-en-no-cjk (Chromium and WebKit, 420 and 1100 wide, en zh zh-TW
  ja de): 78 of 78.
- The full suite and cross-OS vet ran at the next commit, which this
  one is under.
- Real use: Claude Code 2.1.327 in a sandbox HOME loaded a rule without
  paths at launch and one with paths only on touching a match; a
  sandbox magpie on mica wrote ~/.claude/rules/go-style.md with
  paths: ["**/*.go"].
Not tried: Cline and Kiro CLI loading the files for real, project-level
rules (.claude/rules in a repository), Copilot and CodeBuddy (not
verified, not listed), Windows and Linux.
2026-11-19 12:20:02 +08:00
yetone 567ba3a277 codex: a function tool goes with a strict the backend can compile (Anotiaww on X)
Anotiaww on X: LobeHub's OpenAI provider, pointed at magpie, asked a
Codex model on Responses and got "Codex: Invalid schema for
'tools[3].parameters': oneOf constraints are not supported. Enable
'coerce_one_of' option to approximate oneOf with anyOf".

Cause: LobeHub sends its tools on Responses with no strict
(convertChatCompletionToolToResponseTool spreads the function, no
strict), and magpie passed them to the ChatGPT backend so. Left out,
the backend compiles a tool's parameters as a strict grammar; its
calculator's defintegrate bounds and limit's point are a oneOf of
string and number. Codex CLI itself says "strict": false on every
function tool (codex-rs/tools ResponsesApiTool). A Chat or Messages
client asking strict true with a schema strict mode refuses (calculate's
optional precision, an allOf, a lookaround) was turned away the same way.

Fix, in codexBody, so every route to a Codex account (Responses relayed,
Chat and Messages built as Responses) passes it: a function tool's
strict left out goes false, as Codex says it; strict true is kept when
the schema fits strict mode, with a oneOf asked as anyOf (the backend's
own suggestion); a schema strict mode still can't take goes as written
with strict false. Namespace tools, additional_tools and
tool_search_output are covered. coerce_one_of is not used: it is nowhere
in Codex's source or any docs found. Other vendors are unchanged.

What strict mode takes was tried on the backend (2026-11-19, the
owner's ChatGPT account, gpt-5.6-luna and gpt-6-sol among others):
refused with strict true: oneOf, allOf, not, if, uniqueItems,
minProperties, contains, propertyNames, dependentRequired, an optional
property, additionalProperties not false, a root anyOf, a lookaround, a
node with only a const ("schema must specify a type"); taken: anyOf
(nested, in items, in $defs), $ref, enum alone, a type list, const with
a type, min/max keywords, format, pattern, $schema, title, examples.
Left out, a lookaround is refused and false takes it.

Run:
- go test ./internal/provider -run TestCodexToolStrict,
  ./internal/gateway -run 'TestCodexToolSchemasTheBackendCompiles|
  TestToolStrictOnlyForCodex': ok on mica.
- go vet ./internal/provider ./internal/gateway for darwin, linux and
  windows: ok on mica. gofmt -l: clean.
- Real backend: LobeHub's 10 calculator tools as this change sends them
  (strict false on Responses; strict true from a Chat client, defintegrate
  kept strict as anyOf; calculate, evaluate, sort, limit and solve,
  which have optional properties, false)
  and a mixed set (oneOf nested in items and $defs, a const-only oneOf,
  an allOf, a lookaround): 200 on gpt-5.6-luna and gpt-6-sol. The old
  strict-true request was refused ("required must include declared
  property precision"). That run found the const-only case, fixed here.

Broken by hand: with the codexToolStrict call removed, the gateway
test is red with the reporter's message word for word (tools[5],
defintegrate). TestToolStrictOnlyForCodex passes on the old code too;
it guards scope (OpenAI's API, a relay and a Chat provider keep strict
left out and the oneOf).

Not tried: the reporter's exact 400 could not be reproduced on this
account, where a oneOf with strict left out was taken on every model
tried; the lookaround case shows the same rule. LobeHub itself was not
run. The full suite runs after the tag (mote load 28 on 18 cores, mica
in another session's suite); its result goes in a follow-up.
2026-11-19 12:10:09 +08:00
yetone 2051dfc232 library: the Pi market finds packages by name on npmmirror (eachg0 on X)
eachg0 on X: searching the Pi market for "rename" (or "pi-rename") found
nothing, though npm's pi-rename 1.2.0 carries the pi-package keyword.
cf20df721 (11-18) made the market ask the registry in use first: magpie's
own, the user's .npmrc/bunfig/env, or npmmirror with the 「国内镜像」
switch. npmmirror knows no keywords: qualifier. It answers 200
{"objects":[],"total":0} to "keywords:pi-package rename", so npm's own
search, asked only when the registry fails, never was. Its plain search,
"pi-package rename", finds 52, every one with the keyword.

A search with words that comes back empty is now asked again with the
qualifier as a plain word (plugin.PlainKeywords), and the keyword is
still checked here. The list before a search is unchanged: npmmirror
answers it with nothing, and magpie's snapshot stands, as before.

Sibling: the Plugins page's search (plugin.Search) asks
"keywords:pi-package <q>" too, and with the switch on source.Do sends it
to npmmirror first, so it found no pi provider packages there either.
searchNPM retries the same way. No other search uses a qualifier.

Tests, from npmmirror's own bytes (testdata/npmmirror, 2026-11-19):
TestPiSearchFindsByNameOnNPMMirror ("rename" and "pi-rename" find
pi-rename with npm's own search down), TestSearchFindsPiPackagesOnNPMMirror,
TestPlainKeywords.

Run (mica, at this tree; origin/main 3869aee3b, unchanged at push):
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok; go build, GOOS=linux go build -tags
  nogui, GOOS=windows go build: ok
- go test -tags nogui ./internal/library ./internal/plugin: ok
- go test -tags nogui ./internal/gui: two reds, both filed and both
  passing alone at this tree: TestAppReplacesItsOlderGatewayOnceIdle
  (#6297) and TestGatewayModeListsNoOwnSessions (#7064)
- GUI library-pi-market.test.cjs: Chromium 22/22, WebKit 11/11

Broken by hand: the old pimarket.go and market.go with the new tests:
TestPiSearchFindsByNameOnNPMMirror red ("rename": [] asked
["keywords:pi-package" "keywords:pi-package rename"]),
TestSearchFindsPiPackagesOnNPMMirror red (Search = []).
Real use (sandbox HOME, NPM_CONFIG_REGISTRY=https://registry.npmmirror.com,
live npmmirror): old code "rename" 0 results, "pi-rename" 0; new code
52 and 52 with pi-rename; Plugins search "antigravity" finds the pi
provider packages. npm's own registry: pi-rename found before and after.
Not run: the full go test ./... (mote and mica each had another
session's full suite running), the whole GUI suite (no GUI or API change).
Not tried: the real 「国内镜像」 switch in the app (same registry URL as
the env var path).
2026-11-19 11:50:37 +08:00
yetone 3869aee3b0 sessions: agy's calls in T3 Code are on Usage → Requests
zzzkl on X: requests from Antigravity in T3 Code weren't on Usage →
Requests, while a plain agy's were.

T3 Code (pingdotgg/t3code, read at 00c6adbd) runs agy for each
Antigravity instance as an ACP server on the instance's own Google
sign-in: `agy acp --gemini-dir <profile> --app-data-dir antigravity-acp`
(antigravityAuthSupport.ts), the profile being
<T3 Code's folder>/userdata/providers/antigravity/<sha256 of the
instance id>, the folder $T3CODE_HOME or ~/.t3 (dev for its dev
server). Those requests go to Google, never through the gateway, and
magpie's agy reader looked only in ~/.gemini/antigravity-cli, so
nothing counted them. agy writes the same transcript_full.jsonl there
as in its own folder (agy 1.5.10 run that way in a sandbox against a
fake Gemini endpoint; the fixture is its bytes).

agyCallFiles now reads every T3 Code profile's antigravity-acp too, and
Found lists agy for those folders, so the read consent covers them.
T3 Code's folder is appdir.T3Code, shared with agent's t3Base.

Siblings: `agy acp` from any other ACP client with the defaults writes
to antigravity-cli, already read (agy acp --help). T3 Code's magpie
instances (Claude, Codex) go through the gateway and are counted there.

Run: TestAgyCallsInT3Code (default folder, T3CODE_HOME, ~/ form) red
on the old calls_agy.go/access.go with 0 calls, and with Found() =
[claude codex] when only access.go is old; green with the change.
gofmt -l clean; go vet (darwin, GOOS=linux, GOOS=windows) of appdir,
agent and sessions on mote. Full suite (go test -timeout 45m ./..., mica, at 0e3d09361 plus this):
every package ok but agent, dirent, gateway, gui, library and profile;
each red was run again at the base: TestWSLAgentFolderIsALink 2 of 12
red at the base too (filed #7150), the dirent watch tests and
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes red at the base
(#7031, #7117), TestGatewayModeListsNoOwnSessions (#7064) ok alone,
library and profile hung in testenv.warmAt (#5267) and ok alone.
After the rebase on 14b6b9555 (this commit's tree): appdir ok, agent ok
but TestWSLAgentFolderIsALink (#7150), sessions ok (2335s).
Rebased again onto 9768b384e (its three commits touch none of
sessions, agent or appdir): go build ./... and the TestAgy/T3 tests
of sessions and agent ok at this commit.
No GUI file is reached (no string, API or page change).

Not tried: a real T3 Code signed in to Google (the profile layout is
from T3's source, agy's files from a real agy acp); T3 Code in WSL;
a plain agy with its own GEMINI_HOME/--gemini-dir. The calls count as
agy (Antigravity CLI), not T3 Code, and the Sessions page doesn't list
these conversations (agy --conversation would look in agy's own folder).
T3's throwaway helper sessions delete their files, so their calls go too.
2026-11-19 11:18:11 +08:00
yetone 9768b384e4 router: find_tools finds tools for a query in Chinese, and names every tool when none matches (Passings_z on X)
Passings_z asked on X (tweet 2123227759409586219) why, with the MCP
router's tools on demand, some tools never get used. An agent given
find_tools and call_tool that asks in Chinese found none of the tools
there were:

- hubWords split only at characters that aren't letters or digits, so
  帮我截个图 was one word, and hubWordIn looked for it whole in the
  description, which an English one never has.
- hubMatch.clears needs two thirds of the query's key words, so
  截图 screenshot failed on a tool named screenshot too: 截图 counted
  against it.
- With nothing matched, the reply named 8 tools a server, so a model
  had no way to the rest.

Now:
- hubWords also cuts where a spaceless script (Han, kana, Hangul) meets
  another (截图screenshot is 截图 and screenshot). A spaceless word is
  cut at characters that say nothing of a tool (hubStopRunes: 我 帮 个
  を …), each piece a key word (帮我截个图 is 截 and 图), found in a text
  when it is one character there or at least half of its two-character
  runs are (hubPhraseIn).
- Key words are matched against the tool's router name, its server's
  own name (a server named in Chinese) and its description.
- A key word with letters not in ASCII counts only for a tool whose
  name, server or description has such letters, so 截图 screenshot is
  screenshot to an English tool. An English query matches what it did.
- No match names every tool of each server when that fits in hubSayMax
  (2000 characters), else 8 a server and that find_tools with an empty
  query names every tool. A query not in ASCII when no tool has such
  letters is told the tools are named and described in English.

Siblings: hubNear (call_tool's close names) shares hubKeyWords and
hubMatchOf, so it takes the same words. The GUI's searches are
substring filters (includes), not this tokenizer; nothing to change.
find_tools' and call_tool's descriptions and the instructions, the text
that goes to the vendor, are unchanged.

docs/subsystems/mcp-router.md: Tools on demand says the new matching
and the no-match reply.

Tests (internal/gateway/hub_find_cjk_test.go):
- TestHubFindInChinese: 截图 screenshot, 截图screenshot, 帮我截个图,
  截取屏幕, 发消息到群聊, 截屏 (a server named 截屏工具) find their tool
  first, and not each other's.
- TestHubFindNotFoundNamesEveryTool: all 12 of a server named, the
  English hint, and past the budget the empty-query hint.
- TestHubFindEnglishAsBefore: 30 English queries match exactly what
  they matched at 14b6b9555.

Run:
- Old code (14b6b9555 with the new test file, on mica):
  TestHubFindInChinese FAIL ("截图 screenshot" matched [], "帮我截个图"
  matched [], 6 of 8), TestHubFindNotFoundNamesEveryTool FAIL (not
  every tool, no English hint, no empty-query hint),
  TestHubFindEnglishAsBefore PASS (as it should).
New code, at base 14b6b9555, on mica (mote's load was over 18):
  gofmt -l prints nothing; go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.
  HOME=<temp> go test -tags nogui -timeout 45m ./...: every package ok
  but agent, dirent, gateway and gui. Each red rerun on mica at the new
  code and at 14b6b9555:
  - internal/dirent watch tests: red at both (#7031).
  - TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes: red 3 of 3 at
    both (#7117).
  - gateway doneHold.serve "close of closed channel" panic
    (continuation_test.go:781): #6505, #6690; not seen on the rerun.
  - TestWSLAgentFolderIsALink (#7150) and TestGatewayModeListsNoOwnSessions
    (#7064): pass on the rerun at both.
  The new hub tests and every Hub/HubMCP/HubFind test pass.
- Rebased on origin/main 7d5db0f29 (cli plugin hosts, update hint; no
  file in common): go build, go vet ./... and
  go test ./internal/gateway -run 'Hub' run again there: build ok, vet ok, gateway Hub tests ok.
- Not tried: a real agent without its own tool search (e.g. OpenCode,
  Kimi) asking the router in Chinese end to end; the queries tested are
  my own phrasings against real servers' English descriptions plus
  invented Chinese ones, not the reporter's own tool list.
2026-11-19 10:54:42 +08:00
yetone 7d5db0f29a cli: a command that ends ends its plugin hosts, and one that doesn't serve starts none (#7146)
athemeroy (WangYeruo on X) runs `magpie serve` as a LaunchAgent with the
magpie-google-ai-studio browser plugin and 11 accounts. Each
`magpie --version`, `version`, `licenses` or `group <id>` run beside it
left a second magpie-bun host with PPID 1, holding the Chrome profiles
the gateway's host wanted ("Chrome exited before starting WebView").
Their analysis was right on each count:

- plugin.Cached starts a background list of the plugins' providers
  whenever this process hasn't listed them (provGood is in memory), so
  every short command reaching provider.Catalog (startUp's RenameLegacy,
  groups, models, ...) started a host.
- Main ended through os.Exit and never stopped it. A host whose stdin
  closes leaves only once nothing is pending, and a plugin holding a
  browser keeps Bun up meanwhile, so the host outlived magpie, adopted
  by init. SIGTERM (launchd stopping serve) orphaned serve's own host
  the same way.
- --version and licenses were answered after startUp.

Now:
- Cached asks the plugins in the background only when
  plugin.ListInBackground is on; run sets it from servesPages (app,
  web, serve, TUI). Other commands read the list on disk.
- Main ends through exit(), which runs plugin.EndHosts first, on
  success and error; die does too on SIGINT/SIGTERM/SIGHUP, bounded by
  hostsOnSignal (20s, past the 15s a renewing host gets).
- provider test returns exitError instead of os.Exit(1).
- -v/--version/version and licenses answer before any start-up work.

Audit of the os.Exit calls in internal/cli: data_cli.go:135 and the
CheckEnv exit in Main run before anything can start a host;
claudeLetGo already called EndHosts.

Tests (red on the old code, the non-test sources reverted to
14b6b9555, green with the fix):
- TestOneShotCommandsStartNoPluginHost: groups, group fakeco, models,
  providers, accounts each started a host (5 reds); version, --version,
  -v, licenses and agents start none; Cached in a serving magpie still
  lists.
- TestExitEndsPluginHosts: a real host whose stuck usage hook holds it
  up (new STUCK_USAGE_HOLD, STUCK_PID in testdata/stuck), the magpie
  ended by `version`, by an error and by SIGTERM: all three left the
  host at PPID 1 on the old code, none now. 10 of 10 on macOS, 3 of 3
  on Linux (WSL), version/error on Windows (no SIGTERM there).
- TestSessionCommandsSkipStartUp: version/--version/-v/licenses don't
  run startUp (red on the old code for version). Three tests that used
  `version` to reach startUp/makeDirs use `groups`.

Real use, sandbox HOME on mote, a plugin whose provider list takes 90s
holding a timer, signed in with a key, `magpie serve` running:
- old binary: groups, group holdco and models each left a magpie-bun
  at PPID 1; after SIGTERM to serve, serve's host was at PPID 1 too
  (4 left).
- new binary: only serve's host, and none left after SIGTERM. The
  commands take 0.02-0.15s.

Run at the pushed head:
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build: ok (mote).
- go test -count=1 -timeout 45m ./... on mote: 102 packages ok, two
  red, each red the same at the base 14b6b9555 (-count=3/5 there):
  internal/cli TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr,
  TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr and
  TestUpdateFindsAMagpieThatWroteNoRecord (#6471, #6223: an ssh
  session's forward holds 127.0.0.1:3425 on mote), and internal/gateway
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117).
- Rebased on 598bc4534 (it changes internal/cli's update code), at
  the pushed head: go test ./internal/cli ./internal/plugin on mote:
  plugin ok; cli ok but for the same three #6471 reds.

Not tried: the reporter's real Google AI Studio plugin with Chrome, and
a real LaunchAgent stop (launchctl); the repro sends serve SIGTERM as
launchd does.
2026-11-19 10:38:25 +08:00
yetone 598bc45346 update: a container's hint names the found version's own image, not :latest (fishmagic80 on X)
In Docker, Settings › About on the Daily channel said "0.1.4479 is out
… docker pull ghcr.io/yetone/magpie:latest". :latest is the newest
release (docker.yml), daily and stable the Daily and Stable channels'
(docker-daily.yml, docker-stable.yml), so :latest held 0.1.4504, not the
0.1.4479 announced; on Stable it is weeks apart. docker.yml writes every
release's own tag (ghcr.io/yetone/magpie:0.1.4479; checked on ghcr: 4479,
4395, latest, daily, stable, 0.1 all resolve, daily = 4479's digest).

update.Image(version) is that tag, and every place that printed the
command names it now, with "recreate the container from it" (a compose
file on :latest would otherwise run the old tag again):
- the GUI's Version row and Update pill (/api/update's new `image`,
  stuck "container"; app.js updateStuck);
- `magpie update` in a container (internal/cli);
- a Remote magpie row's tip for a container: UpdateRemotes now keeps the
  version it asked for on an "unsupported" answer too, so the tip names
  that version's image;
- i18n zh, zh-TW, ja, de for both strings;
- docs/docker (en, zh, ja): Updates says Settings › About names the
  version's own image and that latest may be ahead of the channel;
  llms-full and search indexes rebuilt (site/docs-index.mjs).

Run at this tree (mica, through mica-run):
- red on origin/main 14b6b9555 with the new tests copied in:
  TestUpdateInContainerSaysPullTheImage (cli: ":latest" in the error),
  TestRemoteMagpieAskedToFollow (gateway: Version v0.1.100, not the asked
  v0.1.200), update-stuck.test.cjs container cases and
  remote-update.test.cjs, both engines;
- green here: go test ./internal/update ./internal/cli, internal/gateway
  and internal/provider -run TestRemote*, internal/gui except
  TestGatewayModeListsNoOwnSessions, which fails the same on
  14b6b9555 alone (#7064);
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build, gofmt -l (nothing);
- node --test site/docker-tags.test.mjs; GUI files in chromium and
  webkit: update-stuck, remote-update, update-channel,
  update-stable-newest, update-release-page, update-check, lan-docker,
  i18n-keys, gui-de, gui-zh-tw, i18n-en-no-cjk (216 pass, 0 fail);
  gui-ja's "ja has every zh string" is red on main for another string
  (#7144).

Not run before the push: the full `go test -tags nogui ./...` (mote and
mica each had another session's full suite running); it runs after.
Not tried: a real container pulling the new tag. Not checked at runtime:
whether the version's image is already on ghcr; docker.yml pushes it in
~6 minutes, before the release is published, and a missing one makes
docker pull fail with "manifest unknown", not pull another version.
2026-11-19 10:26:23 +08:00
yetone 14b6b95556 sessions: a session resumed into copies isn't read whole again after a start (shangyuan0818 on X)
shangyuan0818 on X, on the latest Windows build: after using an agent,
Sessions took 18 s to load. They had ~100 Claude Code sessions of 30 to
100 MB and read Claude Code only, and guessed it was dedup, since
ccusage is slow on the same files.

Cause: older `claude --resume` wrote each resume as a whole copy of the
session under a new sessionId. ccFamily judges such a group by every
file's message uuids (ccUUIDsOf), and ccRest reads each copy for what
its keeper doesn't hold. Both were kept in memory only. cc-rest.json
kept the rests, but without the uuids they were read from (ids nil).
After a start, the first turn of the session the copies are kept in
changed the group's signature and its size, so every file of the chain
was read whole twice: gigabytes before Sessions showed. Codex is not
read with Claude-only reads (the cold load is the same with its folder
empty).

Fix: the uuids of each file of a group are kept on disk, one file each
in cc-uuids/ (named by a hash of the path), with the size, mtime, the
offset read to and a prefixHash of the bytes up to it. A start reads
them back and goes on from the offset only while the hash still
matches the file's start; otherwise the file is read from its start.
The rest ids are kept in cc-rest-ids.bin under the rest's key, so a
keeper that only grew leaves its copies unread after a start too.
Entries whose session file is gone are pruned once a start. Trash
drops an entry. Reset forgets the in-memory uuids, like a real start.
Not changed: a first start (no cache) still reads each copy three
times (parse, ccUUIDsOf, ccRest), filed as #7143.

Windows (xiaomi-gpu, Windows 11, CGO_ENABLED=0 builds, Claude-only
reads, sandbox HOME). The fixture is 5 resume chains of 20 files, 30 to
107 MB each, 6.9 GB. Time is for the page's three requests together.
                                     origin/main   this change
  cold, no cache                         20.2 s        17.6 s
  warm restart                            0.30 s        0.30 s
  restart after 1 keeper's turn       3.29/3.14 s   0.38/0.25 s
  1 keeper's turn while running           1.60 s        0.11 s
  restart after 5 keepers' turns          7.25 s        0.92 s
  5 keepers' turns while running          3.32 s        0.78 s
The profile of a restart after a turn on origin/main was ccFamily →
ccUUIDsOf (1.23 s) and ccCopyStates → ccRest (1.14 s) in scanThin.
The kept uuids take 2.4 MB for the fixture's 100 files.

Tests (internal/sessions/cc_copies_test.go):
- TestClaudeKeeperTurnAfterAStartReadsNoCopy: a turn, then Reset, reads
  no file from its start, and the turn is counted.
- TestClaudeKeeperTurnTheBranchHeldAfterAStart: a keeper that grows,
  after a start, with a message the branch held on its own counts it
  once.
- TestClaudeKeptUUIDsOfAFileWrittenOver: an entry whose file was
  written over doesn't stand.
- TestClaudeKeptUUIDsRoundTrip.

Run at this tree:
- go test ./... -count=1 -timeout 45m on mote: 102 packages ok, 2
  red, both filed: internal/cli's TestHealthcheckFindsTheRunningGateway
  WithoutMagpieAddr, TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr
  and TestUpdateFindsAMagpieThatWroteNoRecord (#6471, #6223: they ask
  whatever serves 127.0.0.1:3425 on mote), and internal/gateway's
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117, red on main).
- go test ./internal/sessions -race -count=1 -run TestClaude -timeout
  25m on mica: every new test passes; 2 reds, both data races filed and
  outside this change: TestClaudeCdKeptParseReadAgain (#6213, red the
  same at 0e3d09361 on mica) and the claude-desktop-3p subtest of
  TestClaudeTraceSubagentsShareSessionWithoutIDCollisions, failed by
  testenv.Zone's cleanup against provider's sweepStale timer (#4360).
  A first try at -count=3 hit go test's default 10m timeout mid-run
  (3 x ~240s under -race), not a hang.
- go vet ./internal/sessions on darwin, GOOS=linux and GOOS=windows
  (mote): clean. gofmt -l: clean.
- win-run go test ./internal/sessions: 4 reds, TestAgySessions,
  TestAgyRowOnly, TestAntigravityAppFolder and
  TestCCListingKeepsItsNames. The same 4 are red at origin/main
  0e3d09361 on the same box, filed as #6071.
- No GUI test reaches this: the GUI tests fake the API, and no asset
  changed.
Broken by hand:
- kept uuids not read back (ccUUIDKept ignored):
  TestClaudeKeeperTurnAfterAStartReadsNoCopy red, all three files read
  whole on each turn.
- rest ids not read back: that test red, the two copies read whole.
- rest ids read back as empty: TestClaudeKeeperTurnTheBranchHeldAfterAStart
  red, 90 tokens in where 80 are wanted.
Not tried: the reporter's own files, or a real Claude Code --resume
chain (the fixture is generated in that shape). Not tried on a slow
disk or with Defender scanning, which the reporter's 18 s may include.
2026-11-19 09:10:33 +08:00
yetone 0e3d093611 library: a memory holding magpie's end line stays inside magpie's part
magpie's part of an agent's instructions file (AGENTS.md, CLAUDE.md...)
ends at the first "<!-- magpie:end -->" in it, wherever it sits. The
part holds memory's digest, which an agent (memory_save), a remote
Memory key or a distilled conversation writes, and a18ed4995 now keeps
a memory's own lines. A memory holding that line ended the part early:
the text after it read as the user's own instructions, was written
again after the part on every sync, and stayed in the file after the
memory was forgotten or memory turned off. So one memory saved from a
prompt-injected session became a lasting instruction in every ticked
agent's file, outside anything the Memory page shows or removes. It
held before a18ed4995 too, with the line inside a memory's one line.

markersOut makes "<!-- magpie:" inert ("<!-- magpie :") in what magpie
writes into its part: wanted (shared text, an agent's own, memory's
digest), a project's instructions, and withBlock itself. Doing it in
wanted keeps the part in the file equal to what magpie compares it
with, so the page doesn't call it the user's edit.

Run on mica at this tree:
- go test ./internal/library ./internal/memory: ok, ok.
- go vet ./internal/library ./internal/memory on darwin and
  GOOS=windows on mica, -tags gtk3 on Linux (wsl-run): clean.
- gofmt -l: clean.
Broken by hand:
- markersOut returning text as it is: both new tests red. The text
  after the line was outside the part, a second sync wrote it again,
  and taking the part out left it.
- markersOut in withBlock only, not in wanted:
  TestMemoryWithEndLineStaysInMagpiesPart red, with codex's row Edited.
Not tried: a real agent's file through the app.
2026-11-19 07:05:22 +08:00
yetone a18ed4995f memory: a memory of several lines keeps them, folded to its first line (_meouwu on X)
_meouwu on X: a memory added by hand in several lines showed as one line
with its breaks gone; it should keep its format and, folded, show the
first line and an ellipsis.

Cause: the store never lost the breaks. A memory file's body is
m.Text as written (encode/apply trim only the ends). They were lost
where it was shown: the Library row clamped the name to two lines with
white-space normal, the digest given to agents went through oneLine
(strings.Fields), and so did memory_search / memory_list in the memory
MCP.

Now:
- Library: a folded row and a suggestion show firstLine(text) (first
  line, " …" when more follow); an open row shows the whole text
  pre-wrap. The editor already kept "\n".
- Digest and memory MCP: memory.Indented keeps each line, the lines
  after the first indented two spaces so the memory stays one list
  item.
- Dream and distill listings stay one line on purpose: the model's
  reply is read line by line, and a user's memory is Fixed, never
  rewritten by them. Written in docs/subsystems/memory.md.

Memories saved before: their files already hold the breaks, so after
updating they show, edit and reach agents in their own lines. Nothing
to redo, no migration.

Run at 3fabaf8f2 (on origin/main b332ef7ef, the pushed head),
f6452d777 (on 1622484a8) and ee84e288a (on 54117164c), on the WSL VM magpie-desktop: mote and mica were over
their cores with other sessions' suites for ~2h.
- go vet -tags gtk3 ./... ok; gofmt -l clean.
- go test -tags gtk3 -count=1 -timeout 45m ./... at ee84e288a: 101 ok,
  2 FAIL, both red at origin/main 2416beed6 on the same VM:
  internal/gui TestClipboardReadBack (#7074, #7073), internal/usage
  TestRequestStateKeptAcrossACatalogFetchedAgain (#6572).
- Whole GUI suite (concurrency 8): 1355 of 29368 red in 221 files under
  load. Those 221 again at concurrency 3: 71 red; 66 of them red at
  base 54117164c too. Of the other 5, 3 pass alone;
  codex-auto-reset-settings (#6108) and copilot-ghe (#1949) are red at
  base alone too (2 of 3 and 3 of 3 rounds), commented there.
- After the rebase (f6452d777): internal/memory, internal/memdistill
  and -run "Memory|Budget|I18n" in gateway, gui, library ok. All 84
  library-*.test.cjs: 1920 of 1950 pass; each red file alone, beside
  1622484a8: commands-import, group-steady, mcp-copy-config,
  mcp-off-fold, open-again and all are red at base too (#7097; all 3 of
  3 at base); memory-suggest, mcp-json and bili pass alone.
- At 3fabaf8f2 (b332ef7ef brought flying_crp's digest header and
  memory_save note; conflicts were only both sides adding tests and
  doc text): go vet memory, gateway, memdistill; go test memory,
  memdistill, access, and -run "Memory|Budget|I18n|Digest" in gateway,
  gui, library ok; library-memory*.test.cjs 112 of 112.
- library-memory-lines.test.cjs: 5 langs x 980/420 x chromium/webkit.

Broken by hand (old code, new tests): TestMultiLineMemoryKeepsItsLines
red at the digest step only (save, edit and the file passed: the store
kept the breaks), TestIndented and TestMemorySearchKeepsTheLines red,
library-memory-lines red ("Release steps: …" expected).

Not tried: a macOS run (mote, mica busy), Windows, the real app.
2026-11-19 06:32:40 +08:00
yetone b332ef7efe memory: a project's own instruction files win over memory, and its rules go there (flying_crp on X)
flying_crp on X: with memory on, the digest in the agent's instructions
disagreed with the project's own rules, and things that belong in the
project were saved to memory instead, while the user keeps the
project's docs tidy themselves.

- The digest's header (internal/memory/digest.go) now puts the
  project's own instruction files (AGENTS.md and the like) and docs
  first: where a memory disagrees, the agent follows the files and
  says which memory is out of date. A project's rule or fact belongs in
  its files; memory keeps what holds for the user across projects.
- memory_save's description says the same, and a new save made in a
  project whose root holds AGENTS.md, CLAUDE.md, GEMINI.md,
  .github/copilot-instructions.md or .cursorrules ends with a note
  naming the files found: for a memory of the caller's project (any
  kind but profile and preference), to offer to write it there and
  forget the memory once it is; for a global rule or procedure, the
  same when it holds only in this project (projectFilesNote). The save
  itself is kept.
- Distillation's instructions leave a project's rules and conventions
  to its files, and drop what disagrees with them.
- The texts name neither magpie nor a vendor (checked in each test).
  The only filenames named are AGENTS.md "and the like" in the fixed
  text, and in the save note the files actually found on disk.
- docs/subsystems/memory.md says all three.

Tests, each red on the old code (the three source files put back to
origin/main by hand, tests kept), green with the change:
TestDigestDefersToTheProjectsFiles (internal/memory), TestWhatIsSent
(internal/memdistill), TestMemorySavePointsProjectRulesToItsFiles
(internal/gateway, -tags nogui).

Real agents, sandbox HOME and CLAUDE_CONFIG_DIR, model through the live
gateway as an endpoint only, nothing live written:
- Digest: a git project whose CLAUDE.md/AGENTS.md say "Python code here
  is indented with tabs", and a digest in the sandbox CLAUDE.md with a
  project memory "Indent Python code with 4 spaces". Asked to write
  add.py, with the old header Claude Code (haiku and sonnet) both used 4
  spaces, following memory; with the new header both used a tab and
  said the memory was out of date.
- Save: a sandbox `magpie serve` built from this tree on 127.0.0.1:3471,
  Claude Code (sonnet) with its memory server over --mcp-config, asked
  to "remember for this project: tests always run with pytest -x". The
  save came back with the note naming AGENTS.md, CLAUDE.md, and the agent
  offered to add the rule to them and then delete the memory.

Full suite (`go test -timeout 45m ./...`, mica):
- at a9696f14d: mica's disk filled during the run; reds in 17 packages
  were "no space left on device". Not counted.
- at 8647ac995 (origin/main + this): 101 ok, 3 red, each filed and not
  in code this change touches: internal/dirent watch tests (#7031),
  internal/gateway TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes
  (#7117), internal/gui TestGatewayModeListsNoOwnSessions (#7064).
- at d67beb049 (this commit's tree, on origin/main 67405d560): 101 ok,
  the same 3 filed reds (#7031, #7117, #7064), nothing else.
GOOS=linux and GOOS=windows go vet of memory, memdistill and gateway:
ok. gofmt -l: clean. No GUI or i18n change, so no GUI suite run.

Not tried: Codex or other agents (Claude Code only); a memory server
reached from another computer (the note stats the project roots that
computer named, on this one: at worst an advisory note).
2026-11-19 03:27:25 +08:00
yetone 67405d5609 gui: the management API leaves a key let use Magpie Memory alone
4e24994a6 let a gateway key the user picks use Magpie Memory from another
computer (access.Key.Memory). memory-key is left out of the management
API, but rotate-key is not: an admin key, which may manage magpie and
nothing more, could rotate a Memory key through POST
/v1/magpie/admin/gateway-keys/rotate-key and get its new secret back (or
set a secret of its own). With it, it read and wrote memory, whose digest
goes into every agent's instructions on this computer.

adminMayChangeKey now refuses any action on a key with Memory, as it
already did for a key that may manage magpie; the caller's own key stays
its to change. TestAdminAPILeavesMemoryKeys covers rotate-key, with and
without a chosen secret, and memory-key.

Run on mica at this tree:
- go test ./internal/gui ./internal/access: access ok; gui red once on
  the first run, and the log of that run wasn't kept, so the failing test
  isn't named. Two more runs of ./internal/gui, logged whole: ok, ok.
- go vet ./internal/gui ./internal/access on darwin, GOOS=windows on
  mica, and -tags gtk3 on Linux (wsl-run, magpie-desktop): clean.
- gofmt -l: clean.
Broken by hand: with the new check off, the test is red. rotate-key
answers 200 with the Memory key's secret, and the caller's chosen secret
opens "Remote box".
Not tried: a running gateway with a real remote admin key.
2026-11-19 03:06:55 +08:00
yetone 06428541ac agent: Dim's Magpie provider names each model with its provider, so two vendors' DeepSeek are told apart (T_t__biu on X)
T_t__biu on X: in Dim alpha, models of its built-in Magpie provider
can't be told apart by the magpie provider behind them; two vendors'
DeepSeek read the same.

Cause: Dim names a listed model by the display_name (or displayName,
name) of the endpoint's /v1/models (crates/dim-app-server
provider/remote.rs), shown in its Models page, `dima models` and the
picker's search. magpie's /v1/models gives display_name the name alone
(PlainName) to every client but Cindy and Claude Code's discovery.

- /v1/models asked with Dim's key gives display_name the name the
  agents' lists give the model (provider.LabelsFor("dim"): its
  provider's after it, as the Provider in model names setting says),
  as Cindy's already is.
- Dim takes names only when it lists the models again
  (provider.refresh). dim.json now keeps dimListed (a hash of the ids
  and names) of the last listing, and Sync, while Dim's daemon runs,
  lists the provider again when it changed: a provider renamed or
  added, the setting changed, and a Dim connected by v0.1.4497, which
  kept none, on its first Sync.
- A name the user gave a model in Dim (provider.models.edit) is a
  descriptor override, which Dim's refresh keeps. No other provider of
  Dim's is touched; disconnect is as before.

Run at this commit's tree (rebased on origin/main c4bae0724):
- Red on the old gateway.go/dim.go (a Listed field stubbed in):
  TestCindyDiscoveryNamesModelsApart/dim (Dim told "GLM-5.3-Flash"
  for all three providers) and TestDimListsAgainWhenNamesChange (no
  refresh on Sync). Green on the new code.
- Real Dim 0.1.0-alpha.24 (npm dimcode-alpha) in a sandbox HOME on
  mote, a sandbox `magpie serve` on 38741 with two custom providers
  (SiliconFlow, DeepSeek Official) each serving deepseek-v3: after
  `magpie dim sf/deepseek-v3`, `dima models magpie` and the daemon's
  provider.management list "DeepSeek V3 · SiliconFlow" and "DeepSeek
  V3 · DeepSeek Official". After renaming ds/deepseek-v3 to "My DS"
  in Dim (provider.models.edit) and `magpie provider set sf
  name="SiliconFlow CN"`, Dim lists "DeepSeek-V3 · SiliconFlow CN" and
  "My DS" (listed hash moved). `magpie dim default` turned the provider
  off, key cleared, 3425/v1.
- At 4938d8527 (on origin/main c4bae0724): gofmt -l clean; go vet -tags nogui
  internal/agent and internal/gateway, GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./... ok (mote). go test -count=1 -timeout 45m:
  internal/agent ok (265.9s, mote); internal/gateway (mica) ok except
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, red on origin/main and
  filed and taken as #7117 (OpenCode Go/Zen, not Dim). The full ./... suite
  was not run.
- Rebased onto 4e24994a6 (gateway Memory access): gofmt, vet (darwin,
  linux, windows) of both packages and -run 'TestDim|TestCindyDiscovery|
  TestListModels|Memory' ok again at 65cd98fca's tree (mica).

Not tried: Dim's desktop app (CLI and daemon only); Windows and Linux
with a real Dim (the change is in the gateway's list and a refresh call
the Windows pipe already carries); upgrading a real v0.1.4497 connect
(the unit test clears the listing to stand for one).

Not changed: a model the gateway knows no limits of, which magpie gives
them at its pick (provider.models.edit), holds a Dim descriptor
override with the whole entry, its name as listed then (Dim's
merge_visible_edit); a later rename doesn't reach that one model until
it is reset in Dim. One picked under v0.1.4497 keeps its plain name so.
2026-11-19 02:47:38 +08:00
yetone 4e24994a6e gateway: a key let use Magpie Memory reaches it from another computer
Niapyaya on X reaches their own MCP servers through the MCP hub from a
remote machine, but not magpie-memory: memory answered the agents on
this computer alone, on /mcp/magpie/memory (547585cd9) and in the hub
(HereOnly), whatever key came. That was on purpose: a friend's key
could read every memory or plant a global rule the digest writes into
every agent's instructions here.

So it stays off for every key, and the user can let one key of their
own use it:

- access.Key.Memory, set by "memory-key" (`magpie gateway-key memory
  <id> on|off`, or the key's ... > Advanced > Magpie Memory). As Admin,
  only a key the user made can have it (memoryOf): never the sharing
  key, a read-only or Browser key, nor an issued or expiring one.
  Read-only takes it away; the management API can't set it.
- memoryMCP lets a caller from elsewhere in only while magpie is
  shared, by such a key, and never from a page by hubFromPage (Origin,
  Sec-Fetch-Site, a Mozilla/ agent; Node's fetch sends Sec-Fetch-Mode,
  #5522). This computer's check is unchanged.
- The hub gives magpie-memory (HubServer.Memory, from isMemory) to an
  Away visitor only by such a key (HubVisitor.Memory), listed and run,
  in the gateway and again in the library's Call.
- Advanced in the key's menu now opens Management API and Magpie
  Memory, each its own pick; a key with it says so in its row. Strings
  in zh, zh-TW, ja, de. Docs: memory.md, mcp-router.md, and the site's
  remote page (en, zh, ja) with its index rebuilt.

Image already answers a key directly (/mcp/magpie/image, held to the
key); sessions stays this computer's. There is no skills MCP server.

Tests: TestMemoryMCPToAKeyGivenIt, TestHubGivesMemoryToAKeyLetUseIt,
TestMemoryKey, the hubServerOf Memory column, and gateway-key-admin's
GUI file now goes through Advanced > Management API and covers Memory.

Run (mote unless said; base d01e0a465, rebased onto c4bae0724, which
only touches the Settings keep guard):
- Red on the old code (mica): TestMemoryMCPToAKeyGivenIt (403 to the
  key) and TestHubGivesMemoryToAKeyLetUseIt (hub listed [docs] only).
- go test -count=1 -timeout 45m ./internal/access ./internal/gateway
  ./internal/library ./internal/cli ./internal/gui: access, library ok.
  Reds, each the same at a clean origin/main c4bae0724 and filed:
  gateway TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117) and
  the doneHold panic log (#6505); cli TestHealthcheck…/TestUpdate…
  WithoutMagpieAddr, TestUpdateFindsAMagpieThatWroteNoRecord (#6471,
  #6223); gui TestSettingsSaveKeepsWhatItDoesNotSend (fixed by
  c4bae0724).
- GUI, both engines, every language, at this head: 64 files (every
  caller-keys / gateway-plugin file and i18n-*): 1008 of 1024 pass;
  api-key-theme (#6444) and connect-address-kept (#6755) fail the same
  at clean origin/main c4bae0724.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... ok; builds for all three OSes ok.
- Broken by hand: drop !hubFromPage -> the Sec-Fetch-Site case gets 200,
  red; drop the key's Memory check -> another key gets 200, red. Drop
  sharedWith -> still green: serveMCP's share guard refuses first, so
  memoryReaches' check is a second line, not the only one.

Not tried: a real remote agent against a real shared magpie (tests use
httptest with 192.0.2.7 as the remote address); the full suite runs
after the push.
2026-11-19 02:31:18 +08:00
yetone c4bae07248 gui: the keep guard sets ImageResolution, which only its own row sends
f6a538ece (v0.1.4490) added Settings > Images' Resolution. The server
keeps it when a save leaves it out, but TestSettingsSaveKeepsWhatItDoesNotSend
wants every field the Settings page doesn't send set in its fixture, and
was red: "ImageResolution: not sent by the Settings page". Found by the
post-ship full suite on mica at f6a538ece.

Run on mica: go test ./internal/gui -run
'TestSettingsSaveKeepsWhatItDoesNotSend|TestSettingsImageResolution'
ok. Broken by hand: dropping the keep in settingsapi.Merge turns it red
("ImageResolution:  after a save of the Settings page, was 4K").
2026-11-19 02:02:53 +08:00
yetone d01e0a465a agent: Dim's built-in Magpie provider is filled in, so a plain dima runs on magpie (T_t__biu on X)
T_t__biu on X: Dim alpha has a provider named Magpie built in, and
magpie's one-click connect left it empty, relying on DIM_* variables a
shell function set for each run. Dim launched any other way (its app, a
terminal opened before, an IDE) was not on magpie.

Dim keeps providers in a database only its daemon writes, so magpie now
talks to the daemon the way Dim's own clients do (JSON-RPC 2.0 after a
hello of protocol 4, on <home>/rust/daemon.sock, or on Windows through
Dim's pipe bridge `dimcode-server app-server --connect-pipe`; read from
Dim's crates/dim-app-server and dim-client source). Picking a magpie
model:
- writes the gateway's /v1 (the port magpie is on), magpie's key and
  enabled onto the `magpie` provider only, each against the record's
  version (provider.update);
- refreshes it, gives a model its token limits when the gateway doesn't
  know them (provider.models.edit), and makes it Dim's pick
  (provider.select against the pick's version);
- records first, in magpie's own dim.json (temp+rename), what was there
  and the pick to give back.
A key or address the user set on that entry themselves is kept: magpie
writes nothing to the provider and only picks the model. Sync writes the
port and key again when they change. Disconnect (`magpie dim default`
or the switch) turns the entry off with the key cleared (Dim clears a
key only on a provider turned off), puts the address back, and puts
back the model Dim was on. No other provider is read or written. The
per-run env and shell function stay only as the fallback when Dim's
daemon can't be reached or started.

Run at this commit's tree (on origin/main d048939da, then rebased over
3 commits that touch neither internal/agent nor the docs here):
- go test -run TestDim ./internal/agent on mica: 8 ok. Red on the old
  dim.go (with a stub for the new test helpers): FillsItsMagpieProvider
  (key empty), MagpieProviderPort, MagpieProviderUsersOwn/key (not
  picked), SyncMovesToProvider.
- Real Dim 0.1.0-alpha.24 (npm dimcode-alpha) in a sandbox HOME on
  mote, with a sandbox `magpie serve` on 38725 and a fake upstream:
  the user's own deepseek provider set and picked first. `magpie dim
  up/m1` left deepseek at v3 untouched, set magpie to on, 38725/v1, a
  key, and picked magpie/up/m1; a plain `dima exec -p` with no DIM_*
  set answered PONG-FROM-UPSTREAM through the gateway. `magpie dim
  default` turned magpie off, no key, 3425/v1, pick back to
  deepseek/fake/known. With a key and address set on the Magpie entry
  by hand first, connect wrote nothing to it (wrote:false) and only
  picked; disconnect gave the pick back and left the entry as set.
- Windows (xiaomi-gpu, real Dim alpha.24 in a sandbox DIMCODE_HOME):
  dimConnect through the pipe bridge did the hello and read the magpie
  provider and selection (a throwaway probe test, not committed).
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... on mote: clean.
- go test -tags nogui -count=1 -timeout 45m ./... on mote (suite.lock):
  every package ok (internal/agent 372 s) except 6 reds, each red the
  same on a clean origin/main d048939da copy and already filed:
  internal/cli TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr,
  TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr,
  TestUpdateFindsAMagpieThatWroteNoRecord (#6223); internal/gateway
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117),
  TestLaneLimitRoutes (#5150); internal/gui
  TestSettingsSaveKeepsWhatItDoesNotSend (#7127).

Not tried: a full connect/disconnect on Windows or Linux with a real
magpie serve (only the Windows pipe read); Dim's desktop app (the CLI
and daemon only); a UNC or symlinked DIMCODE_HOME on Windows.
2026-11-19 01:38:23 +08:00
yetone 1622484a86 update: a restart whose new version couldn't be started leaves this magpie running instead of quitting (ShipInSand on X)
restartInto logged a relaunch error that was not a system refusal and still returned true, so the caller quit with the new version installed and nothing started; the handover's fallback did the same. Both now keep this magpie up, say why in the version row (Error), and let a later restart through.

Run, on mote/mica (macOS), at origin/main de58a3879 plus this commit: TestRestartThatCouldNotStartStaysUp is red on the old update.go and handover.go ("restartToUpdate said to quit, though the new version didn't start") and green with the fix; the Restart and Handover tests in internal/gui ok; internal/update ok; gofmt -l clean; go vet for darwin, linux with -tags nogui and windows clean. Windows: internal/update Relaunch|Blocked|Install|Aside ok; the new test skips there (a failed start on Windows is always a BlockedError). Full internal/gui run at d048939da+fix: red only in TestLaneLimitRoutes (#5150), TestSettingsSaveKeepsWhatItDoesNotSend (#7127) and TestAppReplacesItsOlderGatewayOnceIdle's TempDir cleanup (#6297); the first two are red the same on origin/main de58a3879, the third passes alone on both. TestUpdateThatWontStart is red on Windows on main (#6059).

Not tried: a real failed relaunch on a real install; Linux gui tests (wsl-run lacks gtk); the Windows AwaitPredecessor/lock hypothesis (commented on #5922), which this does not change; no GUI .cjs tests (no GUI file touched).
2026-11-19 01:25:26 +08:00
yetone de58a3879b sessions: a cold read packs idle Claude sessions' calls into one file
shangyuan0818 on X: on Windows, Usage -> Sessions took 18 to 25 s with
long Claude Code sessions. The cause: a cold read wrote a calls-v15 .gob
shard and a .rev for every Claude session, about 21k files for 12k
sessions, and Windows Defender scans each file as it is closed.

Sessions not changed within the hour are now written into one
calls-v15/*.pack per pass (MPCALLS1 magic, the frames, a gob index of
path/offset/count, length, CRC32, magic). It is written to a temp file
and renamed, and flushed at the end of a pass, at checkpoints, in Saved
and every 32 MB. A session's own shard is read before the pack, so a
session that grows gets its own shard and its lines are appended there
as before. A bad pack means the source is read again. The hourly prune
sweeps packs no session points at. Working sessions keep a shard and a
.rev as before.

Measured on xiaomi-gpu (Windows 11, Defender on), fixture of 12,016
Claude session files, no magpie cache, first /api/sessions reply, the
runs alternating old and new:
  origin/main build: 31.67 s, 25.26 s, 20.74 s
  this change:        5.92 s,  5.85 s,  5.65 s
  restart with the pack written: 1.97 s and 2.16 s; then 0.25 to 0.31 s.
  The cache held 1 .pack and 4 .gob.

Tests (call_pack_test.go): TestColdSessionsReadWritesOnePack,
TestPackedCallsServeRequests, TestPackedSessionGrows. With the pack
branch turned off by hand the first fails (.gob:63 .rev:62) and the
second finds 0 packs.

Run at 4ace48feb (this change on origin/main 2ab2f6913):
- gofmt -l: clean.
- go test ./... -timeout 45m -count=1 on mote: 101 packages ok
  (internal/sessions 154 s), 3 red, none in code this touches, each
  filed: internal/cli TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr,
  TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr and
  TestUpdateFindsAMagpieThatWroteNoRecord (#6223: another session's ssh
  forward listened on mote's 127.0.0.1:3425); internal/gateway
  TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117) and
  TestLaneLimitRoutes (#5150); internal/gui
  TestAppReplacesItsOlderGatewayOnceIdle (#6297) and
  TestSettingsSaveKeepsWhatItDoesNotSend (#7127, red since f6a538ece).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go
  build: clean.
- internal/gui/tests/sessions-*.test.cjs (46 files): 322 of 322 in
  chromium, 322 of 322 in webkit.
- wsl-run go test ./internal/sessions: ok (25.3 s), at the base before
  the rebase.
- win-run go test ./internal/sessions: 4 reds, the same on origin/main
  07d19510f and filed as #6071 (TestAgySessions, TestAgyRowOnly,
  TestAntigravityAppFolder, TestCCListingKeepsItsNames). go vet clean.

Rebased onto fcbc1a2d0 (three gateway commits, none in
internal/sessions or its doc). At the pushed head: go test
./internal/sessions ok (209 s); go vet of it on darwin, linux (nogui)
and windows clean; go build clean.

Not tried: a real user's profile; the timings use a generated fixture
the size of the report.
2026-11-19 01:22:40 +08:00
yetone fcbc1a2d02 gateway: Claude Code's deferred tools are declared in full where a load would lose the cache
Seapawn1 on X: GPT in Claude Code loses its prompt cache with tool search
on. A tool ToolSearch loads joined the top-level tools on the next request
on every route but Anthropic's and a Responses upstream that loads in
place (LoadedInPlace, #2660). An OpenAI-style cache is a prefix with the
tools before the messages, so each load (2.1.327 defers WebFetch,
WebSearch, Monitor and the other built-ins too) read the whole
conversation again uncached. A sandboxed Claude Code 2.1.327 through a
fake upstream showed it: on Chat and on a Responses relay the tools
changed at req1 and req3; in place they held.

On such a route a Claude Code request carrying DeferredToolPlaceholder is
answered 400 invalid_request_error naming tools.defer_loading, locally.
The real Claude Code 2.1.327 answers that (after its beta-strip retries,
3 refused requests) by declaring every tool in full for the rest of that
conversation, --continue included; a new conversation, on a Claude model,
tries tool search again. The message doesn't name the beta header, which
Claude Code would remember everywhere. Only while the reminder names 50
deferred tools or fewer: an MCP router's hundreds keep tool search, and a
request whose reminder can't be read keeps it too. Anthropic routes and
in-place Responses upstreams are unchanged. The refusal is not a member's
fault (retryable/shapeRefused false), so a group doesn't fall over or
rest.

Not handled: a user who set ENABLE_TOOL_SEARCH themselves can't be told
apart on the wire; additional-tools=on keeps search on a relay that takes
the item.

Run:
- mica: go test -run 'TestDeferred|TestLoadedTools|TestKimiIsSent|TestToolSearch|TestDeferredToolBlocks' ./internal/gateway ok.
- Broken by hand (the check in translate made false): TestDeferredToolsTurnedAwayWhereTheyLoseTheCache and TestDeferredToolsKeptWhereLoadedInPlace red (status 200, upstream called).
- mica: GOOS=linux and GOOS=windows go vet ./internal/gateway ./internal/agent ok; gofmt -l clean.
- wsl-run (magpie-desktop): go test -timeout 45m ./internal/gateway ./internal/agent started before push; result with the full suite.
- Real Claude Code 2.1.327 in a sandbox HOME against a fake 400 naming defer_loading: retried with every tool declared, kept for the conversation and --continue, new conversation searched again.

Full suite: run after push.
2026-11-19 01:13:33 +08:00
yetone d048939daa gateway test: a turn on Codex's own sign-in counts its hold in Send and Wait together
TestCodexOwnSignInTellsWhereItsTimeWent went red in a full run at
3438b7bd9 on the magpie-desktop WSL box (Linux, busy):
  timing {... Send:4 Wait:196.9 Head:202.1} for a 200ms hold
The fake backend starts its hold once it has read the body, and that can
come before the client's WroteRequest fires, so up to Send of the hold is
counted in Send, not Wait. The test now wants Send+Wait to cover the hold
and Wait at least half of it (the vendor's wait is still where the time
goes), and Head past Wait, as before. Test only; nettrace is unchanged.

Run (wsl-run, magpie-desktop): go test -count=30 -run
'TestCodexOwnSignInTellsWhereItsTimeWent$' ./internal/gateway ok.
Broken by hand: Wait divided by 4 in nettrace.go: red ("Wait:50.375 ...
for a 200ms hold").

Not tried: injecting the WroteRequest delay itself; the cause is read
from nettrace.go (Send = gotConn to wrote, Wait = wrote to first byte).
2026-11-19 01:02:38 +08:00
yetone 91e8146727 gateway: words written after a call go before it, so DeepSeek takes the call as answered
wizcheu on X (Claude Code 2.1.327, deepseek-flash at max effort on
DeepSeek's own API) still saw "400 due to tool use concurrency issues"
after v0.1.4478: "DeepSeek: messages.422.2: `tool_use` ids were found
without `tool_result` blocks immediately after:
call_00_wIys8uRO8314ixexw3r35173", and earlier messages.71.2.

The block index is the clue. Checked against api.deepseek.com/anthropic
today: an assistant message with a text block after a tool_use is
refused with messages.N.K, K the text block, even when the next message
answers the call ([T, tu, X] -> messages.1.2; [X, tu, T, X] ->
messages.1.3; [tu, X, tu] -> .2; an empty text after the call too),
while [T, tu, T, tu] and [T, X, tu] pass. A system message between a
call and its result (d74754970) gives messages.N with no block index,
so the reported .2 was this other shape all along.

toolBlocksPaired (passthrough and count_tokens) now moves the blocks an
assistant message wrote after its first call to before that call
(callsLast), thinking kept where it was and empty text dropped; a
message without that shape keeps its bytes. pairToolBlocks does the same
for a translated build (blocksCallsLast): a Responses turn's message
item after its function_call. Applied for every Messages upstream:
Claude writes no words after a call, and the order of the words relative
to the call is the only thing that changes.

Run (mote, at this tree on origin/main 2ab2f6913):
- go test ./internal/gateway -run 'TestWordsAfterACallGoBeforeIt|
  TestCallsLast|TestSystemMessage|TestChatSystemMessage|Pair' ok;
  -run 'Tool|Pair|Anthropic|Steer|Thinking|Messages' ok (91s)
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of the package
  ok; gofmt -l clean
Broken by hand: with both source files at origin/main, all four
TestWordsAfterACallGoBeforeIt cases are red with the reporter's message
(messages.1.2 / 1.3) and TestCallsLast red; with only pairToolBlocks'
reorder taken out, TestCallsLast is red on the built message.
Live: api.deepseek.com/anthropic, deepseek-flash: the old shapes 400,
the mended ones ([T, X, tu], [X, X, tu, T]) 200.
Not tried: wizcheu's own conversation (the trailing text's source isn't
confirmed; four live max-effort replies gave [thinking, tool_use] only),
the full suite (to follow), a Claude relay with [tu, X] (the openrouter,
yylx and aihubmix keys have no balance).
2026-11-19 00:57:11 +08:00
yetone 2ab2f69132 agent: Codex's status line shows the account's quota or the relay's balance (opt-in)
lyj1115 on X asked for the current account's quota, or the relay key's
balance, under Codex's chat box, off by default. Codex's TUI draws its
footer from a status line provider from 0.171.0-alpha.12 on: a stdio
MCP server whose tool advertises a statusline entrypoint, picked in
[tui] status_line_provider behind [features] tui_extensions_statusline.
Codex reads it about once a second with the thread's id. Nothing is put
into the prompt or the model's reply.

- `magpie statusline --codex` is that server. Each read asks the local
  gateway for the thread's latest route and the kept quotas (no vendor
  read). It answers `→ provider/model` and that provider's account that
  answered last, with its windows or a key's balance. A gateway that is
  down gives a null tree, never an error, because an error stops Codex's
  reads. The tool's name and words name neither magpie nor a vendor,
  since the tool is listed to the model.
- A status line square on Codex's row (`magpie codex statusline on`)
  writes the flag, [mcp_servers.quota_line] (this magpie by full path,
  args statusline --codex, env_vars = ["MAGPIE_ADDR"]) and the
  provider. Every write is read back, and the file is restored on a
  mismatch. Off and Disconnect take out only magpie's keys, and the flag
  only when the stash says magpie wrote it.
- Nothing of the user's is written over. A provider of their own, a
  quota_line of theirs, the flag turned off or an unreadable file keeps
  the square away and refuses on.
- The switch is offered only when a Codex CLI here is 0.171.0-alpha.12
  or newer (0.170.0 reads the keys and draws nothing), and only on this
  computer, not in a WSL distro.
- In the GUI, the status line square's title takes the note of its
  field's on option, which Claude Code's field already sent with the
  same words TOGGLES kept, so Codex's says its own words in en, zh,
  zh-TW, ja and de. TOGGLES' copy of Claude's note went, and app.js
  stays under its budget (30 bytes of room) without a raise.

The Codex desktop app has no such footer. cockpit-tools reaches it
through a debug port, and magpie doesn't.

Run (WSL magpie-desktop, since mote's load was over 18):
- go vet -tags nogui ./...; GOOS=windows go vet of agent, cli, provider
  and gui; gofmt -l clean.
- go test -tags nogui of ./internal/cli and ./internal/provider: ok.
- ./internal/agent -run "CodexStatus|Statusline|StatusLine|TestCodex|
  TestWSLCodex": ok.
- ./internal/gui -run "CoreScript|Budget|I18n|Keys" and node --test of
  codex-statusline, claude-statusline and i18n-keys (both engines, every
  language, window and panel), with vet (and GOOS=linux and windows
  vet) of agent, cli, provider and gui, on mote at the rebased head
  (on 1bd1a08a3): all ok, 64 of 64 GUI cases.

Broken by hand:
- free() reduced to `readable`: TestCodexStatusLineLeavesTheUsers is red
  on their provider, their server and flag off.
- The field not appended: TestCodexStatusLineSwitch is red ("no
  statusline field").
- The first build checked `at.base == nil` after codexIn had set base.
  Every agent test went red, which is how that bug was found.

Real Codex, in a sandbox HOME on WSL with a fake gateway:
- 0.171.0-alpha.13, with `magpie codex statusline on` writing config.toml,
  draws `→ relay/glm-5  relay $4.20` under the prompt, and the server is
  read about once a second.
- Without env_vars, Codex starts the server without MAGPIE_ADDR: nothing
  was asked and nothing was drawn. That is why env_vars is written.
- On a second time leaves the file byte for byte. Off brings it back to
  what it was, apart from Codex's own NUX counter.
- 0.170.0 lists quota_line from the same file and runs fine.

Not tried: macOS and Windows Codex; a real gateway with real accounts
(the server was fed through MAGPIE_ADDR); whether an open Codex session
picks the footer up without a restart.

Full suite: run after push.
2026-11-19 00:44:40 +08:00
yetone 1bd1a08a3a mcpauth: a server never reached says it is the network, and is asked twice (CHENGJIAHEGOXIS on X)
CHENGJIAHEGOXIS on X clicked Sign in on the Library's Notion server
(https://mcp.notion.com/mcp) and got "couldn't reach mcp.notion.com: Post
"https://mcp.notion.com/mcp": EOF", then asked whether the server supports
sign-in at all. It does (Notion answers 401 with OAuth metadata, checked
with curl from here); the first request's connection was cut on their
side of the network.

- discover asks the initialize probe once more when it gets no answer:
  Go never sends a POST again by itself, so a kept-alive connection that
  a proxy or the server closed reads EOF and failed the sign-in.
- The failure is mcpauth.UnreachableError, with the host and the proxy
  the request went through (redacted) or none. api.go says it with an
  i18n key (unreachableSaid): the network, not the server's sign-in, with
  the way it went and what to do, Go's words kept in brackets. zh,
  zh-TW, ja, de.

Run at this head's tree on mica (mote at load 33):
- go test ./internal/mcpauth/ ./internal/gui/ ./internal/library/: ok
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  internal/mcpauth and internal/gui: ok
- GUI: mcp-*.test.cjs, i18n-*.test.cjs, signin-browser-down: 328/328,
  Chromium and WebKit; mcp-signin gains the direct and proxy cases in en
  and zh.
Broken by hand: without the second ask, TestSignInAsksAgainAfterACut
Connection and TestSignInUnreachableSaysTheWay/direct go red, the first
with exactly the reporter's message.
Rebased on f6a538ece (also i18n.js): go test -run Budget|I18n
./internal/gui/ and i18n-keys, mcp-signin, image-resolution GUI
(32/32) run again at this head on mica: ok.
Not tried: a real cut connection to mcp.notion.com from the reporter's
network; the full Go and GUI suites.
2026-11-19 00:32:47 +08:00