Commit Graph
5101 Commits
Author SHA1 Message Date
yetone b2d005bf38 gateway: a MiniMax API key makes videos with H3 (_tigerqueen_05867)
A MiniMax API-key provider (api.minimax.io, api.minimaxi.com, api.minimax.cn)
now lists MiniMax-H3, -H3-Highspeed, -H3-Lite and -H3-Max as video models.
They are never in chat lists. generate_video and /v1/videos start a task at
<host>/v2/video_generation, poll /v2/query/video_generation/<id> and hand back
the MP4. The prompt, seconds (raised to each model's minimum and capped at
15), resolution (from Extra or size, clamped to the model), ratio, first and
last frame and up to 9 reference images go through. /v1/videos now reads
last_frame; MiniMax and a remote magpie pass it on, other videomakers
ignore it. The MCP schema is unchanged.

Failures say which one it is: a turned-away key (1004/2049/401), no
pay-as-you-go balance (1008/402), refused input or output (1026/1027), a
Token Plan key without H3 (2061/2068/2057, which moves on to the next key),
or the rate limit. AutoVideomaker puts MiniMax last, so generate_video,
which has no model argument, uses MiniMax-H3 only when nothing else makes
videos. All of it is gated on a MiniMax host, so no other vendor changes.

Run on mote at 798c8fd48 (base a0ba8e1f2). The pushed head's only other
change is fb5959553, one test file in internal/usage, which none of these
packages import:
- gofmt -l: nothing listed.
- go vet ./... (darwin), GOOS=linux -tags nogui, GOOS=windows: ok.
- go test -tags nogui -timeout 45m ./internal/gateway ./internal/provider
  ./internal/imagemcp: ok (gateway 557s, provider 95s, imagemcp 6.5s).

The fake server answers with the literal samples from MiniMax's docs (create,
succeeded, failed 1026, 401, 402, 422), plus a task stuck past the timeout.

Broken by hand, each watched go red:
- no Videomakers hook (the old code): TestMiniMaxKeysMakeH3Videos,
  TestMiniMaxH3IsNoChatModel, TestImageMCPMakesMiniMaxVideos.
- minimaxWhy returning "": TestMiniMaxVideoFailuresSayWhy.
- MiniMax not put last: TestMiniMaxComesAfterOtherVideomakers.
- no move past a Token Plan key: TestMiniMaxVideoMovesPastATokenPlanKey.

Not tried:
- the real MiniMax API: no MiniMax key is on this machine. The bodies follow
  the docs' samples only.
