Commit Graph
849 Commits
Author SHA1 Message Date
bbornandClaude Opus 5.5 ae7dc10ae2 docker: the image is Debian 12 slim, so the Cursor and Devin CLIs magpie installs at sign-in run in it (#2834, bborn2)
magpie installs a subscription's CLI at sign-in with its vendor's
`curl … | bash` (internal/provider/install.go: Cursor, Devin, Grok
Build). The distroless image had no curl and no /usr/bin/env (the
installers' shebang), so that install couldn't run there, and only
Grok Build had a native fallback. bborn2 reported that a Cursor CLI
installed by hand failed with "cannot execute: required file not
found". The image is now debian:12-slim with ca-certificates and
curl. It keeps the nonroot user at uid/gid 65532, HOME and XDG under
/config, the healthcheck, and magpie on PATH. Size: 157MB against
82MB for origin/main's image, both built here on arm64. Running a
feature magpie offers is worth the 75MB.

Changed in review: dropped the branch's GOPROXY build arg, a separate
goal. The comments in install.go and install_test.go that said the
image has no curl now say "had". docs/reference.md and the site's
Docker page (en, zh, ja) say Debian with bash and curl instead of
distroless with busybox.

Run, with OrbStack's docker:
- docker build of this tree and of d783df46c's Dockerfile: 157MB vs
  82MB.
- docker run of the new image: health "healthy", user nonroot (id
  65532). `curl https://cursor.com/install -fsS | bash` exit 0, then
  `~/.local/bin/cursor-agent --version` printed 2026.10.16-e3cb207.
  Devin's install.sh installed devin v3000.11.92 (its trailing
  `devin setup` said "Login canceled" with no terminal, as on any
  host). `devin --version` printed 3000.11.92. bash and `magpie
  version` run.
- Old image: `which curl` finds none, and /usr/bin/env doesn't exist.
- A volume written by the old image (file owned 65532) was read and
  written by the new image.
- gofmt -l clean; go vet darwin, linux (nogui) and windows clean.
- Full `go test -tags nogui -timeout 45m ./...`: every package ok
  except internal/agent and internal/gateway, which timed out at 45m
  mid-test (TestConnectSaysHow, TestLargeRequestEndpoints) under a
  load average of about 200 from parallel suites. This commit changes
  no code those packages build, only comments in internal/provider,
  which passed (992s), so they weren't rerun.
Not tried: a Grok Build install inside the image, and a full
in-magpie Cursor/Devin sign-in with a real account in the container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 00:19:53 +08:00
yetone d783df46cb plugin: a plugin's page adds items to a provider's and an agent's row menu (P6)
package.json's magpie.actions: [{id, menu, title, titles}] puts items in
the row menus magpie draws, after its own: a provider row's (right-click)
and an agent row's (its handle, or right-click). Picking one opens the
plugin's page and posts it {event: "action", data: {id, provider|agent:
{id, name}}}, nothing else of the row; the bridge's magpie.onAction(fn)
gets it, and an action picked before fn was given waits for it.

