Commit Graph
1896 Commits
Author SHA1 Message Date
yetone 2c2bd15d71 memory: Tidy up every night, a switch in the Memory tab
The Memory tab gets a second row under Learn from conversations. It is
off by default. Switched on, the first tidy is due at the next 03:00.
Tidy now runs one at once, and Undo puts the last one back. While
distillation is off, the row has its own model picker; both rows share
one model.
Routes: POST /api/memory/dream {on}, /dream/run and /dream/undo.
GET /api/memory/distill carries "dreaming", so a tidy no longer shows
as conversations being read.

The prompt's stale rule is narrower. On the first real run it set aside
two decisions because "the work is done". Now only a note that later
notes contradict, one past its date, or one about a finished one-off
task is stale; a decision, direction or preference stays.
docs/subsystems/memory.md gets a Dreaming section.

Real run: a sandbox memory.json of 62 real distilled memories, 12 active
and one each user-written and pinned, with auto/claude-haiku-5-5 through
the live gateway.
- Before the prompt change: 12 changes in 48s, 10 merges and 2 set aside.
  Both set-aside notes were decisions.
- After: 12 merges in 46s, none set aside. Each merge joins real
  duplicates (three ~/.codex/sessions cleanup rules into one, the
  TestFlight 1.66/1.68 pair). One went into the fixed memory, whose text
  was kept word for word.
- Undo: 25 restored. memory.json's ids and statuses equal the backup
  taken before the run, and every merged memory is gone.

Broken by hand, each red:
- Undo not reloading the list: library-memory 22 failed.
- Ignoring DreamSince: TestDreamsOnceANight.
- A plan applied after an error: TestDreamFailureChangesNothing.
- Tidy's fixed guard and Untidy's status check: their memory tests.

Run on mote at this tree:
- go test internal/memory, memdistill, library: ok.
- internal/gui -run 'Distill|Dream|I18n|Budget': ok.
- library-memory.test.cjs: 22/22 in both engines.
- i18n-keys and i18n-en-no-cjk: 4/4 each.
- go vet (darwin), GOOS=linux -tags nogui, GOOS=windows: ok.
Not run yet: the full suite at this head.
2026-11-10 03:25:45 +08:00
yetone 3445d8384e memdistill: a proposal stands on words the user wrote
A real run (Haiku through the live gateway, 10 of this Mac's Claude Code
conversations, magpie's config/cache/state in a sandbox, HOME real)
proposed 38 candidates. The ones without a quote were the assistant's
own standing instructions said back (run heavy commands on mote, no
git add -A, ask before deleting), not anything the user said. Now the
prompt asks for the user's words copied exactly and leaves out what
only the assistant said, and keep drops a proposal whose quote is
missing or isn't in the user's text (letters and digits compared,
case aside).

Same 10 conversations again: 24 candidates, every one quoting the
user, none of the echoes.

Run (mote): go test ./internal/memdistill: ok. Broken by hand: the
check off, TestReadsQuietSessionsOnce red (Added 5, want 3).
2026-11-10 03:25:45 +08:00
yetone 4d12d44163 memory: Learn from conversations, a switch in the Memory tab
The Memory tab gets a row that reads finished conversations into
candidate memories (To review). It is off until switched on; switched
on it reads at once, then hourly (5 minutes after start, then every
hour), through the gateway this process serves under the agent
"memory", with the automatic model unless one is picked through the
app's menu. Read now runs it again; a run that stopped says why.

- memdistill: Keep (the hourly loop) and Running.
- gui: /api/memory/distill (GET, POST {on, model}), /distill/run;
  distillComplete posts /v1/messages to the served gateway's handler
  with the memory agent's token.
- library client: the row, its poll while a run goes, and the
  memories reloaded when it ends; strings in zh, zh-TW, ja, de.
- docs/subsystems/memory.md: a Distillation section.

Run (mote, at this tree):
- go vet ./internal/gui ./internal/memdistill ./internal/memory; GOOS=linux
  -tags nogui and GOOS=windows vet of gui and memdistill: clean.
- go test ./internal/gui ./internal/memdistill ./internal/memory
  ./internal/library: ok.
- node --test internal/gui/tests/library-memory.test.cjs: 22/22, Chromium
  and WebKit, 5 languages, 980 and 420.

Broken by hand:
- the memories not reloaded after a run: the GUI test is red waiting
  for the proposed memory.
- the token not the memory agent's (earlier): TestDistillCompleteThroughGateway
  red on the Trace's agent.

Not tried yet: a real model's run (next), the whole GUI suite (queued
behind the suite lock on mote), the full Go suite.
2026-11-10 03:25:45 +08:00
yetone 2b2ee49ded gui: the Library's Memory tab
A tab after Instructions lists what the agents remember, in use, to
review (what an agent only guessed) and archived, pinned first then
newest; searches it, narrows it by where it applies, and adds, edits,
pins, keeps, archives and deletes memories (Delete asks with a second
click). Kind and scope are picked from the app's menu, never a <select>.
A card on top switches the digest in the ticked agents' instructions on
or off and names those agents, and offers Magpie Memory while it isn't
in the Library.

