Commit Graph
1737 Commits
Author SHA1 Message Date
yetone d1fa254b1d gui: masked words and Never mask are a list, a row per word (noahhrreion on Discord)
noahhrreion: "希望脱敏词选项可以做成真正的列表,在一个小输入框里面不方便管理多个脱敏词".
Settings → Privacy's Masked words was one comma-separated box. It is now a
list (wordList in plugins/redact/settings.js): each word is its own row,
edited in place (Enter or leaving the row saves, Escape puts it back,
emptied is removed), × removes it, and the last row adds. Its sibling,
Never mask under the mask actions, had the same box and gets the same list.

Stored values are unchanged: redactWords and the allow list are still
string arrays, saved through the same savePrefs / settings/redact-allow
calls, and nothing is rewritten on open (the new test checks that opening
the page saves nothing). Typed or pasted text splits as the old box did
(, , and newlines, trimmed, empties dropped), so a pasted "a, b" is two
rows. The Hide eye still shows every row as dots. New strings are in the
redact plugin's i18n for zh, zh-TW, ja and de; the two old "separated by
commas" hints are gone from the core i18n. The site's masking docs (en, zh,
ja) say a row each.

Run (on mote via mote-run, Chromium and WebKit):
- new redact-words-list.test.cjs: 5 languages × 1100/400px × both engines,
  draw, add with Enter, paste-split, edit, Escape, ×, empty-and-Tab, reload;
  with i18n-keys 24/24 ok
- redact-words-hidden, any-case, whole, mask-actions, redact-route,
  redact-kinds, redact-shape, settings-search, settings-sections,
  settings-lines-wrap, settings-hints, settings-groups, readable-focus,
  masking-records, mask-alert: 378/378 ok
- go test ./internal/gui/ -run 'TestCoreScriptBudget|TestSettings': ok
  (app.js shrank; no budget raised)
- screenshots light/dark, 1100/400px, both engines, looked at

Broken by hand: without wordFocusBack (focus kept across a redraw) the new
test goes red (waitForFunction timeout after the first add). Dropping the
blur guard during a redraw (wordsRedrawing / isConnected) stays green in
both Playwright engines, which fire no blur on removal; it is kept as a
guard for engines that do, with no test that fails without it.

Not tried: the real app on WebKitGTK / Windows WebView2; no Go files changed.
2026-11-04 12:38:10 +08:00
yetone 43345c0ca8 docs: gateway-routing names the GPT ids sent output_config.effort 2026-11-04 11:33:01 +08:00
yetone 247794c613 codex: an account that is out takes over for other models too (reverses f37742e14)
With one ChatGPT account out and nothing to serve Codex's own model on
(provider.CodexServesWhileOut false), f37742e14 left Codex on its sign-in
to keep the account's menu. But the Codex app greys Send for every model
while authMethod is chatgpt and /wham/usage says not allowed, so shamen
(mac, banner "Codex 和工作使用额度已用完"), chenhan and xiaoq6285 could send
nothing on GLM-5.3 or any other magpie model. A grey Send for every model
costs more than the menu, so this is the owner's product call: sending on
other models comes first.

When joined, on ChatGPT and held, and magpie has a model on no ChatGPT
account (codexOtherModel), Sync makes magpie the provider on that
stand-in, keeps the user's model in codex.out_own and the stand-in in
codex.out_stand, and at the reset puts Codex back joined on its own model
(#540 way back). Once per held/unheld transition: on the stand-in the model
is magpie's, so the branch is not met again. With nothing else to offer,
Codex stays on its sign-in as in f37742e14. Nothing about identity,
base_instructions or the account's state is changed or faked; magpie only
becomes the provider, as for any held account.

Run (mote-run, win-run, sandbox HOME, fake upstream; no real exhausted
account was tried):
- go test -tags nogui ./internal/agent -run Codex: ok; ./internal/provider
  -run CodexServes: ok; win-run ./internal/agent: see the tag notes.
- gofmt -l, go vet linux/windows/native on internal/agent: clean.
- New TestCodexOwnModelOneSpentAccountTakenOverForOtherModels: takeover,
  three more Syncs with no config write and no codexAppRoute change, the
  reset back once, a further Sync changing nothing. TestCodexOwnModel-
  OneSpentAccountStaysOnItsSignIn now covers only the nothing-else case
  (fake provider deleted).
- Broken by hand: new branch disabled -> the new test red; the
  !isMagpie(m) one-shot guard removed -> red.
Not tried: a real exhausted account in the Codex app; the stand-in picked
by the user is indistinguishable from staying on it and gives way to the
own model at the reset (documented in agent-wiring.md).
2026-11-04 10:05:32 +08:00
yetoneandSKYhuangjing 2741b749f9 sessions: a codex fork's rollout-<n> turn does not end the copied head (#5090)
ownTurn ended a Codex fork's copied head at the first turn id the parent's
file didn't hold (fb1f4856a). codex-rs names a turn that has no id of its
own "rollout-<n>" (the rollout canonicalizer's implicit turns; the
thread-history builder), and a copied head can carry one the parent's file
lacks. It was taken for the fork's first own turn, so every copied
checkpoint after it was booked as the fork's call: July and August usage
that was the parent's history over again. Reporter: SKYhuangjing, whose
fork branch codex-fork-head-marker (acb034645) this ports.

ownTurn now leaves a "rollout-" turn id alone. callParseVersions and
parseVersions raise codex to 3, so kept shards and call caches are read
again once (the same one-time re-read the codex 2 raise cost).

Changed from the patch: the code comment and the subsystem page
(docs/subsystems/gateway-sessions.md) say what codex-rs does, not what
the reporter's corpus showed; the test comment names #5090.

Checked, not changed: ZCode's fork path (zcDB.copied) matches copies by
the original message id and never reads a turn id; ownTurn has one
caller (codexUsageState.context).

Run (mote-run, at this tree on origin/main + this commit):
- TestCodexForkHeadMarkerDoesNotEndTheCopies red with ownTurn as on
  origin/main (4 calls on the fork, want 1), green with the fix.
- go test -count=1 ./internal/sessions ./internal/usage ok; gofmt -l clean.
- GOOS=windows and GOOS=linux go vet ./internal/sessions clean.
Not tried: the reporter's real database (we have no copy of their
corpus). Not confirmed: codex-rs main has no writer that puts a
turn_context with "rollout-<n>" into a forked file from
record_initial_history, as the issue says; the prefix is confirmed from
the two codex-rs writers above, but which one produced the reporter's
files is unknown. Not handled: a fork whose own first turn is itself a
"rollout-<n>" (a legacy rollout migrated with no ids) still doesn't end
the copies by turn id; checkpoints still match it as before.

Full suite: run after the push, result on #5090.

Co-authored-by: SKYhuangjing <13705011+SKYhuangjing@users.noreply.github.com>
2026-11-04 09:10:52 +08:00
yetone 90bf96a23d search: a plugin can give a web search API (its search hook)
treeman on Discord #help asked for web search to be pluggable so users can
add search vendors. A plugin's `search` hook, {search: {<id>: {name, keysURL?,
keyOptional?, url?, execute({query, count, key, url}, ctx)}}}, adds an API to
Settings > Models > Web search as `<plugin>:<id>`. It is added, keyed, ordered,
switched off and removed like Tavily or Brave. The built-in APIs stay built in.

How: host.js collects the hook's entries (id [a-z0-9-], an execute) into
Loaded.Searches and runs one with the `search` op (timeout from ctx, an error
with a numeric status comes back as a refusal). The host notes them in
plugin-searches.json (internal/plugin/search.go); provider.AllSearchVendors
adds the noted ones of plugins that are on to SearchVendors, so Ready, check,
the CLI and the GUI list see them. askSearchAPI hands a plugin vendor to
askPluginSearch below askSearchAPIKeys, so keys, rest on 401/402/403/429,
order, the masked query and the request-log row are the built-ins' own.

Run (mote, on this tree, whose base df7c94bdf was just fetched):
- go test -timeout 45m ./internal/plugin ./internal/provider ./internal/gateway
  ./internal/cli: ok.
- go vet native; GOOS=windows go vet plugin, provider, gateway, cli: ok;
  GOOS=linux go vet plugin, provider, gateway: ok. gofmt -l: empty.
- internal/gui: TestCoreScriptBudget and TestMainWindowCorners fail in a
  full run. This change touches no script (only api.go's loop), so the
  budget red is the base's (re-checked after the rebase, below);
  TestMainWindowCorners is AppKit on mote (macOS 27).
Broken by hand: skipping off plugins in NotedSearches turns TestPluginSearch
red; the refusal mapping removed turns TestPluginSearchAPI red.
Not tried: a real plugin against a real vendor's API; the GUI JS suite (no
GUI script changed); a Linux or Windows window; site/public/docs (en, zh, ja)
do not describe the hook yet. A plugin just added is listed once the host has
loaded it; RestoreSearchAPIs drops a plugin's entry on a machine without it.
The community README has the template (magpie-community/plugins 3ec42d4).