- plugin.Window reads them (page.go): menu one of ActionMenus (provider,
  agent; a session's menu is left out, its title is user content), id
  ^[a-z0-9][a-z0-9-]{0,39}$, an id given twice is the first's, 8 at most,
  none for a plugin with no page.
- /api/plugin-pages carries them on the page; a missing title is the
  page's, in each language (pluginpage.go).
- pluginpages.js: magpie.actions(menu, context) gives the row menu's
  items; openRowMenu draws a plugin's name as written (literal), not
  through t().
- The Plugins page says which menus a plugin adds to (actionsLine),
  translated in zh, zh-TW, ja and de.
- Docs: plugin-runtime.md's P6 section and verification; the site's
  plugin docs (en, zh, ja) gain "Items in magpie's menus".
- The core's budget (TestCoreScriptBudget) is not raised (#2710): with
  P6 the core came to 1,447,648 bytes, 648 over. pluginpages.js's header
  now says P5's and P6's part in one paragraph and points to
  plugin-runtime.md, which says it in full, and plugins.js's panels and
  actions lines share whereLine: 1,446,845, 155 under.

Run:
- Full: this series (P5, the Plugins dot, the probe test, P6, and a
  built-ins-on commit since dropped for main's own 5a2414acd) was run
  together, at load 200-660.
  At the pushed tree, 88dfab2d3 on origin/main 5380114da (rebased
  from 210bc2b77, no conflicts; its GUI assets and tests are the same
  bytes as the tree the GUI runs below used, diff -rq): gofmt clean,
  vet darwin/linux nogui/windows ok, TestCoreScriptBudget ok
  (1,446,845 of 1,447,000). go test -timeout 45m ./... at load
  193-278: 62 packages ok, red in TestMainWindowCorners (#1936) and
  TestPluginStreamLargeReplies JSON_fast (client timeout; alone 1 of
  3 red here, 0 of 3 on 5380114da side by side at load ~280; the
  series doesn't touch the stream path; #2551 reopened with the
  output, taken). Two earlier runs at this tree are discarded: one
  stopped when the disk filled, one when another session's go clean
  -cache emptied the build cache mid-run. The whole GUI suite at
  this tree was not finished (the disk filled); the files the series
  reaches ran (1318 tests, 124 red), and the 39 red files ran again
  at concurrency 1 on both trees: here 148 ok 120 red, origin/main
  135 ok 127 red. Both sides' reds are page.goto/launch timeouts
  under load (66 here, 71 there) and the same assertions:
  title-bar-tools' and settings-proxy-auth's "access control checks"
  on a cut-off /api/providers read (#2740, taken next), sidebar's
  "the list unrolls" and WebKit "#prefs pressed darkens" (#2684;
  alone, 1 red here, 3 on main), side-toggle (#2732); plugin-move
  red on main only. Six files again one by one on both trees:
  plugin-actions red 1 of 6 here, a 5s goto of ?view=plugins at load
  260; plugin-clash red on both; plugin-own-icon, plugin-gateway,
  plugin-checkin ok on both; settings-proxy-auth ok here, 3 red on
  main.
  At 976c9893a (on origin/main 6f950653f): go test -timeout 45m ./...
  red only in TestMainWindowCorners (#1936, the window's process
  killed at its deadline) and TestSetAnswersWhileDevinAndProvidersHang
  (#1375, 3 of 3 alone). The whole GUI suite, both engines: 10834
  tests, 237 red in 73 files, 184 of them a 180s browser launch. Those
  73 files run again at concurrency 2: 52 green, among them every
  plugin-* and agent-* file and plugin-actions; the 21 still red were
  run at origin/main f191d6423 and are red there too: codex-predictions
  (#2624), lightweight (#2638), segs-glide (#2683), usage-agents-hide
  (#2276), provider-advanced-fold (#2552), routing-bodies (#2559),
  routing-model-rest and rest-try-now (#2115, #2564), routing-keys-fold
  (#1612), routing-wb-restricted (#1905), routing-request-metrics
  (#2571), quota-count-wrap and quota-name-translated (#2228), s3-sync
  (#2448), usage-checkin (#2549), usage-ledger-abort (#2700),
  tencent-access-key (#2733), usage-range (#2734); side-toggle's WebKit
  motion red 1 of 3 on main, 0 of 3 here (#2732); usage-fold green alone.
  Rebased onto origin/main 717b69f78 (60725faa1, no conflicts): gofmt
  clean, vet darwin/linux nogui/windows ok; go test -timeout 45m ./...
  red in TestSetAnswersWhileDevinAndProvidersHang (#1375) and agent and
  gateway at the 45m alarm with tests still moving at load 400+, both ok
  alone (1173s, 1167s); 105 GUI files the series reaches (plugin*,
  sidebar*, side-*, settings*, title*, header*, agent-*): 1322 tests,
  23 red, run alone 214 of 218 ok, the 4 left in sidebar and
  sidebar-overlay-scrollbar (WebKit), red on 717b69f78 too (#2684,
  #1863). The whole GUI suite was not run again after the rebase.
- gofmt -l clean; go vet darwin, linux (-tags nogui) and windows ok;
  TestCoreScriptBudget ok.
- go test -run 'TestWindowActions|TestPluginPageActions' ok: duplicate,
  malformed and session-menu ids dropped, 12 actions kept to 8, none
  without a page, an off plugin's not served.
- plugin-actions.test.cjs: chromium and webkit, en zh zh-TW ja de, at
  1100 and 420: no page adds nothing; the agent menu ends with Hide then
  the plugin's item; the provider menu's item is in the window's
  language; a pick opens the page, which gets exactly {id, provider|
  agent: {id, name}} once, in one frame, though it calls onAction 400ms
  late. The Plugins row says which menus.
- Broken by hand, each red then restored: the bridge not holding an
  action picked before onAction (the late-registering fixture), the
  provider's whole row posted in place of {id, name} (the exact-data
  check), any id and any menu accepted (TestWindowActions).
- Neighbours in both engines: plugin-page, agent-cli-missing,
  agent-disconnect, group-bulk-remove, model-test-why and provider-find
  ok; plugin-panels red before P5's fixture fix (padding, in that
  commit), ok after.
- Real use: a dev build (-tags dev) in a sandbox HOME with a
  local plugin of two actions; WebKit on its dev UI picked "Inspect
  agent" on Claude Code and "Inspect provider" on a local provider, and
  the page logged {"id":"about-agent","agent":{"id":"claude","name":
  "Claude Code"}} then {"id":"about-provider","provider":{"id":
  "local-try","name":"Local Try"}}, one frame. Not clicked in the
  WKWebView window itself; the frame's loading there is
  TestPluginPageLoadsItsFilesInTheWindow's.
2026-10-18 07:13:12 +08:00
yetone b9f790d37b plugins: panels in magpie's pages, a page that replaces a built-in one, titles in the window's language, and a look that matches
P5 of the plugin runtime (docs/subsystems/plugin-runtime.md):

- Panels (magpie.panels): a plugin draws a frame into a slot of a
  built-in page (a provider's editor, Settings, Usage); magpie.context
  says where it is, and the frame is as tall as what it draws.
- A page can replace a built-in one (magpie.page.replaces); show() opens
  it in that page's place, and the sidebar row goes to it.
- page.titles and a panel's titles name it in the window's language
  ({"zh": …}); a malformed map is dropped, the title kept
  (TestWindowTitles).
- main's #2501 already names wails:// in the policy of a page in the
  desktop window (through ownWindow), which is why the usage page drew as
  bare HTML from v0.1.1259. TestPluginPageLoadsItsFilesInTheWindow loads
  a page through ownWindow in a real WKWebView, which Playwright on http
  can't; the subsystem page says how.
- The bridge adds magpie's look for what a page leaves unstyled, every
  rule in :where() so any rule of the page's wins, and the theme's
  colours as --magpie-* variables.

One commit: the panels, the replacing pages and the titles share hunks
in page.go, pluginpage.go, pluginpages.js and the docs, and couldn't be
split cleanly.

Run:
- Full: this series (P5, the Plugins dot, the probe test, P6, and a
  built-ins-on commit since dropped for main's own 5a2414acd) was run
  together, at load 200-660.
  At the pushed tree, 88dfab2d3 on origin/main 5380114da (rebased
  from 210bc2b77, no conflicts; its GUI assets and tests are the same
  bytes as the tree the GUI runs below used, diff -rq): gofmt clean,
  vet darwin/linux nogui/windows ok, TestCoreScriptBudget ok
  (1,446,845 of 1,447,000). go test -timeout 45m ./... at load
  193-278: 62 packages ok, red in TestMainWindowCorners (#1936) and
  TestPluginStreamLargeReplies JSON_fast (client timeout; alone 1 of
  3 red here, 0 of 3 on 5380114da side by side at load ~280; the
  series doesn't touch the stream path; #2551 reopened with the
  output, taken). Two earlier runs at this tree are discarded: one
  stopped when the disk filled, one when another session's go clean
  -cache emptied the build cache mid-run. The whole GUI suite at
  this tree was not finished (the disk filled); the files the series
  reaches ran (1318 tests, 124 red), and the 39 red files ran again
  at concurrency 1 on both trees: here 148 ok 120 red, origin/main
  135 ok 127 red. Both sides' reds are page.goto/launch timeouts
  under load (66 here, 71 there) and the same assertions:
  title-bar-tools' and settings-proxy-auth's "access control checks"
  on a cut-off /api/providers read (#2740, taken next), sidebar's
  "the list unrolls" and WebKit "#prefs pressed darkens" (#2684;
  alone, 1 red here, 3 on main), side-toggle (#2732); plugin-move
  red on main only. Six files again one by one on both trees:
  plugin-actions red 1 of 6 here, a 5s goto of ?view=plugins at load
  260; plugin-clash red on both; plugin-own-icon, plugin-gateway,
  plugin-checkin ok on both; settings-proxy-auth ok here, 3 red on
  main.
  At 976c9893a (on origin/main 6f950653f): go test -timeout 45m ./...
  red only in TestMainWindowCorners (#1936, the window's process
  killed at its deadline) and TestSetAnswersWhileDevinAndProvidersHang
  (#1375, 3 of 3 alone). The whole GUI suite, both engines: 10834
  tests, 237 red in 73 files, 184 of them a 180s browser launch. Those
  73 files run again at concurrency 2: 52 green, among them every
  plugin-* and agent-* file and plugin-actions; the 21 still red were
  run at origin/main f191d6423 and are red there too: codex-predictions
  (#2624), lightweight (#2638), segs-glide (#2683), usage-agents-hide
  (#2276), provider-advanced-fold (#2552), routing-bodies (#2559),
  routing-model-rest and rest-try-now (#2115, #2564), routing-keys-fold
  (#1612), routing-wb-restricted (#1905), routing-request-metrics
  (#2571), quota-count-wrap and quota-name-translated (#2228), s3-sync
  (#2448), usage-checkin (#2549), usage-ledger-abort (#2700),
  tencent-access-key (#2733), usage-range (#2734); side-toggle's WebKit
  motion red 1 of 3 on main, 0 of 3 here (#2732); usage-fold green alone.
  Rebased onto origin/main 717b69f78 (60725faa1, no conflicts): gofmt
  clean, vet darwin/linux nogui/windows ok; go test -timeout 45m ./...
  red in TestSetAnswersWhileDevinAndProvidersHang (#1375) and agent and
  gateway at the 45m alarm with tests still moving at load 400+, both ok
  alone (1173s, 1167s); 105 GUI files the series reaches (plugin*,
  sidebar*, side-*, settings*, title*, header*, agent-*): 1322 tests,
  23 red, run alone 214 of 218 ok, the 4 left in sidebar and
  sidebar-overlay-scrollbar (WebKit), red on 717b69f78 too (#2684,
  #1863). The whole GUI suite was not run again after the rebase.
- plugin-panels' tall panel (body{margin:0}) measured 220, not 180,
  after the look above gave an unstyled body 20px of padding; the
  fixture now sets padding:0 too, as a page that wants none would.
  plugin-panels ok in chromium and webkit after.
- gofmt -l clean; go vet darwin, linux (-tags nogui) and windows ok.
- GUI: plugin-page and plugin-panels in chromium and webkit, en zh zh-TW
  ja de, wide and narrow, ok.
- Broken by hand, each red then green: titled() in pluginpages.js
  (the "draws in its frame" test), the wails:// scheme in pagePolicy
  (the WKWebView test, before the rebase onto #2501), titles' parsing
  (TestWindowTitles).
- Real use: the published @magpie-community/page-usage 0.1.1 in a
  sandbox magpie window, its tiles styled.
2026-10-18 07:13:09 +08:00
yetone 5380114da1 LESSONS: 10-17: runs recorded at another tree, "under load" reds left unowned, a body scan on every passing reply
Folds the review of 10-17 04:00 to 10-18 04:00 (77 commits, v0.1.1277
to v0.1.1283) into LESSONS.md, and moves two lessons seen a third day
into docs/code-standards.md:
- magpie's default never overrides a value the user set (10-05, 10-10,
  10-17: 5a2414acd's Essentials to All, #2749), a row under "What a
  change contains";
- a checkout, worktree or log belongs to the session that made it
  (10-09, 10-12, 10-17: 7660399a1's worktree checked out by another
  session, 17557132c's log deleted), under Commits.

New lessons, each seen once:
- a named sibling left alone gets an issue (d4a1b9baa, plugins#176)
- a fix that only covers new data says what happens to the old
  (dccfefdf7)
- keep a suite's log whole (5b12407e8)
- close a two-part issue when both parts are fixed (#2449, #2702)
- a size budget raised on every hit bounds nothing (#2710)
- a publish run red for one package hides new failures (plugins#180)

Seen a second day:
- hot-path cost, widened from a polled field to b14784c03's body scan,
  fixed in 7ac20247a
- one suite per machine (load 313 on 10-17)
- the #1794 pattern of "seen again" comments with no owner (#2444,
  #2737), with one test filed three times (#2169, #2711, #2737)

Also adds the criteria still missed on 10-17 (a run record at a tree
other than the pushed one, a wrong issue cited) and what was done right
(the retire stack, df3734b95, f550d3699, 48aae83b8 and others).

Docs only. Every sha and issue number was checked against git log, gh
and the commit bodies.
2026-10-18 04:43:41 +08:00
yetone b14784c03f gateway: a fallback too small for the request is asked once every account with room is out of its allowance (Kai on Discord)
Kai on Discord (0.1.1278): Claude Code to claude/claude-opus-5-5, the
Claude provider's two subscription accounts (Max, Pro) both at their
limit ("resets 5:58am", "resets Oct 18 at 3pm"), its Fallback
codex/gpt-6.1-sol. Routing said the second account's 429 had nobody left
to try, and Claude Code had the 429. The fallback was never in the
route's order.

Cause: roomy (0f398c489, 10-15) leaves out, before anyone is asked, a
candidate whose known window is no larger than the request's estimate.
A Codex account's gpt-6.1-sol is 272K (its live list's context_window);
Opus holds 1M. A Claude Code conversation past ~272K tokens left the
Codex fallback out of the candidates and the trace's order, silently,
and when both Claude accounts failed for their allowance the agent was
told to wait hours. "It worked yesterday": the conversation was shorter.
A short request on current main already fell back (the new test's first
cases pass on the old code).

Fix: roomy hands back what it left out (small, with its order rows).
When the last candidate with room fails out of its allowance or credit
(failQuota/failCredit), nothing before it failed otherwise (other ==
nil), no account is pinned, and it isn't an overflow, refusal or
turned-away prompt, those left out that aren't resting are appended and
asked, their rows added to the trace's order, and the failed one rests
as one before the last does. The too-small fallback's overflow then
reaches the agent through the existing outgrew path, to compact, after
which it holds the conversation. Any other failure (a bad key, a busy
vendor) reaches the agent as before, the small member not asked, so
dgqyushen's free-200K-first group keeps its behaviour. Streaming and
non-streaming share the loop; count_tokens and System One's decision
models don't go through roomy. The Routing page still shows a member
left out and not asked only by its absence (no GUI change).

Tests:
- TestClaudeAccountsSpentFallBackToCodex (new): fake `claude` CLI that
  answers every account with rate_limit_event rejected + "You've hit
  your limit", a fake Codex backend, Claude's Fallback codex/gpt-6.1-sol,
  Codex's window 272K. Short request streamed / not / with accounts
  already resting: Codex answers (green before and after). A ~375K-token
  request streamed and not: red on the old code (429, codex asked 0,
  order = the two Claude accounts), green now.
- TestMemberTooSmallIsTheLastResort (new): group paid(10K) then
  free(2K), a 2.2K request. paid 401: the agent gets the 401, free not
  asked. paid 429 insufficient_quota: free answers, paid rests, free in
  the order.
- TestRoomyLeavesWhatItCantJudge checks the handed-back candidates.

Broken by hand:
- the new block disabled (false &&): both stream cases of the Claude
  test red (429, codex asked 0), TestMemberTooSmallIsTheLastResort red
  (429 insufficient_quota, free 0). Restored: green.
- the quota condition forced true: TestMemberTooSmallIsTheLastResort's
  401 case red (free asked, 200). Restored: green.
- the other == nil condition removed: still green; no test has an
  earlier member failing otherwise before a quota failure.

Run:
- gofmt -l: clean. go vet ./internal/gateway (darwin), GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./... at de671719a (load ~240-470): every package ok,
  internal/gateway included (2451s), except three reds in packages this
  doesn't touch, each already filed and each a timing bound under load:
  internal/gui TestMainWindowCorners/macOS_26_SDK killed at its deadline
  (#1936, #2645; red alone too on this loaded machine), internal/library
  TestCheckStdio/timeout_ends_the_tree (#2765; -count=3 alone: ok),
  internal/plugin TestStopLetsARenewalEnd (#2743; -count=2 alone: ok).
- After rebasing on origin/main: go test ./internal/gateway -run with the
  new and roomy/overflow tests: ok.

Not done: Routing still shows a member left out and not asked only by
its absence; a row saying "too small for this request" would be a GUI
and i18n change of its own. Not tried against Kai's real accounts.
2026-10-18 02:17:02 +08:00
yetone e44b9aef33 middleware: onProvider changes what one provider a request is tried on is sent
A JS gateway middleware can export onProvider(body, ctx). The gateway
calls it on each try, just before the body goes to that provider, with
ctx.provider = {id, name, account, model}: account is the subscription's
kind (claude, antigravity, …), absent for a key. Every try starts again
from the body onRequest left, so a change for one provider never reaches
another in a routing group. null and ctx.reject turn nothing away there.
A hook that throws or runs past 250ms leaves the try's body as it was.

A plugin could act only before routing until now, by the model name the
agent asked for. Claude Desktop asks for opaque aliases, so a plugin
couldn't tell which vendor a request was going to. The first user is
@magpie-community/middleware-antigravity-cloak: it changes only what an
Antigravity account is sent, so that Antigravity stops refusing Claude
Code's system prompt (xzplzpl on X). magpie itself still sends every
prompt as the agent wrote it.

- gwmw.To and gwmw.Tried; middleware.Run.Tried runs the hooks.
- serveAgent puts the runs on the request's context, and serve's
  candidate loop calls triedOn before the Antigravity foresight, so it
  judges the body that will be sent.
- Docs: gateway-middleware.md, reference.md, integrating.md, and the
  hooks table and community list in site docs plugins.html (en, zh, ja).

Run:
- go test ./... -timeout 45m in a sandbox HOME (macOS, at de671719a):
  every package ok but two. internal/middleware's TestPointsLoadErrors
  pinned the old list of exports; it now says onProvider too, and the
  package is green. internal/gateway's
  TestTranslatedStreamKeepsClientAlive/chat_to_responses went red under
  the full run's load (#2737, numbers added there); -count=10 alone is
  10/10 green, and with no middleware triedOn returns the body as is.
- TestMiddlewareOnProviderPerTry (gateway): a group a/m1 (500) then b/m1;
  a got "asked for a/A/m1/key", b got "asked". With the triedOn call
  replaced by `_ = triedOn` it is red (sent a:"asked" b:"asked").
- TestOnProvider (middleware): per-try bodies, throw and null fail open
  and are counted, a reject is a no-op, a nil Run passes through.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  on the changed packages.
- node --test internal/gui/tests/plugin-middleware.test.cjs: 24 pass.
- Real use: a sandbox magpie built from this tree, a real Antigravity
  account, the plugin installed from its folder. Real Claude Code 2.1.302
  (`claude -p` with a sandbox CLAUDE_CONFIG_DIR, model
  antigravity/gemini-3-flash) got its answer. With the plugin's
  {"off": true} the same run got the 400 "Resource has been exhausted".
  Direct /v1/messages with the billing line, the Agent SDK line, and
  Claude Code's three blocks: 200 each with the plugin on, 400 each with
  it off.
2026-10-18 00:50:14 +08:00
yetone de671719a0 provider: a retired built-in's failed move is tried again in 10 minutes, not 6 hours
A failed move waited moveRetry (6h) before KeepRetiringMoved tried it
again. That was fine while the built-in carried on serving the accounts.
A retired built-in serves nothing, so a move that failed for a moment
(npm out of reach, or the plugin listed in plugins.json but not installed
yet, which the real-account run on 85b8f6d4d hit with Command Code: the
first Move failed, the second worked) left the user's subscription
unserved for up to 6 hours unless they pressed Move.

- retryWait(id) is retiredRetry (10 minutes) for a retired built-in, and
  moveRetry otherwise. MoveRetiring and HandOver both use it (retryDue).
- KeepRetiringMoved's next run is brought forward to when a retired
  built-in's failed move is due (nextRetiringRun, at least a minute),
  instead of always an hour.
- docs/subsystems/provider-plugins.md says so.

TestMoveCutShort now also checks:
- a failed move 11 minutes old waits while the built-in serves it, and
  the next run is an hour;
- once retired, the next run is 10 minutes, it isn't tried at once, and
  it is moved after retiredRetry.

Broken by hand, each red:
- retryWait returning moveRetry for a retired built-in:
  "a retired built-in after retiredRetry: map[]"
- nextRetiringRun always an hour:
  "the next run after a retired built-in's failed move: 1h0m0s, not 10m0s"

Run: go test -tags nogui ./internal/provider -run TestMoveCutShort: ok.

What was run for the stack, at load ~300 (it was rebased from bad4508c4
onto 1acd79cdf; the only conflicts were in
docs/subsystems/gateway-routing.md, resolved to main's text with each
commit's own edit, checked word by word):

- At this commit's tree (bda209c1f, on 1e643ba7e; then rebased onto 1acd79cdf, where vet on all three systems and internal/gui ran clean):
  gofmt -l clean; go vet darwin/linux/windows clean; go test
  ./internal/provider ./internal/cli ./plugins/search ok; ./internal/gateway
  -run 'Jev|Auto|Review|Plugin|Retire|Move|Search' ok. The full suite
  wasn't run again on 1e643ba7e's four new commits (a provider display
  name, two Jev changes, auto-mode review), none in a file the stack
  touches but the gateway-routing doc; CI runs it before the tag.
- Full suite at 3f0858b6f (on c4aeaec74): gofmt -l
  clean, go vet darwin/linux/windows clean, go test -tags nogui ./...
  -count=1 -timeout 90m: 64 ok, exit 0.
- Full suite at a42a1090c (on 89521b03d) and ee288bc65 (on 717b69f78):
  the same, 64 ok, exit 0. Factory's own min commit (0.1.32) was dropped
  in the last rebase: main raised it to 0.1.33 in b5c76935b.
- Full suite at cbf4626a3 (on bad4508c4): gofmt -l clean, go vet darwin/linux/windows
  clean, go test -tags nogui ./... -count=1 -timeout 90m: 64 ok, exit 0.
  At 4c6c99bbd the same run had gateway red on TestPluginStreamLargeReplies
  only (#2551; passes alone, 181.957s).
- GUI: retired-move 4/0 in both engines. The remaining 519 files ran at
  85b8f6d4d, two at a time (3864 ok, 109 not ok when this was written;
  18 of the reds are browser launch timeouts). Each red file was run
  alone at the head, and those still red were run on origin/main
  bad4508c4:
  - red the same on main, filed: segs-glide 20/20 (#2683), routing-bodies
    (#2559, #2658), routing-model-rest (#2115), routing-keys-fold (#1612),
    routing-wb-restricted (#1905), provider-advanced-fold (#2552), sidebar
    (#2684), s3-sync (#2448), routing-request-metrics (#2571),
    rest-try-now (#2564), quota-name-translated and quota-count-wrap
    (#2228), lightweight (#2638), codex-predictions (#2624),
    gateway-key-models under load (#2648);
  - green alone: plugin-list-error, sessions-paging, plugin-kinds-discover,
    plugin-kernel, session-terminal, routing-time-went, routing-flood,
    routing-context-fold, routing-agent-gone, plugin-local,
    plugin-key-hint, name-suffix-no-names, nav-sub-unroll, model-api-gemini,
    model-api-preset.
  At ee288bc65: retired-move 4/0, routing-compaction 10/0,
  library-ime-scroll 18/0; title-bar-tools 4/6, red the same on main
  2042123f4 (#2740: a reload cuts off sideGwRead's read).
  The stack's only GUI change is the unmoved line in renderMovable, shown
  only when /api/providers has unmoved entries.
- Real accounts through the plugins (85b8f6d4d, sandbox HOME): grok,
  workbuddy, workbuddy-ai, cursor, zcode 200; devin, commandcode-plan,
  mimo-app 200 after a first timeout; qoder 401 shown as lapsed
  (plugins#181, the built-in had no 10605 handling either). Not tried:
  kiro, factory, zed (no account here).
- The built-in-only WorkBuddy model ids: the plugin reads WorkBuddy's live
  list, which doesn't offer them.
2026-10-17 23:15:26 +08:00
yetone bd30b068d3 docs: every deprecated built-in is retired; AGENTS.md and gateway-routing say so
AGENTS.md: the table's subscriptions are retired, not moving; the plugin
does everything, the built-ins' code is gone but for what the movers
read; the "fix the built-in too" step is gone; the parity tests hold
each plugin to what its built-in did.

gateway-routing.md: no bridges to a vendor's own API are left, so the
structured-output, tool-image and billing-line lists lose Cursor, Kiro,
Qoder, Devin and Command Code; Kiro's image ordering is its plugin's.

Run: docs only; the full suite runs at the stack's head.
2026-10-17 23:11:01 +08:00
yetone be62bcf79e provider: Command Code's built-in is retired; its plugin serves it
commandcode-plan joins retiredBuiltins (migrate.go): PluginServes is true
for it moved or not, and @magpie-community/opencode-commandcode-auth does
its sign-in, models, requests and usage.

Removed
- Sign-in: the StartSignIn case (startCommandCodeSignIn, the Studio
  callback, cmdOrigins, cmdWhoamiWait, commandCodeCallback/Keep) and the
  pasted-key branch (commandCodeKey, cmdSignedIn).
- Accounts: commandCodeAccount, cmdProvider, cmdSide, cmdLoginList,
  switch/on/forget (switchCommandCodeLogin, setCommandCodeLoginOn,
  forgetCommandCodeLogin, commandCodeAlsoOn), the Logins case, and the
  per-login usage (cmdLoginQuota, cmdQuota, the perLogin fetch). The
  Logins("") list keeps {CommandCodePlanID, nil} so its order holds.
- The Go plan's path: CommandCodeGenerate, cmdGoModels/cmdGoFetch/
  cmdGoRefused, cmdModels, cmdFree/cmdMarkFree, cmdPlansSeen's built-in
  users (cmdRemember, cmdPlanKnown, cmdPlanNow), CommandCodeOutputOf, and
  the account's generate field.
- asksOwnBackend's Command Code case.
- Gateway: the cmdGenerate/serveCommandCode dispatch and countOn's
  cmdGoing clause; internal/gateway/commandcode.go (the /alpha/generate
  translator) deleted.
- Built-in-only tests: gateway commandcode_test.go and
  commandcode_place_test.go, TestBillingLineLeftOutOnCommandCode;
  provider commandcode_go_test.go, commandcode_go_models_test.go,
  commandcode_free_test.go, TestCommandCodePlan,
  TestCommandCodeSignInWhoamiDown, TestCommandCodeSignInAgainToRemovedOwn,
  TestCommandCodeSignInPastedKey.
- Docs: Command Code out of gateway-routing.md's bridge lists (the
  2xx check, structured output, tool images, the billing line).

Kept, and why
- The mover and what it reads: cmdAuth, cmdOwn, cmdWho, cmdLogin,
  cmdSaved, cmdLogins (migrate_side.go, plugin_accounts.go).
- cmdAPI/cmdStudio (plugin_usage.go's moved card), cmdKeysURL
  (pluginsignin_paste.go), the plan and credit readers (cmdPlans,
  cmdPlanOf, cmdPlanName, cmdWindows, cmdLeft, cmdQuotaOf, cmdTime,
  cmdSubscription, cmdKeyWindows, cmdKeyPlanID): the keyed preset
  "commandcode", planquota.go, balance.go and qoder_usage.go use them.
- CommandCodeMaxOutput (models.go caps the plugin's "commandcode-plan"
  models with it), estimatedMoved, chat.go's plugin host cases, the
  gateway parity tests, and the PLUGIN-SERVED notice in
  commandcode_plan.go, now in the retired wording.

Tests whose meaning changed
- TestLoopbackSignInsTakePastedAddress no longer starts Command Code's
  built-in sign-in; the plugin's (TestLoopbackPorts) says its key is
  posted, never pasted as an address.
- The Go plan's free-model marks (TestCommandCodeFreeModels) were the
  built-in's alone; the keyed preset never marked them.

Run (worktree magpie-wt-rt-a, on top of 9a64c4025)
- gofmt -l internal: clean
- go vet -tags nogui ./... (darwin, GOOS=linux, GOOS=windows): clean
- staticcheck U1000 on ./internal/...: no declaration unused that wasn't
  unused at HEAD
- go test -tags nogui -count=1 ./internal/provider/ -run
  'CommandCode|commandcode|Migrat|Move|Moved|Retir|SignIn|AsksOwnBackend|
  SideLogin|Logins|Unmoved|Paste|Loopback|Account|PlanQuota|Balance|
  FetchNew|FetchingNew|LeftAlone|Identit|Order': ok (100s)
- same, -run 'Usage|Card|Quota|Discovery|Exposed|Models|Output': ok
- ./internal/gateway/ -run 'CommandCode|commandcode|Plugin|Parity|Moved|
  BillingLine|Search|ShapeFallback|GroupFails|CountTokens|Count|Format|
  ToolImage|Cursor|Connect': ok (117s)
- ./internal/cli/ ./internal/gui/ -run 'CommandCode|commandcode|Plugin|
  Retired|Moved|SignIn|Login': ok
- Not run: whole packages, the full suite, the GUI node suite (the
  machine is loaded; the parent runs those).
2026-10-17 23:11:01 +08:00
yetone 07a445f42b provider: Devin's built-in is retired; its plugin serves it
"devin" joins retiredBuiltins, as Zed (c0605abc2) and Grok (60ecd598c)
did. @magpie-community/opencode-devin-auth serves it, moved or not.

Removed:
- Sign-in: the PKCE localhost listen and callback branch in signin.go,
  devinExchange/devinExchangeURL. The exchange is Codex's alone again.
- Accounts: devinAccount and devinProvider in the account list, and the
  Logins, switch, on and forget cases (devinSide, devinLoginList,
  switchDevinLogin, setDevinLoginOn, forgetDevinLogin, removeDevinHome,
  addDevinLogin, devinAlsoOn). "devin" keeps its place in Logins("") with
  a nil list.
- Usage: devin_usage.go whole (perLogin fetch, usageLogins, loginQuota).
  devinUsageVersion moved to devin_images.go, which still uses it.
- asksOwnBackend's "devin".
- Gateway: attempt()'s serveDevin dispatch and the Devin translator
  (serveDevin, askDevin, buildDevin, decodeDevin, the Gemini schema and
  tool-description rewriting, the call-id helpers). gateway/devin.go is
  now connect_pb.go and keeps only the protobuf and Connect framing that
  cursor.go uses.
- Tests of the built-in alone: gateway devin_test, devin_gemini_schema,
  devin_sampling and devin_tool_ids; provider devin_usage_test,
  devin_cli_signed_out_test, TestDevinSignIn, TestDevinSeveralAccounts,
  TestSignInInstallsMissingCLI, TestDevinSignInUnseen, the Devin case of
  the required-tools test, and TestDevinSplitParallelCallsKeepTheirResults.

Kept, because the plugin, the devin agent or the move uses them:
- The mover, devinLogins, devinIdentity/devinStatus, DevinAuthAt,
  devinCredentialsAt, newDevinHome, devinCommand/devinProxy.
- DevinFamilies, DevinVariant and models.go's p.ID == "devin" shaping
  (the plugin's provider id is "devin" too). internal/agent/devin.go
  reads the families.
- The installer's "devin" case: the plugin's sign-in installs the CLI.
- The PLUGIN-SERVED notices in devin.go, devin_accounts.go and
  devin_images.go, reworded as retired.

Also fixed:
- cliIdentities no longer lists devinStatus. No look at the accounts
  asks it now, so it stayed unsettled, and FetchNewBehind told every page
  that lists were on their way (TestFetchingNewOnceStarted went red).
- 60ecd598c (Grok) left TestFetchingNewForgottenWhileListed red: its
  hook was GrokExecutable in the account listing. It and
  TestFetchNewListsAgainForAnAnswerWhileListing now hook kiroCLIDB,
  which is read after Cursor's account. Retiring Kiro will need another
  hook.

Tests whose meaning changed:
- TestSignInInstallFails and TestSignInCanceledWhileInstalling go
  through StartPluginSignIn("devin"), the plugin's install of the CLI.
- TestDevinCLIGoesThroughItsProxy seeds both accounts in logins.json
  instead of signing one in. The sign-in's proxy is covered by
  TestPluginSignInGoesThroughItsProxy.
- TestLeftAloneRunsNoCLI no longer expects `devin auth status` when the
  subscription is switched on.
- TestFetchingNewOnceStarted's unanswered CLI is Cursor's.
- devinRawID moved to anthropic_call_ids_test.go. A Devin call id is
  checked as safeCallID("dv_", ...).

Run:
- gofmt -l internal: clean.
- go vet -tags nogui ./... on darwin, GOOS=linux and GOOS=windows: clean.
- staticcheck U1000 on provider and gateway: no Devin leftovers.
- go test -tags nogui -count=1 -run '^(every test in provider, cli and
  gateway that names Devin|TestFetchNew.*|TestFetchingNew.*|
  TestLeftAlone.*|.*Identit.*)$' ./internal/provider ./internal/cli
  ./internal/gateway: ok.
- -run 'Migrat|Move|Moved|Retir|SignIn|AsksOwnBackend|SideLogin|Logins|
  Unmoved|Install|Proxy|Account' ./internal/provider: ok.
- -run 'Devin|Required|Split|CallID|Cursor|Connect|Parity|ToolImage|
  Format|BillingLine' ./internal/gateway: ok.
- -run 'Devin|Plugin|Retired|Moved' ./internal/gui ./internal/agent: ok.
- Not run: the whole packages, the full suite, the GUI node suite (the
  machine is loaded).
2026-10-17 23:11:01 +08:00
yetone 2927a161ef provider: Grok's built-in is retired; its plugin serves it
Grok ("grok") joins Zed in retiredBuiltins. It is served by
@magpie-community/opencode-grok-auth, moved or not.

Removed, the built-in's own paths:
- the sign-in (startGrokSignIn) and the per-account homes it made;
- the Logins/switch/on/forget cases and the alsoOn branch;
- grokAccount and the account list entry;
- the usage fetch (grokSubscriptionUsage, grokLoginUsage, the windows);
- the model list (grokModels, grokContextModels, the window labels);
- the token refresh, the headers, the version probe, and routing's usage
  clearing.
grok_usage_test.go is deleted, along with the six built-in-only tests in
grok_test.go and the four in grok_accounts_test.go.

Kept, because something still uses them:
- grokLogins and readGrokCredential, for the mover (migrate_side.go);
- grokBody, for the plugin's request bodies;
- GrokHome, the CLI install (pluginRunsCLI) and GrokBase;
- the gateway's grok draw, video, search and namespace code. It asks
  PluginProvider()=="grok" too.
Each remaining grok file has a PLUGIN-SERVED notice.

Fixes the retirement needed:
- movedAgent asks Moved again, not PluginServes. A retired Grok that is
  not moved yet still records the CLI's own sign-in, so the move takes it.
  TestMoveGrok fails without this: only the second account moved.
- In Logins(""), a retired built-in keeps its place, with no list. Grok's
  and Zed's accounts list where the built-ins' stood. Without this,
  TestAllLoginsMovedKeepTheirPlace fails ("[zed grok]").

Tests whose meaning changed:
- The gateway's grokSignedIn now serves Grok through the fake plugin
  moved onto "grok". It proxies to provider.GrokBase, read per request
  and refused unless loopback, so no test reaches the network. It names
  127.0.0.1 in fetchPrivate, because the vendor's own host is now the
  fake's.
- TestVideoContentAtPrivateAddressNotFetched clears that setting. Without
  the clear it fails with "200 secret-bytes".
- TestGrokAccountDraws checks the plugin's Authorization only. The real
  plugin's headers are the plugin repo's to test.
- The Grok cases in TestVideosRedacted and TestMediaRedactedErrors reach
  their echo through GrokBase (grokEcho).
- TestVideoModelByItsBareName's chat model is the fake's fake-1.
- TestGrokPluginSearchesItself expects "grok", not grok-plugin.
- TestGrokHideOwnSignIn is removed: hiding the CLI's own sign-in was the
  built-in's ForgetLogin.
- grok_accounts_test.go keeps test-only newGrokHome and addGrokLogin
  fixtures for the mover's tests.

Run in the worktree:
- gofmt -l internal: empty.
- go vet -tags nogui ./... on darwin, GOOS=linux and GOOS=windows: clean.
- go test -tags nogui -count=1 -run
  'Private|Grok|grok|CallerUsageVideos|GatewayKeyModelsHoldTheImageAndVideoLists|RemoteMagpie|Video|Redact'
  ./internal/gateway: ok.
- go test -tags nogui -count=1 -run
  'Grok|grok|Migrat|Move|Moved|Retired|Retir|SignIn|AsksOwnBackend|SideLogin|Hide|OwnRow|Logins|Unmoved'
  ./internal/provider ./internal/cli: ok, ok.
- go test -tags nogui -count=1 -run 'Grok|grok|Plugin|Retired|Moved'
  ./internal/gui: ok.

Not run: the full suite, the GUI node suite, and a real Grok account.
The machine is under heavy load.
2026-10-17 23:11:01 +08:00
yetone 1357236917 docs: the retired built-ins leave the gateway and account pages 2026-10-17 23:11:01 +08:00
yetone 21252f6a2c provider: Zed's built-in is retired; its plugin serves it
The first built-in taken out (the owner, 10-16: 陆续把内置Provider下线掉,
一定要下线完毕). @magpie-community/opencode-zed-auth serves Zed for
everyone now; built-in accounts not moved yet are moved by the hourly
loop, or from the Providers list's line (the commit before).

Removed: the built-in's sign-in (zed_signin.go and its loopback paste
branch), usage (zed_usage.go), its login list, switch, forget and
account cases, its own-backend case in asksOwnBackend, the gateway's
serveZed and zed.go, internal/zed, and the tests of only those.

Kept, because the mover and the plugin path use them: zed.go's
credential and login readers (migrate_zed.go's move), zed_body.go
(plugins.go), and Zed in accountIDs, side_logins, cards_kept,
plugin_usage's movedCards, the gateway's estimatedMoved and the CLI's
account names, which name the plugin's accounts too. Zed the editor as
an agent (internal/agent, the library's MCP target) is untouched.

Tests changed: TestMovedBuiltinQuiet is TestRetiredBuiltinQuiet (no Zed
card, its sign-in refused, the move still offered with the account);
TestZedMoveCarriesItsModels compares the models without internal/zed;
TestLoopbackSignInsTakePastedAddress and asksOwnBackend's set lose Zed.
AGENTS.md and gateway-routing.md no longer name Zed's built-in client.

Run on this tree over af08ecb27's parent tree:
- go test -tags nogui ./... -count=1 -timeout 90m: 64 packages ok,
  internal/gui red only in TestCoreScriptBudget (the Move line; the
  budget is raised in af08ecb27). Rebased onto it:
  go test -tags nogui ./internal/gui -count=1: ok.
- Earlier on wt6 before the three fixes: provider red in
  TestAsksOwnBackendAgreesWithTheGatewayDispatch and
  TestLoopbackSignInsTakePastedAddress (Zed still named), fixed here.
- gofmt -l internal: nothing; GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: clean.
- GUI: retired-move, plugin-move, deprecation-notice and
  deprecated-subscriptions, both engines, en and zh: 20 pass.
2026-10-17 23:10:59 +08:00
yetone 0f1666b387 provider: a built-in can be retired, its plugin serving it moved or not, and its unmoved accounts get a Move line
The owner (10-16) wants every deprecated built-in taken out of magpie,
one at a time. This is the ground for that; it retires nothing yet.

- retiredBuiltins / BuiltinRetired(id) in migrate.go name a built-in
  whose code is gone. Only an id with a mover can be retired.
- PluginServes(id) is Moved(id) or retired. Every gate that asked
  Moved(id) asks it now: sign-in, Factory keys, usage, logins, cards,
  forget, accounts, check-ins, plugin sign-in, the CLI's accounts and
  providers, the GUI's account label.
- A retired row's move.state is plugin, and its id is in onPlugins
  once the plugin is installed.
- /api/providers lists a retired subscription's built-in accounts that
  haven't moved in `unmoved` (MoveCandidate, now with the failed move's
  error and why). The GUI shows a quiet line over the Providers list
  for each, with Move / Try again (unmovedLine), in en, zh, zh-TW, ja
  and de.
- AGENTS.md and docs/subsystems/provider-plugins.md say what a retired
  built-in is.

Run at 270aa1c9c with this change:
- go test -tags nogui ./... -count=1 -timeout 90m: 66 packages ok.
- gofmt -l internal: nothing. GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: clean.
- GUI, both engines, en and zh: retired-move (new, 4/4), plugin-move,
  deprecation-notice, deprecated-subscriptions, plugin-move-unserved,
  plugin-movable-review, i18n-keys: 39 pass.
- TestRetiredBuiltinIsThePlugins -count=20 (it picks a mover at random).

The Move line is the Providers list's own, not a page that could be a
plugin. It took the core's scripts to 1,427,218 bytes, which the budget
main raised in 81313b912 (1,447,000, issue 2612) already holds;
TestCoreScriptBudget passes.

Broken by hand: retired-move goes red with unmovedLine not appended;
TestRetiredBuiltinIsThePlugins goes red with BuiltinRetired's Movable
check dropped.
2026-10-17 23:10:59 +08:00
yetoneandggbdpq 45b8c725cf gateway: a legacy /responses/compact carrying another account's native compaction goes to that account, or is refused saying why (#2727, ggbdpq)
codexBackend's /responses/compact relayed to Codex's sign-in (or, with the
sign-in paused, compactOn's account) before any seal check, so a compact
whose input carries a compaction magpie recorded another account as the
writer of reached an account that can't read it, and Codex got the
backend's bare 400. Now sealedCompact judges it, as /responses already is
(codexSealedFor -> serve, #2642): the writer on in magpie answers it,
signed as the writer (codexUpstreamOn); a writer gone (signed out, lapsed,
paused, switched off, kept from the model) is refused 400 with
checkpointError's reason; the sign-in's own seal, a key's seal, a request
naming its own chatgpt-account-id, and a sign-in state magpie can't read
relay as before. Two Team seats of one email still read as one (the
record holds the email).

Review fix on top of ggbdpq's 781381f4: a gateway key held to some
accounts (#905) was checked (compactSigninHeld) against the sign-in before
the compact was handed to the writer, so a key held to me@ spent the
writer biz@ (acct-2 asked, 200), and a key held to biz@ was refused 403
"goes through the account Codex is signed in to" though the compact
would go to biz@. The hold is now asked of the account the compact goes
to; a writer the key may not use gets 403 sealedCompactHeldError naming
the writer, with nothing asked. The test's fake backend now records under
a lock.

Reviewed and run (reviewer, at this commit with the #2739 commit under
it, on 89521b03d; rebased after onto origin/main, see the last line):
- Each fix broken by hand, TestNativeCompactionCompactJudgesItsWriter:
  M0 codex_backend.go as on main: 3 subtests red (writer answers, gone
  refused, compactOn gone). M1 the key '#' skip dropped: "a seal a key
  wrote is not judged" red (400). M2 the chatgpt-account-id skip
  dropped: its subtest red (400). M3 the writer never relayed to: the
  healthy-writer subtest red (backend saw ""). M4 gone never refused:
  2 red. M5 judged after compactOn's relay: the compactOn subtest red
  (backend saw acct-2). Each green with the code restored.
- TestNativeCompactionCompactKeepsTheKeysAccounts (new) on ggbdpq's
  781381f4: red both ways ("200, the backend saw acct-2" for a key held
  to me@; 403 "goes through the account Codex is signed in to" for a key
  held to biz@). Red again with the hold put back on the sign-in; green
  with this change. TestGatewayKeyAccountsHoldCodexCompact and
  TestGatewayKeyCompactOnCodexAPIKey still pass.
- -race -count=3 on both tests: ok.
- gofmt -l clean; go vet ./... and -tags nogui (darwin), GOOS=linux and
  GOOS=windows go vet -tags nogui ./...: clean; go build, GOOS=linux go
  build -tags nogui, GOOS=windows go build: ok.
- Full suite, set -o pipefail, go test -tags nogui -count=1 -timeout 45m
  ./... at 519bcc843 (both changes, on 89521b03d), load ~300: exit 0,
  66 packages ok (internal/agent 2246s, internal/gateway 2040s,
  internal/provider 786s); none timed out.
- Not run: a real Team-seat pair or a real sealed compaction through a
  ChatGPT account.
- After the rebase onto origin/main 1e643ba7e (a doc-line conflict in
  gateway-routing.md resolved by hand, main's text kept): go build,
  darwin/linux/windows go vet -tags nogui of internal/gateway and
  internal/provider, and the NativeCompaction|Compact|Checkpoint|
  GoesZstd|StayPlain|TestGatewayKey and TestCodexCompressed tests: ok.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 23:02:36 +08:00
yetoneandpc418 0eab029ea7 provider: a ChatGPT account's turn is zstd-compressed with at most Codex's own 2 MiB window, not 8 MiB (#2739, pc418)
codexZstd (internal/provider/codex_zstd.go) set no window, so klauspost's
encoder declared its default 8 MiB (and, single-segment, up to the body
size below that) on every turn magpie re-compresses for the ChatGPT
backend: the accounts loop (forwardOnce), the native relay
(codexUpstreamOn) and warm-up all go through CodexCompressed. Codex's own
client never sends that: openai/codex ce0323f2
codex-rs/http-client/src/request.rs compresses with
zstd::stream::encode_all(Cursor, 3); zstd 0.13.3 (Codex's Cargo.lock)
copy_encode streams through Encoder::new(dest, 3) with the size unknown,
which libzstd 1.5.7 gives level 3's windowLog 21 (2 MiB). pc418's
15,173,526-byte image-heavy turn got 400 in the 8 MiB frame and 200 at
2 MiB; a later replay of the 8 MiB bytes was taken, so this matches the
client's envelope rather than proving a backend limit. Level and checksum
are unchanged. Cost: a large turn is bigger on the wire at 2 MiB with
SpeedDefault (pc418's turn 7.59 MB -> 12.44 MB; libzstd -3 gives 9.78 MB).

Reviewed and run (reviewer, at this commit on 89521b03d):
- Source checked: request.rs on openai/codex main ce0323f2 (encode_all,
  level 3), Cargo.lock zstd 0.13.3, zstd-rs v0.13.3 copy_encode.
- libzstd check: a 9.4 MB fixture with a 3 MiB random block repeated
  ~4 MiB apart. `zstd -3` from stdin: Window Size 2.00 MiB, 6,293,668 B.
  The old encoder's frame: 8.00 MiB window, 4,297,564 B, and
  `zstd -d --memory=2MB` refuses it ("Window size larger than maximum:
  8388608 > 2097152"). This commit's frame: 2.00 MiB window, 8,377,219 B,
  and `zstd -d --memory=2MB` decodes it to the same bytes. (For the record,
  SpeedBetterCompression at 2 MiB gave 6,293,661 B, libzstd's size; not
  changed here.)
- TestCodexCompressedLargeImageTurn fails with the option removed:
  "zstd frame window = 8388608 bytes, want at most 2 MiB"; passes with it.
- The gateway zstd tests in gateway-routing.md's commands pass;
  -race -count=3 on the new test passes.
- gofmt -l clean; go vet ./... and -tags nogui (darwin), GOOS=linux and
  GOOS=windows go vet -tags nogui ./...: clean; go build, GOOS=linux go
  build -tags nogui, GOOS=windows go build: ok.
- Full suite: see the #2727 commit after this one, run at that head with
  both changes.
- Not run: a real ChatGPT account through magpie (pc418 ran real native
  relay and account-pool image turns at 2 MiB: 200 each).

Co-authored-by: pc418 <271863285+pc418@users.noreply.github.com>
2026-10-17 23:02:36 +08:00
yetone 5a2414acdd plugins: every built-in plugin starts on, a new install's too
The owner (10-17): "所有的内置插件默认都应该是开启的", "尤其对新用户来说……
不然新用户都不知道有哪些功能". Since 3ccbe6bc1 (10-13) a new install was
written plugins.yml with the Essentials preset, which left Sessions, the
Library, routing groups, warm-ups and Observability off for every new user
(origin/main's binary, fresh sandbox HOME: those five "off").

- pluginrt.Settle() writes All when there is no plugins.yml, new install or
  not; settings.RanBefore, which only told the two apart, is gone.
- plugins.yml gets `settled: 1`. A file below it is brought up once on
  start: an Essentials preset becomes All, the user's own rows kept (a
  plugin they turned off stays off). Every write (Set, SetConfig,
  SetPreset) sets it, so `magpie plugin preset essentials` picked
  afterwards stays the user's. An unreadable or unparsable file is left
  alone, as before.
- Docs (plugin-runtime.md) and comments that said a new install starts
  with Essentials.

Run (origin/main 72ed518bc + this):
- gofmt -l internal: clean; go vet pluginrt, cli, gui, settings: clean.
- go test ./internal/pluginrt/ ./internal/settings/: ok. New
  TestSettleBringsUpAnEssentialsInstall; TestSettleAndSet and
  TestBuiltinSwitch now check a new install has all 14 on.
- Broken by hand (Settle writing Essentials, the bring-up skipped):
  TestSettleAndSet, TestSettleBringsUpAnEssentialsInstall and
  TestBuiltinSwitch go red; restored, green.
- Real binary, sandbox HOME: a new install lists all 14 on and writes
  `preset: all, settled: 1`; a plugins.yml of `preset: essentials` with
  otel off comes up `preset: all`, groups/library/sessions/warmups on,
  otel off.
- go test -count=1 -timeout 45m ./...: every package ok but internal/cli
  (TestPluginLoginTakesTheLapseOff, passes 5/5 alone here and on
  72ed518bc; filed #2748) and internal/gui (TestMainWindowCorners, #1936).
- GUI: builtins.test.cjs 4/4 (chromium + webkit; a first try under load
  ~445 had chromium's page.goto time out at 5s, #2542),
  routing-groups-off.test.cjs pass. Only comments changed in those two.
2026-10-17 22:54:38 +08:00
yetone 1e643ba7e1 provider: a model listed by its display name ("GPT-6 Sol") joins the group magpie found for gpt-6-sol (Chill on Discord)
Chill added a provider "Only through routing groups". Its Claude models
(tidy ids) were filed into the groups magpie found, but a model the relay
lists as "GPT-6 Sol" was not grouped with gpt-6-sol.

Cause: autoGroups buckets models by mergeKey, which is sameModel: it
lowercased and turned "_" into "-" but kept spaces. "gpt-6 sol" and
"gpt-6-sol" were two buckets of one provider each, so no group held
them, though the group id (Slug of the key) was auto-gpt-6-sol for both.
Siblings checked: AutoGroupOf (and AutoStandIn, reseat and group import's
Instead through it), GroupFor and groupNamed already compare by
Slug(sameModel(..)) and were right; setModelSame's "its own id" check and
the editor's Merge placeholder (MergeName) use sameModel raw and get the
same fix. Group Match patterns are the user's own globs, not a name
match, and are unchanged.

Fix: sameModel spells a run of spaces (a no-break one too), "_" and "-"
as one "-", after dropping the vendor's prefix. Every word still counts,
so gpt-6, gpt-6-mini, gpt-6-sol and gpt-6-sol-mini stay apart, as do a
:variant and a four-digit release. Two ids now merged already had the
same auto-… id, so no saved group id or agent config changes.

Not done on purpose: OpenAI's dashed date (gpt-4o-2024-08-06) is not
stripped. sameModel strips YYYYMMDD and Ark's YYMMDD, but keeps release
suffixes that are models of their own; an OpenAI dated id is a pinned
snapshot apart from the moving alias, and stripping it would change the
id of a group magpie has found for years (auto-gpt-4o-2024-08-06) that
agents and saved groups name. The test pins it apart.

Test: TestSameModelDisplayNameAsID (sameModel spellings, pairs that must
stay apart, and Chill's case end to end: provider x with gpt-6-sol and
gpt-6-mini, provider y Unlisted with "GPT-6 Sol", "GPT 6", "GPT-6 Sol
Mini"; auto-gpt-6-sol has x/gpt-6-sol and y/GPT-6 Sol, no other found
group forms, AutoGroupOf and GroupFor agree). With group.go put back it
fails: sameModel("GPT-6 Sol") = "gpt-6 sol", and auto-gpt-6-sol: [] false.

Docs: providers-accounts.md's Routing groups row says what the same
model is.

Run at this head (sandbox HOME, pinned caches): gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
-tags nogui ./..., go build: ok.
Full suite: go test -timeout 45m ./... at 2042123f4 + this change (sandbox
HOME, load ~350 with two other full suites running): 64 packages ok,
internal/gateway and internal/provider among them. Two reds, both filed
already: internal/agent hit the 45m timeout (#2723, #2544), and
internal/gui's real-window AppKit tests (TestPanelCloseHidesIt,
TestPanelJoinsFullScreenSpaces, TestDockJoinLeadsCommandTab,
TestDockReopenKeepsTheWindowsSpace, TestMainWindowCorners) were killed
at their 30-40s deadlines (#2645, #1936). Rerun alone: internal/gui ok
(326s), internal/agent ok (2619s).

No GUI asset changed, so the Playwright suite was not run. Not tried
against Chill's real relay: the fixture is the model id as reported.
2026-10-17 22:46:55 +08:00
yetone 48aae83b82 gateway: what Jev is told of a turn is masked unless Jev itself may have it unmasked
A routing group whose every member the user set to go unmasked
(unredactedRoute, provider.SkipsRedaction) hands its rules the body as the
agent wrote it. That was right for the members, but a group's Jev is none
of them: askJev sent the message, and since the commit before also the
user's message before it and the reply, to a remote decision provider
unmasked. The chat-model classifier was not affected (it goes through
serve, which masks).

askJev now masks the state's three texts with maskedText (maskedState)
unless Jev's own provider skips redaction, and fails closed when the
masker can't serve, as redacted does. Found by the agent writing the
commit before, on reading unredactedRoute's callers.

TestJevIsToldTheTurnMaskedWhenTheGroupGoesUnmasked: both members
Unredacted on local addresses, mask personal data on, an email in the
message and the one before; no state value Jev gets holds it. Broken by
hand (the SkipsRedaction check made `false &&`): red, "previous_user_message
went to Jev unmasked". gateway-routing.md says it beside unredactedRoute.

Full suite at bf2018807 (89521b03d + both commits): go test -p 3 -tags nogui -timeout 45m ./... under a sandbox HOME: 65 packages ok, gateway among them; internal/agent hit the 45m timeout (#2544, as on main under load ~330). gofmt -l clean; go vet -tags nogui, GOOS=windows go vet of internal/gateway ok.
2026-10-17 22:45:57 +08:00
yetone 6b5501027d gateway: Jev is told the user's message before and the reply to it, so a short follow-up routes like its turn (@HirotaNagai on X)
A follow-up like "继续", "yes" or "fix that" was classified alone, so it routed
as a trivial turn. The decision classifier (Jev's state and the chat-model
classifier's prompt) now also gets previous_user_message and
previous_assistant_reply, when present.

- Taken from the same parsed request as the classified message, after the
  gateway masks it, so the new fields are masked the same way. The answer
  cache key includes them.
- The reply is the text of the latest assistant message after the previous
  user message. Never thinking, tool calls, tool results or system prompts;
  a tool-only reply gives nothing.
- Caps: the message keeps 3000+1000. The previous user message is cut to
  its first 750 and last 250; the reply keeps its last 1000. Together at
  most half the message's cap.
- The intent, level and effort instructions name the keys only when they
  are present, as context, not the thing being judged.

Tests: TestTurnBeforeEachProtocol, TestTurnBeforeCuts,
TestJevIsToldWhatCameBefore, TestChatClassifierIsToldWhatCameBefore,
TestClassifyKeepsAnAnswerPerTurnBefore, TestJevSeesTheTurnBefore. Each was
broken by hand and went red (10 breaks: reply taking thinking or tool
arguments or a tool result, searched past the user message, no caps,
jevState dropping the keys, priorAsk naming both always, writePrior not
called, rules.go not setting prev, a cache key without the turn before,
privacy off in the end-to-end test).

Run at 85eef5d87 + this: gofmt -l clean; go vet ./..., GOOS=windows go vet
./..., GOOS=linux go vet -tags nogui ./... ok; go test -p 3 -tags nogui
-timeout 45m ./... 65 packages ok; internal/agent timed out at 45m under
load ~350 (origin/main alone: 2305s), alone with -timeout 90m ok, 936s
(#2544). Rebased on 89521b03d; full suite at bf2018807 (89521b03d + both commits): go test -p 3 -tags nogui -timeout 45m ./... under a sandbox HOME: 65 packages ok, gateway among them; internal/agent hit the 45m timeout (#2544, as on main under load ~330). gofmt -l clean; go vet -tags nogui, GOOS=windows go vet of internal/gateway ok.

When every group member skips redaction, unredactedRoute handed Jev the
unmasked body, now with the turn before as well; the next commit masks
what Jev is told.
2026-10-17 22:45:57 +08:00
yetone 6690caaaec gateway: auto mode's review isn't asked of another subscription's Claude model, and Claude Code's set model is judged where it goes
Claude Code 2.1.302 tells a session behind magpie "this session isn't
eligible because your requests go through 127.0.0.1:3425" and points the
gateway at code.claude.com/docs/en/auto-mode-classifier-billing. That
page asks a gateway to forward the dangerous-tool-use-2026-09-03 beta and
the top-level `safeguards` field, and to return `safeguard_results`
(message_delta.delta in a stream) with tool-use ids unchanged; one that
can't should have clients set CLAUDE_CODE_AUTO_MODE_SERVER=0. magpie
already does this on every route Anthropic answers (Claude subscription
bridge, api.anthropic.com, relays, Bedrock, Vertex) and writes the 0
when no reachable model is reviewed (24350a372). Only Anthropic can
produce safeguard_results, so for any other model the 0 is the remedy;
magpie never answers one on Anthropic's behalf.

Gap fixed here: AutoModeReviewed counted any claude-* name as reviewed,
so a Claude model on another vendor's subscription or a plugin (Copilot,
Kiro, Cursor…) was sent the beta and safeguards (Copilot 400s on them,
#1756) and counted as reviewed by the agent wiring, which then left
CLAUDE_CODE_AUTO_MODE_SERVER unset and the notice showing. Now an
account provider counts only when it is the Claude subscription or sits
on api.anthropic.com; providers with a key keep the name rule. And
claudeReviewed resolves the models Claude Code is set to (group,
provider, fallback) before judging them, as the gateway would, instead
of by name alone.

Tests: TestAutoModeReviewedRoutes (copilot/kiro/plugin cases),
TestAutoModeReviewLeftOffOtherSubscriptions,
TestClaudeReviewedJudgesTheSetModelWhereItGoes. Broken by hand: with
automode.go reverted, the first two go red (copilot/kiro/x-plugin true;
copilot beta+safeguards sent); with claude.go reverted, the third goes
red (v/gpt-x falling back to a/claude-sonnet-5 not reviewed).

Run at 2042123f4 + this change, sandbox HOME, load ~350:
- gofmt -l: clean. go vet ./... (darwin), GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: clean.
- go test -timeout 45m ./...: 63 ok, 3 red, all filed and none in code
  this touches: internal/agent hit 45m (#2723, #2544); gateway's
  TestPluginStreamLargeReplies/JSON_fast hit its client timeout (#2551);
  gui's TestMainWindowCorners was killed at its deadline (#1936, #2645).
- Reruns alone: internal/agent -timeout 90m ok (2637s);
  TestPluginStreamLargeReplies ok; TestMainWindowCorners/macOS_26_SDK
  killed at 40s again at load ~200 (#1936).
After rebasing onto origin/main c4aeaec74 (6 commits, none in these
files): go vet of gateway and agent clean; TestAutoMode*,
TestSafeguards*, TestClaudeBridgeSafeguard* ok; the agent review tests
printed one bare FAIL whose output was cut off by tail, then passed
alone and -count=3 -v (all PASS); cause of that one FAIL not known.
Not run: a real Copilot/Kiro account through Claude Code (the agent test
covers the resolution with key providers; the account rule is covered
in the gateway unit tests), the GUI node suite (no GUI change).
2026-10-17 22:43:54 +08:00
yetone 72ed518bca gateway: an account's own list of models no longer refuses a ChatGPT account's GPT Image (heyiwei5 on X)
heyiwei5 on X: a Codex routing group's agent asked Magpie Image for
codex/gpt-image-2 and was told 403 "model "codex/gpt-image-2" is set not
to be served by any account or key of Codex: each one's own list of
models leaves it out. Add it to an account's models in magpie
(Providers → the account's Models)". That advice can't be followed: an
account's own list (#474) is picked in the editor from the provider's
chat models, and a ChatGPT account's GPT Image (like a Grok
subscription's Grok Imagine and a WorkBuddy plan's image models) is
never among them. So any account list kept for some chat models turned
every drawing away.

drawOnAccounts now treats those accounts as not listing the image model
(asked after those that do) rather than barred, for providers whose image
models magpie names itself (listsCantName: drawsCodex, drawsGrok,
drawsWorkBuddy). A capped account is still held. A key's own list, which
is picked from models that include its image ones (a relay's
gpt-image-2), still bars them, as nonchat_keys_test checks. Videos don't
go through account lists for Grok, so nothing to change there.

Run:
- TestCodexDrawsPastAccountModelLists on origin/main 6f950653f: red with
  the reporter's 403 above; green with the fix (gpt-image-2 and 2.5).
- go test ./internal/gateway -run 'Draw|Draws|NonChat|Keys|AccountModels|Grok|WorkBuddy': ok.
- go test -timeout 45m ./...: every package ok except internal/agent,
  which hit the 45m timeout with load average ~400 on this machine
  (running TestOwnProviderNamedAsMagpies/openchamber for 2s, not hung);
  rerun alone with -timeout 90m: ok in 1923s.
- gofmt -l clean; go vet ./internal/gateway on darwin, GOOS=linux, GOOS=windows.
- Real ChatGPT account in a sandbox HOME (auth.json copied, 140h left on
  its token, nothing refreshed), its own list set to gpt-5.5 with
  `magpie provider account-models codex <user> gpt-5.5`, POST
  /v1/images/generations codex/gpt-image-2: origin/main's build answers
  the reporter's 403 word for word; this build draws a PNG.
2026-10-17 21:28:33 +08:00
yetone d432920f02 search: DeepSeek's Search API as a search API vendor (TJHHHH on Discord)
DeepSeek's own Search API (api-docs.deepseek.com/guides/search) can now be
added as a search API, with a DeepSeek API key:
- provider.SearchVendors: deepseek, at https://api.deepseek.com, keys at
  platform.deepseek.com/api_keys, offered after You.com.
- askSearchAPI: POST /v1/tools/search, Bearer key (the default), body
  {query, count: searchHits}. The query is cut to the 128 characters the
  docs allow (a longer one is a 400); need_content stays false.
- readSearchAPI reads its summary (the docs' text "for a model",
  ~600-800 chars) as the page's text, since content is empty without
  need_content; its snippet stands in when there is no summary, and its
  date (RFC 3339 or null) is the page's age. Other vendors' fields are
  read as before; summary and snippet are only fallbacks after content.
- 402 (no balance) and 429 (5 QPS per account) already rest a key as out
  of credit and rate limited (searchRestFor); the test pins it for
  deepseek.
- Siblings: CLI usage (main.go, search_cli.go's api list and empty-state
  hint), README.md, README.zh-CN.md, gateway-routing.md's path list. The
  GUI takes its vendors from SearchVendors (no vendor list in app.js or
  i18n), so no GUI file changes.

Not tried against the real DeepSeek API (no key in this run); the fake is
built from the docs' response shape, with null site_name/date and empty
summary/content. Note DeepSeek bills direct API calls ($0.75 per 1,000
non-empty searches).

Run (worktree on origin/main bad4508c4 + this, the Factory and the Qoder
mover commits; machine load 130-345):
- TestDeepSeekSearchAPI (new) passes. Broken by hand five ways, each red
  with its own message: summary not read (Text "Download Go."), query not
  cut ("a long query went as 200 characters"), date not read (Age ""),
  path /search instead of /v1/tools/search, snippet not read (second
  page's Text ""). Restored: ok.
- gofmt -l internal cmd: nothing.
- go vet -tags nogui ./... on darwin, GOOS=linux, GOOS=windows: all ok.
- set -o pipefail; go test -tags nogui -timeout 45m ./... under a scratch
  HOME: 65 packages ok (gateway 2654.9s, provider 930.5s, cli 533.2s);
  internal/agent timed out at 45m (2704s, TestReverseProxyIsStillMagpie/
  nginx running). That is #2723, untouched by these commits; rerun alone
  with -timeout 90m: ok 3565.0s. Recorded on #2723.

After rebasing onto origin/main 89521b03d (13 new commits, none in the
search or mover files): gofmt -l . empty; go vet -tags nogui ./... ok on
darwin, linux, windows; go test -run 'Search|Mover|Moved|Migrat|Plugin'
./internal/gateway/ ./internal/provider/ ok (173.4s, 89.8s); go test
./internal/cli/ ok (286.5s). The full suite was not rerun at the rebased
head.
2026-10-17 21:24:33 +08:00
yetone 89521b03d6 cli, gateway: magpie cpu records the running magpie's CPU profile for 30s, for a report of high CPU (@LeiCheng42 on X)
@LeiCheng42 on X reports magpie using the most CPU while Codex runs. As
with magpie heap (e085d6e92), Activity Monitor and `sample` show Go's
frames as ???, so `magpie cpu [<file>] [--seconds N]` asks the magpie
serving the gateway for GET /v1/magpie/cpu?seconds=N: runtime/pprof's CPU
profile over 30s (5..120; else 400), gzipped protobuf, with the pid,
version, uptime, CPU time used over the window (getrusage / GetProcessTimes)
and since start, cores, GOMAXPROCS and goroutines in X-Magpie-CPU-Stats. It
tells the user to use magpie as when busy (run Codex) while it records,
writes <file> else magpie-cpu-<date>-<time>.pb.gz (0600), refuses a file
that is there before recording, and says "is magpie running?" at once when
nothing answers. --help writes nothing; an unknown flag, "-", a second file
or --seconds out of range are refused before anything is asked.

Only the profiling request waits: the gateway serves everything else
meanwhile. pprof keeps one CPU profile at a time, so a second ask gets 409
(cpuRecording), and a caller that hangs up stops the recording. The route
takes heap's guard: heapRefused's checks move into profileRefused, shared
by cpuRefused, so only a loopback, unproxied, browserless call to a
loopback Host gets it, with or without a gateway key or lanGuard.

Run at bad4508c4 + this: gofmt -l (nothing); go vet ./..., GOOS=linux go
vet -tags nogui ./..., GOOS=windows go vet ./... (clean); go test -tags
nogui -timeout 45m ./... under a sandbox HOME: every package ok except
internal/agent (45m timeout, #2544; again alone, in TestPortMovesEveryAgent)
and internal/gateway (TestTranslatedStreamKeepsClientAlive/chat_to_responses,
sibling of #2169/#2711, filed as #2737; alone with -timeout 45m only
/chat_to_anthropic, #2169; the test passes 5/5 alone). TestCPU* -race
-count=3 ok. Broken by hand: cpuRefused returning "" (19 failures in
TestCPUProfileOnlyToThisComputer); no one-at-a-time guard and no hang-up
stop (TestCPUProfileOneAtATime red each); no seconds bounds, no pre-check
of the file, no is-it-running check, no help case (each CLI test red).
Rebased on 2042123f4: go build ./..., gofmt -l, GOOS=windows and
GOOS=linux vet of internal/gateway and internal/cli clean; go test -run
'CPU|Cpu|Heap|Help' ./internal/cli ./internal/gateway ok.

Real use: the built binary's `magpie serve` under a sandbox HOME on
127.0.0.1:3493; `magpie cpu --seconds 5` saved a 0600 profile that go tool
pprof -top reads and printed the numbers; a concurrent second one got the
409 while GET / answered in ms; Origin: null and a rebound Host got 403;
--help wrote nothing; an existing file was refused. Not tried: the GUI
app's process, or the Windows box.
2026-10-17 20:52:13 +08:00
yetoneandtimonwong 2042123f43 provider: a provider switched off for a while stays in the groups magpie found, so agents on auto-<model> aren't rewritten to the one left (#2671)
timonwong (#2671, with the branch this is): a found group, auto-<model>,
was built from the providers that are on only, so switching off one of
its two providers took the group away. Every agent on group/auto-<model>
was reseated to the other provider's model (agent.Reseat → sameModel),
rules and groups naming it went 404, and switching the provider back on
brought the group back but not the agents' settings.

timonwong's change, ported as is (05927b833, 063fe15a2):
- models.go: entriesOf(of, off), and heldOffEntries(), the models of the
  providers that are Ready and Off (a keyless one, a plugin not signed in,
  finds no group), held per request like the other entries.
- group.go: foundGroups/foundFrom merge those back in the Providers order
  before autoGroups, in groupsIn, DeleteGroup and RenameGroup. membersIn
  already skips a switched-off member, and the Routing page already says
  it as switched off (memberJSON.providerOff).
- A removed provider still leaves the group; NoAutoGroups and
  ModelSameAs are honoured; a hidden found group stays hidden.
  Side effect: a found group whose only usable member is left shows while
  a provider is off, which is the point.
Reviewed line by line; nothing writes a user-set value, and Reseat now
has nothing to move for these agents, so there is nothing to restore when
the provider is on again.

Added here: TestReseatKeepsAFoundGroupWithAProviderOff (internal/agent:
Claude Code and Hermes on group/auto-gpt-5 are not moved when cop is
switched off, a model only cop served still is, the group resolves, and
switching cop on moves nobody) and TestFoundGroupMemberOfASwitchedOffProvider
(internal/gui: auto-x is on the Routing page with b/x said as switched
off). The docs row names the tests.

Red on bf931f82c's provider code (models.go and group.go from main): both
new tests, timonwong's TestFoundGroupWithAProviderOff (404 as in the
issue) and the updated TestProviderOff. Broken by hand (heldOffEntries
returning nil): the agent and gui tests and TestFoundGroupStaysWithAProviderOff
and TestFoundGroupRemovedWithAProviderOff go red.

Run at this change on bf931f82c: gofmt -l clean; go vet ./... (darwin),
GOOS=linux and GOOS=windows go vet -tags nogui ./... ok; full go test
-tags nogui -count=1 -timeout 45m ./... (load average ~140): every package
ok, internal/gateway and internal/provider included, except
internal/agent, which ran past 45m (#2544), and internal/middleware's
TestDocsExample, a strategy's wall-clock budget under load that passes
alone (filed as #2728). internal/agent then alone, -timeout 100m: ok in
2971s.
No GUI asset changed (the gui test is a Go test of groupsState), so the
Playwright suite was not run.

Co-authored-by: timonwong <timon86.wang@gmail.com>
2026-10-17 20:38:06 +08:00
yetone 992f288e20 gateway: a Chat-only relay that refuses tools with reasoning and none too moves a group on (#2670, JJ-Lin)
JJ-Lin's analysis in #2670 found both causes and gave the mock upstream
the tests use. A relay with a Chat URL alone answers tools with
reasoning_effort with "use /v1/responses or set reasoning_effort to
'none'", and then refuses none ("Supported values are: 'low', ...").

- forwardTranslated: when none was #176's own and is refused naming the
  levels, offRefused is still remembered (it is true of the model), but
  the request isn't asked again at the lowest level (refused the same by
  the upstream's own word). The tools refusal is the answer. The #176
  retry is gated on turnedAway(none) plus a per-request guard, so it
  can't loop. Before: the first request went [xhigh none low] and every
  later one [high], with the 400 going to the agent.
- passthrough (a chat client's relayed request), the sibling: the same.
  It used to ask none on every request and hand back the confusing
  "'none' is not supported" error.
- shapeRefused/retryable: a 400/422 that wrongEndpoint reads reaches the
  group only once the member has tried every API it has a URL for. The
  next member is now asked once, and this one doesn't rest (failShape).
  Before, the group stopped on it.
- The agent's error still names the Responses URL the provider lacks
  (wrongAPINote via asksResponses). Reading supported_endpoint_types from
  /v1/models was left out: wrongAPINote already says what to set, and
  trying Responses on the Chat base unasked isn't clean.
- docs/subsystems/gateway-routing.md says both.

Plain chat without tools, and gpt-6-astra (where none is taken) are
unchanged; TestToolsEffortNoneTaken pins both
([effort none] -> 200 three times in a row; no-tools [xhigh] -> 200).

Tests (internal/gateway/tools_effort_none_test.go, JJ-Lin's mock):
- TestToolsEffortNoneRefused: one Server, Codex xhigh/high/high asks
  [xhigh none], [high], [high]. Each answer is the tools refusal with
  the Responses-URL note. A chat client gets [high none], [high].
- TestGroupPassesOverToolsRefusedOnChat: group relay -> other. Three
  requests in a row are all 200 from other, tries[0] is failShape, no rest.
Broken by hand:
- fallback.go reverted: the group test is red (400 to the agent).
- translated restore off: "request 1 asked [xhigh none low]".
- passthrough check off: the chat client gets "'none' is not supported".
- turnedAway gate off: "request 2 asked [high low]". Without the
  per-request guard too, it loops forever (seen, killed).

Run on origin/main 7660399a1 (full suite), then rebased (darwin, machine load ~200):
- gofmt -l internal/gateway: empty.
- go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet -tags nogui ./...: ok.
- go test -tags nogui -timeout 45m ./... under pipefail: 63 packages ok,
  3 FAIL. internal/gateway hit the 45m timeout with no test failing
  (load ~200). internal/agent timed out in TestReverseProxyIsStillMagpie/nginx
  (#2723). internal/cli: TestPluginLoginInstallsItsCLIFirst TempDir
  cleanup "directory not empty" (#2722, as #2449).
- Rerun alone on cb05dc2d1: internal/gateway ok 2454s (-timeout 90m),
  internal/cli ok 764s, internal/agent ok 3100s (-timeout 60m).
- Rebased onto 04e8aa8f1 (fallback.go conflict with #2656's
  customToolRefusal; both matchers kept): vet (darwin, linux, windows)
  ok, internal/gateway ok 2454s.
- Rebased onto 50a703190 (no conflict; #2649, #2651, #2639 and #2444
  touch the gateway): go vet ./internal/gateway ok, and
  -run 'ToolsEffort|GroupPassesOverToolsRefused|CustomTool|Effort|Group'
  ok 234s. The whole package was not rerun at this last base.
Not tried against the reporter's real relay: the mock is built from the
bytes in the issue.
2026-10-17 20:33:28 +08:00
yetone e183604f06 claude: a tool named with a dot comes back under the name the client declared (#2649)
tsy0716's client offers a tool named "spawn.agent". Through a Claude
subscription the reply's tool_use called "spawn_agent", a tool the client
never offered: Claude Code keeps only [A-Za-z0-9_-] of an MCP tool's name,
and magpie handed the call back under the name Claude Code used.

The MCP helper now offers each tool under bridgeToolName: a name Claude
Code keeps as it is (and at most 51, 64 with mcp__magpie__) is unchanged;
any other, or one ending as a changed name ends (_ and 12 hex digits), is
cut to 38 of [A-Za-z0-9_-] and given 12 hex digits of its SHA-256. So
"a.b" and "a_b" stay apart, and the name is the same in every run: a
resumed session, the history told to a new run (renderParts) and the
tool-choice line (toolChoiceAsk) name it as the run was offered it.
subscriptionRun.names maps it back to the declared name in toolStart (Claude
Code's streamed and whole messages, so every API the bridge serves) and in
mcpCall (what an agent like Cursor is told through onCall). A name Claude
Code already kept goes upstream exactly as before.

What was run:
- New TestClaudeToolNamesComeBackAsDeclared: tools "spawn.agent",
  "fs/read", "has space", an 83-character name, "a.b" and "a_b", through
  /v1/messages, chat/completions and responses, client stream on and off,
  Claude Code's reply streamed and whole (12 cases); a fake Claude Code
  that changes names as Claude Code does and calls every tool it was
  offered. Checks the client gets exactly the declared names, and Claude
  Code was offered six valid, unique names of at most 51; and the history
  and tool-choice text use the offered name.
- Broken by hand: with the encoding taken out the test fails; with only
  the decoding in toolStart taken out, every case fails ("the calls name
  [a_b a_b_2e7336dc8eba fs_read_96379919f693 ...], want the declared").
- go test -run 'Claude|Bridge|MCP|Mcp|Tool' ./internal/gateway/
  ./internal/claudebridge/: ok.
- gofmt -l clean; go vet -tags nogui ./... on darwin, linux, windows: ok.
- Full suite at this head (8b1fad8f5 before the message change), as
  recorded in the #2651 commit: ok but three timing reds outside this
  change (#2719, #1889, and one fixed on main by bad4508c4), each green alone.
- Rebased onto origin/main 17557132c (7 commits, none in these files):
  gofmt and vet on all three systems, then internal/gateway,
  internal/provider, internal/netproxy and internal/claudebridge at
  9af3bb98b: ok. The whole suite wasn't run again at this head.

Not tried: a real Claude Code run with such a tool name.
2026-10-17 19:55:50 +08:00
yetone f550d3699c claude: a SOCKS proxy reaches Claude Code through magpie's HTTP bridge (#2651)
demystify0137's Claude account sits behind a socks5:// proxy. Every turn
was answered 502 after minutes of retries, Claude Code failing each try as
UnsupportedProxyProtocol: it is a Bun binary, and Bun takes only http://
and https:// proxies. magpie handed it the socks5:// URL as HTTPS_PROXY.

Every Claude Code magpie runs for the subscription now gets its env from
one helper, netproxy.EnvForBunWith, which sets the proxy as before and
puts the loopback HTTP bridge (netproxy.Bridge, #1409) in place of a SOCKS
URL: a turn (startRun), the model test (askClaude), /usage (claudeUsage),
sign-in (startClaudeSignIn) and the sign-in check (claudeSignedIn). Where
the bridge can't be used (it doesn't start, or Claude Code runs in WSL
under NAT, which doesn't reach this computer's loopback) the request fails
at once with that reason, instead of Claude Code retrying for minutes.
Other CLIs magpie runs with a proxy (grok, devin, cursor-agent) aren't Bun
(checked their binaries), and the settings.json env writer already leaves
SOCKS out.

What was run:
- Real Claude Code 2.1.302 in a sandbox HOME with a fake API key, through
  a fake SOCKS5 proxy (temporary test, removed): raw socks5:// gave "API
  Error: Unable to connect to API (UnsupportedProxyProtocol)" with 0
  SOCKS connections; bridged it reached Anthropic, 401 "Invalid API key",
  7 SOCKS connections.
- New tests TestEnvForBunWithBridgesTheProvidersSOCKS,
  TestClaudeCodeGivenTheBridgeForASOCKSProxy (turn, askClaude,
  claudeUsage), TestClaudeSignInBridgesASOCKSProxy. With proxied()
  put back to EnvWith both gateway and provider tests went red ("Claude
  Code was given the SOCKS proxy: https=socks5://127.0.0.1:1...",
  "login-proxy: Claude Code ran with HTTPS_PROXY=\"socks5://127.0.0.1:1\"").
- gofmt -l clean; go vet -tags nogui ./... on darwin, GOOS=linux and
  GOOS=windows at 8b1fad8f5: ok.
- Full suite at 8b1fad8f5 (this and #2649 on origin/main 9f9bfc160),
  -tags nogui -timeout 100m, load ~290: every package ok except three
  timing reds outside this change, each green alone with -count=3:
  TestBurstTellsNoSpeed (#2719), TestFXStateDoesNotWait (fixed on main since, bad4508c4),
  TestTaggedReposSlowRead (#1889). internal/agent passed (3659s); at
  -timeout 45m it timed out twice at the earlier base 7660399a1 with no
  --- FAIL before the deadline (#2544), and passed alone at 100m (2790s).
- Rebased onto origin/main 17557132c (7 commits, none in these files):
  gofmt and vet on all three systems, then internal/gateway,
  internal/provider, internal/netproxy and internal/claudebridge at
  9af3bb98b: ok. The whole suite wasn't run again at this head.

Not tried: Windows, or Claude Code in WSL (mirrored or NAT).
2026-10-17 19:55:49 +08:00
yetone 717b69f78a routing: a conversation held to its native compaction's account says so, not "the only account on" (#2639)
A turn carrying a native compaction goes only to the account that
sealed it, so the route's order has one account, and Routing's first
line read "{who} is the only account on for {model}". On #2639 that
read as the other account not serving the model. The route now names
the sealer (Route.Compaction, compactionWho), and Routing says the
conversation stays on it because only it can read the compaction, and
that a new conversation uses the others. Translated in zh, zh-TW, ja
and de.

Run on origin/main f191d6423 with this change:
- TestNativeCompactionRouteNamesItsWriter: green; with Compaction taken
  off the route in gateway.go by hand, red (compaction "").
- go test -run 'NativeCompaction|Compact|TestCodex|Trace|Route|
  TestProtection' ./internal/gateway: ok. go vet ./internal/gateway on
  darwin, GOOS=linux and GOOS=windows -tags nogui: ok. gofmt -l clean.
- routing-compaction.test.cjs (chromium and webkit; en zh zh-TW ja de)
  with i18n-keys: 13/13; with the client.js line removed by hand,
  routing-compaction 10/10 red.

Earlier, on dccfefdf7 with an older series around this change (since
landed by bf931f82c in another form, so dropped here): full suite once,
go vet ./... on all three OSes ok, go test -timeout 45m ./... every
package ok except internal/gui's 7 real-window AppKit tests killed at
their deadlines at load ~290 (#2645). The routing-*, panel-routing* and
i18n-keys GUI files, one at a time: reds only in routing-bodies,
routing-keys-fold, routing-model-rest and routing-request-metrics, red
the same on origin/main 84cd686af (28 there, 25 with this; #2658,
#2559, #2571). Not run on f191d6423: the full suite.
2026-10-17 19:29:07 +08:00
yetone 04e8aa8f10 library: typing with an input method no longer moves the page (#2636)
In Library -> Instructions, typing Chinese through an input method made the
page jump up or down while a word was composed. The cause: the textarea's
autosize set height:auto to measure scrollHeight, so the page went short for
a moment and the browser clamped the view's scrollTop. Putting the height
back doesn't undo a clamp. app.js's scroll guard took the clamp for a scroll
the reader didn't make, and its scrollIntoView({block:"nearest"}) pulled a
textarea taller than the view to one of its edges. Every composition step is
an input, so this happened on every keystroke.

autosize (the only one in the GUI, used by a set's text, an agent's own
text, a skill's description and subagent boxes) now holds the textarea's
parent at its height while measuring, so the page never goes short.

What was run:
- New internal/gui/tests/library-ime-scroll.test.cjs covers en/zh, 980/560px,
  a Default set's text and Cline's own text. Chromium composes through CDP
  Input.imeSetComposition/insertText. WebKit gets synthetic
  composition events and inputs.
  - With the fix: 9/9 in both engines, before and after rebasing onto f191d6423.
  - With client.js reverted by hand: red in both engines (4 of 9), set:default
    in every lang/width; the page went e.g. 1000 -> 862, 1401, 1634.
  - extra:cline wasn't red on main: its clamp is put back before paint. It
    stays as a sibling guard.
- library-row-open-scroll and library-instr-sets pass in both engines.
- The whole GUI suite ran in both engines at concurrency 6, load ~150-300.
  - Chromium: 5408/5519. WebKit: 5442/5547.
  - Failed files were rerun at concurrency 2 and on unmodified main
    (c1e95f919). All are red on main too and already filed (codex-predictions
    #2624, segs-glide/lightweight #2683, provider-advanced-fold #2710,
    tray-cell-click #2686, removed-groups-menu-scroll #2172/#2211, others as
    filed).
  - WebKit plugin-moved-signin and update-release-page passed alone.
    removed-groups-menu-scroll went 4/4 three times. No library file
    stayed red.
- gofmt -l: clean. go vet: darwin, and GOOS=linux and GOOS=windows with
  -tags nogui: clean.
- go test -timeout 45m ./... under pipefail in a sandbox HOME: exit 0.

Not tried: a real system input method (macOS Pinyin) in the real app. Only
CDP and synthetic composition were used.
2026-10-17 19:04:59 +08:00
yetone 17557132cb gui: in a narrow window the title bar's tools show their icons, then the title gives way; nothing lies over it (#2625, linusxiong)
Beside the sidebar, Library's, Plugins' and Settings' heads sit in the
title bar after the breadcrumb, between --tools-l (the crumb's right +
16) and the window's buttons, laid out flex-end. When the tools needed
more than that room they ran on to the left, over the crumb: at about
650pt with the sidebar, Library -> MCP servers had 「发现」 over
「MCP 服务器」's last character. The crumb never gave way to them.

app.js tools() now shares the room out, laying out and reading each
step in its one frame, the next only if the tools still run over:
1. the crumb whole (its natural width from its parts, the last one's
   scrollWidth) and the tools with their words;
2. body.tools-tight: Library's Discover / Library folder / Backups and
   Plugins' "Mirrors in China" show their icon (or switch) alone. Each
   keeps its name as aria-label (a hidden span leaves the accessible
   name) and its tooltip as before (the folder's path, the backups'
   note and path, Discover's and the mirrors' sentences);
3. --crumb-max: the crumb drops its leading parts ("Work /"), a part
   and its slash at a time, and last cuts the page's name at its end.
In the side-nav head the Library buttons and the mirror switch are
flex: none and Plugins' search keeps 120px, so what doesn't fit shows
as running over rather than shrinking out of sight. The views'
MutationObserver also asks tools() again, as a tab's own tools change
(Discover only on MCP servers and Skills) without the crumb resizing.

title-bar-tools.test.cjs (new): every Library tab, Plugins' three and
Settings, sidebar picked, window mode, at 560 (the window's least),
650, 760, 900, 1024 and 1280px, in zh, zh-TW, ja, de and en, Chromium
and WebKit. No tool lies over the shown title or another tool or out
of the bar, no label is cut, an icon-only tool has aria-label and
title, only leading crumb parts go and the page's name shows, whole
from 650px. Against the old assets (MAGPIE_GUI_ASSETS) it fails in all
five languages at 560px Library Instructions ("a tool lies over the
title"); with the change Chromium 5/5 and WebKit 5/5. Looked at
screenshots of zh Library MCP servers and Plugins Discover at 560, 650
and 760px.

docs/subsystems/gui-shell.md says how the title bar gives way.

Run with both #2623's and #2625's changes, on b7d9616d0 (macOS, Go
1.26.8, load average 80-270 from other sessions):
- gofmt -l: nothing. go vet -tags nogui ./... with GOOS darwin, linux and
  windows: clean.
- set -o pipefail; go test -timeout 45m ./...: every package ok except
  internal/agent (2702s) and internal/gateway (2721s), which ran past
  45m under the load (#2544, #2108; no test hung, each was seconds into
  its run). Rerun with -timeout 90m: internal/agent ok (2816s);
  internal/gateway's only red is TestDesktopSubagentUnsetDoesNotDecode,
  "allocated 1 times" (10/10 green alone, filed as #2699). The textcalls
  tests passed in that run.
- The whole GUI suite, both engines (NODE_PATH at playwright@1.62.0). It
  ran in two parts, because another session deleted the first part's log
  mid-run; the files from provider-* on were run again. title-bar-tools
  passed 10/10 inside the suite. The reds are red the same way on
  b7d9616d0's assets, rerun beside them (MAGPIE_GUI_ASSETS) at
  concurrency 1-2:
  - segs-glide 20/20: filed #2683.
  - sidebar under load: filed #2684; 4/6 red on the old assets.
  - lightweight: filed #2638.
  - Already filed:
    - usage-agents-hide (#2276), routing-bodies (#2559, #2658),
      routing-keys-fold (#1612), routing-model-rest (#2115),
      routing-wb-restricted (#1905), rest-try-now (#2564), s3-sync (#2448).
    - quota-count-wrap, quota-name-translated and usage-fold (#2399),
      usage-checkin (#2549), usage-refresh (#2184), usage-ledger (#1876).
    - codex-predictions (#2624), github-sync (#2631), login-import (#1307).
  - The rest were Playwright launch timeouts under load (#2371).
- After rebasing on origin/main 85eef5d87: title-bar-tools Chromium 5/5,
  WebKit 5/5. Before that, WebKit zh and ja failed on a page error, "Fetch
  API cannot load /api/providers due to access control checks". That is
  WebKit's report of a sidebar read cancelled by the test going to the
  next page (#1350, #1307). The test now leaves that one WebKit message
  out. Against b7d9616d0's assets, WebKit ja is still red: "a tool lies
  over the title at 560px library instructions".

Not tried in the real app on Linux (WebKitGTK) or Windows (WebView2);
no motion or new browser API is involved, only layout.
2026-10-17 18:41:43 +08:00
yetone 7ea8aeaba7 gateway: DSML written with a run of pipes (<||DSML||invoke) is made the call too, not left as text (#2623, OKURBITO)
DeepSeek wrote its tool call as <||DSML||invoke name="get_weather">…
(two full-width pipes each side) and the reply reached the Responses
client as that markup: textCallAt only knew the one-pipe marks, so
nothing was held and parseTextCalls, whose regexes already read a run
of pipes, never ran. dsmlMark now finds a DSML tag's mark as the parse
regexes (dsmlTag) read one, with no list of spellings: <, spaces, / and
spaces for a close, a pipe, a run of pipes and spaces, DSML, and
another run that may be empty. A pipe is ASCII | or full-width |, in
any number and any mix of widths. textCallAt uses it to find a call
and to hold a mark still being written (down to a full-width pipe's
first bytes); cutMark uses it to trim a tag cut short at the end, once
the tag has begun its pipes, so a value ending "a < " keeps its "<".
Every route goes through these: textCallSee (translations),
textCallTidy (relayed Chat streams) and wholeTextCalls (whole Chat
replies). OKURBITO pointed out on the issue that a spelling table
leaves |||, ||, || and the like as text; this reads the class.

Tests (textcalls_pipes_test.go). Which cases were seen and which were
made up, as OKURBITO set out on the issue: one reply was written by a
model on its own in real use (deepseek-flash offered web_search:
<||DSML|| calls> … <||DSML|| invoke name="web_search"> …), kept
byte for byte as observedPipes; the issue's get_weather reply came from
asking the model to echo the markup; every other spelling (three pipes,
ASCII, widths that disagree, spaces after <, no pipes after DSML) is
constructed and has not been seen.
- TestTextWrittenDSMLDoublePipe: the observed reply, relayed Chat
  streamed and whole, is a web_search call with its query and no DSML
  left; the issue's reply through /v1/responses, streamed and whole, and
  a whole Chat reply, is a get_weather call with {"city":"Beijing"} and
  no message item.
- TestTextWrittenDSMLAnyPipes: | | || || || || ||| ||| "| |", each reply
  sent one character per chunk: the call, wrapped with text before, a
  space before invoke (the live <||DSML|| invoke), no parameters, cut
  short, tags only with the last cut short, a tool not offered, a mark's
  start at the end, pipes without DSML; each ends as the one-pipe reply.
- TestTextWrittenDSMLDoublePipeEveryCut: the reply split at every byte
  boundary JSON allows is the same call; textCallAt holds each prefix of
  the mark, a full-width pipe's first bytes too.
- TestTextWrittenDSMLMarkAsParsed: widths that disagree within a tag
  and between its open and close, spaces after < and around /, no pipes
  after DSML are each the call; a cut-short <parameter> value ending in
  "a < " keeps it; "x < y and a <" stays text.

Fails without the change: with b7d9616d0's textcalls.go all four
FAIL, the observed reply among them ("text \"<||DSML||invoke …\" calls
map[] finish \"stop\"", "a message item beside the call"; MarkAsParsed's
widths that disagree, spaces after <, no pipes after DSML); the one-pipe
rows pass there. With an earlier draft of dsmlMark (a run of pipes,
none after <, one required after DSML) MarkAsParsed FAILs its
spaces-after-< and no-pipes-after-DSML rows; with cutMark's
has-begun-its-pipes guard taken out it FAILs the cut-short value ("a "
for "a < ").

Not tried against a real DeepSeek upstream: the fixtures are the
bytes OKURBITO posted. In the observed event the request offered only
a hosted web_search ({"type":"web_search"}), not a function; a call to
a tool the request didn't offer by name still goes on as text, as
before, and the test offers web_search as a function.

Run with both #2623's and #2625's changes, on b7d9616d0 (macOS, Go
1.26.8, load average 80-270 from other sessions):
- gofmt -l: nothing. go vet -tags nogui ./... with GOOS darwin, linux and
  windows: clean.
- set -o pipefail; go test -timeout 45m ./...: every package ok except
  internal/agent (2702s) and internal/gateway (2721s), which ran past
  45m under the load (#2544, #2108; no test hung, each was seconds into
  its run). Rerun with -timeout 90m: internal/agent ok (2816s);
  internal/gateway's only red is TestDesktopSubagentUnsetDoesNotDecode,
  "allocated 1 times" (10/10 green alone, filed as #2699). The textcalls
  tests passed in that run.
2026-10-17 18:41:43 +08:00
yetone 8233eadaec provider, gateway: a plugin's model served at priority has fast mode, whichever plugin (Lovest on Discord)
Since #2514 a plugin can say which tiers its vendor serves a model at
(serviceTiers). CanFast still returned true only for Cursor's plugin, so
no other plugin's models could be a group's fast member or an agent's
fast pick. The Routing and Agents pickers (gui/groups.go, agent/route.go
FastFor) and SetFastPick/SaveGroup all read CanFast, so they refused too.

Changes:
- CanFast: a plugin's model has fast mode when the plugin says it is
  served at "priority", on its Chat or Responses API (pluginTierOn), where
  the gateway sends service_tier. This holds for any plugin. Cursor's
  fast flag and -fast sibling logic are kept below it, unchanged.
- UltraOn/CanUltra: such a model can also be picked Ultrafast when the
  plugin says "ultrafast". Before, plugins were excluded outright.
- forwardTranslated: a plugin's request whose agent spoke Claude's API
  carries fast mode as speed "fast", with no tier. It is now given tier
  "priority" ("ultrafast" for an Ultrafast pick) when the model is served
  at that tier. Before, Claude Code's fast pick on a tiered plugin went
  out with no service_tier.
- The "no fast mode" error names plugins.
- docs/subsystems/provider-plugins.md says all of this.

Test: TestPluginTiersGiveFastMode (gateway, fake plugin with FAKE_TIERS):
- CanFast and CanUltra: fake-1 (priority+ultrafast) true/true,
  fake-resp (ultrafast only) false/false, fake-claude (none) false/false.
- fake-claude is refused as a fast member and as a fast pick.
- A fast group member reaches the plugin's fetch as priority from Chat,
  Responses and Anthropic.
- Claude Code's fast pick sends priority, its Ultrafast pick sends
  ultrafast, and another agent's request sends none.

Broken by hand, each then restored green:
- CanFast's tier check off (the old behaviour): red on CanFast(fake-1),
  CanUltra(fake-1) and the fast member being refused.
- forwardTranslated's Fast-to-tier off: red on the anthropic member, the
  fast pick (nil, want priority) and the Ultrafast pick.
- UltraOn's plugin branch off: red on CanUltra(fake-1) and "no account
  offers Ultrafast".
Existing TestPluginServiceTierReachesFetch, TestPluginModelServiceTiers*
and TestCursorPlugin* pass.

No GUI asset changed (the pickers only read canFast/UltraOK from Go), so
the GUI suite was not run.

Run:
- gofmt -l: clean.
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows -tags nogui.
- go test -tags nogui -timeout 90m ./... at 9f9bfc160+this: EXIT=0, 66
  packages ok, none failed (agent 3928s, gateway 2739s, provider 785s).
  The timeout is 90m because the load average was ~150-270, and 45m cut
  agent and gateway short on this box earlier today.
- Rebased then onto bf931f82c (4 commits, gateway/gui among them): vet
  of gateway, provider, agent and gui (darwin), gateway and provider
  (linux, windows nogui), and every gateway/provider test matching Fast,
  PluginServiceTier, PluginModelServiceTiers or CursorPlugin, green there.
2026-10-17 18:38:09 +08:00
bf931f82c3 gateway: a Codex conversation compacted natively is held to its account only when native compaction is on, and told why when it can't go there (#2642, #2582)
ScarfQian (#2642, still on v0.1.1279): after a native compaction by one
Codex account, routing to another answered 400 "only that key or account
can read the compaction it sealed ... switched off, removed, or no longer
serves". Three causes, one fix each:

- #2582 (Dony2050, ump45nose's patch): one of Codex's own models asked on
  the backend path through magpie's accounts (codexAccounts) kept the
  compaction_trigger whatever the codex provider's native compaction
  setting, so every compaction was sealed by and recorded to one account.
  It is now decided as a magpie model's is: codexInputAs with
  nativeCompactionFor("codex/<model>"); off (the default) gives
  codexCompact's magpie1: summary, which any account reads, and records
  no writer. Unlike ump45nose's branch, /responses/compact and Codex's
  own single sign-in relay are left as they were: the legacy endpoint's
  body has no trigger for codexCompact to answer, and a lone sign-in has
  no other account to move to.
- ggbdpq's fix (0ab41eba0, e1646488d, ported as is): a writer whose own
  model list has since dropped the model sat in planned.left, out of the
  candidates, so checkpointReaders never found it and refused although it
  was on. It is now taken back from planned.unlisted (plan, planLevel and
  the nested weighted plan), its row moved from left to order.
  sealedReaders, run before it for a sealed subagent task, narrows
  unlisted too (sibling).
- A request carrying a recorded seal while only Codex's own sign-in is on
  was relayed as it came (codexAccounts false), so with the writer
  switched off the one account left was sent it. codexSealedFor routes
  it through serve, where checkpointReaders holds it to the writer.
- checkpointError now says the reason magpie's settings give
  (checkpointGone: provider removed, account signed out, sign-in lapsed,
  paused while others are on, switched off, kept from the model in Names &
  levels, key off or gone, model disabled, or the model/group asked for
  not routing to it), the fix for that reason, and whether native
  compaction is on for the writer's provider now. The old catch-all
  sentence is gone.

The seal is still treated as readable only by the account that wrote it,
as #1099 and #2271 found; chestnutLeeeee's report that another account read
one in a direct canary was not tried here (no real accounts).

Tests (fake ChatGPT backend, sandbox HOME, nothing on the network):
TestCodexOwnModelCompactionHonoursTheToggle (off: summary, no trigger
upstream, no writer; on: native seal kept, writer recorded),
TestNativeCompactionWriterGoneSaysWhy (spare switched off, own paused,
Names & levels, signed out), ggbdpq's
TestNativeCompactionWriterWhoseListLacksTheModel and
...ThroughAGroupWhoseListLacksTheModel. All four are red on 7660399a1.
Broken by hand on this change, each went red: codexInputAs back to
(false,false) -> Toggle; codexSealedFor not called -> spare switched off;
the unlisted loop emptied -> both WhoseList tests; the Paused case
skipped -> own paused.

TestProtectionRefusalAskedOnceNobodyRests (vs's 502 "response protection
is unavailable" on a bare gpt-5.5 compaction through three accounts) was
about the native path, which that model now takes only with native
compaction on; it turns it on (nativeOn). Off, the compaction is magpie's
summary, as TestProtectionRefusedCompactionAsText already covers.

Run at this change on 7660399a1: gofmt -l clean; go vet ./... (darwin),
GOOS=linux and GOOS=windows go vet -tags nogui ./... ok;
full go test -tags nogui -timeout 45m ./... (load average ~140): every
package ok except internal/agent and internal/gateway, which ran past 45m
(#2544, #2108), and TestProtectionRefusalAskedOnceNobodyRests, mine,
fixed above. Then each alone: internal/gateway -timeout 45m finished in
2345s with one red, TestTranslatedStreamKeepsClientAlive/responses_to_chat
(a keepalive timing test under load, passes alone; filed as #2711, sibling
of #2169); internal/agent -timeout 100m ok in 2115s. The protection,
compaction and Codex tests (-run 'TestProtection|Compact|Compaction|TestCodex')
ok after the test change.
No GUI file changed. Not tried against the real ChatGPT backend.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
2026-10-17 18:19:51 +08:00
yetone 5b12407e8e gateway: a custom tool a Responses upstream turns away is translated, not given back as a 400 (#2656)
DeepSeek's Responses API answers Codex's exec, a custom tool, with 400
"Unsupported custom tool: 'exec'. Only 'apply_patch' is supported."
The relay (attempt -> passthrough) sent the tools as they came, so the
translation that offers a custom tool as a function and gives its call
back as a custom_tool_call never ran, and the 400 matched no word list,
so a group's next member wasn't asked either.

- passthrough: a 400/422 matching customToolRefusal, on a Responses
  body that offers a custom tool (tools, a namespace's, an input item's
  tools), marks the model (customToolRefused) and returns not done.
- attempt: then, and on a marked model's later requests with a custom
  tool, the request is translated on the client's own API (ownAPI), so
  exec keeps its name and comes back as custom_tool_call. A Codex
  compaction (keepsCompaction) isn't translated and gets the refusal.
- shapeRefused also takes customToolRefusal, so where the refusal does
  reach a group, the next member is asked and nobody rests.

Not scoped to DeepSeek: any Responses relay (key, plugin) that says its
custom tools are unsupported is handled the same; an upstream that never
refused them still gets them as sent (tested).

Tests: custom_tool_test.go, fixture from the reporter's literal error
text and request. TestCustomToolTranslatedWhereRefused (stream and
not), TestCustomToolRefusalInGroup (reporter's ordered group, next
member asked 0 times), TestCustomToolRefusalWordings. Broken by hand:
passthrough branch off -> both request tests 400 with the reporter's
exact message; attempt pre-skip off -> next turn asked 4 times, not 3;
shapeRefused addition off -> Wordings red.

Run:
- gofmt -l clean; go vet ./... (darwin), GOOS=linux and GOOS=windows
  go vet -tags nogui ./... clean, at the pushed head.
- Full go test -tags nogui -timeout 45m ./... on e085d6e92 + this
  change: every package ok except internal/agent, timed out at 2706s
  (TestPortMovesEveryAgent running 30s at the deadline; load ~100-150;
  same as #2544, commented there). internal/agent alone -timeout 60m:
  ok 3031s.
- After rebasing onto cb05dc2d1 (3 commits, none in this path):
  internal/gateway -timeout 60m run twice. First: FAIL at 2559s; I
  piped it through tail and lost which test, so it is not named or
  filed here. Second, full log kept: ok 2509s (load ~150).
- Rebased again onto 9f9bfc160 (3 more commits: agent, provider's
  Codex window; none in this path): TestCustomTool*, TestCodexCustom*,
  TestToolStrict*, *Shape* ok; gofmt and vet (darwin, linux, windows)
  clean. Then onto 85eef5d87 (GUI quota refresh only): build and
  TestCustomTool* ok. The full suite was not rerun at this head.
- Not tried against the real DeepSeek API; the fake upstream refuses as
  the reporter's logs show.
2026-10-17 17:44:23 +08:00
yetoneandchiperman 85eef5d87a gui: quota refreshes stay centered and finish each turn without jumping (#2397)
chiperman's patch (df288db, #2397), landed here since external PRs are
collaborators only. The card redraw replaced its refresh button on a
background reading and again when the click finished, restarting its
rotation and hover reveal and moving the Updated text; a fast reply also
stopped the spin partway through a turn. Each account's control and its
animation are kept through redraws, the reply is shown at once and the
current 800ms turn finishes (at least one), Reduce Motion skips it, and the
glyph sits on the text baseline in an inline grid instead of a pixel offset.

Changed in landing: main had since given the tray panel's Allowances the
same quotaRefresh (#panelQuota, #840). A kept button is reused only when its
redraw took it out of the page, so a refresh started on the Usage page is
never moved out of the panel (or back); the other place's copy of a turning
control gets busy+spun and turns by itself until done() clears it. The
panel's hover rule (.pq-card:hover) reveals it as the Usage card's does.
quota-refresh-order's vm harness gets a document stub for that.

app.js's budget goes from 1,250,000 to 1,269,000: with four comments
shortened it is 1,250,904 here, the core's own code since the tray panel
draws the same control, plus 1.5% as the budget's comment asks. Every core
script together is still under coreScriptBudget, which is unchanged.

Run, sandbox HOME, pinned GOMODCACHE/GOCACHE, load ~110-360 from other
sessions' suites:
- Full suite on 81313b912 + this change: set -o pipefail; go test
  -timeout 45m ./...: 64 packages ok; gateway and gui red
  in 3 tests:
  - TestCoreScriptBudget (app.js 47 bytes over; this change, fixed above)
  - TestPluginModelServiceTiersListed: ENOSPC, disk full; -count=3 ok
  - TestMainWindowCorners: killed at its deadline, red alone on main too
    (#1936)
- At this head:
  - go test ./internal/gui/: only TestMainWindowCorners red (#1936)
  - TestCoreScriptBudget: ok
  - gofmt -l: clean
  - go vet -tags nogui for darwin, linux and windows: ok (./... on
    81313b912 + this change; ./internal/gui/... at the rebase)
  - node --check app.js: clean
- GUI, Chromium and WebKit, at e085d6e92 + this change: usage-card-refresh,
  quota-refresh-order, panel-quota-refresh, gui-zh-tw, gui-ja, gui-de:
  84 pass, 0 fail. At this head usage-card-refresh, quota-refresh-order
  and panel-quota-refresh: 75 pass, 0 fail.
- Broken by hand: the new tests against the old app.js/app.css fail 26 of
  46 in usage-card-refresh ("a background reading replaced the spinning
  control", "the refresh icon and the first text line must share a
  vertical center": 253.875 vs 252.375).
- Whole GUI suite (789 files) on 81313b912 + this change, per file, 3 at a
  time. Every red file was rerun alone and checked against plain main
  where it stayed red. None is from this change:
  - Red on main as well, already filed: codex-predictions (#2624),
    lightweight (#2638), segs-glide (#2683), sidebar (#2684),
    login-import, routing-keys-fold, routing-bodies (#2658),
    usage-agents-hide (#2276), quota-count-wrap, quota-name-translated
    (#2228, #2399), routing-model-rest (#2115), rest-try-now (#2564),
    routing-request-metrics (#2571), s3-sync (#2448), usage-checkin
    (#2549), usage-refresh (#2184), quota-curve (load).
  - Load reds filed now, red on main too: tray-cell-click (#2686),
    usage-ledger-abort (#2700), sessions-paging (#2703).
  - The rest were launch or goto timeouts in the parallel run and pass
    alone (about 30 files, among them provider-max-output and
    plugin-agent).

Co-authored-by: chiperman <chipermanju@gmail.com>
2026-10-17 17:26:58 +08:00
yetoneandggbdpq 252bc61ce9 agent: a caller key of the gateway's own in Claude Code's and Codex's config survives a model pick (#2545)
What changed:
- writeTiers (claude.go) wrote env.ANTHROPIC_AUTH_TOKEN = wiredKey() on
  every model and tier pick, and putProvider beside the thread-provider
  tables (codex.go) wrote experimental_bearer_token = at.gwKey() the same
  way: a caller key of the gateway's own the user put in their place was
  written over, and it was never stashed, so no Disconnect brought it
  back. Both keep such a token now, as a sync keeps one (mergeKept,
  keyHolds of #2510): only a value the gateway would refuse is wired
  over. The sign-in field's own Set is unchanged, as that switch is the
  user's own.
- The sharing key magpie itself made is never one of those: access.Default
  says a secret is the default key ConfigureLAN keeps, sharing on or off,
  and the two write points ask it before keeping what they hold. With
  sharing off the key stays enabled in the store, Authenticate still took
  it, and keyHolds held it for the user's — Rekey could no longer bring
  gateway.Token back (TestRekeyGivesWSLAgentTheSharingKey, deterministic
  red on the first cut of this patch, found in review). Claude has no WSL
  twin: the sharing key reaches it by an address beyond loopback
  (MAGPIE_ADDR), and a pick kept it the same way there, so
  TestClaudeSharingOffWiresGatewayTokenBack holds a sharing on, then off,
  to gateway.Token.
- docs/subsystems/agent-wiring.md's sentence about a hand-set key said
  Check reports it; Check has taken one since #2510, and a pick keeps it
  now too, the sharing key excepted.

Patch by ggbdpq (c809f7ad), the second cut after review: the first
(835d3bf8) turned TestRekeyGivesWSLAgentTheSharingKey red, as the
sharing key stays enabled with sharing off and was kept as the user's.
Applied unchanged on e085d6e92.

Run (landing worktree, sandbox HOME, private GOCACHE):
- Broken by hand: access.Default returning false: FAIL
  TestRekeyGivesWSLAgentTheSharingKey (wsl_rekey_test.go:88, "sharing
  off: key sk-magpie-key-…") and TestClaudeSharingOffWiresGatewayTokenBack
  (claude_test.go:291). claude.go and codex.go put back to main's: FAIL
  TestClaudePickKeepsAGatewayKeyOfTheUsers and
  TestCodexPickKeepsAGatewayKeyOfTheUsers ("a model pick wrote over the
  user's caller key"). Restored: all four and TestRekey* ok.
- gofmt -l: clean. go vet darwin (gui), GOOS=linux and GOOS=windows
  -tags nogui: clean.
- Full suite, go test -tags nogui -timeout 45m ./... under pipefail at
  7380d99e4 (this on e085d6e92), load ~180: every package ok except
  internal/agent, which ran past 45m as a whole (2704s, the test at the
  deadline 5s in; #2544, this run posted there). Alone at -timeout 45m
  it ran out again (2702s, load ~210). Alone with -v -timeout 100m: ok,
  854 tests passed in 3017s, the five above among them.
- Rebased on cb05dc2d1 (#2576, #2578, #2657: no internal/agent or
  internal/access file): build and vet of both packages ok.
Not tried: a real WSL distro, or the real app's sharing toggles.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 16:12:14 +08:00
yetoneandcaozeal cb05dc2d1b sessions: CodeBuddy Code's own sessions are listed on the Sessions page, resumed with codebuddy --resume and deletable (#2657, caozeal)
CodeBuddy Code keeps its sessions as WorkBuddy does, ~/.codebuddy/projects/<cwd>/<id>.jsonl. magpie read them for the calls ledger (#1779) but never listed them: allFiles() and Dirs() left them out, parserFor sent them to the Claude parser, and Deletable didn't name the agent. caozeal's branch (85cc186a2) adds them to allFiles, Dirs, parserFor (workbuddyLine) and Deletable, with the meta cwd fallback WorkBuddy has, and the ledger reads through the same list. On top of it: the resume command is `codebuddy --resume <id>` (its CLI's `-r, --resume [sessionId]`, read from @tencent-ai/codebuddy-code 2.168.2's dist/codebuddy.js; codebuddy is one of the package's three bins). The Sessions page's and Usage > Sessions' agent label come from the agent registry (CodeBuddy Code, codebuddy-color) and needed no change; a test now holds them.

Fixtures are the real `codebuddy -p` runs already in internal/sessions/testdata/codebuddy (#1779).

Tests:
- TestCodeBuddy (caozeal's, extended): two sessions with their cwd, title and model tokens; the resume command on each OS's form; Deletable.
- TestCodeBuddySessionsListedUnderTheirName (new, internal/gui): /api/sessions, /api/sessions/manage and /api/sessions/stats name them CodeBuddy Code with its icon, resume command and trash.
- Broken by hand, each red: allFiles reverted and parserFor reverted ("want 2 CodeBuddy Code sessions, got 0" in both tests), resume reverted (resume ""), Deletable reverted ("not deletable", "offers no trash").

Run at e085d6e92 plus this change:
- gofmt -l internal/: clean. go vet ./... (darwin): exit 0. GOOS=linux and GOOS=windows go vet -tags nogui ./...: exit 0.
- go test -tags nogui -timeout 45m ./... under set -o pipefail: 64 packages ok, 2 red at load average ~110, neither ours:
  - internal/agent timed out at 45m (TestWSLMoreAgentsPick running; 2702.7s), recorded on #2544.
  - internal/gui TestRestartWhenIdle "restarted in a tool chain's gap" (30ms sleep vs 80ms idleSettle); passes -count=10 alone; filed #2673.
- After rebasing onto origin/main 7660399a1 (#2576, #2578: gateway model list, gui Claude Desktop chip): internal/sessions ok (169.6s) and internal/gui ok (303.7s) at the rebased head on 7660399a1.

Co-authored-by: caozeal <21231607+caozeal@users.noreply.github.com>
2026-10-17 14:05:17 +08:00
yetoneandggbdpq 7660399a12 gui: a provider's Claude model chip says the number Claude Desktop's menu shows beside it (#2578)
jerrychoi (#2578) has two providers serving the same Claude models, and
Claude Desktop's menu tells them apart only by a 10-digit number. The
provider editor now shows that number on the model's chip.

From ggbdpq's patch (dcb00beb5), changed after reading desktop.go and
Desktop 2.7032's app.asar:
- Desktop renames a row to its own catalog's name ("Opus 5.5") only
  when the id resolves into that catalog, which is the
  magpie-<n>.anthropic.<model> form claudeLooking gives a Claude model
  with reasoning levels. Every other row is named by our display_name
  (which already says the provider) or by its own id, and its number
  never shows in the menu. The patch put a number on nearly every chip;
  DesktopNumber now returns one only for the .anthropic. form ("" for
  mythos-magpie-<n>, anthropic/magpie-<n>, own ids and groups).
- The number shows only while Claude Desktop is installed, and only for
  a model Desktop is shown (CatalogFor("claude-desktop"), not the whole
  catalog, so a model hidden from Desktop gets none).
- The numbers are worked out once per Providers page build, not once
  per provider.
- The GUI test runs en and zh at 900px and en at 420px in both engines
  and checks the badge sits inside its chip.
- docs/subsystems/agent-wiring.md says why the number is there.

The badge reuses the muted .badge.ctx pill beside the context size. Its
tooltip is in zh, zh-TW, ja and de (ggbdpq's strings).

Broken by hand, each watched red then restored:
- ggbdpq's DesktopNumber: TestDesktopNumber red for glm (mythos), glm
  (anthropic/magpie) and a group led by Claude; the GUI Go test red for
  m2.
- the installed check removed: red "without Claude Desktop,
  claude-opus-5-5 says desktop ...".
- provider.Catalog() in place of CatalogFor: red for the hidden haiku.
- j.Desktop dropped: red for claude-opus-5-5.
- app.js without the badge: model-desktop-number.test.cjs 0 passed.

Run (macOS arm64, sandbox HOME, pinned GOMODCACHE/GOCACHE):
- model-desktop-number.test.cjs 6/6 in chromium and webkit (en, zh at
  900px, en at 420px); screenshots checked: zh at 900px shows "Opus 5.5
  [number]" as a muted pill, Sonnet none.
- Go, this tree, as 1160f2e7d before the bodies were reworded (with the
  #2576 commit, on origin/main ebf3f48f7):
  gofmt -l clean; GOOS=darwin, linux and windows go vet -tags nogui
  ./... clean; go test -tags nogui -timeout 45m ./... under pipefail,
  exit 0, 66 packages ok. The same was green at 18828ea1a (on
  6f950653f) and d6881341d (on ed0335f75).
- rebased onto e085d6e92 (six commits, gateway.go and i18n.js among
  them, no conflict) after that run: gofmt and vet of internal/gateway and
  internal/gui clean, and their Models, Desktop, Science and
  ProviderModelsSayDesktopNumber tests ok; the full suite was not rerun
  there.
- GUI, both engines, on this tree: every file that reaches the model
  chips or failed in a whole-suite try, 54 files (349 tests per engine).
  Reds: Codex predictions at 420px (#2624, red on main alone);
  provider-advanced-fold's "Advanced grows open" (#2552, a sampling
  flake under load); and browser launches past 180s. Each of the others
  passed when its file was rerun alone (codex-accounts-via 4/4 in
  webkit; provider-draft-picks and provider-fetch-again in chromium).
- Not done: a whole GUI suite to the end in both engines. Two tries at
  load ~300 (14 cores) failed mostly on browser launches timing out at
  180s, and in one of them another session checked out origin/main in
  the worktree mid-run, so those results were set aside.
Not tried: a real Claude Desktop with two providers of one model, and
the [1m] rows.

Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>
2026-10-17 13:11:43 +08:00
yetoneandggbdpq b566745b8a gateway: the model list says each model's reasoning levels as plain names too, for Catwalk clients (#2576)
Clients of the Catwalk schema (Crush and kin) read reasoning_levels, a
flat array of names, to know which reasoning efforts a model takes, and
drop reasoning_effort from requests to a model that names none. magpie's
/v1/models said the levels only as objects (supported_reasoning_levels,
[{"effort":"low"},...]), which such a client reads as none (cyancity).
modelObject now also says reasoning_levels: the same e.Efforts in the same
order, [] when there are none, never null. The objects stay as they were.

Every row built by modelObject carries it: the provider/model rows,
routing groups, bare ids, /v1/models/{id}, deciders, and Claude Desktop's
and Claude Science's lists. Muse's list has its own shape and the
image/video rows say no levels, so neither changes. No gateway default
for thinking, no thinking/enable_thinking aliases and no
default_reasoning_effort, as decided on the issue. Docs: reference.md,
integrating.md and the site's integrate page (en, zh) name the field.

ggbdpq's patch (base a69cd070); the review folded its test into
TestModelsListReasoning, which now checks reasoning_levels on every row it
already checks (groups included, and [] on a/plain and b/mixed) and on
GET /v1/models/b/sol.

Run (macOS arm64, sandbox HOME, pinned GOMODCACHE/GOCACHE):
- broken by hand two ways: the key renamed, TestModelsListReasoning red
  ("b/sol: reasoning_levels <nil>; want [medium,high]", and the single
  model); slices.Clone(e.Efforts) (null when empty), red ("a/plain:
  reasoning_levels <nil>; want []"). Green restored.
- this tree, as 1160f2e7d before the bodies were reworded (with the
  #2578 commit, on origin/main ebf3f48f7):
  gofmt -l clean; GOOS=darwin, linux and windows go vet -tags nogui
  ./... clean; go test -tags nogui -timeout 45m ./... under pipefail,
  exit 0, 66 packages ok. The same was green at 18828ea1a (on
  6f950653f) and d6881341d (on ed0335f75).
- rebased onto e085d6e92 (six commits, gateway.go and i18n.js among
  them, no conflict) after that run: gofmt and vet of internal/gateway and
  internal/gui clean, and their Models, Desktop, Science and
  ProviderModelsSayDesktopNumber tests ok; the full suite was not rerun
  there.
Not tried: a real Crush or Catwalk client.

Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>
2026-10-17 13:11:41 +08:00
yetone e085d6e926 cli, gateway: magpie heap writes the running magpie's Go heap profile, with its memory numbers
A user on X (FatimaHill74421) reports the macOS app at 3.95 GB physical
footprint after ~12h (v0.1.1273, after 8a1b5916f's #2278 fix), and a macOS
`sample` shows Go's frames as ???. `magpie heap [<file>]` asks the magpie
that serves the gateway for GET /v1/magpie/heap: runtime/pprof's heap
profile after a GC (gzipped protobuf, go tool pprof reads it), with
HeapAlloc, live heap, HeapInuse, HeapSys, StackSys, Sys, NumGC and the
goroutine count in X-Magpie-Heap-Stats. It writes <file>, else
magpie-heap-<date>-<time>.pb.gz here (0600, never over a file), and prints
the path, the pid and the numbers. --help writes nothing; an unknown flag,
"-" or a second file is refused before anything is asked.

The route answers only a loopback, unproxied caller with no browser marks
calling localhost or a loopback IP. heapRefused checks this in the handler
itself, so a gateway key never lets in another machine, a listed page,
Origin null, a localhost page or a rebound Host, and it holds where Handler
is served without lanGuard.

Run at dccfefdf7: gofmt -l (nothing); go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./... (clean); go build for darwin,
linux (nogui) and windows; go test -tags nogui -timeout 45m ./... under a
sandbox HOME: every package ok (gateway 1218s, cli 613s). Broken by hand:
heapRefused returning "" turns TestHeapProfileOnlyToThisComputer red
(19 failures).

Real use: the built binary's `magpie serve` under a sandbox HOME on
127.0.0.1:3481; `magpie heap` saved a 10 KB profile (0600) and printed the
numbers, go tool pprof -top read it, --help wrote nothing, and a curl with
Origin: null got 403. Not tried: the GUI app's own process, or the
Windows box.
2026-10-17 12:04:53 +08:00
yetoneandggbdpq df341e7671 gateway: a member that answers a stream request with a whole reply is asked once, not again and again (#2455)
An upstream that answers stream:true with a whole JSON reply (a relay
that doesn't speak SSE) fails as a 502 "did not stream". magpie read
that 502 as a failure a moment may mend: the same-one retries (passing)
asked it twice more, then a group's patience (busy, #1418) kept asking
it until the budget was spent. The failure is the same however often it
is asked. With production pauses that is about 7 requests and 60s at the
default Patience, about 14 at 240s; the test's 1ms pauses let the 12
replan rounds run out first, 15 requests (ggbdpq's correction on the
issue).

busy() and passing() now leave a body that says didNotStream alone, and
the four places that word the error (translate, streamTranslated,
askTranslated, holdWriter.settle) share that constant. A group still
moves on to the next member, whose API may stream; retryable() is
unchanged.

Patch by ggbdpq (f9e09ca7), applied on main with the docs sentence
placed by hand (the hunk no longer applied).

Run:
- TestStreamlessMemberIsAskedOnce with both exclusions taken out: FAIL,
  whole and stream ("asked 15 times"); with only busy()'s: FAIL ("asked
  13 times"); with only passing()'s: FAIL ("asked 3 times"). Restored:
  ok (asked once, the agent gets the 502 naming "did not stream").
- TestStreamlessMemberHandsOnToTheNextMember (b, which streams, answers
  after a): ok.
- TestQuietNotAReplyLastFails, TestPatience*, TestStreamOverflow*,
  TestCodexOverflowInGroupNotAskedAgain, TestAgentGoneInTheRetryPause,
  TestRelayInputCap, TestOverflowGoesToAMemberWithRoom: ok.
- Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail,
  sandbox HOME, load ~350) at 0224e826f (these four commits on
  ebf3f48f7) plus #2545's patch: every package ok except internal/agent,
  whose one red (TestRekeyGivesWSLAgentTheSharingKey) is #2545's, which
  was dropped (problems posted on #2545). internal/agent alone at
  0224e826f: ok. Rebased on dccfefdf7 (#2635, internal/library only):
  build, vet, internal/library ok. gofmt -l clean; go vet darwin (gui),
  GOOS=linux and GOOS=windows -tags nogui: clean. GUI (i18n-keys,
  gui-de/ja/zh-TW, import-*, key-import, login-import): all pass except
  login-import's Chromium case, which fails the same alone on origin/main
  ebf3f48f7 (#1307, output posted there).
Not changed: a same-protocol passthrough whose vendor answers 200 with
a whole reply is still relayed as it came (named on the issue). Not
tried against a real relay that doesn't stream.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 11:54:56 +08:00
yetoneandump45nose ae98cda651 gateway: an inner group's own Patience waits out its busy members through an outer group (#2410)
serve read Patience only from the group the request named (g.Waits()).
planLevel stamped a nested group's FirstToken (#2246) on its candidates
but not its Patience, so an inner group's budget was never read through
an outer one: an inner 4 min under an outer default gave up at 1 min,
and an inner Off was still asked again for 60s.

Each candidate carries the innermost Patience that is set on its way
down (innerPatience, as innerFirstToken). waitsOf reads it as Group.Waits
does, falling back to the asked group's when unset; PatienceOff keeps the
member out of replan. replan counts each member's budget from waitFrom
and asks again only those with budget left past the pause; the hold on
the last failure lasts while any member's may (maxWaits), and the
trace's Patience is the member's own. With no nested Patience set,
every member's budget is g.Waits(), as before.

Patch by ump45nose (61b1c17c); ggbdpq checked it against main on the
issue. Review changes: the docs sentence was placed by hand (the docs
hunk no longer applied), and the tests' budgets moved from inner 8s /
outer 3s to 10s / 4s, so every round's pause ends 2s or more from a
budget line (it was 1s from the 3s line), as a timing test leaves room
on both sides.

Run:
- With fallback.go, gateway.go, patience.go and patience_test.go put
  back to main: TestNestedGroupPatienceThroughOuter FAIL ("a.n=2, want
  3 — the inner group's 10s budget was not read"),
  TestNestedGroupPatienceInnerOff FAIL ("code=529 a.n=13 (want 529, 1 —
  no replan)"). With replan reading only the fallback budget:
  ThroughOuter FAIL the same. Restored: ok.
- TestNestedGroupPatienceFallsBackToOuter, TestGroupWaitsOut*,
  TestPatienceIsUsedUp: ok.
- Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail,
  sandbox HOME, load ~350) at 0224e826f (these four commits on
  ebf3f48f7) plus #2545's patch: every package ok except internal/agent,
  whose one red (TestRekeyGivesWSLAgentTheSharingKey) is #2545's, which
  was dropped (problems posted on #2545). internal/agent alone at
  0224e826f: ok. Rebased on dccfefdf7 (#2635, internal/library only):
  build, vet, internal/library ok. gofmt -l clean; go vet darwin (gui),
  GOOS=linux and GOOS=windows -tags nogui: clean. GUI (i18n-keys,
  gui-de/ja/zh-TW, import-*, key-import, login-import): all pass except
  login-import's Chromium case, which fails the same alone on origin/main
  ebf3f48f7 (#1307, output posted there).

Co-authored-by: ump45nose <ump45nose@users.noreply.github.com>
2026-10-17 11:54:56 +08:00
yetoneandggbdpq 08400f4ebd gateway: a byte cap after the stream has begun says request_too_large, so Pi compacts (#2533)
A vendor's 413 that came after the stream's headers had gone out (a
keepalive sent while the vendor was quiet) reached Pi as a stream error
of type api_error saying "413 Request Entity Too Large". Pi compacts only
when the error's text says request_too_large (overflow.ts), so the turn
stopped. A 413 before the headers was already typed request_too_large
(writeErrorSaid, 97f264c7).

streamError, which every failure in a stream already begun goes through
(failTo and holdWriter's), appends "(request_too_large)" to the text of a
413 that isn't a context overflow and doesn't say it already; the Chat
and Anthropic encoders type that event request_too_large. Gemini keeps
its own status shape; an overflow stays context_length_exceeded.

Review change (on top of ggbdpq's 8a278645): the test matched
request_too_large anywhere in the body, so Chat's new type alone passed
it: with the text append taken out by hand it stayed green. It now reads
the error event's message (what Pi reads) and type. The new
TestStreamErrorByteCapInEveryShape runs streamError for Chat, Anthropic,
Responses and Gemini, and for a 413 that says the prompt is too long.

Run:
- With gateway.go, chat.go and anthropic.go put back: both tests FAIL.
  With only the text append taken out: both FAIL. With only Anthropic's
  type taken out: TestStreamErrorByteCapInEveryShape FAILs ("anthropic …
  want "type":"request_too_large""). Restored: ok.
- TestBodyRejectionErrorShapes, TestStreamErrorSaysItPasses,
  TestGroupLastFailureInStreamSaysItPasses: ok.
- Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail,
  sandbox HOME, load ~350) at 0224e826f (these four commits on
  ebf3f48f7) plus #2545's patch: every package ok except internal/agent,
  whose one red (TestRekeyGivesWSLAgentTheSharingKey) is #2545's, which
  was dropped (problems posted on #2545). internal/agent alone at
  0224e826f: ok. Rebased on dccfefdf7 (#2635, internal/library only):
  build, vet, internal/library ok. gofmt -l clean; go vet darwin (gui),
  GOOS=linux and GOOS=windows -tags nogui: clean. GUI (i18n-keys,
  gui-de/ja/zh-TW, import-*, key-import, login-import): all pass except
  login-import's Chromium case, which fails the same alone on origin/main
  ebf3f48f7 (#1307, output posted there).
Not tried: a real nginx 413 or a real Pi compacting after it.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 11:54:55 +08:00
yetone ebf3f48f7f usage: a reported call takes first_text_ms and flow_ms, so a reasoning reply tells its speed and a burst is held (#2637)
POST /v1/magpie/usage/requests turned away first_text_ms and flow_ms as
"not a field a reported record takes", so a reported reasoning reply was
timed from its first reasoning token and a burst-at-the-end reply was
never held. The ingest now takes both, validated like ttft_ms (whole
milliseconds, 0..ingestMaxMillis, null = unset), and checks:
- first_text_ms <= ms, and first_text_ms >= ttft_ms when both are set
  (the first text is content too);
- flow_ms <= ms*10/8+1, since the gateway's flow is the tenth-to-nine-
  tenths span scaled by 10/8 and can exceed ms.
The fields reach usage.jsonl through the Record, so DecodeOf, Row.Decode
(ThinkPace, HeldShare) and the Reported totals read them as they do the
gateway's own rows. docs/reference.md and gateway-sessions.md say so.

Tests: TestUsageIngestTellsSpeed posts the reporter's literal repro
(grok-4.7, out 307, reasoning 129, ms 5035, ttft 4632, first_text 4700:
178 tokens over 335ms), a burst held by flow_ms, an even reply told, and
a ThinkPace hold, and checks the totals. TestUsageIngestTimesChecked
covers each bound, its edge, null and absent fields.

Broken by hand: old code fails both tests (field refused); dropping
FirstText tells repro-1 0; dropping Flow tells the burst 601/4035;
removing the ttft check accepts first_text 299 < ttft 300; bounding flow
by ms rejects the valid 1501.

Run at 8bb9375e7 + this diff: gofmt -l clean; go vet ./... on darwin,
GOOS=linux and GOOS=windows -tags nogui clean; set -o pipefail; go test
-timeout 45m ./... exit 0 (66 ok, gateway 1192s) under a sandbox HOME and
private GOCACHE (an earlier run against the shared cache had build
errors from cache files removed mid-run, not code). Machine load ~250.
Not tried with a real reporting client.
2026-10-17 10:14:03 +08:00
yetone 333c167575 routing: a rule can set the reasoning its model is asked for (#2633)
dengtongcai asked for a routing rule that picks both the model and the
reasoning it is asked for (a quick question goes to a cheap model at low).
A rule now has an output field, useEffort (low|medium|high|xhigh|max). When
the rule matches, its member is asked for that effort. A member's own fixed
effort still wins. Otherwise the rule beats the model's suffix, the turn's
pick and the agent's pick. The existing effort condition is unchanged.

- The value is fitted to the model's levels (max -> high on a model that
  tops out at high). A model with no Efforts is sent what the agent asked,
  untouched. Unset changes nothing. Failover members are not affected.
- The trace records it: Rule.UseEffort and the try's RuleEffort (the second
  Try construction in the candidate loop was missing it).
- Saving a group rejects an unknown value or one on a pause (cleanRules).
  The CLI takes use-effort=; the TUI and CLI lists show " at <effort>".
- GUI: a chip after the rule's model, picked from the app menu (pickFrom,
  no native select), set/changed from the rule's menu. A pause clears it.
  Strings in zh, zh-TW, ja, de.
- A Gemini-protocol client is left unchanged, as with every effort magpie
  sets.
- Docs: docs/subsystems/gateway-routing.md; site docs intent and start (en,
  zh, ja).

What was run, at d4c03a2c5 (rebased on d4a1b9baa) unless said:
- gofmt -l: none. go vet ./... (darwin), GOOS=linux and GOOS=windows
  go vet -tags nogui ./...: clean.
- go test -count=1 ./internal/gateway ./internal/provider ./internal/cli
  ./internal/tui: ok.
- The full go test -timeout 45m ./... under pipefail, before the rebase at
  6f950653f: every package ok except internal/gui. There, 8 real-window
  darwin tests were killed at their deadlines with the load average at
  150-300. Four passed on a rerun. TestMainWindowCorners,
  TestMainWindowRightToLeft, TestTrayCellClickReleasedPanel and
  TestCoveredWindowStaysUp fail the same way on a clean 6f950653f checkout
  (added to #1936). This change has no Go in internal/gui.
- Broken by hand: ruleEffort returning "" turns the four gateway tests red
  (Chat member, intent rule, failover member, Anthropic member). Returning
  the raw value for a model with no levels turns the unset/no-levels test
  red. Dropping the cleanRules checks turns TestCleanRulesUseEffort red.
  routing-rule-effort.test.cjs against the 6f950653f routing client.js and
  i18n.js is red.
- GUI: routing-rule-effort.test.cjs passes 18/18 in chromium and webkit
  (en, zh, zh-TW, ja, de; 1100 and 420 wide). The 140 GUI files that open
  the Routing view ran 560 tests before the run stopped with no summary.
  Two of the 560 were red: group-from-model-add (#2388) and
  name-suffix-where-named (filed #2640, a skeleton-row race). Both pass
  alone. The whole 791-file suite was not finished. At a load near 280 it
  covered about 20 files in 40 minutes. The reds it showed were in
  account-* files, and account-models passes 12/12 alone.
- Then rebased onto 8bb9375e7 (#2635, internal/library only) and
  go build ./... at the final head.
2026-10-17 10:04:39 +08:00
yetone df3734b959 proc: the login shell's variables count only when exported, and Codex's proxy detail names the variable it read (#2627)
ReneXiong: Codex showed the "proxied" drift, "through the proxy at
http://127.0.0.1:7890, set in HTTP_PROXY", while Codex went direct. The
value was fish's universal http_proxy from an old Clash setup, never
exported (`set -S` says "unexported"), so no program fish starts has it.
shellEnv asks fish beside the login shell (zsh), and shellProbe printed
"$http_proxy" in the shell itself, which expands unexported variables too;
mergeShellEnv then filled zsh's empty value with fish's.

Fix at the shared reader: every shell is now asked to run
/bin/sh -c 'printf ... "$PATH" "$CODEX_HOME" ...', the form nushell already
used (still with its ^). A child sees only exported variables, so each
value is what an agent started from that shell gets. This covers every
reader of the probe: Codex's proxy (codexEnv), Claude Code's provider
switches (claudeShellEnv), and agentenv.Vars such as CODEX_HOME and
CLAUDE_CONFIG_DIR that magpie takes into its own environment; an
unexported zsh or bash variable no longer counts either, which matches what
an agent run from that terminal sees. Proxy variables are still merged from
fish when the login shell has none: a fish user who exports one runs Codex
with it from fish, so taking proxies from the login shell only (the
report's other suggestion) would miss that case.

codexProxyFor named HTTP_PROXY (or HTTPS_PROXY, ALL_PROXY) for a value in
the lowercase variable. It now names the one it read, in both the reqwest
and respect_system_proxy paths, and the detail's NO_PROXY advice matches a
lowercase name too (and not "the system's proxy settings").

Other proxy readers checked: the daemon's carried env, wslrun's proxyVars,
netproxy and the plugin host read magpie's own environment, not a shell;
the WSL probe scripts ask for no proxy variable.

Tests: TestLoginEnvUnexportedNotCounted, a login shell with the reporter's
literal values unexported beside an exported NO_PROXY; TestShellEnvRealFish
now writes the reporter's literal fish_variables lines and checks that
http_proxy, https_proxy and all_proxy read empty;
TestCodexProxyNamesItsVariable. Broken by hand, each went red: the old
in-shell printf (unexported values read back, in the fake shell and in real
fish 3.7.1), and env() naming keys[0].

Run: go test ./internal/proc and the codex proxy tests on darwin;
TestShellEnvRealFish, TestShellEnvFishLogin and
TestLoginEnvUnexportedNotCounted on real fish 3.7.1 in an alpine container
(linux/arm64), green with the fix and red without it; gofmt -l clean; go vet
-tags nogui ./... for darwin, linux and windows; the full go test -tags
nogui -timeout 45m ./... under pipefail, both fixes together on
origin/main ec6454395: exit 0, 66 packages ok, no FAIL.

Not tried: the reporter's Mac with fish itself, and nushell (not installed
here; TestShellEnvNushell's real-nu part skipped, its probe-shape check
passes).
2026-10-17 05:35:45 +08:00
yetoneandggbdpq ed0335f75c gateway: an assistant turn cut off before it said anything is left out of what a Chat upstream is sent (#2599)
timonwong (#2599): after the user stops a reply while the model is still
thinking, the agent keeps a turn with no text and no calls and sends it
again on every later turn. Translated (buildChat) or relayed, it reached
the Chat upstream as {"role":"assistant","content":""} (reasoning_content
alone, on DeepSeek), and DeepSeek and Kimi turned every request of the
conversation away: "Invalid assistant message: content or tool_calls must
be set".

One rule, withoutSilentAssistants (chat.go), runs on both Chat routes:
buildChat before pairToolMessages (Claude Code, Codex and Gemini clients,
and the plugins fed by buildChat), and silentAssistantsOut in passthrough
next to developerAsSystem (a Chat client's own body). An assistant
message with no content or only blank text parts, and no tool_calls or
function_call, is left out; the user messages it stood between join into
one (texts with a blank line, else their parts in order), so no two user
messages stand in a row. A prefill (prefix, partial, a Resume), a legacy
function_call, a refusal and an audio reply stay. A relayed body without
such a turn goes byte for byte. TestChatThinkingOnlyAssistantKeptOutside-
Exchange pinned the old pass-through; it now expects the joined message.

Built on ggbdpq's patch (cb438ebb on their fork) and its fake upstream,
written again because the review found it missed shapes the issue names:
- after a tool result it kept the empty turn ("a strict template wants the
  reply behind its tool message"), so the interruption mid tool loop still
  sent content "" and still got the 400. tool then user is what any agent
  sends when the user writes after a tool result; it is now left out.
- the relay dropped an assistant with a legacy function_call or a refusal
  and empty content, and a client's own prefix/partial prefill;
  kept blank text-part arrays (still refused); joined only string users;
  re-marshalled with HTML escaping.
- its Resume check compared a joinSplitCalls turn index with
  len(r.Messages)-1.

Verified (sandbox HOME, pinned caches, go1.26.8 darwin/arm64, base
origin/main 72d6103e2):
- The fake upstream refuses with the issue's literal 400 body any
  assistant without content or tool_calls, plus DeepSeek's #1462/#1822
  reasoning rule. On main's product code 18 subtests of the new tests go
  red with that 400 (Claude Code: thinking, redacted, empty text,
  thinking+empty text, [], "", after a tool result; Codex: lone reasoning,
  empty output_text, no content; Gemini thought-only; relay: "", null, no
  content, blank parts, after a tool result; relay keeps-what-speaks), and
  TestChatThinkingOnlyAssistantLeftOutOutsideExchange. With ggbdpq's
  product files instead, after-a-tool-result (both routes), blank parts
  and TestChatRelaySilentAssistantsOnly are red. With this change all
  pass; TestChatResumeEmptyPrefillKept is a guard, green before and after.
- gofmt -l: clean. go vet -tags nogui ./... for darwin, linux, windows:
  ok. Full suite with both this and the #2575 test change in the tree,
  set -o pipefail; go test -tags nogui -timeout 45m ./... : 66 packages
  ok, none failed (internal/gateway 825s, internal/provider 266s).
- Rebased onto origin/main ec6454395 (claude_subscription, ir.go):
  gofmt clean, vet darwin/linux/windows on internal/gateway and
  internal/settings ok; go test -tags nogui -timeout 45m
  ./internal/gateway ./internal/settings: ok (gateway 668s).
- Not tried against real DeepSeek or Kimi (the fake answers with the
  issue's bytes). Gemini and Responses upstreams are not changed; the
  Messages build already drops an empty turn and merges same-role
  neighbours (anthropicBody's push).

Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>
2026-10-17 05:15:16 +08:00
yetone ec64543952 claude: a switch gives a Claude subscription's run the agent's instructions as its system prompt, in place of Claude Code's
Every request through a Claude subscription is answered by the real
Claude Code, which sends its own system prompt, with the agent's
instructions in the run's first user message. Settings › Replies › Short
Claude system prompt (claudeLeanPrompt, off by default) starts the run
with --system-prompt-file holding the agent's instructions instead
(without a client Claude Code's billing line, plus the tool-choice
line), and the first message holds the conversation alone. The file is
under the distro's mount in WSL. A request with client cache marks
(#1717) is never lean. The mode is part of the run's identity, so a run
started in one mode never takes the other's turns. The row says the
risk: requests look less like Claude Code's own.

Measured with a real Claude subscription, Sonnet 5.5, Claude Code
2.1.301, off then on:
- chat client, ~600-token prompt, 2 tools, 3 turns: 10,048 -> 6,580
  input tokens (-35%)
- claude -p as the client, Read and Bash, 4 requests: 85,453/85,471 ->
  81,948/81,977 (-4%)
A fixed ~0.9-1.2K tokens a request.

Run at this head (rebased on 72d6103e2):
- go test -tags nogui -timeout 45m -count=1 ./...: all 66 packages ok
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok
- TestClaudeLeanPrompt*: 4 pass; each guard broken by hand goes red
  (cacheIdentity's lean bytes, the tool-results mode check, the
  client-cache exclusion, the WSL path)
- whole GUI suite (before the rebase, machine load ~300-430): the 23 red
  files were rerun alone here and on origin/main. mobile-web's settings
  screenshot differed from main because of the new row; it now takes
  the row out until BASE_REF has it, as it does for other new parts,
  and passes with claude-lean-prompt-setting (4 languages, 1100/420,
  chromium and webkit). The rest are red on main too or under load and
  already filed: usage-agents-hide (#2276, #2399), routing-bodies
  (#2559), routing-model-rest (#2115), sidebar-overlay-scrollbar
  (#1863); plugin-other-ways passed alone.
2026-10-17 04:39:59 +08:00
yetone 72d6103e28 gateway: a Chat tool in MCP's or another API's shape goes upstream as a Chat function tool (#2622)
jinyue806 (#2622): ZCode sends its tools on /v1/chat/completions in MCP's
shape, {"name","description","inputSchema"}, with no type and no function
object. magpie relayed them as they came, and SenseNova turned every request
with tools away ("field Tools[0].Type invalid, should be set"; a flat
{"type":"function","name":…} got "function cannot be empty"). A missing
type is invalid Chat Completions for every upstream, not SenseNova only, and
the translated routes were broken too: parseChat read no name from such a
tool, so Messages and Responses upstreams were offered a tool named "".

shapeChatTools puts a tool with its name at the top (no type, or type
"function" without a function object) into {"type":"function","function":
{name, description, parameters, strict}}, parameters taken from
parameters, inputSchema or input_schema; other fields stay beside it. It
runs right after liftMessageTools at the same two choke points: handle, for
every Chat body before routing (relay, schema fixers, redaction, plugins),
and parseChat, for a body that never came through handle. A tool that has
its function, a hosted tool (any other type) and one with no name are left
alone, and a request with nothing to shape is relayed byte for byte.

Verified:
- TestChatToolInAnotherShapeIsShaped sends the reporter's curl body with
  each of the four tool shapes from the report through the Chat relay,
  Messages and Responses. With shapeChatTools made a no-op by hand all 12
  subtests FAIL: relayed as {"name":"f","inputSchema":{…}} as it came, and
  translated as {"name":"",…}. TestShapeChatToolsLeavesChatShape (byte for
  byte on Chat-shaped/hosted/nameless tools; strict and cache_control kept)
  FAILs on the same break. Both pass restored.
- gofmt -l: clean. go vet -tags nogui ./... for darwin, linux, windows: ok.
- Full suite at 81313b912 + this change, sandbox HOME, pinned caches:
  set -o pipefail; go test -tags nogui -timeout 45m ./... : 59 packages ok
  (internal/gateway 1134s, internal/provider 548s). 7 packages failed only
  on "no space left on device" while the disk filled mid-run (cli
  TestModelDisableCmd, library TestAgentMCPFiles, sessions
  TestCodexTitleEvidenceBound, settings TestSaveConcurrent, and gui, tui,
  usage which printed PASS but couldn't write testlog.txt). Rerun once
  space was back (30G free): cli, gui, library, sessions, settings, tui,
  usage all ok.
- Rebased onto origin/main a69cd0707 (#2611's chat call ids, chattidy):
  gofmt clean, vet darwin/linux/windows on internal/gateway ok,
  go test -tags nogui -timeout 45m ./internal/gateway ./internal/source:
  ok (gateway 510s). No other package changed between the two bases.
- Not tried against the real SenseNova (no key here); the reporter's own
  table shows {"type":"function","function":{…}} answered 200.

The "inference request is invalid ... reason=unknown retryable=false" text
in the report is not magpie's (no such string in the repo); it is the
client's wrapper of the upstream error, so nothing changed there.
2026-10-17 04:07:25 +08:00