Commit Graph
3557 Commits
Author SHA1 Message Date
yetone e740ee7cc0 agent: a Claude Code tier set to a model keeps it when the main model moves onto that model, not "Same as main model" (#2257, luokinging)
A Fable tier set to GPT-6.1 Sol read "Same as main model" once the main
model was switched to Sol, and the next main-model move took it with it.
On a move of the main model, a tier equal to the new main model was kept
as its own only when it equalled what it would follow there. Fable follows
nothing on a model that is no Fable, and haiku follows a Claude model on
its Haiku, so neither was marked: Get then hid the tier as following, and
the next move rewrote it. The new main model itself now counts as the
tier's own model too, for every tier and both routes (magpie and Claude
Code's /model). GUI, TUI and CLI all read the same Field.

A user already caught by it sees "Same as main model" and sets the tier
again once; that state can't be told from a tier that follows.

TestClaudeFableTierOnClaude modelled 0.1.1229's wiring with fable=Sol
written before the main model moved onto Sol, which is this issue's own
case; its fixture now writes it after, as 0.1.1229 did.

Run:
- TestClaudeOwnTierOnTheNewMainModelStays (every tier, two own models,
  magpie and /model): on the old code fable fails for both models and
  routes, and haiku given Opus fails ("haiku reads \"\""); passes now.
- CLI in a sandbox HOME/CLAUDE_CONFIG_DIR, old and new binary: main ->
  k2.8, fable -> Sol, main -> Sol, main -> GLM. Old: fable gone after the
  move onto Sol, no ANTHROPIC_DEFAULT_FABLE_MODEL after GLM. New: fable
  Sol after both, env ANTHROPIC_DEFAULT_FABLE_MODEL=oa/gpt-6.1-sol.
- go test -tags nogui ./internal/agent/ ./internal/tui/ ./internal/cli/:
  ok. gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
Not tried: the GUI by hand (no asset changed; it reads the same Field).
2026-10-15 06:07:43 +08:00
yetone fbfb76149c provider: TestCopilotSecretToolUsername's fake secret-tool answers a loaded Mac's suite, not "token """ after two 5s waits (#1627)
The cause: the test wrote its fake secret-tool with os.WriteFile, so its
first exec paid macOS's check of a newly written program (0.27s here at
load ~10, several seconds while a go test ./... starts its binaries, as
testenv.Program's own doc records). That ran into copilotSecretWait (5s),
which the happy path was held to: both lookups (account, then username)
were killed and the token read as "".

Not a product bug from this cause: copilotSecretTool runs only on Linux,
against the user's installed secret-tool, which has no such check. The 5s
bound is for a keyring prompt nobody answers (#723) and stays.

The fix, in the test only:
- both fakes are testenv.Programs (a file that has already run once);
- the lookups that answer get copilotSecretWait = 10 minutes, since which
  attribute is asked is no question of time; only the keyring that never
  answers keeps 200ms;
- that case's bound moves from 10s to 30s: bounded it takes 2.4s at most
  unloaded, unbounded 60s, so a loaded runner has room on both sides.

Run at the reviewed head (macOS, load ~9-15):
- Injected delay (sleep 6 at the top of the fake): the old test fails with
  copilot_cli_test.go:94 token "", want the one under username (12.01s);
  the new one passes (27s). Removing only the 10-minute wait by hand, with
  the delay, goes red again.
- Broken by hand in copilot_cli.go: asking "account" only fails the test
  (token ""), and dropping the timeout fails it on the hang case (63s).
- go test -count=20 -cpu 1,4 -run 'TestCopilotSecretToolUsername$|TestCopilotCLI'
  ./internal/provider: ok.
- gofmt -l: clean. go vet -tags nogui for darwin, windows, linux: clean.
- go test -p 4 -timeout 40m ./... under a sandbox HOME: 53 packages ok,
  no FAIL.
2026-10-15 05:54:03 +08:00
yetone 9916a94608 gateway, usage, plugins: OTel export is the first plugin on the gateway's observer point (P3)
P3 of docs/subsystems/plugin-runtime.md opens the gateway to plugins. The
observer point is first: it only reads, so it carries the least risk.
With plugins/otel off, the gateway exports nothing and does no observing
work. It keeps no reply whole and adds no request context.

- usage.Observer:
  - Methods: Serve, Bodies, Begin(Request) Watch and Ledger(Record). Watch
    has Attempt and End.
  - Observe(o) registers an observer until its remove is called.
  - ServeObservers is counted, and only Server.ListenAndServe calls it.
  - ObservedBodies takes the most any observer wants.
  - Record.SkipOTel becomes Watched, set by appendUsage for a request an
    observer watched.
- The gateway's otel.go becomes observe.go:
  - observeRequest asks each observer through Begin.
  - attempt and end call each Watch. Bodies are added only when an
    observer asks for them, and the whole reply only for WholeBodies.
- internal/otlp: the exporter (otel*.go) moves out of internal/usage, and
  the gateway's per-request span state moves into request.go. otlp.New()
  is an Exporter, a usage.Observer. What it sends is unchanged.
- plugins/otel:
  - Apply registers otlp.New() and disposes of it when turned off.
  - InUse is 1 while settings.OTelExport says to send. A user who exports
    only through MAGPIE_OTEL_* keeps the plugin on under Essentials.
- pluginrt.KeepFresh: the process serving the gateway refreshes every 2s
  when plugins.yml or settings.json changes. A switch made in the window or
  the CLI reaches a running gateway, or a headless serve, without a restart.
- docs: plugin-runtime.md gets a P3 section, a gateway runtime path and an
  updated failure section; reference.md says the export is the otel plugin.

Run at this tree on origin/main 82f48f093 (rebased onto 52ee84761 after,
which touches only the Linux tray icon):
- gofmt -l is clean. go vet passes on darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- go test -count=1 -timeout 25m ./...: ok, 55 packages, none failed.
- New tests:
  - usage: TestObserverServesWithTheGateway and TestObserverLedgerAndBodies.
  - gateway: TestObserverPoint, covering unwatched, no bodies, captured,
    whole and whole streamed.
  - plugins/otel: TestOnExportsOffSendsNothing (on, off, on, with a real
    collector) and TestInUseByEnvironment.
  - pluginrt: TestKeepFreshFollowsPluginsYml.
  - The OTel tests moved with their code to internal/otlp.

Broken by hand, each red, then restored:
- Apply without Observe, and without its dispose.
- KeepFresh refreshing only once.
- InUse reading settings.json only.
- Ledger keeping Watched rows: 3 gateway OTel tests red.
- ObservedBodies taking the last observer's answer.
- Observe not serving a late registration.
- appendUsage not setting Watched.
- Whole bodies never kept.
- Bodies always on with no observer asking.
2026-10-15 05:39:01 +08:00
yetone 52ee847612 gui: a Linux bar's tray icon is the bird's silhouette, not the app's tile, and the tooltip says today's total (ylorn on Discord)
ylorn (Hyprland, 0.1.1241): the StatusNotifierItem's IconPixmap was the
coloured app icon on an opaque white tile, which clashed with a bar's
monochrome icons and became a solid block on bars that tint icons by
alpha; the tooltip said only "magpie".

- Linux now gets the macOS menu bar's template bird (tray.png) in one
  colour on transparency (trayIconFor / linuxTrayIcon, trayglyph.go):
  light, or dark when xdg-desktop-portal's org.freedesktop.appearance
  color-scheme is 2 (prefer light); it is set again on the portal's
  SettingChanged (watchTrayScheme, own D-Bus connection). An unreadable
  portal counts as no preference (light). No IconName is set: a host
  that resolves a -symbolic name but draws it untinted would show a
  black bird on a dark bar with no pixmap fallback. macOS keeps its
  template icon, Windows the coloured app icon.
- With no cards in the menu bar the tooltip is "magpie" over one line of
  today's total, as the panel's Usage tab sums it (trayIdleTip: all
  tokens, cost in Settings' currency, requests), refreshed with the
  cards' loop. Cards picked: unchanged.
- The menu is unchanged (Open / version / Quit): no info lines. The
  panel one click away has the models and usage, and the menu is shared
  with Windows and macOS.

Run (sandbox HOME, pinned GOMODCACHE, shared GOCACHE), on origin/main
21aa40285:
- TestTrayIconPerOS fails with Linux given appIcon back ("linux:
  (0,0)-(64,64), want the menu bar bird's (0,0)-(44,44)"); TestTrayIdleTip
  fails with the tooltip back to plain "magpie". Both pass restored, with
  TestPortalLight, TestTrayTotals, TestTrayIconSize, TestSNITipIsSafeMarkup.
- gofmt -l clean; go vet ./... (darwin), GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./... clean; GOOS=windows go build and
  GOOS=linux go build -tags nogui OK.
- traytip_linux.go (linux && !nogui, cgo) can't be vetted from macOS: the
  two new functions were copied into a darwin build and vetted there.
- go test -p 4 -timeout 40m ./...: exit 0, 53 ok, no FAIL.
- GUI: tray-*.test.cjs (Playwright 1.62.0): 112/112 pass.

Not tried on a real Linux bar (the Windows box with its WSL2/Omarchy VM
was unreachable over ssh): the pixmap, its colour on a light/dark scheme
and the tooltip on waybar/Quickshell/KDE are unverified on hardware.
2026-10-15 05:30:58 +08:00
yetone 82f48f0935 gateway, provider, gui: a provider set to compact natively is asked Codex's compaction_trigger as sent and its sealed compaction goes back unchanged; a checkpoint stays with its writer (#1099)
A new per-provider option, off by default. With it on, Codex's
compaction_trigger reaches the provider as Codex sent it, and the
provider's encrypted compaction item goes back to Codex unchanged instead
of magpie's magpie1: summary. Off, nothing changes.

Where it can be on (provider.CarriesCompaction): a provider with a
Responses API (Sub2API and other OpenAI relays, a remote magpie), a
ChatGPT (codex) account, and the built-in GitHub Copilot on its GPT
Responses path. Copilot's Claude models are asked on chat completions, so
they still get magpie's summary (CompactsOn). A group compacts natively
only when every member does.

No silent downgrade:
- A turn carrying a sealed compaction goes only to the key or account that
  wrote it (compactions.json beside affinity.json, 0600, 1024 entries /
  30 days). With none left, Codex gets a 400 saying the conversation was
  compacted natively on <who>, not a summarised or dropped context.
- A provider whose request would have to be translated (not relayed) is
  refused with a 400 instead of losing the item.
- The upstream's own refusal goes back to Codex as it came, one call.
- base_instructions and Codex's identity are untouched.

Turning it on:
- GUI: the provider editor's Compaction row, "Codex compacts on this
  provider" (shown only where the wire can carry it; zh, zh-TW, ja, de).
- CLI: magpie provider set <id> compaction=native|magpie. A provider that
  can't carry it is refused.

Run on origin/main 00501401a, then rebased onto 84f14e555 (no file in
common) and reran gofmt, vet and go test for gateway, gui, provider,
cli, usage and sessions: all ok. Rebased again onto 8d2a4a7da (gateway.go
and codex_backend.go changed on both sides, merged clean) and reran
gofmt, vet (darwin, linux nogui, windows) and go test for gateway, cli,
provider and gui: all ok. Last rebased onto 7a3fed6bb (only
gateway-routing.md shared, merged clean): gofmt, vet on all three OSes,
and go test -run for the native compaction, sink, CORS, rebind and origin
tests in gateway plus the provider tests: ok.
- gofmt -l: clean. go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
  clean.
- set -o pipefail; go test -timeout 40m ./...: every package ok but
  internal/provider's TestCopilotSecretToolUsername (copilot_cli_test.go:93
  token "", 10.05s), the open load flake #1627; it passes alone -count=5
  and this change doesn't touch it.
- GUI (node --test, chromium + webkit): the provider-editor files, 946
  pass, 0 fail; the new provider-native-compaction.test.cjs runs 5
  languages at 1100 and 420 (60 cases).
- New Go tests: TestNativeCompactionPassesTheTrigger, ...RefusalGoesBack,
  ...StaysWithItsWriter, ...Copilot (gateway), TestCarriesCompaction,
  TestSetNativeCompaction (provider), TestProviderSaveNativeCompaction
  (gui), TestProviderCompactionPair (cli).

Broken by hand, each red, then restored:
1. codexInputAs dropping the trigger even when native: all 4 gateway
   tests fail.
2. checkpoint filter off: StaysWithItsWriter fails.
3. forced relay off: all 4 gateway tests fail (the web_search tool sends
   the turn to translation).
4. GUI save sending nativeCompaction false: the GUI test's first case
   fails.

Not tried: any real upstream (Sub2API, ChatGPT, Copilot). Copilot may
refuse a compacted history holding web_search items; that refusal would
go back to Codex as-is.
2026-10-15 05:20:17 +08:00
yetone 118f4f28bf plugin: a community plugin npm doesn't have installs from the plugins repo's dist branch, so a reviewed plugin no longer waits unmerged for an owner's npm 2FA (magpie-community/plugins#84)
npm's Trusted Publishing can't create a package, so a new plugin's first
version needs an owner's 2FA, and reviewed PRs sat unmerged for it. A
trust made after 2026-09-03 also allows stage publish only, which is why
npm refused zed 0.1.7 and zen-free 0.1.7.

The plugins repo now packs every merged version onto its `dist` branch
(scripts/dist.mjs, magpie-community/plugins f5308cd): tgz/<file> and an
index.json with each version's sha512, manifest and README, with no
credentials. magpie still asks npm first. Only when `bun add` fails for a
@magpie-community package at latest or an exact version, and not because
of the user's minimumReleaseAge (that hold is kept), does installDist
fetch the tarball. It refuses the tarball unless its sha512 is the index's,
keeps it in plugins/dist and runs `bun add ./dist/<file>`. A later npm
install replaces it, and pruneDist removes tarballs package.json no longer
names. npmAsk (market version, Update, the hourly check) takes dist's
latest when npm errors or is behind, and Readme falls back to dist's. The
branch is read through jsDelivr when the China mirror switch is on, else
raw.githubusercontent.com. installMu is now held for the whole install,
fallback included.

Run at this head (on origin/main 8d2a4a7da):
- go test ./... -count=1: all ok but internal/gateway, which hit the
  600s default timeout inside a file rename. The disk was at 5.3 GB free
  and the load around 22. Rerun alone with -timeout 30m: ok in 559.7s.
- gofmt -l clean. GOOS=windows go vet ./... ok. GOOS=linux go vet ok on
  every magpie package that doesn't import Wails (its Linux files need
  cgo, which can't be cross-compiled from macOS).
- New tests, with real Bun 1.4.2 against a fake npm and a fake dist:
  TestDistInstallsAPackageNPMDoesntHave, TestDistServesAVersionNPMRefused,
  TestDistRefusesATarballNotItsIndexs and TestDistWanted.
  TestUpdateBunHoldsBackSaysWhy now has dist holding the held version too.
- Broken by hand, each went red: no fallback, no sha512 check, no prune,
  no dist version in npmAsk, a loose file regexp, and no minAge guard.
- The real dist branch serves index.json and zed's 0.1.7 tarball from
  raw (200). jsDelivr's @dist answered 200, cold in ~20s.

- Real use, sandbox HOME, live npm and live dist: Info said zed 0.1.7
  (npm has 0.1.6), and Add@0.1.7 installed it from dist, package.json
  naming ./dist/magpie-community-opencode-zed-auth-0.1.7.tgz.

Not tried: the GUI's Add on the live branch, or the China mirror path.
2026-10-15 05:18:56 +08:00
yetoneandggbdpq 7a3fed6bb5 gateway: a group in the group sinks its own rate-limited keys by its own Sink, not only the group the agent named (#2255, ggbdpq)
What changed
- planLevel applies a nested group's own Sink (sinkOwn) to its own
  candidates and their trace rows at both places it plans one: the
  weighed units (Smart, usage, pace, weight) and the ordered walk. A
  key or account of that group rate limited with quota left goes behind
  its group's others, within that group's place, as it plans by its own
  routing (#576) and rules. The group the agent asked for still sinks
  the whole after, as before. sinks() still leaves out rotate, weight
  and manual.
- Why: only planGroup read Sink, for the group asked for; an inner
  group's switch did nothing, and its rate-limited account went back
  to the front as soon as its rest ended.
- provider/group.go's comment and gateway-routing.md's Sink row say so.

Ran
- TestNestedGroupSinksItsOwnOrder (outer ordered, smart and by weight;
  three levels deep with the middle group's Sink and with the
  innermost's; inner Sink off; the outer's Sink alone): fails on
  origin/main 00501401a ("order [a b x], want b then a"; "mid's Sink:
  order [a b c y], want [b c a y]"), passes with the change.
- Broken by hand, each red: sinkOwn never sinking (all subtests); only
  the ordered path left unsunk (outer ordered and deeper).
- TestGroupRateLimitedSinks, TestRateLimitedSinksToTheBack (-count=3),
  and -run 'Sink|Nested|OwnRouting|Weighted|Group': ok.
- gofmt -l clean; go vet ./..., GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./... clean.
- go test -p 4 ./... (macOS): ok in every package but internal/agent and internal/gateway, which hit the 10m package timeout under load ~30 with no test hung (the running test 1-2s old); rerun with -timeout 40m: gateway ok 551s, agent ok 426s.

Not tried: a real nested pool with live accounts. The report's sibling,
a nested group's Affinity read only from the outer group, is left for
its own issue.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 05:17:38 +08:00
yetoneandggbdpq d182294be7 gateway: a page at a localhost subdomain spends a subscription only with a gateway key, as Origin null does (#2256, ggbdpq)
What changed
- corsGuard refuses (403) an http(s) Origin at a subdomain of localhost
  unless the call carries an enabled gateway key (localhostSubdomain),
  the rule Origin "null" got in #2242. foreignPage still passes it, so a
  page there that holds a key keeps working; neither gets CORS headers.
- Why: Chrome and Firefox resolve *.localhost to loopback themselves,
  but Safari and other WebKit views hand the name to the system
  resolver, which before macOS 26 asks the network's DNS (WebKit bug
  160504, closed MOVED: "implemented in OS frameworks below WebKit",
  2025-09-19; fails on macOS 15.7). A captive portal's or hostile
  network's resolver serves such a page from anywhere, and its "simple"
  text/plain POST spent subscriptions with no key.
- tauri.localhost and wails.localhost stay keyless on Windows only,
  where Tauri's and Wails' webviews serve themselves at those names. On
  macOS and Linux those apps use tauri:// and wails://, so the two names
  are any page's there, and a hostile resolver answers them as readily
  as any other (the residual the report left open). webviewOS
  (runtime.GOOS) lets the test be each system.
- The same page also reached the gateway rebound: at evil.localhost:3425
  once the name turns to 127.0.0.1, its GET carries no Origin, and
  lanGuard's ownHost counted every *.localhost Host as this computer, so
  GET /v1/models and /v1/magpie/quotas answered 200. ownHost no longer
  counts a subdomain of localhost (localhost itself and
  docker.for.mac.localhost still count); a browser at one needs a key.
- TestForeignPagesRefused's tauri.localhost row now sends a key, and
  TestReboundPageRefused expects wails.localhost refused.
- docs/subsystems/gateway-routing.md says both.

Ran
- TestLocalhostSubdomainNeedsAKey (darwin, linux and windows as
  webviewOS; six routes; cross-origin and rebound; the fake vendor never
  reached): fails on origin/main 00501401a (76 errors, e.g. "POST
  /v1/chat/completions from http://evil.localhost with no key: 200"),
  passes with the change.
- Broken by hand, each red: ownHost counting *.localhost again (the
  rebound GETs 200); localhostSubdomain always false; the Windows-only
  exception dropped (tauri.localhost answered keyless on darwin).
- The cors, rebind, LAN, usage-ingest and allow-list tests: ok.
- gofmt -l clean; go vet ./..., GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./... clean.
- go test -p 4 ./... (macOS): ok in every package but internal/agent and internal/gateway, which hit the 10m package timeout under load ~30 with no test hung (the running test 1-2s old); rerun with -timeout 40m: gateway ok 551s, agent ok 426s.

Not tried: a real Safari on macOS 15 against a resolver that answers
*.localhost; Tauri or Wails apps on Windows.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 05:17:37 +08:00
yetone e9943c1797 release: a release whose notes went out without Chinese is said on one open issue, not only in magpie-releases' log (#2122, KaiZe on Discord)
magpie-releases writes the Chinese notes with a DeepSeek call. Its balance
ran out, so v0.1.1233 to v0.1.1242 shipped English only, and Chinese apps
showed English notes until a user reported it. The failure was only a
warning in a log nobody reads.

mirror-release now checks notes.md for the <!-- lang:zh --> marker. When it
is missing, the job comments on the open "Release notes without Chinese"
issue, or files that issue if none is open. If gh fails, the step only
warns, so the release itself never fails here.

What was run: the step's script against a fake gh in four cases (Chinese
present, no issue open, issue already open, gh failing); the real
`gh issue list` query, read-only; a YAML parse of the workflow. Not run:
a real release (the next tag will run it). No Go code changed.
2026-10-15 05:14:44 +08:00
yetone 21aa402856 gui tests: the Codex subagent details test writes its rollouts now, not on 2026-10-15, so main is green in UTC (#1591)
3c4b4dc97's TestCodexSubagentDetailsReachSessionAPIs held usage's clock at
2026-10-15 12:00 local and wrote the rollouts then, but
/api/sessions/overview reads sessions.StatsFor, whose 7-day window ends at
the real today. On CI (UTC, still 10-14) the fixture day was tomorrow and
the child was left out: "overview token top omitted the active Codex
child", red on macOS and ubuntu at 84f14e555 and aae49d086. In UTC+8 it
passed, and from 10-23 it would have failed everywhere. The test now holds
the clock at time.Now().

What was run, at origin/main 8d2a4a7da:
- before: TZ=UTC go test -run TestCodexSubagentDetailsReachSessionAPIs
  ./internal/gui fails as on CI; Asia/Shanghai passes.
- after: the test passes under TZ UTC, Asia/Shanghai, America/Los_Angeles
  and Pacific/Kiritimati; go test -tags nogui ./internal/gui (local TZ and
  UTC) and ./internal/sessions (UTC): ok. go vet ./internal/gui: clean.
- Siblings: no other internal/gui test holds a fixed date and reads
  /api/sessions.
Not run: the rest of ./... (test-only change in one file).
2026-10-15 05:10:28 +08:00
yetone 8d2a4a7da3 gateway: a Codex subagent sealed to ChatGPT's backend says to turn on Settings › Codex subagents on any model, or to start a new thread when it is on (#2245, qikairo7)
TestSealedTaskNamesSubagentsOnAnyModel.

Run at this head (on 6485056e1, with the #2245/#2246/#2247 fixes together): gofmt -l clean; go vet ./... for darwin and windows, and linux -tags nogui; the full go test ./... in a sandbox HOME, all green. The new test fails on the old code and passes with the fix.
2026-10-15 04:46:57 +08:00
yetone 91c4705e39 gateway: a nested group's own firstToken times its seats, not the outer group's (#2246, Gaudi-XIX)
Each candidate now carries the firstToken of the innermost group that sets one; a candidate with none falls back to the requested group's value. TestNestedGroupFirstToken.

Run at this head (on 6485056e1, with the #2245/#2246/#2247 fixes together): gofmt -l clean; go vet ./... for darwin and windows, and linux -tags nogui; the full go test ./... in a sandbox HOME, all green. The new test fails on the old code and passes with the fix.
2026-10-15 04:46:57 +08:00
yetone 8ef14be3e6 gateway: an effort=auto group leaves a turn the agent sent with reasoning none alone and asks no classifier, so its pick and what went out agree (#2247, sryimnoob123)
The classifier's pick was recorded but never applied when the agent asked for none, costing a classifier call per turn. The outer effort in the routing record is what the agent asked; the effort sent is tries[].effort on the try marked picked:true, which the groups help now says. Thanks to ggbdpq for the reproduction.

Run at this head (on 6485056e1, with the #2245/#2246/#2247 fixes together): gofmt -l clean; go vet ./... for darwin and windows, and linux -tags nogui; the full go test ./... in a sandbox HOME, all green. The new test fails on the old code and passes with the fix.
2026-10-15 04:46:57 +08:00
yetone 198c7637a1 gateway tests: the queued-stream tests order the gateway's writes and the vendor's arrivals by a sequence, not a clock that ticks every ~0.5ms on Windows (#2249)
TestQueuedStreamKeptAliveForASlot checked heard.Before(asked) on
wall-clock times. On Windows time.Now() advances in ~0.5ms ticks, and
the keepalive, the slot being freed and the vendor being asked fit in
one, so heard == asked and the test failed with the right order.
Loosening it to !asked.Before(heard) would pass a broken keepalive: with
queued keepalives off, the first write (the reply) lands in the same ms
as the ask, seen below.

A shared counter (step) now gives each gateway write a place in order,
taken before the write so nothing the agent does on hearing it can come
earlier, and each vendor arrival and answer one too. The sibling checks
use it: TestQueuedStreamKeptAliveForTheMinute's same heard-before-asked
and TestQueuedStreamKeptAliveOnceSentToItsVendor's writeLog.within (its
"kept alive before the vendor was asked" is the same strict compare on
the one write that frees the slot).

Run:
- Reproduced by truncating both clocks to 100ms (forced equal ticks):
  old ForASlot FAIL 5/5 at queue_keepalive_test.go:387 with equal
  times, the issue's message; OnceSentToItsVendor FAIL 5/5 "the agent
  wasn't kept alive before the vendor was asked". With the fix and the
  same truncation, all TestQueuedStream* pass 3/3.
- Broke the guarded behaviour by hand (queuedAlive := func() {} in
  gateway.go): all three tests FAIL at the body check; with the body's
  ": keepalive" check also dropped, each FAILs at the new order check
  (ForASlot :433, ForTheMinute :304, OnceSentToItsVendor :368).
- go test -tags nogui -race -count=20 -run of these and
  TestTranslatedSilenceStillTimesOut: ok (358s). gofmt -l clean,
  go vet -tags nogui ./internal/gateway (darwin) clean.

Not run: the full go test ./..., GOOS=linux/windows vet, the Windows
box. Stopped because the disk dropped below 10G free.
2026-10-15 04:46:57 +08:00
yetone 85ab808b5e gateway tests: TestTranslatedSilenceStillTimesOut times the client's idle wait over the body only, not over getting the headers (#2248)
The 400ms context deadline covered the whole request, so on a loaded
machine the gateway's slow response headers ended the test at
http.DefaultClient.Do ("context deadline exceeded") before it reached
what it checks. The 400ms now starts once Do returns (time.AfterFunc
cancel), standing for the client's idle timeout over the body.

Run:
- Reproduced by injecting a 600ms sleep before the fake vendor's first
  byte: old test FAIL keepalive_test.go:202 "context deadline exceeded",
  the issue's error; fixed test passes 3/3 with the delay in.
- Broke the guarded behaviour by hand (a 5ms ticker calling alive() in
  readSSEAlive, so silence is covered), delay still in: FAIL "a silent
  provider was covered for: 30 in_progress events".
- go test -tags nogui -race -count=20 -run of this test and the
  TestQueuedStreamKeptAlive* tests: ok (358s). gofmt -l clean,
  go vet -tags nogui ./internal/gateway (darwin) clean.

Not run: the full go test ./..., GOOS=linux/windows vet. Stopped
because the disk dropped below 10G free.
2026-10-15 04:46:56 +08:00
yetone aae49d0866 provider: moved Cursor users get plugin 0.2.13, where a Run cancelled while it opens is closed upstream and dashboard usage is collected per account (plugins #130, #131)
0.2.13 (magpie-community/plugins 3351e47) carries two community fixes by
nicegui. #130: a cancel landing between the HTTP/2 head and runOnce's abort
listener was never seen, so the Run kept streaming upstream with its
heartbeat for nobody; it is now closed at each hand-off. #131: the usage
ledger's claimed/owed/flights were keyed by conversation alone, so a
conversation moved to a second Cursor account had that account's own
dashboard event taken as the first account's debt; they are now keyed by
account and conversation. The built-in doesn't share this code, so
un-moved users are unchanged. The cursor mover's min goes to 0.2.13 so
keepMovedCurrent updates every moved user.

Run: npm view @magpie-community/opencode-cursor-auth@0.2.13 version
--prefer-online gives 0.2.13. Plugin: full bun test 1292 pass, 0 fail;
own repros fail on 0.2.12 and pass on 0.2.13. Here: gofmt -l; go vet
./internal/provider for darwin, GOOS=linux -tags nogui, GOOS=windows;
go test -timeout 40m ./... in a sandbox HOME: exit 0. Not run: a real
Cursor account, nor GUI tests (no GUI change).
2026-10-15 04:46:15 +08:00
yetone 84f14e555c usage: a Codex call with no response_id leaves compaction out of Usage requests instead of saying false (#1591)
Codex added token_usage_record and compaction_response_id together, in
openai/codex#41912 (2026-08-31). A call that magpie reads from a
token_count event alone, as in older rollouts, has no response_id. It
can't carry the compaction marker either way. The previous commit
reported such calls as `compaction: false`, which claims they were not
compactions. codexCompactionOf now returns no state for them, so the
ledger and the requests page leave the field out, as they do for any call
with no native evidence.

What was run:
- New test TestCodexCallWithoutResponseIDHasNoCompactionState. On the
  previous commit it fails with `ledger: a call with no response_id claimed
  a compaction state: {..."compaction":false...}`, and with the same message
  for the requests page. It passes now.
- go test -tags nogui ./internal/sessions ./internal/usage: ok.

For all three commits on origin/main 1ad60446f:
- gofmt -l on the changed files: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: ok.
- go build for darwin, linux (nogui) and windows: ok.
- Full suite: go test -tags nogui -timeout 40m ./... (pipefail, sandbox
  HOME): 53 packages ok, exit 0.
- No GUI asset changed, so no Playwright run.
- Not tried: a real Codex subagent rollout (legacy or paginated). The
  formats are from Codex's source, and Hogeexxl checked two real paginated
  subagents.
- Rebased onto origin/main f255a3e3b (12 commits newer, including #2233 and
  #2234 in internal/sessions; no cache-version clash). Rerun there: go
  test -tags nogui -count=1 ./internal/sessions ./internal/usage
  ./internal/gui, gofmt and vet on both packages: ok.
2026-10-15 04:21:31 +08:00
yetone a78ac27532 sessions: a Codex subagent in a legacy-history rollout gets its spawn task_name too, and a forked child's copy of its parent's spawns no longer erases its siblings' titles (#1591)
Two gaps in the previous commit's title link:

- Legacy rollouts. Codex's ThreadHistoryMode is Legacy by default. The local
  thread store has only defaulted to Paginated since openai/codex#47900
  (2026-09-24). A legacy rollout doesn't persist item_completed for a started
  SubAgentActivity. It persists an event_msg instead:
  {"type":"sub_agent_activity", "event_id": <call id>, "agent_thread_id",
  "kind":"started", ...}. Its children got no title. That event now links
  the same way, through one helper (codexAgentStarted) shared with the
  item_completed path.
- Forked children. A forked child's rollout repeats its parent's history,
  including the spawns of its siblings. The same call id then linked from
  two files, which counted as a conflict and erased the sibling's title.
  Titles are now keyed by {child, parent}, and only the file of the child's
  own parent_session names it or takes a name away from it.

What was run:
- New tests. On the previous commit each fails with:
  - TestCodexSubagentTaskTitleFromLegacyActivity: `legacy activity title
    for child-started = "", want "Legacy started task"`.
  - TestCodexSubagentTaskTitleComesFromItsOwnParent: `a fork's copy of the
    parent's spawn erased the child's title: ""`.
- Broken by hand: with the parent dropped from the key, the second test
  fails with `a spawn its parent never made named the child: "Only in the
  fork's copy"`.
- go test -tags nogui ./internal/sessions ./internal/usage: ok.
- The event's field names come from Codex's source (protocol
  SubAgentActivityEvent and the rollout persistence policy, openai/codex
  669449b). Not tried: a real legacy-history Codex subagent rollout.
2026-10-15 04:21:31 +08:00
Hogee 3c4b4dc973 sessions, usage: a Codex subagent with no title takes its parent's spawn_agent task_name, its nickname shows apart, and Usage requests say which calls were compactions (#1591, Hogeexxl)
Hogeexxl's change (his fork branch codex/codex-session-details, f7c176c9),
cherry-picked with his authorship:

- A Codex child thread whose title is still empty after the existing
  precedence takes the task_name of the parent's spawn_agent call, linked by
  the call id and the SubAgentActivity "started" item that names the child's
  agent_thread_id. Conflicting links leave the title empty.
- session_meta.agent_nickname is exposed as `nickname` on the list, one,
  manage and overview responses, beside the title, not in place of it.
- GET /api/usage/requests and /v1/magpie/usage/requests carry `compaction`
  (true/false) for Codex calls with native evidence, and leave it out
  otherwise. A gateway row matched by a unique response_id takes the marker
  and keeps its own model, usage, cost and kind.
- Flags bits 1024 (rowCompactionKnown) and 2048 (rowCompaction) are new.
  TestRowFlagsApart covers them, and they don't overlap 1..512. The sessions
  cache goes to version 21 and the calls cache to calls-v15.

Review:
- Rollout format checked against Codex's source (openai/codex 669449b):
  - v2 spawn_agent args carry task_name.
  - A paginated rollout persists item_completed with a SubAgentActivity
    item: kind "started", id = the call id, agent_thread_id.
  - SessionMeta has a top-level agent_nickname, which Codex's own list.rs
    and metadata.rs read too.
  - compaction_response_id lives in token_usage_record.
  Gaps in legacy rollouts and in calls without a response_id are fixed in
  the next two commits.
- Privacy: only a title string the user's own Codex wrote and a boolean
  are added to local API responses. Nothing new goes to a vendor or to
  telemetry. The ingest POST parses fields one by one, so it is unchanged.
- No .github, dependency or network changes.

What was run:
- His tests pass: go test -tags nogui ./internal/sessions ./internal/usage,
  and the two new internal/gui API tests.
- Broken by hand, each caught by his tests:
  - the nickname read removed;
  - the conflict checks removed;
  - mergeCodexCompactions broken;
  - the gateway pair's setCodexCompaction removed;
  - the flag read forced to true.
- Not caught:
  - the parent check on the title link (covered by a test in the next
    commit);
  - `copy.codexCompactions = nil` in cloneCodexChunks removed. That line is
    defensive only: the shared chunks never hold the map.
- The gofmt, vet and full-suite record for the three commits is in the
  last one.
2026-10-15 04:21:31 +08:00
yetone f255a3e3b7 gui: a routing group's editor keeps its member rows and pattern row inside it, a long model's name ellipsized, not the chips cut off (碳碳双键 on Discord)
碳碳双键's screenshot (zh, ~770px): in a group's editor the 模型 rows ran
past the editor's right edge, 跟随分组推理 / 标准速度 cut off, and the 模式
row didn't line up with them. .fallback and its .fbl are grids with an
auto track, which grows to the widest row's min-content: one long model
id (nvidia/nemotron-3-super-120b-a12b:free) widened the whole column.

The track is minmax(0, 1fr) now, so the column is the editor's width. A
member row's name and its provider shrink and ellipsize (the provider
first), with the whole name as a title on hover; when the chips still
don't fit they wrap to a second line, right-aligned. The rules group
(.rt-rules) and the phone's own row layout (body.web, which wraps and
starts at the left) are left as they were; the new rules sit in :where()
so the phone's still win.

New test group-editor-fits.test.cjs: Chromium and WebKit, the desktop
window and the web page, 1100, 770 and 420 wide, en, zh, zh-TW, ja, de.
It checks that nothing in the members or patterns box passes the
editor's edges, no chip is cut, the page doesn't scroll sideways, the
pattern row's edges are the members box's, and the long name is a title.
It fails on origin/main 00501401a in both engines (desktop 1100 en
already: past the editor's edge) and passes here. Screenshots at zh 770
and de 770 desktop and zh 420 web compared with origin's by eye.

Run: the group-* and routing rules/weight/columns/shape files, 258 of 258;
the full GUI suite (node --test, concurrency 6, 9679 tests): 34 red,
in quota-count-wrap, quota-name-translated, refusal-retries-setting,
routing-held-member, usage-agents-hide, usage-fold (red alone the same
on the unchanged base 8e8316ed2; filed as #2228, #2163, #2252, #2211 and
the new #2258) and four that pass alone (deprecation-notice,
login-import, name-suffix-no-names, remote-magpie).
2026-10-15 04:20:09 +08:00
yetone 00501401ae gui: the subagent effort note's words live with the Routing page, which is a plugin now (#2232)
Koohoko's patch was written before Routing moved into plugins/routing
(eb7199e12): its one new Routing string went into the core i18n.js. It is
used only by plugins/routing/client.js, so its zh, zh-TW, ja and de go in
plugins/routing/i18n.js, beside the page's other words, and the core
scripts' size budget (91b9065a5) isn't spent on it.

Run: claude-subagent-tag, desktop-subagent-model, subagent-effort,
codex-subagent-model, routing-kind, purpose-filter, routing-purpose-state,
i18n-keys and agent-notice-lang (Chromium and WebKit, 1100 and 420, the
five languages where each test covers them): 111 pass, 0 fail.
2026-10-15 03:34:59 +08:00
Haogao Gu d966e19154 gateway, gui: the Routing page tags a Claude Code subagent's turn as it does Codex's
Codex names a subagent's request (x-openai-subagent: collab_spawn), and
the Routing page tags its row Subagent, with why it went where it did.
Claude Code names no kind, so Claude Desktop's subagent turns, which
magpie now moves to their own model and effort, read as the lead's: a
Desktop session's rows on one routing group could not be told apart.

Claude Code 2.1.295 sends x-claude-code-agent-id from every agent context
but the main one. Its x-claude-code-request-class and
x-claude-code-agent-type hints go only to a first-party base URL or with
CLAUDE_CODE_GATEWAY_HINT_HEADERS, so magpie doesn't get them.

- subagentTurnOf keeps the id in Route.SubagentID for a request that
  offers tools and names no kind: the turn desktopSubagentPick and
  desktopSubagentEffort take. Desktop's and terminal Claude Code's turns
  are kept, moved or not. The lead's turns, a subagent's tool-less helper
  calls (#2081: Claude Code's housekeeping) and a blank id are not. A
  kind wins over the id.
- A Desktop pick or effort that found the turn is trusted, so the body
  isn't decoded again; a request without the id isn't decoded at all.
  Only a subagent's turn with neither setting reads its tools once.
- Kind stays empty (#2081), so the ledger, the Usage page and the
  Purpose filter keep the turn unmarked. The ledger's Subagent already
  keeps the same id, on the helper calls too.
- routing.js tags it through tagKind in the request list (by request and
  by session), the story, the replay and the tray panel, with Codex's
  words and reasons (kindWhy's collab_spawn: moved or kept, within a
  routing group, on the model asked for). No new strings.
- The day's history keeps the id. A route kept before it has no tag, and
  its moved/kept story reads as before.

Verified at this head, on b9c589eb, under a temporary HOME with Go's
caches pinned:
- Each new test fails with its guarantee broken by hand (a real FAIL, not
  a build error), then passes restored. Go, 10: the id never set; tools,
  kind or the trusted pick ignored; tools decoded before the header (the
  lead's request then allocates 10 times, 1 for its headers); the route
  not given the id; Desktop only (terminal fails); every request trusted
  (the helpers fail); the JSON key renamed; the field left out of the
  history. GUI, 8, each 0 pass / 4 fail (Chromium and WebKit, 1100 and
  420, zh) at its own assertion: tagKind ignoring the id; the list, the
  story, the replay or the panel testing Kind alone; kindWhy's
  collab_spawn reasons on Kind alone; the id over a kind; the Purpose
  filter following the tag.
- go test -tags nogui ./...: 53 packages ok.
- go test -race -count=20 -run
  '^(TestSubagentTurn|TestHistoryKeepsSubagentID|TestDesktopSubagent)'
  ./internal/gateway: ok.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: exit 0.
- claude-subagent-tag.test.cjs: 20/20 (Chromium and WebKit; en, zh,
  zh-TW, ja, de; 1100 and 420), three runs in a row.
- Desktop-bundled Claude Code 2.1.295 through the built gateway, a
  temporary HOME, a loopback-only sandbox and local fixture replies, its
  Agent tool spawning a real subagent: with nothing set, with a subagent
  model, and as terminal Claude Code, each run kept 4 routes; the
  subagent's one turn has the id the client sent upstream, the lead's 3
  requests none, Kind empty; the model pick moved it to m2. No tool-less
  helper call came in these runs; the Go tests cover them.
- The Routing GUI tests around it, 91 files (every routing-*, the tray
  panel's two, purpose-filter, click-scroll, the Codex and Desktop
  subagent files, subagent-effort, search-instead, search-mcp, vision-mcp,
  remote-group-served, reasoning-speed, usage-ledger, sessions-overview
  and the new one), six files at a time: Chromium 602/617, WebKit
  572/617. Each failure fails without this commit too. On b9c589eb
  untouched (checked for the effort commit): routing-days-fit,
  routing-failed-open and routing-side-calls in both engines (their
  position checks against #2134's at-top rule), routing-wb-restricted
  (#2115's wheel), and at 420 in WebKit routing-agent-gone,
  routing-agent-hue-not-red, routing-rest-off and routing-held-member.
  On 6926b7ce: search-instead in WebKit, 5 of 5 alone, and
  routing-context-fold's picked request in WebKit, a row out of view, 2
  of 5 runs alone there and 3 of 5 here.

Not run: the whole GUI suite, a real Claude Desktop window or Cowork,
Linux and Windows machines (GOOS vet and build only), WebKitGTK.
2026-10-15 03:34:59 +08:00
Haogao Gu cdeb00f841 gui tests: desktop-subagent-model reads each write once its answer is back
A pick on the Agents page redraws its square at once and writes behind
it, queued (commit, and the effort slider's onchange). The test read the
fixture's last write as soon as the square changed, so a slow write raced
it: in a broad Routing run, six files at a time, Chromium's en 1100 case
read "high" for the subagent effort just set back to Default.

Each pick now waits for its /api/set answer, which the fixture sends
after noting the write. The app is unchanged.

Checked with the fixture's write held 300 ms (a probe, not committed):
the test before this fails 4 of 4 (Chromium and WebKit, 1100 and 420,
en) at "Desktop pick posts the catalog id", the model pick #2081 brought;
with this change it passes 4 of 4. Unheld, the race is rare: six runs of
the whole file at once pass 120/120 before this and after it. The file
alone: 20/20. The three UI breaks of the subagent effort still fail 4 of
4 (zh), and pass restored.
2026-10-15 03:34:59 +08:00
Haogao Gu b476dc5a93 agent, gateway, gui: Claude Desktop's subagents can have a reasoning effort of their own
After #2081 gave Desktop a subagent model, its effort still came from the
request. Add subagent_effort beside that model, using the existing effort
slider. The live setting DesktopSubagentEffort belongs to magpie; no
Claude client file or binary is changed.

Empty preserves the request's effort, including disabled thinking. A pick
applies only to Desktop requests with an agent id and tools, independently
of model replacement: unset, equal and unavailable model picks all work.
Reuse the attempt-level fitting; fixed group-member efforts and reasonless
models keep their existing precedence. count_tokens applies the pick after
unmasked-body restoration. A Codex SubagentPick is not evidence of a
Desktop tool turn.

Route.Effort keeps the incoming level, SubagentEffort records the configured
pick, and tries/usage keep the actual level. Routing explains the pick
even without a model replacement. Options follow the target model; a
saved level survives a model change. POST /api/settings preserves it.
Disconnected preferences, Disconnect/reconnect and restored settings work;
a Live pick gives restart advice only when it actually connects the agent.
Codex's own settings and default-effort explanation are unchanged.

Verification on b9c589eb plus this change, with temp HOME and pinned Go
caches:
- go test -tags nogui ./...: 53 packages pass.
- Gateway effort tests under -race -count=20: pass.
- gofmt -l: empty; darwin, linux nogui and windows vet/build: exit 0.
- 23 intentional Go behavior breaks produce real FAILs, then pass
  restored: application, scope, model independence, Default/none,
  disabled thinking, fitting/member priority, counts, next request,
  trace, saving/validation, Live notices and model-dependent options.
- Three UI breaks fail in both engines at 1100/420: default explanation,
  missing effort story and missing translation. Restored: Desktop's new
  controls/story matrix passes 20/20 across five languages. Desktop,
  Codex, tier/effort and translation regressions pass 97/97.
- Desktop-bundled Claude Code 2.1.295 runs real Agent calls through the
  built gateway, temporary HOME and loopback-only sandbox, all replies
  local fixtures. Low/high/Default sends its child low/high/xhigh on m2;
  its lead remains xhigh on m1. All three runs exit 0.

The expanded Routing run is not green: Chromium 510/525, WebKit 485/525.
These failures reproduce on untouched b9c589eb, including targeted reruns.
The day/row anchor assertions conflict with #2134's at-top rule: undoing
that one guard makes all 12 tests pass. A narrow request lies below the
viewport; user wheel input makes the failed click pass. WorkBuddy's wheel
pointer/hidden-button failures overlap #2115; moving the wheel to the
view gutter fixes 3/4 selected cases, one WebKit 420 case remains.
The held-member clipping assertion also reproduces on base; its timing
cause is not established. This baseline evidence is reported separately
in the follow-up feature issue, not counted as passed or fixed here.

Not run: the complete GUI suite, the Electron window/Cowork, native
Linux/Windows or WebKitGTK. Cross-builds are not runtime checks.

Reported-by: Koohoko
2026-10-15 03:34:59 +08:00
yetone 932a62d5e0 gateway tests: a silently kept cache stays in Gemini's shape, across a restart, and a prompt too small still moves (#2230)
JasonBuildAI's test covers OpenAI's Chat shape and a reply with no usage.
TestAffinitySilentCacheGeminiRestartAndSmall adds the cases the same
substitution has to hold for: Gemini's usageMetadata (promptTokenCount,
cachedContentTokenCount 0 on a first turn), the stick read back from
affinity.json after the in-memory one is dropped, and a 600-token prompt,
under cacheWorth, which still moves as "no-cache". Each case also checks
the trace tells CacheRead 0 and CacheWrite equal to the prompt sent.

Run:
- With the substitution in answered taken out, both this test and
  TestAffinityKeepsACacheTheVendorKeptSilently fail "Why:no-cache ...
  want cache" (the second turn went to k2). With it: PASS.
- go test -tags nogui -run TestAffinity ./internal/gateway: ok.
- go test -tags nogui ./... on macOS with this series (at 1b96dcc96 before the
  rebase): every package ok. gofmt -l, go vet ./... on darwin, linux
  (nogui) and windows, and the three builds: clean.
2026-10-15 03:34:58 +08:00
JasonBuildAI 7c5bfd7a1d gateway: auto affinity keeps a conversation where a vendor's cache is kept without saying so (#2230, JasonBuildAI)
A vendor that keeps the prompt cached by itself and reports nothing of it —
OpenAI's automatic prefix cache, Gemini — says neither a read nor a write of
the turn that built the cache. affine judged that turn's stick by what the
reply read and wrote (0 + 0), found it under cacheWorth and moved the
conversation's second turn as "no-cache": the whole prompt went afresh to
another key or account and was paid for in full, on every turn after the
first, for anyone with more than one key or account and Affinity auto (the
default).

7f968b95b named this as not covered: "a vendor that caches without reporting
a write (OpenAI's automatic prefix cache, Gemini) still reports CacheWrite 0
on a first turn, so its second turn may still move".

What such a vendor holds of the conversation after a turn is the prompt that
turn was sent, which is what its cache now has. answered takes the reply's
usage rather than its two cache counts, and where the reply reports neither
a read nor a write, the prompt it was sent (Input) stands for the write: the
second turn stays to read it, as it does for a turn that wrote its cache. A
reply that reports no usage at all (Input 0) counts as no cache, as before,
and a prompt under cacheWorth (1024) still moves. A read or a write the
vendor does report is used as it was, and resting, spent, cold, strict, turn
and rotate are judged before this, so nothing else changes.

The observable change: with Affinity auto, a conversation whose last reply
reported neither a cache read nor a cache write, and was sent at least 1024
tokens, is kept where it was (Why "cache", Kept true) rather than moved
(Why "no-cache"). Its stick, affinity.json and the trace's
Affinity.CacheWrite carry the prompt sent, and Affinity.CacheRead stays 0,
which is what the Routing page shows as read and written; the page itself is
unchanged.

Tests:
- affinity_silent_cache_test.go (new): TestAffinityKeepsACacheTheVendorKept
  Silently. Two keys, least-used routing, and a Chat vendor reporting
  prompt_tokens 3000 with cached_tokens 0 — what OpenAI and Gemini send of a
  first turn — keeps the second turn on k1 as "cache", with the trace
  telling CacheRead 0 and CacheWrite 3000; a vendor reporting no usage at
  all still moves to k2 as "no-cache".
- TestAffinityKeepsACacheJustWritten, its "too little either way" (300/300,
  no-cache) case included, passes as it did.

Run:
- go test -tags nogui -count=1 -run TestAffinity ./internal/gateway: ok,
  80.982s (TestAffinity 39.36s, TestAffinityKeepsACacheJustWritten 26.54s,
  TestAffinityKeepsACacheTheVendorKeptSilently 9.68s).
- go test -tags nogui -count=1 -timeout 45m ./...: every package passes
  except 21 tests red on this Windows machine — agent 4
  (TestInstallWithoutNodeParses, TestWSLClaudeFollowerOnTheMainModelIsNoDrift,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI), gui 4
  (TestGatewayHeldByAContainer, TestGatewayFixQuitsOnlyAMagpie,
  TestFXStateDoesNotWait, TestUpdateThatWontStart), library 3
  (TestAgentsSkillsFolders, TestRemoveFoundSkill,
  TestHooksCodexTrustMovesWithTheGroups), gateway 2 (TestClaudeAsRootEnv,
  TestSweepBridgeProjectsTakesOnlyTheBridgesFolders) and one each in backup,
  davsync, pluginrt, provider, sessions, update and usage. A fresh worktree
  at the base e98440ae, without this change, fails the same 20 of them. The
  21st, gui's TestPurposeAssetMatchesUsage, fails only in this checkout,
  whose internal/gui/assets/purposes.js is CRLF (git says i/lf w/crlf) and so
  keeps the "\r" its TrimSuffix(";\n") doesn't cut; the file is not in this
  diff and the test passes in the base worktree.
- gofmt -l on the changed files: nothing. go vet ./..., GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./...: nothing. go build,
  GOOS=linux go build -tags nogui, GOOS=windows go build: ok.
- Broken by hand: with the substitution removed the new test fails —
  "silent cache: affinity &{... CacheRead:0 CacheWrite:0 ... Why:no-cache},
  want cache". At the base commit the case fails the same way, the second
  turn going to k2.

Not tried: the Playwright suite (no GUI asset changed; the Routing page
reads the same JSON) and a live OpenAI or Gemini key.
2026-10-15 03:34:58 +08:00
yetone ec15f87393 sessions: a Codex Desktop fork's replayed parent checkpoints book no usage, so a thread_spawn session isn't counted ~1000x (#2234, zlxdengtianhei)
A token_count event that can't be paired with a response record fell
back to the cumulative total's delta whenever a previous total existed,
even when the event's own last_token_usage was there. A Codex Desktop
subagent fork (thread_spawn) writes two cumulative counters into one
rollout: its parent's, replayed with last=0, and its own. Each switch
from the fork's lower counter back up to the parent's booked the gap,
tens of millions of tokens, as one call. The reporter's day read 187.4B
tokens where ~10.3B was real.

last_token_usage is the request's own usage, exact even when zero, so it
is used whenever it is valid; only a missing or invalid last falls back
to the delta, and with no previous total to the total itself, as before.

Run:
- TestCodexUsageForkReplayCountsOnlyLast (new), on the reporter's own five
  lines (testdata/codex-fork-replay-checkpoints.jsonl, numbers untouched),
  checking both Calls and the session summary. Old code: FAIL "calls
  booked {Input:832145 Output:281374 CacheRead:82834688 ...}, want
  {Input:3273 Output:1201 CacheRead:72448 ...}". New: PASS, on macOS and
  on the Windows box with every TestCodex* test.
- TestCodexUsageUnpairedCountKeepsLegacyDelta and the other Codex usage
  tests still pass; go test -tags nogui ./... on macOS with this series:
  every package ok.
- gofmt -l, go vet ./... on darwin, linux (nogui) and windows: clean.

Not run: a reindex of the reporter's full dataset; the numbers above are
from their excerpt.
2026-10-15 03:34:58 +08:00
yetone 4f020a95ff gui tests: the take-over test copies its fake magpie on Windows, so the temp folder can be deleted
TestGatewayFixQuitsOnlyAMagpie hard-links the running test binary as the
fake magpie it ends. On Windows a hard link to a running executable is
that executable, so t.TempDir's cleanup failed "unlinkat ...magpie.exe:
Access is denied" and the test went red even once the take-over worked
(#2231). On Windows it now copies the binary, as it already did where
linking fails.

Run on the Windows box with the previous commit: 3 of 3 PASS (~7s each);
without this change the take-over passes and the test fails in cleanup
only. macOS: go test ./internal/gui ok in the full-suite run.
2026-10-15 03:34:58 +08:00
yetone b25659344f proc: on Windows a port nobody listens on reads as no listener, not "exit status 1", so the take-over doesn't say "stuck" (#2231, JasonBuildAI)
ListeningOn on Windows ran Get-NetTCPConnection with -ErrorAction
SilentlyContinue. When nothing listens the cmdlet fails with
ObjectNotFound, and PowerShell still exits 1 for it, so the read answered
"exit status 1" where lsof and /proc answer no pids and no error. The
Gateway page's take-over waits for exactly that answer to know the older
magpie let the port go; with an error it waited out its deadline and said
"stuck" with the port already free. The command now catches the error and
exits 0 only for ObjectNotFound; any other failure (the cmdlet missing, a
PowerShell cut short) is still an error.

JasonBuildAI's 85a8c8c0 reads "exit 1 with nothing on either stream" as
none found instead. Catching the category keeps a silent failure of
another kind an error, so this takes that route; his separate point that
the darwin reader has no deadline guard is not in this commit.

Run:
- TestNothingListeningIsNoError (new), on the Windows box: old code FAIL
  "nothing listens on 56409: exit status 1", new PASS; TestListeningOn
  passes on both. go test ./internal/proc on macOS: ok.
- TestGatewayFixQuitsOnlyAMagpie (internal/gui) on the Windows box: old
  code FAIL "take-over: {OK:false Reason:stuck ...}" after 12.5s; with
  this change the take-over succeeds (the test's own cleanup failure is
  the next commit). With both, 3 of 3 PASS in ~7s each.
- go test -tags nogui ./... on macOS with this series: every package ok.
- gofmt -l, go vet ./... on darwin, linux (nogui) and windows: clean.
2026-10-15 03:34:58 +08:00
yetone d92cc5b84b sessions: WorkBuddy's and MiniMax's session folders behind a link are read too, each session named under the agent's folder (#2233)
The previous commit followed a linked ~/.codex/sessions. Two more agents
hand one root to filepath.WalkDir the same way and missed everything
behind a junction or a symlink: WorkBuddy's (and CodeBuddy Code's)
projects folder (buddyFiles) and MiniMax Code's sessions folder
(minimaxCallFiles). The follow-and-rename is now walkLinked, used by all
three, so each names its files under the agent's own folder rather than
the link's target, as JasonBuildAI's change does for Codex. The other
WalkDir calls in internal/sessions walk magpie's own folders or a single
session's folder, not an agent's root.

Run:
- TestBuddyProjectsBehindALink (new): with buddyFiles back on
  filepath.WalkDir it fails "WorkBuddy sessions behind a link: 0, want 3";
  with walkLinked's rename taken out it fails "a WorkBuddy session behind
  a link is named .../002/projects/..., want it under .../.workbuddy/projects",
  and TestCodexRolloutsBehindALink fails "a rollout behind a link reads as
  .../002". Passes with the change, on macOS (symlink) and on the Windows
  box (mklink /J junction), with every TestCodex* test there.
- go test -tags nogui ./... on macOS with this series: every package ok.
- gofmt -l, go vet ./... on darwin, linux (nogui) and windows: clean.
- Windows internal/sessions as a whole: TestCursorEditorCopiedOncePerChange
  fails there with and without this (a %TEMP% folder another test leaves;
  noted on #1827).
2026-10-15 03:34:58 +08:00
JasonBuildAI 85e84d6254 sessions, usage: a Codex folder whose sessions folder is a junction lists its sessions and calls again (#2233, JasonBuildAI)
The Codex CLI on Windows leaves every folder under .codex as a junction when
.codex is kept on another drive, sessions and archived_sessions among them.
codexFilesIn handed that folder to filepath.WalkDir, which lstat()s the root
it is given, and to lstat a junction is not to see a folder: the walk called
back once for the root, descended no further, and missed every rollout. The
Codex session was absent from the Sessions page, and its calls, tokens and
cost from Usage and the ledger. On the machine this was found on, whose
~/.codex/sessions is a junction to
D:\CDriveData\C_\Users\黄江南\.codex\sessions, two binaries built from this
tree and from 2a99e7a4 alone read the same .codex as:

  magpie usage all, 2a99e7a4: 26563 calls, no Codex row among the agents
  magpie usage all, this change: 98736 calls, Codex 72173 of them, 257M, 67%
  magpie sessions, 2a99e7a4: 483 sessions, none of them Codex
  magpie sessions, this change: 1083 sessions, 600 of them Codex

Follow the link with proc.RealPath, the resolver already kept for Codex's own
install.ps1 junctions - filepath.EvalSymlinks leaves a junction as it is - and
walk what it returns. Each rollout is still named at its path under the Codex
folder, not under the link's target: a rollout's path is read back to the
Codex folder for its config.toml and state_*.sqlite (codexHomeOf, the
provider each session reads as, MoveCodexProvider), and the target holds
neither. On this machine C:\Users\Jason\.codex has config.toml and a
state_*.sqlite while D:\CDriveData\C_\Users\黄江南\.codex has neither, so a
rollout named under the target would read as a provider the user is not on,
and a move offered on it would write nothing Codex reads. A folder that is
not a link is untouched: the root is resolved only where lstat says it is no
folder.

TestCodexRolloutsBehindALink links the fixture's sessions folder to a folder
beside it, a junction on Windows and a symlink elsewhere, and wants the same
rollout keys and sizes, the same session count, a rollout that reads back as
the fixture's Codex folder, and every session's provider read from the
config.toml written there. With the resolver taken back out:

  --- FAIL: TestCodexRolloutsBehindALink (2.28s)
      codex_link_test.go:65: rollouts behind a link: map[], want map[codex:01a0bdc9-b5fd-7e63-9658-68bc8dce5ecd:833]

with the walk left at the link's target instead:

  --- FAIL: TestCodexRolloutsBehindALink (2.14s)
      codex_link_test.go:71: a rollout behind a link reads as D:\Temp\...\002, want D:\Temp\...\001\codex

With the change: PASS.

Run, on windows/amd64 over 2a99e7a4 with this change:
- gofmt -l internal/sessions/sessions.go internal/sessions/codex_link_test.go (empty)
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... (each exit 0)
- go build ./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build ./... (each exit 0)
- go test -tags nogui -count=1 -run TestCodex ./internal/sessions/ (ok, 11s)
- go test -tags nogui -count=1 ./internal/sessions/ (ok, 82s, with TMP and TEMP
  pointed at a fresh folder. Without that TestCursorEditorCopiedOncePerChange
  fails on %TEMP%\magpie-cursor-fresh, which TestCursorLeftCopiesSwept leaves
  behind, having set TMPDIR, which os.TempDir does not read on Windows. It
  fails the same way with this change taken back out: a Windows
  test-isolation red of that pair, not of this change.)

Not run: the GUI's Playwright suite (no GUI asset changed), and the rest of
go test -tags nogui ./... (internal/sessions is the only package the change
reaches).

AI disclosure: this change was drafted with AI assistance at my request,
under my direction and review.
2026-10-15 03:34:58 +08:00
yetone 8bf98110b8 plugin: a folder plugin's path written on macOS or Linux is a path on Windows too, so a backup or a sync leaves it out (#2229, JasonBuildAI)
plugin.IsPath read a spec as a path when filepath.IsAbs said so on the
host. On Windows "/Users/me/plugin" is not absolute, so a folder plugin
added on a Mac was carried into a backup and a WebDAV sync as if it were
an npm package, and the Windows machine restoring it asked bun to install
"/Users/me/plugin". A spec starting with / or \ (a UNC path among them)
now counts as a path on every system, as a drive-rooted one already did
off Windows.

Run:
- TestIsPathWhicheverSystemWroteIt (new). On the Windows box at the old
  code it fails for "/Users/me/plugin", "/home/me/plugin/index.js" and
  `\Users\me\plugin`; on macOS for the two backslash forms. Passes on both
  with the change.
- On the Windows box, the three reds the issue names, old code then new:
  TestPluginsCarried (provider), TestRestorePluginsAndSignIn (backup),
  TestSyncPluginsAndSignIn (davsync) FAIL then PASS.
- go test -tags nogui ./... on macOS with this and the next four commits:
  every package ok.
- gofmt -l, go vet ./... on darwin, linux (nogui) and windows, and the
  three builds: clean.
- Windows internal/plugin as a whole: TestTaggedRepos, TestTaggedReposSlowRead,
  TestReadmeOfTaggedRepo, TestGitPluginUpdateOnlyWhenItsRepositoryMoved,
  TestMarketIconsAreBundled, TestEnsurePi and TestGitPlugin fail there
  with and without the change (Windows-only, CI compiles them only).
  TestLoadConcurrentWithSavesAndEdits failed once in the full package run
  with the change; alone it passed 6 of 6 at the old code and 6 of 6 with
  it. Noted on #1827, the open issue for Windows-only reds.
2026-10-15 03:34:58 +08:00
yetone 1ad60446ff gateway: a model failing between its siblings' answers climbs its own rest ladder, not a minute forever (#2241, weizsw)
The backoff count was kept per account (restKey), and any model's answer
cleared it. On an account serving several models, a model that kept
failing while its siblings answered was counted 1 every time and rested
one minute, forever. weizsw's Antigravity seat: 41 of 43 rests at
failures: 1.

restAfterMarked now also counts each model's own failures (restID), and
only that model's answer clears that count (servedCandidate). When a
model's own count is past the account's, a sibling answered since the
model last did, so the failure belongs to the model. It climbs its own
ladder (1, 2, 4, 8, 10 minutes) and rests alone, keyed by restID, while
its siblings stay served. If every model fails with no answer between
them, the account still climbs and rests whole, as before. A window
rest wins as before. A candidate naming no model keeps the account's
count alone.

What was run:
- TestModelLadderClimbsPastSiblingAnswers (new, model_ladder_test.go).
  Old code: FAIL ("failure #2 after a sibling's answer: 1 failures,
  rests 59.99s; want 2m0s"). With the restID choice taken out by hand:
  FAIL ("rests antigravity@seat@example.com, want the model alone").
  With the fix: pass.
- The first full run caught TestSmartRouting. Its modelless candidate
  ("t#fail") was given a "t#fail/" count that its served() call never
  cleared. Fixed by counting per model only when the candidate names
  one. TestSmartRouting and the rest/ladder tests pass.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui and GOOS=windows
  clean.
- HOME=<scratch> go test -tags nogui -timeout 40m ./...: every package ok
  except gateway's TestSmartRouting (above). After the fix, gateway was
  rerun whole: ok (468s).
2026-10-15 03:25:41 +08:00
yetoneandJasonBuildAI c20bb76c4c gateway: a sandboxed frame's Origin: null spends a subscription only with a gateway key (#2242, JasonBuildAI)
A sandboxed iframe, or a page opened from file://, sends `Origin: null`.
foreignPage judges only http and https origins, so corsGuard let "null"
through without a key. A simple text/plain POST from such a page (no
preflight) reached /v1/chat/completions and spent the user's
subscription. corsGuard is where every route's same-origin is decided,
so the fix goes there: a request with Origin: null is answered only
when it carries a working gateway key (keyedCaller, which the listed-
origin 401 path now uses too). It gets 403 and a message that says how
to send a key. App schemes (app://…) and requests with no Origin are
unchanged.

The patch is JasonBuildAI's fe11a8abd (fork branch
fix/null-origin-keyless-spend-a13b21). docs/subsystems/gateway-sessions.md
also says that a null Origin needs a key.

What was run, at this commit's parent 8e8316ed2 vs. this tree:
- Repro with a sandbox HOME, a fake upstream on 127.0.0.1:3672 that logs
  each hit, and `magpie serve` on 127.0.0.1:3671. On main, curl POST
  with Origin: null got 200 and reached the vendor. A sandboxed srcdoc
  iframe in a file:// page, in Playwright WebKit and Chromium, reached
  it too (2 hits). Fixed: null POST and GET /v1/models got 403,
  app://cherry and no-Origin got 200, and both browsers were refused
  with 0 upstream hits.
- With main's cors.go and the new tests, TestForeignPagesRefused and
  TestOpaqueOriginNeedsAKey FAIL ("a sandboxed frame with no key reached
  the vendor 5 times"). With the fix both pass.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui and GOOS=windows
  clean.
- HOME=<scratch> go test -tags nogui ./...: every package ok except
  internal/gateway and internal/agent. Those hit the 10m timeout at load
  average 76-91: the running tests were 14s and 23s old, not hung. Rerun
  with -timeout 40m: gateway ok (724s), agent ok (620s).

Co-authored-by: JasonBuildAI <jasonbuildai@gmail.com>
2026-10-15 02:58:41 +08:00
yetone d5847f1985 provider: a Codex token refresh replaces ~/.codex/auth.json through a flushed temp file, so a crash or a file held on Windows leaves Codex signed in, not an empty auth.json or a spent refresh token (#2239, JasonBuildAI)
codexToken wrote the rotated tokens back into the user's own Codex
sign-in (~/.codex/auth.json, $CODEX_HOME when set) with a bare
os.WriteFile: O_TRUNC, then write, error dropped. A machine going down
between the two leaves the file empty or zeroed (#1505's shape, on the
vendor's sign-in), and on Windows a file another program holds for a
moment refuses the open, so the rotation never reached the disk while
the refresh token on it was spent (refresh_token_reused on the next
refresh, magpie's or Codex CLI's). It now goes through writePrivate
(edit.Target + steady.WriteFile: temp file beside it, fsync, rename,
held target waited out by steady.Rename for up to 0.5s, mode 0600); a
write that still fails is logged rather than dropped silently, and the
fresh access token still serves the request. codexToken is the one
path for the default home's account, its usage, resets, keep-alive and
the Usage page.

Siblings: grepped every os.WriteFile / O_TRUNC / os.Create outside
tests. The only other write of an agent's live sign-in that truncated
was writeClaudeCredential's file branch (Claude Code's
.credentials.json, written when magpie switches Claude Code's
sign-in off the Keychain); it now goes through writePrivate too and returns a failed
flush as an error instead of "saved". Saved accounts' refreshes
(logins_on.go) already go through writeLogins; Kiro's IDE file through
writeFileAtomic; Codex/Claude switches through writePrivate; mcpauth
and plugin-auth through steady. Gemini's oauth_creds.json, Cursor's,
Grok's, Command Code's, ZCode's credential files are only read. The
remaining os.WriteFile calls write magpie's own caches, marks, ids,
temp files, or create a file only when it is empty (dsh, zcode).
docs/subsystems/providers-accounts.md's #1505 entry says so.

Tests (internal/provider/credentials_write_test.go, _windows_test.go):
- TestCodexRefreshFlushesAuthJSONBeforeReplacingIt: steady.Sync made to
  fail leaves auth.json byte-identical and no temp file; with a working
  flush, auth.json still holds the old sign-in at flush time, the temp
  is beside it, the result keeps every other field and mode 0600.
- TestClaudeCredentialFlushesBeforeReplacing: same for
  .credentials.json, and a failed flush is an error.
- TestCodexRefreshOutlastsAHeldAuthJSON (Windows): auth.json held with
  CreateFile(GENERIC_READ, FILE_SHARE_READ) for 100ms during the
  refresh; the rotated r-work-2 must be on the disk afterwards.

Broken by hand: with both writes put back to os.WriteFile, on macOS the
first two FAIL ("a flush that failed left auth.json ...r-work-2...,
want the sign-in as it was"; "a write whose flush failed reported as
saved"), and on the Windows box (Windows 11 x64, amd64 test binary,
sandbox USERPROFILE/APPDATA/LOCALAPPDATA/TEMP) all three FAIL, -count=3,
the third with "the rotated tokens are not on the disk, only the spent
one's: ...r-work...". With the fix all three PASS 3/3 on Windows and
the two PASS on macOS.

Run on origin/main 7be68467f: gofmt -l (empty),
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go build,
and go test -tags nogui ./... under a sandbox HOME with pinned caches
(every package ok but internal/agent and
internal/gateway, which hit go test's default 10m timeout with no hang
in their stacks, the machine at load average 50-90 from other
sessions; rerun with -timeout 40m both ok, 800s and 874s). On the Windows box: the full internal/provider
test binary run from the package folder:
all pass but TestPluginsCarried (open #2229, the same on the old
binary), TestBorrowedOffLevelIsNotAdvertised and
TestAsksOwnBackendAgreesWithTheGatewayDispatch, which read ../catalog
and ../gateway that weren't copied there.

Rebased onto origin/main 3d3a834d6 (30 files, none of them these):
go vet ./internal/provider for darwin, linux (nogui) and windows, and
go test ./internal/provider in the sandbox HOME, ok.

Not tried: a real Codex refresh against OpenAI (the change is only the
write; the refresh request is unchanged), and a real power cut.
2026-10-15 02:47:23 +08:00
yetone ce13984567 testenv: a stand-in codex is found before the installed one on Windows, so the gateway's tests don't read the user's Codex version (#1827, EdwinDigital)
Windows finds a program through PATHEXT and skips a file with no
extension. testenv.inertTools wrote a .bat beside each #!/bin/sh stand-in.
The gateway's TestMain calls StandIns directly, though, and StandIns wrote
only the extensionless file. On a box with Codex installed, LookPath went
past the stand-in to the user's codex.cmd.
TestCodexPoolSaysTheClientsVersion then saw the installed 0.162.0 instead
of its fixture's 0.161.0, which is exactly what EdwinDigital reported. The
.bat is now written in StandIns, so every caller gets it.

TestStandInsComeBeforeTheInstalled puts StandIns("codex") on PATH first
and an "installed" codex (codex.cmd on Windows) that prints 0.162.0
further down. LookPath must pick the stand-in, and running it must fail
with no output.

Run:
- gofmt -l is clean.
- go vet passes for darwin, linux -tags nogui and windows (testenv and
  gateway).
- go test ./internal/testenv/ passes on macOS.
- Windows 11 x64 box (ssh), test binaries cross-built with Go 1.26.8.
  A fake codex.cmd printing "codex-cli 0.162.0" was on PATH.
  - The gateway binary before this change fails
    TestCodexPoolSaysTheClientsVersion with EdwinDigital's error (UA
    codex_cli_rs/0.162.0). The binary after it passes.
  - The testenv binary before this change fails the new test, and the one
    after it passes.
- Full gateway binary on that box, with its testdata copied (no source
  tree): the same failures before and after. They are source-reading tests
  that need the checkout, and TestClaudeAsRootEnv (#1827). The one
  exception is TestQueuedStreamKeptAliveForASlot, which failed once in the
  run after this change. It passes 5 of 5 alone on both binaries. Its cause
  is Windows' ~0.5ms clock tick in a strict Before (filed as #2249).
2026-10-15 02:36:26 +08:00
yetone bcd7881364 git: every text file checks out with LF, so a Windows checkout with autocrlf on doesn't turn four guard tests red (#1827, EdwinDigital)
TestEveryNoticeIsTranslated (agent), TestBuiltinsTranslated,
TestPurposeAssetMatchesUsage and TestRedactKindsAreRedacts (gui) parse
source files with LF-only patterns. Git for Windows' default
core.autocrlf=true checked those files out with CRLF, and all four
failed there; EdwinDigital found they pass from an LF checkout. A root
.gitattributes with `* text=auto eol=lf` makes every text file check
out with LF whatever autocrlf says. internal/agent/testdata's own
`* -text` still keeps its CRLF .cmd fixtures byte for byte.

The index already holds every text file with LF (git ls-files --eol:
the only i/crlf files are those two -text fixtures), so nothing is
renormalised.

Run: two --shared clones with core.autocrlf=true and a sparse checkout
of internal/gui/assets, notice.go and the mise-windows fixtures. At the
parent, i18n.js and app.js check out with CRLF; at this commit with LF,
snow.cmd keeps CRLF, and git status is clean in both. Not run: the four
guard tests on a Windows checkout (no Go on the Windows box); a
checkout made before this commit keeps its CRLF until the files are
checked out again, as in a fresh clone.
2026-10-15 02:36:26 +08:00
EdwinDigital 595b9a25bc gateway: WorkBuddy's own X-Conversation-ID names its session, so Routing groups its requests by conversation, not under No session ID (#2236, EdwinDigital)
WorkBuddy and CodeBuddy name their conversation in X-Conversation-ID,
which sessionHeaders didn't list, so every WorkBuddy request had no
session: Routing put them all under "No session ID", and affinity, usage,
transcripts, OTel and a remote magpie lost the conversation too. The header
is appended last, so the aliases already read keep precedence, and the
vendor is never sent it.

Moved users are covered by the same line: the gateway gives a plugin the
session as ConversationHeader from conversationID(), plugins.go passes it
as FetchRequest.Session, and the WorkBuddy plugin derives its own
X-Conversation-ID from that. No plugin change is needed.

EdwinDigital's record (Windows ARM64, Go 1.26.8, temporary HOME):
- Removing only the alias makes TestWorkBuddySessionHeader,
  TestWorkBuddySessionThroughGateway and TestRemoteMagpieKeepsTheSession
  fail. They pass with -count=20.
- gofmt and git diff --check are clean. Windows go vet ./... and Linux
  ARM64 go vet -tags nogui ./... pass.
- Installed WorkBuddy 5.8.2 (engine 2.161.0) ran against the patched
  gateway and a loopback streaming mock. Two native sessions grouped 2+1,
  with both titles resolved.

Review and run at this head (macOS, Go private cache, sandbox HOME):
- I read the patch line by line.
- The three tests pass. Commenting out the alias by hand makes all three
  fail.
- gofmt -l is clean. go vet passes on darwin, linux -tags nogui and
  windows.
- go test -tags nogui -count=1 -timeout 40m ./internal/gateway/: ok (811s).

Not tried by me: a real WorkBuddy or CodeBuddy client, and real vendor
calls. EdwinDigital ran WorkBuddy against a mock.
2026-10-15 02:36:26 +08:00
yetone 2bbe89bdba gui: the Requests tab's Agent name sits on the row's middle line, level with the time and model, not ~2px above them (#2237, duanckham)
The Agent cell's .who was inline-flex. Its first item, the agent icon,
holds no text, so the box took the icon's foot as its baseline and sat
that on the line's baseline, which lifted the name about 2px over the
Time and Requested cells. .who is now a flex block, which the cell
centres as it centres the time and the model.

New internal/gui/tests/usage-ledger-agent-middle.test.cjs: for a Codex
row with a route link (the reporter's), a Claude Code row and magpie's
own row with its badge, the name's text midline is within 1px of the
time's, the requested model's, the cell's and the icon's, and Status
stays level with the time. Chromium and WebKit, en/zh/zh-TW/ja/de, at
1100 (light) and 420 (dark). On the old CSS every case fails (name
~2.07px above the time); with the fix 22/22 pass.

Run: that file plus usage-ledger*, ledger-* and own-* GUI tests in both
engines (254/254), go test -tags nogui ./internal/gui/ (ok). CSS only,
no Go change, so no vet. Not tried in the real Wails window.
2026-10-15 02:36:26 +08:00
yetone 3d3a834d62 gateway: a held key its owner lets see quotas is told those of the providers and accounts it may use, not none (#2216, Kenoia)
#1981 refused every quota route to a gateway key held to a budget, models
or accounts, so a Remote magpie set up with such a key showed none of the
providers it may use. A key's owner can now let it be told them:
access.Key.Quotas, set from the key's new "Quotas" badge on the Gateway
page or `magpie gateway-key quotas <id> on|off`. Off stays the default,
so #1981's answer is unchanged for every key until its owner says so.

With it on, /v1/magpie/quotas (and ?kept=1), /quotas/history,
/quotas/cards and POST /quotas/refresh go through scopeQuotas
(internal/gateway/quotas_scope.go):
- a provider is told only when the key may use every model the catalog
  lists of it: a key with some of a provider's models is told nothing of
  it, since the models it may not use spend the same quota;
- of those, only cards of accounts and keys AllowsAccount lets it use,
  matched by the card's User against AccountIDs (a name two accounts
  share needs both; a card no account is known by only where the key's
  list names none of that provider's); a provider's only key's card,
  named by no one, is that key's;
- cards read from another magpie (From) are never told;
- a refresh of a card outside the scope is 403 gateway_key_held, one
  naming no card reads again only the scope's cards, not ReadAllCards;
- a scope with no card answers the cards routes 403 gateway_key_held, so
  the remote shows the key's own card rather than "nothing read".
/v1/magpie/concurrency and /v1/magpie/usage still refuse a held key.

Run at the reviewed head:
- gofmt -l: clean; go vet ./... (darwin), GOOS=linux -tags nogui,
  GOOS=windows: clean.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME, after the
  rebase onto 7be68467f (#2227's several limits; conflicts in access,
  the CLI usage and test, keys.js and providers-accounts.md resolved by
  keeping both): every package ok but internal/gateway, whose
  TestTranslatedSilenceStillTimesOut went red once at load ~95 (its
  400ms deadline also covers the response headers; filed #2248) and
  passed 5 of 5 alone. Before the rebase the whole suite was ok, with
  agent and gateway rerun at -timeout 40m after the 10m timeout under
  load.
- TestHeldKeyToldItsOwnQuotas (new): a provider-wide key sees A only,
  a key with A/m1 sees nothing of A, an account-held key sees only its
  key's card, a provider's only key, a key told nothing gets 403 from
  the cards route, Quotas-off still 403 everywhere, refreshes outside
  the scope 403. Broken by hand, each red: scope returned nil (every
  card told), every[id] forced true (partial models), the account check
  skipped, the refresh check removed, the only-key rule removed, and the
  told-none 403 removed. TestHeldKeyToldNoAccounts (#1981) still green.
- TestRemoteMagpieShowsHeldKeyItsQuotas (new): a magpie with this one as
  its Remote magpie provider, through a key held to alpha's Two, shows
  office/alpha's Two card beside the key's own; a key told none shows its
  own card alone. Red with the told-none 403 removed ("nothing read on
  that magpie yet").
- TestGatewayKeyQuotasCLI (new): show, on, off, bad values refused.
- GUI: gateway-key-quotas.test.cjs (new) in chromium and webkit, at 1100
  and 420, in en, zh, zh-TW, ja, de: 20/20; red when the badge sends the
  value it already has.
- The badge is a gateway key row's: off, it folds to no width until the
  row is hovered (the row had no room left at 390px: gateway-connect-keys
  went red in en until it did), and on a phone it is shown like the
  row's other controls (phone-rows went red until its rule won).
- GUI, 119 files matching gateway|key|usage|quota|remote|i18n|caller|
  web-|phone|narrow, both engines, concurrency 2: 1349/1385. The reds
  besides phone-rows (since fixed, above): quota-count-wrap and
  quota-name-translated webkit (#2228), usage-agents-hide (#2211) and
  usage-fold chromium en/zh (#2163), each red alike on a fresh
  origin/main. gateway-key-quotas, gateway-connect-keys, phone-rows and
  gateway-key-groups rerun: 38/38; after the rebase every gateway-*,
  phone-rows and key-limit file, both engines: 210/210.

Not tried: a real Remote magpie against a second machine with a held key;
the GUI badge in the Linux and Windows apps.
2026-10-15 02:29:11 +08:00
yetone f0f63bf6b8 provider: Zen's free models answer again: asked at opencode.ai/inference/v1, with stand-in tools that take a parameter, and without x-session-affinity (c9cu on Discord)
c9cu: "opencode muse 1.3 又不行了,magpie v0.1.1239". Zen's free tier moved and
tightened in mid-October 2026, found against the real upstream on 10-15:

- free models answer only at https://opencode.ai/inference/v1 (models.dev's
  opencode api is that URL now); OpenCodeFreeURL maps /zen/... there for a
  free model, never /zen/go or another host, in forwardOnce and the probe;
- the bash and read tools offered must each have at least one parameter:
  the stand-ins (zenfree.go, the probe) now carry OpenCode's own
  (OpenCodeToolSchemas);
- a request carrying x-session-affinity is answered 403 FreeTierError.
  OpenCode 1.19.0, captured through a forwarding proxy, sends Zen neither
  x-session-affinity nor X-Session-Id, so OpenCodeClient takes both out;
  the agent's own session id still names x-opencode-session.
  Bisected header by header: X-Session-Id, Accept and the UA version
  don't matter; x-session-affinity alone turns a 200 into a 403.

Live against the real Zen with the public key (a test file since removed):
muse via /v1/responses streamed (xhigh) and not, big-pickle on chat
streamed, mimo-v2.6-flash-free on chat: all 200; muse via /v1/messages 200.
The same code with x-session-affinity left in: 403 on every case.

Run: gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
-tags nogui on internal/provider and internal/gateway; the full
go test -tags nogui -count=1 ./... in a sandbox HOME, whose one red was
gateway's TestOpenCodeClientHeaders still expecting the two headers
(updated here), then internal/gateway alone again: ok (678s).
New tests TestZenFreeAtInferenceURL, TestOpenCodeFreeURL and the probe's
non-empty properties check fail on the old code.

The community plugin got the same fix in magpie-community/plugins 5fc0a75
(zen-free 0.1.7); its npm publish is blocked on the repo's publisher setup.
2026-10-15 02:25:17 +08:00
yetone 8e8316ed2f provider, gui: a routing group's pickers offer OpenRouter's decision models only as the provider's picks say (coeo91 on Discord)
coeo91 picked two free OpenRouter models, and a new routing group's member
picker showed those two and then a run of others. Those were OpenRouter's
decision models (liquid/d1, pplx-decider, jev-latest and the rest of its
output_modalities=decisions list): Deciders() took decideModels() for a
provider that lists its decisions (OpenRouter, oMLX, MLX-Serve), Bailian,
a remote magpie or a plugin, whatever its picks, while the provider editor
draws the same models as unpicked chips.

OfferedDeciders is what a group's pickers offer: with picks saved, only
the picked decision models plus any a group already names as a member or
classifier (so a group made before reads the same); with no picks, every
one, as before. /api/groups' deciders (member and classifier pickers),
the templates and the TUI's member picker use it. Deciders() is
unchanged, so the gateway still lists every decision model to a remote
magpie (X-Magpie-Deciders) and RouteDecider still answers an unpicked one.
docs/subsystems/providers-accounts.md says which is which.

Run in a private GOCACHE and sandbox HOME:
- the new TestOpenRouterDecidersOfferedAsPicked passes; with the pick
  filter turned off by hand it fails ("chat models picked, offered:
  [pplx-decider-v1-27b liquid/d1 jev-latest]").
- go test ./internal/provider -run 'Decide|Decider|OpenRouter|Template|
  RemoteMagpie|Bailian|OMLX|Omlx|MLX': ok.
- go test -tags nogui ./...: every package ok except internal/library,
  which hit the 10m timeout with the machine at load ~150 (stacks in
  mcpauth flow.end sleeps; nothing here touches library). Rerun alone
  at the same load with -timeout 25m: ok in 252s, 285 tests passed, the
  slowest TestAgentMCPFiles at 33s, so the 10m was the whole suite's
  load on this box, not a hang.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows;
  GOOS=linux -tags nogui and GOOS=windows builds.

After rebasing on origin/main 924f62e90: provider, gui, tui ok; gateway
ok alone with -timeout 28m in 1129s at load ~100 (it hit the 10m default
beside the other three packages; it passed in the full run before).

Not run: the Playwright GUI suite. internal/gui/assets is unchanged and
those tests mock /api/groups, so they can't see this server-side list.
Not tried against the real OpenRouter API or in a running GUI; the fake
OpenRouter serves its real decision-list shape.
2026-10-15 02:00:44 +08:00
yetone 7be68467f4 gateway: Claude Code's own "Prompt is too long" is a 400 that says whose check it was, not a 502 that reads as Anthropic's fault (#2162, iefnaf)
iefnaf's pi, on claude/claude-sonnet-5-5 through a Claude subscription,
was answered 502 "Claude Code: Prompt is too long" at about 176-180K
tokens of a 1M model, in 30-50ms, with no request id. That is Claude
Code's own check, not Anthropic and not magpie: Claude Code 2.1.299
refuses a conversation locally once its estimate passes its window
less the reply's room, and it clamps a 1M model's window to 200K for
the rest of the process once Anthropic has answered 429 "Extra usage is
required for long context" (its longContext1mCreditsBlocked latch).
200K less the reply's room and 3000 is about where the refusals sat.
A fresh API-key Claude Code against a fake upstream is refused only
near 990K, which is why it isn't the model's window. Lifting the check
(CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE) was tried and dropped: Anthropic
would then refuse the same request itself.

The bridge passed that error on as a 502, which a client reads as an
upstream fault. bridgeFailed now answers a status-less "Prompt is too
long" from Claude Code with 400, as Anthropic's own too-long answer
is, so writeError gives it context_length_exceeded and a routing group
offers the overflow to a member with a bigger window. The words a
client knows an overflow by stay first, and what follows says it was
Claude Code's check and what to do: compact, or turn on extra usage
for the Claude account. A run error with a status, or one about quota,
keeps its own, as before.

Run, on origin/main 2a99e7a42, and
again on 91b9065a5 for vet, gui, provider, tui, gateway, agent and
the tests named here:
- TestClaudeCodesOwnTooLongIsA400 (a fake claude answering
  {"is_error":true,"result":"Prompt is too long"}, Messages and Chat,
  streamed and not) is red without bridgeFailed, with the reporter's
  exact 502 body, and green with it. TestBridgeFailedKeepsOtherStatuses
  holds Anthropic's 400 and 429, a quota message, a plain error and
  another bridge's words.
- Claude Code 2.1.299's binary read for the check and the latch; a
  real claude -p in a sandbox HOME against a local fake Anthropic.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ./...;
  go build for the three; go test -tags nogui -count=1 -p 4 ./... at a machine load of 100-150:
  50 packages ok; internal/agent and internal/gateway ran past the 10m
  default under that load and pass with -timeout 40m (674s, 798s);
  internal/gui's TestSetAnswersWhileDevinAndProvidersHang failed once
  (a state took 10.4s; open as #1375) and the package passes rerun.
Not tried: the reporter's account, or a real 429 for long context.
2026-10-15 01:56:35 +08:00
yetoneandggbdpq f348025c09 gateway: a Chat or Messages client's interrupted tool call gets its synthetic result on the way into Responses, not the upstream's 400 "No tool output found" every turn (#2222, ggbdpq)
A Chat or Anthropic client whose turn was cut off (Esc, a dropped
connection, a crash) sends its history with a tool call no result
answers. buildChat and buildAnthropic each give such a call a
synthetic result (pairToolMessages, pairToolBlocks), but buildResponses
didn't, so a Responses upstream answered 400 "No tool output found for
function call <id>" on that turn and every turn after it.

ggbdpq's patch called pairToolItems on the body in forwardTranslated.
It is called at the end of buildResponses instead: that is where every
Responses body is built from a client's request, including Zed's
(zed.go builds through it and doesn't pass forwardTranslated). The
patch's tests are kept as written.

Run, on origin/main 2a99e7a42, and
again on 91b9065a5 for vet, gui, provider, tui, gateway, agent and
the tests named here:
- TestTranslatedToResponsesAnswersALoneCall is red without the
  responses.go change (the lone call_a goes into input unanswered) and
  green with it; TestPairToolItems*, TestResponsesRelay* and the Zed
  tests pass.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ./...;
  go build for the three; go test -tags nogui -count=1 -p 4 ./... at a machine load of 100-150:
  50 packages ok; internal/agent and internal/gateway ran past the 10m
  default under that load and pass with -timeout 40m (674s, 798s);
  internal/gui's TestSetAnswersWhileDevinAndProvidersHang failed once
  (a state took 10.4s; open as #1375) and the package passes rerun.
- The shape against ChatGPT's real Codex backend (gpt-5.6-luna, the
  owner's account, store false): a lone call is answered "No tool output
  found for function call call_a." and the same history with the call
  paired completes.
Not tried: a real interrupted Chat client end to end through magpie.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 01:56:35 +08:00
ggbdpq 05107bf03e tui: the library page keeps the row picked in view, however many section heads the window holds
What changed: viewLibrary sized its window from the row picked down in
rows (`start = lrow - visible + 3`), but the loop it feeds spends the
same budget in lines: every section head it crosses takes a line and
the blank before it, two the row count never paid for. With two or
more heads between the window's start and the row picked (servers,
then skills, then those found in the agents — a handful of each on a
terminal some thirty lines tall), the loop stopped above the row
picked: the highlight vanished, and j and down did nothing the screen
could see until the row count brought it back. The window now starts
where the lines to the row picked still fit, counted the way the loop
spends them.

Run: go test -tags nogui -count=1 ./internal/tui/ (the new
TestLibraryViewKeepsTheRowPicked is red without the change, watched on
a36319d6); gofmt -l internal/tui; go vet ./internal/tui/

Review (yetone, #2220): read line by line and kept as written. The
window's start is now counted in the lines the render loop spends, a
head and its blank line included, so it can't stop above the row
picked.

Run at the reviewed head, on origin/main 2a99e7a42, and
again on 91b9065a5 for vet, gui, provider, tui, gateway, agent and
the tests named here:
TestLibraryViewKeepsTheRowPicked is red with main's library.go ("row
21 (skill-10) picked, but the view stops short of it") and green with
the patch; go test -tags nogui ./internal/tui/ ok; gofmt -l, go vet on
three OSes, go test -tags nogui -count=1 -p 4 ./... at a machine load
of 100-150: 50 packages ok; internal/agent and internal/gateway ran past the 10m
default under that load and pass with -timeout 40m (674s, 798s);
internal/gui's TestSetAnswersWhileDevinAndProvidersHang failed once
(a state took 10.4s; open as #1375) and the package passes rerun.
Not tried: a real terminal; the test renders viewLibrary at 30 lines.
2026-10-15 01:56:35 +08:00
ggbdpq 7a6b101045 provider, gui: a login token beside sub2api's /v1/usage is told the panel's account query, not sent to the key's
What changed:
- balance.go: the guard that never sends a balance token to new-api's
  /api/usage/token (c9e47f043) now covers sub2api's /v1/usage too, and
  says to set <site>/api/v1/user/profile (Balance field $data.balance)
  or remove the token, as the new-api branch says its /api/user/self.
- gui: the editor's token warning (balanceFix) and the refusal wording
  (balanceError) each name sub2api's /v1/usage beside the token; two new
  strings in zh, zh-TW, ja and de.

Run:
- TestSub2APIKeyUsageWithLoginToken (new): a JWT beside /v1/usage is
  never sent there and the panel's account query is named; the key alone
  still asks. On upstream/main 2c18c697 it fails asked=true with the
  panel's raw 401 (the token went out as Authorization).
- TestKeyUsageWithAccessToken, TestBalanceKeyAsBearer and the balance
  tests unchanged; go test -tags nogui -p 2 -count=1
  ./internal/provider ok (71.9s). i18n-keys.test.cjs 3/3.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
  internal/provider and internal/gui; go build darwin, GOOS=linux
  -tags nogui, GOOS=windows.

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

Review (yetone, #2217): read line by line and kept, with one change in
the GUI. The editor's warning for a token beside /v1/usage offered both
/api/user/self and /api/v1/user/profile, but /v1/usage is sub2api's, so
only the panel's profile is offered now, and a saved "$remaining" (the
key query's field) gives way to $data.balance as the button sets the
URL. balance-fix.test.cjs gets a test for it (chromium and webkit, 440
wide): it is red on the patch's app.js ("only sub2api's account query
is offered") and on main's.

Run at the reviewed head, on origin/main 2a99e7a42, and
again on 91b9065a5 for vet, gui, provider, tui, gateway, agent and
the tests named here:
- TestSub2APIKeyUsageWithLoginToken is red with main's balance.go (ok
  true, the panel's 401 "invalid API key", asked true) and green with
  the patch.
- node --test balance-fix.test.cjs i18n-keys.test.cjs: 103 pass, 0 fail
  (chromium + webkit; the file's matrix is en, zh, ja, de at 900 and
  440; zh-TW strings are checked by i18n-keys only).
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ./...;
  go build for the three; go test -tags nogui -count=1 -p 4 ./... at a machine load of 100-150:
  50 packages ok; internal/agent and internal/gateway ran past the 10m
  default under that load and pass with -timeout 40m (674s, 798s);
  internal/gui's TestSetAnswersWhileDevinAndProvidersHang failed once
  (a state took 10.4s; open as #1375) and the package passes rerun.
Not tried: a real sub2api panel.
2026-10-15 01:56:35 +08:00
yetone f299faef48 gateway keys: a key holds several limits at once, every one must pass, and the 429 names the one that resets last (#2227, oxsean)
A key may now hold up to five limits, each in its own window (5 hours
and a week, say). A request needs every one: budget.Reserve checks
each, holds one reservation per window and settles each, and when some
are spent refuses with the spent limit that resets last, so
X-Magpie-Limit-Reset and Retry-After say when the key is really back.
Two limits in one window are refused (change that one instead).

Saved format: the first limit stays in "limit", which older magpie
reads, the rest go in "moreLimits". A file without moreLimits reads as
before.

- access: Change.Index adds (index = len), replaces (keeps its Since)
  or removes (nil) one limit; reset-limit-key with an index resets one,
  without resets all; the plain limit-key replaces all, as before.
- /v1/magpie/limit: "limit" is the binding one (what older clients
  read), "limits" is each. A remote key card shows a window per cap of
  each limit and falls back to "limit" from an older remote.
- CLI: magpie gateway-key limit <id> list | add <period> ... |
  remove <n> | reset [<n>]; the single-limit form still replaces all.
- GUI: the key's badge names the limit holding it most and "+N limit(s)",
  a line per limit under the row, and the editor has a tab per limit
  with Add a limit / Remove this limit. Strings in en, zh, zh-TW, ja, de.
- docs/reference.md and docs/subsystems/gateway-routing.md say so.

Run (worktree on e98440ae6, sandbox HOME):
- go test ./internal/access/ ./internal/budget/ ./internal/gateway/
  ./internal/cli/ ./internal/provider/ ./internal/gui/: all ok.
- gofmt -l clean; go vet darwin, GOOS=linux -tags=nogui, GOOS=windows
  on those packages: clean.
- GUI (Playwright 1.62.0) chromium and webkit: the new
  gateway-key-limits test (5 languages x 1100/420), gateway-key*,
  gateway-caller-keys, gateway-keys-off, gateway-own-key,
  gateway-connect-keys: 94/94; i18n-keys ok. quota-name-translated
  webkit en is red with HEAD's assets too, filed as #2228.
- Broken by hand, each went red: Reserve checking the first limit only;
  the refusal naming the first spent limit, not the latest reset; the
  endpoint without "limits"; every limit saved in moreLimits; duplicate
  windows allowed; the remote card ignoring "limits"; the CLI plain form
  adding instead of replacing; the GUI save without its index; the GUI
  badge taking the first limit.

Not tried: against a real remote magpie or real accounts. Known gaps:
two N-day cycle limits are both named "this cycle" on a remote card;
an older magpie that rewrites the keys file keeps only the first limit.
2026-10-15 01:54:28 +08:00
yetone a870fb2158 gui: with Reduce Motion the header is fitted to its tabs' real width, so no page scrolls sideways a few pixels (#2142, #1864, #2023)
The reduced-motion rule sets every element's transition-duration to .01ms
with !important. An element that declares no transition has the default
`transition: all 0s`, which that turns into `all .01ms`. So a header tab's
label span eased its font-size for one frame when fitTop() added crowded or
packed, and fitTop's synchronous measurement still read the old, wider
text (Chromium and WebKit both). It fitted the header to the narrower tabs;
a frame later the tabs came to 594px instead of 576, .actions poked past
the window, and the page's scrollWidth was over innerWidth. That is
usage-sum-whole's sideways overflow at 740-860px in de and ja, and what
real users with Reduce Motion saw.

Under reduced motion, anything that declares no transition of its own now
has transition-property: none, through :where() so it has no specificity
and any declared transition wins. Every transition in app.css declares its
property in a base rule (checked: no longhand-only declaration relies on
the default `all`), and no JS sets a transition duration. transitionend
listeners in app.js are on .ag-open, .agent-fold and .agent-hid-fold, all
of which declare theirs.

usage-sum-whole also counted a width as cut when the page's frames were
held past its 3s wait by a busy machine ("1220px: " with nothing after
it). It now looks again once the wait ends, and a redrawn cost with no sum
in it yet isn't read as a cut one.

Run:
- usage-sum-whole: 3 runs x 8 cases, 24/24 pass. Without the app.css
  change, 6/8 (de and ja overflow at 780 and 850-860). With a 3.5s busy
  loop injected at 1220px: 8/8 with the new wait, "1220px: " in every
  language with the old one.
- Full GUI suite (chromium + webkit, all languages and widths the tests
  carry) with the change at load ~300: 9335 tests, 127 failing in 30
  files. Every failing file was rerun alone on this tree and on
  origin/main 2c18c697c side by side: routing-wb-restricted, rest-try-now,
  routing-failed-open, routing-days-fit, search-instead,
  routing-agent-hue-not-red, routing-side-calls, routing-agent-gone,
  usage-agents-hide, refusal-retries-setting, purpose-filter,
  routing-context-fold, sidebar-overlay-scrollbar, login-import,
  library-servers-bulk fail the same on main (filed: #2211, #1905, #2115,
  #1863, #1307, #1537); the plugin-*, bare-ids, agent-update-all,
  library-chip-fan, model-copy-id, model-id-space, group-duplicate,
  usage-fold, usage-alert (a SIGSEGV), switch-only and tray-cell-click
  failures came and went on both trees under load, and pass alone.
- Rebased on origin/main 91b9065a5 (Routing and Usage as plugin pages):
  usage-sum-whole 4/4 runs whole with the change, and 1 of 3 runs on
  91b9065a5 without it still overflows (webkit ja 740px: 748 wide).
- An attempt to observe #nav in topFit's ResizeObserver was rejected: it
  refit ~40 times a second at 780 and 860 in de and ja.

Not tried: a real WKWebView window with macOS Reduce Motion on; the
usage-checkin (chromium zh) and settings-proxy-auth (webkit zh) flakes
named in #2142, which this doesn't touch.
2026-10-15 01:52:33 +08:00
yetone 91b9065a5f gui: the window's core scripts have a size budget, so a page can't grow back into it (P2)
TestCoreScriptBudget adds up the scripts index.html loads that aren't a
plugin's (assets/plugins/<id>/) or the words (i18n.js): app.js may weigh
1,215,000 bytes (1,198,239 now Sessions, Library, Routing and Usage are
plugins) and the core 1,377,000 (1,358,034), about 1.4% room. A change that
needs more raises them and says why in its commit. boot.js, made by the
server, isn't on disk and isn't counted.

Run: go test -run TestCoreScriptBudget ./internal/gui ok. Broken by
hand: with the app.js budget at 1,190,000 it fails naming app.js's bytes,
and with plugins/usage/page.js counted as core it fails on the total
(about 1.5 MB).
2026-10-15 01:32:13 +08:00
yetone 3c7ec4ba24 gui: Usage is a plugin's page, its code, markup and words in plugins/usage (P2)
P2 of docs/subsystems/plugin-runtime.md, the fourth page after Sessions,
Library and Routing, and the largest part of app.js.

- The Usage page's code (~3000 lines: the Overview's cards, the
  Requests ledger and heatmap, the Sessions tab, the Agents list) moves
  from app.js to assets/plugins/usage/page.js; its markup, index.html's
  <main id="view-usage">, is client.js's part html. app.js 25756 →
  22675 lines (1,355,376 → 1,198,239 bytes).
- page.js builds on app.js at the top level (its timers, ?view=usage's
  tab and filters), so it is the one plugin script that loads after
  app.js. index.html: kernel.js, the plugins' other scripts, app.js and
  the scripts beside it, each page.js, then start.js, which is app.js's
  old tail (magpie.start(), navHides, OPEN_VIEWS, the first page shown,
  load()), so the first page has its code. TestBuiltinClientsLoaded
  holds that order.
- Hooks: open loads it, refresh(again) is load()'s read of it, reload is
  Refresh now, costs redraws costs on a currency change, tab says the
  tab for focusQuotaCard. app.js calls those through magpie.call. The
  allowance cards, quotasOpened, panelQuotaFocus and panelUseFocus stay
  in app.js: the tray panel draws them too.
- plugins/usage: Essential, Requires window, no InUse. Off, its nav tab
  goes and so do the ways to it (data-feature="usage": the panel's Open
  Usage, Routing's View usage); show("usage") gives way to Agents; the
  panel's Allowances tab stays. builtins.test.cjs switches it off and
  checks each.
- The 173 strings only Usage says move to plugins/usage/i18n.js;
  i18n.js 15032 → 14344 lines. "{n}s" and
  "All sessions" stay: context.js says them too since #1591.
- context.js: with context.js now in before the first page is shown,
  the page's open and load()'s first refresh both reached loadContext,
  and the second drew "Reading…" again over the advice the first had
  just drawn, so its curves never played their entrance (context-tune,
  3 of 3 red). loadContext draws the waiting pane once for the same
  days. Its dead last line, which loaded the tab once context.js came
  in late, goes.
- context-window.test.cjs's "arrives after the state" becomes "loads at
  once though context.js is slow": start.js now waits for it.
  usage-stale-answer reads page.js beside app.js. quota-refresh-order
  (#1630) cut app.js at the period picker's comment, now in page.js; it
  ends at the next comment that stays (5 of 5; without keepRefreshedQuotas'
  call, 2 of 5 red).
- docs: plugin-runtime.md, gui-shell.md.

Run, at this tree on origin/main af27b70b4 (main's keepRefreshedQuotas
and quotaRefresh changes, #1630, stay in app.js beside loadQuotas: the
tray panel draws those cards too):
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- go test -count=1 ./internal/gui ./internal/pluginrt ./plugins/...: ok
  (-skip TestMainWindowCorners, #1936); gateway and usage as above.
- usage-card-refresh, quota-refresh-order, builtins, editor-picker-clicks,
  context-window, usage-stale-answer: Chromium and WebKit green.
- The full GUI set: see the Routing commit; every Usage red there is the
  same on main or red only under load.
2026-10-15 01:32:13 +08:00