Reported by treeman.
2026-11-04 08:37:21 +08:00
yetoneandMYCF711 df7c94bdf5 gateway: inline image descriptions survive a restart (#5121)
The vision description cache (Server.sights) was in memory only, so a
restart, update or handover described every image of a long conversation
again (62 calls in 2.5 minutes in the report). Completed descriptions of
inline images are now appended to vision-cache.jsonl (0600) in the config
dir before their waiters are released, and New restores them under the
same 2048-entry LRU. URL images stay in memory (their bytes can change);
failures are never written. Appends and compaction go through a file lock,
a corrupt or truncated line is skipped (and backed up before compaction),
and shutdown waits for pending saves within the drain window.

Patch by MYCF711, applied clean on main. One change: the Unix permission
test now makes the config folder before it pre-creates the file (it failed
on a fresh sandbox, where the folder doesn't exist yet).

Run (mote, at this tree): go test ./internal/gateway filtered to the
vision/sight/cache tests, ok; gofmt -l clean; go vet ./internal/gateway
for linux and windows, clean. Broken by hand: saveSight call removed from
see(), TestDescriptionSurvivesGatewayRestart red (2 descriptions, want 1),
green again with it back. Windows: the same filtered tests on xiaomi-gpu
via win-run. Not tried: full go test ./..., go vet ./... for linux (wails
cgo doesn't build off-platform on mote), a real process kill or a real
handover, a real gateway with a real vision model.

Co-authored-by: MYCF711 <323101370+MYCF711@users.noreply.github.com>
2026-11-04 07:57:43 +08:00
yetone 6673171595 update: the app and magpie web follow each other's update (visamzh on X)
visamzh on X: with the desktop app and magpie web both open, an update
from either side left the other still offering it ("↑ 更新") until it was
quit by hand.

Cause: the app and magpie web are two processes over one program, each
with its own updater (state, download, latest) in memory. One restarting
to update puts the new binary in; the other is told nothing. Its
replaced() (the binary on disk is no longer the one it started from) was
read only on a click of its own Update or on magpie update's gateway ask
(restartBeside), which reaches only the process serving the gateway. And
a browser's page reloaded (backAsNew) only after a restart it asked for
itself, so magpie web's tab kept the old page and its pill even once
the process under it was new.

Fix:
- followReplaced (update_beside.go): every updater stats its binary each
  5 s and, once another magpie replaced it, restarts into it through
  restartBeside, once: at once when idle, else after the gateway's
  requests (waitIdle), as for magpie update's ask. Not for what this
  process put in itself (installed, set by install, cleared by
  wontStart), not twice (followed), not for a build that isn't a release
  (make dev, go build rebuild in place). It stops with backendCtx, so a
  copy left draining after a handover doesn't look.
- waitFor (update_wait.go): a wait for the gateway restarts into what
  another magpie put in whatever the feed says now; before, a feed out
  of reach or a "latest" answer ended the wait with nothing restarted.
- boot.js names the version that served the page (bootPrefs.version);
  app.js's servedAnew reloads a browser's page (web) when /api/update's
  current names another, on the reads it already made (load, focus, back
  into view) and once a minute while shown. The app's own windows come
  back with their new process and are left alone.
- docs/subsystems/gui-shell.md describes it.

Run (mote, through mote-run, at 1e1068c86 + this change unless said):
- gofmt -l internal/gui: nothing.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go
  build: all ok.
- go test -tags nogui -race -count=5 -run
  'Follow|AnotherMagpies|OwnUpdate|OwnBuild|UpdateClicked|Wait|Beside|
  Restart|Install|WhatsNew|Quiet' ./internal/gui/: ok (102.9s).
- go test -tags nogui -timeout 45m ./internal/gui/... ./internal/cli/...
  ./internal/update/... . : gui, update, update/launcher and magpie ok;
  internal/cli red in TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red the same on origin/main
  51fa4b7eb alone, filed as #5026 (from 0872bc2a0).
- node --test internal/gui/tests/update-served-anew.test.cjs: 34/34
  (Chromium and WebKit; en, zh, zh-TW, ja, de; 1100 and 420 wide; the
  minute poll under page.clock; the app's window not reloaded).

Broken by hand, each red, then put back:
- followReplaced never restarting: TestAnotherMagpiesUpdateRestartsThisOne
  and TestAnotherMagpiesUpdateWaitsForTheGatewayThenRestarts red.
- the installed guard dropped: TestOwnUpdateIsNotFollowedAgain and
  TestUpdateClickedOverAnothersIsNotFollowedAgain red (a second restart).
- waitFor's "in" case off: TestAnotherMagpiesUpdateWaitsForTheGateway
  ThenRestarts red (the wait ends with nothing restarted).
- boot.js without the version: TestBootNamesTheVersionThatServedThePage
  red.
- servedAnew not reloading: 15 of 16 subtests red in Chromium.
- the minute poll removed: the 5 "left on screen" subtests red in WebKit.

A first cut also refused a second install() once one was in; that made
TestRestartBySelfComesBackQuietly and TestWhatsNewQuietAfterRestartTo
Update red (they restart one updater several times), so the flag only
keeps followReplaced off.

Not tried: a real pair of the app and magpie web on two release builds
with one replacing the binary (only temp files and fakes); Windows
(InstallBinaryAside starts the staged file there, so the own-install
test is skipped and the click test covers the flag) and Linux runs;
the whole GUI suite: mote was never free (two other sessions' full GUI suites, load ~400), so it runs on the Linux box after this lands.
2026-11-04 06:59:29 +08:00
yetone 0e1054ce19 statusline: the gateway serves Claude Code's status line to another computer (steven_4422)
steven_4422 (Discord) runs magpie in Docker and Claude Code on the host.
The status line square writes the host's settings.json, which the
container can't reach, with a command naming a binary inside the container.

GET or POST /v1/magpie/statusline answers the line `magpie statusline`
prints, as text/plain, so the host needs only curl:
  curl -fsS -m 1 -H 'Authorization: Bearer <key>' --data-binary @- http://<host>:3425/v1/magpie/statusline || true
Claude Code's stdin JSON (session_id) adds the model, as /v1/magpie/route
does; ?session= and ?only= work too. The renderer moved to
provider.StatuslineText, shared by the CLI and the endpoint. A caller that
isn't this computer needs a gateway key (lanGuard, unchanged; the handler
also refuses a non-local caller without one). A read-only key is allowed
(GET and POST in readOnlyRoutes) and gets the windows without the model; a
key held to budget, models or accounts sees only its own (scopeQuotas).
corsGuard and origin checks are untouched.
magpie web shows the command in Settings -> About (en, zh, zh-TW, ja, de).
Docs: reference.md, agent-wiring.md, gateway-routing.md, docker pages en/zh/ja.

Run at this head (rebased on d8b3749ef), on mote:
- go build, gofmt -l, GOOS=windows go vet and GOOS=linux go vet -tags nogui
  on gateway, cli, provider: clean.
- go test: internal/gateway ok (a first full run failed once, 888s, name not
  kept; the rerun had no failure), TestStatusline*, TestReadOnlyKeyEveryRoute,
  TestStatuslineEndpointIsTheCLIsLine ok. internal/agent ok earlier, at the
  pre-rebase base.
- TestCoreScriptBudget ok after shortening the new strings (no raise).
- GUI: statusline-remote (22: 2 engines x 5 languages x 1100/400, plus the
  app without the row), public-url-default, i18n-keys, claude-statusline: all pass.
Broken by hand: model made wrong -> TestStatuslineEndpoint red; held-key
scope removed -> red; separator changed in the shared renderer ->
TestStatuslineEndpoint and cli TestStatuslineTellsRouteAndEveryAccount red;
the row's web check inverted -> the GUI test 0 of 22. Removing the
handler's own key check stays green because lanGuard refuses first (the
401 asserts hold through it).
Reds not from this change: cli TestEveryRouteHasACommandOrIsNamed
(GET /api/context/reply, from main), gui TestMainWindowCorners (red on
origin/main on mote), provider TestMoveToPlugin and TestMoveCutShort (red in
the full run, green alone).
Not tried: Docker or any container (not on mote or WSL); the real binary
from another computer over the LAN with a real Claude Code; the whole GUI
suite (running, 1182 files, finishes after the push); Windows and Linux
test runs.
2026-11-04 06:39:37 +08:00
yetone 59c1306035 claude: an auto-mode client's tool loop keeps its interactive run (#4804)
Auto mode's safeguards change with every tool batch: prior_turn_context
grows by the turn before. An interactive Claude Code run read them once,
from CLAUDE_CODE_EXTRA_BODY in its environment as it started. So a tool
loop either started the run again (the whole conversation written to the
cache again), or kept it and sent the classifier the context it started
with, which is not what real Claude Code sends.

Each turn's safeguards now reach the running run:
- The bridge writes the extra body to <run tmp>/guard.json and hands its
  path to the helper as MAGPIE_CLAUDE_GUARD (mapped for WSL in newTap).
- tap.js, on each /v1/messages request whose string body has a
  safeguards key, reads the file and puts its safeguards in the body. It
  also sets CLAUDE_CODE_EXTRA_BODY to the file's text, so Claude Code's
  own later reads agree. The first time, it writes guard.json.live.
- setSafeguards rewrites the file (temp and rename, retried for Windows)
  instead of restarting, once .live exists. Without .live (a Claude Code
  that doesn't load the tap), it falls back to the old rule: keep the run
  when only the varying parts changed, otherwise restart. A beta change,
  or safeguards appearing or going, still restarts.
The tap changes only the safeguards value; any other byte of the body is
Claude Code's own. Bodies without safeguards, count_tokens and non-string
bodies are passed through untouched.

The tool-results path logged "process expired" alone while the run's end
read "magpie ended it". It now aborts the run with the reason and logs
"tool results process expired: <reason>". continueWith's "not waiting for
tool results" does the same.

Tests:
- TestClaudeTUIToolLoopCarriesEachBatchsSafeguards: three tool batches
  with growing prior_turn_context, then the answer. Checks one run and
  that each request carried its own batch's safeguards.
- TestClaudeTUIToolResultsLogWhyTheRunEnded: no tap and the rules change.
  Checks that the log has the reason.
- TestTapPutsTheGuardFilesSafeguards (bun and node): the rewrite, the
  bodies left alone, the env, and .live.
- TestTapEnv: MAGPIE_CLAUDE_GUARD is passed through, WSL-mapped.

Run (worktree at c360d9d30 + this change):
- mote: go test -run 'TestClaudeTUI|TestClaudeBridgeSafeguard|
  TestClaudeToolResults|TestClaudeNoRunSaysWhy' ./internal/gateway ok
  (73 PASS); go test -run TestTap ./internal/claudetui ok (bun and
  node); go vet ./internal/claudetui ./internal/gateway on darwin, linux
  and windows ok; gofmt -l internal clean.
- Full suite, go test -timeout 45m ./..., ran on the Linux box (wsl-run,
  magpie-desktop), not mote. mote had two other sessions' GUI suites
  sitting at 0% CPU for 3h42m at load 300, and one suite per machine.
  Result: 80 packages ok, internal/claudetui ok. Red:
  - TestGrokInstalled (#3548)
  - TestCodexBodyLimitFromMemory (#5118)
  - TestMoveCutShort (#5119)
  - TestCCListingKeepsItsNames (#4925)
  All four are red the same way run alone at origin/main d8b3749ef on
  that box. Root, internal/cli and internal/gui don't build there
  without GTK4 (#5120).
- Real use, macOS:
  - Sandbox HOME and CLAUDE_CONFIG_DIR, the owner's Max account copied
    to the sandbox dir's keychain item and deleted after. The refresh
    token didn't rotate.
  - A gateway on 127.0.0.1:3496; magpie built -tags dev at c360d9d30
    (before) and with this change (after).
  - Client: real interactive Claude Code 2.1.316 in tmux,
    --permission-mode auto, sonnet 5.5 through the gateway.
  - One turn, three sequential Bash calls (echo one, ls -la, echo three),
    four upstream requests.
  - Before: one run (pid 49488), cache_write 23005/86/162/86 (the first
    request cold). Its CLAUDE_CODE_EXTRA_BODY stayed the first request's
    safeguards, with no prior_turn_context, so requests 2 to 4 sent the
    classifier stale context.
  - After: one run (pid 64000), cache_read 23005/23091/23091/23253,
    cache_write 0/0/162/86. guard.json.live was written; the tap logged
    3 "guard":"set" (requests 2 to 4), and guard.json ended with 3
    prior_turn_context entries.

Broken by hand:
- The old claude_subscription.go makes both gateway tests red ("request
  0 carried ..."; the log said "tool results process expired" alone).
- tap.js without the rewrite makes TestTapPutsTheGuardFilesSafeguards
  red in bun and node.

Not tried:
- A tool loop whose rules change mid-loop with a real client (restart
  path; only the fake covers it).
- Linux or WSL with a real Claude Code (the TUI isn't used on Windows).
- Comparing the before/after upstream bodies byte for byte (the tap
  logs that it set the value, not the bodies).
- The gateway package as its own -timeout 45m run on macOS: only the
  targeted tests ran on mote, and the full package ran on Linux.
2026-11-04 06:38:56 +08:00
yetone d8b3749ef7 agents: Copilot CLI reaches magpie's models through its providers.json (BYOK)
tony9759 on Discord asked for Copilot CLI to be wired to magpie, since its
docs say it takes a custom model provider URL.

What Copilot does (1.0.105, @github/copilot-darwin-arm64's cli-main.js,
`copilot help providers` / `help environment`; GitHub docs
docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models):
env BYOK (COPILOT_PROVIDER_BASE_URL, _TYPE openai|azure|anthropic, _API_KEY,
_WIRE_API completions|responses) and a providers.json at
$COPILOT_PROVIDERS_CONFIG, else <COPILOT_HOME or ~/.copilot>/providers.json:
{providers:[{name,type,baseUrl,apiKey}], models:[{id,provider,name,
maxPromptTokens,maxOutputTokens,...}]}, picked as <provider>/<id> in
settings.json "model". Neither needs a GitHub sign-in. The multi-provider
file is marked experimental in the SDK types. The version BYOK started in is
not verified (github/gh-aw#25014 says 1.0.19; GitHub's changelog of
2026-04-07 announces it).

magpie writes the persistent file, not the environment: provider "magpie"
(openai chat completions, the gateway's /v1, the agent-named key) and one
models entry per catalog model, then model = magpie/<ref>. Only entries
naming magpie are magpie's; the user's providers, models and other keys stay
through connect, Sync and Disconnect (which also restores the model they were
on); a file that does not parse is never written over. COPILOT_HOME and
COPILOT_PROVIDERS_CONFIG are honoured (the latter added to agentenv.Vars).
Copilot's own models stay in the field's list.

Run at this head (a4fb75bfd's tree on 47b7ba303, mote): go test -timeout 45m
-count=1 ./internal/agent ./internal/agentenv ok; gofmt -l clean; GOOS=linux
and GOOS=windows go vet ./internal/agent ./internal/agentenv ok. Before the
rebase also ./internal/gui (only TestMainWindowCorners, red on origin/main
47b7ba303 too, #3949) and ./internal/library ok. TestModelReadersShareTheList
caught a first draft ranging over magpieModels; it uses sharedModels.
Real e2e: magpie's own Pick wrote the files into a sandbox COPILOT_HOME, the
real copilot 1.0.105 binary (no GitHub account) ran `-p "say hi"` against a
fake OpenAI server and sent POST /v1/chat/completions, model deepseek/pro,
Bearer magpie-copilot. The interactive TUI was also started earlier on a hand-written
providers.json and answered from it.
Broken by hand, each red: user providers dropped on write, Disconnect's
unwrite a no-op, an unparseable file treated as empty, Sync a no-op.

Not tried: a real magpie gateway behind it (the fake stood in), Copilot's
`anthropic`/`responses` wire types, Windows/WSL Copilot, an org with
forceLoginOrgs, tools/streaming against a real vendor model, the GUI suite
(no Agents-row layout change).
2026-11-04 05:13:45 +08:00
yetone b045362a92 routing: importing a shared group whose id is one of yours replaces that group (issennknight)
Import on the Routing page always added a new group. When the pasted text
carries the id of a group of the user's own (not one magpie found), the
box now says so before it is pressed: the button reads "Replace <name>"
and a line under the box says its models, routing and rules are replaced
and its accounts and folder rules stay. Pressing it posts groups/import
with replace, and provider.ImportGroupOver saves the text's group over
that one, in its place in the list. Matching is by id only; no other group
changes. Kept as the user has them, since the text can't carry them: the
group's accounts, its folder rules (that still fit the new members) and
its on/off switch. A name another group has gets a number. A text whose
id nobody has, a found group's id, or any import that doesn't ask to
replace adds a group as before. ImportGroup is unchanged.

Run on mote at the pushed tree before rebase:
- go test ./internal/provider (Share|ImportGroup): ok; the new
  TestImportGroupOverReplacesSameID is red with the match switched off by
  hand (replaced=false, id three-2).
- go test ./internal/gui -skip TestMainWindowCorners: ok. TestMainWindowCorners
  fails on mote's macOS 27 box and on an untouched origin/main checkout
  alike (c360d9d30), so it is not this change; not filed here.
- GOOS=windows go vet ./internal/provider ./internal/gui, gofmt -l: clean.
  GOOS=linux go vet of internal/gui can't cross-compile wails (cgo), not run.
- group-import-replace.test.cjs (new, 10 tests: chromium and webkit x en,
  zh, zh-TW, ja, de, at 420px): green; red 10 of 10 with the id match
  broken by hand. Its checks: Import for an unknown id or a found group's
  id, Replace One + the line for an own id, the label survives a redraw,
  replace is posted only then, the list keeps its groups.
- group-*.test.cjs, i18n-keys, gui-de/ja/zh-tw, routing-accounts-narrow,
  routing-save (407 tests, chromium and webkit): all pass. A wider run of
  group/routing/i18n/gui-* files at concurrency 3 was cut at 444 tests with
  one red, routing-accounts-narrow, chromium en, which passes alone (load
  from other sessions on mote); the rest of that wide run was not finished.

Not tried: a real account's group pasted into a real magpie; the TUI/CLI
have no import, so nothing there changed.
2026-11-04 03:56:38 +08:00
yetone a6f5d738fc gateway: a group's serial walk has a total budget of 540s (#5113)
Nine members at a 60s first-token wait took 660s, past the 600s a client
waits. The client hung up first and the member it was on was told as the
failure. Nothing bounded the sum of the members' waits.

groupBudget (540s) counts from the walk's start. A member asked with less
left than its FirstToken gets only what is left (holdWriter.budgeted); when
that runs out, or the walk has used the budget, no further member is asked,
the member isn't rested (it was cut short, not slow), and the error is a 504
naming the budget. A client cancel was already read first (nobody blamed),
and is unchanged.

Reported by mycf_711 in #5112; #5113 stays open for the reporter.

Run at the pushed head (rebased on origin/main 7aff42d86): mote-run
go test ./internal/gateway -timeout 45m: ok (667s); GOOS=linux and
GOOS=windows go vet ./internal/gateway and gofmt -l: clean.
TestGroupWalkStopsAtItsBudget waits on the response, not a duration; with
gateway.go's change reverted it is red (the second member is asked after
60s and answers 200).
Not tried: a real 9-member group against a vendor; the budget is not
configurable per group.
2026-11-04 02:11:09 +08:00
yetone 7033f50722 gui: the panel opens the main window from its edge nearest the tray
isaac_bai on Discord, after v0.1.2857 named the header's icon "Open the
main window": with Windows' taskbar at the bottom, the panel stands above
the tray and its header is the panel's whole height from the icon; the
button left of Quit was where his pointer already was. yogurt36 had asked
for one opener, not two, so the panel still has exactly one, now on the
edge nearest the tray:

- Hung below its icon (the Mac's menu bar, a taskbar or bar at the top)
  it is the header's icon, as before.
- Standing above it (Windows' bottom taskbar, a bottom panel on Linux) it
  is "Open the main window" left of Quit in the foot (#openMain), and the
  header has no icon. The string is the one the icon's name already
  uses, in all five languages.

Which side: once togglePanelNow has placed and shown the panel,
tellPanelSide reads the panel's bounds and its screen's and sends
magpiePanelOpenAt("foot") when the panel is nearer the screen's bottom,
"head" otherwise (panelOpenAt, panelside.go; the Mac is always "head").
Under Wayland a window can't read where the compositor put it, so there,
and until the app says, layout.js sets body[data-open-at] by the system:
"foot" on Windows, "head" elsewhere. CSS shows one of the two from it.

Tests:
- TestPanelOpensTheWindowFromTheEdgeNearestTheTray: Windows bottom/top
  taskbar, a tall panel, a second screen above the first, Linux X11
  bottom/top, Wayland, a screen not read, the Mac, unknown places; only
  "head" or "foot" reach the page.
- TestPanelToldItsSideWhenShown: both show paths in togglePanelNow call
  tellPanelSide after placing; app.js has magpiePanelOpenAt.
- panel-open-once.test.cjs, Chromium and WebKit x en/zh/zh-TW/ja/de:
  on a Mac platform exactly one opener, the header's, named per
  language, opening /api/window/main, foot ["profBtn","quit"]; told
  "foot" it moves. On Win32 exactly one opener, the foot's, left of Quit
  (["profBtn","openMain","quit"]), the foot's buttons fitting apart with
  their words whole at 360px, opening /api/window/main; told "head" it
  moves back; an unknown side changes nothing.

Run on mote via mote-run:
- At this head (rebased on 8468afecb): go test ./internal/gui -run
  'TestPanel|TestTrayDouble|Budget|I18n|Asset': ok; node --test
  panel-open-once, i18n-keys, window-no-footer, panel-profiles,
  quit-ask-setting, gui-de, gui-ja, gui-zh-tw: 165 of 165 pass.
- At the same change rebased on f168dd278 (main's 8 commits since are
  Library, Routing, browser and Codex-subagent work, none in the
  panel's header or foot): the 127 GUI files that load
  mode=panel or touch the foot, Quit, i18n or a budget, both engines,
  6 at a time: 2112 of 2136 pass. The 24 reds are in 7 other files; run
  again 2 at a time, 16 stay red at this change and 17 at origin/main
  1e1068c86, the same tests: usage-fold, tray-cell-click and
  codex-auto-reset webkit de (#4790), remote-magpie (#4398), and one
  provider-mask case (filed #5109); account-mask (#3951) and
  quota-curve (#4768) went green on the second run.
- At this head: wsl-run go vet -tags gtk3 ./internal/gui: ok
- win-run go vet ./internal/gui: ok; win-run go test -run
  'TestPanelOpens|TestPanelToldItsSide|TestTrayDouble' ./internal/gui: ok
- gofmt -l internal/gui: empty

Broken by hand (in a copy): panelOpenAt always "head" plus the page's
default and magpiePanelOpenAt doing nothing: the Go test red on 5 cases,
panel-open-once 20 of 20 red. Only the CSS rule that hides the header's
icon at the foot dropped: panel-open-once red (two openers shown).

Not tried: a real Windows tray with the taskbar at the bottom or the top,
or a Linux X11 bottom panel; the bounds Wails reports there are read from
its source (positionWindow, the screen's Bounds), not seen. The whole GUI
suite (1175 files) was not run: mote was at load ~55-100 from other
sessions' suites.
2026-11-04 00:22:54 +08:00
yetone 8468afecb3 claude: a turn's images say they are attached, so the file notes after them are not taken for the images
Claude Code notes each image it is given ([Image: source: .../images/N.jpg])
in a note after the message, with a path in the gateway's temp folder. With
no history before the turn, nothing said what they are: the model took the
paths for the images, said it could not see them and quoted the paths as on
another computer (sinsoul1647 on Discord, v0.1.2862, 7 tool-result photos).
The prompt (renderClaudePrompt) and a saved session's turn (renderClaudeTurn)
now say the images, tool results' too, are in the message.

Tried: real claude 2.1.316 on mote against a fake Anthropic server, with
-p user images, MCP tool-result images, a url source, the TUI paste and a
resumed transcript: every one reached the API as image blocks, so the loss
is the model's reading of the notes, not a dropped image.
Not tried: the reporter's client; whether the model stops quoting paths.
Broken by hand: with the note left out, TestClaudePromptSaysToolResultImagesAreAttached is red.

Run at the pushed head (rebased on 8e27369bd): gofmt -l clean; go vet gateway linux and windows ok; go test ./internal/gateway -run Claude|Subscription|Prompt|Image ok (not the full gateway suite: another full suite was on mote).
2026-11-04 00:14:37 +08:00
yetone 1e1068c86c codex: "Same as the lead" holds every subagent to the lead's model (cleverpigo on X)
cleverpigo (Windows, Codex App 26.1027.6604.0) had Codex's lead on
WorkBuddy's DeepSeek-V4.1-Flash, the subagent model on what the GUI called
"Same as the lead", and the Routing page still showed a subagent on
gpt-5.6-sol through Codex's own sign-in.

Cause: that setting, unset, never held a subagent to anything. Since
67c8f562c (mengxiao) a subagent keeps the model its lead names in
spawn_agent (codexFollowTo leaves subagents alone; codexSubagentPick
returns nil with nothing set), and Codex lists its own models first under
spawn_agent's model overrides, so the DeepSeek lead named gpt-5.6-sol.
Codex's side calls use luna, terra or codex-auto-review, not sol, so it
was the subagent, not a side call.

Now:
- "lead" (settings.CodexSubagentLead / provider.CodexSubagentLead) is a
  value of CodexSubagentModel: every Codex subagent goes on the model the
  lead's own turns last went on (codexLeads.lookup), whatever it names.
  The trace says so (SubagentPick.Lead) and Routing tells it as "the
  model its lead is on".
- A lead on one of Codex's own models is followed on the ChatGPT backend
  route only; in serve such a lead leaves the request as asked. With no
  lead turn seen, a subagent goes as asked.
- The GUI's picker offers "Lead's pick" (unset, mengxiao's case, as
  before) and "Same as the lead" (the new value); the texts say which one
  holds the subagents. en, zh, zh-TW, ja and de.
- No prompt text sent to a vendor changes.

Users who had it unset stay on Lead's pick; the label now says what it
does, and they pick Same as the lead to hold their subagents.

Docs: agent-wiring.md (subagent model field), gateway-routing.md
(CodexSubagentModel paragraph).

Ran, on mote through mote-run at this tree (base origin/main 50265256b):
- go test -tags nogui ./internal/gateway (whole package, -timeout 45m): ok
- go test -tags nogui ./internal/provider ./internal/settings
  ./internal/settingsapi: ok; -run Codex ./internal/agent ./internal/gui:
  ok; -run Budget ./internal/gui (TestCoreScriptBudget): ok
- go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags nogui
  ./... (and -tags nogui darwin/windows): clean; gofmt -l: nothing
- node --test, both engines: codex-subagent-model (now picks Same as the
  lead and back, sheet row, Routing story of a lead-moved subagent, five
  languages), codex-subagents-lead, i18n-keys, routing-request-model,
  routing-sealed-task: pass. routing-story-shrinks is red in WebKit (4
  subtests, "held while under way"), the same alone at origin/main
  50265256b: #3954.

Broken by hand (in mote's copy only):
- lead lookup turned off in codexSubagentPick: both new tests red
  (TestCodexSubagentFollowsTheLeadWhenSet: "ChatGPT was asked for
  [gpt-5.6-sol]", the reporter's case).
- codexBackend's gate back to bare models only:
  TestCodexSubagentFollowsALeadOnCodexsOwnModel red.
- On the old code the tests don't build (no "lead" value), and
  SetCodexSubagentModel refused "lead".

Not tried: a real Codex App/CLI with a DeepSeek lead spawning a subagent,
and nothing on Windows (the change has no OS-specific path). The whole GUI
suite wasn't run: mote had two other sessions' full GUI suites going.
2026-11-03 23:12:33 +08:00
yetone 50265256ba library: a note on a skill or an MCP server, the library's own (youyo.p_10001)
youyo.p_10001 on Discord: with many skills and MCP servers installed,
you can't tell what each is for or which to use. A skill has the
description its author wrote for models, often in English and about
what it does, not why you installed it. An MCP server has nothing but
its command and its tool list. So each now takes a note in the user's
own words.

- Server.Note and Skill.Note in library.json: one line of at most 200
  characters, whitespace run together (checkNote), as a hook's
  description (#2011). A longer one is turned away, not cut.
- The server editor has a Note field under the name. A skill's reader
  (2a19043af's file reader) has one over its files: Save shows once it
  changes, saves the file being edited with it, and a changed note is
  asked about before the dialog closes. SkillNote, POST skills/note.
- A row shows the note in place of its command or description, so rows
  keep their height; the tooltip gives the note, then that line. The
  skills' filter matches notes.
- No agent is given a note: not in any agent's MCP entry, a project's
  file, the MCP router's list or a skill's copied SKILL.md.
- A sync carries it (CarriedSkill.Note; a server goes whole), and
  clearing it is carried too. An older magpie on another computer
  doesn't know notes: a bundle it writes has none, so a sync from it
  clears them. The TUI's server editor keeps a note as it was.

Run at the pushed head:
Run at the pushed head (on origin/main f168dd278, then
rebased onto 94d0fbfcd, whose two commits change only
migrate_zcode.go and the searcher-pick test):
- mote: go test -timeout 45m internal/library (TestNoteNeverGiven,
  TestNoteCarried, TestNoteTooLong), gui, tui, davsync, backup: ok,
  except internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's SDK
  (#3949). GOOS=windows go vet of library, gui, tui and GOOS=linux of
  library, tui: clean. gofmt -l: clean.
- mote, both engines, every language, narrow and wide: skill-edit (the
  skill reader's note), library-mcp-json (the server's note, its row and
  the filter), mcp-editor-cancel, library-mcp-win-line, market-address,
  market-have, i18n-keys: 108 of 108.
- WSL, the whole GUI suite: no red in a library file that origin/main
  hasn't too (see the command commit; #4120, #4471 for the rest).
- "Note" is in core i18n.js, not the plugin's: agent code says it as a
  word. The rebase had dropped main's title on a server row's command
  line (library-mcp-win-line went red); it is back, and with a note the
  tooltip gives the note, then that line.

Broken by hand, each red, then restored:
- add("note", s.Note) in Claude's MCP format: TestNoteNeverGiven
  (.claude.json held the note).
- the carry of Note left out: TestNoteCarried.
- note left out of the server editor's save: the GUI test, 22 of 22.
- notes left out of the skills' filter text: the GUI test, 22 of 22.
- the note's save left out of the skill reader's Save: skill-edit, 22
  of 22 (Save never goes away).
- the note left out of the reader's unsaved check: skill-edit, 22 of 22
  (closing never asks).

Not tried: a real sync between two computers, a real agent reading its
config (the guard reads every file magpie writes in a sandbox HOME), a
real app window, Linux WebKitGTK.
2026-11-03 21:43:54 +08:00
yetone a80575cc86 library: an MCP server's command wraps, and the editor shows the server as JSON (hema_17384)
hema_17384 on Discord: in Library > MCP servers, the editor's Command
field was one line, so `npx -y universal-db-mcp --type sqlserver --host
... --user sa --password ... --database ...` was cut off, and they asked
to see and edit the server as JSON.

- The command is a box that wraps (lineBox, a textarea of one row that
  grows with autosize). It is still one line: Enter saves, Escape
  closes, and a newline is a space between words (a shell's \ before it
  too, except on Windows, whose lines keep their backslashes). At 390
  wide it wraps over several rows; nothing scrolls sideways.
- The editor's head has a Form | JSON switch (the app's segmented
  control, not a <select>). JSON is the server as Copy config gives it
  for Claude Code: {"mcpServers": {name: {type, command, args, env}}},
  or {type, url, headers} for a URL, with ${NAME} references as written.
  An edit there is read as a paste is (serversIn) and becomes the form's
  at once. JSON that isn't one server's marks the box invalid, says so,
  and keeps the dialog from saving or going back to the form, and
  counts as unsaved for Cancel. The agents, sync and the startup
  timeout and OAuth app stay in the form and are kept as they were.
  ⌘/Ctrl-Enter saves from the box; a paste into it is the box's, not
  the dialog's "paste a README's JSON".
- Strings in en, zh, zh-TW, ja and de.

Run at the pushed head (on top of the note commit, which shares these
files):
Run at the pushed head (on origin/main f168dd278, then
rebased onto 94d0fbfcd, whose two commits change only
migrate_zcode.go and the searcher-pick test, with the note commit
on top, which shares these files):
- mote: go test -timeout 45m internal/library, gui, tui, davsync, backup:
  ok, except internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's
  SDK (#3949). GOOS=windows go vet of library, gui, tui and GOOS=linux of
  library, tui: clean (internal/gui's Linux vet needs gtk3 and ran clean
  on WSL before the rebase, with no Go change since). gofmt -l: clean.
- mote, both engines, en/zh/zh-TW/ja/de, 390 to 1100 wide:
  library-mcp-json (new), mcp-editor-cancel, library-mcp-win-line,
  market-address, market-have, skill-edit, i18n-keys: 108 of 108.
- WSL, the whole GUI suite (before this rebase, at the same change):
  541 subtests red in 57 tests, the WSL baseline (#4120, #4471). Those
  in library files are red on origin/main too, run side by side:
  found-skill-pick-remove (#5013, #4097), library-mcp-hub (#4483),
  market-more (#5076), library-chip-fan (#3072), library-mcp-tools ja
  420 (#4693). market-address and market-have were mine: they still
  looked for the command's <input>; they find textarea.lib-cmd now and
  pass 32 of 32 on WSL.
- "Form" is in core i18n.js, not the plugin's: agent code says it as a
  word, which i18n-keys turns away in a plugin.

Broken by hand, each red, then restored:
- .lib-cmd back to white-space: pre: "the command scrolls sideways".
- the command field back to an <input>: the new test and
  library-mcp-win-line fail (28 of 28).
- save without the JSON check: the "isn't an MCP server's JSON" error
  never shows and the broken JSON goes to save.
- (wrap="off" on the textarea alone stays green: the CSS's pre-wrap
  wins, so the CSS is the guard.)

Not tried: a real magpie app window (the GUI tests fake the API), the
reporter's real server, Linux WebKitGTK.
2026-11-03 21:43:54 +08:00
f168dd2784 gateway: a relayed Messages stream is read in whole events, however its reads are cut (#4868)
anthropicTextCalls (the filter that turns calls a model wrote into its
text into tool_use blocks, on a Messages passthrough that offered tools)
split each read with bytes.SplitAfter on "\n". The piece ending a read
always left a trailing empty slice, which line() took for the blank
line that ends an SSE event. So an upstream that flushed `event:` and
`data:` in separate reads had its events dispatched early: a
content_block_start reached the client without its data ("Unexpected
end of JSON input"), or a held block start was joined to the next
event without a blank line ("Unexpected non-whitespace character after
JSON"). Claude Code retried and gave up; hugemulberry on Discord sees
499s often.

The filter now reads whole events with tidyEvents and eventData, as
responsesTextCalls, phaseTidy and idTidy already do. Because tidyEvents
hands out slices of a buffer the next write reuses, the held block
start and stop are copied (startHeld, stopHeld); nothing else the
filter keeps past an event points into the buffer (pending and held
are strings, m is read within the call).

Siblings: the other SSE writers that cut a read on its last "\n"
(textCallTidy, geminiTextCalls, chatTidy, crTidy, usageSniffer) handle
each line alone and keep no event across lines, so the trailing empty
piece goes on as nothing; phase.go's withData and redact's splitEvent
split a whole event. Only this filter gathered lines into events.

Port of oDaiSuno's fix (7bee8c4d0) and tinytub's regression tests and
doc line (d1a7b02a8); yetone/magpie PRs are collaborators-only. Added
here: TestAnthropicTextCallsSSEChunksKeepFraming feeds each stream in
two reads cut at every byte (LF and CRLF), and
TestAnthropicMessagesSSEChunksKeepFraming cuts the handler's upstream
after each line and adds a request with no tools.

Run on mote at this tree (origin/main 4c0c6c02b + this change):
- go test ./internal/gateway -timeout 45m -count=1: ok (628s)
- gofmt -l internal/gateway: empty
- GOOS=linux go vet ./internal/gateway, GOOS=windows go vet
  ./internal/gateway: ok

Broken by hand:
- textcalls_anthropic.go from origin/main: 36 subtests red (lines,
  bytes, CRLF lines, every cut, each line cut, for all four streams in
  both tests: "SSE frame "content_block_start" has 0 data lines");
  whole, events and no-tools stay green.
- the fix without the startHeld/stopHeld copies: 30 subtests red,
  events reads included (a held start overwritten by the next event's
  bytes: "has 2 data lines").

Not tried: a live provider through this build (tinytub reproduced the
original failure through JoyCode on v0.1.2838 with Claude Code
2.1.316); lone-CR line endings, which neither the old nor the new
reader supports.

Co-authored-by: oDaiSuno <157346420+oDaiSuno@users.noreply.github.com>
Co-authored-by: tinytub <1871460+tinytub@users.noreply.github.com>
2026-11-03 21:20:26 +08:00
yetone 4c0c6c02b8 plugin: keep idle plugin sign-ins alive in the background (#5080)
A plugin with auth.refresh had a sign-in renewed only when something
used the account (a request, its models, usage or check-in) within its
refreshLead of expiry. An account left idle past its token's life
lapsed. OrcaTerm's WeChat token lives two hours, and after that its
refresh answers SESSION_EXPIRED for good, so the user had to sign in
again (orinsid, magpie-community/plugins#675).

The gateway now renews each such sign-in as it comes due
(provider.KeepPluginsSignedIn, started beside KeepPluginsListed):

- Due times come from plugin-auth.json through filememo
  (plugin.RenewAt: expires less the lead the host reckons, now listed
  as Provider.Renews/RenewLead). Nothing is asked, and no host started,
  until an account is due. The loop sleeps until the next one, at most
  5 minutes, and renews them one after another.
- A due sign-in goes through the host's own renewal (host.js
  keepSignedIn, which shares renewal() with fresh()). It is one at a
  time per account whoever asks: a request arriving meanwhile waits
  for the same promise, under the cross-process lock file, through the
  account's proxy.
- Kept: accounts switched on and not marked, of a plugin provider not
  switched off, hidden (leftAlone) or being moved.
- A failed renewal marks nothing. It is held back for 1m, doubling to
  at most 30m, for that sign-in only. Only the plugin's
  signIn:"expired" marks it, as at a request.
- A plugin can opt out with auth.keepAlive: false. None in the plugins
  repo needs to: no refresh costs quota, the ones rotating single-use
  refresh tokens (Cline, Factory, Nous, SenseNova, CodeArts, Qoder,
  MiniMax) rotate at use already, and kimi-work's reference accounts
  and Raccoon's desktop reuse never refresh another app's token.

Docs: provider-plugins.md "A sign-in nothing uses"; leftAlone list in
providers-accounts.md.

Run at the pushed head, on mote (mote-run), -tags nogui:
- go test -count=1 -timeout 45m ./internal/plugin ./internal/provider
  ./internal/gateway: ok (109s, 119s, 637s), rebased on origin/main
  6cfe78635. Rebased again on b088fd0f0 (gateway.go, prompt.go
  changed): go build ./..., go vet of the three packages and the new
  tests plus TestLivePrompt*: ok.
- the new tests on Windows (win-run) and Linux (wsl-run): ok.
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
  go vet ./...: ok. gofmt -l: clean.

Broken by hand, each red, then restored:
- keepSignedIn refreshing by itself, not through renewal()/the lock:
  TestKeepSignedInRenewsIdleSignIns red (r-ok-busy renewed twice
  beside concurrent requests).
- keepAlive:false ignored: red (stayco listed as renewed).
- a network failure reported as gone: red (down: Gone true).
- Go backoff removed: TestKeeperBacksOffAFailedRenewal red.
- the On, Lapsed and leftAlone filters each dropped:
  TestKeptSignInsAreTheOnesSwitchedOn red.
The new tests don't compile on the old code (no KeepSignedIn).

Not tried: a real OrcaTerm account idling past its 2h token with the
gateway running; Windows/Linux runs of the new tests (vet only); a
magpie with many plugin accounts beyond the unit test's look.
2026-11-03 21:01:27 +08:00
yetone b088fd0f09 gui: the panel's header icon is named "Open the main window"; a double-click on the Windows tray icon opens it
isaac_bai on Discord missed the "Open magpie" button beside the quick
panel's Quit, and was setting the tray click to open the main window just
to get back to it; he asked for a double-click on the tray icon.

History: the foot's button (#openMain) was taken out on purpose in
e0ad48641 (10-30, yogurt36 on Discord): the panel had two buttons to the
same window, the header's open-as-a-window icon (#open) and the foot's
"Open magpie". The header icon stayed, but its tooltip said "Open as a
window", which reads as this panel in a window. Rather than bring the
second button back (and undo yogurt36's ask four days later), the icon now
says what it opens: "Open the main window", a string every language
already had (Settings' tray-click choice). "Open as a window" is out of
i18n.js, nothing else used it.

Double-click, per OS, from Wails v3.0.0-beta.24's source:
- Windows: systemtray_windows.go passes WM_LBUTTONDBLCLK on as
  OnDoubleClick. A double-click arrives as LBUTTONUP (the click: the panel
  opens), LBUTTONDBLCLK (now: ShowMain, whose openMain hides the panel),
  LBUTTONUP again; that last one is swallowed once (trayDouble, within
  2s) so it doesn't open the panel over the window.
- macOS: the status item's action runs per mouse-down with no click count
  (systemtray_darwin.m statusItemClicked); a double-click would be the
  panel opened and closed. Not added.
- Linux: StatusNotifierItem has Activate only (systemtray_linux.go); the
  same. Not added.
docs/subsystems/gui-shell.md step 10 says so.

Tests:
- TestTrayDoubleClickOpensTheWindowOnWindowsOnly: windows on, darwin and
  linux off, and app.go wires OnDoubleClick to ShowMain and checks the
  swallow first in OnClick.
- TestTrayDoubleClickReleaseSwallowedOnce: the release after a
  double-click opens nothing, once; the next click, or one past the bound,
  opens the panel. Fixed instants, no sleeps.
- panel-open-once.test.cjs: the header icon's title and accessible name
  are "Open the main window" in en, zh, zh-TW, ja and de, both engines.

Run (at the pushed head's tree before rebase onto 78667e9b7, which changes
only docs/subsystems/gui-shell.md among these files):
- mote: gofmt -l internal/gui clean; GOOS=windows go vet ./internal/gui ok;
  go test -run TrayDouble ./internal/gui ok.
- Linux (wsl-run, magpie-desktop): go vet -tags gtk3 ./internal/gui ok;
  go test -tags gtk3 -run 'TrayDouble|TrayMenu' ./internal/gui ok.
- Windows (win-run, xiaomi-gpu): go test -run TrayDouble ./internal/gui ok.
- mote GUI, both engines: panel-*, phone-web, old-webkit and i18n-keys
  (24 files), 280/280 ok.
- Broken by hand (a copy on mote): trayDoubleClicks false for windows and
  the swallow never reset are both red; the old "Open as a window" title
  is red in every language, Chromium 0/5 and WebKit 0/5.

At the pushed head (rebased on 78667e9b7), mote: gofmt clean, go test -run
TrayDouble ./internal/gui ok, panel-open-once + i18n-keys 14/14 ok.

Not run: the whole GUI suite (a tooltip only, no layout or API change) or
the whole Go suite. Not tried: a real double-click on the Windows tray
icon in the built app, or the panel in the real tray on any OS.
2026-11-03 20:54:01 +08:00
JoeyWu-techandyetone 6cfe786351 agent: Codex that can't be joined again isn't connected by its helper models alone (#3868)
why8023: Codex switched off and on again showed 「已接入」 with its
subagents' and memories' models back, while its own model never reached
magpie. fae438b4a (NancyTom18 on X) made reconnect call Join first, which
fixed the ChatGPT sign-in case, but where Join can't apply then (a
model_provider of the user's own, magpie API) reconnect still put the
helper fields back alone and answered Wired(), which a helper field on
one of magpie's models makes true. So the switch said connected while
Codex's own turns went to the user's provider.

Now, when Join doesn't join and the model Codex was on wasn't one of
magpie's, reconnect gives up and the switch connects Codex as at first,
on one of magpie's models. Where its model was magpie's, that model
routes it, as before. docs/subsystems/agent-wiring.md says so.

coffemon's (JoeyWu-tech) patch 9ee95ba9, re-ported onto fae438b4a: main
already joins first, so only the !ok check is taken, with his
TestCodexOffAndOnJoinsAgainWithItsHelpersOnMagpie (seven cases, all
green on main too since fae438b4a). TestCodexOwnProviderOffAndOnIsNot-
ConnectedByItsHelpers is new and covers the case that was left: a relay
model_provider, Connect, subagents' model on magpie, gpt-5.5 picked
back, off and on.

Run (mote-run, macOS, go1.26.8, -tags nogui):
- the new test: ok. With the check turned off by hand (if false && ...):
  red, "on again ({How:again ...}) with its own model off magpie".
- TestCodexOffAndOnJoinsAgainWithItsHelpersOnMagpie,
  TestCodexReconnectStaysJoined, TestCodexConnectKeepsItsPick,
  TestReconnectKeepsTheLastPick, TestCodexDisconnectStaysWithAccountsOn
  and the OpenCode/OpenChamber tests: ok.

Not tried: the Agents page and a real Codex on a relay afterwards; the
test drives ConnectHow and Disconnect, which the switch calls, with
config.toml in a sandbox HOME.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).

Co-authored-by: yetone <9rqwv2ak@gmail.com>
2026-11-03 20:38:11 +08:00
JoeyWu-tech d3de7e8f3e agent: a provider of the user's own at magpie's gateway, under OpenCode 2's providers, stays theirs (#3915)
Found while fixing #3883. OpenCode 2 keeps a provider under providers,
its base URL in settings.baseURL, and reads it there before the same
name under provider, OpenCode 1's spelling: the one under providers is
taken whole, and the other is only a WARN, "retained native value over
legacy value" (packages/core/src/config/normalize.ts, mergeMaps, at
v2.1.4). OpenChamber's provider form saves a provider there and takes
it out of provider (packages/web/server/lib/opencode/config-v2.js,
writeSectionEntry). magpie read the user's own providers under provider
only, in the two places that look for them:

- ownGatewayProvider: a provider of the user's own at magpie's gateway
  that lists the model, as a layout of one provider per family of
  magpie's models has, gets a pick of that model of magpie's as
  <theirs>/<model>, with no provider.magpie beside it. One under
  providers wasn't seen, so the pick went to magpie/<model> and
  magpie's provider was added beside the user's.
- openCodeSpelled: a model on a provider named as one of magpie's and
  at the gateway (relay/glm-4.6 on the user's own relay) counts as
  magpie's. Under providers it didn't, so Agent.Models left it out.

On origin/main e056779a, the same provider under each spelling:
  provider:  pick -> magpie-relay/relay/glm-4.6, no provider.magpie
  providers: pick -> magpie/relay/glm-4.6, provider.magpie added
  provider:  Spelled=true  Models=[relay/glm-4.6]
  providers: Spelled=false Models=[]

Both now read a provider under providers as OpenCode 2 reads it: the
base URL from settings.baseURL (openCodeBaseURL), and a name under both
is the one under providers. They serve OpenCode, OpenChamber's pickers
on OpenCode's config, MiMo Code and DevEco Code; a config without
providers, as OpenCode 1 and the forks on it write, is read as before.
This changes what magpie reads, not what it writes, so there is no old
data to bring up. agent-wiring.md says so beside DevEco Code.

What was run (tree 77e2237e, on origin/main 2b038757, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestOpenCodeKeepsItsOwnGatewayProvidersUnderProviders, new: a pick
  of magpie/relay/glm-4.6 with the user's magpie-relay under providers
  is written as magpie-relay/relay/glm-4.6 with no provider.magpie; a
  model on relay under providers at the gateway is in Models; with
  relay under both, the one under providers is read, for Models and
  for a pick: ok
- broken by hand, one at a time, with
  TestOpenCodeKeepsItsOwnGatewayProviders (the same under provider)
  green under each:
  - openCodeSpelled reading provider only, as on main: red, "models =
    []"
  - ownGatewayProvider reading provider only, as on main: red, "model
    = "magpie/relay/glm-4.6""
  - the one under provider read over the one under providers, in
    openCodeBaseURL: red, "the provider under provider read over the
    one under providers: [relay/glm-4.6]"; in ownGatewayProvider: red,
    "picked on the provider under provider: model =
    "mine/relay/glm-4.6""
- the 26 internal/agent tests matching OpenCode, OpenChamber, MiMo,
  DevEco or Spelled: ok
- OpenCode 2.1.4 itself (opencode models, sandbox HOME): with
  magpie-relay under providers as the test writes it, it lists
  magpie-relay/relay/glm-4.6; with relay under both, it logs "retained
  native value over legacy value" for $.providers.relay and lists only
  the models under providers (a model only under provider is gone)
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 68 packages ok and 8 red, none in what this changes; in
  internal/agent every test this adds or touches passes. The reds: agent
  TestFolderVarsAreListed (#3884, fixed on main since in 3116b8f5),
  TestCodexDriftReached (#3398), TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir (#3141),
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
  #3640); gateway TestPluginToldWhereTheAgentWorks (#3675); gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649); proc TestEnvOfChild and provider TestCodexAppServersOnHome
  (#3906), then "close of synctest channel from outside bubble" from
  TestUnreadLoginsWriteErrorsKeepCredentials (#3632); tui
  TestTUIFetchesSubscriptionModels/agent (#3919).
- gofmt -l clean. go vet -tags nogui and go build -tags nogui for linux,
  windows and darwin, and go vet and go build for windows without the
  tag: exit 0 each. go vet and go build without the tag on linux: exit 1
  (this box has no GTK or WebKitGTK dev packages).

Not tried: OpenChamber's app itself, a request sent through such a
provider, Windows and macOS.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
JoeyWu-techandyetone 0ed9891de0 agent: magpie's provider under OpenCode 2's providers is kept current (#3883)
Murciee (#3883, OpenCode 2.1.4 as OpenChamber bundles it, Windows): a
model added in magpie never reached OpenCode 2, though magpie said it
was exposed. ~/.config/opencode/opencode.json held magpie's provider
twice, provider.magpie with 43 models and providers.magpie with 38, and
opencode models listed the 38. OpenCode 2 keeps a provider under
providers, in words of its own, and still reads OpenCode 1's provider:
a provider named under both is the one under providers, whole, and the
other only a WARN in its log, "retained native value over legacy value"
(packages/core/src/config/normalize.ts, mergeMaps, at v2.1.4).
OpenChamber's provider form saves a provider under providers and takes
it out of provider (packages/web/server/lib/opencode/config-v2.js,
writeSectionEntry). Once it had saved magpie's, magpie's next sync put
provider.magpie back, as a model of magpie's was picked, and from then
on brought only that one up to date.

Where an OpenCode config keeps magpie's provider under providers, each
sync and model pick now write it there too, and the wiring check reads
it there (opencode_providers.go). It is written as OpenCode 2 reads
magpie's provider.magpie (packages/core/src/v1/config/migrate.ts,
migrateStandardProvider and migrateModel): npm as package
"aisdk:<npm>", options as settings, a model's modalities as
capabilities beside tools, its variants a list of {id, settings, body}
with the options OpenCode 2 reads itself in settings and the rest in
body (provider-options.ts, COMPATIBLE_KEYS: a fast variant's
service_tier), and reasoning, which it doesn't read, left out. As under
provider (theirsKept, openCodeKept), magpie's models are written whole,
a key of the user's in the block stays, and so does a variant the user
put on a model of magpie's. A variant is magpie's when it says what
magpie's of its name says, split as OpenCode 2 splits it or all in
settings, as OpenChamber carries one over from provider
(toModelVariants). A config without providers.magpie doesn't get one:
provider.magpie is still what magpie writes, and OpenCode 1 and 2 both
read it. Taking magpie out of OpenCode or OpenChamber takes out both
blocks, as OpenChamber's own delete does. agent-wiring.md says so
beside #2379's variants.

Old data: a config already in the reporter's state is brought up to
date by the next sync, which SyncCatalog runs over every agent at each
start and update of magpie. A providers.magpie an older magpie left
behind when taking magpie out (it took out provider.magpie alone) is
kept up to date from now on, and goes the next time magpie is taken
out.

Not changed:
- Air: its magpie-opencode.json is magpie's own and holds
  provider.magpie alone. With OpenChamber's providers.magpie in the
  global config and nothing else of magpie's there, OpenCode 2.1.4
  handed Air's file as OPENCODE_CONFIG still listed the model only
  Air's file had.
- MiMo Code and DevEco Code go through the same code. Their configs
  hold no providers block unless something of theirs writes one; not
  checked against their source.
- A provider of the user's own at magpie's gateway kept under providers
  isn't read by openCodeSpelled and ownGatewayProvider, which read
  provider alone: #3915, filed with this.
- What else OpenChamber's form puts on a model of magpie's under
  providers (a modelID, a cost) goes with the rest of the model at the
  next sync, as a key on one under provider does today.

What was run (tree 61b3fff7, on origin/main e056779a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestOpenCodeNativeIsOpenCode2s, new: openCodeNative of a block with
  levels, fast variants, an image model and one without levels is what
  OpenCode 2.1.4's opencode debug config printed under providers.magpie
  for that block in an opencode.json (its apiKey, shown as ***, put
  back).
- TestOpenCodeProvidersKeptCurrent and
  TestOpenChamberProvidersKeptCurrent, new: a config as OpenChamber's
  form leaves it, provider.magpie gone and providers.magpie from before
  think/new (a stale baseURL and key, a header and a timeout of the
  user's, a modelID, magpie's variants of levels deep no longer has,
  one of them in OpenChamber's form, one the user wrote over, one of
  their own, and a model the catalog dropped). A sync, and a model
  picked, bring it to the models under provider with the user's keys
  and two variants kept; a second sync writes nothing; stepping off
  magpie takes out both. A config without providers gets none.
  TestOpenCodeCheckReadsProviders, new: a providers.magpie at another
  address is off until a sync.
- The 21 tests named TestOpenCode*, TestOpenChamber* and TestDevEco*:
  ok. -race -count=5 over the four new ones: ok.
- Broken by hand, one at a time, each red where it says: no sync under
  providers in OpenCode's Sync, in a pick, in OpenChamber's Sync; no
  delete there for OpenCode or for OpenChamber; the check reading
  provider alone; no theirsKept; the user's variants dropped; no
  variant taken for magpie's; only OpenCode 2's split taken for
  magpie's (OpenChamber's high-fast stayed); providers written into a
  config without it; a write on every sync; every option in settings;
  no capabilities. The sync, pick, delete and check breaks at once,
  which is what e056779a does: three of the four new tests red.
- The reporter's case with the real binaries, in a sandbox HOME: magpie
  at e056779a wired OpenCode to think/deep; OpenChamber's own
  toProviderEntity (openchamber main 6b48aecb, its zod import stubbed
  so the module loads) turned that provider.magpie into the
  providers.magpie its form saves, and provider.magpie was taken out,
  as its form does; think/new was added, and magpie at e056779a synced.
  OpenCode 2.1.4's opencode models (npm @opencode/cli-linux-x64,
  integrity checked) listed magpie/think/deep alone, and its log had
  two "retained native value over legacy value" lines. The same file
  synced by this commit: magpie/think/deep and magpie/think/new, no
  such line, and a second sync left the file as it was, mtime too.
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 69 packages ok and 7 red, none in what this changes; in
  internal/agent every test this adds or touches passes. The reds: agent
  TestFolderVarsAreListed (#3884, main's CI red), TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath (#3141: alone at -count=40, TestZedAppPath is red
  37 and 35 times at e056779a, 35 and 38 here),
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641); davsync TestSync
  (#3420: alone at -count=20, red 3 times at e056779a and 2 here); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
  #3640); gateway TestPluginToldWhereTheAgentWorks (#3675); gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649); provider TestCodexAppServersOnHome (#3906, main's CI red),
  then "close of synctest channel from outside bubble" from
  TestUnreadLoginsWriteErrorsKeepCredentials (#3632, main's CI red).
- gofmt -l clean. go vet -tags nogui and go build -tags nogui for linux,
  windows and darwin, and go vet and go build for windows without the
  tag: exit 0 each. go vet and go build without the tag on linux: exit 1
  (this box has no GTK or WebKitGTK dev packages).

Not tried: Windows, the reporter's system, and OpenChamber's app
itself: its converter alone was run.

Ported onto main by yetone. Since this was written, cdd470ce9 (#4575)
made the models of magpie's provider under provider an ordered list
(orderedJSON) instead of a map, so the block under providers came out
with no models at all (TestOpenCodeProvidersKeptCurrent and
TestOpenChamberProvidersKeptCurrent red on main with the patch as it
was), and #4575 added a model's cost. openCodeNative now reads that list
and writes the models under providers in the same order, and a cost in
OpenCode 2's words: a list of tiers, cache prices under cache
(migrateModel's costs in packages/core/src/v1/config/migrate.ts).
OpenCode's source read at v2.1.4 (68bc26b7) and v2.2.5: in both,
normalize.ts merges provider into providers (mergeMaps), and a name
under both is the one under providers, taken whole, so the fix holds
on the current 2.2.x too. TestOpenCodeNativeKeepsOrderAndCost is new,
and providersCurrent checks the order.

Run for the port (mote-run, macOS, go1.26.8): go test -tags nogui
-count=1 -run 'OpenCode|OpenChamber|MiMo|DevEco|Spelled|Wiring'
./internal/agent: ok.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).

Co-authored-by: yetone <9rqwv2ak@gmail.com>
2026-11-03 20:38:11 +08:00
yetone af55a7917f tui: quitting where magpie opens at login says how to have the gateway handed on (#3756)
With #3372, Open at login on Linux reads a package's own autostart entry
in $XDG_CONFIG_DIRS (nixpkgs ships one). JoeyWu-tech's #3756 asked what
`magpie daemon install`'s guard and `magpie tui`'s hand-off as it quits
should count on a box no desktop logs into (NixOS-WSL, a server over SSH),
where nothing ever starts that entry.

Decided: both keep counting what Open at login shows (autostart.Enabled).
A session check can't tell (an SSH login into a desktop box has no
DISPLAY either), and counting less than the switch shows would install
the service beside an app the desktop does start. The install already
refuses with "run `magpie autostart off` first", which is the way out.
The terminal's quit only said "the gateway stopped", with nothing about
why or what to do; it now says magpie opens at login and serves it then,
and that `magpie autostart off` has magpie tui hand it on where no
desktop logs in (atLoginNote). Off Linux and with nothing connected the
note is as before.

What was run (wsl-run, magpie-desktop Ubuntu 24.04, go1.26.8):
  go test -tags nogui -count=1 ./internal/autostart ./internal/daemon
  ./internal/testenv ./internal/tui: ok
  With keep.go as before (the test kept): TestKeepGatewayAsTheTerminalQuits
  red, "app at login: ... the gateway stopped with magpie tui; ..."
  gofmt -l: nothing

Not tried: a real NixOS-WSL login; mtul0729 ran the #3372 patch on real
NixOS + COSMIC, at the systemd generator's level.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
JoeyWu-tech ab25a2317b autostart: on Linux the switch follows a package's own entry (#3372)
mtul0729, packaging magpie for nixpkgs (#3372, COSMIC on Wayland,
v0.1.1334): a package that ships its own autostart entry
($XDG_CONFIG_DIRS/autostart/magpie.desktop, /etc/xdg when unset) has
magpie open at login, but enabled() read only
$XDG_CONFIG_HOME/autostart, so Open at login said off over it. Off
removed a user file that wasn't there, and the package's entry went on
starting magpie. On wrote this copy's own path over the package's entry:
under a package manager a versioned path, gone once the package is
upgraded and collected. The package doc says the switch "can't say one
thing while the system does another"; on such a system it did.

Now, as the XDG Autostart spec has it:
- The entry that counts is the user's, else the first of the
  $XDG_CONFIG_DIRS folders (/etc/xdg when unset or empty) that has one.
  A relative folder has none, as the spec says, and neither has a file
  listed there, a folder this user can't search or a name too long,
  which systemd's generator and GLib can't open either. The user's own
  folder listed there too, by any name (os.SameFile, so /home linked to
  /var/home too), is still the user's.
- An entry is read as GLib's key file and systemd's parser read it: the
  keys of its [Desktop Entry] group alone (a [Desktop Action]'s Exec is
  not the entry's), spaces around = and CRLF lines as any others, the
  last of a key given twice, true or 1 for Hidden. It opens magpie when
  it is an application (Type=Application) with an Exec other than true
  (below), not Hidden.
- X-GNOME-Autostart-enabled=false (or 0) reads off too, as the issue
  asks. GNOME's and Cinnamon's sessions read it; systemd's generator
  (KDE's and COSMIC's sessions under systemd) doesn't, so there such an
  entry reads off while it starts.
- Off, over a package's entry that some desktop starts, writes an entry
  of the user's that hides it; that includes one GNOME has off, which
  systemd's generator still starts. Otherwise off removes the user's
  entry, as before. On, over a package's entry that starts magpie,
  removes the user's entry and writes no path; otherwise (no package
  entry, a hidden one, or one GNOME has off) it writes this copy's
  entry, as before.

The hiding entry is "[Desktop Entry] Type=Application Name=magpie
Exec=true Hidden=true". A session holds back the entries of a name only
once it has read one, and each reads differently (from their source):
- gnome-session (main and 42.0) and cinnamon-session load an entry with
  g_desktop_app_info_new_from_filename. GLib (main,
  g_desktop_app_info_load_from_keyfile) refuses one with no Type or
  Name, or whose Exec names a program it can't find, and the session
  skips an entry it can't load, so the package's starts.
- mate-session's egg_desktop_file_new refuses an application entry with
  no Exec, and the entry then takes no app id.
- cosmic-session without systemd never reads Hidden: it starts what Exec
  names, and takes the name once that ran.
- systemd's generator (main, xdg-autostart-service.c) reads Hidden
  first, and hides an entry it can't parse, which still holds back the
  rest.
true is on every system by that name, so each session reads the entry,
and COSMIC's runs true where it would have run magpie. A copy of the
package's own Exec would stop holding the package's back on GNOME once
its store path is collected. With this box's GLib 2.72.4 (Ubuntu
22.04's) and 2.84.2 (anaconda's), through ctypes: Exec=true and no Exec
load, hidden; an Exec naming a store path that is gone, and a bare
"[Desktop Entry] Hidden=true", don't load. An entry that runs true opens
nothing, so it reads off: XFCE's Session and Startup lists the hiding
entry as magpie, unticked, and ticking it there writes Hidden=false into
it (xfae-model.c), which runs true, not magpie. On takes it away for the
package's.

What is no entry, and what can't be read: a path where no regular file
is (a folder, a link that leads nowhere or round in a loop) is no entry,
as systemd's generator and GLib pass over it, and on leaves a folder
there alone. A file that can't be read (EACCES, EPERM, EIO) counts and
starts nothing, as systemd's generator has it; GLib passes over it, so
where the first entry is unreadable GNOME starts the next folder's while
Open at login reads off. Any other failed read, magpie out of files or
memory, says nothing of what the desktop reads at login: Set returns it
and writes nothing, and Open at login reads on, as the package's doc has
it for a system that can't be asked (Windows' Run key that can't be read
is not a no either).

The user's entry is written where the desktop reads it. A link there (to
magpie's launcher, which install.sh writes, the usual way to have an app
open at login; or into a read-only store), or a hard link, is replaced
by the entry, not written through: edit.WriteAtomic writes a link's
target, and a hard-linked file in place, so off over a package's entry
would have left the launcher running true, and failed over a read-only
target with the switch still on. Main's enable() wrote through such a
link too, when on was asked over one (a linked launcher already reads
on); it goes through the same write now.

Old entries: a user entry an older magpie wrote stays and still counts
over a package's, as before. The switch reads on over it, so in the app
taking it away is off, then on; `magpie autostart on` does it in one
step. One whose store path was collected reads on as well, though
systemd's generator starts nothing for it and still holds the package's
back, so on COSMIC or KDE magpie doesn't open while the switch says on;
GLib passes over it, and GNOME starts the package's.

The daemon and the terminal: `magpie daemon install` refuses while
magpie opens at login, so the app and the service don't both serve the
gateway, and `magpie tui` quitting hands the gateway on (keepGateway,
75e78a5a) only where nothing opens magpie at login. Both read
autostart.Enabled, code unchanged, so a package's entry counts for both
now. Where a desktop session runs XDG autostart that is the point:
install says to run `magpie autostart off` first, which now hides the
entry, where before the service went in beside an app the package's
entry went on opening. On a box no desktop logs into (NixOS-WSL, a NixOS
server over SSH) nothing runs the entry, yet install refuses and
keepGateway only says the gateway stopped; `magpie autostart off` gets
both going. That is #3756, filed with this, for yetone to say what they
should count on Linux; a session check wouldn't settle it, since install
over SSH into a desktop box has no DISPLAY either.

An entry the desktop's own settings switched off reads off for the guard
as well: XFCE writes Hidden=true into the user's entry, which main still
counted (it read Type and Exec alone), so install refused; now it goes
in. I kept that reading, and daemon.go's comment now says so, rather
than have the guard count such an entry. The switch and `magpie
autostart` read it off, and a guard counting it would refuse with
"magpie already opens at login" where `magpie autostart` says it
doesn't. The Mac has a state for that case (NeedsAllowing, which the CLI
and the app explain in System Settings' words), and Linux has none to
show it; Windows reads a Run value Task Manager switched off as off, and
on switches it back, as Set(true) does here. What it costs: ticking
magpie again in the desktop's settings after the install opens the app
beside the service, in #3756 too. For an AppImage or a tarball, with no
package entry, on and off write and remove as before, and what changes
is how an entry reads (Hidden, the GNOME key, a failed read, as above)
and that a link at the entry is replaced, not written through.

docs/subsystems/gui-shell.md says how Open at login reads on Linux, and
that the terminal's hand-off counts a package's entry (#3756).

Rebased onto origin/main 58fb3a77: 824100f3 added a line to
gui-shell.md next to the one this patch changes, so 7e9003aa no longer
applied. The code and the docs line are as they were (the same patch
for internal/).

What was run (tree 59fb33a8, on origin/main 58fb3a77, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- go test -tags nogui ./internal/autostart ./internal/testenv -v:
  autostart ok, its new tests among them; testenv ok but TestProgram,
  red under this box's umask 077 (#3640), as on main.
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  vet for windows without the tag, go build -tags nogui for linux and
  darwin, and go build for windows: exit 0 each; untagged linux vet and
  build stop at pkg-config (no GTK headers here). GOOS=freebsd vet: not
  run at this tree.
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2, 8m35s, load 19 at its start: 70 packages ok, autostart,
  daemon, cli and tui among them; reds in 6, each known: agent
  TestInstalledVersion, TestCursorFolderFromTheEditorIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath (#3141), TestCodexDriftReached (#3398) and the two
  Reasonix tests (#3641); davsync TestSyncTeraCloudStillSeesOtherWrites
  (#3420);
  edit TestWriteAtomicReadOnlyHardLink and testenv TestProgram
  (umask 077, #3640); gateway TestPluginToldWhereTheAgentWorks (#3675),
  the package ran to its end; gui TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649).

The rest is what was run for 7e9003aa, at tree 719db0e7 on origin/main
6e6aba51, the same code (not this tree):
- Real use (real.log): the built magpie (-tags nogui) and origin/main's,
  each in a sandbox HOME under env -i, with a package entry (Exec=magpie
  tray, magpie on PATH) in XDG_CONFIG_DIRS, and systemd 249's
  systemd-xdg-autostart-generator after each step:
  - the package's entry alone: main says magpie doesn't open at login
    while the generator starts magpie tray; this says on.
  - off, twice: main writes nothing and it still starts; this writes the
    hiding entry, and the generator starts nothing.
  - on: main writes its own path, which it starts; this takes the hiding
    entry away, and the generator starts the package's magpie tray.
  - no package entry, on then off: both write their own path, which
    starts, then remove it, and nothing starts. The package's entry put
    back, off again: as the first off.
  - the package's entry with X-GNOME-Autostart-enabled=false: both say
    off while the generator starts it. Off: main writes nothing and it
    still starts; this writes the hiding entry, and nothing starts. On:
    both write their own path.
  - the hiding entry ticked again as XFCE does (Exec=true, Hidden=false)
    over the package's: the generator runs /usr/bin/true; main says on,
    this says off. On: this takes it away and the package's magpie tray
    starts; main writes its own path.
  - the user's entry a link to magpie's launcher, off over the
    package's: main takes the link away and the package's entry still
    starts; this writes the hiding entry in the link's place, and
    nothing starts. The launcher is unchanged in both.
  - an old entry of magpie's naming a store path that is gone, over the
    package's: both say on, and the generator starts nothing. On: this
    takes it away and the package's starts; main writes its own path.
- The new tests over origin/main's autostart_other.go, with a nil
  systemRecords and readEntry added so they build (red-on-main.log): all
  9 new ones red, and TestSet and TestSetThenTruncatedRecordReadsAsOff,
  which main has, pass. The first red of each: :101 "the package's entry
  opens magpie at login, and Open at login reads off"; :226 "the second
  system folder's alone: off, want on" (and 5 more rows: three more
  where a system folder alone has the entry, the user's own entry
  Hidden, and the user's own off by the GNOME key); :241
  "XDG_CONFIG_DIRS unset: [], want
  ["/etc/xdg/autostart/magpie.desktop"]"; :311 and :373, no hiding entry
  written; :440, off over a link to the launcher left no entry of the
  user's, and :437, on over it with no package's entry wrote through to
  the launcher (main's own enable(), the sibling above); :491 "a folder
  at the user's entry, the package's entry there: true: off, want on";
  :534, on over an unreadable user entry leaves it; :568, no hiding
  entry to read.
- Broken by hand (breaks.log), each one part of the fix undone, all 36
  red, the fix put back ok after. The first red of each:
  - where entries come from: no system folders :101; the system's
    folders over the user's :108; unset XDG_CONFIG_DIRS with no /etc/xdg
    :241; a relative folder kept :266; the user's folder, by any name,
    taken for a system's :290.
  - how an entry reads: Hidden ignored, Hidden=false read as hidden,
    Hidden=1 not read, all :226; the GNOME key ignored, and its 0 not
    read, :226; the system's entry starting whatever its Type :226;
    spaces around = kept, a line's CR kept, every group's keys read as
    the entry's, all :226; an entry that runs true read as opening
    magpie :120.
  - what off and on write: off always removing :108; off writing the
    hiding entry with no package entry :173; off deciding by GNOME's
    reading :373; on always writing this copy's path :131; on over a
    package's entry keeping the hiding entry :127; on taking away a
    folder of the entry's name :495.
  - the hiding entry: with no Exec :323, no Type :318, a store path for
    Exec :326, true named by a path :326.
  - what can't be read: a file in XDG_CONFIG_DIRS, a folder this user
    can't search and a name too long, each read as a failed read, :269;
    a folder at the entry's path, and a link loop, read as one :491; an
    unreadable entry read as no entry :528; every failed read an entry
    that starts nothing :576; magpie's own failed read read as no entry
    :576, and taken for a no :580.
  - links: a symlinked entry written through :437, and a hard-linked one
    :437.
- internal/autostart, daemon, cli and tui (pkgs.log): ok.
  internal/autostart with -race -count=3 (race.log): ok; nothing in it
  runs in a goroutine of its own.
- Probes at this tree, thrown away after (probes-3756.log): keepGateway
  with the real reading and all else stubbed, and Install behind
  daemon_test's fakes (fake systemctl, launchctl and loginctl alone on
  PATH). With the package's entry, keepGateway only says the gateway
  stopped and Install refuses before any systemctl call. Under the
  hiding entry off writes, and with no package entry but the user's own
  entry Hidden=true as XFCE writes it, keepGateway installs the service
  and Install goes through (the fake's daemon-reload, enable and
  restart).
- Full suite, -tags nogui (CI's Linux job tags gtk3), outside graftcp
  (systemd-run, umask 077, Bun 1.4.2 first on PATH as on CI, -timeout
  45m, log kept): 64 packages ok, autostart, daemon, cli and tui among
  them, and 8 packages red, each filed:
  - agent TestCodexDriftReached: #3398; TestInstalledVersion,
    TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI,
    TestOmpDetectedWithPiDir and TestZedAppPath: #3141;
    TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: this box's /tmp/.git,
    #3641.
  - davsync TestSyncTeraCloudStillSeesOtherWrites: #3420.
  - edit TestWriteAtomicReadOnlyHardLink: this box's umask 077, #3640.
  - gateway TestPluginToldWhereTheAgentWorks: this box's /tmp/.git,
    #3675.
  - gui TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie:
    this box's millions of open fds, #3649.
  - #3741.
  - provider: "fatal error: close of synctest channel from outside
    bubble" in TestUnreadLoginsWriteErrorsKeepCredentials, main's CI
    red, #3632; the package's tests after it didn't run.
  - testenv TestProgram: this box's umask 077, #3640, red so at
    origin/main 6e6aba51 alone too (testprogram-main.log).
- gofmt -l: clean. go vet -tags nogui for linux, windows and darwin,
  GOOS=windows go vet ./..., GOOS=freebsd go vet ./internal/autostart/
  ./internal/daemon/, go build -tags nogui for linux and darwin and
  GOOS=windows go build ./...: all clean. Untagged linux vet and build
  stop at pkg-config here (no GTK headers on this box).

Not changed: gnome-session also reads $XDG_DATA_DIRS/gnome/autostart,
between the user's folder and $XDG_CONFIG_DIRS; it isn't in the spec,
and this doesn't read it. systemd reads an XDG_CONFIG_DIRS that is set
but empty as no folders, and opens a relative folder from its working
directory; this follows the spec: /etc/xdg for an empty one, and no
relative folder. Whether the program an entry's Exec or TryExec names is
there isn't checked, and an entry with any Exec (Exec=magpie serve,
another program's magpie.desktop) reads as magpie opening at login. With
no package entry that starts magpie (none, a hidden one, or one GNOME
has off), on still writes the path self() gives, a versioned one under a
package manager (#3621, where skygunner has a branch, 0aac5452, which
git apply --check takes over this one); a Linux refresh() that took away
an old entry of magpie's whose Exec is gone, where a package's entry
starts magpie, belongs there too.

Not tried: a real login into GNOME, KDE, MATE, Cinnamon, XFCE or COSMIC
(what each session does is read from its source, GLib's loading tried
with the two GLibs above); NixOS itself, and home-manager's links; a
real `magpie daemon install` or keepGateway over a package's entry,
which would reach this box's own systemd and gateway
(TestRefusedBesideAutostart and TestKeepGatewayAsTheTerminalQuits stub
what they read, and the probes above use the real reading).

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
JoeyWu-tech 985b9f1a0a gateway: Reasonix's session-context snapshot is the agent's (#3938)
keeyangyy (#3938) named their client: Reasonix 1.x, which sends no
session header (it sets x-opencode-session on its OpenCode Go paths
only) and opens every conversation on a snapshot it writes, the same
bytes in every conversation started in one workspace while its memory
and skills catalog don't change:

  {"role":"user","content":"<session-context version=\"1\">\nThis host-generated snapshot supersedes every earlier session-context snapshot.\n\n## Environment\n...\nDigest: sha256:<hex>\n</session-context>"},
  {"role":"user","content":"the question the user actually typed"}

userWords didn't know the block, so the commit before this one still
hashed it alone: every conversation a workspace opened had one id, and
under Stays = session each new one was kept on the account that
answered the first.

"<session-context" joins injected, beside Codex's
"<environment_context>", with no closing ">" so that its version
attribute matches. What asks userWords now passes over the snapshot as
it passes over Codex's context:
- the conversation's id runs from the snapshot through what the user
  typed (conversationOpening);
- the turn count: [snapshot][typed] is turn 1, where it was 2
  (turnIn);
- a group's conversation key is the typed words, where it was the
  snapshot, the same for every conversation in the workspace
  (firstWords, in ruleKey and the affinity scope);
- the turn before, which the classifier is told (turnBefore): on a
  conversation's first turn, and on each turn a new snapshot comes
  with, it was the snapshot, workspace and memory and all, as the
  user's previous message with no reply; now it is nothing on a first
  turn, and the user's words before the snapshot and the reply to them
  on a later one;
- the classifier's question, Copilot's Auto and gatewayQuery take the
  user's last words before a snapshot sent after them, and the Claude
  subscription takes one after tool results as the agent's notice
  (agentNotice).

A Reasonix conversation under way when this lands gets an id of its
own on its next turn and is routed once as a new conversation, as the
previous commit says of the others: it may move to another account,
and its cache there starts over.

The shape is the report's, which keeyangyy read from Reasonix's source
(internal/sessioncontext) and didn't capture; its folder and digest
are left out as they left them, and the tests use it as written.

Not changed: the prompt breakdown (promptBuilder.userText) keeps its
own list of Codex's blocks and still files the snapshot as a chat
turn, so a Reasonix conversation's first turn shows there as two
turns, where Codex's context adds none. That is left for a commit of
its own.

What was run (tree 71364f08, on origin/main a5315c70, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- With the previous commit's prompt.go and the tests as committed, the
  four tests this commit touches are red:
  TestReasonixConversationsInOneWorkspaceAreApart on every protocol
  ("chat: two conversations opened on one snapshot:
  magpie-310d1b42730f273079337f01 and magpie-310d1b42730f273079337f01
  (the snapshot alone: magpie-310d1b42730f273079337f01)");
  TestNewConversationsInOneFolderAreRoutedApart ("Reasonix's second
  conversation went to k2 as "session", conv
  magpie-310d1b42730f273079337f01; its first is on k2, conv
  magpie-310d1b42730f273079337f01"); TestTurnInSkipsWhatTheAgentPutIn
  ("Reasonix's snapshot, then the user's words: turn 2 within false,
  want 1 false"); TestFirstWordsAreWhatTheUserSaid ("key changed for
  conversation 4").
- Here, those four -count=5: 20 pass.
- The tests of the opening and of what userWords feeds, in
  internal/gateway, sessions, gui and provider (the conversation id,
  dsh's ids, affinity, rotate, strict, OpenCode's sessions, the turn
  count, the classifier's question, firstWords, Copilot's Auto, a
  rule's turn held past an agent's message): ok, 121 top-level tests
  passed, none failed.
- The previous commit's 12 hand-breaks of conversationOpening,
  userOpens and writeOpening, each alone on this tree: each red on the
  same tests as at a6037f68, and the first (the first user message
  hashed alone) also on TestReasonixConversationsInOneWorkspaceAreApart.
- -race -count=5 of the routing and opening tests with the new ones:
  85 pass, no race. -race -count=3 of the two allocation bounds: 6
  pass.
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  build -tags nogui for linux and darwin, and go vet and go build for
  windows without the tag: exit 0 each. go vet and go build without the
  tag on linux: exit 1 (no libsoup-3.0 or gio-unix-2.0 here).
- go test -tags nogui -count=1 -timeout 45m ./... (Bun 1.4.2, log
  kept; 8m43s, load 28 at its start): 72 packages ok, 5 red, none of
  them this commit's tests or what they cover. internal/gateway ran to
  its end (510s), so the new tests passed in it. The reds: agent
  TestInstalledVersion, TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir (#3141), and
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641, the Agents page's
  check of the Reasonix CLI, which this doesn't reach); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
  #3640); gateway TestPluginToldWhereTheAgentWorks (#3675) and
  TestUploadStillUnderwayIsNotCutByHealthPing (red on main, #3909,
  which has a test-only patch); gui TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649).

Not tried: Reasonix itself, or a body it sent. Its source
(internal/agent/session_context.go, 1.39.10) sends a new snapshot only
when its digest changes, as a user message of its own; the openai
provider magpie writes for it (internal/agent/reasonix.go) sends each
message as a Chat message of its own, and its Anthropic provider,
which merges adjacent user messages, keeps the snapshot a text block of
its own, which userWords reads alone.

Ported with the commit before onto origin/main 5ee5274bd from
JoeyWu-tech/magpie fix/3938-opening-run-4 (02c1de292, f50687a46; posted
on #3938, sha256 7cdb7e83...). The code applied as is; the docs and
extrabody.go's comment were merged by hand beside main's newer text
(${threadId}, ${subagentId}).

What was run for the port (mote, macOS, go1.26.8): the five tests in
conversation_opening_test.go and user_said_test.go's new case, with
the conversation id, dsh, affinity, rotate, strict, sticks and extra
body tests: ok. The same tests on 5ee5274bd (old code, new tests):
TestConversationsOnOneEnvironmentMessageAreApart (chat, messages,
responses, gemini, gemini without roles),
TestReasonixConversationsInOneWorkspaceAreApart,
TestCacheMarkMovingOnKeepsTheID, TestOpeningHashReadsInPlace and
TestNewConversationsInOneFolderAreRoutedApart red.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
JoeyWu-tech 55a190f195 gateway: conversations opened on one fixed message no longer share an id (#3938)
keeyangyy (#3938): with no session header, conversationID named a
conversation by the raw bytes of its first user message alone. Some
agents open every conversation on a message they write themselves and
send what the user typed as the next user message:

  {"role":"user","content":"<environment_context>cwd=/w/proj ...</environment_context>"},
  {"role":"user","content":"the question the user actually typed"}

That message is the same in every conversation started in one folder,
so all of them had one id: under Stays = session each new one was kept
on the account that answered the first, and rotate never moved on.

conversationOpening now says what is hashed, from the first user
message on (Chat and Anthropic messages, Responses input, Gemini
contents, where an omitted role is the user's):

- A first user message that holds anything of the user's own is hashed
  alone, as the request has it, exactly as before: their words
  (userWords, which already tells an <environment_context> or
  <user_instructions> block or an instruction file from what the user
  typed), an image, a file or a recording (userOpens). So is one that
  holds a tool's result.
- One the agent wrote alone is hashed with the user messages after it,
  in order, through the first that holds the user's own. A system or
  developer message between them is passed over.
- A reply, a call, its output, reasoning, a tool's result (Gemini's
  function result too), an item without a role (Chat, Responses) or
  one that can't be read ends the opening. With nothing of the user's
  before it, the first message is hashed alone, as before.

Every later turn repeats the opening before the first reply, so the id
holds through the conversation. A Responses input that is one string
is hashed as before.

An opening of several messages is hashed as writeOpening reads them,
one after another: every object's members in key order with no space
between, no cache_control at any depth, and a content of one text part
as that part's text. An agent marks its newest user message for the
cache and moves the mark on next turn, so the typed message's bytes
change at turn 2; some spell a marked message as a list of one part and
an unmarked one as a plain string (dsh does). Hashed as sent, an
opening of several would get a new id at its second turn, and on
/v1/messages under rotate that turn would go to the other key as a new
conversation (below). writeOpening reads the messages where they are:
the id of a 1.1 MB body whose opening holds a screenshot allocates
about 10 KB (TestOpeningHashReadsInPlace).

Every conversation whose first user message is the user's own keeps
the id it has, so no stick record needs moving. One that opened on an
agent's message and is under way when this lands gets an id of its own
on its next turn and is routed once as a new conversation: it may move
to another account, and its cache there starts over. The record they
all shared stays under the old id.

A tool's result (Anthropic clients send it as a user message) ends the
opening: it answers a call the model made, so the opening is over. A
history that starts with one was cut by its client (magpie takes such
orphans, TestMessagesOrphanToolResultWithoutACallBecomesText). Its
opening is gone, and whatever was taken in after the cut would move the
id each time the client cuts again, so its first message is hashed
alone, as before.

Not the issue's "first two user messages", nor every user message up
to the first reply: in an ordinary conversation the second user message
is the next turn, so the id would move when it arrives, and every
record would need the migration the issue describes. And a run of
every user message takes in what dsh sends after the typed prompt, its
runtime context, where the Context page finds dsh's sessions by the
typed prompt's hash alone; TestDshSessionConvsAreTheGatewayIDs and
TestDshRoutesCarryTheSessionConvs go red under such a run (below).

What reads the id moves with it: stickKey (session, turn and strict
affinity, and rotate's spread of new conversations), the Routing
trace's conv (convOf), a sealed task's lead (leadProvider,
loggedAnswerers), extraBody's ${sessionId}, Kilo's task and session
headers (KiloClient), X-Magpie-Conversation to plugins and OpenCode's
x-opencode-session fallback (openCodeSeed). A group rule's key reads
conversationID without a body, beside firstWords, which already passes
over the agent's blocks, so it doesn't change. One reader rebuilds the
id itself: sessions' dshConvs, which the Context page joins dsh's
sessions by (joinConvs). It hashes dsh's typed prompt, a first user
message of the user's own, which is still hashed alone, so its ids stay
the same. Nothing else in sessions, gui or elsewhere rebuilds a
"magpie-" id. The comments that named the first user message, and the
Gateway routing and Providers and accounts pages, say what the id is
now.

Siblings left for a decision, each in an issue filed with this
patch: #3988, ChatGPT accounts (conversationKey in
internal/provider/codex_request.go, for a client that sends no
prompt_cache_key), and #3989, Antigravity accounts (antigravitySession
in internal/provider/google.go). Both hash the first user message in the
provider package, and userWords is the gateway's.

Not changed: a fixed first message that userWords doesn't read as the
agent's is still hashed alone, so the conversations an agent opens on
it still share one id. A first user message hashed alone is hashed as
the request has it, cache mark and all, so a client without a session
header that marks that message on its first turn only gets a new id at
its second, as before. An agent that answers its own first message
with a fixed reply before the user's turn ends the opening at that
reply, so its first message is hashed alone too.

What was run (tree 523c770b, on origin/main a5315c70, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- This commit's tree alone: not run. It is a6037f68 rebased: its
  internal/ diff is the same (one patch-id), and
  docs/subsystems/gateway-routing.md was merged by hand beside main's
  new One try row. At the next commit's tree (71364f08), which adds a
  line to userWords' list and tests: this commit's tests, every break
  below again, -race, vet and the full suite, recorded in the next
  commit.

The rest is what was run for a6037f68, at tree e8fc1eee on origin/main
e9dd8e83, the same code (not this tree):
- New: TestConversationsOnOneEnvironmentMessageAreApart, on Chat,
  Messages, Responses and Gemini bodies, the last with and without
  roles. The issue's two conversations from one folder get two ids,
  neither the environment message's own, and each keeps its id on its
  next turn. A conversation that opens in the user's words has
  "magpie-" and the hex of sha256(its first user message)[:12], alone,
  on a later turn and with the agent's message after it. A screenshot
  after the agent's message opens a conversation as words do. A
  developer or system message between them doesn't move the id. dsh's
  turn, its runtime context marked for the cache, has the typed
  message's own. A history cut at a tool's result keeps its first
  message's own, and so do these after the agent's message: a tool's
  result, a Chat message without a role, a Responses call, its output
  or reasoning, and a Gemini function's result, in a user content or
  in its own role. A Responses string input is hashed as before.
  TestCacheMarkMovingOnKeepsTheID: the issue's opening on Messages,
  Chat and Responses, the mark on each turn's newest user message,
  turns 1, 2 and 3 with one id, the typed message going on unmarked as
  one part, as a plain string or with a screenshot, and on Chat marked
  on the message itself. TestOpeningHashReadsInPlace: the 1.1 MB body
  above under image_input_test.go's bar of an eighth of the body.
  TestNewConversationsInOneFolderAreRoutedApart: two keys, rotate,
  Stays = session, no session header. On /v1/chat/completions the two
  conversations are each "first", on different keys with different
  convs, and each next turn stays on its key as "session" with its
  conv. On /v1/messages a third conversation, its mark moving on, is
  "first" and turns 2 and 3 stay on its key as "session" with its conv.
- Broken by hand, each red:
  - back to the first user message alone (the old rule):
    TestConversationsOnOneEnvironmentMessageAreApart on all five bodies
    ("two conversations opened on one environment message": one id, the
    message's own; and the screenshot case),
    TestCacheMarkMovingOnKeepsTheID (each of its ten first turns the
    environment message's own),
    TestOpeningHashReadsInPlace ("the environment message was hashed
    alone") and TestNewConversationsInOneFolderAreRoutedApart (the
    second conversation on k1 as "session", with the first's conv).
  - every consecutive user message, unread: the five bodies' cases
    with the agent's message after the user's, the screenshot cases,
    dsh's two turns, the cut history, the tool's result after the
    agent's message and Gemini's function result in a user content,
    and TestDshSessionConvsAreTheGatewayIDs and
    TestDshRoutesCarryTheSessionConvs (the turn's conv not among the
    session's).
  - a tool's result taken into the opening, and passed over like a
    developer message: the cut history, the tool's result after the
    agent's message and Gemini's function result, each way.
  - a system or developer message ending the opening: the Chat and
    Responses pairs.
  - an image, a file or a recording not counted as the user's: the
    screenshot case on all five bodies.
  - an item without a role passed over like a developer message: the
    Chat message without a role and the Responses call, output and
    reasoning.
  - Gemini's functionResponse not read as a tool's result: its case.
  - an opening of several hashed as sent:
    TestCacheMarkMovingOnKeepsTheID at turns 2 and 3 in all ten
    spellings, and on /v1/messages turn 2 went to k2 as "first" with a
    new conv, where turn 1 was on k1.
  - cache marks kept: the screenshot spellings and the message marked
    on Chat, at turns 2 and 3 (a one-part content is read as its text
    either way).
  - a content of one text part not read as its text: the three plain
    string spellings at turns 2 and 3.
  - each string copied before it is hashed: TestOpeningHashReadsInPlace,
    2,233,788 bytes an id.
- With their neighbours, -v: TestConversationID, the Dsh tests in
  gateway and sessions, TestContextDshSessionTitles,
  TestImageWalkReadsTextOnlyTurnsInPlace, the orphan tool result tests,
  TestClaudeConversationKeepsItsAccountsCache, and the affinity,
  rotate, strict, sticks, session route, OpenCode, extra body,
  WorkBuddy session and gateway conversation tests: 115 tests in
  gateway, sessions, gui and provider pass (154 with subtests).
- -race -count=5: TestConversationsOnOneEnvironmentMessageAreApart,
  TestCacheMarkMovingOnKeepsTheID,
  TestNewConversationsInOneFolderAreRoutedApart, TestAffinity,
  TestRotateSpreadsSessions, TestRotateSpreadsABurstOfNewConversations,
  TestGeminiFallbackSessionAffinity, TestSticksWrittenBehind, the three
  TestStrictAffinity tests, the two dsh conv tests and
  TestClaudeConversationKeepsItsAccountsCache: 14 tests, 5 of 5 each.
  -race -count=3: TestOpeningHashReadsInPlace and
  TestImageWalkReadsTextOnlyTurnsInPlace, 3 of 3 each (the id under
  -race: 17 to 32 KB).
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  build -tags nogui for linux and darwin, and go vet and go build for
  windows without the tag: exit 0 each. go vet and go build without
  the tag on linux: exit 1 (this box has no GTK or WebKitGTK dev
  packages).
- go test -tags nogui -count=1 -timeout 45m ./... (tools/suite.sh, Bun
  1.4.2, log kept; 8m23s, load 21 at its start): 71 packages ok, 5
  red, none in what this changes: agent TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath (#3141), TestCodexDriftReached (#3398) and the two
  Reasonix tests (#3641); edit TestWriteAtomicReadOnlyHardLink and
  testenv TestProgram (umask 077, #3640); gateway
  TestPluginToldWhereTheAgentWorks (#3675), the package ran to its
  end, so the new tests passed in it too; gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649).

Not tried: keeyangyy's own client, or any real agent end to end.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
JoeyWu-tech b59e4b747f gateway: a conversation on a new account leaves out the old one's seals (#3887)
hheei (#3887): a Codex conversation with a web search in it (OpenAI's
own web_search, a web_search_call in its history) failed on every turn
with "HTTP 400: Codex: Encrypted content could not be decrypted or
parsed. (code: invalid_encrypted_content)" once magpie had moved it to
another ChatGPT account of the same routing group: after its affinity
went cold ("why": "cold", over two hours on), or after the account it
was on was used up or rate limited.

What an account's turn wrote comes back sealed for that account
(encrypted_content): its reasoning, a web search, and with Codex's
output token replay on (codex-rs core/src/client.rs: only for a provider
named "OpenAI", which Codex signed in reaches magpie as) each message
and call. Codex hands it all back on every turn, and between ChatGPT
accounts, or a ChatGPT account and an OpenAI API key, magpie sends it as
it came (forVendor, 2a19245c). The account asked next can't read the
first's seals and says so. serve asked again without the reasoning only
(withoutReasoning), was refused again over the web search, had no
compaction to leave out, and passed the 400 on. What it remembered as
refused for the conversation's later turns (refusedSeals) was reasoning
and compactions only, so each later turn went the same way. The relay of
Codex's own sign-in (withoutUnreadable) left only the reasoning out as
well.

Now such a refusal is asked again without every seal but a compaction's
(withoutSeals): reasoning goes whole, as before, and any other item
keeps all but its encrypted_content (withoutItemSeal, the rest of it
byte for byte). refused records what was taken out for the key or
account that refused, and withoutRefused leaves it out of the
conversation's later requests there up front, reasoning whole and the
rest by its seal alone. What that one sealed itself still goes along,
and a request on the account that sealed what it carries goes as it
came, so a turn that doesn't move keeps OpenAI's cache and replay as
before. A compaction keeps its own step (withoutCompaction after a
second refusal, unless native compaction is on). The relay asks again
the same way after its 400. The retry is serve's, so it holds whatever
moved the conversation: an account used up, rate limited or resting, the
next member of a group, routing's own pick once the affinity went cold;
on the backend path (one of Codex's own models, signed in) and on
/v1/responses (the codex provider's model, a group of it) alike.
gateway-routing.md says so.

A refusal doesn't say whose seal it couldn't read, so the account asked
loses its own seals from an earlier stay in the conversation too, and
they are remembered as refused, as its reasoning already was.

Not changed, each as on main (#3934): a context_compaction
another account sealed stays in through both steps (keepsSeal has it,
compactionKinds doesn't); the relay keeps no record of what was refused,
so each later turn there is refused once and asked again, and a refusal
in its stream reaches Codex as it came; the relay's /responses/compact
isn't asked again; the Routing view still calls such a try "another
account's reasoning" (client.js and its translations).

What was run (tree 326b178e, on origin/main f8cd964a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestForeignSealedItemsMoveToAnotherAccount, new: a conversation
  holding acct-1's sealed reasoning, web search, call and answer moves
  to acct-2 as acct-1 answers 429 or response.failed
  rate_limit_exceeded, signed in, as codex/gpt-5.5 and as group/g,
  acct-2 refusing with a 400 or in its stream (12 cases). acct-2 is
  asked with every seal, refuses, is asked again bare and answers, and
  the next turn asks it bare with its own seals on: ok
- TestForeignSealedItemsAfterAColdSwitch, new: the same conversation
  moved back to acct-1 by its affinity gone cold (Why "cold"), 6 cases:
  ok
- TestForeignSealedItemsRelayedToAnotherSignIn, new: Codex's own sign-in
  relayed as acct-2, the history sealed by acct-1: ok
- TestSealsTakenOutLeaveTheRest, new: the exact bytes withoutSeals and
  withoutRefused leave (a seal first, in the middle and last in its
  item; compactions keeping theirs; reasoning alone taken as
  withoutKinds took it), and nothing taken out for another account or
  conversation: ok
- the three new end-to-end tests with affinity.go, gateway.go,
  codex_backend.go and routing.go as on main (swapped in through go test
  -overlay, the checkout left as committed; the unit test left out, as
  it calls withoutSeals): 21 of 21 red. The 400 cases: "moved on: 400
  {"error":{"code":"invalid_encrypted_content","message":"Codex:
  Encrypted content could not be decrypted or
  parsed.","param":null,"type":"invalid_request_error"}}", and "gone
  cold: 400" with the same; in the stream: "moved on: 200" and "gone
  cold: 200", the response.failed invalid_encrypted_content passed on to
  Codex; the relay: "400 {"error":{"message":"Encrypted content could
  not be decrypted or parsed.", ...
  "code":"invalid_encrypted_content"}}"
- broken by hand, one at a time, each swapped in the same way, beside
  the tests already there for foreign seals, compactions, reasoning and
  output replay (TestForeignSeal*, TestForeignCompaction*,
  TestForeignReasoning*, TestCodexOwnModelAfterAnotherVendor,
  TestCodexSpentMovesToGrokWithSealedReasoning, TestCodexOutputReplay*),
  all green under each but where named:
  - serve's retry taking the reasoning only (withoutKinds(body,
    "reasoning")): TestForeignSealedItemsMoveToAnotherAccount (12 of 12)
    and TestForeignSealedItemsAfterAColdSwitch (6 of 6) red, "moved on:
    400" and "gone cold: 400" with the error as on main
  - the relay's taking the reasoning only:
    TestForeignSealedItemsRelayedToAnotherSignIn red, "400
    {"error":{"message":"Encrypted content could not be decrypted or
    parsed.",...}}"
  - refused recording reasoning and compactions only (seals as on main):
    the same 18 cases and TestSealsTakenOutLeaveTheRest red, the next
    turn refused once more, "then asked [{"acct-2" "message user,
    web_search_call 上海天气 gAAAA-acct-1-w1, function_call c1
    gAAAA-acct-1-f1, ..."} {"acct-2" ...}]", and "next turn:" with the
    seals left on
  - withoutRefused taking out reasoning and compactions only: the same
    19 red, with the same lines
  - withoutRefused dropping each refused item whole: the same 19 red,
    "then asked [{"acct-2" "message user, message assistant, message
    user, message assistant, message user, reasoning gAAAA-acct-2-r3,
    ..."}]", the searches and calls gone
  - withoutItemSeal writing the item out again (marshalPlain):
    TestSealsTakenOutLeaveTheRest red, "got {...}" with the web search's
    keys sorted,
    {"action":{...},"id":"ws_1",...,"type":"web_search_call"}
  - withoutItemSeal without its keepsSeal check:
    TestSealsTakenOutLeaveTheRest and TestForeignCompactionToGrok red,
    "grok was sent [["compaction:sealed-by-openai-compaction"
    "reasoning:sealed-by-openai"] []]": the compaction lost its seal in
    the first step instead of going in its own
- the related tests (TestForeign*, TestCodexOwnModel*, TestCodexSpent*,
  output replay, the rewrite equivalence tests, TestAffinity*,
  TestNativeCompaction*, TestRemoteMagpie*, TestGatewayKey*, groups and
  Codex accounts): 257 passed with their subtests, none skipped (Bun
  1.4.2)
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway (log
  kept), Bun 1.4.2: 5418 passed with their subtests, 3 skipped, and one
  red, TestPluginToldWhereTheAgentWorks (#3675): "not in one: the plugin
  was told "/tmp/TestPluginToldWhereTheAgentWorks191044475/005", git
  "yes"; want "/tmp/TestPluginToldWhereTheAgentWorks191044475/005",
  "no"". It is red the same alone, and with the four code files as on
  f8cd964a: this box has an empty /tmp/.git, and GitOnDisk counts a .git
  in any folder above.
- read against main's 7f0f71a0 (#2481) and fff05e55 (#2725), which
  change code beside this: 7f0f71a0 puts the route on two of the relay's
  record exits, which come after withoutUnreadable has chosen the body
  asked again; fff05e55 changes only whether Codex's compaction trigger
  is kept native (plannedCarrier), not serve's retry or the step it
  skips for a provider compacting natively (compactsNatively), so a
  trigger it now has magpie summarise goes through serve and the same
  retry. Neither changes what withoutSeals or withoutUnreadable do.
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 69 packages ok and 7 red, none in what this changes; gateway's
  only red is TestPluginToldWhereTheAgentWorks (#3675), the new tests
  pass in it. The reds: agent TestInstalledVersion,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir (#3141), the two Reasonix tests (#3641) and
  TestWSLColdPlaceOpensNothing (#3924); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
  #3640); gui TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649); provider
  TestCodexAppServersOnHome (#3906), then "close of synctest channel
  from outside bubble" (#3632); tui
  TestTUIFetchesSubscriptionModels/agent (#3919).
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  build -tags nogui for linux and darwin, and go vet and go build for
  windows without the tag: exit 0 each. go vet and go build without the
  tag on linux: exit 1 (this box has no GTK or WebKitGTK dev packages).

Not tried: real ChatGPT or OpenAI accounts. Whether the ChatGPT backend
takes a web_search_call with neither its id (magpie's Codex account
route sends none, as on main) nor its seal; hheei's 200 was OpenAI's
Responses API with the id kept. Whether one account refuses another's
replayed message and call seals at all (the fake does; if it reads them,
they are still taken out on a hop, where the conversation's cache is
gone anyway). OpenAI refusing in the stream: the fake does, as xAI may;
hheei's refusal came as a 400. An OpenAI API key as the next member of a
group: forVendor keeps the seals for *openai.com only, so a fake on
127.0.0.1 can't stand in for it; it reaches the same retry in serve. Nor
magpie's summary of a Codex compaction after a move: codexCompact asks
through serve, so the same retry should apply, but no test drives it.

Ported onto origin/main 5ee5274bd from yinwu01/magpie 2d764b1c (posted
on #3887, sha256 d9185e84...). Conflicts resolved by hand: main had
since grown noteRefused (also used by reasoning_carry.go's
refuseCarried), so refused(key, who, sent, left) now hands it the seals
sent minus those left; foreignReasoning keeps main's broader pattern;
foreign_seal_test.go keeps main's TestForeignSealAzureSummary and
TestForeignSealGrokRelayCompactionBlob beside the four new tests; the
Affinity row and the new bullet in gateway-routing.md were merged into
main's text.

What was run for the port (mote, macOS, go1.26.8):
- go vet -tags nogui ./internal/gateway, and go test -tags nogui
  -count=1 -run 'TestForeign|TestSeals|TestCodexOutputReplay|
  TestCodexOwnModel|TestCodexSpent|TestRefused|TestReasoningCarr|
  TestWithout|TestNativeCompaction' ./internal/gateway: ok
- the three new end-to-end tests on 5ee5274bd (old code, the unit test
  left out as it calls withoutSeals): all red,
  TestForeignSealedItemsMoveToAnotherAccount and ...AfterAColdSwitch
  "moved on: 400 {...invalid_encrypted_content... Codex: Encrypted
  content could not be decrypted or parsed.}" and "gone cold: 400",
  ...RelayedToAnotherSignIn "400 {...Encrypted content could not be
  decrypted or parsed...}"

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
vincentandJoeyWu-tech 62f612fd44 proc: recheck tools installed within a directory clock tick
Adapt JoeyWu-tech f9d7eac9: do not retain lookup answers or directory listings while their timestamps are fresh. Freeze the clock in the same-tick regression so scheduler delays cannot age the fixture. Keep the settled/future directory cache and document the 100ms resolution limit.

Validation: the same-tick regression fails with both old layers, only the stamp fixed, and only the listing fixed. Restored proc lookup and four affected agent tests pass five race runs.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).

Co-authored-by: JoeyWu-tech <joey110551567@gmail.com>
2026-11-03 20:38:11 +08:00
yetone fb1f4856a8 sessions: a fork's own calls are counted; only its copies are the parent's (ZCode, Codex)
Sky (skyhuang1994) on Discord, on their real ZCode database after
v0.1.2847 (1d0fc2bb0): September's message table holds 57,787 rows,
13.552B tokens; 5,204 rows (1.537B) carry a forkOrigin and are copies,
and ZCode's cloud usage says 12.057B. The new version took 5.094B out,
3.6B of it real. The biggest was the "msc" session: forked at the end of
August, then 11,409 calls of its own in September (3.489B), none with a
forkOrigin, a custom-UUID provider. The Usage page had 0 of them.

Cause (ZCode): readZCodeCalls marked copies in a map keyed by m.ID. A
row's id is in the message table's id column, not in its data (OpenCode
writes data without id; checked on this machine's real opencode.db: 2 of 2
rows have no $.id), so every message decodes with ID "". One copy in a
session set copies[""], and every assistant message of that session was
left out: a fork that went on working lost all of its own calls. The test
fixtures had "id" inside data, so they never saw it. The Sessions page
(parseOpenCode) asks zcDB.copied per message and was right.
Fix: copies are marked by row index. Only a message whose forkOrigin
names a messageId still in the database is skipped.

Codex: a fork's checkpoint was a copy whenever its {total, last} was one
the parent's rollout holds, anywhere in the fork. A fork goes on working,
and its first own call can carry exactly the numbers of the parent's
next call after the fork (same history, same next prompt). The copies
are now the head of the fork only: the fork's first turn_id the parent
never had (turn_context or task_started) ends them (ownTurn,
CopiedTurns, read with the parent's checkpoints). A rollout with no turn
ids is matched as before; its running total keeps later calls apart.

callParseVersions codex 2, zcode 2 and parseVersions codex 2, so the
parses kept by v0.1.2847 are read again once. ZCode's Sessions parse
didn't change and stays at 1.

Tests (fixtures follow Sky's case: a parent of 08-30, a fork with
forkOrigin copies of its replies, ZCode's fork notice, then 40 replies of
its own in September with no forkOrigin, no id in data, provider a UUID):
- TestZCodeForkThatWentOnWorkingKeepsItsOwnCalls: red on origin/main
  7d022bdb6 ("the fork's calls: 0 {...}, want its 40 own"), as Sky saw.
- TestCodexForkThatWentOnWorkingKeepsItsOwnCalls: red on main and with
  ownTurn turned off by hand (1 call on the fork, want its 2 own).

docs/subsystems/gateway-sessions.md says this.

Run on mote (mote-run) at this change on origin/main 7d022bdb6; rebased
on 08d7bfaaa (gui, redact, gateway-key only), go build ./... and
internal/sessions run again: ok.
- gofmt -l internal: empty
- GOOS=linux go vet -tags nogui ./... ; GOOS=windows go vet ./... : ok
- go test -count=1 -timeout 45m ./internal/sessions ./internal/usage
  ./internal/tune ./internal/otlp ./internal/davsync ./internal/tui : ok
- go test -run 'Session|Usage|Calls|Ledger|Stats|ZCode|Codex|Fork'
  ./internal/gui ./internal/cli : ok

Broken by hand:
- the copies keyed by message id again (origin/main): the ZCode test red,
  0 calls on the fork.
- ownTurn's call in context() off: the Codex test red, 1 call on the fork.

Not tried:
- Sky's real ZCode database; there is none on this machine and no ZCode
  source to read its writer. That ZCode's data has no id, as OpenCode's,
  rests on the symptom (every row of the fork gone) and OpenCode's real
  rows here.
- a real forked Codex rollout that went on working; the turn ids of a
  real 0.117 fork were read from the fixtures' shape, not a real file.
- the whole gui and gateway suites, and a full go test ./...: other
  sessions' suites were running on mote.
2026-11-03 20:21:17 +08:00
yetone d136d0fe98 gateway-key: rotating a key can give it a value of the user's own (isaac_bai)
isaac_bai on Discord: a gateway key's value is random, and only rotate
changes it, to another random one; they want to set one easy to pass on.
Adding a key could take an own value since 6b6113aa; an existing key
couldn't.

- access: rotate-key takes Change.Secret. Given, it is checked as an
  added key's own value (ownSecret: 8-256 printable ASCII, no space, not
  sk-magpie-, no other key's value; its own current value is allowed);
  empty, magpie makes one as before. The key keeps its id, name, limits,
  models and accounts, and Named counts a request from this computer
  with it as that key.
- ownSecret now refuses a value that is one of the user's provider keys
  (a provider's Key or any of its Keys, constant-time), for add-key too:
  a client sending it would spend that provider directly.
- CLI: `magpie gateway-key rotate <id> --key <value|->`; docs/reference.md.
- GUI (plugins/gateway/keys.js, outside the core budget): the Rotate key
  dialog has a hidden "Your own key (optional)" field; Enter rotates,
  Escape cancels; an own value says "Gateway key changed. Clients that
  send this key reach magpie now." Strings in zh, zh-TW, ja, de.

Tests: TestRotateToOwnValue (bad values refused, old value still works
after a refusal, trimmed own value authenticates as the same key, is
Named, listed masked; empty makes a new key; add-key refuses a provider
key). TestRotatedOwnValueKeepsTheKeysLimit: after rotating to an own
value the old one is 401 from another computer, the own one 200 from
another computer and from 127.0.0.1, and a 700-token day limit stops
the third request from either (429), every record under the key.
gateway-key-own-rotate.test.cjs: chromium and webkit, en/zh/zh-TW/ja/de,
1000 and 400px.

Run (mote): at the pushed head: TestCoreScriptBudget ok, ./internal/access ok, the
own-key/caller-key gateway tests ok. At f37742e14 with this change (no file the rebase touched):
gofmt -l clean; go vet GOOS=linux and windows (./internal/access ./internal/gateway, cli with
-tags nogui on linux) ok; ./internal/cli red on TestEveryRouteHasACommandOrIsNamed only,
/api/context/reply (#5026, 0872bc2a0, the same at main); GUI: gateway-key-own-rotate 20/20,
every gateway-key-*, redact-*, masking-*, privacy-* file and i18n-keys pass.
Broken by hand: the rotate own-value path off made TestRotateToOwnValue and
TestRotatedOwnValueKeepsTheKeysLimit red (401 from another computer); the provider-key check off
made TestRotateToOwnValue red ("accepted upstream-first-key").
Not run: the whole GUI suite (two runs lost: one to another run of this tree, one to mote
rebooting mid-run); it runs after the push. Not tried: a real client on another computer with
the own value, the real app.
2026-11-03 20:17:00 +08:00
yetone 22f5cf69e5 library: an agent in WSL links to the distro's one copy of a skill (cutemmuu on X)
Cause: an agent in a WSL distro could only get copies (Target.Copy).
A distro can't follow a link to the library's folder on Windows. A
link Windows makes through \\wsl.localhost (os.Symlink) is an empty
folder inside the distro. Windows can't use a link the distro has: it
can Lstat one (irregular), but Readlink fails ("Incorrect function"),
and Stat, ReadDir and Remove all say it isn't there. Probed on
xiaomi-gpu with magpie-desktop. So every agent there got a copy of
its own of every skill.

Now each distro keeps one copy of each skill its agents are given,
magpie's and marked, in ~/.local/share/magpie/skills (Target.Store,
storeSkill). Each agent there gets a link to it, which wsl.exe makes,
reads and removes inside the distro (agent.WSLSymlink, WSLReadlink,
WSLRemoveLink). The scripts refuse to put a link over a folder or file.
- An edit made through the link is in that copy, and takeEdits reads
  it like any copy of magpie's.
- When no agent there links to a copy or is given its skill any more,
  sweepWSLStores removes it. An edited copy goes to the backups.
- A folder in the store that isn't magpie's is never touched. Each
  agent it blocks reports a problem and keeps what it had.
- An agent set to copies (SkillHow) still gets copies of its own.
- So does one whose skills folder or the store is on a Windows drive
  (#4502): a link the distro makes there can't be read from Windows.
- The copy isn't put in the distro's ~/.agents/skills. Every agent
  there that reads that folder would get each skill, ticked or not.
- A stopped distro's agents are now shown as linked (HowLink), not as
  forced to copies.

Agents that read ~/.agents/skills on their own (readsShared, checked
against each one's source or docs when the list was made): Codex,
Gemini CLI, OpenCode, DevEco Code, Crush, dsh, Command Code, Devin,
Droid, Cline, Grok Build, Grok App, fx, Alma, Kimi Code and OmO, plus
Pi from 0.54.0 and omp from 11.0.0. Claude Code doesn't. Ticks are per
agent, so the store keeps per-agent choices working in WSL.

Existing users: nothing to do. On the next sync, each per-agent copy
magpie made in a distro is replaced by a link:
- its edit is taken into the library first (newest edit wins);
- a copy whose edit lost is set aside with the backups (wslRelink);
- unmarked folders (the user's own skills) are left alone.

Run:
- mote, at 3f1f1882a plus this change:
  - go test ./internal/library ./internal/agent -timeout 45m -count=1:
    both ok (493 and 1210 Test funcs; library 184s, agent 312s).
  - gofmt -l .: empty.
  - GOOS=windows, linux and darwin go vet of both packages: ok.
- xiaomi-gpu, Windows 11, WSL 2, distro magpie-desktop only:
  - TestWSLLinksLive passes. A link made through wsl.exe is followed by
    the distro, read back from Windows, refused over a folder and
    removed alone.
  - TestWSLSkillsLinkedLive passes. Working in a /tmp home inside the
    distro, it checks:
    - links for Codex and Claude Code that the distro follows;
    - a second sync changes nothing;
    - an edit made in WSL through the link reaches the library and
      Windows' Claude Code;
    - copies, then links again;
    - an untick removes the links and the store copy.
  - go test ./internal/library ./internal/agent -run 'WSL|Wsl|Skill'
    with MAGPIE_WSL_TEST_DISTRO set: library ok. In agent, only the
    older TestWSLCodexLive is red. It calls wslList() without -l -q, so
    it lists no distros. Filed as #5077; this change doesn't touch it.
New tests:
- TestWSLLinks (fake);
- TestWSLOldCopiesBecomeLinks, which edits a copy and then syncs;
- TestWSLEditThroughLinkReachesTheLibrary;
- TestWSLStoreSweepKeepsEdits;
- the two live tests above.
TestWSLSkillsCopied is now TestWSLSkillsLinked.

Broken by hand (logs in wsl-skills-scratch):
- WSL targets given copies again: 7 red, including TestWSLTargets,
  TestWSLSkillsLinked and TestWSLOldCopiesBecomeLinks.
- takeEdits not following the link to the store: 1 red,
  TestWSLEditThroughLinkReachesTheLibrary.
- ours not counting a link to the store: 3 red.
- wslLinkScript's folder refusal dropped: TestWSLLinksLive red on the
  real distro.

Not tried:
- the magpie GUI on Windows against a real distro, and agents running
  in a real WSL reading a skill through the link (the distro reads the
  link's files, checked with cat);
- WSL 1;
- a distro whose home is on a Windows drive (covered by the fake
  #4502 tests only);
- the GUI suite, since no GUI file changed.
2026-11-03 20:03:00 +08:00
yetone 6c201095d8 gateway: in Docker, other containers on the host are shown the host's Docker bridge address
jiezhengj (Discord #feedback) runs magpie in Docker on a NAS at
192.168.31.218. The web UI's host address, http://192.168.31.218:3425,
works for other devices. Other containers on the NAS couldn't use it, and
not the container's own 172.17.0.x either. What works for them is the
host's Docker bridge address, http://172.17.0.1:3425. On Linux,
host.docker.internal is there only in a container given extra_hosts.
magpie showed no such address.

- gateway.ContainerHostURL: in a container on a bridge network, the
  gateway of /proc/net/route's default route (172.17.0.1 on the default
  bridge, a compose network's own otherwise), on the gateway's port.
  It is "" outside a container and on the host's network
  (`network_mode: host`, told by the host's
  docker0/br-*/veth*/podman* interfaces). In that case ContainerAddrs is
  false too, since the addresses are the host's own.
- The GUI gets it as /api/providers' gateway.containerHost,
  /api/settings' lanContainerHost and boot's sideGateway.containerHost.
- settings.js lanShown is fed by the new gwLAN(g) for Gateway, Connect,
  the sidebar and the key page. Each case lists:
  - Opened at the host: the host's address first, then the bridge
    address, labelled "Other containers on this host".
  - At localhost: the bridge address alone, with that label, and a line
    that the host's own is MAGPIE_PUBLIC_URL's.
  - No default route: as before.
  The container's own 172.17.0.x is no longer offered beside them. The
  sidebar line and the key page prefer an address other machines reach.
  The scheme comes from the URL, not a hard-coded http. Three new strings
  are in zh, zh-TW, ja and de.
- CLI: `magpie web` and the share banner print "other containers on this
  host <url>".
- docs/reference.md and site docs/docker (en, zh, ja): the log example and a new "Other
  containers on the same host" paragraph.

Run on mote, at this change on d8501848a:
- gofmt -l: clean. node --check: passes.
- Vet: darwin go vet, GOOS=linux go vet -tags nogui and GOOS=windows go
  vet of internal/gateway, internal/gui and internal/cli: ok.
- go test -timeout 45m: internal/gateway ok. internal/gui is red only on
  TestMainWindowCorners/macOS_26_SDK, which is red on macOS 27 at main
  (#3949). internal/cli is red only on TestEveryRouteHasACommandOrIsNamed
  for GET /api/context/reply, red at main (#5026).
- GUI, chromium and webkit: lan-docker (en, zh, zh-TW, ja, de) and the
  40 files on the caller-keys fixture or the LAN paths. 586 tests, 580
  pass. Each red is also red alone at the base d8501848a or af9ac3d25:
  - phone-connect-menu 420, 4 reds (#4706, #4707).
  - gateway-key-models webkit en (#4616, #4081; 4 of 4 at the base).
  - gateway-caller-keys chromium en (#3797; 2 of 3 at the base, 1 of 3
    here).

After the rebase onto 3f1f1882a (187f3e272, the usage page alone, came after): the commits
between touch none of these files. Linux and Windows vet ok. go test -run
'Container|HostNetwork|DefaultGateway|PublicURL|LAN|Boot|Provider' ok in
gateway, gui and cli. GUI lan-docker, i18n-keys, side-gateway-lan and
key-page: 56 of 56, in both engines.

Broken by hand, in a copy:
- defaultGateway reading big-endian: TestDefaultGateway goes red
  ("1.0.17.172").
- The old settings.js, client.js and keys.js: every lan-docker test goes
  red, in both engines and every language.
TestDefaultGateway stubs the in-container check, so it tests the
container path on mote and CI too.

Not tried:
- a real Docker container, on a NAS or anywhere;
- reaching 172.17.0.1 from a container on another compose network on the
  reporter's NAS;
- a published port that differs from the gateway's (MAGPIE_PUBLIC_URL
  sets the host's; the bridge address uses the gateway's own port);
- Podman's rootless networking (slirp4netns, pasta), where the default
  route may not be the host.
2026-11-03 19:41:02 +08:00
yetone 3f1f1882ac claude: magpie's model names never stay in a Claude Code switched off it (roswellcsy on X)
roswellcsy on X (v0.1.2846). Claude Code was switched off magpie and on
its own sign-in, with several Claude accounts and one made first. Every
session said "There's an issue with the selected model
(claude/claude-opus-5-5)", while settings.json's model was the bare
claude-opus-5-5.

Cause: a name of magpie's left in Claude Code's env.
- The env's ANTHROPIC_MODEL outranks settings.json's model (Claude Code
  2.1.316: Wg(), `i.ANTHROPIC_MODEL||settings.model`). The tier variables
  stand in for opus/sonnet/haiku. On Anthropic's endpoint a
  provider/model name is a 404, shown as that message.
- How it got there and kept coming back:
  - Connecting a Claude Code that is not routed stashes its env models as
    "the user's own" (claude.env.<VAR>), magpie's names included.
  - Disconnect (unroute) then writes them back, again unchecked.
  - Once one is there, every connect and switch-off keeps it.
  - The bare model is the user's own, from connect.was or untouched.
- Nothing took the name out afterwards:
  - unroute returned at once when not routed;
  - Sync only did desktopOnly;
  - Disconnect is a no-op once Wired() is false (a bare model with no
    gateway URL).
- Sibling: wiring at an older gateway address (magpie's key) was left in
  place by Disconnect, while set("") already took it out.

Fix (internal/agent/claude.go):
- claudeMagpieModel(v): v is a catalog ref, read through ClaudeRead and
  with any :effort or [1m] taken off.
- It is never stashed as the user's own, and never given back from a
  stash (one an older magpie wrote included).
- dropStray: with no ANTHROPIC_BASE_URL (Anthropic's own endpoint), every
  claudeModelEnv key and `model` holding one of magpie's names is taken
  out. ANTHROPIC_MODEL, SMALL_FAST, SUBAGENT, the four tiers and the
  auto mode model are covered.
  - It runs from Sync when not routed, so SyncCatalog repairs users
    already in this state at the next start.
  - It also runs from unroute when not routed (Disconnect, the default
    model, a non-magpie model).
  - An endpoint of the user's own may name its models so, and those
    stay.
- unroute, when not routed: wiring at an older gateway address
  (keyOurs) goes whole, as set("") takes it.
- docs/subsystems/agent-wiring.md says so.

Test: TestClaudeOffLeavesNoMagpieModel, in a sandbox HOME. Each subtest
reads settings.json as Claude Code starts on it (ANTHROPIC_MODEL over
model, the tiers, small fast, subagent, auto mode).
- start: the stray env, then SyncCatalog;
- connect + Disconnect twice;
- a stash an older magpie wrote;
- the user's own models come back;
- an older gateway address;
- another endpoint's names are left alone.

Red on the old code: start, connect+Disconnect and older-address fail
(red-old.log). "connected and switched off again" reproduces the report
exactly: model "claude-opus-5-5" with env ANTHROPIC_MODEL
"relay/claude-opus-5-5".

Broken by hand, each through mote-run:
- dropStray out of Sync: start red.
- Both stash guards out: connect+Disconnect red.
- The restore guard alone out: older-stash red.
- keyOurs cleanup off: older-address red.
- With the stash guard alone out, the restore guard still holds, so it
  stays green.

Run on mote (mote-run, at d8501848a plus this change; the doc edit came
after the run):
- go test ./internal/agent/ ./internal/provider/ -count=1 -timeout 45m:
  ok agent (200s), ok provider (136s).
- The new test: 7 of 7 PASS (the parent and 6 subtests).
- GOOS=windows go vet ./...: ok.
- GOOS=linux go vet -tags nogui ./...: ok. Without the tag it stops in
  Wails' cgo-only Linux files when cross-compiling, which this change
  doesn't touch. GOOS=linux go vet ./internal/agent/ ./internal/provider/
  is ok too.
- gofmt -l: clean.

Not tried:
- A real Claude Code run against Anthropic. The 404 path was read from
  the 2.1.316 bundle, not hit.
- The user's literal provider id claude/: the test uses a relay
  provider. isMagpie resolves both the same way.
- WSL's Claude Code goes through the same claudeIn and wasn't run.
- A Claude Desktop Code tab with a provider/model in settings.json's
  model and no base URL would also lose it at Sync. Desktop writes
  mythos-magpie-<n> ids there, not provider/model ones.
2026-11-03 19:18:50 +08:00
yetone 1d0fc2bb08 sessions: a fork's copies of its parent's calls are counted once (Codex, ZCode)
Sky (skyhuang1994) on Discord: on ZCode, 10-31 showed ~0.70B GLM-5.3
tokens where ZCode's own model_usage had ~0.28B. A selection side chat
opened on 11-02 from a 10-31 session holds a copy of its 860 assistant
messages, with the 10-31 times and the same 421,041,276 tokens, and made
no calls. On Codex, a week of 2026-03 read 5,136,041,178 gpt-5.4 tokens,
where the machine had spent ~0.27B.

ZCode: ZCode 3.17's CLI copies a session's messages (gce, for a side
chat, a fork and a checkpoint restored) with a new id and session, the
original's time, model and tokens, and metadata.forkOrigin
{sessionId, messageId}. zcDB.copied says a message is a copy of one still
in the database, and readZCodeCalls and parseOpenCode (for ZCode) leave
it out. A copy of a copy names the copy it came from, so of each chain
one is counted. A copy whose original is gone is counted. ZCode's own
fork notices carry a forkOrigin with no messageId, and are not copies.

Codex: a fork (/fork, spawn_agent with the parent's context) writes every
line of the parent's rollout into its own first, token_count events too,
stamped at the fork's time (codex-rs 0.117 record_initial_history,
InitialHistory::Forked). Each copied checkpoint was booked as a call on
the fork's day. The fork's session_meta has forked_from_id. The parent's
rollout is found in the same Codex home: the UUIDv7 day of its id ±1
day, then every day, then archived_sessions. Its checkpoints, {total,
last}, are read once (8 parents kept), and a fork's checkpoint found among
them only advances the running total, on Usage (calls) and Sessions
(stats) both. A parent not found leaves the fork read as before.

callParseVersions and parseVersions raise codex and zcode to 1, so their
kept parses are read again once. The version tests (call_versions,
parse_versions, cache_decode) now hold the versions at none raised: they
test the mechanism, not the current numbers.

docs/subsystems/gateway-sessions.md says all of this. Filed #5072:
OpenCode's fork copies the same way and names no original, so it is
still counted twice.

Run at this head on mote (mote-run):
- gofmt -l internal: empty
- GOOS=linux go vet -tags nogui ./... ; GOOS=windows go vet ./... : ok
- go test -count=1 -timeout 45m ./internal/sessions ./internal/usage
  ./internal/tune ./internal/otlp ./internal/davsync ./internal/tui : ok
- go test -run 'Session|Usage|Calls|Ledger|Stats|ZCode|Codex'
  ./internal/gui ./internal/cli : ok

Broken by hand:
- zcDB.copied returning false: TestZCodeCopiesCountedOnce red. msg_c1 and
  msg_d1 were counted as calls, and the Sessions page's 10-31 read
  {1200 300 1800} for {400 100 600}.
- the copied() check in count() off: TestCodexForkCountsOnlyItsOwnCalls
  red. 4 calls on the fork, {87984 5950 268416} for {45744 3550 179584}.

Not tried:
- a real ZCode database or side chat. There is none on this machine.
  The copy shape was read from ZCode 3.17.2's zcode.cjs (gce).
- a real forked Codex rollout or one from 2026-03. ~/.codex/sessions here
  spans 2026-07 to 11 and has no forks. The fixtures follow codex-rs
  0.117's writer. Whether Sky's 5.1B week is all fork copies is not
  known; a cumulative count read as per-turn in an older format was not
  found in that source.
- newer rollouts' token_usage_record copies in a fork, and a parent in
  another Codex home (WSL, CODEX_HOME).
- the whole gui and gateway suites. Another session's suite was running
  on mote; gui and cli ran only the tests above.
2026-11-03 19:13:00 +08:00
yetone d8501848a7 gateway: an Ark image request's own fields go to Ark, and watermark and response_format are the caller's
axelburks on Discord listed what /v1/images/generations did to a Seedream
request against Ark's images API (docs 82379/1541523). Checked against
those docs and draw.go / draw_volcengine.go; the real ones:

- Image params were dropped. drawing read OpenAI's fields alone, so
  sequential_image_generation and its options (a group of up to 15),
  optimize_prompt_options, tools, layer_decomposition and every other
  Ark field never reached Ark. Now the request's fields magpie doesn't
  read (drawingRead) are drawing.Extra, from a JSON body or a multipart
  form, masked as the prompt is (fails closed), and sent to Ark as they
  came; a form's values are typed as Ark takes them (formValue, with
  Ark's text fields kept as text). layer_decomposition with an image
  needs no prompt.
- watermark and response_format were forced. Every request went with
  watermark false and response_format b64_json. Now watermark false is
  magpie's default only, and a caller's watermark wins; response_format
  "url" asks Ark for its URL and answers it, anything else still asks
  b64_json.
- stream true would have gone to Ark and come back as events this route
  can't read: it is a 400 that names
  /v1/magpie/native/<provider>/images/generations.
Kept as it was: n stays OpenAI's, that many requests, each one image or
one group.

Tests: TestArkImagesPassOnTheirOwnFields (a group, optimize_prompt_options,
a caller's watermark, tools and url reach Ark as sent; a form's fields
typed; stream refused naming the native route). Docs: gateway-routing.md
(the Ark images row and paragraph), docs/integrating.md and the site's
integrate page (en, zh) on the vendor fields and the native route.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- Extra not merged into Ark's request: TestArkImagesPassOnTheirOwnFields red
- response_format url not asked of Ark: TestArkImagesPassOnTheirOwnFields red

Not tried: no real Ark image was drawn (no money spent); the shapes are
from Ark's docs, on a fake Ark.

Credit: axelburks on Discord.
2026-11-03 18:46:55 +08:00
yetone db87e014f2 gateway: /v1/magpie/native/<provider>/<path> passes Ark's own images and video-task API on
axelburks on Discord asked for a way to reach what the OpenAI-shaped
routes can't carry: Ark's image stream, its task list and cancel, a
field newer than magpie. A coordinator asked for it to stay behind the
gateway's key and auth like every route, and for the design to be said.

Decided:
- One route, /v1/magpie/native/{provider}/{path...} (POST, GET, DELETE),
  for Volcengine Ark only (isArk, not a remote magpie), at the paths it
  makes images and videos at: POST images/generations; POST/GET
  contents/generations/tasks (with Ark's query); GET/DELETE
  contents/generations/tasks/<id> (nativeArkPath). Never Ark's chat,
  whose routing, usage and masking are the chat routes'. Another
  provider or path is a 404 that says what is served.
- Behind every guard a /v1 route has (a key beyond loopback, corsGuard,
  the key's rate), and refused to a read-only key (readOnlyRefused).
- Refused (403) to a key held to models, accounts or a spend limit, or
  issued by one (nativeHeld): a poll or a cancel can't be tied to a
  model, and magpie prices no answer it doesn't read, so it couldn't
  hold such a key to them. Such keys use /v1/images/generations and
  /v1/videos, which now pass the vendor's own fields on.
- A model the user switched off is refused. The body's strings are
  masked (fails closed) and put back in the answer (restoring); numbers
  go exact (UseNumber, a 17-digit seed is kept).
- Signed with the provider's key and magpie's User-Agent; no caller
  header goes on but Accept. The answer comes back as it came, an event
  stream flushed as it arrives.
- Each request is a Requests row and a usage record (Operation
  "native", no tokens).

Tests: TestNativeArkRoute (the stream, the task list's query and a
cancel reach Ark signed with the provider's key, the body as sent; chat,
a wrong method, a deeper path, another provider, an unknown one and
every held key are refused without Ark being asked),
TestNativeArkStreamsAsItComes (the first event reaches the caller while
Ark holds the rest), TestReadOnlyKeyEveryRoute (the three patterns in
readOnlyRefused). Docs: gateway-routing.md's native route section.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- nativeHeld skipped: TestNativeArkRoute red
- an issuer's hold not read: TestNativeArkRoute red
- nativeArkPath skipped: TestNativeArkRoute red
- isArk not checked: TestNativeArkRoute red
- no flush: TestNativeArkStreamsAsItComes red (its 30s bound)
- the DELETE pattern out of readOnlyRefused: TestReadOnlyKeyEveryRoute red

Not tried: no real Ark request through the route (it would spend money);
Ark's answers are a fake shaped from its docs.

Credit: axelburks on Discord.
2026-11-03 18:46:54 +08:00
yetone b2034c1bcf gateway: an Ark video keeps the caller's content, ratio and own fields, and answers Ark's
axelburks on Discord listed what /v1/videos did to a Seedance request
against Ark's own API (docs 82379/1520757 create, 1521309 query). Each
item checked against those docs and video.go; the real ones:

- A caller's content was overwritten. volcengineVideoBody built content
  from the prompt and OpenAI's image fields and set it over the caller's,
  so reference_video, reference_audio and draft_task items were lost.
  Now a content sent is Ark's own and kept whole; the prompt goes first
  only when it has no text item, OpenAI's image fields after it.
- Image-to-video needed a prompt; asset:// and seconds -1 were refused.
  Ark's image-to-video takes no prompt, its asset library's asset://
  ids are images, and duration -1 lets the model choose. Now the prompt
  is optional with an image or a content, asset:// is kept as it is, and
  -1 goes as -1. These three are Ark's alone: arkOnly turns them away
  with a 400 before another vendor (MiniMax, Grok, an OpenAI-compatible
  one) is asked.
- size overrode an explicit ratio/resolution, and its mapping was wrong.
  size went through to ratio and resolution after the caller's own were
  copied, so ratio "adaptive" was lost; its resolutions stopped at 1080p
  and its ratios were Grok's, without 21:9 (3840x2160 went as 1080p). Now a ratio, resolution
  or duration the caller sends is never overridden; size is the nearest
  of Ark's tiers by pixels (480p, 720p, 1080p, 4k) and of Ark's
  ratios (arkVideoSize).
- Every string field, a JSON body's too, was read as JSON when it parsed
  as a bool or a number, and nothing else was: a form's tools stayed the
  string "[{...}]", and safety_identifier "12345" became 12345. Now only a
  multipart form's values are parsed (formValue), and Ark's text fields
  (arkTextFields: safety_identifier, callback_url, service_tier, ratio, …) stay strings. A
  JSON body's values keep their JSON types.
- The query answer dropped Ark's extras. Now every field of Ark's task
  that OpenAI's video object doesn't have (content.last_frame_url, usage,
  resolution, ratio, framespersecond, seed, tools, output_format, …) is
  passed on as it came (videoState.Ark, all but arkOwnFields).
- A MOV was served as mp4. /content now reads the ftyp brand ("qt  " is
  video/quicktime), then the vendor's video/* type, then Ark's
  output_format; mp4 only when none says otherwise (videoType).
- The expired message was wrong: Ark's expired is a task that ran past
  its execution_expires_after (48h by default) unfinished, not a link
  that expired. It now says so.
Not real: watermark is not forced on videos (it went as sent already).

Tests (internal/gateway/ark_video_fields_test.go):
TestArkVideoKeepsCallersContent, TestArkVideoFromImageNeedsNoPrompt,
TestOnlyArkTakesItsOwnVideoAsks, TestArkVideoSize,
TestArkVideoFieldTypes, TestArkVideoAnswersItsOwnFields, TestVideoType.
Docs: gateway-routing.md's Ark video paragraph and /content row.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- the caller's content not read: TestArkVideoKeepsCallersContent red
- the prompt required with an image: TestArkVideoFromImageNeedsNoPrompt red
- arkOnly skipped: TestOnlyArkTakesItsOwnVideoAsks red
- size overriding a named ratio: TestArkVideoSize red
- Grok's ratios in place of Ark's: TestArkVideoSize red
- Ark's text fields parsed as JSON: TestArkVideoFieldTypes red
- a JSON body's values parsed as a form's: TestArkVideoFieldTypes red
- Ark's extra fields not copied: TestArkVideoAnswersItsOwnFields red
- the old expired wording: TestArkVideoAnswersItsOwnFields red
- a MOV served as mp4: TestVideoType red

Not tried: no real Ark video was made (no money spent); the request and
answer shapes are from Ark's docs, on a fake Ark.

Credit: axelburks on Discord.
2026-11-03 18:46:54 +08:00
yetone af9ac3d25d gateway: /v1/models lists image and video models when ?kind= asks for them, chat models alone by default
axelburks on Discord asked that /v1/models return the image and video
models too, so a client can find them. It listed chat models alone, with
no way to ask for the others.

Decided: they are listed only when asked for, with ?kind=image,video
(or ?kind=chat,image,video, or ?kind=all), each row marked "kind":
"image" or "kind": "video". Without ?kind= the list is the same chat
list as before. Why not add them by default:
- Agents and clients offer every id this list gives as a model to chat
  with: OpenCode's and Cherry Studio's model lists, ZCode's and others'
  pasted ?format=text. An image or video id there would sit in their chat
  pickers and fail on the first message (an image model on
  /v1/chat/completions).
- OpenAI's own list mixes gpt-image and sora in with nothing to tell them
  apart, so a client has no field it would already read to skip them.
- magpie's own callers that want them already ask (another magpie's
  drawers header, kind=image/video/decision on the MCP list); ?kind=
  gives any other client the same.
An unknown kind is a 400 that names the kinds, not read as none. A
gateway key held to models or accounts sees only its own image and video
models, as on the chat list (drawerObjects/videomakerObjects already
check modelAllowed and accountServes). Unticked image and video models
(HiddenDrawers, HiddenVideomakers) are left out.

TestModelsListMediaOnlyWhenAsked: the default list and ?kind=chat have no
image or video row (so no agent's chat picker that reads it can offer
one), ?format=text likewise; ?kind=image / video / image,video / all give
them, marked; a bad kind is 400.

Docs: docs/integrating.md, providers-accounts.md, site docs (en, zh).

Run on mote, this change rebased on f4c664a09:
- go test -count=1 -timeout 45m ./internal/catalog ./internal/provider
  ./internal/gateway ./internal/gui: catalog, provider and gateway ok;
  gui red only in TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- GUI: the 51 provider-*, drawers, image-models, i18n and
  video-models-hide files, both engines, every language, wide and narrow:
  1161 of 1188 ok. The 27 reds are 5 files that are red the same 27 at
  origin/main d1cdce130 run alone: provider-fetch-again (#3292/#5057),
  provider-models-rest (#4396), provider-picks-stay (#4397),
  provider-levels-scroll (#4395), provider-typed (#4673).
  video-models-hide: 22 of 22 ok.
- The whole GUI suite (all files) ran earlier at this change on 8af751987,
  347 of 19153 red at load 100 to 200; the 66 files with a red, run again
  alone, are red in the same tests at origin/main 17f2387e1 (all filed:
  #4388, #4391, #4398, #4320, #4541/#5013, #2564, #4244, #4304 and the
  above).
Rebased again onto d1cdce130 (sessions, Cursor mover, library and routing
plugins, group-unlists; nothing this change touches but gateway.go,
which merged clean) and run there: TestCoreScriptBudget and internal/gui's
new tests, the gateway's ?kind= and video tests, internal/provider and
internal/catalog, video-models-hide 22 of 22: ok.

Broken by hand, each red, then put back:
- listKinds' default returning all three kinds:
  TestModelsListMediaOnlyWhenAsked red
- an unknown kind let through: TestModelsListMediaOnlyWhenAsked red

Not tried: no real client was pointed at ?kind=; the agents' pickers were
checked by what they read (the default list, unchanged), not by opening
each one.

Credit: axelburks on Discord.
2026-11-03 18:34:19 +08:00
yetone 92d2ed74f9 providers: an Ark key's Seedance models are under Video models in its editor, each to tick
axelburks on Discord: "供应商里方舟的配置页,有图像模型选项能勾选模型,但是没
有视频模型选项不能勾选视频模型". A Volcengine Ark key's editor listed its
Seedream models under Image models, to tick, and had its Seedance models
among the chat models or nowhere.

Cause, two parts:
- The editor had no video section at all: video models had no list and no
  hidden set (gateway-routing.md said "Video models aren't listed in the
  editor, so there is nothing to hide there").
- catalog's live parse read only "kind" and modalities.input/output. Ark's
  /api/v3/models marks no kind: it says domain "VideoGeneration" /
  "ImageGeneration" and modalities.input_modalities/output_modalities. So
  Seedance came back as a chat model, and 3D models (output 3d, no text)
  as chat models too.

Change:
- catalog: a live row with no kind is a video model when its domain is
  VideoGeneration or it outputs video without text, an image model for
  ImageGeneration or image without text; Ark's input_modalities /
  output_modalities are read when input/output aren't there, so a model
  that gives no text (Ark's 3D) is left out of the chat list.
  TestFetchArkMarksVideoModels runs on a captured Ark list
  (testdata/volcengine-ark-models-2026-11-03.json, fetched read-only
  with GET /api/v3/models, no key in it).
- provider: HiddenVideomakers beside HiddenDrawers, VideomakerHidden.
- gateway: VideomakersOf (Videomakers on a given list, for the editor),
  OfferedVideomakers = Videomakers less the unticked ones, read by
  AutoVideomaker, videomakerObjects (another magpie's list) and
  mediaModels(true) (generate_video). A hidden one still makes its video
  when named: bareVideomaker, videosCreate and arkFilms read Videomakers.
- gui: the editor's Video models section (renderVideomakers), filmIds and
  hiddenVideomakers on /api/providers, kept on save as hiddenDrawers is;
  i18n for every language. app.js comments cut to stay under
  TestCoreScriptBudget, which this change reached; no raise.
- docs: gateway-routing.md's Hidden image models section.

Old data: an Ark list fetched before keeps Seedance among its chat models
until its list is fetched again;
customVideomakers already counts any Seedance id an Ark key lists or picks
as a video model, so it makes videos and shows under Video models now.

Run on mote, this change and the next (/v1/models ?kind=, gateway and
docs only) rebased on f4c664a09; this commit's own tree, on 17f2387e1,
gave the same Go results with Linux and Windows vet of ./internal/...
clean:
- go test -count=1 -timeout 45m ./internal/catalog ./internal/provider
  ./internal/gateway ./internal/gui: catalog, provider and gateway ok;
  gui red only in TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. gofmt -l: nothing.
- GUI (at the next commit's tree, which adds no GUI file or script): the 51 provider-*, drawers, image-models, i18n and
  video-models-hide files, both engines, every language, wide and narrow:
  1161 of 1188 ok. The 27 reds are 5 files that are red the same 27 at
  origin/main d1cdce130 run alone: provider-fetch-again (#3292/#5057),
  provider-models-rest (#4396), provider-picks-stay (#4397),
  provider-levels-scroll (#4395), provider-typed (#4673).
  video-models-hide: 22 of 22 ok.
- The whole GUI suite (all files) ran earlier at this change on 8af751987,
  347 of 19153 red at load 100 to 200; the 66 files with a red, run again
  alone, are red in the same tests at origin/main 17f2387e1 (all filed:
  #4388, #4391, #4398, #4320, #4541/#5013, #2564, #4244, #4304 and the
  above).
Rebased again onto d1cdce130 (sessions, Cursor mover, library and routing
plugins, group-unlists; nothing this change touches but gateway.go,
which merged clean) and run there: TestCoreScriptBudget and internal/gui's
new tests, the gateway's ?kind= and video tests, internal/provider and
internal/catalog, video-models-hide 22 of 22: ok.

Broken by hand, each red, then put back:
- the domain/output check in catalog's live parse:
  TestFetchArkMarksVideoModels red
- OfferedVideomakers returning Videomakers whole:
  TestHiddenVideomakerLeavesListsButStillFilms red
- the editor's filmIds left empty: TestVideoModelsHidden red
- a save without hiddenVideomakers dropping the old ones:
  TestVideoModelsHidden red
- renderVideomakers' call in the editor left out: video-models-hide
  22 of 22 red
- a chip's click not changing the draft: video-models-hide 22 of 22 red

Not tried: no real Ark video was made (no money spent); the list parse was
checked on a real Ark list fetched read-only. The editor was not opened in
the real app, only in the GUI tests' fake API.

Credit: axelburks on Discord.
2026-11-03 18:34:19 +08:00
yetone d1cdce1302 provider: the group alone keeps subscription models out of agents' lists (shaoyang.)
shaoyang. on Discord (#general, 11-03): with a routing group's Model
lists set to the group alone (its card's 成员模型不单独列出), the model
list fetched still had every model of the group.

Cause: 88e6fb9cf (v0.1.2176, 10-30) had catalogOf keep a signed-in
subscription's models (SubscriptionKept: a ChatGPT, Claude, Copilot or
plugin account's) for every agent, leaving the group alone only for a
client that is no agent (""). Over HTTP no client is "": agentOf falls
back to usage.AgentOf(User-Agent), which is "other" or the UA's name, so
every /v1/models fetch, every agent's written list and every picker
listed a subscription member beside the group. For a group made of
subscription models, as most are, the option changed nothing.

Fix: catalogOf gives every agent but Codex Catalog(), as before
88e6fb9cf; Codex keeps its ChatGPT sign-in's own models (CodexOwn,
a3ee00c05), which its app reaches on that sign-in. SubscriptionKept is
gone; Unlisted() and GroupKept() name subscription members again, so the
picker's "kept for routing groups" note and the provider editor's
"listed alone" line (3d063e34f) say where they went. The routing editor's
hint says Codex keeps its own, in en, zh, zh-TW, ja and de. Docs:
reference.md, gateway-routing.md.

Behaviour change for 士奇's case (88e6fb9cf): with "The group alone" on,
Hermes, WorkBuddy and the rest lose the group's subscription models
again; that is what the option says. Listing its models too keeps them beside
the group, which the new test checks.

Tests:
- gui TestGroupAloneKeepsSubscriptionModelsOutOfEveryAgentsList (replaces
  TestSubscriptionModelsStayInEveryAgentsListWithGroupOn): a sandbox
  ChatGPT sign-in's 5 models in a group listing alone. For every agent
  but Codex that lists the group, its Agents-page list, CatalogFor and
  model pickers leave them out; Unlisted names them; with "Its models
  too" hermes, workbuddy, claude and codex list them.
- gateway TestGroupAloneKeepsSubscriptionModelsOffAgentsModelList:
  GET /v1/models with no key, "magpie" and magpie-hermes/-claude/-opencode
  lists group/mine and not its members; /v1/models/{id} doesn't find one
  for Hermes; Codex's key lists and finds them; listed again with
  listed too.
- TestCodexOwnModelsListedOnlyThroughGroups again expects Claude Code not
  to list a group-alone member.

Run on mote at 3da80330a (rebased on origin/main c3593dc49): gofmt -l
clean; go vet (darwin -tags nogui, GOOS=linux -tags nogui at the base,
GOOS=windows) on provider, gateway, gui ok; go test -timeout 45m
internal/provider ok, internal/gui ok, internal/gateway -run
"TestGroup|TestCodex|TestUnlisted|TestModels|TestDesktop" ok. At the
base 40a287b21: internal/provider, gateway, gui and agent whole ok;
internal/cli red only in TestEveryRouteHasACommandOrIsNamed (GET
/api/context/reply, #5026, red on main since 0872bc2a0). GUI:
group-unlists (en/zh/zh-TW/ja/de, 1100 and 420px), unlisted-group-kept,
unlisted-models, agent-models-group-on, i18n-keys in chromium and webkit,
56 of 56.

Broken by hand: catalogOf back to SubscriptionKept with the new tests in
place; the gui test failed with 484 "the group alone" errors (codex/gpt-5.5
in claude's, claude-desktop's, claude-science's lists and pickers among
them) and the gateway test for every key, no key and "magpie" included.

Not tried: a real ChatGPT/Claude sign-in or the running app, and the
reporter's Docker deployment (same /v1/models path, no OS branch); which
agent fetched the list isn't known.
2026-11-03 18:23:13 +08:00
yetone 00098f12bf library: Magpie Browser's "which agents may use it" is a line of its own under its row
tao0194 on Discord (v0.1.2828, zh, panel-width window): in Library > MCP
servers the magpie-browser row showed the connected ask (green dot, the
question, a button per agent) inside the name's column, wrapped into a
narrow strip between the command and the row's Scope and agent chips,
three lines tall beside every other server's two.

browserAsk's element was appended to the row's .who. It is now the row's
own child: the row gets lib-asking while it shows, wraps, and the ask
takes a line under the name, command and chips, from the name's left
edge (the picture plus the row's gap, 37px, 38px in the window's rows)
to the row's right edge. The first line keeps the name, command and
chips as the other rows have them (.who flex-basis 0 above 560px). At
560px and under, where rows already wrap, a long command now ellipsizes
beside the row's picture instead of taking the name to a line of its
own under it; that was so for any server with a long command, and the
ask's left edge follows the name. docs/subsystems/library.md says where
the ask sits.

library-browser-ask.test.cjs now has three agents (Codex, Zed among
them) and a context7 row beside it, runs at 1100, 600, the panel's 440
and 360, and checks the ask starts under the first line, at the name's
left edge, reaches the chips' right edge, that the first line is as
tall as another server's, and that the name sits beside the picture.

Run (mote, Playwright 1.62.0, Chromium and WebKit, en/zh/zh-TW/ja/de):
- library-browser-ask.test.cjs on the old client.js/library.css: 42 of
  44 red (every layout subtest; the two not-connected/given ones pass).
  With the change: 44 of 44 green.
- The 84 GUI files that open the Library, name lib-row/lib-server or
  library.css, or check budgets and i18n keys: 1480 of 1480 ok, before
  the rebase onto c3593dc49 (no upstream change touches these files);
  library-browser-ask, i18n-keys and builtins again after it: 52 of 52
  ok. go test ./internal/gui at the rebased head: TestMainWindowCorners
  red only (an AppKit window test, the same on origin/main 78cd4e6dd,
  #3949); everything else ok.
Not tried: the real app's panel (WKWebView) with a connected extension;
the full GUI suite.
2026-11-03 18:21:58 +08:00
yetone f4c664a09c plugin, gui: magpie web ends its plugin hosts, waited for, before it runs the new version (#3285)
The second way acezan's 57 <defunct> magpie-bun (v0.1.2819, a Linux
systemd service, 47 hours) pile up: magpie web's restart to update
(AutoRestart) runs the new version with syscall.Exec in the same pid.
The running plugin host was the old image's child, and the old image's
host.read held the only Wait for it. After the exec nothing waits for
it, so it ends on stdin EOF and stays <defunct> under that pid, one per
restart to update. skygunner reproduced it and AAEE86 counted 22 zombies
for 23 images under one pid (#3285). With about a hundred releases a
day, an AutoRestart service makes about one a hour, as acezan's did.

- plugin.EndHosts (host.go) stops every host started and not yet
  reaped, including the retiring ones, waits until each one has been
  waited for, and refuses to start another (errHostsEnded). startOn
  starts the host and records it under one lock (live), so a host that
  starts during EndHosts isn't missed.
- Web.Wait calls it right before update.Reexec.

Run at 72bc741ef (on origin/main 40a287b21, after the previous commit):
- mote (macOS): gofmt -l clean; go vet ./internal/gui ./internal/plugin,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok.
  go test -count=1 -timeout 45m ./internal/plugin: ok; -run Web
  ./internal/gui: ok.
- WSL magpie-desktop (Linux): ./internal/plugin ok, including
  TestEndHostsLeavesNoChild and TestHostReapedWhileItsChildHoldsStdout
  with a real Bun host; -race -count=3 of both: ok; go vet -tags nogui
  and -run Web of ./internal/gui: ok.

Both commits were then rebased onto 0acba61a3, which changes only
app.js and plugin-checkin.test.cjs; no Go file these runs built moved,
and they were not run again there.

Broken by hand: EndHosts returning at once makes
TestEndHostsLeavesNoChild fail on Linux ("children left once EndHosts
returned: [16459 S bun]").

Not tried: a real magpie web restart to update (a downloaded update
exec'd in the same pid) on Linux. The test covers EndHosts, not the
exec. Not changed: anything else alive at the exec (pii's helper,
awake's caffeinate, #4188) still outlives it the same way.

Reported by acezan on Discord. Diagnosed in #3285 by skygunner and
AAEE86.
2026-11-03 17:58:31 +08:00
yetone a9a8f11e7f plugin, proc: a plugin host is waited for when it ends, not when its stdout does
acezan on Discord (v0.1.2819, Linux x86_64, a systemd service): after
47 hours, 57 <defunct> magpie-bun children of magpie, growing toward the
unit's TasksMax until a restart.

One cause: the plugin host's only cmd.Wait ran in host.read after its
stdout reached EOF. A program a plugin started that kept a copy of the
host's stdout (Bun.spawn given Bun.stdout, which host.js's spawn guard
doesn't catch, #5063; a daemon left behind) held that pipe open past the
host's end, so EOF never came, Wait never ran, the host was never marked
dead, and every host stopped (Restart, a moved proxy, hostStale) stayed a
zombie until magpie quit. Reproduced on Linux (WSL magpie-desktop,
Bun 1.4.2): one more Z-state bun under the test process per Restart,
1, 2, 3, 4 over four rounds. The other cause, magpie web's restart to
update leaving the running host behind its exec (#3285), is the next
commit.

- proc.Output (new, internal/proc/output.go) gives a command's stdout and
  stderr pipes of magpie's own and waits for the command the moment it
  ends. Its readers then have OutputGrace (2s) to read the last lines;
  the pipes are closed after that, which ends a read held up by a
  grandchild. startOn uses it, and a reap goroutine fails the host when
  its child ends. host.read no longer calls Wait. The tests' fake hosts
  (no child) keep cmd.Wait.
- Every other start that wasn't waited for now goes through
  proc.StartReaped (Start, then go cmd.Wait()). Process.Release doesn't
  reap on Unix: codexrelay.Start (a relay that can end while magpie
  runs), tui serveInBackground, uninstall's startAfter, update's
  runAfterExit and OpenBeside (no Wait at all), and Windows' Reexec.
- TestEveryStartedCommandIsWaited (internal/proc) parses every non-test
  .go file. In each function, an x.Start() on a command needs an
  x.Wait(), or x handed on (a call's argument, a struct field), and
  .Process.Release() is refused. It found exactly the sites above.
- docs/subsystems/provider-plugins.md says how the host is reaped.

Checked and left as they are (each waits): the StartTree callers
(provider/install, library mcp_run and mcp_check, gateway claude_warmup
and claude_subscription), pii/serve, provider grok and claude_signin,
claudetui child_unix and wslread, awake, every other bun start (bun.go,
bunupdate, store, dist use Output/CombinedOutput).

Run at 82460a2f9 (on origin/main 40a287b21):
- mote (macOS): gofmt -l clean; go vet on the touched packages,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok.
  go test -count=1 -timeout 45m ./internal/plugin ./internal/proc
  ./internal/codexrelay ./internal/tui ./internal/uninstall
  ./internal/update: all ok. -race -count=3 of the new proc tests: ok.
- WSL magpie-desktop (Linux): the same six packages ok, including
  TestHostReapedWhileItsChildHoldsStdout with a real Bun host; -race
  -count=3 of it and the Output tests: ok.
- Windows (xiaomi-gpu), at the tree before the rebase (base 5ee5274bd):
  proc and codexrelay ok. plugin and update had TestPiPackage,
  TestLoadConcurrentWithSavesAndEdits and TestPackagedByDpkg red; each
  fails the same at untouched origin/main 40a287b21 on that box, 3 of 3,
  and is filed (#4115, #1827, #4603).

Broken by hand, each red:
- host.go back to StdoutPipe with Wait only after EOF:
  TestHostReapedWhileItsChildHoldsStdout fails on Linux ("the host isn't
  marked ended 15s after Restart").
- Output.Start waiting for the readers before Wait:
  TestOutputWaitsPastWhatHoldsIt fails (not waited for in 10s).
- codexrelay back to Process.Release: TestEveryStartedCommandIsWaited
  names relay.go:89 and :92.

Not tried: a full go test ./... (mote and WSL were each running other
sessions' package runs, load 39 and 110); a real magpie serve or web
running for hours on Linux; the host test on macOS (no /proc; the
Output test runs there). Not changed: killing what a host left behind
(its process group) when it is stopped; an orphan like the sleep above
stays in the service's cgroup until it ends on its own.

Reported by acezan on Discord.
2026-11-03 17:58:31 +08:00
yetone 40a287b217 gateway: a quiet Claude Code run begins the reply and pings its client (#5043)
A streamed Claude subscription turn whose run says nothing for minutes
(the interactive mode tells a message only once it is whole; a long
conversation replayed to a new Claude Code is prefilled uncached first)
gave its client the held stream's 200 and comments, and those stop at
keepaliveLongest (5 min). Claude Code 2.1.316's byte watchdog then ended
the request 300s later, at 599s: the reporter's 599.29s and 599.33s.
Each cancel aborts the TUI run (letGo), so the retry is a new Claude Code
that replays the history and writes it to the cache again (#3808).

keepBridgeHeard wraps the run's events for a stream: after
bridgeHeardAfter (1 min) of a quiet run it sends an empty KStart, which
makes relay begin the reply (message_start), and a KAlive every
keepaliveEvery while it stays quiet, up to translatedQuietLongest, so the
client gets its protocol's pings (#2316's pattern). The hold still holds
the frames to holdLead and passes an error over. The run's own start
later adds its usage (collector), and a failure in the first minute is
still a status.

The gain is bounded. Claude Code 2.1.316 turns every 10s with bytes into
a ping of its own (RSr, __n=1e4) and counts 30 pings in a row (vSr=30),
so a stream of pings and comments alone ends 600s after its last other
event. The run now has until about 14 minutes (message_start at ~4 min
plus 600s), where it had 599s. The reporter's retries answered first at
385s and 527s.

Run:
- Real claude.exe 2.1.316 (-p, sandbox HOME, env -i) against a fake
  Anthropic server:
  - headers at 3s, comments to 300s: ended at 598.38s ("[byte-watchdog]
    ... no bytes for 300000ms"; "Stream idle timeout before first event").
  - comments forever: ended at ~600s from headers ("no chunks received
    for 300s").
  - no headers: "Request timed out" at 360s.
  - this fix's shape (message_start + ping at 300s, a ping every 60s):
    lasted to 904s, then "no chunks received for 300s" and fell back to
    non-streaming. That is the 600s bound above.
- mote-run: go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ok (675.8s), at this change before its comment-only edits.
- mote-run: go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ok (680.2s) again at this tree, rebased on origin/main 5ee5274bd.
- mote-run: TestClaudeBridgeQuietRunKeepsClientAlive -count=3 ok, and
  gofmt -l internal/gateway clean, at the committed tree.
- mote-run: GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gateway ok.

Broken by hand:
- Without the keepBridgeHeard call, the new test fails: no
  message_start or ping before the reply.
- Without the synthetic KStart (KAlive alone), it fails with "0 pings
  while the run was quiet": the client gets comments only.

Not tried:
- A real Claude account, the interactive (TUI) mode, a real replay.
  The test uses a -p fake Claude Code. The wrapper doesn't depend on
  the mode.
- Chat and Responses clients through the bridge. Their encoders take an
  empty KStart, but no test covers it here.
- A run quiet for longer than ~14 min still ends. Only a real event of
  the reply would keep it alive (#5060).
- magpie's pingEvery comment in gateway.go describes 2.1.311's count
  without the synthetic pings. Not changed here.
2026-11-03 17:36:51 +08:00
yetone 9019ca88d6 gui: Scroll to top and Scroll to bottom move when the page under them changes, not only on a scroll (Jiabubu)
Jiabubu on Discord: with the capsule in sight, a click that opened a
Routing group left it over the editor's member rows (Remove beside Up
and Down) and its held Cancel and Add, and it moved off them only once
the page was scrolled.

scrollends.js placed the capsule on a scroll, a resize, focus or the
pointer leaving it, and a hidden attribute set anywhere. Opening a group
in place sets none, unless something else on the page happened to be
hidden again in the same draw (an empty pool list is, on every draw,
which is why the earlier tests saw it move). It now also watches the
open page and each of its own children with a ResizeObserver, and the
page's child list, so any change of size under it (a group opened or
closed, rows added or taken out) places it again on the next frame: it
rises above a held foot, steps aside at the page's foot, or comes back.
One file serves every page with the capsule (Agents, Providers, Routing,
Library, Settings, plugin pages), so they all take it. No core script
changed; scrollends.js loads lazily and has no budget.

view-ends-relayout.test.cjs: with no scroll after the change, the capsule
must be where the reader's next scroll puts it, and over nothing of the
editor's:
- Routing, 16 groups of the reporter's rows ("低-ultra", 922K), a pool in
  the list: a screen down, a click on the card lowest in sight opens its
  editor; then Cancel closes it.
- Agents, 40 rows: a little above the foot, a block at the list's end
  taken out so the foot comes up under the capsule.
Desktop 1100, 700, 560; browser page 1100, 440, 360; Chromium and WebKit,
en/zh/zh-TW/ja/de.

Run on mote (mote-run) at this tree:
- view-ends-relayout, both engines, every language: 10 of 10 ok.
- On 5ee5274bd (origin/main just fetched) plus this change:
  view-ends-relayout, view-ends, routing-editor-foot, old-webkit and
  i18n-keys: 62 of 62 ok.
- Before the rebase (on c0d4f17a3), with group-editor-selected,
  group-editor-fits, group-member-drag, drag-rows-shift, routing-rows-fit,
  click-scroll, add-button, library-discover-jump and account-eye beside
  those: 214 of 214 ok.

Broken by hand: scrollends.js as at origin/main, 20 of 20 red (both
engines, every language), each part on its own:
- Routing: "desktop 1100px: opened, the capsule above the held Cancel
  and Add, with no scroll: 569-624, bar from 591".
- Agents only: "desktop 1100px agents shorter: the capsule stepped aside
  as a scroll has it, with no scroll: [[true,569,624,1739],[false,...]]".

Not tried: the whole GUI suite. Both machines already had full suites of
other sessions running (WSL: four, at load ~140; mote: one, 49 minutes
in), and one full suite runs on a machine at a time. The capsule's
behaviour is the only change, no layout and no new API call. Also not
tried: the Windows app (WebView2) and the Linux app (WebKitGTK) themselves,
and the reporter's own groups.
2026-11-03 17:26:53 +08:00
yetone 900ae0fa51 backup, sync: sign-ins go too when picked, sealed, never over a later renewal
qianxunji (#feedback) and curtinp118 on Discord: a VPS restored from a
backup, or a new computer joining sync, had to sign in to every
subscription again. Sign-ins (subscription accounts in logins.json,
Codex's auth.json, plugins' sign-ins in plugin-auth.json) can now go too,
in each place only when picked; all are off by default, so an upgrade
carries nothing new.

- Sync (WebDAV, S3, GitHub): a "Sign-ins" tick in the form, with a line
  saying anyone with the passphrase and the server's file can use the
  accounts, and that an account on two computers can be signed out on one
  when the other renews it. CLI: `magpie webdav|s3|github set sign-ins=yes`.
- Export: "With the sign-ins", off; ticked, the passphrase hint says the
  file holds them. CLI: `magpie backup --sign-ins`.
- Import: "Bring in the sign-ins too, when the file has them", on. CLI:
  `magpie restore --no-sign-ins` leaves them out.
- Back up by itself: "Sign-ins in backups", Off/On. On asks for a
  passphrase (twice) that seals the sign-ins alone (the rest of an
  automatic backup stays unsealed, as before); it is kept in
  autobackup.json (0600), never sent in the view. A backup whose sign-ins
  another passphrase sealed restores without them and says so.

What goes (provider.CollectSignIns, plugin.CarriedAuth): magpie's own
copies only, not an agent's own account, an agent-home row, a hidden or
plugin: row, or a retired built-in. Each record is keyed by agent +
email + org (or the account key); ids two rows share go on neither side.

Restore/import (RestoreSignIns) adds what is missing and updates only
when the incoming copy was renewed later; nothing here is removed.
Before writing over a row it counts every row that could be the same
account (same login, same refresh token, same id): none adds, several
keeps all, one is kept when it isn't magpie's own copy, is held, or is
the agent's live account. Codex's auth.json is written temp-and-rename,
0600, only where Codex is signed out.

Sync merges per record against the last sync's hashes (MergeSignIns):
the later renewal wins; a removal crosses only when the other side still
had it as of the last sync; ApplySignIns re-checks each row's hash
before writing so a renewal in between is kept. A computer with the tick
off sends none, so others remove nothing for it; turning it off, a
Restore, or a replaced server file clears the last-sync record.

Export's and Import's forms moved out of app.js into syncfiles.js,
imported when one opens (as autobackup.js is), so the core is 3.2KB
under its budget with no raise (app.js 3.2KB smaller than before).

docs/subsystems/sync-backup.md has a "Sign-ins, when picked" section;
subscription_signin_test.go's header now says it pins the default.

Run at the pushed head (678d28cba on origin/main bc10a6198):
- wsl-run go test -tags nogui -timeout 45m: backup, davsync, plugin, gui
  ok (TestCoreScriptBudget in it). provider: one red,
  TestCancelledPluginSignInSavesNothing, the late sign-in saved after
  Cancel. It is green 20 of 20 alone, at this head and at origin/main
  alike, and this change adds only new files there whose tests run after
  it; filed as #5047. cli there hung in proc.lookStamp's os.Stat on WSL
  at load 100, so it ran again on mote: one red,
  TestEveryRouteHasACommandOrIsNamed (GET /api/context/reply, #5026),
  the same at origin/main. gateway -run TestCompactionOverByteCapEveryTime
  ok (#4862 on mote's full run). TestMainWindowCorners on mote: red the
  same at origin/main (#3949).
- GUI, on mote: the 16 files that open Sync, plus i18n-keys and
  old-webkit, Chromium and WebKit, every language: 255 of 294 pass. The 39
  reds are segs-press-redraw's searchAllRow (#4566), s3-sync in WebKit
  (#2448) and usage-agents-hide (#3414). The same files at origin/main
  bc10a6198 give the same 39 pass and 39 fail. sync-signins, auto-backup,
  sync-sign-in, i18n-keys and old-webkit alone on WSL: 92/92.
- The whole GUI suite on WSL, stopped at 737 of its tests (1162 files,
  load ~100 there): 9 reds, all WebKit, none in a Sync file:
  account-eye (#4244, #5052), add-button (#4792), account-plugin-user
  and agent-expand-steady. The last two pass at this head and at
  origin/main on mote. The rest of the suite was not run.
- gofmt -l: clean. go vet: darwin (internal/gui, internal/cli),
  GOOS=linux and GOOS=windows -tags nogui for backup, davsync, provider,
  plugin, cli, gui: ok.
- win-run and wsl-run: go test -tags nogui -run
  'SignIns|Carries|AutoBackupSignIns' ./internal/provider
  ./internal/backup ./internal/davsync: ok on Windows 11 and Ubuntu 24.04.
- sync-signins.test.cjs: 20/20, Chromium and WebKit, 1100 and 420px,
  en/zh/zh-TW/ja/de, no horizontal overflow, no page errors.

Then rebased on origin/main 5ee5274bd (12 commits; davsync.go, app.js and
i18n.js merged with no conflict) and run again at the pushed head on mote:
gofmt clean; go test -run 'TestCoreScriptBudget|SignIns|Carries|
AutoBackup|Sync' for gui, davsync, backup and provider: ok; sync-signins,
auto-backup, sync-sign-in, i18n-keys, old-webkit: 92/92.

Broken by hand, each red, then restored:
- RestoreSignIns writing an older token over a newer one:
  TestRestoreSignInsNeverWritesAnOlderTokenOver red.
- The ambiguous-account guard has two layers (more than one match, and
  a single match with another record id); with only the first removed
  the test stayed green, with both removed
  TestRestoreSignInsLeavesAnAmbiguousAccount went red.
- MergeSignIns removing a row renewed here: TestMergeSignInsRemovedOnlyWhenTheOtherSideRemovedIt
  red.
- Codex auth.json written over a signed-in Codex:
  TestRestoreSignInsSignsCodexInOnlyWhereSignedOut red.
- ApplySignIns not re-checking the hash: TestApplySignInsKeepsWhatChangedSinceTheMerge
  red.
- davsync forgetting the last-sync record (st.SignIns = nil):
  TestSyncSignIns red.
- GUI: Export's tick on by default, and auto backup's On posting with
  no passphrase: sync-signins.test.cjs red for each.

Not tried: real accounts carried to a real VPS or second computer (all
Go tests use testenv homes, fake DAV and fake tokens; the Keychain is
never reached); a real vendor's refresh after a carried sign-in, and how
each vendor treats one refresh token used from two machines; the CLI
flags against a sandbox HOME (covered by the cli package's tests only);
auto backup's sign-ins have no CLI switch.
2026-11-03 17:24:19 +08:00
yetone 5ee5274bd9 quotas: a remote magpie's Codex reset is used from its card here (#3850)
prgrmrwy runs magpie on a home server and uses it from work through a
remote magpie (and DSH). The remote Codex card said "1 reset", but the
reset could only be used from the GUI of the computer that holds the
sign-in.

What changed:
- Gateway: POST /v1/magpie/quotas/codex-reset?user=<email>[&credit=<id>]
  (Server.codexReset) spends one of that account's resets with
  provider.SpendCodexReset. That is the Usage page's own code
  (UseCodexResetCard, then AwaitAllowance), moved out of
  internal/gui/usage.go so both use it. A reset can't be undone, so the
  route needs an enabled gateway key with full access, from loopback too.
  No key gets 401, and that covers every corsGuard exemption that has no
  key: Origin null, app schemes, *.localhost and a missing Origin. A
  read-only key gets 403 gateway_key_read_only (readOnlyGuard, which
  readOnlyRefused now lists, and again in the handler). A held key gets
  403 gateway_key_held, even one told quotas. The account must be named
  (400 otherwise). One ask runs per account at a time (409). When the
  reset is used, that card is read again.
- Remote client: UseRemoteCodexReset (remote_quotas.go) asks the remote
  with the provider's key. remoteJSON's status mapping is shared through
  remoteBody. A read-only key there is told as such, and a 404 as a
  remote too old. With no answer in time it says the reset may have been
  used, and it never asks again by itself. A remote Codex card now keeps
  its Resets; a GLM team's (byWindow) and every check-in are still
  dropped.
- GUI: "Use a reset" / "Use one..." show on a remote Codex card
  (codexResetCard). They open the same in-app confirmation sheet, with a
  line saying which computer's magpie uses it, and send the card's
  provider to /api/usage/codex-reset. The remote's errors are put in the
  user's words. New strings are in all 5 languages.
- DSH: no code here. Its provider plugin reads /v1/magpie/quotas/cards
  and can call the new route with a full key.
- resetOutcome (a reset's result in words) moved from app.js into
  resetask.js, the only place that says it, so the core's scripts stay
  in TestCoreScriptBudget's 1,533,802 with no raise (1,533,003 after;
  origin/main b967b1620 is 1,533,756).
- Docs: reference.md (remote quotas, gateway keys), gateway-routing.md
  (read-only list, the route's admission), providers-accounts.md.

What was run (rebased on origin/main b967b1620, then on 2e4735f8f):
- mote, at the head before the rebase and the resetOutcome move:
  go test -count=1 -timeout 45m ./internal/provider ./internal/gateway
  ./internal/gui at load ~300-450. provider ok. gateway: only
  TestCompactionOverByteCapEveryTime (#4862). gui: TestCoreScriptBudget
  (this change, 158 bytes over; fixed by the move), TestMainWindowCorners
  (#3949) and TestGatewaySkewOfAnotherIsSaidNotQuit/own_build (#5053,
  passes alone here and at b967b1620).
- mote, same run: 155 GUI files (reset|quota|usage-|panel-|i18n|budget|
  remote|gui-|old-webkit|core-script|script-size), 1856 of 1904 pass.
- WSL (magpie-desktop), the 9 red files alone, at this change and at
  origin/main b967b1620: this change 147 pass / 43 fail, main 146 / 44;
  every test red here is red on main too: codex-auto-reset webkit de
  (#4790), remote-magpie (#4398), usage-agents-hide (#3414), usage-fold
  (#3415, #4790), usage-heatmap (#4718), usage-ledger (#5048).
  codex-reset-lead (#5054) and panel-routing-providers (#5055) were red
  only under mote's load and pass alone on both.
- mote, at this head: TestCoreScriptBudget and
  TestGatewaySkewOfAnotherIsSaidNotQuit ok.
- WSL, at this head: account-every-reset, codex-resets-used, i18n-keys,
  providers-reset-use, remote-codex-reset, reset-each-title,
  reset-pick-card, reset-providers, quota-used-no-reset: 99 of 102 pass.
  The 3 reds are providers-reset-use's 420px Windows cases ("a click
  moved the page", #4873); that file alone is red on origin/main
  b967b1620 too (3 of 40 there, 2 of 40 here).
- WSL, rebased on 2e4735f8f (main had changed internal/gateway): the new
  tests and the read-only, CORS, LAN-guard, held-key, remote-magpie and
  UseCodexResetCard tests in ./internal/gateway ./internal/provider ok;
  core scripts 1,532,960 under 1,533,802; gofmt clean.
- Earlier on mote: TestCodexResetNeedsAFullKey,
  TestRemoteCodexResetThroughTheGateway, TestRemoteCodexResetAnswers, the
  read-only, CORS, LAN-guard, held-key and remote-magpie tests ok;
  remote-codex-reset and reset-pick-card 20 of 20 (chromium and webkit,
  5 languages, 900/390/440px). gofmt clean; go vet darwin, windows ok,
  linux for provider and gateway.

Broken by hand:
- With the handler's key check turned off, TestCodexResetNeedsAFullKey
  went red: "this computer, no key: 200 {code: reset}" and a reset was
  spent.
- With codexResetCard put back to provider === "codex",
  remote-codex-reset.test.cjs went red ("one Use, on the remote Codex
  card"). On the old code the route doesn't exist, so the full-key case
  gets 404.

Not tried:
- A real Codex reset spent between two real magpies: none was spent, to
  keep the owner's resets. The ChatGPT backend is the fake from
  codex_autoreset_test.
- DSH's plugin calling the route.
- GOOS=linux vet of internal/gui: it needs gtk4/webkitgtk, which neither
  mote nor magpie-desktop has. Its change is usage.go only, and that was
  vetted on darwin and windows.

Thanks to prgrmrwy for the report and the proposal.
2026-11-03 17:12:25 +08:00
yetone 69167bc299 usage: a reply let go under a second after a wait four times longer tells no speed
pluviophile714 on Discord: a gpt-6.1-sol row on Routing read 1,539
tok/s (input 21,617, output 392, first token 8.2 s, total 8.3 s), where
another monitor measures ~70. The reply came whole about 255 ms after an
8.2 s wait. Its content was spread over that short window (flow 230 ms),
so the HeldShare flow check passed, and so did the 100 ms floor, and
392/0.255 s read as 1,539 tok/s.

New rule, usage.HeldWindowMs: a window under 1,000 ms whose start
(first token, first text or first reasoning) is more than HeldShare (4)
times the window tells no speed. One rule in every place that computes
one:
- usage.DecodeOf: the Usage page's speed and totals, the CLI, the GUI's
  model speeds, and the gateway's Speed first pacing (noteTrySpeed);
- routing/client.js decodeOf: the Routing row's speed and its story line;
- usage/page.js ledDecode, plus a ledNoSpeed_ reason for the dash's
  tooltip, in en, zh, zh-TW, ja and de.
docs/reference.md and docs/subsystems/gateway-sessions.md say so.

On the owner's usage.jsonl (read only), 103 of the 106 rows over 600
tok/s were such windows (e.g. 448 tokens in 107 ms after 8.1 s) and are
dropped. The 3 that stay have windows of 2 to 5 s. The overall speed
goes from 103.8 to 97.9 tok/s.

What it costs: a short reply that really streamed after a long wait
tells no speed either. The live visible-reasoning fixture (76 tokens
over 731 ms after 6.8 s, ~104 tok/s) and #2637's grok record (307 tokens
403 ms after a 4.6 s first token, 531 tok/s) now read "—". Their tests
keep their guarantees with the same timings after a short wait, and also
check the long-wait case.

Tests:
- New: internal/usage TestShortWindowAfterLongWaitTellsNoSpeed (the
  reporter's numbers, a reasoned row from the ledger, the boundary, a
  second after a long wait, Totals) and internal/gateway
  TestShortWindowAfterLongWaitNotesNoPace.
- GUI: usage-speed-every-row has the reporter's row (dash, and the
  tooltip in all five languages); routing-burst-speed has it (first
  token 8.2 s, no tok/s).
- Updated to the new rule: TestVisibleReasoningSpeed's decode-minimum
  and max-speed cases (short wait now), TestCodexTurnMeasured...'s
  gateway/Claude rows, TestLiveVisibleReasoningFixture and
  TestUsageIngestTellsSpeed.

Run on mote at this tree (rebased on e41ef6288):
- go test -timeout 45m: internal/usage ok, internal/tui ok.
- internal/gateway: red only in TestCompactionOverByteCapEveryTime
  (#4862, full package run; passes 3 of 3 alone).
- internal/gui: red only in TestMainWindowCorners (#3949, macOS 27).
- internal/cli: red only in TestEveryRouteHasACommandOrIsNamed (#5026,
  red on main since 0872bc2a0).
- The two speed fixtures that failed in the gateway run pass on rerun.
- GUI, chromium and webkit: 36 files (every speed, ledger, i18n,
  routing-request and burst file), 609 tests, 603 pass. The 6 reds are
  usage-ledger's "newest live route needs no return-to-live button"
  (#5048, #4078, #3104 on main).
- Rebased on 1af868a15 (f0e0385a0 changed routing/client.js), then
  run again at the pushed head: internal/usage ok; the gateway speed
  tests (-run ...Speed|Pace|Decode|TTFT...) ok; 8 GUI files (both
  speed files, routing-request-metrics/-model, routing-speed-first,
  i18n-keys, reasoning-speed, usage-speed-tip) 94 of 94 in both engines.
- gofmt -l clean. GOOS=windows go vet of usage, gateway, gui and cli ok.
  GOOS=linux go vet of usage and gateway ok; gui and cli need cgo/GTK
  for Linux, the same on main.

Broken by hand: with the check off in usage.go, client.js and page.js,
the new Go tests, TestCodexTurnMeasured..., TestLiveVisibleReasoningFixture,
TestUsageIngestTellsSpeed and both GUI files (1537 tok/s shown) go red.

Not tried:
- the reporter's own request;
- a real GPT stream, to confirm that a 255 ms window after 8.2 s is a
  held reply from this vendor;
- the whole GUI suite (no new API call or layout change);
- the Linux and Windows app.
2026-11-03 17:01:51 +08:00
yetone d10f377657 providers: Names & levels is Names, prices & levels, where a model's own price at one provider is set (ferock4669)
ferock4669 asked on Discord whether magpie has a screen to price each
model, since one model can cost differently on each provider. It has:
each row in a provider's per-model list has a price box (input, output,
cache read, cache write, 1h cache write, long-context tier, $ / 1M
tokens), saved in settings' ModelPrices under pid/model. It wins over
the list price in Usage (usage.Pricer through provider.BasePriceIn) and
in a key's spend cap (usage.KeySpent through NewCoster). Nothing has to
be built; the button opening it said only "Names & levels", so nobody
finds a price there.

What changed:
- The button, its panel's heading and fold, and every note that sends
  the user there say "Names, prices & levels" (zh 名称、价格与推理档位,
  zh-TW 名稱、價格與推理檔位, ja 名前・価格・推論レベル, de "Namen,
  Preise & Stufen"); the gateway's vision and compaction notes, the
  provider package's text, the subsystem pages and the site's start
  docs (en, zh, ja) follow.
- The button's tooltip says it sets what each model costs at this
  provider; Usage's "estimated" tooltip says where a provider's own
  price is set and that it counts over the list price. Both in en, zh,
  zh-TW, ja and de.
- Not changed: the Codex model description text in internal/codexcat
  (it goes to Codex, so a vendor sees it) and core_budget_test's
  history comment.
- app.js: a comment above the price box is shortened so the core
  script stays under its budget, not raised (app.js 116 bytes under
  origin/main).

Run at the pushed head (rebased on origin/main 1af868a15), on mote:
- go test -run 'Budget|ModelPrice|ModelPref|Vision|Compaction'
  ./internal/gui ./internal/provider ./internal/gateway: ok.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
  ok (before the rebase, which touched no Go of this change).
- GUI, both engines, every language each file runs: the 149 files that
  name the label or open a provider's editor (before the rebase): 1191
  ok, 30 red in 7 files. Each of the 7 is red the same way alone at
  origin/main without this change: provider-fetch-again (#5057),
  provider-typed (#4673), provider-levels-scroll webkit (#4395),
  provider-picks-stay (#4397), usage-agents-hide (#3414), usage-ledger
  Requests (#5048), mobile-web (#3952, no .git in mote-run's copy).
  name-suffix-remote "chromium de" (ERR_NAME_NOT_RESOLVED once) passed
  alone at the head. After the rebase: model-price-edit, i18n-keys,
  name-suffix-remote, usage-ledger, usage-agents-hide again: go tests above ok; model-price-edit, i18n-keys and
  name-suffix-remote (all 10 cases) ok; usage-ledger Requests and
  usage-agents-hide red as at origin/main 1af868a15.
Broken by hand: model-price-edit.test.cjs at origin/main's label is red
in all 4 cases (the button "Names, prices & levels" is not found).
Not tried: the whole GUI suite (another session's full suite was on
mote, WSL at load ~100 with 31 test runners); the real app.
2026-11-03 17:00:38 +08:00