- the GUI: nothing changed there (it lists no video models per provider).
- test runs on Windows and Linux; vet only.
- last_frame from the MCP tool, whose schema doesn't take it.
2026-10-29 04:56:46 +08:00
yetone fb59595530 usage: TestClearedUsageLeavesThePages leaves no clear behind for the next test
The test ends by clearing everything up to now. readCleared keeps what it
read in clearedAs, and a test that builds a page straight from chunks
(buildRequestBlocksWithCodex) never reads the clears again, so it judged
its rows by that stale clear and hid them all: with
-run "Heatmap|Pair|Scratch|Request|Page", TestCodexRequestPageDoesNotMutateSharedCompactionChunks
(3 subtests), TestCodexRequestPageFoldsCopiesBeforeResponseMatching and
TestRequestDiskNamesItsSource failed on origin/main 49d4d0f7a ("page rows
= 0"). Bisected to this test as the only polluter. The full package's
order happened to put them before it. The test now drops clearedAs when
it ends.

Run on mote at this head (rebased on a0ba8e1f2):
- go test -count=1 -run "Heatmap|Pair|Scratch|Request|Page" ./internal/usage: ok
  (red without the cleanup, as above)
- go test -count=1 -timeout 45m ./internal/usage: ok
- go test -count=1 -timeout 45m ./internal/usage: ok
2026-10-29 04:44:43 +08:00
yetone a0ba8e1f2e grok: each model's context_window follows Long conversations, and one set by hand stays through a sync (uk.jent)
uk.jent (Discord #feedback) reported that magpie writes every Grok Build model's context_window as the model's whole window. They wanted about 300K without editing dozens of models, and they lost hand edits on each sync, because SetTOMLTables replaces the [model."magpie/..."] tables whole.

Grok Build now uses Long conversations, the mechanism Codex and Claude Code already use. grokWindow gives:
- min(window, Compact) when the model or provider has its own threshold;
- otherwise settings.Working(window): 272K by default on longer windows, the typed size, or the whole window with Full context.

What magpie wrote is stashed under grok:<path>:windows, and grokOwnWindow uses it to tell a hand edit apart:
- A value that differs from what magpie last wrote is the user's, and it stays.
- In a config written before the record, a value other than the model's whole window is the user's.
- Disconnect forgets the record.

The agent sheet's Long conversations row now shows for Grok Build (AGENT_PREFS). Its texts, the provider editor's hint, the Context tab's note and `magpie model compact` now name Grok Build, in en/zh/zh-TW/ja/de. setCompact and setAsync now share prefWrite. That dedupe keeps app.js under its budget, which is not raised.

Behaviour change: a Grok Build model whose window is over 272K now gets 272K by default, as Codex does, unless Full context is on.

Run on mote, at this head (c893c2229, rebased on fe05f0a72):
- gofmt -l: 0 files.
- go vet ./internal/{agent,gui,cli,settings}: darwin, plus GOOS=linux and GOOS=windows with -tags nogui. All ok.
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gui ./internal/cli ./internal/settings: all ok.
- GUI agent-prefs, compact-at, compact-one-value, context-tune, context-window, gateway-mode, i18n-keys, settings-general: 202/202 in Chromium and WebKit. The new cases cover Grok's sheet in five languages at 1100 and 440, and in the 360 panel.
- At the pre-rebase head, 104 GUI files the change can reach: 1590/1622.
  - 29 of the reds were browserType.launch timeouts at load 85. Run again one at a time, every one passed, and so did usage-fold.
  - context-map's WebKit 420px "two tiles overlap" is red on origin/main fe05f0a72 too, run alone. It is recorded on #3488.

Broken by hand:
- With the keep logic removed, TestGrokKeepsAWindowSetByHand and TestGrokKeepsAWindowSetBeforeTheRecord go red ("pro 1000000 (set by hand to 300000)").
- With grokWindow returning the whole window, TestGrokKeepsAWindowSetBeforeTheRecord and TestGrokWindowFollowsLongConversations go red ("compact at 300K: pro 1000000").

Not tried:
- A real Grok binary reading the written config. Grok 1.0.67's own help documents model.<id>.context_window as driving auto-compact.
- Linux/WSL and Windows runs. Only cross-OS vet was run.
- Grok App still writes the whole window, and neither agent writes the context_windows choice list: #4117.
2026-10-29 04:43:22 +08:00
yetone 49d4d0f7ab usage: the request matcher keeps its maps for the next call, and gives them back once the window rests (#2278)
Every poll while an agent works matches a year's history again:
matchedBlocks and codexChunkResponsePairs grew their maps (byID,
reserved, used, groupOf, picks, picked, ...) and slices from nothing on
each call. They were ~3.0 GB of the ~40 GB a poll-heavy 80 s allocated
on the real-history harness (d1951 heap diff, 120 s to 200 s).

A sync.Pool was tried first and kept nothing in real use: under
tightenGC a poll collects 4-5 times a second (1029 GCs in 230 s), each
collection empties the pool, and the matcher's flat allocation went
only from 2241 to 1840 MB. So one scratch of each is kept in an
atomic.Pointer, emptied after a call (clear() keeps the maps' buckets,
and drops every chunk the call saw), and let go by usage.ReleaseScratch,
which releaseIfPagesRest calls before FreeOSMemory: once the window's
reads have rested 3 s, what the matching kept goes back with the rest.
A call that finds the scratch taken makes its own, sized as before.
matchedBlocks' result map is now made once the id matches are known,
not grown from the response pairs alone.

Measured on mote (Apple M5 Pro), at aeacc6358 + this change:
- BenchmarkPairRows (2000 files x 100 calls), -count 3: 100.8 MB/op,
  7,056 allocs/op at aeacc6358; 48.4 MB/op, 5,458 allocs/op after.
- Real history (copy of the user's usage.jsonl, sandbox HOME, polls +
  appended calls, run2278d.sh 230 s), heap alloc 120 s to 200 s:
  matchedBlocks flat 2241 -> 1295 MB, codexChunkResponsePairs flat
  806 -> 143 MB, of a total about the same (39.8 vs 39.3 GB). That run
  was before the result-map change. Its CPU and peak RSS (974 MiB vs
  936) aren't comparable: mote's load went from ~25 to 50-88 from other
  sessions during it.

Tests:
- New TestPairScratchKeepsNothingBetweenCalls (pairRows on one history
  after another matches what a first call does; ReleaseScratch lets go)
  and TestMatchScratchForgetsTheLastCall (a gateway call one call used by
  id or reserved by a response pair is matched in the next; ids the last
  call looked up in another gateway aren't).
- Broken by hand, each red: without clear of byID (index out of range),
  used ("the last call's id match held the gateway's call"), reserved
  ("the last call's response pair held"), groupOf and picks (index out
  of range). ids, named and picked only choose which chunks are opened,
  so a stale entry there costs a read, not a match.
- go test -count=1 -timeout 45m ./internal/usage/ ./internal/usageapi/
  ./internal/sessions/ ./internal/gui/ at aeacc6358 + this change: usage,
  usageapi, sessions ok; gui red in TestMainWindowCorners/macOS_26_SDK
  alone, mote's macOS 27 (#3949). An earlier gui run there had ten
  AppKit window tests killed at their 20-40 s deadlines at load ~40-88
  (#2645).
- GOOS=linux, windows, darwin go vet -tags nogui ./internal/usage/
  ./internal/gui/ ./internal/usageapi/: ok.

Rebased onto origin/main fe05f0a72 (library and Claude-account changes,
nothing in internal/usage or page_memory.go); after the rebase
./internal/usage/ and ./internal/usageapi/ ran again at the pushed
tree: ok, and go build . ok.
2026-10-29 04:33:14 +08:00
yetone fe05f0a721 library: a skill can be turned off on this computer alone, and a sync neither carries that nor turns it on
hanslin1666 on Discord (#general 1565016936344191096) wanted a library
skill off on one computer only ("只在这台电脑上关掉"). The only way to do
that was to untick its agents, and the ticks are what a sync carries, so
every other computer lost it too. A sync from a computer that had it on
also gave it back here.

Skill.OffHere (library.json "offHere", omitempty) turns a skill off on
this computer. No agent here gets it, whatever Agents says. Every reader
that gives a skill to an agent now asks gives():
- syncSkills, including the shared ~/.agents/skills check;
- desktop_skills.go;
- skill_changed.go;
- skill_edits.go;
- behind;
- Targets.
Agents stays what a sync carries, and the page shows those chips faded.

Collect never carries OffHere, so turning a skill off changes no part a
sync uploads. Put keeps this computer's OffHere for a skill it puts, so
a sync from a computer that has it on (or that gives it to more agents)
leaves it off here.

Where to turn it off:
- GUI: a power button on the skill row (aria-pressed). When off, an
  "Off on this computer" tag sits on its own line under the name; it
  says why and turns the skill on when clicked.
- CLI: `magpie library skill off-here|on-here <name>`.
- TUI: the row says the skill is off.
The strings are in en, zh, zh-TW, ja and de.

Existing users: nothing changes. An older library.json has no offHere,
so every skill stays on, and a skill that was never turned off writes no
key (TestSkillOffHereOldLibraryIsOn).

Not covered:
- a project's skills;
- a library skill whose own folder is inside ~/.agents/skills, which
  agents read in place;
- a skill another computer removes (the flag goes with it).
The skill's files in the library folder still update while it is off.

Docs: docs/subsystems/library.md and sync-backup.md.

Run at the parent aeacc6358 (rebased on origin/main), on mote:
- gofmt -l: clean.
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go
  vet ./...; go build ./...: ok.
- go test -tags nogui -timeout 45m ./internal/library ./internal/davsync
  ./internal/cli ./internal/tui ./internal/gui ./internal/backup: all ok.
- GUI, Chromium and WebKit:
  - skill-off-here: 22/22 (en, zh, zh-TW, ja, de at 860 and 400px).
  - i18n-keys, gui-ja, gui-de, gui-zh-tw, library-items, library-mcp-hub,
    library-all and library-toggle-status: green. The first try timed out
    in browserType.launch (mote at load ~60); run again one file at a
    time, they passed.
  - library-row-remove: Chromium red in the hooks part, 2 or 3 of 11
    each run. It is red the same way on origin/main aeacc6358, 3 of 3
    runs there too (#3099); this change doesn't touch hook rows.
- Before the rebase, at e5e2aa58e plus this change: the 98 GUI files
  that reach the library page (1350 tests). 68 reds, nearly all
  browserType.launch timeouts under load; run again one file at a time,
  all passed except mobile-web's "desktop matches origin/main"
  subtests. Those need .git, which mote-run doesn't copy.

Then rebased onto ec3dad75a, which changes no library file. At this
pushed head: go build ./..., go vet of library and gui, the gui Budget
tests, and i18n-keys plus skill-off-here in both engines (26/26), all
ok.

Broken by hand (restored afterwards):
- Put dropping OffHere:
  - TestSkillOffHereStaysHere:96 failed: "a sync from a computer with it
    on gave pdf to an agent here again".
  - TestSkillOffHereThroughSync:108 failed: "a sync from A, with pdf on,
    gave it to an agent on B again".
- gives() ignoring OffHere: TestSkillOffHereStaysHere:74 failed: "off
  here, claude still has pdf".
- The GUI test fails on the old code, which has no button.

Not tried:
- no real WebDAV or GitHub backend (the sync test uses the fake S3);
- no real app run with real agents;
- no Windows or Linux test runs (only GOOS=windows and GOOS=linux vet);
- not the whole GUI suite, only the 98 files that reach the library page,
  the i18n checks and gui-ja, gui-de and gui-zh-tw.
2026-10-29 04:23:33 +08:00
yetone ec3dad75ae provider, gateway, gui, cli: Claude's accounts can be kept to Claude Code's own sign-in, magpie serving nothing on them (myduso)
myduso on Discord asked for an exclusive mode on Claude's subscription:
switch the credentials locally and proxy no traffic, since Claude Code
is used on its own and the SDK run magpie's bridge makes spends more of
the allowance than the interactive client.

The switch-only setting Codex has (#1907) now also takes claude. On it,
Provider.KeptToAgent is true and On() false, so the gateway, catalog,
groups, fallbacks, search, draw and embeddings serve nothing on the
Claude accounts, and a request naming them is refused 404 saying they
are kept to Claude Code's own sign-in and how to undo it (switchedOff).
Switching Claude Code's sign-in when an account is used up, and reading
usage, go on: both are gated by leftAlone on the raw Off, which this
doesn't set. Groups magpie found keep their Claude members
(heldOffEntries). Nothing is sent as Claude Code: magpie only writes and
restores Claude Code's own credentials as it already did.

GUI: the tick under Claude's accounts, shown with one account too, drawn
by the block Codex's tick had (one block now, its strings picked by
agent). app.js stays under its budget with no raise (1,311,711 of
1,311,735). CLI: magpie accounts switch-only <codex|claude> [on|off].
Docs: reference.md, subsystems/providers-accounts.md.

Run on mote at this tree on 06950fbbb; then rebased on aeacc6358 (two
app.js comments shorter) and go test -run TestCoreScriptBudget ./internal/gui
run again at the pushed head: ok.
- gofmt -l internal: clean. GOOS=linux go vet -tags nogui ./internal/...
  and GOOS=windows go vet ./internal/...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/gateway ./internal/cli ./internal/gui: all ok.
- node --test (Chromium + WebKit, every language the file covers):
  claude-switch-only (new), switch-only, keep-login, i18n-keys, gui-ja,
  gui-de, gui-zh-tw: 85 of 93 in one run beside other sessions' full GUI
  suites (load 23-73); the 8 reds (claude-switch-only chromium en/zh,
  gui-de and gui-ja in both engines) were not captured, and those files
  then passed alone twice (35 of 35 each run).
- Earlier, at ecbd694a2 (on ddf31ca30): internal/agent ok; add-sheet,
  api-key-usage pass; account-models and account-proxy 40/40 alone after
  8 browserType.launch timeouts at load 40-70 from other sessions.

Broken by hand, watched red:
- On() without the KeptToAgent term: TestClaudeSwitchOnlyServesNothing-
  AndStillSwitches and TestClaudeKeptToClaudeCodeServesNothing fail (the
  gateway ran Claude Code through the bridge, 200).
- SetSwitchOnly refusing claude: both fail.
- app.js without the claude branch: claude-switch-only 16/16 red in
  Chromium, switch-only (Codex) 16/16 green.

Not tried: real Claude accounts or a real Claude Code (the switch itself
is the existing path, tested with a fake claude in a sandbox HOME); the
whole GUI suite (only the files that open Claude's or a provider's
editor, plus the i18n ones); Linux and Windows test runs (vet only).
2026-10-29 04:15:56 +08:00
yetone aeacc6358a gui: app.js back under its budget after 06950fbbb landed on f00407200
f00407200 set app.js's budget to its own size (1,311,735), and
06950fbbb, rebased onto it, added 11 bytes net, so TestCoreScriptBudget
went red on main. Two of 06950fbbb's own comments are shorter; no
raise. app.js is 1,311,732.

Run (mote-run): go test ./internal/gui -run TestCoreScriptBudget: ok.
Comment-only change; nothing else run.
2026-10-29 03:46:24 +08:00
yetone 06950fbbbb gui: Codex's two subagent settings say which is the default and which holds every subagent
HoGee_xxl on X read Codex's "subagent model" as the default for a
subagent the lead names none for, and found every subagent held to it.
The two read alike ("subagents" / "subagent model"), so each now says
what it is, in en, zh, zh-TW, ja and de. Wording and notes only:

- subagent model, unset: the lead picks each subagent's model, one it
  names none for runs on the lead's model, a resumed subagent stays on
  the model it started on, and a pick here holds every subagent even
  when the lead names another.
- subagent model, set: every subagent on it even when the lead names
  another; Same as the lead gives the pick back.
- subagents (Codex's default_subagent_model): the model a subagent
  starts on when the lead names none; the lead may still name another.
- Codex's settings row "Codex subagent model" shows that line as a .sub
  note under its name, as the rows beside it do, not only on hover (the
  empty note is in index.html).

app.js stays under its budget with no raise (1,311,673 of 1,311,681):
the comments beside these strings were condensed.

Run (mote-run, Chromium and WebKit, every language):
- node --test codex-subagent-model, codex-subagents-lead, i18n-keys,
  codex-memories, codex-memories-settings, codex-start-model-field,
  context-tune, gateway-mode, subagent-effort, agent-tweak-fold,
  claude-auto-mode, claude-subagent-effort-row, claude-subagents-pick,
  desktop-subagent-model: 227 of 248 ok on the first run; 20 reds were
  "browserType.launch: Timeout 180000ms" with mote at load 71 and 43
  Chrome processes from other runs, one a desktop-subagent-model zh
  420px routing wait. The five files with reds, rerun one at a time:
  76 of 76 ok.
- After the budget trim: codex-subagent-model + codex-subagents-lead
  40 of 40 ok (concurrency 1; at concurrency 2 under load 52 the first
  chromium en case of each was red, #2645's class), i18n-keys ok.
- go test ./internal/gui: TestCoreScriptBudget ok. AppKit window tests
  killed at their deadlines at load 71-105 (#2645) pass rerun, except
  TestMainWindowCorners/macOS_26_SDK, red the same way on origin/main
  e0ea15b8e (#3949).
Not tried: the real app's Settings sheet.
2026-10-29 03:45:57 +08:00
yetone 25bf394a72 gateway: a resumed Codex subagent goes back on the model it was spawned on
HoGee_xxl on X: a Codex subagent brought back with resume_agent ran on
the lead's model, not the one the lead spawned it on.

Codex's multi-agent V1 (the one magpie's own models ask for) builds the
resumed subagent's config from the lead's current turn:
codex-rs core/src/agent/child_config.rs build_agent_resume_config ->
build_agent_shared_config sets config.model to turn.model_info().slug,
and core/src/agent/control/spawn.rs resume_single_agent_from_rollout
starts the thread on that config without reading back the thread's
stored model. Neither the spawn_agent model nor [agents]
default_subagent_model is asked again. V2's ensure_v2_agent_loaded does
put a thread back on its stored model, so this follows Codex's own rule.

The gateway now notes the model each Codex subagent thread (thread_id in
x-codex-turn-metadata / client_metadata; session_id only on a Codex old
enough not to share it) first asked for, and puts a later request of
that thread asking for another back on it. Kept in codex-subagents.json
beside providers.json (0600, temp file and rename, the 512 latest, 30
days), so a resume after a restart is known. A model set for every
subagent (codexSubagentPick) still wins. No prompt or base_instructions
is touched.

Run (mote-run): go test ./internal/gateway -run 'TestCodexResumed|
TestCodexSubagentThreadOf|TestCodexSubagent|TestCodexFollow|
SessionMetadata|TestCodexSide' -count=1: ok.
Broken by hand: skipping the restore in codex_backend.go turns
TestCodexResumedSubagentKeepsItsSpawnModel red ("worker-1 asking gpt-5.5
went on gpt-5.5, want gpt-6-astra"); skipping the save turns its
after-restart step red.
Not tried: a real Codex resume_agent run against a real ChatGPT account.
2026-10-29 03:45:57 +08:00
yetone f004072007 agents: More in Plugins is in sight with Install another agent folded
The owner: 插件中还有更多,不应该折叠在安装更多Agent里. e8e9245ec put the
row naming the agents Plugins has at the end of Install another agent,
inside its fold, so with the commands folded (as they are once any agent
is here) nobody saw it. It now follows the section whether that is
folded or open, 6px under the header; the header counts the install
commands only, and with no command left the row stands alone with no
header over it.

Budgets: app.js 1,311,735 and the core 1,530,861 (+54 each), no room
added.

Run at this head (rebased on ddf31ca30), on mote:
- agent-plugin-agents, agent-cli-missing, agent-prefs, agent-stale-copies,
  agent-tweak-fold, agent-unreachable, agent-update-all,
  agent-visibility-saving, click-scroll, page-width, page-width-steady,
  i18n-keys, one file at a time, both engines and the files' languages:
  294 of 297, the 3 reds a chromium launch timing out at 180s and one
  zh-TW 420 click waiting for the header under load 95; those two files
  run again alone: 54 of 54.
- An earlier run of every agent-* file plus those, 4 at a time at load
  100, timed out in 36 places across the files above; the run above is
  the record.
- go test ./internal/gui -run Budget: ok.
Broken by hand: with the row back inside the fold,
agent-plugin-agents goes red in every language and width.
Not tried: the real app on Windows and Linux.
2026-10-29 03:44:36 +08:00
yetone 06469694b7 usage: pairing a poll's calls allocates 40% less, in a few slabs (#2278)
Under polls, with calls coming in, GC was ~35% of magpie's CPU and
madvise another 16%, both driven by how much a poll allocates. The
pairing that the heatmap and every page run did most of it: in an 80 s
heap diff on a year's history, matchedBlocks allocated 3.2 GB and
codexChunkResponsePairs 2.6 GB.

- matchedBlocks: a match key holds a call or two, so each key's ends
  and range counts were two slices of their own. They are now one ends
  slab and one counts slab, a group an offset into them, and groupOf is
  made the size of the calls it keeps. The candidates and unique maps
  are a slice and a []bool over slab positions.
- codexChunkResponsePairs: picks and their slab are made the size of
  the gateway's response ids, and a gateway call is judged from its
  packed strings (codexGatewayCall) instead of being made a whole Row.

What a call pairs with is unchanged.

BenchmarkPairRows (new; 2,000 session files of 100 calls, half Codex by
response id, half Claude Code by session and tokens), on mote:
  e0ea15b8e: 170,154,300 B/op, 208,673 allocs/op
  this:      100,846,208 B/op,   7,056 allocs/op
(ns/op isn't comparable: mote was at load 20-35, both ~0.7-1.0 s/op.)

Not yet measured: the poll-and-feed A/B against a real build on mote
(load 86 from other runs); its numbers go on #2278.

Run at this head on mote: go test ./internal/usage ./internal/usageapi
ok; go test ./internal/sessions ok; ./internal/gui: TestMainWindowCorners/
macOS_26_SDK red only, #3949 (macOS 27 AppKit, untouched here); go vet
-tags nogui ./internal/usage/... ./internal/gui/... ./internal/usageapi/...
for linux, windows and darwin ok.

Broken by hand: the counts slab without the group's +k offset (groups'
range counts overlap) failed TestIndexedExportMatchesExhaustiveOracle,
TestRequestMatchIndexEquivalent, TestMatchOpensOnlyNamedChunks and
TestCodexCacheWriteMatchesGatewayCall; codexGatewayCall taking a
rejected call failed TestCodexRejectedGatewayDoesNotPairWithNativeCall.

Not run: the full ./... suite.
2026-10-29 03:40:18 +08:00
yetone e0ea15b8e8 library: an MCP hub, one magpie server in place of every library server (#2679)
With Library → MCP → "MCP hub" on (off by default), each agent that takes
an MCP server over HTTP is given one entry, magpie, at
/mcp/magpie/hub/<agent>, in place of the library servers ticked for it.
magpie runs those servers itself, once for every agent: a command starts
on its first call and ends after 10 idle minutes, a URL server is reached
with its headers and MCP sign-in. Tools are <server>__<tool>; a tool off
in the library is neither listed nor run. Any other app connects at
/mcp/magpie/hub, which serves every library server. Both are guarded as
/mcp/magpie/tools is (local or a gateway key, no foreign page, 4 MiB,
the key's limit per call). An agent that reaches no server over HTTP
(Claude Desktop), has a magpie entry of its own, or sits beside a library
server called magpie keeps each server's own entry, and the page says why.
Off gives every agent its servers back and ends every process the hub
started.

GUI: a switch under the MCP list, a line of what it serves, the address,
and a Connect… sheet. The sheet lists every agent magpie detects that
takes MCP (not a fixed four), each with where it stands; one given none of
the hub's servers has a Connect that ticks it for every server it can
reach (servers/agents-all), so it gets the entry, and the sheet stays
open. Then any other app: Cursor (when it isn't a detected agent), VS
Code, Other, with the JSON and, in the app, "Add to …" through the app's
own install link built in Go (servers/hub-open; the page never sends a
link). CLI: magpie library mcp hub on|off. Design: docs/subsystems/mcp-hub.md.

With #3885 (62045475b): with the hub on, Codex is given the one magpie
URL entry, and the servers behind it never reach runVia, which takes a
command server only; with the hub off Codex gets /mcp/run/<name> as before.
Rebased onto it; the one conflict was both commits declaring base in
syncMCP.

Run:
- At 62045475b + this (the pushed tree), on mote: gofmt -l, go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui clean; go test
  -timeout 45m internal/library (108s), gateway (510s), cli (50s) ok.
  The GUI files and internal/gui weren't run again: 62045475b touches
  neither, and the rebase changed nothing in them.
- At ddf31ca30 + this: go test -timeout 45m for
  internal/library, gateway, cli and gui on mote; gofmt -l; go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui; win-run of
  library-mcp-hub and i18n-keys (both engines, en zh zh-TW ja de, 420px).
  gofmt and the three vets clean; library, gateway (554s) and cli ok;
  gui ok but TestMainWindowCorners, red the same on origin/main ddf31ca30
  on mote (#3949); GUI 26 of 26 pass.
- Earlier base (582bd8036, before TestHubConnectAnAgent and the oneport
  consts): full go test ./... on mote, every package ok but gateway's
  TestClientPathCoversHandler (fixed here: HubMCPPath, HubMCPAll and
  {agent} added to its consts; passes) and internal/gui's AppKit tests.
  Of those, TestMainWindowCorners fails the same on origin/main ddf31ca30
  on mote's macOS 27 (#3949); the other six (dock, panel, plugin page,
  right-to-left) passed rerun alone at load ~95 (#2645).
- win-run of every library-*, gui-*, i18n*, click-scroll and menu-scroll
  GUI file: 49 files, 839 tests, 839 pass.
- Real use in WSL (magpie-desktop), sandbox HOME, real echo MCP server:
  hub on, Cursor given servers → ~/.cursor/mcp.json holds only magpie at
  /mcp/magpie/hub/cursor; initialize, tools/list (echo__echo) and two
  calls ran on one server pid; a foreign Origin got 403; hub off → the
  echo process ended, tools [].

Broken by hand: Connect button removed → 6 GUI cases red; the old row
wrap rule → 6 red (icon on its own line at 420px); EveryServerAgents
call removed from TestHubConnectAnAgent → red (hub "").

Not run: the whole GUI suite (~960 files); Windows agents (VS Code, Cursor
on Windows) against a real hub; an "Add to Cursor" click in the real app
(the link is built and tested, the app's own confirm wasn't driven).
2026-10-29 03:17:58 +08:00
yetone 62045475b4 library: Codex on magpie reaches a command's MCP server through the gateway, run only while a thread uses it (#3885)
Codex starts every stdio server in its config once for each thread it
has loaded and keeps them as long as the thread: YPYT1 counted 204 node
processes, 21 GB, beside one Codex. While Codex is on magpie (Wired, not
disconnected, this machine's gateway key, not WSL) the library now gives
it a server run by a command as url = <gateway>/mcp/run/<name>, which
magpie serves over streamable HTTP and runs the command for itself
(internal/library/mcp_run.go):

- a session (Mcp-Session-Id) starts its own child only when it sends
  something past initialize, the first page of tools/prompts/resources
  lists and ping; those are answered from what the first child said for
  the same command, args and env, and a list_changed from a child drops
  that list;
- a (re)started child gets the session's own initialize replayed, so a
  server that keeps state per client still keeps it per thread;
- a child idle for 15 minutes is stopped (a later call starts it again),
  DELETE stops it, and a server changed or removed from the library has
  its children stopped at the next sync;
- server-initiated requests and notifications go to the session's newest
  open stream (GET, or a POST answered as SSE).
The gateway route lets only this machine in: no Origin, a loopback Host,
no forwarded or LAN address (TestRunMCPThisComputerOnly). A server with
an env var magpie hasn't, a remote one, and Codex off magpie, in WSL or
on another machine's key keep the command as before. agent.Rewired
re-syncs the library when Codex is connected or disconnected, so it is
handed the commands back when it leaves magpie.

Tests (internal/library/mcp_run_test.go, a fake server): starts on a
call and not on initialize/lists, idle end and DELETE, a server's own
request round-trips, list_changed, a changed/removed spec, an unknown
session, and the Codex entry in a sandbox (url when wired, the command
back when not, a keyed env var kept as a command). Each was red with its
part broken by hand: the init cache removed, the sweep off, runsFor
forced false, forget a no-op, the Origin/Host guard dropped.

Real runs:
- mote, sandbox HOME, real codex 0.162.1 + @modelcontextprotocol/
  server-memory: config.toml gets url = "http://127.0.0.1:3581/mcp/run/
  mem"; codex app-server's mcpServerStatus/list lists its 9 tools
  through the bridge.
- this Mac, sandbox HOME with only the DeepSeek provider copied, codex
  0.162.1 on deepseek/deepseek-flash: a real turn called mem
  create_entities and read_graph through the bridge and answered with
  the stored observation. Three codex exec turns at once that used no
  tool started 0 memory-server node processes (before: one each).
- Windows 11 (xiaomi-gpu), sandbox profile, codex 0.161.0: url entry
  written, app-server lists the 9 tools, 0 memory-server node.exe left
  after Codex closed.

Run at the pushed head (mote): GOOS=linux/windows/darwin go vet -tags
nogui ./internal/library/ ./internal/gateway/ ./internal/agent/: ok.
go test -count=1 -timeout 45m ./internal/library/ ./internal/gateway/
./internal/agent/ ./internal/gui/: library ok (167s), gateway ok
(596s), agent ok (279s); gui FAIL only TestMainWindowCorners/macOS_26_SDK
("a toolbar doesn't change the corners ... yet the main window's was
taken off"), #3949, red on mote's macOS 27 on main too; no gui or AppKit
file is touched here.
Windows (win-run): go test -run 'TestRun|TestFakeRunServer|TestMCPProxy'
./internal/library/ ./internal/gateway/: ok.

Not tried: the Codex desktop app (the same config.toml), a server that
asks the client for sampling or elicitation in a real agent. Codex picks
up the new entries when it restarts.

Reported-by: YPYT1
2026-10-29 03:06:48 +08:00
yetone ddf31ca305 gateway: a large translated body is written into itself, its items not kept beside it (#4004)
marshalBody marshalled every item of a translated request's list (the
messages, the input items) and kept the bytes, so it could size the body
exactly before copying them in: at the body's peak the written items
were a whole copy of the conversation beside the body. Past bodyKept
(4 MiB) of kept items, an item is now only measured, encoded through a
json.Encoder into a writer that only counts, and
once the body is made it is encoded again straight into it, then let go
when its list is spent. A body under 4 MiB is written as before, with no
second encoding; a larger one pays its encoding once more (on mote the
47 MiB case of TestMarshalBodyAllocatesTwoBodies went 0.09 -> 0.11 s
for both marshals together). The bytes are json.Marshal's either way.

Measured on mote, scratch harness (not committed): a 45 MiB Codex
conversation sent Responses -> Chat through the gateway, GOGC=10,
HeapInuse sampled every 2 ms, 3 runs each, base heap 54 MiB:
  425a61322 (before 8eb7f5565):  peak 302, 301, 301 MiB
  8eb7f5565 (spent list):        peak 278, 271, 273 MiB
  this change:                 peak 264, 263, 263 MiB
marshalBody of the 47 MiB test body allocates 52 MiB, was 98 MiB.

Tests: TestMarshalBodyAllocatesTwoBodies now holds marshalBody to 1.5x
the body (was 2.5x); red on the old code, which allocated 98 MiB for
47. TestMarshalBodyIsJSONMarshal runs every body, and every value
json.Marshal refuses, with everything kept, with every item measured
(bodyKept 0) and with the first kept and the rest measured (1).

Run at the pushed head (mote): GOOS=linux/windows/darwin go vet -tags
nogui ./internal/gateway/: ok. go test -count=1 -timeout 45m
./internal/gateway/: ok (465.1s)

Not tried: a real upstream; the bytes sent are unchanged.
2026-10-29 02:26:33 +08:00
yetone 8eb7f5565b gateway: a translated body lets its built conversation go as it fills (#4004)
marshalBody wrote a translated request's list (Chat's and Anthropic's
messages, Responses' input) an item at a time, but the list itself, the
conversation the builder made, strings joined from the request's parts
among it, stayed held in the body's map until the whole body was
written: at the body's peak it sat beside the written items and the
body. The builder names that list as spent, and each item is set to its
zero value once written. Every caller's map is its own and dropped after
the call (buildChat, buildAnthropic, buildResponses); buildGemini spends
nothing. Keys are checked before anything is spent, so the json.Marshal
fallback for an odd key still sees the whole map.

Measured on mote, TestZZPeak4004-style scratch harness (not committed):
a 45 MiB Codex conversation sent Responses -> Chat through the gateway,
GOGC=10, HeapInuse sampled every 2 ms, 3 runs each:
  base 425a61322: peak 302, 301, 301 MiB (base heap 54 MiB)
  this change:    peak 278, 271, 273 MiB
Live at send is the same, 149 MiB above base (the request, its parse,
the body), as the conversation was garbage by then either way.

Tests: TestMarshalBodyLetsSpentGo (new) writes a list of probes, each
looking whether the item before it was let go, and that a list not
named spent is unchanged. Broken by hand (spend never zeroing): red,
"items [0 1 2 3] were still held when the next was written".
TestMarshalBodyIsJSONMarshal passes with the messages spent.

Run on mote at 425a61322 + this change: GOOS=linux/windows/darwin go
vet -tags nogui ./internal/gateway/: ok; go test -count=1 -timeout 45m
./internal/gateway/: ok (537.8s). Rebased onto f6e7214af, whose only
gateway change is a host in buildChat's inlineThink; at the pushed head:
the three vets again ok, and go test -run 'TestMarshalBody|MiniMax|
Minimax|TestChat|TestResponses|TestAnthropic|Translat' ./internal/gateway/:
ok (31.8s).

Not tried: a real upstream; the bytes sent are the same, which
TestMarshalBodyIsJSONMarshal holds to json.Marshal's.
2026-10-29 02:17:47 +08:00
yetone f6e7214af7 minimax: api.minimax.cn is MiniMax China, for the usage card and the thinking sent back
MiniMax moved its China API host to api.minimax.cn (MiniMax-AI/cli
8746d48f, 2026-09-28: mmx agent setup now writes it into Claude Code,
Codex, OpenCode and pi). api.minimaxi.com still answers, but a provider
pointed at the new host got no usage card, because the plan-quota source
knew only api.minimaxi.com and api.minimax.io. Chat requests to it also
lost the <think> block MiniMax wants back on the turns after.

Every place in magpie that matches MiniMax by host is covered:
- planquota.go: api.minimax.cn reads /v1/token_plan/remains on its own
  host. Probed without a key, api.minimax.cn answers this path with the
  same base_resp 1004 as api.minimaxi.com.
- gateway/chat.go: inlineThink also matches minimax.cn.
Pricing and the catalog go by the provider's Catalog id ("minimax"),
not by host, so nothing changes there. The presets keep api.minimaxi.com.

Tests: a TestPlanQuotaSource case and a TestMiniMaxThinkingGoesBackInTags
case for api.minimax.cn. Both are red on the old code (code reverted by
hand, test kept; mote-run) and green with the fix.

Run on mote (mote-run):
- At 96bfdd57c (base 11c427eaa): gofmt -l on the changed files prints
  nothing; GOOS=linux go vet -tags nogui ./... ok; GOOS=windows go vet
  ./... ok; go test -count=1 -timeout 45m ./...: 76 packages ok
  (internal/gateway 1073s, internal/provider 490s). internal/gui timed
  out at 45m, with TestRestartHandsTheGatewayOver stuck 43m in
  gateway stopAccepting during the handover at load ~110. That is not
  this change: filed as #4107 with the stacks.
- Rebased onto 425a61322 and run again at this head: TestPlanQuotaSource
  and TestMiniMaxThinkingGoesBackInTags pass; ./internal/provider ok;
  go vet (darwin), linux -tags nogui and windows vet ok;
  TestRestartHandsTheGatewayOver -count=5 ok.
Not tried: a real Coding Plan key against api.minimax.cn (I have none),
so the card on that host is checked only by the shape of the no-key reply.
2026-10-29 01:52:34 +08:00
yetone 2fc2d53583 routing: the head's line keeps its height live, so a pick doesn't pull the list up
c5cdb043e (v0.1.1926) gave a finished request nothing took its own line
under the head ("Nothing took this request: …") where it had the
one-account hint. That line sits over the list, so in English picking
the WorkBuddy 400 of routing-failed-open (mythfish's case) shrank it
from three lines to one and pulled the list up under the click:
"picking the request moved the page", chromium and webkit en live.

holdMode keeps the line, live, as tall as the last three requests told
it, as holdStory does the story, keyed by width and language. A layout
is read only when the line's words or the width change (#3164), and the
head is told again once the steps' width is first known, so a pick
before the next second's telling is held too.

Run (mote):
- routing-failed-open at c5cdb043e: 2 of 8 red (en live, both
  engines); at 602ad84ad (before it) green; with this change green
  alone, beside held-request and mode-goes (108 pass, 0 fail), and
  under load beside rule-remove, rules-line, rule-drag and affinity
  (all failed-open and held-request cases ok).
- Every routing-* and click-scroll* file at the first version of this
  change (before the header retell): 1666 pass, 30 fail. All but two
  of the reds are in files red at 602ad84ad too (rule-drag,
  rule-remove, rules-line, rule-models, row-swap, steady,
  story-shrinks). routing-failed-open webkit en live was still red
  under that load, which the header retell fixes (green in the runs
  above); routing-many-keys' two reds passed in the next run
  (failed-open, held-request, mode-goes, many-keys, story-shrinks,
  steady: only steady's 2 and story-shrinks' webkit red, both red at
  602ad84ad).

Not run: the whole GUI suite; the Go suite (no Go change).
2026-10-29 01:50:14 +08:00
yetone 425a613224 library: a server run with npx -y reaches the agent as node running the package (#3885)
npx stays running as the server's parent for the server's whole life.
On Windows that is cmd.exe + npx's node + a second cmd.exe beside the
server: measured on xiaomi-gpu with @modelcontextprotocol/server-memory,
4 processes and 143 MB (cmd 8.1, npx node 76.2, cmd 8.2, server 50.8)
for one instance. Codex starts an instance a thread; #3885 had 223 node
processes under codex.exe.

A library server `npx -y <registry package> args` (no other npx flag)
is now installed with npm into ~/.config/magpie/mcp-npm/<hash> in the
background, and the next sync writes it into each agent on this machine
as `node <package bin> args`: node by name for npx by name, or the node
beside an npx given by path. Until the install is done, or when npm
fails (tried again after an hour), the agent keeps npx. An unpinned
spec is installed again after a day, as npx would fetch the newer one;
an install no library server runs any more is removed a day after its
last. The library's own entry, a server's check, Copy config… and WSL
agents keep npx. Taking a server off ends node's run of the program
(launchedBy reads the node line), as before for npx.

Run at this head (rebased on origin/main 1ff54f079; nothing it brought
touches internal/library):
- mote: go test -count=1 -timeout 45m ./internal/library ok (116s);
  GOOS=linux/windows/darwin go vet -tags nogui ./internal/library ok;
  ./internal/proc/... ./internal/testenv/... and the root package ok;
  TestNpx*/TestReadNpx under -race ok.
- xiaomi-gpu (win-run): TestNpx*/TestReadNpx ok.
- Real, on xiaomi-gpu, Node 22 + real npm registry, sandbox HOME: the
  library synced server-memory into a Codex config.toml; the install
  took 12.8s and the second sync wrote command = "node", args = [the
  install's …\server-memory\dist\index.js]. Started from that entry, the
  server answered initialize and tools/list, and its process tree was 1
  process at 56.2 MB, against 4 processes and 143 MB through npx.
- Broken by hand: without the npxDirect call in syncMCP,
  TestNpxServerRunsByNode is red ("the package was never installed").

Not tried: a real Codex or Claude Code session starting the node entry
(the entry has the same command/args shape they already start), and
macOS's process tree (npx's node and sh there too).
Not done (#3885 stays open): Codex starting the same MCP once a thread.
2026-10-29 01:30:58 +08:00
yetone 1ff54f079f grok: each model is asked on its native API (responses, messages), not Chat for all (uk.jent)
uk.jent on Discord: magpie wrote api_backend = "chat_completions" on every
[model."magpie/…"] table of Grok Build's config.toml, so a Responses-only
GPT or a Claude on an Anthropic endpoint was translated through Chat by
the gateway. Grok Build 1.0.67's own docs (the "Supported API Backends"
page bundled in its binary) take api_backend per [model.*] table:
"chat_completions" (default), "responses" and "messages" (Anthropic
Messages), sent to base_url + /chat/completions, /responses or /messages.
grokBackend now writes the model's native API from catalog.Model.APIs, as
Pi, droid and dsh pick theirs; Chat stays for a Chat-native or unknown
model and for a group whose members differ. All three go to the same /v1.

Grok App (grokapp.go) is unchanged: it has one channel, [model.magpie],
whose model the App's composer switches, so a backend written for the
picked model would be wrong for the next one picked there.

Run:
- TestGrokAsksEachModelNatively (new): red with the old "chat_completions"
  put back by hand ("resp/gpt-6-sol: api_backend "chat_completions" ...
  want "responses""; same for anth/claude-sonnet-5 / "messages"), green
  with the change.
- At this head (rebased on origin/main 2cdbe92de), on mote: gofmt -l clean;
  go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./... all exit 0; go test -tags nogui ./internal/agent ok (220s).
- Real Grok Build 1.0.67 in a sandbox HOME/GROK_HOME against a sandbox
  magpie serve on 127.0.0.1:3491 (this tree's build), with a copy of the
  Copilot editor sign-in: magpie wrote messages for copilot/claude-*,
  responses for copilot/gpt-* and grok-*, chat_completions for gemini and
  kimi. grok -p on copilot/claude-haiku-5.5 and copilot/gpt-5.6-luna
  answered PONG; a tool turn (read a file) with --reasoning-effort high
  on copilot/claude-sonnet-5.5 and copilot/gpt-5.6-luna returned the
  file's contents. usage.jsonl shows 200 on ep /v1/messages and
  /v1/responses with no translation arrow. yylx, AiHubMix and OpenAI key
  providers reached the vendor on /v1/messages and /v1/responses with
  magpie's Bearer key, and were refused for balance.

Not run: the full go test ./... suite: mote had two other sessions' full
suites running (load ~136), and one suite per machine. Not tried: Grok
App, Windows/Linux Grok Build, a Claude subscription (it is Chat-native
here, so unchanged).
2026-10-29 01:30:13 +08:00
yetone 2cdbe92ded pii: a value the model found sure once in a text is sure wherever it found it there
wangwu25685333 on X (10-29): of one sentence with an address repeated
400 times, the address was left unmasked "a few times", thought to be
where the text was cut into chunks.

Reproduced with the real model (AstrLink Guard, pure Go, Linux box,
GOMAXPROCS=4) through masking's strict path and redact.MaskJSON, 400
copies of a sentence in one message:
  "Please ship it to 1600 Amphitheatre Parkway, Mountain View, CA 94043
  by Friday." joined by "\n": 346 of 400 left as written; by " " or
  nothing: 0. Two Chinese addresses, any joiner: 0.
It isn't where the text is cut. Guard found the address on every line,
but less surely the more often it had read it in the text: 0.99 alone,
0.59-0.70 at 20 copies, and on 400 the whole address 325 times at 0.50
to 0.90 and split ("1600" at 0.85, the rest at 0.50-0.59) 65 times.
Masking takes 0.8 and over, so it masked only the sure ones, about one
a piece. Joined by "\n" the pieces are alike, so every piece got the
same few sure finds.

Now spread puts each value of 8 bytes or more the model found in a text
(minSpread, as redact's minKnown) wherever else it is in that text,
with its label and the score of its surest find there, then merges. A
value never found sure stays as unsure as it was, and a house number
alone isn't looked for. It runs on each text and piece the model reads
and on a long text's merged pieces, before they are cached. Spans from
the disk cache written before keep their scores until read again.

After, the same probe: 0 of 400 left for every sentence and joiner.

Test: TestValueFoundSureOnceIsSureThroughoutItsText has a stand-in model
that finds an address sure only first in its first read and unsure
after, on 3 and 400 lines, and fails when an address is left unsure,
another value never found sure is raised, or a short one is spread.
Broken by hand: without spread in find.go it fails ("1600 Amphitheatre
Parkway" at 110 scored 0.50).

docs/subsystems/gateway-routing.md says this, the pieces' ends
(landmark) and the turn's order (takeTurn, queue) of the two commits
before.

At ca221e115 with the three pii commits of this push: gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... and go build ok (mote); go test ./internal/pii/...
./internal/masking ok on mote, on Windows (win-run) and with -race on
Linux (wsl-run). Not run before the push: go test ./... (both mote and
the Linux box were running other sessions' full suites, one a machine).

Not tried: the reporter's own sentence (not in the tweet); 400 copies
spread over 400 messages (each its own text, read alone at 0.99 here);
Privacy Filter (spread is the same for both models, tried on Guard).
2026-10-29 01:28:25 +08:00
yetone 43a9d04400 pii: of the requests waiting for the local model, the one with the least left to read goes next
wangwu25685333 on X (10-29, v0.1.1840, Linux, i5-7500 4c/4t, AstrLink
Guard on): requests of 1.4K tokens waited 8.5s for the model behind a
fresh session's 31.5K, and their client gave up at 20s.

The model's turn was a buffered channel, and the requests blocked
sending on it took it in the order they came. A long request gives the
turn up between chunks (4 KB for Guard, about a second or more on 4
cores), but a short request that came after another long one waited
a chunk of each long request ahead of it.

Now each request waiting says how much it has left to read (the bytes
of its texts and pieces neither got nor the cache has; of a Bounded
request's backlog, no more than it will read), and only the one with
the least left (the first to come of those with as little) sends on the
turn; the others wait for the queue to change. The channel stays, so
Warm and guardIdle take the turn as they did. Privacy Filter's pf-serve
turn is the same backend and gets the same order.

Measured with the real model (AstrLink Guard, pure Go) on the Linux box
(wsl magpie-desktop) with GOMAXPROCS=4 taskset -c 0-3, a 5 KB request
sent 1.5s after long requests (a 110 KB system prompt each, cold):
  alone:          2.47s before, 2.54s after
  behind 1 long:  5.49s -> 4.91s
  behind 2 long:  8.29s -> 4.50s
(after: the chunk on the model when it came, then its own two chunks;
before, 8.3s is the reporter's 8.5s.)

What this leaves as it was: masking's waits (2s for the model on by
default, then the rules alone; 15s for a model the user turned on) and
its log line when the rules mask alone (notePartial, once a minute) are
unchanged. Most of the reporter's case was fixed after v0.1.1840 (tool
definitions not read v0.1.1871, the 2s and 15s waits v0.1.1874 and
v0.1.1886, newest first and a 4 KB chunk v0.1.1891, windows in
parallel v0.1.1864).

Order is by bytes left, not by age: a long request waits while shorter
ones keep coming. With masking's waits bounding every request, a long
one waits until its wait ends and the rules mask the rest.

Test: TestShortRequestGoesBeforeLongOnes puts a long request (4 chunks)
on the model, another long one waiting, then a short one, and fails
unless the short one is read second. Broken by hand: with find.go of
the previous commit it fails, read in the order d, h, hi Alice, c, g...
(the second long request's chunk first). Run -race -count=20 with the
turn tests (TestStopped*, TestWaiter*, TestQueued*) on mote: ok.
Run (mote): go test ./internal/pii/... ./internal/masking ok; gateway
-run 'Mask|Redact|PII|Guard|Model' ok.
At ca221e115 with the three pii commits of this push: gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... and go build ok (mote); go test ./internal/pii/...
./internal/masking ok on mote, on Windows (win-run) and with -race on
Linux (wsl-run). Not run before the push: go test ./... (both mote and
the Linux box were running other sessions' full suites, one a machine).

Not tried: a real Hermes client with its 20s timeout; the reporter's
4c/4t i5 (the Linux box is a 32-core AVX-512 machine held to 4 cores).
2026-10-29 01:28:25 +08:00
yetone 40593e898c pii: a long text's pieces end where its own text says, so an edited system prompt is read again around the edit only
wangwu25685333 on X (10-29, v0.1.1840, Linux, i5-7500 4c/4t): a fresh
Hermes session of 31.5K tokens spent 98.8s in the local model (AstrLink
Guard) and 2.3s upstream, and every new session (cron opens one each
time) read the same ~30K of system prompt again.

The cache by content was already there (#3682: sha256 of each text or
piece -> spans, in memory and in found-<rev>.bin, no text), and tool
definitions are no longer read (a5315c70d). What made a fresh session
miss it is how a long text is cut: a piece ended after the last line's
end in its second half, so its end was a distance from the piece's
start. A line of the prompt edited (Hermes puts its date, memory and a
workspace snapshot in the prompt) moved every later piece's ends by as
many bytes, and every piece after the edit was new to the cache.

Now a piece ends after the line's end (else space) in that second half
whose 48 bytes before it hash least (FNV-1a): the text's own choice. Once
one end meets an end of before, the rest are the same pieces, known by
hash. The rune-start fallback (no line's end or space in 2 KB) is
unchanged.

Measured, pieces new to the cache after one edit (4 inserts x 2
deletes at every ~1 KB) of three texts, guardChunk pieces (cut only):
  39 KB of AGENTS.md/LESSONS.md/code-standards: mean 3.92 -> 1.65,
    worst 13 of 13 -> 5 of 18
  68 KB of LESSONS.md/agent-wiring.md: 2.80 -> 1.63, worst 14 -> 6
  58 KB of prose(): 4.96 -> 1.64, worst 20 of 20 -> 4 of 28
The cost: pieces are 3/4 as long on average, so a cold read reads
142% of the text where it read 130% (overlaps). Tried and dropped:
a narrower window (3/4 of the piece: 2.49 mean, worst 9) and the last
line's end whose hash is 0 mod K (K 4..32: worst 9 to 15 at the
small K, no better than this at 32).

The real model (AstrLink Guard, int8, pure Go) on the Linux box with
GOMAXPROCS=4 taskset -c 0-3 (wsl magpie-desktop), a 110 KB Hermes-like
system prompt (about 28K tokens; AGENTS.md, code-standards, LESSONS.md
and two subsystem pages, a memory section, a date line):
  cold:                         59.9s -> 62.4s
  a line added at 10/25/50/75%: 3.06/4.77/1.79/2.49s ->
                                1.35/2.93/1.65/2.48s (mean 3.03 -> 2.10)
  memory line + date changed:   2.83s -> 2.72s
  the same prompt again:        0s both (the cache by hash)
On mote (CoreML) the cold read is 1.3s both ways.

Test: TestEditedTextReadsItsPiecesAgainOnly reads a 40 KB prompt-like
text, then the same with a line inserted at 14 places x 4 inserts, and
fails when more than 3 pieces' bytes are read again or a span is lost.
Broken by hand: with find.go of origin/main it fails ("Conversation
started: ..." at 536: 53573 bytes read again, want at most 12288).

Run (mote): go test ./internal/pii/... ./internal/masking ok; gofmt -l
clean.
At ca221e115 with the three pii commits of this push: gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... and go build ok (mote); go test ./internal/pii/...
./internal/masking ok on mote, on Windows (win-run) and with -race on
Linux (wsl-run). Not run before the push: go test ./... (both mote and
the Linux box were running other sessions' full suites, one a machine).

Not tried: the reporter's own Hermes prompt (it is on their machine);
the measure is on this repo's docs and on prose(); a CJK text with no
line's end or space for 2 KB still cuts by distance.
2026-10-29 01:28:25 +08:00
yetone 67d0e4da61 gui: app.js is back under its budget; the lane comment says what it said before
TestCoreScriptBudget was red on main: 72ca3d593 left app.js at 1,311,690
bytes over its 1,311,681 budget, and 53913be7a (the lane pill's running
count) added 7 more on top, 1,311,697. That commit's comment edit (35
bytes) goes back to main's wording, which already says the pill tells how
many run and wait, so app.js is 1,311,662 with no budget raised and no
behaviour changed.

Run on mote at this tree: go test -run TestCoreScriptBudget ./internal/gui
ok; lane-limit.test.cjs in Chromium and WebKit ok. Broken by hand: none
needed (the test was red at 53913be7a, the byte count shows it). Not
tried: the whole GUI suite (comment-only change).
2026-10-29 01:19:51 +08:00
yetone ca221e115e routing: a pick lets the stage go live when the reader is back to newer requests
未寒 on Discord (#feedback, 10-28): the Routing page's stage stayed on
a 16:36 Mozilla request to qwenwork/flash, "The agent canceled the
request", headed "16:36 的请求是怎么路由的", while the requests list
under it went on with auto/deepseek-v4-flash at 17:08 and 17:09.

Cause: that head is a pick. A click on a list row, the errors stat,
the context card, Usage's openRoute or the tray's ?req= pins the stage
to one request. #1389 lets a pin go only when the request leaves the
60 the page keeps, so at a calm pace a pick holds for hours. A reader
who left for another app or another page and came back finds the
stage on a request they no longer remember picking, and reads it as
stuck.

Fix (plugins/routing/client.js): the reader leaving while a pick holds
the stage (window blur, another page, the window hidden) marks the
newest request then. Back in sight and focused, if a request newer
than the mark has come, the pin is dropped and the stage follows live
(followListed). This is checked in start() when the poll was running,
and in the poll's catch-up pass when it had slept out of sight, so
requests read only on return count too. Back to nothing new, the pick
stays. A reader who never left keeps it as requests come, as before. A
new pick clears the mark. Day mode and a replay are left alone. The
tray panel has no pin, so there is no sibling there.

Test: internal/gui/tests/routing-pin-away.test.cjs. The canceled
request is picked from the list. It holds while requests come, and it
holds after leaving and coming back to nothing new. The reader then
leaves while 8 more come, still within the 60, and comes back: the
head is "How the last request was routed", there is no Back to live,
the first row is pressed and the stage shows the newest model. Three
ways of leaving (another app, another page, the window hidden), en at
1100 and zh at 420, in Chromium and WebKit.

Run on mote at this head (rebased on c5cdb043e; main to 5a85a9836 changed nothing under internal/gui, and the two pin files ran again there):
- routing-pin-away: red on the old code in every case (the head kept
  "How the request at … was routed…Back to live"); green after.
- All routing-*, panel-routing*, i18n-keys, gui-zh-tw, usage-ledger,
  click-scroll and dates-gui-lang GUI files in both engines (132 files):
  1755 of 1793 pass. The 38 reds are in 9 files. Run alone, they are
  red the same way on an unchanged copy of main c5cdb043e (33 there,
  36 here, at mote load 70 to 200; the counts in the rule-editor files
  vary between runs): routing-row-swap #3799, routing-steady #3412,
  routing-story-shrinks #3954, usage-ledger #4078, routing-rule-drag
  #3789, routing-rule-remove #3094/#3096, routing-rules-line #3593,
  and routing-failed-open's en live case, which had no issue and is
  filed as #4105. routing-pin-away and routing-pin-leaves are green.
- go test -tags nogui ./internal/gui/ (TestCoreScriptBudget and the
  asset tests): ok. TestLoopGuardLeavesOrdinaryRepliesAlone and
  TestAntigravityTurnedAwayHintIsTheRoutingPages (they read
  client.js): ok.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gui/...:
  ok. gofmt -l: clean. No budget raised.

Broken by hand:
- Dropping the poll's catch-up check: the another-page and
  window-hidden cases go red (the poll slept while away), and
  another-app stays green.
- Dropping the check in start(): the another-app cases go red in both
  engines.

Not tried: the real Wails window's blur and focus in WKWebView,
WebView2 and WebKitGTK. The test dispatches the window events and fakes
document.hidden. Not tried with the reporter's own gateway either.
2026-10-29 01:19:25 +08:00
yetone 53913be7aa providers: a key or account with no limit on requests at once shows how many run (chentuoyan on Discord)
The account and key rows' lane pill said only "No limit at once" when no
concurrency limit was set, never how many requests were out. Now, with no
limit and requests out, it says "{n} running" (zh: "{n} 运行中") and is
shown without a hover, in the same pill style (no full-lane or queue
colour). Idle with no limit it says "No limit at once" again and goes back
to hover-only. Rows with a limit are unchanged.

Backend: /api/lanes (Server.Lanes, /v1/magpie/concurrency's data) only
listed lanes with a limit, because lanes.take took nothing for limit 0.
take now counts a request with no limit in its lane (Limit 0, never
waits; grant still lets any waiter go at once when a limit is lifted) and
gives it back through the same once-only releaser, so Lanes says Busy for
it. Cost: the same one mutex take every request already paid, plus one
small lane and closure; /api/lanes, read every 2s, copies a map of only
the lanes with requests out. A limit set while unlimited requests are out
now counts them (the vendor does see them). The only caller of take
(serve) always calls release (deferred after attempt, or on an RPM
failure). Strings in zh, zh-TW, ja and de. gateway-routing.md says it.

Tests:
- TestLanesCountWithNoLimit (new, internal/gateway): three held streams on
  a provider with no MaxConcurrency read Lane{Busy:3}; all gone after.
  Red on origin/main's concurrency.go: "lane = {Busy:0 Waiting:0 Limit:0},
  want 3 out, none waiting, no limit".
- TestLanesLimitLifted now releases its limit-0 acquire (it was a no-op
  before).
- lane-limit.test.cjs "with no limit, what runs is shown, and none running
  says no limit again" (Chromium and WebKit, en and zh), red on
  origin/main's app.js: expected '3 running', actual 'No limit at once'
  (zh: '3 运行中' vs '并发不限'). lane-limit.test.cjs whole: 16/16 ok on mote.

Run on mote at the tree rebased on 655f8dbd1: gofmt -l clean; go vet
./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...
clean; go test ./internal/gateway ok (593s); ./internal/gui all ok,
TestCoreScriptBudget included (app.js 1,311,665 <= 1,311,681, no budget
raised), except TestMainWindowCorners/macOS_26_SDK, #3949, red the same
way on a clean origin/main 655f8dbd1 run on mote.
Rebased again on e5e2aa58e (its commits change gateway fallback/wallets,
routes and gateway-routing.md's Limits row, merged by hand; none of the
lane code). At this head on mote: gofmt -l clean, go vet ./internal/gateway
./internal/gui clean, the gateway's lane/concurrency/busy tests and
TestCoreScriptBudget ok, lane-limit and i18n-keys in WebKit 12/12 ok.
Whole GUI suite (node --test, both engines, every language): NOT
finished. A run at the 655f8dbd1 tree was ~25 min in (load 60-100) when
my own later mote-run into the same copy deleted its log, so its result
is lost; it is run again at this head after the push. Reds seen before
the log went: account-alias.test.cjs's Usage-page #usageMask click
timeouts (chromium, every language), a page this change doesn't reach;
not yet checked on origin/main.

Not tried: a real gateway with real accounts, and the real Linux/Windows
apps (the pill is the same element and CSS as before). The full go test
./... was not run (only the two affected packages).
2026-10-29 01:19:08 +08:00
yetone 72ca3d593b codex: magpie as Codex's provider keeps the Codex app's ChatGPT account while it has room, so its Work chats and projects stay
Qyburn3 on X: with magpie taking Codex over, the Codex app's "Work"
sessions don't load while the model still answers; turned off, they
come back.

Cause: [model_providers.magpie] had no requires_openai_auth, so Codex's
app-server answers account/read and getAuthStatus with no account and no
token whenever magpie is Codex's provider (magpie API, or the codex.out
takeover). ChatGPT.app 26.1021 then switches to an identity of no
account: onboarding again with no name, ChatGPT mode's projects and
chats ("Work") empty, no avatar, no Chrome control (#1824).

Now putProvider writes requires_openai_auth = true while Codex has a
ChatGPT sign-in with room (openaiAuth: codexChatGPTKnown and not
codexUsedUp), and takes it out otherwise:
- API key alone: left out. With it Codex drops image_gen (captured: 11
  tools without, 10 with), and there is no account to keep.
- No sign-in: left out (the app would ask for a sign-in).
- A sign-in the Codex app holds (codex.out, or magpie API while used
  up): left out, since the app's composer gate (authMethod chatgpt +
  allowed false, #540) would grey Send for magpie's models again. The
  takeover's note now names "its ChatGPT chats and projects" among what
  is off till the reset, beside Keep on ChatGPT.
- An unknown sign-in read leaves the table as it is.
Sync rewrites the key on any table that disagrees (authStale), an older
magpie's included, and the key joins codexAppRoute, so the Codex app's
app-server is restarted onto its account with nothing for the user to
do. The magpie API note no longer says Chrome control needs ChatGPT (en,
zh, zh-TW, ja, de); agent-wiring.md says why.

Real app (mote, ChatGPT.app 26.1021 with its codex 0.164.0-alpha.11,
sandbox CODEX_HOME, copied real ChatGPT auth, auth.json unchanged after):
- native config: the account's projects and recent chats listed.
- magpie table without the key: onboarding, "ChatGPT Work" with no
  projects, no chats. app-server: account null, authMethod null.
- magpie table with requires_openai_auth = true (the keys this commit
  writes): every project and chat back; account/read chatgpt pro,
  getAuthStatus authMethod chatgpt with a token.
- Model requests to a capturing server, with and without the key:
  Bearer is magpie's experimental_bearer_token, no ChatGPT-Account-ID,
  15 tools both ways with a ChatGPT sign-in (image_gen kept).

Tests: TestCodexMagpieProviderKeepsChatGPTAccount (ChatGPT + magpie API,
used up and back; taken over and the reset; an older magpie's table from
live config bytes; API key and no sign-in, fresh and after ChatGPT) and
TestCodexAppRouteFollowsOpenAIAuth. Broken by hand: on the old codex.go
5 of 7 subtests red; without the Sync re-derive 3 red; with the key kept
while used up 2 red; agents.go without the route key, the route test red.

Run (mote-run, at this tree on origin/main 157d575c3; the build and the
agent run again after the rebase onto e5e2aa58e, ok; 5a85a9836 after it touches redact only,
no agent
or GUI file, ok): gofmt -l clean;
go build ./...; go vet linux (-tags nogui) and windows ./..., darwin
./internal/agent; go test -tags nogui -run 'Codex|Agents|Sync|Disconnect|Route'
./internal/agent ok; GUI codex-signin-always, codex-app-out, i18n-keys
and the i18n files, Chromium and WebKit, 96/96.
Not run before the push: the full go test ./... (mote had three other
sessions' full suites at load ~100); it runs after, and any red gets an
issue. Not tried: the used-up case on the real app with the key (the
composer gate is from #540's reading of 26.1013), Windows and Linux
Codex apps.
2026-10-29 01:18:59 +08:00
yetone 5a85a9836c redact: a value at the end of a tool call's arguments keeps its closing quote (xiaojiang091499 on X)
xiaojiang091499 on X (v0.1.1808): "隐私脱敏误把 Codex 工具参数结尾的引号和
花括号一起替换了,破坏了参数格式,导致会话一直报错重连". Still the case on
main before this commit.

Cause, outbound: a tool call's arguments are masked as JSON text
(MaskJSON, escaped). A span is kept out of escapes (#3022) but not inside
its JSON string, so a span that runs past the string's end took the
closing quote with it. The local model does this: Privacy Filter's
tokenizer merges a punctuation run, so in {"cmd":"export
DB_PASSWORD=Hunt3r!"} the real model's SECRET span is `Hunt3r!"`, and a
secret's edges are kept by design (#3591). Same with "the api key is
AbC…!?\"", "ship to 221B Baker Street, London.\"", "pwd=Qq123456@#\"".
A user rule like `tok-\S+` does the same. The vendor got
{"cmd":"export DB_PASSWORD={{SECRET_…}}}: arguments no longer JSON, so
Codex's turn failed and reconnected. The model is on by default since
v0.1.1858, so this hits every user from then.

Fix: inStrings (redact.go) moves each span in escaped text onto the JSON
string it starts in and ends it where that string ends. A span that is a
whole bare value (a number a rule finds, "acct": 12345678901) is kept and
its placeholder goes in quoted (span.bare); any other span outside a
string is dropped. Text that isn't valid JSON is left as before. This is the
path for Responses function_call and Chat tool_calls arguments (JSON
text); Anthropic tool_use input and Gemini functionCall args are
objects, masked string by string, so a span there never leaves its
string.

Sibling, inbound: Writer.event and restoreJSON read an event's "type" as
the walk reached it, so a Responses function_call_arguments.delta whose
"delta" key comes before "type" (as a Go map or any key-sorting proxy
writes it) had its value put back unescaped: a password with a quote in
it ended the arguments' string. typeOf now reads the type first, and the
Writer falls back to the SSE event name. Chat tool_calls and Anthropic
input_json_delta were already right (key "arguments"/"partial_json").

Tests (internal/redact/argstail_test.go):
- TestArgumentsValueAtEndKeepsQuote: the real model's four spans
  (captured from Privacy Filter on mote) and a \S+ rule, in Responses and
  Chat bodies; arguments stay JSON, the value is gone, Restore gives the
  original back.
- TestArgumentsBareValueQuoted: a bare number is masked as a string.
- TestWriterStreamArgumentsValueAtEnd: a value with a quote and a
  backslash, at the end of the arguments, split at every byte after its
  placeholder starts, through Responses deltas (delta before type),
  Chat tool_calls and Anthropic input_json_delta.
- TestRestoreJSONDeltaBeforeType: the whole-body path.

Broken by hand: without inStrings, the first two fail; with the type
read in the walk again in writer.go, the stream test fails at cuts 28-43
({"cmd":"export DB_PASSWORD=Hunt3r!"\x"}); the same in json.go fails
TestRestoreJSONDeltaBeforeType.

Real model: a probe (not committed) ran Privacy Filter on mote over 36
argument texts through MaskJSON as the gateway does; before, the
arguments were broken for each case above; after, all 36 are valid JSON
with the value masked.

Run on mote (mote-run): go test ./... -timeout 45m -count=1 at this
change on 655f8dbd1: every package ok except two reds already filed and
outside redact: internal/gui TestMainWindowCorners/macOS_26_SDK (#3949)
and internal/provider TestClaudeAccountServesModelsListedSinceItsFetch
(#3174). Rebased on 362774210/e5e2aa58e (gateway and routes only), then
internal/redact, internal/pii and internal/masking again at the pushed
head: ok. go vet ./..., GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
-tags nogui, GOOS=windows go build: ok. gofmt -l: nothing.

Not tried: a real Codex session through the gateway with a masked
password; Gemini's functionCall with the real model (its args are an
object, masked string by string, never as JSON text). No docs/subsystems
page describes where spans are placed, so none changed.
2026-10-29 01:17:04 +08:00
yetone e5e2aa58e5 routes: each provider's wallets go by what they have left in a group too (#4095)
mycf_711 (#4095, comment): SuperMagic's accounts asked directly went by
their points (6,636, 282, 119), but in group/deepseek-v4.1-flash1017
they went 282, 119, 6,635, the provider's listed order. A Smart group
weighs its members' accounts as one pool (planLevel → weigh over the
heads), and the pool held WorkBuddy's credits beside SuperMagic's
points: byLeft returned nil as soon as it saw two kinds of LeftIn, so
no balance ordered anyone. Each 400 「积分已不足」 was then met on the
small balances first.

byLeft now orders each kind (provider + unit) in the places its own
seats take: the told seats' places in the pool's order (Smart) or by
what magpie sent each lately (Pace, Least used, as their tie-break
after the balance), each kind's seats put into its places by what they
have left, and seats of two kinds keep that order between them. A seat
that told none still goes after those that did. It is one rank per
seat, so the comparators stay a consistent order; comparing two kinds
as a tie would not be. One kind alone orders exactly as before
(TestWalletsGoByWhatTheyHaveLeft unchanged).

Tests: TestWalletsOfSeveralProvidersEachGoByWhatTheyHaveLeft (routes:
Smart, Pace, Least used, the reporter's three behind a WorkBuddy seat,
two kinds interleaved, and Least used's token order between kinds) and
TestGroupWalletsGoByWhatTheyHaveLeft (gateway: weigh over a group's
pool with the reporter's balances, smart/pace/usage).
docs/subsystems/provider-plugins.md and gateway-routing.md say it.

Broken by hand: with the old strategies.go both tests are red (the
group keeps 632, 710, 051 under every routing).
Run on mote, at 157d575c3 with both #4095 commits on it (the pushed tree):
go test -count=1 -timeout 45m ./internal/gateway/... ./internal/routes/...
ok (gateway 781s, routes 0.4s); gofmt -l internal/gateway internal/routes
empty; GOOS=windows and GOOS=linux go vet ./internal/gateway/...
./internal/routes/... ok. The same was green at the earlier bases
40f206dff and 7a7931833. Pushed on 99299c7b1, whose commits since
157d575c3 change only internal/edit's tests; not run again there.
Not tried: a real group with SuperMagic and WorkBuddy accounts; the
affinity that keeps a conversation on a low wallet ("turn") is unchanged.
2026-10-29 01:14:42 +08:00
yetone 3627742104 gateway: an error read as out of credit moves on at any 4xx (#4095)
mycf_711 (#4095): SuperMagic answered an account with no points left
400 "非常抱歉,当前对话需要调用大模型 / 付费工具,您的可用积分已不足。
您可以点击右上角「用户头像」,通过「充值」通道补充积分…". failure() read
it as failCredit (creditWords: 充值), but retryable()'s 400/422 branch
asked quotaWords only, which has neither 积分, 不足 nor 充值. So
hw.failed() was false: the 400 went to the agent while another account
in the order had 6,467 points, and the empty account was never rested.

retryable() now takes any 4xx failure() reads as failCredit, after the
overflow check, so the two deciders agree on credit at every status
(400, 422, and the 4xx outside the always-retried list, 409 say).
Sibling: shapeRefused() kept out quotaWords but not creditWords, so a
shape refusal saying 请充值 would rest nobody; it now keeps out both.
Quota: usedUpWords (failQuota) is a subset of quotaWords, so 400/422
already agreed; a quota word at another 4xx (413's "exceeded the
limit" is the request's size) is left alone on purpose.

Tests (credit_400_test.go), with the reporter's literal body:
TestCreditRefusalIsRetryableAtAnyStatus (400/409/422, raw and as magpie
tells it on, plus shapeRefused) and TestCredit400MovesToTheNextAccount
(two keys: the empty one 400s, the next answers 200, the empty one
rests as credit 400, the next request goes straight past it).
docs/subsystems/gateway-routing.md says it.

Broken by hand: with the new case disabled and creditWords taken out
of shapeRefused, both tests are red (every status not retryable, the
shape case rests nobody, the request ends 400 after k-empty alone).
Run on mote, at 157d575c3 with both #4095 commits on it (the pushed tree):
go test -count=1 -timeout 45m ./internal/gateway/... ./internal/routes/...
ok (gateway 781s, routes 0.4s); gofmt -l internal/gateway internal/routes
empty; GOOS=windows and GOOS=linux go vet ./internal/gateway/...
./internal/routes/... ok. The same was green at the earlier bases
40f206dff and 7a7931833. Pushed on 99299c7b1, whose commits since
157d575c3 change only internal/edit's tests; not run again there.
Not tried: a real SuperMagic account at 0 points (the plugin 0.3.26
already turns this 400 into 402 there).
2026-10-29 01:14:42 +08:00
yetone 99299c7b1c edit: the big-TOML ratio test compares 1 MB with 8 MB under a bound of 24 (#2219)
36200091a (Niko-Wu's patch from #2219, picked as written) bounds the
8 MB parse by 8 times the 2 MB one, 2x room on each side of the linear
4x and the quadratic 16x. On mote at load 250 it went red 1 run in 13:
load didn't slow both parses alike. The sizes are now 1 MB and 8 MB, so
linear is 8x and quadratic 64x, and the bound of 24 leaves about 3x on
each side; each size keeps the fastest of five parses.

Run on mote (macOS 27), at this tree:
- go test -tags nogui -count=30 -run TestTOMLBigFile ./internal/edit at
  load 214: ok.
- Broken by hand, tomlShaper's line found by a scan from the top of the
  file (the per-key pass 2a4042a9 removed): red, "an 8 MB file took
  1m52.9s to parse, 71.4x the 1 MB one's 1.58s". Reverted.
- gofmt -l clean.
Still a timing test: it measures a ratio, not a count, since the parse
has no counter to read without adding one to toml.go.
2026-10-29 01:11:18 +08:00
Niko WuandClaude Code 36200091ad edit: the big-TOML shape test bounds the parse by two sizes' time ratio, not one second of wall clock (#2219)
edussss on 10-15, running `go test -tags nogui ./...` for #1928 at load
average ~190: TestTOMLBigFileParsesInLinearTime went red, a 3 MB file
took 1.272s against the 1s bound. Rerun alone it passes. The parse was
still linear; the bound was not.

The check now parses a 2 MB and an 8 MB file three times each, keeps
the fastest of each, and requires the 8 MB time to stay under 8 times
the 2 MB one. Load slows both parses together, so their ratio holds
where a wall-clock second does not. The code standards' "a timing test
leaves room on both sides" asked for exactly this: measured here, the
linear parse's ratio is 3.7 to 4.5, and the quadratic parse the test
guards against, which counts each key's line from the top of the file,
needs 16 times the time for the 4 times bigger file. 8 sits between
the two, far from both.

What was run:
- go test -tags nogui ./internal/edit/: ok
- the fixed test with -count=3: ok (6 runs)
- a local quadratic tomlShaper (per-key line scan, the behavior
  2a4042a9 removed): the ratio reads 16.0x (2 MB 5.3s, 8 MB 1m25s)
  and the test goes red; reverted after
- gofmt -l internal/edit/: empty
- go vet -tags nogui ./internal/edit/ at GOOS=windows and GOOS=linux
  (the latter CGO_ENABLED=0; the local macOS SDK has no glibc, so the
  cgo path of a dependency cannot be vetted here): clean

No .github/, site/ or go.mod/go.sum file is touched.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-29 00:57:54 +08:00
yetone 157d575c39 usage: pairing Codex calls by response id allocates no pick an id (#2278)
codexChunkResponsePairs kept a *pick for every response id the gateway
had. The alloc profile of v0.1.1928 on mote (34k session files, 240k
gateway rows, two minutes of polls while an agent worked) had it at
1.05 GB, &pick{} alone 308 MB. The picks are now one slice the map
holds places in, so a poll makes a few slice growths, not an allocation
an id. What is paired is unchanged: every pick is still read once.

TestPairsAllocateNoPickAnID: 4000 Codex calls named once on both sides
are all paired, and a second pairing makes at most n/4 allocations. Red
on the old code (4161 allocations), green on the new.

Run on mote at the pushed head (origin/main 655f8dbd1 plus this; rebased
onto b7da6cf93, a gateway test commit that touches neither package):
  go test -count=1 -timeout 45m ./internal/usage/ ./internal/sessions/
    ok (30.8s, 37.9s)
  GOOS=linux/windows/darwin go vet -tags nogui ./internal/usage/ ok
Not run: the GUI suite (no GUI file changed; at 655f8dbd1 it was red
only in TestMainWindowCorners, #3949), an A/B of the page (next).
2026-10-29 00:57:04 +08:00
yetone b7da6cf932 gateway: the fake ChatGPT socket counts a handshake before it reads the message
TestCodexSocketTooBigGoesOverHTTP was red on ubuntu CI at 8273325b0:
"2 posts, 0 sockets; want both turns over HTTP and one socket tried".
The fake counted a handshake after c.Read returned. A message over the
read limit is closed 1009 inside Read, so magpie can see the close and
finish both turns over HTTP before the fake's Read returns and counts.
It now counts right after Accept, which is what "sockets opened, a
refused message's too" says. The gateway is unchanged.

Run on mote (macOS 27), at this tree:
- With a 500ms sleep injected after the fake's Read: the old count is
  red 3 of 3 with CI's exact message; this one is ok -count=3.
- Without injection: go test -race -tags nogui -count=5 -run
  TestCodexSocket ./internal/gateway: ok. gofmt -l clean.
2026-10-29 00:56:42 +08:00
yetone 655f8dbd1c usage: matching by request id keeps no slice an id (#2278)
matchedBlocks kept each request id's gateway calls in a map of slices,
the local calls that named it in a second map of slices with the id
cloned, and each match group behind a pointer. Over a year's calls the
alloc profile of v0.1.1928 on mote (34k session files, 240k gateway
rows, two minutes of polls while an agent worked) had matchedBlocks at
2.5 GB: groups 598 MB, byID 547 MB, byRequest 504 MB, matched/used
463 MB. Now:
- an id is a place in one slice of calls, its first call held in place
  and only repeats in a slice; the map of ids is sized by a count pass;
- the local calls that name an id are one slice, each linked to the one
  found before it, read back in the order they were found, so the order
  (and newestIDs' sort) is what it was;
- the id is looked up, not cloned, and a call with no id is skipped
  before the lookup;
- groups are a slice the map points into.

TestMatchByIDAllocatesNoSliceAnID: 4000 gateway calls with ids, a third
of the locals naming an earlier id again, match as matchedLocalLegacy
does, and the second match makes at most n/10 allocations. Red on the
old code (11,334 allocations), green on the new (168).

Run on mote at the pushed head (rebased onto origin/main 3ec9babe7, no
change to internal/usage since its base 87a983423; rebased again onto
1319a44bb, four plugin and provider commits that touch neither
internal/usage nor internal/sessions):
  go test -count=1 -timeout 45m ./internal/usage/ ./internal/sessions/
    ok (25.9s, 32.2s)
  go test ./internal/gui/: FAIL only in TestMainWindowCorners, the open
    macOS 27 red #3949
  GOOS=linux/windows/darwin go vet -tags nogui ./internal/usage/ ok
Not run: an A/B of the page on mote; it follows with the Codex pairs
change.
2026-10-29 00:52:47 +08:00
yetone 1319a44bbc docs: plugin guide says what four rules do when a plugin gets them wrong (plugins#468)
Guide (en, zh, ja) and provider-plugins.md:
- usage: leave used out rather than send 0; with amount/limit it is their
  share, with no count the window is text and routing doesn't read it;
  aside keeps a window out of routing whatever its count.
- sign-in: a model refused is 403/404, not 401; a 401 that says only
  that the model isn't served is read as kept.
- free comes only from the vendor's word; rate 0 is none given, never
  free (magpie infers nothing from rate).
- GitHub listing licence: from LICENSE as GitHub reads it, else
  package.json's license.

Docs only. Checked each claim against the source at this tree
(plugin_usage.go quotaOfPlugin, plugins.go modelOnly401, fallback.go
modelRefused, plugin/providers.go Model.Rate, models.go FreeModel,
github.go readTagged). Site deployed with wrangler and the pages read
back with curl.
2026-10-29 00:52:19 +08:00
yetone 5957d45ac1 plugin: a GitHub listing takes package.json's licence when GitHub names none (plugins#468)
GitHub's search gives NOASSERTION for a LICENSE file it can't match to a
licence (MIT's text with a line of credit added) and nothing for none;
magpie drops NOASSERTION, so such a card on Plugins > Discover had no
licence, while the same package from npm shows package.json's.
readTagged keeps package.json's license (a string) as PkgLicense, and
License falls back to it, on a fresh read and across searches (fresh).

Run (mote, at this tree): gofmt -l clean; vet on three OSes; go test
-tags nogui -timeout 45m ./...
(go test -tags nogui -timeout 45m ./... at base 5bfd76cd8: 77 packages ok, none failed (log kept whole). Rebased onto 602ad84ad and run again there: vet on three OSes ok; go test -tags nogui -count=1 ./internal/provider (195s) ./internal/plugin (268s) ./internal/gateway (677s) ok. Rebased onto b5d2858f4 and run again: usage, provider, plugin, gateway ok. Rebased onto 87a983423, the pushed base, and run again at this tree: gofmt -l clean; go vet ./internal/... ok, GOOS=linux and windows go vet of provider, plugin, gateway ok; go test -tags nogui -count=1 ./internal/provider (126s) ./internal/plugin (180s) ./internal/gateway (588s) ./internal/codexcat (1s) ok. Then rebased onto 3ec9babe7 to push; its three commits (WorkBuddy mover min, redact, sessions) share no file with this one, and the same packages are run again at the pushed head after the push).
Broken by hand: on the old github.go TestTaggedRepos is red:
"NOASSERTION, package.json MIT: {... License: ...}".
Not tried: the GUI card against a real NOASSERTION repository (the card
reads r.license as before; no GUI file changed).
2026-10-29 00:52:19 +08:00
yetone 1390aa458f provider: a usage window's count is its share when used is left out (plugins#468)
A plugin window that sent amount and limit but no used was text alone
(Text, Aside), and an account whose windows all did so was unknown to
routing, weighed behind accounts it should beat. quotaOfPlugin now fills
Used from amount/limit when both are above 0 and used is absent: 370 of
1000 is 37. An amount of 0 is what a left-out amount reads as, so a limit
alone still says nothing (#3650 unchanged). aside still keeps a window
out of routing whatever its count.

amount is the amount used: the guide ("amount of limit used") and
host.js's usageOf say so, and every community plugin that sends it
(magpie-community/plugins 95fa761) sends the used count, never what is
left: codearts (limit - remain), joycode (item.used), kiro, minimax
(total - left), raccoon (granted - avail), cloudflare-workers-ai, cline
(used, or total - remaining), zcode (used, total - remaining, or
currentValue), gcp-ai (credits.used), copilot (limit - remaining),
trae, workbuddy. None reaches the new path: each of these windows sends
a finite used beside amount/limit. The one that can leave used out,
cloudflare-workers-ai with no Analytics reading, sends amount null,
which reads as 0, so its window stays text as before. The path is for
plugins outside the community repo (GitHub-tagged or local) that send a
count and no share.

Run (mote, at this tree): gofmt -l clean; vet on three OSes; go test
-tags nogui -timeout 45m ./...
(go test -tags nogui -timeout 45m ./... at base 5bfd76cd8: 77 packages ok, none failed (log kept whole). Rebased onto 602ad84ad and run again there: vet on three OSes ok; go test -tags nogui -count=1 ./internal/provider (195s) ./internal/plugin (268s) ./internal/gateway (677s) ok. Rebased onto b5d2858f4 and run again: usage, provider, plugin, gateway ok. Rebased onto 87a983423, the pushed base, and run again at this tree: gofmt -l clean; go vet ./internal/... ok, GOOS=linux and windows go vet of provider, plugin, gateway ok; go test -tags nogui -count=1 ./internal/provider (126s) ./internal/plugin (180s) ./internal/gateway (588s) ./internal/codexcat (1s) ok. Then rebased onto 3ec9babe7 to push; its three commits (WorkBuddy mover min, redact, sessions) share no file with this one, and the same packages are run again at the pushed head after the push).
Broken by hand: on the old plugin_usage.go TestAWindowsCountIsItsShare is
red: "a counted window: Text true, Aside true, Used 0" and "routing:
known false, used 0; want the count's 37".
Not tried: a real plugin sending counts without used (the reporter's
instance isn't named).
2026-10-29 00:52:19 +08:00
yetone 3ec25523cb provider: a plugin's 401 about the model keeps the account's sign-in (plugins#468)
A plugin that answered "this model isn't available on your plan" with 401
marked the account as needing a new sign-in, and the gateway fails a 401
over to the provider's next account (retryable in fallback.go), so every
account of the provider was marked "sign-in has expired" for credentials
that were fine.

notePluginSignIn now reads a 401 that carries no X-Magpie-Sign-In as
"kept" when its body says the model isn't served (provider.ModelUnserved,
the gateway's unservedWords moved here, read decoded by catalog.Words)
and nothing of a token, key, credential, session or sign-in. Only the
first 64KB is read, and the body goes on whole.

Not changed: the gateway still rests the account under its failure
backoff for that answer; modelRefused still reads only 400/403/404/422 as
the model refused. The guide asks for 403/404 (docs commit).

The 401 bodies the community plugins hold for a sign-in that is gone
(magpie-community/plugins 95fa761, every package's tests), each in the
test's "marks" list and none read as kept (none names a model, which
ModelUnserved needs):
- devin: {"code":"unauthenticated","message":"invalid api key" / "bad key"}
- zed: "unauthorized", "", {"code":"upstream","message":"bad key",...}
- cline: {"error":{"message":"nope"}}, {"success":false,"error":
  "unauthorized"}, {"message":"expired"}, "the sign-in lapsed — sign in
  again"
- raccoon: "unauthorized", {"code":200003,"message":
  "authorization_verify_error"}
- joycode: {"code":401,"msg":"登录票据已失效"}, "private-marker"
- zcode: "", {"code":1001,"msg":"Authorization Token非法"},
  {"error":{"message":"token expired or incorrect"}}
- mimo: "", {"code":401}, {"error":{"message":"stale"}},
  {"error":{"message":"Invalid API Key"}}
- cursor: "no", "Unauthorized — sign in to Cursor again in magpie",
  Connect's ERROR_NOT_LOGGED_IN body
- search1api: {"message":"expired"}
No plugin source builds a 401 whose text names a model.

Run (mote, at this tree): gofmt -l clean; go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./...; go test -tags nogui
-timeout 45m ./...
(go test -tags nogui -timeout 45m ./... at base 5bfd76cd8: 77 packages ok, none failed (log kept whole). Rebased onto 602ad84ad and run again there: vet on three OSes ok; go test -tags nogui -count=1 ./internal/provider (195s) ./internal/plugin (268s) ./internal/gateway (677s) ok. Rebased onto b5d2858f4 and run again: usage, provider, plugin, gateway ok. Rebased onto 87a983423, the pushed base, and run again at this tree: gofmt -l clean; go vet ./internal/... ok, GOOS=linux and windows go vet of provider, plugin, gateway ok; go test -tags nogui -count=1 ./internal/provider (126s) ./internal/plugin (180s) ./internal/gateway (588s) ./internal/codexcat (1s) ok. Then rebased onto 3ec9babe7 to push; its three commits (WorkBuddy mover min, redact, sessions) share no file with this one, and the same packages are run again at the pushed head after the push).
Broken by hand: with the check disabled (if false &&),
TestPluginModel401KeepsSignIn is red: "a 401 about the model marked the
sign-in: The model claude-opus-5 is not available on your plan".
Not tried: a real vendor answering a model-level 401 through a plugin.
2026-10-29 00:52:19 +08:00
yetone 3ec9babe7d sessions: the overview points to the sessions it sums up, not copies (#2278)
Stats.Overview copied every Summary (~400 bytes) into its working slice,
then cloned that slice once per Top ranking. Over 34k sessions the
Sessions page's poll allocated ~1.5 GB in two minutes this way while an
agent worked (alloc profile of v0.1.1928 on mote: `in = append` 958 MB,
slices.Clone 557 MB). It now ranks pointers into st.Sessions and copies
only the k sessions each ranking keeps. shapes, toolUse and skillUse take
the pointers.

TestOverviewCopiesOnlyItsTop: a second Overview over 5000 sessions
allocates at most half of their Summaries' size, and its count and
rankings are what they were. Red on the old code (14,923,144 bytes over a
1,020,000 bar), green on the new.

A/B on mote (34,040 session files, 240k-row usage.jsonl, the feed run
of run2278c.sh: 230s, feed from 60s, Usage and Sessions pages polled),
v0.1.1928 code vs this change. mote's load was 47 to 66 from other runs
throughout, so the numbers are noisy:
  avg CPU after the feed starts  122.8% -> 69.4%
  heatmap poll mean               6.97s -> 4.84s
  all polls mean                  3.11s -> 2.16s
  footprint peak                 685.6M -> 626.1M
  footprint at the end           402.8M -> 337.5M

Run on mote, at base b5d2858f4:
  go test -count=1 -timeout 45m ./internal/sessions/ ./internal/usage/
    ok (30.9s, 18.0s)
  go test ./internal/gui/: FAIL only in TestMainWindowCorners, the open
    macOS 27 red #3949
Rebased onto origin/main 7a7931833 (no change to internal/sessions), and
run again at the pushed head on mote:
  go test -count=1 -timeout 45m ./internal/sessions/ ./internal/usage/
    ok (16.8s, 16.1s)
  GOOS=linux/windows/darwin go vet -tags nogui ./internal/sessions/
    ./internal/usage/ ./internal/gui/ ok
2026-10-29 00:48:47 +08:00
yetone 7a79318337 redact: a package's name goes as written, an import's module first (dniray on Discord)
dniray (v0.1.1917): "脱敏会把包名给替换了", with the case
import { and, eq } from ' drizzle-orm ' going out as
from ' {{SECRET_…}} '. The SECRET came from the local model; the rules
left it. AstrLink Guard reproduces the class on mote with
require( ' jsonwebtoken ' ) -> {{SECRET_…}} and a requirements.txt
django-rest-passwordreset==1.4.0 -> {{SECRET_…}}==1.4.0; Privacy Filter
took a pnpm-lock integrity hash (sha512-…==}) for one, eating the }.

A probe of ~60 package shapes (npm scoped and pinned, Java/Android ids,
Go module paths, Python modules, purls, Debian, Cargo, Gradle, Maven,
CocoaPods, lock files) through Preview, rules alone and with both real
models, default kinds and all kinds, found these and fixed each class:

- model, any kind: the module a line of code loads is never PII
  (moduleAt): a quoted specifier after from on an import/export line or
  after } or *, import 'x', require('x'), import('x'), and unquoted
  from x import / import x / use x:: / extern crate x at a line's start.
  A from in prose ("the token from 'Zq8v…'", "copy it from Zq8v…") is
  judged as before.
- model SECRET: a name a version is pinned after (==, >=, ~=, !=, <=,
  ===; pinnedAfter); @ is left out so s3cretPass@10.0.0.5 still masks.
- model SECRET: an SRI hash (sriRe in namesThing).
- secret-named field rule (fieldAt, keyAt, modelTakes): a version or a
  range is no secret value: "js-tokens": "^4.0.0-beta.1",
  jsonwebtoken = "9.2.0-beta1", secretVersion = '2.1.0-alpha03'
  (versionValue).
- user@host (off by default): js-tokens@4.0.0: in pnpm-lock.yaml went
  as a user and a host (notPackagePin); alice@10.0.0.5 still masks.

Left as is: SECRET_PACKAGE=@acme/secret-store-v2 and
PASSWORD_LIB=passlib-1.7.4 (a value under a secret's name, not told
apart from a password), and Privacy Filter's "Dagger Hilt" as a person.

Tests: package_names_test.go. TestPackageNamesGoAsWritten (rules,
default and all kinds), TestPackagePinIsNoLogin,
TestModelPackageNamesNotMasked (dniray's literal bytes first, through
fakeModel), TestPackageNameChecksKeepRealValues (emails, an ssh host,
password=, API_KEY=, a secret-named field with a real value, alice@ip,
a model secret in prose after from, before ==, before @ip).

Run, at b692de9c8 + this change, on mote:
- go test -count=1 -timeout 45m ./internal/redact/... ./internal/masking/...: ok
- go test ./internal/otlp/... ./internal/pii/... ./internal/sessions/...
  ./internal/settings/...: ok; -run "Redact|Mask|Privacy|Unredact"
  ./internal/gateway ./internal/gui: ok
- go vet ./internal/redact/... darwin, GOOS=linux -tags nogui, GOOS=windows: ok
- gofmt -l internal/redact: clean
- probe with real AstrLink Guard and Privacy Filter (MAGPIE_EVAL_CACHE):
  every shape above as written; emails, ssh host and the author's email
  still masked.

Broken by hand, each red: moduleAt off (TestModelPackageNamesNotMasked:
drizzle-orm, reflect-metadata, jsonwebtoken), notPackagePin always true
(TestPackagePinIsNoLogin), versionValue false
(TestPackageNamesGoAsWritten), pinnedAfter off and sriRe off
(TestModelPackageNamesNotMasked).

Not tried: dniray's own text didn't make either model fire alone on
mote (the model reads context), so the fix is held by the fake-model
test and the jsonwebtoken case the real model does fire on; the eval
recordings were not re-recorded (no eval case added); the full
./internal/gateway and ./internal/gui suites.
2026-10-29 00:45:18 +08:00
yetone b692de9c89 provider: WorkBuddy's mover min is 0.1.45, so magpie's drawings through WorkBuddy work again
iwinux on Discord (10-28 ~22:30 UTC+8, magpie v0.1.1812): the Magpie Image
MCP through WorkBuddy AI answered
  400 Bad Request: Unmarshal create image params failed with error:
  invalid character '\x1f' looking for beginning of value (11101)
from the minute plugin 0.1.43 was published (14:30Z). 0.1.43 gzipped every
non-Messages body its fetch sent, and drawWorkBuddy's JSON to
/v2/images/generations and /v2/images/edits goes through that fetch; the
images API reads plain JSON only ('\x1f' is gzip's first byte). magpie
passes the JSON through unchanged. 0.1.45 (plugins 880cd93) gzips only a
chat completion, and gives only a chat the model's default effort.

npm view @magpie-community/opencode-workbuddy-auth version --prefer-online:
0.1.45.
Run at this head (parent 87a983423): go test -timeout 45m ./internal/provider
on mote: ok; gofmt -l clean. The plugin's own record (red on 0.1.44 with
the reporter's message, 207 pass on 0.1.45) is in plugins 880cd93.
Not tried: a real WorkBuddy drawing through the plugin host.
2026-10-29 00:41:49 +08:00
yetone 87a983423e codexcat: Codex's own GPT models stay in the Codex app's first 100 whatever the user's order (maiya on Discord)
maiya (Discord): after updating, the Codex app lists magpie's models and
none of Codex's own GPT ones.

Cause: the Codex app and its VS Code extension read the first 100 of the
list by priority (codexcat.AppList). codexMerged ranks the list by the
user's order from the Agents page (codexcat.Order, #855), where a model
the order doesn't name goes after every one it does, and codexcat.Fit
only brought the models Codex used back into the 100. The GUI saves the
whole shown list as the order, so an order saved while Codex's list had
no Codex section (the codex provider kept for routing groups before
a3ee00c05, Codex not yet signed in, or a GPT model OpenAI added since)
names 100+ of magpie's models and none of the account's: every unused
GPT model then landed at 101+ and was in no picker of the app. Since
add927e60 the app's desk list (CodexDesktopCatalog) is codexMerged's
too, so this reaches the app beside the ChatGPT sign-in, not only the
backend list.

Fix: codexcat.FitOwn keeps Codex's own listed models in the first 100
ahead of the used ones, in the order they stood; hidden entries still go
last, and a model the user hid in Codex's list was already taken out
before (CodexNativeHidden/CodexNativePicked). codexMerged passes the
backend's slugs; the siblings, /v1/codex/models (codexCatalog) and the
model_catalog_json file (CatalogUsed), pass a ChatGPT account's codex/...
entries (codexcat.ChatGPTOwn). Fit is FitOwn with none. Documented in
docs/subsystems/gateway-routing.md.

Tests:
- gateway TestCodexModelListKeepsOwnModelsInTheAppsHundred: the exact
  setup (ChatGPT sign-in, 130 magpie models, a Codex order naming all 130
  and no GPT model, the backend listing gpt-6-sol, gpt-5.5 and the hidden
  codex-auto-review): on 298bfce59 gpt-6-sol and gpt-5.5 were at 131 and
  132; now in the first 100, auto-review last, magpie's first 98 in the
  user's order.
- codexcat TestFitOwnKeepsCodexsOwnInTheAppsHundred and
  TestCatalogUsedKeepsChatGPTOwn.

Broken by hand: FitOwn with own forced to nil: all three red (131/132,
priority 131); restored, green.

Checked and not real (no change): CodexNativeHidden hiding an own model
while another ChatGPT entry for it is picked. There is one ChatGPT
provider ("codex"), one entry per slug however many accounts are saved,
and catalogOf adds an unlisted own entry once. A probe test (two
accounts, only-picked with both picked, a group that Unlists gpt-5.5, a
plain group, the provider Unlisted, back to hide mode) kept both slugs
out of CodexNativeHidden and in /backend-api/codex/models at every step
on 298bfce59.

Run (mote-run, this tree on 298bfce59): gofmt -l clean; go vet,
GOOS=linux go vet -tags nogui and GOOS=windows go vet on codexcat and
gateway: ok; go test -tags nogui -count=1 -timeout 45m ./internal/codexcat
./internal/gateway ./internal/provider ./internal/agent: all ok
(gateway 633s). Rebased onto b119f8777 (it changed codex_backend.go
elsewhere): gofmt, the three vets and go test ./internal/codexcat
./internal/gateway again: ok (gateway 627s).
Rebased again onto b5d2858f4 (internal/usage), then 40f206dff (vertex): gofmt, vets, codexcat and
usage ok, gateway -run Codex ok (54s); the whole gateway package not rerun.
Not run: the full suite (another session's full run was on mote).
Not tried: a real Codex app or VS Code extension, or maiya's own
settings (her order and provider setup are inferred, not seen).
2026-10-29 00:37:44 +08:00
yetone 40f206dff1 vertex: partner models (DeepSeek V4.1 Flash, GLM, gpt-oss) go to Google's OpenAI-compatible chat completions
Dani Ariyanto (Discord) asked for Vertex AI's partner/open models, such as
DeepSeek V4.1 Flash, beside Gemini. Google serves them (Model as a Service)
on an OpenAI-compatible chat completions endpoint in the same project,
https://<host>/v1/projects/<p>/locations/<loc>/endpoints/openapi/chat/completions,
with the same OAuth token. The model goes in the body as publisher/model
(deepseek-ai/deepseek-v4.1-flash-maas). Source: Google's
maas/call-open-model-apis page.

An existing Vertex provider needs no change. A model id with a slash
(VertexPartner) is a partner model, as is every publisher/model id that
models.dev lists for google-vertex as @ai-sdk/openai-compatible. It is
asked on Base(Chat) = <project base>/endpoints/openapi (ListedAPIs, so
ModelAPI can't move it). Gemini ids have no slash and stay on
streamGenerateContent. Speaks is now [chat, gemini].
- vertexEffort (Gemini's levels) no longer applies to a partner model.
  Before, a Codex xhigh was clamped to high.
- The provider's own test probes Gemini only. A partner model answers
  only after the project enables it in Model Garden, so an unenabled
  partner model would turn every Gemini user's test red. A partner model
  is tested by its own model test.
- tinyBody's chat probe uses Base(Chat), so the probe goes to the openapi
  address. That address is the only one Sign lets the token go to.
- A test as Codex is refused for Vertex, as it already is for Claude Code
  ("only of a relay").

The global list adds the three partner models that Google's docs list as
live at global on 2026-10-28:
- deepseek-ai/deepseek-v4.1-flash-maas (Preview, global only)
- zai-org/glm-5.2-maas
- openai/gpt-oss-120b-maas

Left out of the list: Gemma 4 (Experimental) and the models retired on
10-21 (v3.x, glm-4.7/5, qwen3, llama-3.3...). Gemma 4 still routes when
typed in by its full id. us/eu/regions are unchanged.

Docs: providers-accounts.md and gateway-routing.md Vertex rows;
reference.md (the global row, how a partner id routes, Model Garden
enablement, typing one in).

Run (on mote via mote-run):
- go test -tags nogui -run TestVertex ./internal/provider ./internal/gateway: ok.
- New: TestVertexPartnerModel (gateway). It covers Chat, Anthropic and
  Responses clients, streamed and whole, against a fake openapi endpoint
  answering in the shape of Google's docs. It checks the path, the Bearer
  token, the body model and the client's text, that Gemini stays on
  streamGenerateContent, and that xhigh is kept.
- New: TestVertexPartnerModels (provider). It covers Speaks/Base,
  APIs per model, the global list, no partner model at us/us-central1,
  that Test() probes Gemini alone, and TestModels on openapi with the
  minted token.
- TestVertexProviderListed now pins Speaks [chat gemini].
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./...: all ok; gofmt -l clean.
- Full suite: go test -tags nogui -count=1 -timeout 45m ./... at
  80f2bda50 (this change on cb167fcbd): SUITE-EXIT=0, 77 packages ok.
- An earlier full run at base 396e0e463 was red only in
  TestPluginStreamsPastTheBudgetWait. That is #3946, fixed in 7fd77a944
  after that base. It passed 3 of 3 alone at origin/main cb167fcbd.
- The final rebase onto b5d2858f4 (usage, a gateway test, LESSONS) was
  followed by go build and the TestVertex runs again; the suite was not
  run again.

Broken by hand:
- All nine non-test files restored to main, with VertexPartner kept so
  the tests compile: TestVertexPartnerModel red (asked
  publishers/google/models/deepseek-ai/...:streamGenerateContent with a
  Gemini body), TestVertexPartnerModels and TestVertexProviderListed red
  (speaks [gemini]).
- vertexEffort guard removed: red, "effort xhigh sent ... as high".
- Test()'s Vertex chat skip removed: TestVertexTestRequest and
  TestVertexPartnerModels red (a chat probe of the partner model).
- tinyBody back to q.Chat: TestVertexPartnerModels red ("asked only at
  Vertex AI, at its project's address").

Not tried:
- No real Vertex AI account or project here. Nothing reached Google:
  the endpoint, auth and response shapes come from Google's docs only.
- Per-model thinking controls (chat_template_kwargs: DeepSeek thinking,
  GLM enable_thinking) are not mapped. A partner model gets the generic
  chat completions reasoning_effort, and gpt-oss takes it natively.
- Claude on Vertex (publishers/anthropic rawPredict) is out of scope. It
  takes its own request shape and its ids have no slash.
- No GUI change (the API picker reads URL fields, which Vertex has
  none of), so no GUI suite was run.
2026-10-29 00:33:50 +08:00
yetone b5d2858f41 usage: matching gateway calls decodes only the session files they can match (#2278)
matchedBlocks paired the gateway's calls with the session files' by
request id, then by session, tokens and time, and decoded every session
file of the period for each pass: twice per poll, for the few sessions
the gateway had calls of. In a 24s heap profile of a fed sandbox it was
0.77 GB of the 5.3 GB allocated, and 5.4s of a minute's 42s of CPU.

Each local chunk's hints are now kept by its serial (match_chunks.go,
as chunkIDs keeps Codex's response ids): a 32-bit hash of each request
id it names, a hash of each session a call of it can be matched in
(agy's as agyMatchSession, rows of no tokens and no failure left out,
as the pass does), and its last call's time. A pass decodes a chunk
only when one of its ids or sessions is the gateway's and its last call
is in the period. A hash that matches only decodes the chunk, so the
matches are exact. Hints live 8 matchings past their last use.

Run at this head (cb167fcbd + this change), on mote:
- TestMatchOpensOnlyNamedChunks (new): 20 seeds of 12 session files, the
  gateway naming four sessions and one id in a fifth file; the matches
  equal matchedLocalLegacy's and only named files are decoded. Red with
  namesAny always true ("matching decoded /local/session-4").
- TestMatchOpensAgyChunks (new): an agy step is matched with its file
  alone decoded.
- go test ./internal/usage -timeout 45m: ok (26.9s).
- go vet -tags nogui ./internal/usage for darwin, linux and windows:
  clean.

A/B on mote, the sandbox of #2278's synthetic history (34k sessions,
3000 with gateway records), 10 page endpoints polled every 5s and 4
gateway appends a second, 230s each, old = dc6f6d902 (v0.1.1927):
                       old        new
  all polls mean     4.93s      3.15s
  heatmap mean      11.86s      7.24s
  footprint peak    707.2M     632.4M
  avg CPU after feed  90.0%      79.6%
mote's load was ~100 from other sessions' suites through both arms, so
the times are slower than an idle machine's; the arms ran back to back.
Then rebased onto b119f8777, which changes an internal/gateway test and
LESSONS.md only.

Not tried: the user's own history.
2026-10-29 00:25:57 +08:00
yetone b119f87771 LESSONS: a change to when a value appears re-reads every wait on it (3dd59428e) 2026-10-29 00:20:20 +08:00
yetone 3dd59428e4 gateway: TestClaudeRunsNamesEachProcess waits for the hung run's pid, not only two runs
Red on ubuntu CI under -race at 5bfd76cd8 (run of the Test workflow):
"the run answering, pid 42298, is listed as {PID:0 ...}". The wait took
a listing first and read hang.pid after it. A listing made while the
second run's launch had started Claude Code but not yet set its tree
(983fff23d reads the pid only once the tree is set) has that run at
PID 0; by the time the condition read hang.pid the fake had written
it, so the wait ended on a list without the hung pid. The condition
now also needs a run listed with that pid, which is the state the
check after it is about.

Run on mote (macOS 27), at this tree:
- Injected a 500ms sleep in claudeRuns for a run listed at PID 0 (and
  300ms in launch before the tree is set): the old test is red 3 of 3
  with CI's exact message, this one is ok -count=3.
- Without injection: go test -race -tags nogui -count=5 -run
  TestClaudeRuns ./internal/gateway: ok. gofmt -l clean.
Not changed: the listing itself; a run whose launch hasn't set its tree
yet is listed at PID 0, as before.
2026-10-29 00:19:58 +08:00
yetone cb167fcbd8 usage: CodexModelEffort's allocation bar is a packed row a call, not a visit (#2278)
TestCodexModelEffortLetsUnrelatedCallsGo held a build of
CodexModelEffort to a visit of the log and a half. Since dc6f6d902 a
visit decodes into a lent buffer, and allocated 74 KB or 289 KB as the
pool kept that buffer through the test's GC or not, so the bar moved
under a build of ~430 KB and the test was red now and then (1 of 2 runs
on mote at the change below, "a build allocated 430336 bytes, a visit
73848").

The bar is now what #2776 was about: a build over 3000 unrelated calls
allocates less than one packed row (216 B) for each of them, 648 KB.
Builds measured 215 to 430 KB.

Run at this head, on mote:
- go test ./internal/usage -run TestCodexModelEffortLetsUnrelatedCallsGo
  -count=30: ok.
- go test ./internal/usage -timeout 45m: ok (23.2s).
Not tried: reverting #2776's fix to see the bar go red.
2026-10-29 00:14:17 +08:00
yetone dc6f6d9022 usage: a read of the gateway log decodes its blocks into one buffer (#2278)
logSnapshot.visit unpacked each block of usage.jsonl's snapshot into rows
of its own. Every Sessions, Usage and Routing poll reads the log through
it (buildGatewaySessions, topSummary, buildVias), so while calls came in
it allocated ~800 MB of rows a minute: 1.3 GB of the 5.3 GB a 24s heap
profile of a fed sandbox allocated was unpackReusing's rows, strings and
text under visit. It now decodes every block into one chunkRows buffer,
each over the one before, as the page's other readers do. A record's
strings are the block's own text, not the buffer's, so fn may keep them.

Run at this head (b69f8e96a + this change), on mote:
- go test ./internal/usage -timeout 45m: ok (24s).
- TestLogVisitReusesItsRows (new): visit's records equal a per-block
  unpack's, and one visit of 20000 rows allocates at most a quarter of
  their rows. Red on the old visit (4506304 > 4320000 bytes), green now.
- go test ./internal/gui -timeout 45m: ok but TestMainWindowCorners,
  red the same as before this change (#3949).
- go vet -tags nogui ./... for darwin, linux and windows: clean.

A/B on mote, a sandbox HOME with #2278's synthetic history (34k
sessions, 3000 with gateway records), 10 page endpoints polled every 5s
and 4 gateway appends a second, 230s each, old = v0.1.1923:
                       old        new
  all polls mean     1.69s      1.09s
  heatmap mean       4.54s      2.94s
  footprint peak    648.9M     615.5M
  avg CPU after feed  70.9%      70.3%
Another session's GUI suite ran on mote through both arms, so CPU is
noisy; the poll times are the point.

Rebased onto c5cdb043e (no internal/usage change in between), then run
again there: go test ./internal/usage ok (27.7s); go vet -tags nogui of
internal/usage and internal/gui for darwin, linux and windows clean.
Then rebased onto 8273325b0, which changes site/ only.

Not tried: the user's own history; the A/B's history is made up.
2026-10-29 00:09:24 +08:00
yetone 8273325b05 site: Sidrune AI has a China and a Global site, picked by where the user is
Sidrune reported (10-29) that it runs two sites whose keys don't cross:
China at sidrune.ai and Global at global.sidrune.ai, and its website
sends a browser to one by language. magpie listed the China site only,
so a user abroad who signed up on Global and pasted that key got 401
Invalid API key. They asked for a Global / China choice that moves the
endpoints and the key link with it.

Sidrune's entry is now two regions instead of top-level endpoints:
China (cn: sidrune.ai/v1, sidrune.ai) and Global (global:
global.sidrune.ai/v1, global.sidrune.ai), each with its own key link
(register?promo=MAGPIE3 on its site) and website. With regions named
China and Global, the app's existing paths take over (ef155a5ca): the
editor shows a picker, Get a key and the site link follow the region, a
new provider starts at China's in mainland China and Global's elsewhere,
and the two keep separate accounts (SplitAccounts).

Providers added before keep their endpoints: a provider stores its own,
and its region is read from them, so existing users stay on China.

Checked: global.sidrune.ai/v1/models and /v1/messages answer
API_KEY_REQUIRED without a key, as sidrune.ai does;
global.sidrune.ai/register?promo=MAGPIE3 answers 200;
global.sidrune.ai/ redirects to sidrune.ai/, their landing page.

Run on mote: node --test site/*.test.mjs, 45 of 45 pass. go test
./internal/provider -run TestPartner, all pass. A throwaway test fed
worker.js served() over this partners.js to the app and found Sidrune
valid, a new provider at sidrune.ai in China and when the zone is
unknown and at global.sidrune.ai abroad (key and site /go links with
/cn and /global), SplitAccounts set, and a provider at sidrune.ai
still at China after the user moves abroad.

Not tried: a request with a key on either site, and the editor's
picker for Sidrune in the GUI.
2026-10-29 00:07:00 +08:00
yetone c5cdb043e6 routing: a request held before routing says so, not "0 on" and one account
Jason on Discord (v0.1.1818): the Routing card read "magpie · 0 on",
gave the one-account hint and "Nothing could take ." while his
ChatGPT Pro accounts were healthy. His client (AirbuildEnvironment)
sends Codex turns to /backend-api/codex/responses. A request held over
15s before routing (masking, Settings › Privacy) gets the unrouted
watch's placeholder route; codexBackend never called noteAsked, so the
placeholder had no model, and the card read its empty order as zero
accounts on and one account. The requests themselves were held, then
routed; only the page was wrong.

- codexBackend notes the asked model, as handle and gemini do.
- The card: an empty order says masking…/routing… (or nothing when
  done) instead of "{n} on", hides the chip, and its line says why
  (masking before routing, not routed yet, or the error it ended
  with). The one-account hint needs exactly one account on.
- New keys in zh, zh-TW, ja, de.

Run (mote, at c12d2f130's tree before rebase onto 298bfce59):
- go test -tags nogui -run TestUnrouted ./internal/gateway: ok.
  TestUnroutedCodexPathShowsItsModel is red with noteAsked removed
  (placeholder Model "").
- GUI: routing-held-request (new, 60 cases: chromium+webkit, en zh
  zh-TW ja de, masking/routing/ended, 1100 and 420px) and
  routing-mode-goes: 100 pass, 0 fail. With the old client.js the new
  file is 60 of 60 red.
- go test -tags nogui -timeout 45m ./...: 75 packages ok; the only red
  is internal/provider TestClaudeAccountServesModelsListedSinceItsFetch,
  #3174, unrelated.
- After rebase: gofmt -l clean, go build -tags nogui ./... ok.

Not run: the whole GUI suite (routing-*, i18n-*, gui-* files were
running, 35 ok and 0 not ok when pushed); a real AirbuildEnvironment
client; masking with a real local model.
2026-10-29 00:01:58 +08:00