/api/memory (GET; POST saves the user's own or edits by id),
/api/memory/remove and /api/memory/digest; a change publishes the digest
at once and its reply carries `problem` when that failed.

Words other code also says (Archived, Pin, Keep, the kinds…) are in core
i18n.js; the rest in the library plugin's, in zh, zh-TW, ja and de.
docs/subsystems/memory.md describes the layer.

Run (mote-run):
- node --test internal/gui/tests/library-memory.test.cjs, Chromium and
  WebKit, 5 languages, 980 and 420 wide: ok
- whole GUI suite: not run at this commit; it is queued on mote for the stack head (034f249af before the rebase)
- go vet ./internal/gui, GOOS darwin, linux, windows: ok
Broken by hand: the pinned sort read `b.pinned - a.pinned` (NaN for an
unpinned one) and the test was red in every language until `!!`.
Looked at: screenshots en light 980, zh dark 980, en 420.
2026-11-10 03:25:44 +08:00
yetone ab3710de3a hooks: onSignIn tells a request hook of an account to sign in again
shannnnnks on X: with several Codex accounts behind the gateway, one is
now and then signed out, and they want the notify plugin to push it.

The magpie that serves the gateway now looks every 2 minutes (first
after 1) at the same sign-in states the desktop alert reads
(provider.WatchSignIns' checkSignIns, so every provider: Claude, Copilot
and plugin accounts that lapsed, and built-ins whose mark says the
sign-in expired or must be done again, Codex's revoked and refused
refreshes among them; accounts in use only). Each account to sign in
again, and each Claude sign-in ending within days, goes to every hooks
file that exports onSignIn, once until the account works again, kept in
signin-hooks.json beside the desktop alert's own file. The event is
{provider, providerName, account, state: "signed-out"|"ending", endsAt?}:
the account is its display label; no token and no vendor reason text.
It is fire-and-forget in the Bun host (gatewayRequest operation
"signIn"), each hook under its own timeout, one that throws doesn't stop
the next. With no hooks file nothing is looked at or marked. A hooks
file may now export onSignIn alone, without onRequest.

Docs: gateway-request-hooks.md (Sign-in notification),
providers-accounts.md, site plugins.html en/zh/ja.

Run on mote at d939dd699 (on origin/main 835439ebf; then rebased on
3d49ac069, whose three commits touch only GUI assets, GUI tests and site):
- gofmt -l internal: clean. go vet of internal/plugin, gateway and
  provider for darwin, linux and windows: ok.
- go test -count=1 ./internal/plugin ./internal/gateway: ok (123s, 950s).
- ./internal/provider: crashed in TestCodexAppWorkspaceSwitchReadsEachWorkspace
  (concurrent map writes in its fake server, #5800, not this change);
  run again with -skip WorkspaceSwitch: ok (130s).
- Red on the old code: with origin/main's host.js both new tests fail
  (TestGatewaySignInHook: "magpie.hooks exports no onRequest";
  TestRevokedAccountToldToHooksOnce: the hook never heard of it).
- Broken by hand: without the HasGateway gate, the gateway test fails
  with "told with no hook".

Not run: the full ./... suite (queued behind ~10 suites on mote's
suite.lock). Not tried: the real app with a real revoked Codex account;
the GUI suite (no GUI file changed).
2026-11-10 01:44:24 +08:00
yetone 803d7747e7 gateway: an account rate limited till a time its vendor named is not asked again before it (hsjzg58958 on X)
hsjzg58958 on X: a vendor limited an account for 300 seconds, and magpie
asked it again about every half a second as the agent retried, until the
vendor flagged two accounts.

Cause: a candidate resting on a 429 was still "tried all the same" when
it was the last one left (restLast/probeOne), and the last one left was
never rested at all, so every client retry went upstream. Codex on its
own sign-in is relayed by codexUpstreamOn outside the candidate loop and
had no hold at all.

Fix:
- timedHeld/vendorTimed (fallback.go): when every candidate left rests on
  a 429 whose time the vendor named (Retry-After, anthropic-ratelimit-*-
  reset, x-ratelimit-reset-*, resets_in_seconds/resets_at), none is asked;
  the agent gets 429 with Retry-After = when the first is back. A ChatGPT
  account out of its allowance is answered as the backend's
  usage_limit_reached with its x-codex-* windows (Rest.out/outHeader).
- The last one left now rests too on such a 429 (vendorSaidWhen); a 429
  naming no time rests nobody, as before.
- codexHolds (codex_held.go): Codex's own relayed sign-in is held till the
  vendor's time; its retries are answered locally with the stored body,
  x-codex-* headers and Retry-After. Lifted by restarted() for quota holds.
- Not held: LimitRestOff accounts (the user's setting), auto-reset weeks,
  rests "there" (answered by the vendor's own hold), Codex's API key.

Run:
- New TestRateLimitedKeysHeldUntilTheirReset (4 signals x 1 and 2 keys)
  and TestRateLimitedCodexAccountsHeldUntilTheirReset (3 refusals x 1 and
  2 accounts): red at fc9ce34d8 (each key/account asked on every retry),
  green after.
- Broken by hand: held branch off -> every case red (4 extra hits);
  last-one rest off -> 1-key cases red, Retry-After lost; codexHeld off ->
  1-account Codex cases red.
- mote: go test ./internal/gateway -run 'TestRateLimited|TestAllResting|
  TestQuotaHeld|TestGroupSpent|TestCodex|TestRetryAfter|TestHeldLimit'
  ok; TestCodexLeavingModelCompactsLocally updated (the used-up account is
  now asked once, then held) and ok.
- gofmt -l clean; go vet, GOOS=linux -tags nogui and GOOS=windows go vet
  and build ok.
- mote, whole internal/gateway package at the rebased head 46199a6ae
  (on 80161247a): ok but for TestStrictAffinityPassesTheErrorOn, which
  asserted the bug itself ("resting now, it is still the one asked"). A
  strict conversation's account resting till ChatGPT's named reset now
  gets its own usage-limit 429 from the rest, with nobody asked; updated,
  and with TestRateLimited|TestCodexLeavingModel|TestCodexEveryAccountOut
  ok at this head.
- The full ./... suite was queued behind six other sessions' suites on
  mote's lock and not run before the push; queued again at this head.

Not tried: a real vendor account limited live (no account was rate
limited to test on); Codex API-key relay is not held (OpenAI's platform
headers are Codex's own to read); plugin providers are held only through
the shared candidate loop; a held Codex passthrough body's
resets_in_seconds is stale by the time elapsed (Retry-After is exact).
2026-11-10 00:58:01 +08:00
yetone c6331b427c routing: a group bound to gateway keys is theirs alone (Xerxes754)
Xerxes754 on X asked to bind a routing group to one or two gateway
keys, so other keys neither see nor use it. Before this a key could only
be held to models from its own side (naming group/<id> in its Models);
a key with no limits reached every group, and nothing on a group could
keep it from one.

A group now has Keys (key ids). Set, only those keys, and keys issued
under one of them, may use it:
- groupBarred/groupGiven in key_models.go answer it for every route that
  reaches a group: chat, responses, messages, count_tokens, embeddings,
  images, video, the decider and the subagent and image MCP paths. Any
  other key gets 403 "bound to other gateway keys", naming the group and
  the Routing page, and nothing goes upstream.
- /v1/models and /v1/models/{id} leave it out for any other key, a key
  held to models that names it included. provider.GroupsBound keeps an
  unbound magpie's list as before.
- A keyless request from this computer uses it, as key limits never
  hold one; callerGuard now names a loopback request's key when it
  sends one, so a key used locally is held too.
- SaveGroup keeps the stored keys when a save doesn't name them (the
  CLI, the TUI, the card toggles); an empty list clears them. Ids are
  trimmed, deduped and capped. Sharing a group leaves its keys out;
  importing over one keeps them.
- GUI: Routing, a group's Edit, row "Gateway keys" (网关密钥) with a
  button "Any gateway key" (任意网关密钥) that opens the app menu of the
  user's keys (multi-pick); a bound key since deleted shows "key
  deleted" (密钥已删除). The row shows once there is a key to bind.
  /api/groups lists gatewayKeys (no browser, read-only or issued keys).
  zh, zh-TW, ja, de strings.
- Not covered: a bound group nested in another group is reached through
  the outer one (documented in gateway-routing.md).

Run (mote unless said), at this head rebased on ac4af5823:
- gofmt -l clean; go vet darwin for provider, gateway, gui; GOOS=windows
  go vet for those and access; GOOS=linux go vet -tags nogui; go build.
- go test ./internal/gateway (full package, 905s), ./internal/gui,
  ./internal/access, ./internal/provider: ok. One provider run died on
  workspaceSwitchReadsApart's concurrent map writes in its fake server,
  #5800 already open; the rerun was ok.
- New: TestGroupBoundToKeysIsTheirsAlone, TestGroupKeysKeptBySaves-
  ThatDontNameThem, TestGroupKeysListedAndSaved, and group-keys.test.cjs
  (5 languages x 2 widths x chromium + webkit, deleted key, hidden row).
- GUI on mote: group-keys, i18n*, rt-*, *routing*, *group*, *budget*
  files in both engines: ok. That run found a new group's editor
  throwing on its missing keys (group-editor-align red); the draft now
  gets keys like accounts. group-editor-fits was flaky on origin/main
  too and is fixed in the next commit.
- Whole GUI suite on the Linux box (wsl-run, concurrency 4): still
  running at push; its reds so far are in account-eye,
  accounts-own-signin and accounts-switch-alone (webkit), files this
  change doesn't reach.
- Real binary, sandbox HOME on mote, fake upstream, group bound in
  providers.json: key A lists and uses group/team; key B doesn't list
  it, gets 403 on chat (group/team and "team"), messages, count_tokens
  and responses, 404 on /v1/models/group/team, and still uses fake/m1;
  keyless local lists and uses it; upstream got 3 calls.

Broken by hand, each turned its Go test red: the issuer chain not
walked; an unheld key let through (groupGiven true); a held key's
groupAllowed ignoring the binding; SaveGroup not keeping nil keys.

Not tried: binding from the real app's window end to end (the e2e
bound by file), Windows and Linux runs of the Go tests; the CLI and TUI
can't set keys (they keep them).
2026-11-10 00:13:44 +08:00
yetone fdd38154b8 docs: the Usage, Video generation and sign-in links to their settings
gui-shell.md, gateway-routing.md and providers-accounts.md name the
links 22c665d6f, cedacf1ae and 3b550a99c added: the Usage page's
Allowances head to Settings › Allowances, Video generation's how-to
to the Providers page, and a sign-in kept to its link to Privacy's
Sign-in pages row. Library's limit tag (8607a7a02) has no passage in
library.md to change.

Docs only; nothing run.
2026-11-10 00:02:22 +08:00
yetone 623e797fde plugin pages: read a day's usage and share a picture they drew
A plugin's page can now read one day's usage and share an image it
drew. This is for the day card (JungleyYeh on X asked for a "daily AI
statement"); the card itself is an optional community plugin,
@magpie-community/page-day-card.

- A page that asks for the "usage:day" read gets that day as
  magpie.read("usage:day", {date, tz}): totals, each agent and its
  models, the streak and the average active day (usageapi/day.go,
  gui/pageday.go). The Plugins page names the read before it is granted.
- magpie.image.copy(png) and magpie.image.save(png, name) share a PNG
  of at most 16 MB. In the window they go through
  POST /api/plugin-pages/image (pageimage.go): copy puts the picture on
  the clipboard (clipimage.go: osascript PNGf on macOS, PowerShell
  PNG + Bitmap on Windows, wl-copy or xclip on Linux), and save writes
  it to Downloads under a name made safe. In magpie web, the browser
  saves or copies the picture itself.
- The window's side, pageshare.js, is imported the first time a page
  shares a picture. The core grows by its one call only, paid for by
  comments cut, so the budget is not raised.

Tests:
- New: TestDayOf, TestPluginPageReadsADay, TestPluginPageSharesAPicture,
  TestPageImageName and TestClipImageCommand. plugin-page.test.cjs
  covers the bridge, both engines and a refused SVG.

What was run (mote):
- gofmt, plus go vet on darwin, linux and windows: clean.
- Full go test ./... at the pre-rebase base: 369 packages ok, 3 FAILs.
  - TestEveryRouteHasACommandOrIsNamed and TestCoreScriptBudget were
    this change's own reds. The new route now has a parity entry, and
    the share code moved into lazy pageshare.js with no raise.
  - TestGatewayModeStatsNameTheGatewaySessions is #5690, the red in the
    first hour of the day (it ran at 00:32).
- GUI suite (affected and plugin files, both engines): 1160 of 1179
  passed. Every red is filed and none touches this change:
  - i18n-keys "a plugin's words are its own": #5332, #5426, #5482.
  - page-width-steady: #5013.
  - plugin-card-update in WebKit: #3079.
  - plugin-move-unserved "Try again": #4410.
- At this head, after the rebase on bc8b01d60:
  - gofmt clean; go vet ./internal/... on darwin, linux (nogui) and
    windows ok.
  - internal/usageapi, internal/plugin and internal/cli ok.
  - internal/gui: TestCoreScriptBudget, the TestPluginPage* tests and
    the TestPageImage/TestClipImage tests pass.
  - plugin-page and old-webkit (both engines): 12 of 12.

Real use:
- A sandbox HOME with a copy of real usage, through the real GUI
  server, in Chromium and WebKit, light and dark, en/zh/zh-TW/ja/de, at
  420 and 1100 px. The card showed 87.9M tokens, $9.85 and 4076 calls
  with a 22-day streak.
- Picking an earlier day and WebKit's Copy ("Copied") worked, with no
  page errors.
- Not tried at push: Chromium's Copy (its headless clipboard was
  denied) and magpie web's Save as a captured download. A second real
  run that grants both was still queued on mote's suite lock.
- Clipboard: checked live on macOS (osascript) and Windows
  (PowerShell). Not tried live on Linux: WSLg had no display.
2026-11-09 23:19:14 +08:00
yetone bc8b01d603 claude: the short system prompt is set in the Claude Code editor, not Settings › Replies
The scattered settings audit after netube99 on X. Short Claude system
prompt and Claude Code's interactive mode changed only Claude
subscription runs, yet sat in Settings › Models › Replies, while the
Claude Code editor already had its own "Claude Code runs as" switch for
the second, whose card said "Switched here or in Settings › Models ›
Replies".

Both rows now go in a claudeRunList in the Claude editor (PROV_PREFS), so
Settings' search still finds them and Open goes to the editor. In the app
the editor's own "runs as" switch is the one shown, and the duplicate
interactive mode row is hidden by CSS; in magpie web as a gateway, where
that switch is disabled, the row shows (the list gets a gw class from
renderReplies: body.gateway-mode is set only on a change, not at boot).
provPrefsField lets Claude's run list through in gateway mode, without
the warm-ups, which are this computer's. The card and the "off" reason
no longer name Settings (zh, zh-TW, ja, de written with them), and the
bridge's subsystem page names the editor.

Run (mote, mote-run, origin/main ddd6c649b as BASE_REF):
- claude-lean-prompt-setting, claude-tui-setting, claude-mode,
  provider-prefs, settings-places, i18n-keys, bare-ids and mobile-web,
  both engines: 170 of 170.
- go test -run 'Budget|I18n|Strings' ./internal/gui: ok.

Broken by hand (chromium):
- both rows back in Replies: claude-lean-prompt-setting and
  provider-prefs 18 of 18 red;
- the editor's duplicate row not hidden: claude-tui-setting 8 of 8 red;
- no gw class in gateway mode: claude-tui-setting 8 of 8 red.

Not tried: the real app with a real Claude subscription.
2026-11-09 23:14:57 +08:00
yetone 92e8edd7fc windows: magpie is listed in Installed apps, and its Uninstall puts every agent back
Jevik_AI on X uninstalled magpie and rebooted, and Codex's config.toml
still had openai_base_url = "http://127.0.0.1:3425/backend-api/codex";
Rk1ngggg asked whether an update cleans it. magpie's own uninstall
(Settings › About › Uninstall magpie, `magpie uninstall`) already
disconnects every agent and takes Codex's leftovers (#3866), but on
Windows magpie wasn't in Settings › Apps › Installed apps, so it was
removed the way Windows offers for a program it doesn't list: by
deleting the exe and folders, which runs no code.

shortcut.Ensure now writes
HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\magpie
(DisplayName, DisplayIcon, Publisher, InstallLocation, UninstallString,
URLInfoAbout, NoModify, NoRepair) at every installed start, beside App
Paths, and Remove (uninstall's System step) takes it out the same way:
only while it names this exe, or an exe that is gone. Its Uninstall
runs `magpie.exe uninstall --window` (shortcut.UninstallArgs). magpie.exe
has no console, where the terminal's `magpie uninstall` would refuse
for want of one to ask on, so those exact args open the app's window
(or forward to the running app, OnSecondInstanceLaunch) on Settings ›
About with Uninstall magpie's question asked (uninstallView,
?uninstall=1). It asks once: a redraw of Settings doesn't ask again,
and Cancel removes nothing. magpie web opened at that link asks
nothing. Deleting the app by hand still runs no code (macOS
drag-to-Trash included); agent-wiring.md says so.

Run on mote at the pushed head (rebased onto be9dbce02):
- 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/gui ./internal/cli ./internal/shortcut
  ./internal/uninstall: ok (TestCoreScriptBudget included).
- uninstall-settings.test.cjs and i18n-keys.test.cjs: 40 of 40
  (chromium and webkit; the new Installed-apps cases in en and zh at
  1100 and 420).
At d3f40bedd, the same change on c7ebb6f8d, under suite.lock:
- go test -tags nogui -timeout 45m ./...: ok, every package.
- The whole GUI suite (--test-concurrency=4): 22518 of 22800; the 282
  reds are in 53 files the change doesn't reach (model-chip-steady 40,
  usage-agents-hide 22, zero-priced-free 20, provider-fetch-again 14,
  ...), the full-suite reds of #5475; the numbers are on that issue.
  Their run at c7ebb6f8d alone is queued behind other sessions' suites.
- The first full run found the core scripts 147 bytes over
  TestCoreScriptBudget; the page's part was cut to one line (the
  budget is not raised).
On xiaomi-gpu (win-run): go test ./internal/shortcut, incl.
TestInstalledAppsEntry on the real HKCU registry under a test key: ok.

Broken by hand, each red:
- registerAppPath not calling registerUninstall: TestInstalledAppsEntry
  (UninstallString = "") on Windows.
- main.go not taking UninstallArgs to the window:
  TestInstalledAppsUninstallOpensTheWindow (unknown "--window").
- app.js not asking on ?uninstall=1: 4 of 4 Installed-apps GUI cases.
- app.js asking without its once guard (params.delete): the same 4
  ("asked again").

Not tried: a real Settings › Apps › Uninstall click on Windows with an
installed magpie (the test box's install belongs to other sessions); the
second-instance forward (OnSecondInstanceLaunch) has no test of its own.
2026-11-09 22:33:31 +08:00
yetone 39569d5604 claude desktop: an optional Claude Magpie app beside your own Claude (#5671)
baranwang on X asked to keep Claude Desktop's own (1P, Anthropic) sign-in
while using magpie. Turning on "Separate app" in Claude Desktop's row on
the Agents page (or `magpie claude-desktop launcher add`) moves magpie's
3P wiring into ~/Library/Application Support/Claude-Magpie-3p and adds
~/Applications/Claude Magpie.app. That launcher opens Claude.app with
--user-data-dir on that folder, so it runs side by side with the user's
own Claude.app. Its icon is Claude's icon with a magpie badge. Off is the
default, and turning it off (`launcher remove`) moves the wiring back
and removes the app. It is macOS only: Desktop's packaged app strips
CLAUDE_USER_DATA_DIR, and on Windows it hardcodes LOCALAPPDATA\Claude-3p.
The folder ends in -3p because Desktop adds -3p to any other name.
Restarting the isolated app ends only its own process (pkill on its
--user-data-dir) and opens the launcher again.

Run at 1b25cda26 (this change on origin/main be9dbce02); rebased onto
fdabddeb4 (catalog only), then go build ./..., vet and the budget and
launcher tests again: ok. All
on mote:
- gofmt -l clean; go vet ./internal/...; GOOS=linux go vet -tags nogui
  and GOOS=windows go vet on agent, cli, desktopiso, desktopdir, gui.
- go test (whole packages) desktopiso, desktopdir, settings, settingsapi,
  proc: ok. -run Isolated|TestDesktopInstance|TestAddStartsDesktopOnTheFolder|
  TestScript|TestAddLeavesTheirs|ClaudeDesktop|Restart in agent;
  TestClaudeDesktopLauncher|TestEveryRouteHasACommandOrIsNamed|Help in cli;
  TestCoreScriptBudget|TestSettingsSaveKeepsWhatItDoesNotSend|Budget|Desktop
  in gui and gateway: ok.
- An earlier full `go test ./...` at fef23255f had four reds, all from
  this change and fixed here: the route without a command (now in
  notYet), settings_keep's DesktopIsolated, os/exec instead of proc, and
  the core script budget (paid by sharing the switch helper with the
  largest-window line and cutting comments; no raise). A second full run
  of the touched packages queued ~7h on mote's suite lock behind other
  sessions and was stopped; the targeted runs above replace it.
- GUI on mote, both engines: desktop-isolated (new; en, zh, zh-TW, ja,
  de; 1100 and 640; aria-checked, posts, status text, no scroll, no
  select, absent without `isolated`), desktop-longest, click-scroll,
  plain-names, i18n-keys: ok. page-width-steady, panel-fold and
  zero-priced-free are red, the same 33 tests at origin/main be9dbce02
  (diffed): #4541/#5013, #5796, #5262. i18n-keys' "a plugin's words are
  its own" is red on main too (#5332).
- Whole GUI suite on WSL at an older head: 400 of 22778 red across
  ~100 files of other pages, in line with #5559 (478 of 21666 on main
  there). Not rerun on mote.

Real use, on mote in a sandbox HOME with Claude.app 4.23118 linked in:
`claude-desktop magpie`, then `launcher add`, moved the wiring to
Claude-Magpie-3p (deploymentMode 3p, mcpServers and locale carried).
Opening Claude Magpie.app started Claude with
--user-data-dir=.../Claude-Magpie-3p; it wrote configLibrary and
model-catalog there (3P mode) and no -3p-3p folder. A second, 1P Claude
ran beside it on its own sandbox folder. Opening the launcher again
kept one instance; the pkill pattern matched only the isolated pid; both
quit on SIGTERM. `launcher remove` put the wiring back and removed the
app.

Broken by hand: a folder without -3p (Desktop made -3p-3p), the
CLAUDE_USER_DATA_DIR env route (ignored by the packaged app), os/exec in
the quit (TestNoCommandBypassesProc red).

Not tried: a screenshot of the running app (screencapture fails over
ssh); a model request through a gateway from the isolated app; Windows
and Linux (not offered there). Known: the Dock shows Claude's own icon
for the running isolated app, and Chrome pairing is off in a moved
userData folder.
2026-11-09 22:31:16 +08:00
yetone be9dbce02c settings search: built-ins are found too, off or on, and Open goes to their row
A built-in's switch and the settings it keeps in Plugins › Built-in or on
its own page (Gateway's Recent calls at a time) were found by nothing in
Settings' search, and one switched off took its Settings tab and rows
with it, so searching "Observability" with it off said no setting
matched (the scattered settings audit after netube99 on X). The search
now lists, after Settings' own rows and under "Plugins › Built-in", each
built-in whose name, line or schema setting has the words, in the
language shown or English, one off saying Off. Open goes to Plugins ›
Built-in and lights that row, again when the list is drawn a second time
as the plugins are read.

The list is drawn by a lazy setfeats.js the first time a search runs,
and only when what it finds changes, as Settings' observer runs the
search again on each change under the view.

Run (mote, at f98e954ce's tree plus this): settings-search,
old-webkit, builtin-places, provider-prefs, i18n-keys: 170 pass, 0 fail,
Chromium and WebKit, every language; TestCoreScriptBudget ok. Broken by
hand: without the row's light, and with the match always false, the new
case went red in Chromium (7 pass, 2 fail each).
2026-11-09 22:11:00 +08:00
yetone 88b541a25c images: every pointer names Settings › Models › Images, where the page is
The image models moved under Settings › Models, but the Library's Magpie
Image sheet, the MCP server's instructions to agents, the gateway's
"no image model" errors, the video tool's text and the docs still sent
users to "Settings › Images", a tab that no longer exists (the scattered
settings audit after netube99 on X). Every user-facing string now names
Settings › Models › Images in en, zh, zh-TW, ja and de, as do the site's
Qwen docs (en, zh, ja), llms-full.txt, the subsystem pages and comments.

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2):
- go vet ./internal/gui ./internal/gateway ./internal/agent
  ./internal/provider ./internal/settingsapi: ok
- go test -run 'Image|Draw|Video|Hidden|Group|Settings' ./internal/gui
  ./internal/gateway ./internal/settingsapi: ok; ./internal/imagemcp,
  ./internal/library, ./internal/catalog: ok
- GUI: i18n-keys, i18n-en-no-cjk, image-models-hide,
  library-browser-setup: pass in Chromium and WebKit
- gofmt -l: nothing
Not tried: a real agent reading the new MCP instructions (text only).
2026-11-09 21:51:53 +08:00
yetone a06872dec8 caps: a wallet window's spend is counted, so a cap holds it (#5770)
A window that tells only what is left (QuotaWindow.Balance: AStudio
0.2.0's 通用积分 and 星火积分, SuperMagic's points) read 0% used until
it was empty, so an account cap never tripped on it. 9won capped an
AStudio account at 4 and it spent over 1,000 credits past it.

magpie now counts what such a wallet spends (wallet_spend.go). Each
plugin reading's balance is set against the one before: a fall is
spent, a rise (top-up, daily grant) is not. The count runs over the
window's own period when it tells a reset, else the local day: a
wallet never renews, and a cap reached for good would switch the
account off with no time it comes back; the ask was "N a day". Spend
before a period's first reading, or across a gap between periods, is
unknown and not counted; spentSince says when counting began. The
counts are kept in wallet-spend.json beside providers.json, so a
restart doesn't lose them.

Every wallet window carries spent and spentSince. On an account with a
usage cap (WindowCaps.Holds) it also reads as amount spent of limit
(spent plus what is left), and used that share. A cap by share then
holds it in routing (allowanceOf takes the fields as they are) and on
the GUI row (capHeldOf reads used). So does 40cbdaa7e's amount cap,
which skipped a window with no total: 9won's "at most 300 a day" on a
wallet now holds (magpie provider account-cap ... --window 通用积分
--amount 300). An uncapped wallet is unchanged:
balance alone, routed by Allowance.Left. A cap just set is judged from
the next reading. holdsBounds leaves wallets out: there is no whole to
reckon "holds" from.

Tests, each red on the old code (broken by hand where they compile):
- TestPluginWalletCapHolds: real plugin host, fake plugin, wallet
  10,000 -> 9,500 on an account capped at 4. Used 5, CapHeld set, the
  uncapped account untouched. Red with the plugin_usage.go hook
  removed (Used 0, Spent nil).
- TestWalletSpendCounted: falls counted, top-ups not, a restart reads
  the count back, the next local day and a told reset start over
  (UTC+8 fixed zone), failed and share readings left alone.
- TestWalletCapHolds: account cap 4, the window's own cap 4, and an
  amount cap of 700 (not held at 650 spent, held at 750).
- TestWindowHoldsLeavesAWalletOut: red without the holdsBounds change
  (a wallet reckoned a 500-token whole).

Run on mote at this tree on f8186c691. Rebased under it after: 7000b23b8
(GUI files only) and 36ddd5761 (internal/sessions only) (lockf ~/suite.lock
mote-run):
- go test ./internal/provider -run 'Wallet|Cap|Amount' -count=1: ok
- go test ./internal/usage -run TestWindowHolds -count=1: ok
- gofmt -l .: clean
- go vet ./... for darwin and windows, and for linux with -tags nogui:
  ok
Pushed and tagged at once, per the owner's rule. The full go test ./...
-timeout 45m runs after the push and any red gets filed.

Not changed: the GUI. A wallet meter still shows "{n} left". A capped
one shows "At its cap" from used. The meter's Amount... item still
needs a total and a unit, so an uncapped wallet doesn't offer it yet
(follow-up). A Text window (a balance that isn't
a number) still can't be capped by share.

Reported-by: 9won (Discord)
2026-11-09 19:23:13 +08:00
yetone c056b7c8c3 provider: a Responses provider's turns may go over the Responses WebSocket (#5781)
A provider the user added with an http(s) Responses address can now send
its Responses turns over the Responses WebSocket that magpie already
speaks to chatgpt.com (codexSocket), with `socket=auto|on|off`:

- off, or absent: today's behaviour exactly. Provider.Via hides any
  socket value an outer context carried, so such a provider never dials.
- auto: tries the socket, falls back to HTTP when the handshake is
  refused or the socket ends before the reply, and speaks HTTP to a host
  for 10 minutes once it refused the handshake (codexShun).
- on: the same fallback, but never shuns; the socket is tried each turn.

Provider.Via puts the provider's Responses host and path in the request's
context (withSocket); codexSocket's gate is provider.SocketTurn, which
takes a ChatGPT turn as before, or a POST to that host at
<Responses>/responses. The rest is the ChatGPT leg's: the kept socket and
its delta (codexKeepKey now also hashes the scheme, X-Api-Key and
Api-Key), the error frames, 1009 handling. A provider's reply with no
Content-Type is marked text/event-stream, since it is read as one.
Routing, keys, limits, usage and masking are unchanged: only the
transport under the request differs.

Set with `magpie provider set <id> socket=auto|on|off` (refused on a
provider with an account, no http(s) Responses address, or Vertex,
TakesSocket), saved in providers.json as "socket", shown by `provider
show`, and in the editor's Advanced as a WebSocket tick beside HTTP
version (ticked saves auto, keeps a CLI's on, unticked saves off; shown
only while the Responses address is http(s) and there is no account).
docs/subsystems/providers-accounts.md describes it.

app.js pays for its rows by three long comments cut to one line
(renderMove, the vendors' status pages, header rows): the core's scripts
are 478 bytes smaller than on 0eac4e6aa (1,533,069 of 1,533,802); no
budget raised.

Run on mote at this change on origin/main 0eac4e6aa (since then main
added a39b63e88 and 7cabf0da9, internal/sessions only):
- gofmt -l clean; go vet (darwin) of provider, gateway, cli, gui, clean.
- go test -tags nogui ./internal/gui ./internal/cli: ok;
  ./internal/provider -run TestSocket: ok.
- go test ./internal/gateway -run 'TestResponsesProvider|TestCodexSocket|
  TestCodexKept|TestCodexTurn|TestHTTP1|TestInsecureTLS': ok. The new
  tests use an httptest WebSocket upstream: a turn over the socket, a
  provider without the field never dialling (and one on the same host
  with it), a refused handshake shunned on auto and tried again on on, a
  socket closed before the first event going over HTTP, the kept
  socket's delta on the next turn, and the reply being a stream.
- node --test provider-socket (new; chromium and webkit, en zh zh-TW ja
  de, 1100 and 420 wide), provider-http1, provider-insecure-tls,
  i18n-en-no-cjk: pass. i18n-keys' "a plugin's words are its own" is
  red for three words in files this doesn't touch, filed as #5327/#5332,
  #5426 and #5482.
- One rebase earlier (on 2a48974e8, the same change): GOOS=linux (nogui)
  and GOOS=windows go vet of the four packages clean, and the whole of
  ./internal/provider ok.
- Broken by hand, each red then green: SocketTurn codex-only (all six
  gateway tests red); a path-suffix gate in place of the context
  (WithoutSocketNeverDials, TestSocketTurn red); the never-shun case
  removed (RefusedOnTriesAgain red); the Content-Type line removed
  (ReplyIsAStream red).

Not tried: a real Responses upstream speaking the WebSocket (no network
in tests); the keep key's X-Api-Key/Api-Key separation has no test of
its own; the editor in the Linux app's WebKitGTK; the full suite (run
after the push).

Reported-by: matrix0487 (Discord)
Reported-by: faithleysath (#5781)
2026-11-09 18:57:29 +08:00
yetone 7cabf0da98 sessions: one place says which ids a ZCode request names, and drafts are one group (#5754)
On top of Flandern1211's cherry-picked fix (the commit before this one).
GatewayKeys gave the bare id of a ZCode session (sess_<id> in ZCode's
database, <id> in the gateway's record), but NativeIDs kept its own copy
of the keys: the management page still counted every ZCode session sent
through the gateway as a gateway-only session, its delete listed them,
and its search read them a second time. requestIDs is now the one place
that says which ids a request names a session by; GatewayKeys (Sessions
list, its spend, the stats' native set, viaOf, the manage search) and
NativeIDs (the manage page's count and delete) both read it.

ZCode runs a session started without a project in a folder it makes for
that session alone: <workspaceDirectory>/draft-<id> or <ms>-<uuid>, with
workspaceDirectory = ~/.zcode/workspace (read from ZCode 3.17.2's
out/host/index.js, downloaded from cdn-zcode.z.ai; never the live
~/.zcode). The reporter's group is renamed from "Scratch sessions" to
"Draft sessions" (草稿会话 / 草稿會話 / 下書きセッション /
Entwurfssitzungen), after ZCode's own word for them, with a GUI test of
its own. Comments no longer quote "Seen through the gateway", which
i18n-keys' plugin-words guard read as the core saying the word.

Run (mote, at this tree, rebased on 0eac4e6aa):
- gofmt -l: clean. go vet of sessions/gui/usage for darwin, linux
  (-tags nogui), windows; GOOS=linux -tags nogui and GOOS=windows
  go build: ok.
- go test -run 'ZCode|Gateway|Native|Manage|Merge|External'
  ./internal/sessions ./internal/usage ./internal/gui: ok.
- GUI, Chromium and WebKit: sessions-zcode-drafts (new, 5 languages x 2
  widths), sessions-folder-list, i18n-en-no-cjk: ok. i18n-keys' "a
  plugin's words are its own" is red at origin/main for three words not
  touched here, filed: #5332 (View routing), #5426 (No session ID),
  #5482 (Use the library's). The reporter's comments quoted "Seen
  through the gateway" and made a fourth; reworded.

Broken by hand:
- TestZCodeGatewayRowIsTheSessionItself on origin/main's raft.go,
  manage.go and external.go: red (keys lack zcode|main, fork_of_main,
  abc; NativeIDs lack them; 29 rows for 26 sessions).
- sessions-zcode-drafts on origin/main's Sessions client.js/i18n.js:
  red in every language and width.

Not tried:
- The full Go suite and the whole Sessions GUI set: queued behind other
  sessions on mote's suite lock; run after the push, reds filed.
- A real ZCode database: none on this machine; the reporter's own run
  over 1,105 sessions is in the issue.
- Windows/WSL GUI, and a ZCode data folder the user moved elsewhere
  (only ~/.zcode/workspace is matched).

Reported-by: flandern1211_58540 (Discord)
Refs #5754 (left open for the reporter)
2026-11-09 18:55:01 +08:00
Flandern1211 a39b63e886 sessions: a ZCode session is listed once, and its draft folders are one group
A ZCode request names its session by the id its database gives with a
prefix stripped (sess_…, a subagent's sess_subagent_agent_…: zcodeBareID,
which Titles already used for names), while GatewayKeys kept only the
prefixed id. MergeExternal therefore matched no native session for any
ZCode session sent through magpie's gateway, and each was a row under its
folder and again a row under "Seen through the gateway" with no files
behind it. On this computer's database (1,105 sessions, 3,536 gateway
records) that was 70 of 70 gateway rows: 38 top-level sessions, 9 forks,
23 subagents. A group already holds its forks' and subagents' files
(ocRoots), and assembleListed counts every file's calls in the row, so
each of the 70 counted the same calls a second time.

GatewayKeys now gives the bare id of a ZCode session and of its forks and
subagents; externalAdded reads GatewayKeys instead of keeping its own copy
of the keys in pairs; idInFile names ZCode, so subIDs collects the ids
their own rows give (their files are in the group, no row lists them
apart). The Sessions page draws a ZCode session whose folder ZCode made
for that one session (~/.zcode/workspace/<draft|time>-<uuid>, one for
each session started without a project) in one "Scratch sessions" group
after the projects: 42 of them here were 40 folders of one session under
Other folders, and they are no projects of the reader's. cwd, files and
usage are untouched; a row's tooltip gives the folder it ran in.

The list went from 1,286 rows to 1,216 over the same 1,213 native ones;
the 70 gateway rows had 34.3M input and 2.59M output tokens and $125.66
of the ledger's cost on top of the rows that already counted those calls.
A ZCode row now prices its own calls from the catalog like every other
agent's, and Usage keeps the ledger's figures.

Run:
- go test ./internal/sessions -run 'TestZCode' -count=1: ok.
- go test ./internal/gui -run 'Session|Gateway' -count=1: ok.
- go build ./...; go vet ./internal/sessions: ok.
- gofmt -l; git diff --check; node --check on client.js and i18n.js: clean.
- go test ./internal/sessions -count=1: the same failures as without this
  change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder,
  TestCCListingKeepsItsNames: path separators and allocation counts on
  this Windows box).
- go test ./internal/gui -count=1: the same failures as without this
  change (lody's %AppData%, pageservice's symlink privilege here).

Broken by hand:
- dropping the bare key puts the 70 rows back under Seen through the
  gateway (TestZCodeGatewayRowIsTheSessionItself fails);
- leaving ZCode out of idInFile keeps a fork's and a subagent's own rows
  as gateway rows while the group already counts their calls.

Not changed: the scratch group is worked out on the page (client.js), so
Usage's folder filter still lists the draft folders by their paths; the
group is ZCode's only, and other agents' per-session folders are left as
they were.
2026-11-09 18:49:15 +08:00
yetone 40cbdaa7e8 provider: an account's window can be capped at a fixed amount of its unit
A window magpie reads with a total and a unit (a day's 1000 credits, a
plan's requests) can now be capped at an amount of that unit, not only
a share: 9won_25273 asked to stop an account at 300 of its day's credits.

- AccountWindowAmounts keeps it per account and window (capId). An
  amount and a window's own share replace each other.
- WindowCaps.limitShare turns it into a share of the total for the mark
  and NearCap. CapHeld and capReached hold the account once the window's
  count reaches the amount (past), and rest it as the percentage cap
  does: the next account takes the request. cappedError and the trace
  say "has used 300 credits ... past its cap of 300".
- A reading with no total ignores the amount; the account's share
  applies.
- GUI: the window meter's menu has one more item, Amount..., typed in
  place (provider/windowcap with amount). It shows only on a window
  with a unit and total. Strings in zh, zh-TW, ja, de.
- CLI: magpie provider account-cap <id> <account> --window <name>
  --amount <n|off>.

Usage outside magpie counts: every cap reads the vendor's own count, so
what the account spent in the vendor's app or on another machine counts
from the next reading on. magpie can only hold back its own requests.

Run, at this head on Linux (wsl-run, magpie-desktop):
- gofmt -l: clean; go vet ./... for linux (-tags nogui) and windows: ok (darwin
  vet needs cgo, so it runs with the full suite on mote afterwards)
- go test -run 'Lang|ToolLoop|LoopGuard|Cap|Amount' ./internal/gateway
  ./internal/provider ./internal/cli: ok (TestWindowAmountCapHeld,
  TestSetWindowAmount, TestWindowAmountHoldsTheAccount, the CLI cases)
- GUI window-cap, window-cap-pool, account-cap in chromium and webkit,
  420 and 1100 wide, en zh zh-TW ja de: 78 of 78 in each engine. An
  earlier webkit run lost the amount test's page once ("Target page,
  context or browser has been closed"); it passed in 2 more full-file
  runs and 60 of 60 alone
- i18n-keys: only "a plugin's words are its own" red, words that aren't
  this change's (#5332, #5426, #5482)
Broken by hand: limitShare ignoring amounts (of < 0): TestWindowAmountCapHeld
and TestWindowAmountHoldsTheAccount go red.
Not tried: the full go test ./... at this head (queued on mote, runs
after); a real account at an amount cap.
iFlytek: 9won's 讯飞 overshoot isn't covered. Loomy's daily window sends
used as a count and amount as what is left (plugins#889); AStudio's
wallets tell a balance only, which no cap can hold (#5770).

Reported-by: 9won_25273 (Discord)
2026-11-09 18:19:02 +08:00
yetone 3245b730d2 gateway: the tool-loop notice is written in the conversation's language
When magpie stops a conversation going round one tool call, the notice the
agent shows was English only and began "magpie stopped this turn". A
conversation in Chinese got an English notice. The notice goes upstream
with the next turn, so it now names neither magpie nor a vendor's limits.

conversationLang (reply_lang.go) reads the user's own words in the whole
body. It skips tool results, system prompts and whole <tag> blocks, and
decides by script: kana -> ja, Hangul -> ko, Han -> zh or zh-TW (by
simplified/traditional-only characters), Latin with German marks -> de,
otherwise en. toolLoop.notice(lang) picks the matching text; the setting
is named as the GUI names it in that language (Korean, which the GUI
lacks, names it in English).

Run, at this head on Linux (wsl-run, magpie-desktop):
- gofmt -l: clean; go vet ./... for linux (-tags nogui) and windows: ok (darwin
  vet needs cgo, so it runs with the full suite on mote afterwards)
- go test -run 'Lang|ToolLoop|LoopGuard|Cap|Amount' ./internal/gateway
  ./internal/provider ./internal/cli: ok
  (TestLangOfEachLanguage, TestConversationLangReadsTheUsersWords: each
  language, mixed, empty; TestToolLoopNoticeInTheConversationsLanguage)
Broken by hand: counting kana as Han in langOf; all three tests go red.
Not tried: the full go test ./... at this head (queued on mote, runs
after), a real agent looping in Chinese. The reply loop guard's notice
(loop_guard.go) is still English and names magpie: #5764.

Reported-by: tenacious_eagle_96548 (Discord)
2026-11-09 18:19:02 +08:00
yetone 0024660445 gateway: a key's slot is taken before an account's turn near its cap
ox0pine on X: a gateway key held to one provider sometimes hung "in
routing". With the key's MaxConcurrency set and its account within 5
points of a usage cap, two turns could each wait for what the other
held:

- Turn B took the account's near-cap turn, then the key's slot (kept for
  the whole request, key_slots.go), and got a passing failure (503).
- B slept and went back to the same account (i--). At the top of the
  loop it gave the near-cap turn back.
- Turn A, waiting for that turn, took it and waited in keySlot for the
  key's slot, which B held.
- B found the turn taken, was the last candidate and waited in
  nearCap.take, which A held. Neither could move until its agent hung up.
  Neither had a try that could start, so the GUI showed "routing…".

serve now takes the key's slot before the near-cap turn, so locks are
always taken key, near-cap turn, lane. The wait still counts in the try's
Queued (nearInKey). Eager routes already took the slot before serve.
forward and codexUpstreamOn take it in their handlers and never take a
near-cap turn.

TestKeySlotAndNearCapTurnNeverWaitOnEachOther: one Codex account at 89%
with a 90% cap, a key held to codex/* at MaxConcurrency 1. The first
try gets a 503, and a second turn is sent while the first is paused.

Run on mote (mote-run):
- the new test on the old serve: red 5 of 5 (both clients time out at
  8s). Green after, and green without the key's cap on the old code.
- -run 'NearCap|Key|Cap' -count=2: ok.
- go vet ./internal/gateway for darwin, GOOS=linux and GOOS=windows;
  gofmt -l clean.
- rebased on origin/main f5f68b433, then again: -run 'NearCap|Key|Cap'
  ok (70s), vet darwin/linux/windows ok, gofmt clean.
- full go test ./internal/gateway -timeout 45m through lockf
  ~/suite.lock: not run. It waited 1h17m behind other sessions' suites
  for the lock and is still queued; shipped without it (owner: never
  hold a verified fix behind a full suite).

Not the reporter's case. They later said (v0.1.3371) the key's one
provider is a custom API-key provider, and the row clears by itself in
about a minute. This hang needs a subscription account near a usage cap
and never clears by itself. A probe of a custom key provider behind a
held key (Models plan/*, Accounts held to one of two keys; plain, 429s
and patience, MaxRPM 1, MaxConcurrency 1) had a try in the trace that
matched the order at every 150ms poll, so the Routing page would read
"answering", not "routing…". Their ~60s wait is not found yet.
2026-11-09 18:15:24 +08:00
yetone 2b8ff0fbeb routing: an account's model list older than the model is unknown, not a plan without it
wudao_85256 on Discord: two ChatGPT Plus accounts on the Codex
subscription, each serving gpt-6.1-sol alone. With both on, Routing said
of the second "its plan doesn't list gpt-6.1-sol", and once the first ran
out of its allowance nothing failed over: an unlisted account is asked
only after a listing one refuses the model as unserved, never after a 429.
Re-adding the account and refreshing changed nothing.

Cause: the second account's own list (models/codex@<user>.json) was the
evidence, and it was stale. The ChatGPT backend lists gpt-6.1-sol only to
Codex 0.161.0 and later (dd12c75bf), and a saved account's list is asked
once a day, one account a look, for whatever codexVersion() was then (the
0.159.0 fallback before a Codex client has come through). Codex's own
account is asked every hour, so it gained the model and the saved one kept
a list without it for up to a day, every day the race went that way. A
refresh asks the saved lists only when they are a day old, and removing an
account leaves its list behind, so re-adding found the same list.

Fix, for every subscription that keeps each account's own list in the
catalog (Codex, Antigravity):
- catalog: a kept list records Since, when each model was first in it
  (carried from save to save; a list saved before counts from its fetch),
  and Asked, what it was asked as (LiveSince, LiveAsked, SaveLiveAsked).
- provider.AccountsFor: an account whose list lacks the model is left out
  only when that list can know the model: fetched after, or within
  listRound (10 minutes, one look) before, another account's list first
  had it, and, for ChatGPT, asked for the Codex magpie speaks
  as now (codexListBehind; a list with no version kept is behind). Else
  it is unknown, and routed over at its own place in the order
  (Account.listLags). A Free account's list fetched after the Plus one had
  the model still leaves it out (#520).
- codexFetchSaved asks a behind list at once, as one with no list, and
  one fetched more than listRound before another account's list first
  had a model (catalog.LiveNewest); either waits an hour after a failed
  try. Both Codex lists are kept with the version asked.

Not covered: plugin accounts (pluginLists) and Claude's entitlements keep
their lists elsewhere and are unchanged; API keys' per-key lists
(KeysFor) are unchanged. After the update every Codex list saved before
counts as behind until it is asked again (within the hour), so a Free
account beside a Plus one may be asked a Plus-only model in that time
and refuse it, as an unknown list should be.

Tested: TestStaleAccountListIsNotAPlanWithoutTheModel (two Plus accounts,
the second's list asked for 0.159.0 / with no version / fetched before the
first listed the model / the first's list from before Since: both routed;
fetched since, or in the same look, for this version: left out) is red
on the old AccountsFor, 4 of 6 subtests; its same-look subtest is red
with listRound taken out. TestBehindListAskedAgain is red with the behind
branch of codexFetchSaved taken out by hand, and
TestListOlderThanAnothersModelAskedAgain with the LiveNewest rule taken
out. TestLiveSinceCarriesOver. Without listRound,
TestCodexProviderListsEveryAccountsModels and
TestAntigravityPoolRoutesDiscoveredModels went red (a Free list fetched
moments before the Pro one counted as older than the model).
gofmt -l; go vet ./internal/catalog ./internal/provider ./internal/gateway
for darwin, linux and windows; go test ./internal/catalog ./internal/provider
ok on mote; go test -run 'Unlisted|Codex|Pool|Antigravity|Account'
./internal/gateway ok on mote.
Not tried: a real pair of ChatGPT accounts against the backend; the
version gating is the one dd12c75bf read from the backend's error.

Reported-by: wudao_85256 (Discord)
2026-11-09 18:13:08 +08:00
yetone ff7d84b9b2 gui: a built-in's switch, settings and page lead to each other (netube99 on X)
netube99 (X, 2119721422918742222): masking is switched on in Plugins ›
Built-in, set in Settings › Privacy and seen in Insights › Masking, and
none of the three leads to the others. Web search had the same split.
One pattern for every built-in whose switch, settings and page are apart:

- pluginrt.Manifest.SetAt ("privacy #redactList") says where Settings has
  its settings: redact, search, gateway and otel set one. builtins.go
  sends setAt and page (its nav.page Part).
- Its Built-in row (featGo): "Settings › <tab>" and, while on, its page
  ("Masking"). No settings link while off when those settings hide with
  the plugin (Observability).
- Its settings, while off (featOff): a first row "Off in Plugins ›
  Built-in", what being off means, and Turn on. Privacy and Web search
  use it; search's own off row went.
- Insights › Masking's head: "Settings › Privacy", unless Turn off
  already goes there. At 600px and under its buttons wrap below the title.
- docs/subsystems/plugin-runtime.md documents SetAt.

Proposal for the owner, not built: give each feature one home with its
switch, settings and page together. This commit only links the three.

Core budget: no raise. +~1.9KB of code is paid for by shortening six
app.js comments (logo mask shelf, copy, sidebar, account models,
fitSend, the hold room).

Run on mote at fe672ce69's tree (origin/main 2b22425b4 + these two):
- go vet ./internal/gui ./internal/pluginrt ./plugins/...;
  GOOS=linux -tags nogui and GOOS=windows vet of gui and plugins: clean.
  gofmt -l: clean.
- go test -run 'TestBuiltin|TestCoreScriptBudget|Translated'
  ./internal/gui ./internal/pluginrt: ok (budget passes after the cuts).
- node --test builtin-places, websearch-places, builtins, i18n-keys,
  i18n-en-no-cjk: 235 pass, 1 fail. The fail is i18n-keys "a plugin's
  words are its own" on plugins/usage "View routing", red on origin/main
  too (#5332, #5426, #5482).
  builtin-places and websearch-places cover en, zh, zh-TW, ja and de in
  Chromium and WebKit, at 1100 and 420 wide, nothing past the edge.
Broken by hand: featGo and featOff made to return at once, and 40
builtin-places subtests went red (42 fails with their parents). Round 1's
files reverted made websearch-places 102 of 142 red.

Queued, not waited for (owner: push each verified fix at once): the full
`go test -timeout 45m ./...` then `make test-ui` on mote behind
~/suite.lock; log at
~/workspace/projects/magpie-wt/websearch-surfaces-scratch/full.log. Any
red gets an issue.
Not tried: the real app on Linux/Windows; warm-ups have no SetAt (their
settings moved into the provider editor).
2026-11-09 17:58:11 +08:00
yetone 2b22425b45 agent: Claude Science in a WSL distro is found and run on magpie from Windows
shuitunlulu_ (Discord) has Claude Science in WSL2, and Windows magpie
didn't find it. It is now a WSL twin (claude-science@wsl:<distro>), found
by the probe's claude-science (~/.local/bin or PATH). Its daemon is
restarted there through wsl.exe with ANTHROPIC_BASE_URL set, the same steps
as this machine's (claudescience.go is now one scienceHost for here and for
each distro), and v0.1.3334's keeper puts it back on magpie in each running
distro that has a note (claude-science-wsl-<distro>.json). With no note,
nothing runs in WSL.

The daemon takes http only to a loopback address and sends its Claude
sign-in as the key. In mirrored networking it gets the gateway's address.
Under NAT magpie starts a relay in the distro: socat on
127.0.0.1:<gateway port> to Windows' WSL address. The daemon gets
http://127.0.0.1:<port>/<WSL key>; the gateway's lanGuard takes the key
off the path (takeWSLPathKey) before fromWSL judges it. Connect says so
when the distro has no socat. Disconnect stops the relay with the
connections it forked, as one process group. When Windows' firewall keeps
WSL out, the row shows the same firewall drift and rule as other WSL
agents.

Run:
- gofmt -l clean
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows (mote)
- go test ./internal/agent ./internal/gateway on mote (macOS)
- go test ./internal/agent on xiaomi-gpu (Windows 11): 26 FAIL; 25 fail
  the same at origin/main c7ebb6f8d on that box (#4115, #5019, #3700,
  #5344, #2808, #4785, #2958, #1827, #4786). The 26th,
  TestHermesProfilesFollowMagpieModel, passed 5/5 alone on both and
  failed only in the whole-package run (#4115, #2540). Every
  ClaudeScience test passed there.
- At the pushed head (rebased on 9dd7aabca, which changes neither
  package): go vet darwin + windows and -run 'ClaudeScience|WSL' of agent
  and gateway ok on mote.
- Full suite, -timeout 45m: not finished at push. It waits on the lock
  behind other sessions' runs on mote and on magpie-desktop; the
  packages it changes (agent, gateway) were run above.
- Real run against magpie-desktop (Ubuntu 24.04, NAT, claude-science
  0.1.72 in ~/.local/bin) from a Windows test binary, with a sandbox
  XDG_CONFIG_HOME and a stand-in gateway on 127.0.0.1 and 172.17.32.1:
  - Connect took about 10s, and /proc/<daemon>/environ had
    ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/wsl-...
  - The relay outlived wsl.exe (setsid, its own SID).
  - With the firewall blocking the test binary, the row's drift named the
    firewall and the New-NetFirewallRule.
  - With a temporary allow rule for the test binary (removed afterwards),
    curl in WSL through the relay reached the stand-in with the key path,
    and no drift showed.
  - Daemon and relay were killed as a WSL restart would; one keeper pass
    brought both back.
  - Disconnect left no relay and no relay forks (a held curl fork
    included), and the daemon ran without the variable.

Broken by hand:
- relay := false: the NAT test went red six ways.
- Without lanGuard's takeWSLPathKey line: TestWSLKeyInPath got 403.
- Check's firewall branch off: TestClaudeScienceInWSLFirewall red.
- A plain kill of the relay pid left a fork connecting on the real distro;
  that is what led to the process-group kill.

Not tried:
- The real magpie GUI on Windows with this build.
- A daemon's own model request through the relay; only curl was sent.
- Bridged networking.
- A distro without socat; that path was run only in the fake.

Reported-by: shuitunlulu_ (Discord)
2026-11-09 17:46:13 +08:00
yetone a6a99717e0 gateway: thinking with no signature never goes to Claude
citricdu (Discord, 0.1.3356): Claude Code auto-compacted a session on a
Smart group that had moved to Cursor's Grok 4.7, then the group went
back to Kiro's Claude Opus 5.5. The compacted history kept a thinking
block Grok made, which magpie hands a Messages client signed "", and
Kiro answered 13 times in a row with a bare invalid_request_error. The
same request without the block was answered.

withoutForeignThinking dropped only DeepSeek's UUID-signed blocks and
kept an empty signature on purpose ("a block with no signature Claude
takes"), and Kiro's refusal names nothing boundRefusal reads, so
refuseBoundThinking never mended it. Now every thinking block whose
signature is empty, blank or missing is left out for an upstream
serving Claude (api.anthropic.com, or a claude- model: relays, Bedrock
and Vertex ids, a plugin's fetch such as Kiro's), on every route
forwardOnce takes (relayed, translated, plugin, count_tokens), and
refuseBoundThinking runs it too. Text, tool_use and tool_result stay;
Claude's own signed thinking and redacted_thinking are untouched. A
model that learned thinkingBackNeeded (DeepSeek under another name)
keeps its unsigned blocks. Chat and Responses translated into Messages
already dropped unsigned thinking in anthropicBody.

Tests: TestUnsignedThinkingNotSentToClaude builds the reporter's shape
(the compaction summary, then two tool turns opening with Grok's
thinking signed "") against a fake Kiro that gives the same bare 400,
relayed and through the fake plugin's fetch (FAKE_KIRO model added).
TestGrokThinkingThenClaude runs the switch itself: a group answered by
a Chat Grok, then moved to Claude mid tool loop.
TestWithoutForeignThinking adds an unsigned block, Bedrock and Vertex
ids, a missing and a blank signature.

Run (mote, at this head rebased on 136178803):
- gofmt -l: clean; go vet ./internal/gateway: clean
- go test -run 'TestUnsignedThinkingNotSentToClaude|TestGrokThinkingThenClaude|TestWithoutForeignThinking|TestDeepSeekThinkingThenClaude|Bound|TestPluginBoundThinkingLeftOut|ThinkingBack' ./internal/gateway: ok
Broken by hand: the old predicate (DeepSeek signatures only, the
"signature" precheck only) put back: TestWithoutForeignThinking,
TestUnsignedThinkingNotSentToClaude/relayed and
TestGrokThinkingThenClaude fail (Kiro relay 400 "Improperly formed
request."). The plugin subtest passes on the old code too.
Not run before push: the full suite and the Linux/Windows vet; they
are queued behind other sessions' suites, and their result follows.
Not tried: a real Kiro or Anthropic account; Kiro's exact error text
is the reporter's description, not captured bytes.

Reported-by: citricdu (Discord)
2026-11-09 17:24:09 +08:00
yetoneandreyoung 4314f4b776 otel: export the gateway key's name as magpie.gateway_key.name (#5751)
reyoung (#5751) shares one magpie through several gateway keys and wants
requests in Langfuse or another collector told apart by key. The ledger
row already had CallerKeyName, but the OTLP allow-list dropped it, and
the observer's root and attempt records never carried it.

Ported from reyoung's 9d82162aa (reyoung/magpie feat/otel-gateway-key-name),
applied unchanged onto current main:
- observeRequest takes access.Caller(r).KeyName when observing begins
  and puts it on every End and Attempt record (CallerKeyName), so the
  root span and every try (failures, retries, fallbacks) carry it with
  no lookup at export time.
- otlp's allow-list grows by this one attribute, on generation and
  ledger spans (otelAttributes, so the duration and token histograms
  too) and on the root span. Omitted when the name is empty. The key's
  id and secret are never sent; provider account names stay out.
- docs/reference.md, plugin-runtime.md and the en/zh/ja privacy pages
  say the name goes to the user's collector.

Added on top: docs/reference.md says each key name multiplies a
metric's series, and that keys sharing a name are counted together.

Review of the fork (read every line; run only on mote): no new address,
dependency or credential; the name is read from the auth context at
request time, the same source appendUsage uses for the ledger row;
reported rows (another computer's) already have the caller key cleared
and never reach observers; session spans of local transcripts have no
key. READMEs (en, zh) mention OTLP only as a feature, with no list of
what is sent, so they are unchanged.

Run on mote (lockf ~/suite.lock), at base c7ebb6f8d plus this change:
- gofmt -l internal/gateway internal/otlp: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: ok.
- go test ./internal/otlp ./internal/gateway -run 'TestOTel|TestObserve':
  ok.
- go test -count=1 -timeout 45m ./internal/otlp ./internal/gateway
  ./plugins/otel: ok.
- go test -count=1 -timeout 45m ./... (macOS): every package ok (92),
  exit 0.

Rebased onto 136178803 after that run (5 commits; gateway.go and
prev_response.go, nothing in observe.go, otel*.go or internal/otlp).
The touched packages' run at the pushed head is queued behind mote's
suite lock and was not done before the push.

Broken by hand (each on mote, then restored):
- observeRequest without the name (o := &observed{}):
  TestOTelExportsGatewayKeyName/true red, "span 0: gateway key name ""
  seen 0 times".
- gatewayKeyAttr returning before adding the attribute:
  TestOTelBatchWireAndPrivacy red (attributes lack
  magpie.gateway_key.name) and TestOTelExportsGatewayKeyName/true red.

Not tried: a real Langfuse collector; Windows and Linux runtime runs (vet
only); the site pages are not deployed by this commit.

Co-authored-by: reyoung <728699+reyoung@users.noreply.github.com>
2026-11-09 17:21:48 +08:00
yetone 2d1b7c1b6c codex: a workspace sharing Codex's sign-in reads and sends as its own workspace
JdAZzzzzz (X) has a personal Pro and a Team seat of one ChatGPT login in
magpie, and switches workspace in the Codex app. Both cards read the
same plan ("Prolite"), week, reset time, pace and two reset cards; only
the token counts (local sessions) differed.

Cause: one ChatGPT sign-in reaches every workspace of its login with
one refresh token. Codex's workspace routing (codex-rs
login/src/auth/manager/workspace_routing.rs, /wham/accounts/check)
changes which one auth.json names in tokens.account_id. rememberLogins
saved each workspace as an account (codexWho goes by account_id), both
with that refresh token. renewSaved found the account not in use "held
by Codex" (heldByCodex: same refresh token), renewed through Codex's
store as it should, and returned that store's account id too: the
workspace Codex is on. So the other account's usage, plan, resets and
the gateway's requests for it named the workspace in use, and spent it.

- renewSaved returns the saved account's own workspace for a token read
  where Codex holds the sign-in, in ~/.codex and in another Codex folder
  (codexOwnWorkspace).
- A sign-in sync put Codex's auth.json on every record sharing its
  refresh token, so the other workspace's record was carried as the one
  in use. liveCodex and applyLogins no longer match by refresh token
  when the workspaces are known apart (codexWorkspacesApart).

TestCodexAppWorkspaceSwitchReadsEachWorkspace: one sign-in (same
refresh token, the real token's claim layout), the app's switch with
only account_id rewritten or with the tokens naming the new workspace,
Codex left on either one. On the old code all 4 cases are red with the
report's picture ("jd@example.com · ws-team (ws-team) reads plan
"prolite" ... 2 resets; its workspace has "team" ... 0 resets"), the
account's requests signed for the other workspace, and CollectSignIns
carrying each record as the other workspace. Green with the change.

Run at 9a00bfed1 (origin/main) plus this change, on mote (macOS):
- gofmt -l internal/provider: nothing
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of
  internal/provider; go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: ok
- go test -count=1 ./internal/provider: ok (134s)
Not run: go test ./... (mote's suite.lock queue had five suites ahead;
shipped without holding behind it).
Not tried: a real Team seat (no such account here); that ChatGPT's
backend honours chatgpt-account-id for a token whose claim names the
other workspace is what Codex's routing does, not checked by hand.
Not changed: once Codex rotates the shared refresh token, the other
workspace's saved copy holds a spent one (#5779).
2026-11-09 17:13:17 +08:00
yetone 93bbcc8bfb gateway: a Responses conversation another resource made goes whole, without its item ids
hykql (Discord) uses Azure OpenAI behind a relay that spreads one key
over several resources. A turn after the first was answered by another
resource, which turned it away: "The requested item was created under a
different Azure OpenAI resource. Use the same resource that created the
item to access it." prevRefused only knew "previous_response", so the
400 reached the client, and sending the conversation whole would not
have helped: the items magpie brings back still carry the first
resource's ids.

- prevForeign knows that refusal. A request whose conversation magpie
  holds is asked once more, whole, with the ids of the items magpie
  brought back taken out (prevElsewhere): an item that may go without
  its id (idOptional) loses it, reasoning stays only with its
  encrypted_content, the client's own new input is as sent. Nothing is
  asked again when magpie doesn't hold the conversation, or when the
  body would be the same, so an unknown previous_response_id is still
  relayed as sent and its refusal passed on.
- A kept turn remembers the provider and key whose reply it is (made).
  Going on with another one, those ids are left out at once: it never
  made them. The same provider and key gets them as before.
- No setting and no GUI. This is the part of hykql's branches
  (feat/responses-state-client-profile, feat/provider-editor-responses-
  state) the review kept; their retry stripped previous_response_id from
  a delta magpie doesn't hold (a 200 with the history gone), and their
  client profiles included Claude Code's User-Agent. Neither is taken.

Run on mote (lockf ~/suite.lock mote-run), at c7ebb6f8d plus this change:
- gofmt -l internal/gateway: clean.
- go vet ./internal/gateway on darwin, GOOS=linux -tags nogui, GOOS=windows: ok.
- The three new tests and the existing previous-response tests: ok.
- Broken by hand: prevForeign returning false turns
  TestPreviousResponseOtherResourceDeltaSentWhole and
  TestPreviousResponseOtherResourceWholeSentWithoutIDs red; stripping
  only when forced turns TestPreviousResponseToAnotherProviderSentWithoutIDs red.
- go test -tags nogui -timeout 45m ./internal/gateway: ok (859s).
- Again at the rebased head (on 608c1543e): gofmt clean, the three vets ok, ./internal/gateway ok (873s).

Not tried: a real Azure resource pair. The refusal text is the report's
and hykql's own fixture, not reproduced. Whether Azure takes one
resource's encrypted_content on another is not known; if it refuses it,
the refusal reaches the client as before.

Reported-by: hykql (Discord)
2026-11-09 16:55:21 +08:00
yetone b475004d52 library: Pi's extensions and packages, switched and copied between Pis
leokon3 runs Pi on Windows and in WSL and asked for magpie's Library to
manage Pi's extensions and packages. A new "Pi packages" tab in the
Library lists each Pi here (this computer's and each WSL distro's), with
the extensions and packages it loads, read by Pi's own rules
(@earendil-works/pi-coding-agent 1.4.0). Each has a switch, written as
`pi config` writes it, and a "Copy to…" menu for the other running Pis.

- A package is copied as its settings.json entry; Pi installs it itself
  when it next starts. node_modules is never copied. A local package, and
  one the other Pi already has by Pi's identity (npm name, git host/path),
  is refused.
- An extension file or folder is copied as files, without node_modules,
  .git or symlinks, never over one of the same name. The page says to run
  npm install there when it has dependencies.
- A package that already picks some parts (filtered in `pi config`) shows
  its switch disabled. A settings.json that can't be parsed lists nothing
  and is never written; a stopped distro is never started; every write is
  backed up first.
- GET/POST /api/library/pi, POST /api/library/pi/copy (notYet in the CLI
  parity list, stage 3: the library).

Run at 29d63e2dd (this tree on origin/main c7ebb6f8d; rebased after onto
608c1543e, which changes only internal/gateway), on mote:
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows on
  internal/library and internal/gui: ok.
- go test -tags nogui ./internal/library ./internal/gui ./internal/cli:
  ok, ok, ok.
- A real pi 1.4.0 (npm) in a sandbox HOME and PI_CODING_AGENT_DIR, through
  an uncommitted pireal test: pi -p loads hello.ts (a marker file), the
  switch turns it off (no marker) and on again; a todo folder copied from
  a second Pi's dir is loaded by the real pi; npm:pi-web-access@0.47.0
  copied as a settings entry was installed by pi itself into
  <agentDir>/npm/node_modules and read back as installed v0.47.0; switched
  off, `pi list` still lists it and magpie reads it off.
- GUI, 70 files (library-*, i18n-*, gui-* and the Library's neighbours),
  both engines: 1503 of 1515 pass. The 12 reds are the same on origin/main
  c7ebb6f8d: page-width-steady's 11 (run there alone, 11 of 20 red; #5013)
  and i18n-keys "a plugin's words are its own" for "Use the library's",
  "No session ID" and "View routing" (#5482, #5426, #5332).
  library-pi-extensions runs en, zh, zh-TW, ja and de at 980 and 380px.
On Windows (win-run): go vet with and without the pireal tag ok; go test
-run TestPi ./internal/library ok.

Broken by hand: the first run named the tab "Pi extensions", which a
comment in internal/provider/discovery.go says too, and i18n-keys went
red for it; library-loading went red for the new tab next to RTK while a
Pi is here; and TestEveryRouteHasACommandOrIsNamed went red for the three
routes. All three were fixed and pass in the run above.

Not tried: a real copy between a WSL Pi and the Windows Pi (the WSL side
is covered by the unit tests' fake distro only), the full go test ./...,
and the whole GUI suite.

Reported-by: leokon3 (Discord)
2026-11-09 16:33:28 +08:00
yetone 608c1543e8 gateway: a bare model name goes to the asking agent's own subscription first
freefcw on X: Codex, started by Mirasim, asked for gpt-6-astra by its bare
name. Its own ChatGPT subscription serves it, but magpie sent it to Devin
through the group it found (auto-gpt-6-astra, soonest renewal first).
With found groups off it still went to another vendor: Resolve takes the
first provider in the Providers order, AutoStandIn and agent.Reseat did
the same.

Now:
- A bare model id the asking agent's own subscription in magpie serves (a
  provider whose Account.Agent is the agent: Codex's ChatGPT accounts,
  Claude's for Claude Code, Copilot's) goes there, found groups on or off
  (gateway ownFirst, provider.OwnRoute). count_tokens counts it there too.
- Kept as they were: a group the user made or changed by that name; a found
  group magpie set one of the agent's fields to (agent.SetToGroup over the
  applied record, #750's bare spelling included, wired as
  gateway.SetToGroup); a gateway key held to some models; ids with a
  provider in them and group refs; clients magpie doesn't know as an agent.
- Found groups off: a bare id several providers serve, none of them the
  agent's own, is refused for an agent that has a subscription of its own
  in magpie, with a 400 naming the provider/model ids and
  "magpie group auto on" (provider.OffSpread). Off, magpie picks no vendor.
- AutoStandInFor and Reseat's sameModel prefer the agent's own
  subscription for a found group that is gone.

Docs: gateway-routing.md's Model resolution row and the bare-ids section.

Run (mote, at this tree on c7ebb6f8d):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/agent ./internal/cli ./internal/gateway: all ok.

Broken by hand, each red:
- ownFirst off in serve (and AutoStandIn back):
  TestBareNameGoesToTheAgentsOwnSubscription went to the relay with groups
  on, and again with groups off alone (the reporter's two cases).
- OffSpread check off: TestBareNameOnSeveralVendorsRefusedWhileGroupsOff
  answered 200 from the relay.
- SetToGroup check off: TestBareNameOfAGroupSetOnTheAgentStaysTheGroups.
- The user's-group and own-entry checks off: TestOwnRoute, TestOffSpread.

Not run at this head: the full ./... suite (mote's suite.lock had five
suites queued); it runs under the lock after the push, any red filed.
Not tried: a real Codex with a real Devin plugin account; Reseat's own
preference has no test of its own (needs a fetched Codex account in the
agent package's sandbox).

Reported-by: freefcw (X)
2026-11-09 16:28:02 +08:00
yetone c7ebb6f8d9 settings: Video generation picks the model Magpie Image makes videos with
The same Discord (#feedback) user: a custom provider's video model still
couldn't be chosen. A custom provider's video model was already found
(seedance, kling, veo, wan, hailuo ids by name, or marked by hand with
right-click › Makes › Video model, #1399), but generate_video always used
AutoVideomaker's pick, the first video model of the first provider, with
nowhere to choose another, as Settings › Images does for images.

settings.VideoGen (provider/model or a routing group) is now the model a
request that names none makes its video with, while it resolves; else
AutoVideomaker's, as before. Image generation turned off turns video off
with it, as before. Settings › Models › Images gets a Video generation
row under Image generation: Automatic (naming the automatic pick) and
every model Magpie Image can make videos with. A pick that no longer
makes videos (provider gone or off, model unmarked) says so and the
automatic one is used in its place; the settings API refuses a model
that makes none, and keeps the pick when a save doesn't send it.

The row is drawn by videogen.js, imported when Settings draws Image
generation, with one call in app.js: drawn in app.js it put the core
scripts 616 bytes over TestCoreScriptBudget (1,534,418 > 1,533,802, found
by the first full run), and the budget is not raised.

Run on mote:
- At this change on bceeabd93 (rebased onto c630d9a29, which changes
  only the gateway key page): gofmt -l clean; GOOS=windows go vet and
  GOOS=linux go vet -tags nogui of the changed packages: ok. go test -run
  'Budget|VideoGen|Videomaker|TestSettingsSave|TestKeysAreWhatTheSaveWrites'
  in settings, settingsapi, gateway, gui: ok. GUI: video-gen-pick
  (32 subtests: chromium and webkit; en, zh, zh-TW, ja, de at 1100px, en
  and zh at 400px), old-webkit, i18n-en-no-cjk and the six image/Settings
  files (image-timeout-setting, images-codex-one, images-library-way,
  images-missing, image-models-hide, image-mcp): 220 of 220 ok.
- At 95a3fa3e0 (the change before the videogen.js move and the rebase):
  go test -timeout 45m ./internal/settings ./internal/settingsapi
  ./internal/gateway ./internal/gui: ok except TestCoreScriptBudget
  (fixed above). i18n-keys at 4394ea1b9: only the known plugin-words red
  (#5332).
- Not run at this head: the whole of those four packages and the 183 GUI
  files a Settings change reaches; the suite lock on mote was an hour
  deep in other sessions' suites.

Broken by hand, each red:
- videomaker ignoring VideoGen: TestVideoGenPicksAMarkedModel.
- settingsapi not keeping a pick a save doesn't send:
  TestVideoGenCheckedAndKept.
- No Video generation row: video-gen-pick.test.cjs, 30 of 32.
- videoGen left out of the Settings page's prefsKeep:
  TestSettingsSaveKeepsWhatItDoesNotSend ("VideoGen: not sent by the
  Settings page"), found before it was added.

Not tried: a real video generation with a custom provider's model (the
gateway tests hold the vendor's replies).
2026-11-09 14:25:55 +08:00
yetone c630d9a29c gateway: the key page's Claude Code setup keeps each tier on its own family
The /me page's Claude Code tab wrote the picked model into
ANTHROPIC_MODEL and into ANTHROPIC_DEFAULT_OPUS_MODEL, _SONNET_ and
_HAIKU_ alike, so picking Opus sent every Haiku background call to Opus
too (and picking a GPT model made "haiku" a GPT model).

The pick now sets only ANTHROPIC_MODEL. /v1/magpie/me returns `tiers`,
built by keyPageTiers from the models this key may use: for opus,
sonnet and haiku, the newest model of that family (claudeTier and
claudeVersionOf; routing groups and fable are skipped). A tier the key
has no model for is left out of the snippet, so Claude Code keeps its
own default for it.

Siblings: the agent writer (internal/agent/claude.go) has its own tier
design (tiers follow the main model, haiku to the provider's Haiku, the
user's own tiers kept) and writes the user's real config; it is a
different situation and is left as is. OpenMausBot's snippet writes
only ANTHROPIC_MODEL.

Run (mote, via suite.lock):
- go test -count=1 -run KeyPage ./internal/gateway/: ok
- GUI key-page.test.cjs: chromium 13/13, webkit 13/13
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., and go build for darwin, linux (nogui) and
  windows: ok
Broken by hand:
- old keypage.html: the new GUI test is red in both engines
  (ANTHROPIC_DEFAULT_HAIKU_MODEL 'claude/claude-opus-5', want
  'claude/claude-haiku-4-5')
- keyInfo without keyPageTiers: TestKeyPageTiersAreTheirFamilys red
  ("tiers map[]")
Full suite (go test -tags nogui -timeout 45m ./...): queued behind
other sessions on suite.lock at push time; its result goes on the
follow-up, with an issue for any red.
Not tried: a real Claude Code against the page's snippet, and the
gateway binary in a sandbox HOME.

Reported-by: strinah (Discord)
2026-11-09 14:22:05 +08:00
yetone c81065ca72 providers: System One for a custom provider and Ark's pay as you go
A user on Discord (#feedback) found no System One endpoint under a custom
provider's More endpoints (OpenAI Responses), no System One choice in its
Model settings, and on the Volcengine Ark page neither an endpoint nor any
model a routing group could ask as its classifier.

System One is asked at POST …/systemone under a provider's Decide base;
a model is offered as a group's classifier only when its provider has
one. Two causes:

- A custom provider kept a Decide URL only when its API was "System One
  base URL". With a Responses or chat URL there was no field for it, and
  Save sent "" for one the provider didn't have yet. More endpoints now
  has "System One URL" for any API, saved as typed.
- Ark's pay as you go answers System One on the same key at
  ark.<region>.volces.com/api/v1, but a provider asked at …/api/v3 (the
  preset's or a custom one, chat completions or Responses) had no Decide
  unless the user knew to type it. normalize now sets it (arkSystemOne);
  a URL the user gave is kept. The Coding and Agent Plans answer System
  One 404, so they get none, and decideKeys leaves out a key whose plan
  has none (a Coding Plan key beside a pay-as-you-go one). Ark's one
  decision model is offered whatever chat models are picked, as
  Bailian's is (OfferedDeciders).

Run on mote at this head's tree (65aacb8f8, on e0f6eda64):
- gofmt -l clean; GOOS=windows go vet and GOOS=linux go vet -tags nogui
  of internal/provider, internal/gateway, internal/gui: ok.
- go test -timeout 45m ./internal/provider ./internal/gateway
  ./internal/gui: ok (provider 136s, gateway 849s, gui 131s).
- GUI: custom-systemone-url.test.cjs (chromium and webkit; en, zh,
  zh-TW, ja, de; 1200px and 420px), i18n-en-no-cjk, i18n-keys,
  editor-advanced-align: ok but i18n-keys' "a plugin's words are its
  own", red on main for three plugin words Go files also say (#5332,
  #5426, #5482). Earlier, at c9d253e4a, 30 GUI files a provider editor
  change reaches: the same red, and editor-advanced-align's two whole-run
  reds under load 670 (#4615), green alone and in the run above.

- Rebased onto 77076eef4 (four commits: a group editor's Advanced,
  Remote magpie cards, npm updates on Windows; none in these files' code
  paths): gofmt, both vets, go test -run 'Ark|Decide|Decider|Classif|
  SystemOne' of the three packages, custom-systemone-url and
  i18n-en-no-cjk: ok.

Broken by hand, each red:
- arkSystemOne returning "": TestArkPayAsYouGoDecides and
  TestArkDecisionSkipsPlanKeys.
- OfferedDeciders without the bailianApart exemption:
  TestArkPayAsYouGoDecides (the providers with chat models picked lose
  their classifier).
- decideKeys without the Decides filter: TestArkDecisionSkipsPlanKeys,
  "doubao-seed-2.1-lite asked with: [k-api … k-coding]".
- No System One URL under More endpoints: custom-systemone-url, every
  subtest.

Not tried: a real Ark account (the decision call is held to the
recorded reply); a provider whose main key is on the Coding Plan with a
pay-as-you-go key beside it gets no Decide, since normalize reads the
provider's own URLs.
2026-11-09 13:05:00 +08:00
yetone 08a42c40ff provider: a Remote magpie's cards are passed on down a chain of magpies
yuyong_id (Discord) chains three magpies through Remote: magpie1 has a
Codex subscription, magpie2 uses magpie1, magpie3 uses magpie2. magpie2
showed magpie1's Codex card; magpie3 showed none.

Cause: since 8c71cd27f a magpie told only its own cards
(CachedCards kept From == "") and the receiver skipped any card it was
told with a From (remoteCards). So no card from a remote, of any
provider, reached a third magpie; Codex wasn't special. Antigravity and
DeepSeek showing at magpie3 means magpie2 has those accounts itself
(not checked with the reporter).

Fix:
- CachedCards passes on the cards it already holds from each Remote
  magpie (passedOnCards, from the 30s cache: it asks no remote, and a
  held remote's cards stay home).
- Each card told carries Via, the magpies (catalog.Self) it passed
  through; a receiver leaves out a card that comes back to it or has
  passed more than MaxVia magpies (catalog.Loops, the same rule as
  magpie_via for models).
- Refresh on a passed-on card ("m1/codex" at magpie2) goes to
  RefreshUsage, which asks that remote again, instead of a 400.
- Sibling: the status line (KeptQuotaReport, /v1/magpie/quotas?kept=1)
  read CachedCards too, so a magpie's own Remote cards were missing
  from it; now there.
- A held key still sees only own cards (quotaScope unchanged).
- Codex's resets stay with the magpie next door only, as before.
- catalog.Self becomes a func with SetSelfForTest, so one test process
  can play magpie2 and then magpie3.

Run on mote at b9cdac0c6 (rebased on origin/main 8a7f77cb7):
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build ./...: ok.
- New TestRemoteChainPassesOnCards (magpie1 fake -> this gateway as
  magpie2 -> magpie3 reading it: Codex, Antigravity, GLM plan and a
  DeepSeek balance arrive, named "Codex · M1 · M2", Via [m1 m2],
  refresh reaches magpie1, a looped card is dropped),
  TestKeptReportHasRemoteCards and the updated TestRemoteMagpieCards,
  with TestRemoteMagpie*, TestRemoteSelf, Quota* and TestCachedCards:
  ok; -race -count=3 on the new and changed ones: ok.
- On origin/main with only these tests (and the Via field / Self func
  they compile against): all three FAIL. magpie3 gets just the
  "nothing read on that magpie yet" stand-in for magpie2, the kept
  report is empty, and the third magpie's card is nil.
- Full suite (-tags nogui -timeout 45m ./... under the suite lock):
  cut short when mote closed the connection, before any package
  reported. Rerunning at the pushed head.
- Rebased again onto origin/main e0f6eda64 (gateway changed): go vet
  of gateway, provider and catalog and the same targeted tests: ok on
  Linux (wsl-run magpie-desktop, -tags nogui); mote was refusing ssh.

Not tried: three real magpies on separate machines.
Not changed: a passed-on card's quota history (#5747).

Reported-by: yuyong_id (Discord)
2026-11-09 12:47:12 +08:00
yetone e0f6eda641 gateway: a probe's reply that thinks its 16 tokens and ends unsaid is answered (plugins#827)
Through a Remote magpie, the plain model test of Open Design's
glm-5.3-flash was red. The model always thinks. It spent the test's 16
tokens on that and ended after content_block_stop, with no message_delta
or message_stop. So:

- translate made it a 502 "ended before it was complete";
- the 502 is busy, so the remote retried it and waited out its 60s
  patience;
- the asking magpie had given the remote only 20s (testWait), and said
  no answer came.

Each step is now fixed for the class, not for this model:

- A reply whose request was capped at a short probe's worth
  (cutVoidTokens, 1024) and that spent some of it, then ended cleanly
  with nothing saying it ended, ended at its length (endsAtProbeCap).
  - This holds in translate, in streamTranslated and in gathered (a
    Responses plugin's stream asked whole becomes response.incomplete at
    max_output_tokens).
  - It covers Anthropic and Responses upstreams only. Gemini always
    ends with a finishReason, so a Gemini stream without one stays a cut
    (TestGeminiUpstreamEndedShort, asked for 256, caught a wider first
    draft).
  - A reply asked for more than 1024, or one that spent nothing, is
    still the 502.
- A client may say how long it waits (provider.WaitHeader,
  X-Magpie-Wait, in seconds). The gateway then takes no same-one retry
  pause and no patience round that would end within clientRoom (10s) of
  that wait (keptAlive.outlives), so the client gets the error while it
  still waits. Like every X-Magpie- header, it is not sent upstream.
- A model test through a remote magpie waits pluginTestWait (60s), as a
  plugin's test does here, and sends that wait as X-Magpie-Wait.

Not changed: a stream relayed as it came (passthrough to an agent of the
same protocol) still gets no end added. That is filed as #5736 and named
in gateway-routing.md.

Run, through mote-run:
- At the pushed tree, rebased on origin/main b68218f43 (802f03e68 after
  it changes only site/): go vet, GOOS=windows go vet and GOOS=linux go
  vet -tags nogui of internal/gateway and internal/provider are ok. go
  test of both packages with -run
  "ProbeCap|Gathered|ClientWait|RemoteMagpie|EndedShort|Gemini|SingleProvider|Responses|Enum|Group|Spent|Capped|Patience"
  is ok. That covers the base's new Responses-enum and group commits.
  At 8a7f77cb7 the same kind of run, with Compact|Signin|Carry for that
  base's commits, was ok.
- Full run at 9c34dc7cb (the same change, rebased on origin/main
  e2afbfc15): go vet
  ./internal/..., GOOS=linux go vet -tags nogui ./internal/..., and
  GOOS=windows go vet ./internal/... are ok; go test ./internal/gateway
  ./internal/provider -timeout 45m: provider is ok; gateway is ok
  except TestCodexGeneratedImagesPastOldLimit (#5281: held 31s
  without routing in a full run; at this head it passes alone, 3 of
  3, with -count=3)
- At 32a31963b, the first draft: go vet ./..., GOOS=linux go vet -tags
  nogui ./... and GOOS=windows go vet ./... were ok; gofmt -l was empty.
  The suite there:
  - TestGeminiUpstreamEndedShort was red. The rule was too wide, and it
    is scoped above.
  - TestCodexGeneratedImagesPastOldLimit was red: #5281, the
    images-body hold, not on these paths.
  - TestCodexListTagNotKeptOverAFreshFile was red: #4216, under load.

Broken by hand, then put back:
- endsAtProbeCap returning false:
  - TestProbeCapEndsAtLength goes red, both whole (502 ended before it
    was complete) and stream (no finish_reason length).
  - TestGatheredProbeCapIncomplete goes red (capped 16: 502).
- outlives returning false: TestClientWaitBoundsPatience/short_wait goes
  red (upstream asked 6 times).
- probeOnce's remote-magpie wait and header taken out:
  TestRemoteMagpieProbeWait goes red ("no answer in 1s", X-Magpie-Wait
  said "").

Not tried: a real Open Design account, and a real two-magpie Remote
setup. The fixture is the reporter's described ending (thinking block,
content_block_stop, close), not their captured bytes.

Reported-by: Gitleonan
2026-11-09 12:42:35 +08:00
yetoneandcrayon b68218f43e gateway: a Responses reply to a client that isn't Codex carries only the Responses enum's events (#4482)
Grok Build, reading /v1/responses through async-openai's typed
ResponseStreamEvent, lost whole turns on a ChatGPT account: the backend
speaks part of the Codex protocol (codex.rate_limits,
codex.response.metadata, response.metadata, a keepalive event), and the
client read each as `unknown variant` and ended the turn.

passthrough now runs responsesEnumTidy (responses_enum.go) last in its
chain for a Responses stream to a client that isn't Codex (the
fromCodex / agentOf pair codex_own_v1.go uses): every event whose
`event:` name, or data `type` where it names none, is outside the OpenAI
Responses enum is dropped; a keepalive goes on as an SSE comment so a
quiet upstream still keeps the client's idle timer alive. sniff and
codexLimitsTap read the upstream bytes before it, so failover and the
account's windows are unchanged. Codex itself gets every event as it
came. A plugin's Responses reply goes through the same passthrough, so
it is covered too. The WebSocket route's synthesized header frames
(socketTurnWriter.headerFrames) go to Codex alone too.

The response.failed shape from the report (missing created_at /
sequence_number) was already fixed on main by 29bfd5dc8 (plugins#852);
crayonlu's test for it is kept.

Ported from crayonlu's codex-lead-events branch (917878484, four
commits), with the keepalive comment and OpenAI's audio events added to
the enum.

Run (mote, macOS arm64, Go 1.26.8):
- focused: TestResponsesEventsOutsideTheEnumStayWithCodex,
  TestResponsesEnumAllowed, TestPassthroughResponsesEndsShort,
  TestSocketHeaderFramesOnlyForCodex, TestCodexSocketServed,
  TestResponsesEventsAreClientShaped: ok.
- broken by hand: gateway.go and responses_ws.go back to origin/main
  with the tests kept: both foreign clients red (codex.rate_limits,
  codex.response.metadata, response.metadata, keepalive there=true, no
  keepalive comment) and the socket test red with the leaked frames;
  the Codex cases stay green.
- gofmt -l clean; go vet -tags nogui ./internal/gateway on darwin,
  GOOS=linux and GOOS=windows ok.
- go test -tags nogui -timeout 45m -count=1 ./internal/gateway: ok
  (2186s), at this tree on origin/main c9d253e4a.
- rebased on 44d6dd75d (gateway.go changed upstream): the focused
  tests above with the new cap/group tests (TestCapGroup*,
  TestCodexOneAccountSpent*, TestPluginCapPool*) ok; vet ok.
Not tried: a real ChatGPT account with Grok Build (a second sign-in can
rotate the live refresh token); the full ./... suite (mote at load ~760
with a long suite-lock queue).

Reported-by: crayonlu
Reported-by: Jeo-Meek
Co-authored-by: crayon <hicrayon@outlook.com>
2026-11-09 12:36:18 +08:00
yetone 44d6dd75d1 gateway: a subscription's capped or spent turn goes on to the user's group with it in
adorable_piglet on Discord (v0.1.3354): a Codex subscription with a usage
cap set in magpie, first in a routing group with two APIs after it. Past
the cap the Codex app's turns were answered 429 "usage cap reached" and
never reached the APIs; only switching the subscription off in Providers
moved them.

Cause: the Codex app signed in to ChatGPT asks Codex's own model
("gpt-5.5"), never "group/<id>". With a cap on the account,
codexAccounts routes the turn as codex/gpt-5.5, and serve plans the
codex provider and its own Fallback list only. A group that merely has
codex/gpt-5.5 in it was never planned, so with every account held the
answer was cappedError's 429. A request for the group itself was already
routed on past the cap (TestCappedSubscriptionGivesWayInGroup, green on
the old code too). The same gap was on Codex's own sign-in out of its
allowance at OpenAI: codexFallsBack counted the subscription's Fallback
only, so the backend's usage_limit_reached reached Codex.

Fix:
- provider.GroupsAfter(id): the routing groups the user built that have
  the model in them and another member to go on to, in the user's order;
  auto groups, hidden or switched-off ones are none.
- serve: when every account is held at its cap (pl.capped, no candidate
  left, CapStop off), or for a turn codexFallBack handed on, the provider
  is planned again with those groups after its own fallbacks
  (groupsAfter), each group routed as a request to it is. One place, so
  it holds on every protocol (chat, responses, messages, Codex's backend
  path), streaming or not, and for plugin-served subscriptions.
- codexFallsBack counts those groups as fallbacks too.
- Stop at the caps (CapStop) still answers 429 (planPaused returns
  before any fallback, the groups included).

Tests:
- TestCappedCodexOwnModelGoesToItsGroup: backend path with "gpt-5.5" and
  /v1/responses with "codex/gpt-5.5", stream and not; red on origin/main
  3cabaab54 (4 of 4, 429 usage cap reached).
- TestCodexOneAccountSpentGoesToItsGroup: one ChatGPT account, the
  backend's usage_limit_reached, group [codex/gpt-5.5, a/m].
- TestPluginCarefulPool: the fake plugin as Factory through a real
  plugin host, both accounts past their caps, no fallback, group
  [factory/fake-1, spare/m2]: 429 with Stop at the caps on, the API with
  it off.
- TestCappedSubscriptionGivesWayInGroup (11 routings x 4 paths) and
  TestSubscriptionCappedMidConversationGivesWay pin the group/<id> case.

Broken by hand (each through mote-run):
- the serve block off: TestCappedCodexOwnModelGoesToItsGroup 4 of 4 red
  and TestPluginCarefulPool red ("group, stop off: 429").
- GroupsAfter out of codexFallsBack: TestCodexOneAccountSpentGoesToItsGroup
  red (429 usage_limit_reached).
- the handedOnOf arm out of serve: the same test red.
- the !p.CapStop guard out: still green, since planPaused itself returns
  before fallbacks with CapStop; the guard only saves a second plan.

Run at this tree (mote-run, mote under load from other sessions):
- gofmt -l . empty; go vet (darwin, GOOS=windows, GOOS=linux) of
  internal/gateway and internal/provider ok.
- go test -timeout 45m -count=1 ./internal/gateway ./internal/provider:
  provider ok (673s); gateway FAIL (2545s) on TestBurstTellsNoSpeed/
  responses_from_chat_burst alone (5000 tokens in 1091ms read as a
  speed), a timing red under load, ttft untouched here; 3 of 3 green
  alone at this tree, noted on #2719 (the same test's chat_burst).
  That run was at base 3cabaab54.
- Rebased onto origin/main 8a7f77cb7 (9 gateway/provider files changed
  there): gofmt empty, go vet ok, and go test ./internal/gateway -run
  "Cap|Capped|Fallback|TestCodexOneAccount|TestPluginCarefulPool|
  TestSubscriptionCapped" ok (199s) at the pushed tree.

Not tried: a real Codex app and ChatGPT account past a real cap (fakes
only). Not covered: an account that crosses its cap in serve's near-cap
walk (planned with room, held at its turn) still gets the 429 for that
turn; the next turn is planned with it held and goes to the group.
Drawing (images) and embeddings keep their own planning and are
unchanged. No GUI change.
2026-11-09 12:31:00 +08:00
yetoneandggbdpq 8a7f77cb71 provider, plugin: a sign-in whose refresh token rotates is never carried (#5583)
With Sign-ins ticked in Sync, a MiniMax Code sign-in went to both of the
reporter's computers. MiniMax spends a refresh token once: each computer
renewed it as it came due, the loser got invalid_grant 400 and was
signed out for good, with no newer generation anywhere in the sync path
to come back from. Qoder spends its refresh tokens once too.

The safest rule is that such a credential has one owner: it is never
carried. The auth hook declares `rotating` beside keepAlive and
refreshLead; the host passes it in the providers' row (Provider.Rotating),
and the carry path honours it: CollectSignIns leaves such sign-ins out of
what a backup or sync carries, and records() leaves out one an older file
carried, so MergeSignIns neither takes one in nor sends one up, and
RestoreSignIns writes none. Since the plugins don't declare it yet, and
the plugin host's list may not be read when a sync runs at start, magpie
also knows MiniMax Code (minimax-code, minimax-code-global) and Qoder
(qoder, qoder-cn) as rotating (rotatesKnown, read from their sources).
Nothing is deleted: local sign-ins stay, and a copy already on the server
falls out of the carried set by the usual removal.

The tradeoff, on purpose: each computer signs in to these itself. The
reporter's "relay" (carry one generation chain, re-read the store before
declaring a sign-in dead) would keep cross-computer sync for them; it is
a design of its own, not this fix, and stays open on the issue.

Ported from ggbdpq's patch on the issue, with rotatesKnown added so the
rule holds now and before the host lists its providers.

Run:
- TestCollectSignInsLeavesARotatingSignInOut,
  TestMergeSignInsDoesNotTakeARotatingSignInIn,
  TestRestoreSignInsLeavesARotatingSignInOut and
  TestKnownRotatingSignInsStayWithNoPluginListed (new): all four red on
  the old signins_carry.go ("a rotating sign-in is carried", "put in
  here", Added:1, "minimax-code's rotating sign-in is carried"), green
  after.
- go test -tags nogui ./internal/provider/ -run 'SignIns|Rotating' on mote.
- gofmt -l on the changed files: nothing.

Not tried: the two-computer race with real MiniMax Code or Qoder accounts.

Reported-by: skalitz-wolf (yetone/magpie#5583)
Reported-by: gua2100 (Discord)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-09 12:04:20 +08:00
yetoneandggbdpq 3480f822c5 library: an apply over a library that lost its instructions leaves the agents' parts alone (#5709)
Starting v0.1.3327 applied the Library at launch while it was empty, and
the apply wrote that over nine agents' instruction files: zcode's lost
magpie's part, and codex's, kimi's, opencode's and dsh's AGENTS.md were
deleted whole, with nothing asked or logged. library.json then recorded
hash("") for every agent. syncInstructions fell through to
withBlock(file, "") and, for a file with nothing of the user's outside
the part, edit.Remove.

Now:
- An automatic write (Sync: at a start, and beside a change) that would
  write nothing over a part while the library has no instructions to
  give anyone (no agent ticked, or no shared text) leaves the part where
  it is and logs a line per agent, naming a record whose last write
  hashes empty. The reporter's library.json had both. Only the page's
  own write (changeInstructions) takes parts back; a text still held
  with one agent unticked takes back as before (TestWSLStoppedInstructions).
- An automatic write never removes a whole instructions file; it empties
  it in place. The page's write keeps the removal, with the backup first.
- A set's or an agent's extra text that is there but can't be read
  (readText swallowed the error) is a Problem, never an empty text: an
  unreadable set file no longer cuts parts down, on the page's writes too.

Siblings left: syncMCP, syncHooks, syncSkills and syncSubagents take back
by Applied record what magpie wrote (config entries and links that the
library and market can give again, not prose), and a library reset that
loses their lists loses those records too. The sync chain (an empty part
coming down from another computer) is #5642's commit.

Ported from ggbdpq's patch on the issue, with the guard widened from
"no shared text" to "no agent ticked or no shared text" and the
unreadable-text check added.

Run:
- New tests in internal/library/empty_library_test.go, all red on the
  old instructions.go/sync.go (part cut to the user's own lines, or
  "deleted whole by the apply"), green after:
  TestEmptyLibraryApplyLeavesAgentsFilesAlone,
  TestEmptyTextApplyLeavesTickedFilesAlone,
  TestApplySaysWhyItLeftAPartAlone,
  TestUntickedLibraryApplyLeavesFilesAlone (agents unticked, text kept:
  red under the original patch's guard too; the page's untick still
  takes back), TestUnreadableTextLeavesFilesAlone (set file mode 000).
- go test -tags nogui ./internal/davsync/ ./internal/library/ on mote.
- gofmt -l on the changed files: nothing.

Not tried: the reporter's v0.1.3327 upgrade that emptied the index.

Reported-by: lennonli (yetone/magpie#5709)
Reported-by: gua2100 (Discord)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-09 12:04:06 +08:00
yetoneandggbdpq f411bd304c davsync: a part the server file holds nothing in never empties a joining computer (#5642)
Three computers syncing the Library alone: the main one's providers and
routing groups were gone minutes after it joined. An empty computer had
written the folder's file first, and a join takes the remote setup whole,
so its empty providers, groups, settings and library cleared what the
joining computer had (mirror, displaced copy kept in the sync folder).

On a join (no last sync on record), a part the server file holds nothing
of its own in (unset: no providers or groups, the default settings, no
profiles, an empty library) is the folder never having had one, not a
removal: a computer with that part set up keeps it and sends it up.
After the join an emptied part is a removal and spreads as before. The
check is on content, not a hash of an empty bundle: a fresh computer
writes the default settings and an empty-but-present library, which a
nil-bundle hash misses. Agents (which agents a computer has) are left
as they were.

Not changed: providers, settings and profiles still have no tick of
their own; with the Library ticked alone they still sync. A tick per
category is a feature of its own, not this fix.

Run:
- TestSyncEmptyFirstKeepsLaterSetups (new): red with the new case
  disabled ("a after joining's providers: []"), green with it; it walks
  b-empty-first, a joining with a provider, a group, a theme and an MCP
  server, b taking them (key kept on a), a keeping them, and a removal
  after the join reaching b.
- go test -tags nogui ./internal/davsync/ ./internal/library/ on mote.
- gofmt -l on the changed files: nothing.

Reported-by: tan-yong-sheng (yetone/magpie#5642)
Reported-by: gua2100 (Discord)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-09 12:04:06 +08:00
yetone dc098c1e82 library: a skill from a folder follows GitHub once installed from there (biubiu8802 on X)
biubiu8802 (X, 2119602075864903924) downloaded a skill from GitHub and
put it in the Library from its folder, so it had nothing to update from
and no way to link it to GitHub. Installing it from its GitHub link now
links the two, the way an update of a CC Switch skill already does: the
library's skill by that name takes GitHub's files and GitHub as its
source. A check and an update cover it from then on, and the agents'
links keep pointing at it. When its own files aren't GitHub's, they go to
the backups like UpdateSkill's replace does, and the result says so. A
folder of the user's it was linked to stays as it is.

followsHere (skill_link.go) decides it. It links only a skill with no
remote source that wasn't renamed and is that skill: it traces to this
repository (CC Switch, the skills CLI's lock, a git checkout, From), or
it traces nowhere and its SKILL.md has the same description as GitHub's,
as an older download of it does. One traced to another repository, or
an untraced one that describes something else (mora1n's case,
TestInstallSetPutsAnotherByTheSameNameBeside), still goes in beside it
(skill_beside.go). A had skill with
the same files and no source is bound to the GitHub source it was found
in, so a later install of another repository's skill by that name goes
beside it, not over it (TestSameFilesByNameAreHad).

The probe marks such a candidate links:true. The GUI's Add list tags it
"links to GitHub" with a tooltip, and the report names "updates from
GitHub now" and "files of their own kept with the backups". The TUI's
probe list and result line say the same. The new strings are in zh,
zh-TW, ja and de.

Run on mote (macOS), on 64ecd0f69, then rebased on 8a58c0e30, whose
new commits touch none of internal/library, the TUI's library or the
library page:
- gofmt -l clean; go vet ./..., GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=linux go build -tags nogui
  ./..., GOOS=windows go build ./... all ok
- go test ./internal/library/... ok at this tree; ./internal/tui/...,
  ./internal/cli/... and ./internal/gui/ ok at the tree before the
  description check (that change touches internal/library only)
- GUI (chromium + webkit, 5 languages, wide and narrow):
  skill-install-link (new), skill-install-beside, skill-install-skip,
  skill-install-agents-all, skill-git-source, skill-too-big,
  provider-discovery, i18n-en-no-cjk pass. i18n-keys' "a plugin's words
  are its own" is red on main for three strings this change doesn't
  touch, already filed: #5332/#5327 ("View routing"), #5482 ("Use the
  library's"), #5426 ("No session ID").

Broken by hand: without the description check (the first version),
TestInstallSetPutsAnotherByTheSameNameBeside is red (caveman taken over).
followsHere returning false always turns
TestFolderSkillFollowsGitHub red (probed As:pdf-pro-biubiu) and
TestOwnSkillFollowsGitHubKeepsItsFiles red (linked [] kept []).

Not run: the full go test ./... suite. mote's suite lock had a queue
waiting up to 16h, so this change ran the packages it touches.
No real GitHub install either: the tests use a fake tarball server. Not
tried on Windows or Linux. The market's had-check (haveSkill) is
unchanged: a market skill with a folder copy by that name still counts
as had.
2026-11-09 11:29:51 +08:00
yetone 2a64b4bcb7 library: a skill router, one magpie-skills skill listing an agent's skills
Like the MCP router, for skills. With the Skills tab's new "Skill
router" switch on (off by default), each agent's skills folder gets
one skill of magpie's, magpie-skills, in place of a link of each skill
ticked for it. Its SKILL.md lists them, each with its description and
the path of its SKILL.md, and the agent reads that file when a task
fits. An agent then carries one skill's description in its prompt
however many the Library gives it.

- The entry is a link to <settings dir>/skill-router/<hash of the
  folder>/, which holds SKILL.md and a hidden .skills/<name> link of
  each listed skill (hidden, so Codex, OpenCode and Pi don't find a
  skill twice). Its description stays within 1024 bytes (Codex's
  limit), cut on a whole character.
- Every skill is listed unless it is kept direct (a button on the
  skill, or `magpie library skill router <name> direct`; carried by a
  sync), is only for the user to type (disable-model-invocation), is
  in ~/.agents/skills, is blocked, or the agent has its own by that
  name. Those keep their own links.
- An agent whose folder can't take it keeps every link, and the page
  says why: given copies, a live agent picking its own, the shared
  ~/.agents/skills, a Library skill called magpie-skills, or a
  magpie-skills of the user's (never written over).
- Claude Code 2.1.316 asks before reading outside its project, its
  skills folder too, so magpie adds Read rules for the entry and the
  folders behind it to permissions.allow, records them, and takes out
  only its own when they go (as permissions.deny does).
- The switch is this computer's alone; `magpie library skill router
  on|off` sets it from the CLI.
- Sessions count a routed read of .skills/<name>/SKILL.md as <name>
  (Claude Code, Alma, Droid), and calling up magpie-skills itself as no
  skill, so a use counts once.
- docs/subsystems/skill-router.md, with a row in the index.

Run at this tree (rebased on origin/main 8f74442e4), on mote unless
named:
- go test -tags nogui ./internal/library ./internal/sessions -count=1: ok
- go test -tags nogui ./internal/cli ./internal/gui: ok at bca122bf9;
  ./internal/gui again at 8f74442e4 (app.js changed there): ok
- node --test of every library-*, *skill*, i18n* and gui-* GUI file
  (96 files), in the Linux VM (wsl-run): mote's browsers didn't start
  while another session's simulators ran. 1678 pass, 11 fail at
  bca122bf9, every red also red on origin/main and filed: library-all
  WebKit (#4967), skill-where WebKit 400px (#5154), i18n-keys' plugin
  words (below), and library-own-folder under load, fixed here. The
  files this change touches, add-partners-shine and i18n-keys again
  at 8f74442e4: 111 pass, i18n-keys the 1 red.
- The router's row under the skill list moved four GUI tests'
  footing, fixed in the tests: remove-all-skills counted it as a skill
  (now rows of lists other than a hub's, as list-sort does);
  found-skill-pick-remove and library-pick-remove's reach only wheeled
  down from above the target, so a Select pushed under the sticky tabs
  or below the fold was never reached (now toward it, over the list,
  and the scroll at rest before the click, WebKit's settled a pixel
  late); library-own-folder's Playwright click scrolled the now
  taller page under load (now a click where the button is). Each red
  on the branch before, 22/22 or 14/14 after, twice.
- skill-router.test.cjs: 22/22 (chromium and webkit, 1100 and 420px,
  en zh zh-TW ja de)
- go vet -tags nogui, GOOS=linux and GOOS=windows: ok
- win-run (xiaomi-gpu) go test ./internal/library: ok but
  TestGoneAgentListedToTakeOut and TestCheckMixedServerEachSide, red the
  same at origin/main 6b0b7a96e and filed in #4115 (run at that
  base; nothing in internal/library has changed on main since). The
  router tests' expected rules were /C:/…; Claude Code's form is
  //c/… (claudePath), which the code wrote, so the tests now ask
  claudePath too.
- Broken by hand: routable returning true is red in TestSkillRouter (a
  skill for the user to type is listed); with the routerSkill check
  out of the sessions reader, TestClaudeRoutedSkillCounted is red.
- Real Codex 0.165.0, sandbox HOME, through the live gateway with no
  sign-in copied: a binary built from this change at 6b0b7a96e ran `library skill
  hand-over`, `skill agents secret-word codex` and `skill router on`;
  `codex exec "What is the project's secret word?"` read
  magpie-skills/SKILL.md, then .skills/secret-word/SKILL.md at the path
  given, and answered PELICAN-7319. `router off` put the skill's link
  back and removed the router's folder.
- Real Claude Code 2.1.316, sandbox HOME, through the live gateway on
  auto/gpt-5.6-luna: that binary wrote the router and two
  Read rules into settings.json (the user's "model" kept). "Check your
  skills for one that fits, then greet me." ran Skill magpie-skills,
  then Read .skills/greet-user/SKILL.md without asking, and answered
  with the skill's words. Without the rules that Read was refused
  (tried earlier with hand-written settings). Not tried on the Claude
  subscription route with this binary: there the live gateway drops a
  skill's body, which the gateway commit before this one fixes.

Known: Alma reads Claude Code's and Codex's folders too, so it may find
several magpie-skills (#5722, not tried with a real Alma).
i18n-keys is red on 3 keys that aren't this change's, the same
on origin/main (#5327, #5332, #5482, #5426).
2026-11-09 08:38:02 +08:00
yetone 5506c84437 gateway: a skill's body reaches the run with its Skill call's result
Claude Code answers a Skill call with "Launching skill: <name>" and sends
the skill's SKILL.md after the results, as a text block headed "Base
directory for this skill: …". Since d84f58fd2 (#5403) that text counts
as the agent's own (desktopNote), so it is no longer said to the run as
the user's, which was right, but nothing handed it to the run either:
on the Claude subscription route a model that launched a skill saw
"Launching skill: pdf" and never what the skill says. Every skill
launched through magpie's Claude subscription lost its body.

withSkillBodies appends each such body to its Skill call's result (two
skills at once each get their own), else to the result it follows, else
to the last; saidWithResults still leaves it out of the user's words.

Found with a real Claude Code 2.1.316 in a sandbox HOME against the live
gateway: a proxy between them showed the body in the request, and the
model answered as if it had none.

Run (mote, at this tree):
- go test -tags nogui ./internal/gateway -run
  'SkillBod|Desktop|TaskNotice|SaidWith|MidTurn|Notice' -count=1: ok.
- TestSkillBodyRealClaudeCode parses the request Claude Code sent
  (testdata/claude-code-skill-launch.json: its own bytes, trimmed to the
  launch turn, paths shortened) and checks what the run is handed.
- Broken by hand (withSkillBodies returning results as they came):
  TestSkillBodyReachesTheSkillResult and TestSkillBodiesTwoSkills red.
- go test -tags nogui ./internal/gateway -count=1 -timeout 45m: ok
  (1220.8s), at origin/main 6b0b7a96e. Rebased on 8f74442e4, whose
  gateway change is browser.go: -run
  'SkillBod|Browser|ClaudeSub|TaskNotice' ok.

Not tried: a real run through a gateway built from this tree (the
Claude subscription's sign-in would be refreshed by a sandbox copy).

docs/subsystems/claude-subscription-bridge.md says what withSkillBodies
does, beside withTaskNotices.
2026-11-09 08:38:02 +08:00
yetone 82ca554be9 routing: a provider's accounts routed In order give a conversation back to the first
CryptoSarom on X: with a provider's accounts set to In order, a
conversation that had moved to the second account (the first was
resting) stayed on the second once the first was ready again. Only a
group's members went back to the first; a provider's own accounts never
did, because inOrder was read from the group's routing alone.

- gateway.go: inOrder comes from the provider's routing, or the group's
  when the request is to a group.
- affinity.go: backToFirst compares accounts (who()) for a provider's
  own accounts. For a provider it overrides only a cache that would have
  kept the conversation (cacheHolds: worth keeping and still warm), so a
  cold or empty cache keeps its own "cold"/"new" label.
- plugin_factory_cap_test.go: "auto, cached on B" pinned the old
  stay-on-B behaviour; it now expects A, the first account, on purpose.
- GUI: the Routing affinity line for "order" without a group says the
  provider goes in order and the first is ready again (all languages).
- docs/subsystems/gateway-routing.md: the In order bullet covers a
  provider's own accounts.

Run on mote at this tree on aa3d11d5b; rebased onto c6702f462, which changes only context.css and its own GUI test: gofmt -l clean,
GOOS=linux and GOOS=windows go vet ./internal/gateway ok, go test
./internal/gateway -count=1 -timeout 45m ok (985s).
GUI: routing-affinity-order (new accounts case) and i18n ok in both
engines. i18n-keys "a plugin's words are its own" is red from three
strings not in this change, filed as #5332, #5426, #5482.

Broken by hand: inOrder := false turns
TestOrderedAccountsGiveTheConversationToTheFirst red (k1 k1 k1 k1, why
"cache"). Without cacheHolds TestForeignSealedItemsAfterAColdSwitch went
red (why "order" for a cold switch).

Not tried: a real account pair in the live app.
2026-11-09 05:42:44 +08:00
yetone c6bdc172a0 netguard: a fake-IP resolver's own AAAA beside its fake A is left out, not refused
jiezhengj (Discord, 11-08): under Clash Verge Rev's TUN (mihomo
1.19.33, enhanced-mode fake-ip, fake-ip-range 198.18.0.1/16) every
web_fetch of `magpie mcp search` answered "it is at a private address".
#2593 already lets a name whose every answer is in 198.18.0.0/15 through,
so that wasn't it. Clash Verge Rev writes dns.ipv6: true and
fake-ip-range6: fdfe:dcba:9876::1/64 into its default config (and fills
in 2001:2::/64 when IPv6 is on without one), and mihomo then answers
AAAA from that pool too (dns/middleware.go withFakeIP, read at
v1.19.33). The resolver's answer was 198.18.x.y beside fdfe:dcba:9876::z,
the ULA is private, a fake answer beside a private one is refused, so
every name failed.

netguard.FakePaired names that AAAA: an IPv6 address in fc00::/7 or
2001:2::/48 while the same answer holds an IPv4 one in 198.18.0.0/15.
It is dropped where Loon's paired AAAA is dropped (dropLoon in the
gateway's publicTransport, iconIPs for a provider's icon, the two
places that share netguard), and the fake A is judged and pinned in its
place. 2001:2::/48 (RFC 5180 benchmarking) joins Public's special ranges;
it wasn't covered by 2001::/32 and passed as public.

Why this opens nothing new: the AAAA is never dialled. What is dialled
is the fake A, exactly as when the resolver answered the A alone, which
#2593 already allows: an address in 198.18.0.0/15, which no host on a
normal network uses, so without a TUN it goes to the default route and
reaches the internet or nothing. A hostile DNS that pairs 198.18.0.9
with fd00::<a LAN host> gets the 198.18 address dialled, never the LAN
one. Through a proxy on this computer the proxy gets the name, as for a
pure fake answer; a hostile resolver could already give a proxy another
answer for that name than it gave magpie, so the pairing adds no route.
What stays refused (tests below): a ULA or 2001:2:: alone or beside a
real A, a fake pair beside 10.0.0.1 or ::1, a fake A beside a public
address, and ULA / 2001:2:: / 198.18 address literals.

Ran (on mote; whole packages at base f1a4b5751, the -run set, vet and
gofmt again after the rebase onto the next main):
- go test ./internal/netguard ./internal/provider ./internal/gateway
  -run 'FakePaired|FakeIP|Loon|Icon|Public|Fetch|Guard|Private': ok
- go test -timeout 45m ./internal/netguard ./internal/provider
  ./internal/gateway (whole packages): ok (netguard 0.2s, provider
  130s, gateway 838s)
- go vet for darwin, GOOS=linux and GOOS=windows on those packages,
  gofmt -l internal cmd: clean

Broken by hand: with netguard.go, image_fetch_guard.go and icon.go back
at origin/main, TestFakeIPWithItsIPv6Answer fails with the reporter's
own message ("couldn't fetch http://example.com/: it is at a private
address ..."), TestFakeIPRefusesTheRest lets http://[2001:2::7]/
through, and TestIconIPsLoon refuses fdfe:dcba:9876::5 + 198.18.0.5 and
keeps 2001:2::5. Green with the fix.

Not tried: a real Clash Verge Rev / mihomo TUN on mote or the Mac (the
answers are a fake resolver in the tests, nothing reaches the network);
sing-box's inet6_range is covered only as far as it is a ULA. Not run:
the full ./... suite (mote's suite.lock had five full runs queued).

Reported-by: jiezhengj (Discord)
2026-11-08 22:55:09 +08:00
yetone 7a56c83e72 gateway: a compaction Copilot sealed stays out of Codex's auto-review
echo_ts (Discord #feedback) runs Codex Desktop's turns on GitHub Copilot
through magpie, with Copilot's native compaction on, and Codex's
auto-review on its built-in codex-auto-review through the ChatGPT
sign-in. The guardian's review carries the conversation's history, so
after the first compaction it carried Copilot's sealed compaction item
too. A request for one of Codex's own models with no magpie Codex
account to route it is relayed to the sign-in as it came, and
codexInputAs keeps any non-magpie1: compaction ("OpenAI's own, for
OpenAI"), so OpenAI was sent Copilot's ciphertext and refused every
review: 400 invalid_encrypted_content "The encrypted content P4ih...bDU
could not be verified". After the next compaction, the new ciphertext.

The siblings: a side call routed through magpie (the auto-review set to
a magpie model, a subagent or a title on another provider's model)
met checkpointReaders, found no writer among its candidates and was
refused with checkpointError, so the review failed there too. A turn or
a /responses/compact on one of Codex's own models relayed to the sign-in
sent the seal to OpenAI to be refused (sealedCompact took a Copilot
writer for the sign-in's own and relayed it).

Now:
- compactionAside names the calls Codex makes beside the conversation
  with its history in them: the guardian (or anything asked on
  codex-auto-review), memory, subagent, title, description, thread
  summary, prediction and suggestion. In serve, when the writer of the
  sealed compaction isn't among such a call's candidates, it goes on
  without the compaction item (withoutCompaction, body and plain);
  instructions, developer/user messages, the turns since and their tool
  calls and outputs stay. The conversation's own turns are still held
  to the writer or refused saying why (#1099), unchanged.
- foreignToSignin: on the relay to Codex's own sign-in (codexBackend), a
  compaction magpie recorded as sealed by a provider other than the
  Codex subscription is never relayed. A side call goes without it; a
  turn or a /responses/compact is answered checkpointError, magpie's
  own explanation, with nothing sent to OpenAI. A seal with no record
  (OpenAI's own, compacted on the sign-in), one the codex provider
  sealed, and one whose provider can't be read are left as before.
No portable plaintext summary exists for a native compaction (only the
writer can read it), so the side call goes without it rather than with
a summary.

Run (on mote, through mote-run, at 9730e0199 + this change):
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/usage/: ok (gateway 926s, usage 35s)
- go test -run 'TestForeignCompaction|TestNativeCompaction|TestCodex'
  ./internal/gateway: ok, again after rebasing onto f1a4b5751
  (which changed internal/gateway: trace.go and others)
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  ./internal/gateway; GOOS=linux go build -tags nogui, GOOS=windows go
  build: clean; gofmt -l internal: clean

Broken by hand: with the three non-test files at 9730e0199,
TestForeignCompactionLeftOutOfAutoReview is red in 4 subtests: the
review through the sign-in gets the reporter's exact 400 ("The
encrypted content P4ih...bDU could not be verified ...
invalid_encrypted_content"), the review and a subagent on another
provider's model are refused "compacted natively by copilot@student",
and a gpt-5.5 turn and its /responses/compact sent Copilot's seal to
OpenAI.

Not tried: the reporter's real Codex Desktop, Copilot or ChatGPT
account; the shape is from their report (Copilot compaction item with
encrypted_content, guardian on codex-auto-review). A Copilot compaction
magpie has no record of (made before compactions.json, or older than
30 days) still goes to the sign-in as before. No full ./... run: mote's
suite lock has had full suites queued for 4h; the change is confined
to internal/gateway.

Reported-by: echo_ts
2026-11-08 22:33:12 +08:00
yetone f1a4b57511 agent: Claude Science goes back on magpie after its app starts its own daemon
shuitunlulu_ on Discord: after magpie connected Claude Science, it went
back off magpie. The daemon reads the gateway only from its environment's
ANTHROPIC_BASE_URL. The 0.1.72 app (Electron) attaches its window to a
daemon running; with none it starts its own (`serve --stdio
--adopt-install`, launch_context app-child) in its own environment, which
has no such variable. Its "let the app run it instead", and the offer it
makes once it updated past the daemon, stop magpie's daemon to do the
same. The keeper only started a daemon when none ran, so the app's stayed.

KeepClaudeScience now puts magpie's daemon back on the port the other was
on (stop, serve --detached with the variable) in three cases: a daemon
magpie didn't start, one started for the gateway's old address, or its
own older than the program installed (`--version`, asked again only when
the file changed). It does this only when status says no session runs
(active_frames and active_conversations 0; a status without them counts
as busy). It never touches one launchd or systemd keeps, and does it at
most three times an hour. It reads operon.lock every 10s and asks status
when the lock's pid changed or a minute went by.

Run:
- go test ./internal/agent (mote): ok 261s
- gofmt -l, go vet for darwin, linux and windows (mote): clean
- Real Claude Science 0.1.72 on mote, the keeper driven through a
  throwaway test (not committed) against the real claude-science:
  - App attached to a terminal daemon: status parsed (idle, terminal),
    the daemon was replaced on port 18481 and the new one has
    ANTHROPIC_BASE_URL. shell.log says "adopted daemon restarted
    (45446 → 89598) — following the successor", so the window carried on.
  - App opened with no daemon: it started its own (app-child, port 8000,
    no ANTHROPIC_BASE_URL in ps -E). The keeper replaced it on 8000 with
    the variable, and the app showed its "stopped from the command line"
    screen. Reopening the app attached it to magpie's daemon
    (ADOPT-RUNNING).
- Broken by hand, each red: no idle check (the busy and unknown-status
  cases), no retake cap, no version skew, no lock-pid trigger.

Not tried:
- The screen's "start it again in the app" button (read in main.js:
  runInvariant adopts the daemon running; reopening the app did the
  same).
- A daemon with a session running: one would need a Claude sign-in.
  The fake covers it.
- The Windows attach shell, and Linux.

Reported-by: shuitunlulu_
2026-11-08 22:30:07 +08:00
yetone 9bef67d420 gateway: Claude Code's and Codex's requests reach a Remote magpie as magpie's, so it takes X-Magpie-*
linkaww (Discord #feedback, Mac v0.1.3315 to a Docker remote v0.1.3288):
a capture showed X-Magpie-Claude-Cache-TTL reaching the remote on a
request whose User-Agent was claude-cli/2.1.319, not magpie/. The
remote takes X-Magpie-* only from a magpie's request (magpieAsks), so it
dropped the cache lifetime (Opus still 5m, Haiku 1h), the agent, the
computer (X-Magpie-Via), X-Magpie-User-Agent, and X-Magpie-Hops, the
guard that answers 508 when two magpies are each other's remote.

Cause: forwardOnce sets magpie's User-Agent for a Remote magpie
(userAgentFor, OwnClient), then #179's copy of Claude Code's headers
(p.Account == nil) put claude-cli/... back over it. Codex had the same
hole: its copy (codexClientHeader) puts codex_cli_rs/... on too, which
keepTurnAsks had already worked around.

Fix, on the sending side: after every copy, a request to a Remote magpie
goes with magpie/<Version> (forwardOnce). Decision, retrieval, image and
video requests already set it at their call sites and copy no client
header. On the receiving side, so a relay behind the remote that serves
only Claude Code or Codex still gets their headers: the remote knows
Claude Code by the User-Agent the near magpie named (claudeCodeAsks,
agentUA) for #179's copy, ?beta=true, the test-as record and Desktop's
move, and both copies put on the agent's User-Agent (agentUA), not the
magpie/ one that came in. Codex is known there by its originator, as
before. A key+URL provider that is not a magpie still gets Claude Code's
and Codex's own User-Agent (TestClaudeCodeHeadersReachAnthropicRelay,
TestRemoteMagpieClientHeaders).

The reporter's guess that this empties the remote's Usage > Sessions is
not borne out: with the bug the remote still recorded each call's
session id (x-claude-code-session-id was copied), only under agent
"claude-cli" with no via. Filed separately.

Run (on mote, mote-run, at this tree):
- TestRemoteMagpieTakesClientsHeaders (new): Claude Code and Codex
  through two in-process gateways to a relay. The remote is asked as
  magpie/, with X-Magpie-User-Agent; callerFrom on what it got reads agent,
  via, hops 1, the relayed UA and the TTL 5m picked in settings.json; the
  relay gets the agent's UA, originator, x-app and ?beta=true and no
  X-Magpie-*; the remote's record names the agent and a via.
  Red on the old gateway.go: UA claude-cli/codex_cli_rs at the remote,
  agent "claude-cli", via "", hops 0, ttl "".
- go test -tags nogui ./internal/gateway -run
  'Remote|ClaudeCode|Codex.*Header|UserAgent|ClaudeCacheTTL|Desktop|SawClient|TestAs|Hops|Loop': ok.
- gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway: clean.
Broken by hand:
- the magpie UA reset taken out: the new test red in both subtests
  (remote sent claude-cli/codex UA, nothing taken).
- the remote-side detection put back to fromClaudeCode(in) and the copies'
  UA left as it came: the new test red (x-app and ?beta=true lost,
  relay sent magpie/dev) and TestRemoteMagpieClientHeaders' three Codex
  cases red 403.
Not tried: a real Docker remote or a real Claude Code; the full suite was
not run at push (run after). The remote must update too for its relays
to send them as the agent: an older remote, asked as magpie/, copies no
Claude Code x-app, X-Stainless-* or ?beta=true to its relay, and puts
magpie/ over Codex's User-Agent there (it is known by its originator), so
a relay behind it that serves only Claude Code or Codex refuses until it
updates. The TTL, agent, via and hops need only this (sending) side.

Reported-by: linkaww
2026-11-08 19:10:30 +08:00
yetone d1f8d8aae7 agent: Cherry Studio adds magpie through its providers link (plugins#865)
Cherry Studio (CherryHQ) shows on the Agents page, and with
`magpie cherrystudio`, on macOS, Windows and Linux. Its row is the link
its main process takes, cherrystudio://providers/api-keys?v=1&data=, with
the gateway at <gw>/v1 as an OpenAI-compatible provider named magpie and
the named key agentKeyAt("cherrystudio"). Cherry Studio asks the user to
confirm it. magpie writes nothing into its store. "Added" is read
untouched from its 2.x database (Data/cherrystudio.sqlite, user_provider),
in the default userData and every one boot-config.json moved it to. A
database or boot-config that can't be read, or a 1.x userData (Local
Storage, no database), is unknown. The data is standard base64, because
Cherry Studio swaps raw + and / before parsing and back after. /api/open
lets that link through. aionui's database status is generalized into
dbStatus{has} so both apps share it. Icon: Cherry Studio's own logo, not
cherryin-color (a different product).

Run (mote, at this change on origin/main c66cdbea9; then rebased on
0f04dca6e and run again: vet of agent/gui/cli, Windows vet of agent/gui,
and the Cherry, AionUi, gateway-key and import-link tests, ok):
- gofmt -l clean; go vet ./internal/agent ./internal/gui ./internal/cli;
  GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- go test -tags nogui -count=1 ./internal/agent ./internal/gui
  ./internal/cli: agent and cli ok; gui ok but TestCoreScriptBudget, red the
  same on a clean c66cdbea9 (#4526, 1533856 > 1533802)
- node --test import-row.test.cjs i18n-keys.test.cjs: import-row 20/20,
  chromium and webkit, en/zh/zh-TW/ja/de, and 420px wide; i18n-keys red
  only on "a plugin's words are its own", the same on clean c66cdbea9
  (#5332, #5426, #5482). No new strings.
- TestCherryStudioLinkParsedAs2_1_10 runs the link through 2.1.10's own
  parser (copied into testdata) and the renderer's zod checks, with
  gateways whose base64 spells + and /.
- Real try on mote (macOS 27.2, arm64): released Cherry Studio 2.1.10 in a
  sandbox HOME and --user-data-dir, with a sandbox magpie of this tree on
  127.0.0.1:3561 and a fake upstream. `magpie cherrystudio add` opened the
  dialog with base URL http://127.0.0.1:3561/v1 and the key
  magpie-cherrystudio. Add saved it, turned off as every Cherry provider
  is. `magpie cherrystudio` then said added, read while the app ran (WAL).
  Sync models listed fake/fake-1 from the gateway, and adding it turned
  the provider on. A chat got the fake upstream's reply, and magpie usage
  counted it as Cherry Studio's. A link sent while the first-run welcome
  page was up showed no dialog; after "set up later" it did.

Broken by hand, each red, then restored:
- URL-safe base64: TestCherryStudioLinkParsedAs2_1_10 (baseUrl decoded as
  /x~>/v1 and /xy\x7f?/v1)
- no closing quote/slash on the address match: TestCherryStudioHas
  (another port's provider counted)
- the /api/open prefix dropped: TestCherryStudioImportRow
- Cherry Studio dropped from /api/open's app case:
  TestImportLinkNothingOpens

Not tried: a real run on Windows or Linux (detection is unit tests
only); Cherry Studio 1.x, which reads as unknown; a real vendor upstream
(the try used a fake). Full suite not run at push.

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

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

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

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

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

Reported-by: Chapin2018
2026-11-08 18:24:16 +08:00