Commit Graph
2027 Commits
Author SHA1 Message Date
yetone 0d2a101160 gateway: the Codex app's titles, descriptions and summaries go to the magpie model picked, not ChatGPT (atom_Ray on X)
atom_Ray on X: with a third-party model picked in the Codex app through
magpie, an hour of use still took 2% of the ChatGPT account's 5-hour
window, and at 0% left it could not be used at all.

The cause is the app's hidden side turns. ChatGPT.app 26.1013.40934 asks
for a thread's title, description and one-line summary
(ThreadMetadataGenerationService.generateTitle/generateDescription/
generateSummary in .vite/build/main-CLu1A25j.js; R0/z0/B0 via H0 and Jq
in src-DsLVGakC.js) on ephemeralGenerationModel, gpt-6-luna by default,
whatever model the conversation is on. A summary is asked after each
user and assistant message (bAu in app-initial). With magpie's model
beside the ChatGPT sign-in (openai_base_url), these reach
/backend-api/codex as gpt-6-luna. codexTitlesTo and codexDescriptionsTo
left an unset setting on the model Codex asked for, and thread_summary
had no route at all, so all three went to ChatGPT on the user's sign-in.

Now, with Codex's config model one of magpie's and magpie not Codex's
provider (agent.CodexSideModel, through gateway.CodexSideModel),
codexSideTo sends titles, descriptions and summaries on the Codex
backend path to that model. On Codex's own model nothing changes, and a
model the Titles or Descriptions setting names still wins. Summaries get
the same wrapper as descriptions (codexShaped): the plain answer is
handed back as the {"summary": ...} the schema asks for, with
compactSummary filled and cut to its maxLength (summaryJSON). This also
covers a summary on magpie's own API, where a Chat model's plain answer
was dropped by the app. No prompt, instructions or base_instructions are
changed: the request is sent to another model as Codex wrote it.

Run (this change on origin/main e57e78563 for the full suite; rebased
onto 3a47e377e, which touches internal/gateway, for the packages run
again; then onto 0e643b14e, internal/sessions only, built):
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows for
  internal/gateway, internal/agent and internal/cli: clean.
- New tests: TestCodexSideTurnsOnThePickedModel,
  TestCodexSummaryOnMagpieProvider, TestSummaryJSON (gateway) and
  TestCodexSideModel (agent). Also the existing title, description and
  #540 used-up tests: ok.
- Full suite (go test -tags nogui -timeout 45m ./..., one suite on the
  machine, log tee'd): 70 packages ok, 19 without tests, no FAIL, exit 0
  (gateway 594s, agent 449s, provider 220s, cli 151s).
- Rebased onto 3a47e377e: gofmt and vet (nogui) of gateway, agent and
  cli clean; go test -tags nogui -timeout 45m of internal/gateway,
  internal/agent, internal/cli and internal/usage: all ok.
- Rebased onto 0e643b14e (internal/sessions only): go build ./... ok;
  not run again.

Broken by hand:
- codexSideTo's side-model branch turned off: TestCodexSideTurnsOn-
  ThePickedModel red (the title went to ChatGPT, 0 magpie calls).
- Both codexSummariesTo call sites turned off: TestCodexSideTurnsOn-
  ThePickedModel red on thread_summary, and
  TestCodexSummaryOnMagpieProvider red (plain text came back).
- SideModel without the !asProvider() check: TestCodexSideModel red.

Not tried: the real Codex App with a real ChatGPT account (live ~/.codex
and the running magpie were left alone), Windows and Linux. The app's
ambient suggestions (ambientSuggestionsModel), safety recourse and
commit/PR message turns are not moved; they are asked rarely or only by
user action. Not changed: what ef37b6fb7 does at 0% (Send greyed in the
app until it is reopened). On macOS magpie reopens the app once when it
is idle. On Windows and Linux it only shows a notice
(internal/gui/codex_app_out.go:78). With account discovery off,
readLogins returns nil (internal/provider/logins.go:208), so a used-up
account is never known.
2026-10-25 01:41:23 +08:00
yetone 3a47e377e0 usage: a call whose vendor counts no cache is left out of every hit rate (#3464)
#3464 (zeewell on X): Kiro caches on its side, but its replies give only
credits and a context share, never cache tokens. Every hit rate outside
the Routing page read those calls' CacheRead of 0 as a miss. A Kiro-heavy
day showed "hit rate 6%" when the counted calls hit 90%.

The plugin already says so (opencode-kiro-auth 0.1.16 sends
usage.magpie_cache_unknown), and the gateway already kept it as
RouteUsage.CacheUnknown for Routing. This carries it the rest of the way:

- gateway: Usage.cacheNotCounted() (the vendor said so and no try
  reported a cache token) goes into usage.Record.CacheUnknown on every
  path that records a call: the gateway's own record, the OTel attempt
  path in observe.go, and trace's routeUsage.
- usage: Record.CacheUnknown is kept as ledger row flag 8192
  (rowCacheUnknown; grepped, no other flag uses that bit). Totals sums
  such calls' prompt into cache_unknown and counts them in
  cache_unknown_calls. Totals.HitRate leaves that prompt out of its
  denominator, and gives no rate when nothing is left.
- Old records: calls kept before the plugin said so carry no flag. A
  Kiro call (provider kiro or kiro-plugin) with no cache counted is read
  as uncounted (usage.CountsNoCache): in the ledger's row read, in
  Totals, and for Routing's history in internal/gui/trace.go
  (cacheCounted). The rule is scoped to Kiro's two ids, so another
  vendor's 0 stays a miss (tested).
- GUI: cacheHitOf in app.js drives the tray panel's card, the Usage
  page's agent rows and cache tile, the requests' Cache hit rate card and
  each ranking row. When only uncounted calls are left it shows "—" or
  nothing instead of 0%. Otherwise it says "{n} requests left out: their
  vendor doesn't count the cache". A request row's cache cells show "—",
  and its details say the vendor doesn't count the cache. The Context
  page (context.go, context.js) shows no cache for such a call and doesn't
  score it as a miss.
- No budget raised. This adds 625 bytes to app.js (1,320,224 to
  1,320,849, under its 1,321,336); d08b6118b had already moved the
  masking page's maskWho, maskProv and stillMotion out to
  plugins/redact, which an earlier version of this change did too.
- Strings in zh, zh-TW, ja and de. docs/subsystems/provider-plugins.md
  now describes the ledger side and what is not covered.

Not covered, filed: hit rates read from the agents' own session files
(the TUI and CLI session lists, the Sessions tab's totals) still count
Kiro's 0 as a miss (#3470). Found on the way: System One's calls are
recorded without their cache tokens (#3471).

Run at this tree (on origin/main e57e78563, fetched just before; the
54-file GUI run was at a84d2ec80, and the 14 files that main's
redact page change since could reach were run again here):
- gofmt -l . prints nothing. go build ./... ok. go vet ./... ok,
  GOOS=linux go vet -tags nogui ./... ok, GOOS=windows go vet ./... ok.
- go test -count=1 -timeout 45m ./internal/usage ./internal/gui
  ./internal/gateway: all ok (gateway 388s), TestCoreScriptBudget
  included.
- GUI, 54 files (ledger-*, panel-*, i18n-*, context-*, request*,
  usage-card*, usage-ledger and the masking/redact files),
  concurrency 2: WebKit 439/452, Chromium 444/457. The new
  ledger-cache-unknown test passed in both. Again here (ledger-*,
  masking-*, redact-*, mask-*, usage-ledger): WebKit 104/117,
  Chromium 109/122, the same reds. The reds, both already
  red alone on main before this change:
  - redact-words-any-case, 10/10 in each engine (#3500)
  - usage-ledger "newest live route needs no return-to-live button",
    en and zh in each engine (#3104)
- At earlier bases, with the same change: usage-agents-hide (#3414),
  usage-checkin's WebKit Qoder tab (#3091), usage-fold (#3415),
  usage-focus-steady (#3501) were red, each red alone on main too;
  usage-card-refresh read a row before it was laid out, under load
  (#3509); context-picks (#3483) and
  context-map's tile overlap (#3488) in Chromium. Filed while doing
  this: TestUsageReadAfterAppendHashesNothingOnAFineClock goes red
  about 1 in 20 on main aa3112f4e (#3511); it passed in this run.
- Red on the old code: the new Go tests in usage, gateway and gui, and
  ledger-cache-unknown.test.cjs (the old page shows "hit rate 6%"
  where this shows 90%). Each changed piece was broken by hand and
  turned a test red. The exception is the OTel attempt path in
  observe.go, which no test reaches.

Not tried: a real Kiro account through the GUI.
2026-10-25 01:23:42 +08:00
yetone d08b6118bd agents: Restart a desktop app that started before magpie's change, after asking
微雨南山 and stones on Discord: Claude Desktop, WorkBuddy and the Codex
app read magpie's settings only as they start, so a change made in
magpie did nothing until they quit and reopened the app themselves.

The agent's row now carries a Restart when the app is installed, running,
and started before its config last changed (agent.AppBehind):
Claude Desktop, WorkBuddy and WorkBuddy AI on macOS (bundle executable
via pgrep), Claude Desktop and WorkBuddy on Windows (process tree, main =
earliest process whose parent is outside it). A press opens magpie's own
dialog first (confirmAction); Cancel and Escape send nothing. On accept
POST /api/agents/restart/{id} quits the app gracefully (AppleScript quit
on macOS; taskkill without /F on Windows, then /F /T after appCloseWait
for a tray that holds on), waits, and opens it again. On macOS an app
that won't quit is reported (StillOpen) and never forced. The Codex
app's existing Restart now asks first too. CLI agents get none.

changedAt: a stash digest that changed with no file written since the
app started now counts the change as now, so a change magpie made while
the app ran is seen (it was dated to the old write and missed).

app.js budget, not raised: archivePanel moved into plugins/usage/page.js
(its own comment called it the Usage page's; Routing's trace calls it at
draw time, after page.js has loaded), maskWho, maskProv and stillMotion
into plugins/redact, and usageHidOpen into plugins/usage. app.js is
1,108 bytes smaller than on main, budget unchanged.

Run (the first five at the pre-rebase head, same code):
- GUI agent-app-restart + agent-stale-copies: 120/0, chromium and webkit,
  en/zh/zh-TW/ja/de, window 980 and 440 and panel 440, no sideways scroll,
  no placeholder in aria-label or title.
- Broken by hand: without the confirm the GUI test is red; without the
  changedAt fix TestChangedAtWithoutAWrite is red; without the since gate
  TestWorkBuddyRestartOnMac and TestWorkBuddyRestartOnWindows are red.
- macOS, real fake-app processes in a sandbox HOME with a stubbed
  launcher: quit in 100ms and reopened; a held quit returns StillOpen
  after 4s, not forced.
- Windows box, console session (schtasks /IT), fake app and stub
  launcher: graceful close in 407ms; a tray that holds on is ended after
  5.66s; reopened through the stub.
- gofmt -l clean; go vet darwin (agent, gui), GOOS=linux and
  GOOS=windows; builds.
- At 2c5327925 (on origin/main 703437866): go test -tags nogui
  ./internal/agent ./internal/gui ok. 95 GUI files (mask, redact, usage,
  request-archive, routing-bodies, agent-app-restart, agent-stale-copies,
  i18n, insights, panel), 6 wide: 1380/53. 52 of the reds are the same
  tests red on origin/main 3b5a2f612 run alone, all filed: #3500
  (redact-words-any-case), #3414 (usage-agents-hide), #3415 (usage-fold),
  #2549/#3091 (usage-checkin Qoder tab, WebKit), #3001 (usage-ledger's
  route callback). The 53rd, usage-curve-zoom-back chromium zh-TW, passes
  alone 20/0 twice; noted on #2399.
- At the pushed head (on origin/main 20d63621d, which changed app.js,
  routing/client.js and the panel tests, not internal/agent):
  TestCoreScriptBudget (budget unchanged), go test ./internal/gui ok,
  gofmt clean, go vet gui for linux, windows and darwin. 45 GUI files
  (routing-bodies, request-archive*, panel*, agent-app-restart,
  agent-stale-copies, i18n-keys, library-mcp*, mask-actions,
  masking-records, usage-agents*, usage-ledger*): 720/28. The only reds
  are #3414's and #3001's. Then rebased on aa3112f4e (app.js's panel fit()
  only): TestCoreScriptBudget, i18n and notice tests ok; agent-app-restart,
  i18n-keys and panel-fit-tabs 54/0.
- Not run at this head: the full go test ./... and the whole GUI suite
  (the machine's disk filled mid-run once; shipped on the packages and
  files above, per ship-immediately).

Not tried: a real AppleScript quit from a GUI session (this session is
Background, so the fake was quit by SIGINT and opened by exec), the real
Claude Desktop and WorkBuddy apps (never quit the user's running apps),
Codex app and WorkBuddy AI on Windows (process names unknown, so no
button there), Linux (no desktop app of these runs there).
2026-10-25 00:30:31 +08:00
yetone 14b10f1166 library: an MCP server signed in to in Claude Code, in WSL too, says so instead of "needs sign-in" (CyberCaius on Discord)
CyberCaius signed in to a remote MCP server with Claude Code's /mcp in
WSL, and the Library still said 需要登录. The check connects as magpie,
without the agent's tokens, so an OAuth server answers it 401, and magpie
read no agent's own sign-in anywhere: not on Windows, not in a distro.

The check now reads each Claude Code target's .credentials.json, beside
the settings.json the target already has (readOwnSignIns,
mcp_agent_signin.go). A distro's Claude Code is a target under the
distro's home (wslTargetOf), so its file is read there through
\\wsl.localhost with no new setting. An mcpOAuth entry of the server's
name and URL with an access or refresh token, as Claude Code 2.1.310
counts one, names the agent in ServerHealth.AgentSignIn; the row says
"signed in in Claude Code (Ubuntu)" with the ok dot, and the tooltip says
magpie can't list its tools without signing in itself. An entry without
a token, another URL by the same name, and a file that can't be read or
parsed name nobody, so the row stays "needs sign-in". The tokens are
never sent or kept. A stopped distro has no target and isn't started.
On a Mac only the file is read, never the Keychain. The sign-ins are part
of the check's cache key, so a sign-in in the agent since isn't answered
from the session's earlier check. Strings in zh, zh-TW, ja and de.

Run:
- TestCheckNamesAgentsSignedInThemselves (internal/library): agent.FakeWSL
  forces the Windows+WSL switch (Ubuntu running, its home a temp root),
  sandbox HOME/USERPROFILE/XDG_CONFIG_HOME, CLAUDE_CONFIG_DIR cleared, a
  real httptest server answering 401 with WWW-Authenticate.
- Broken by hand, each red with a FAIL naming the behavior:
  - the old behavior (the reader names nobody): reading only this
    computer's Claude folder (claudeDir()) instead of the target's:
    "signed in in claude@wsl:Ubuntu, the check says {State:auth ...
    AgentSignIn:[]}".
  - counting an entry with no token: "a sign-in with no token counted".
  - leaving the sign-ins out of healthKey: "signed in on both sides, the
    check says ... AgentSignIn:[claude@wsl:Ubuntu]" (stale cache).
- library-mcp-health-wsl.test.cjs, chromium and webkit, en/zh/zh-TW/ja/de:
  red on the old client.js (expected "signed in in Claude Code (Ubuntu)",
  got "needs sign-in"), 12 of 12 after.
- gofmt -l (nothing); go vet on darwin, GOOS=linux -tags nogui and
  GOOS=windows for ./internal/library ./internal/gui; go build darwin,
  GOOS=windows and GOOS=linux -tags nogui ./...; go test -tags nogui
  -count=1 -timeout 45m ./internal/library ./internal/gui: ok (187s, 63s).
- GUI: library-mcp-health, library-mcp-health-wsl, mcp-signin-health,
  mcp-signin, mcp-oauth-app, library-mcp-tools, library-mcp-tool-switch,
  library-mcp-unshown, library-items, i18n-keys, gui-zh-tw, gui-ja,
  gui-de: 161 of 161 pass.
These ran first at a base before origin/main 1f589e3f4, then again at
this head (on 1f589e3f4): vet, builds, internal/library ok (149s), the 13
GUI files 161 of 161. internal/gui is red at this head on
TestCoreScriptBudget alone: app.js is 1321476 bytes, over 1321336. It is
the same on origin/main 1f589e3f4, from 2a8a17746 (this change doesn't
touch app.js, and its size is main's); #3367. The budget isn't raised.

Claude Code's file format was read from its 2.1.310 binary (td's key,
the token save's serverName/serverUrl/accessToken/refreshToken, $Ci's
"neither token is no sign-in").

Not tried: a real /mcp sign-in in Claude Code in WSL on the Windows box
(ssh to 10.0.0.132 timed out), and the full ./... suite. Not covered:
Codex's own MCP sign-ins (keyring, or a .credentials.json fallback whose
format wasn't checked against its source), #3508.
2026-10-25 00:03:52 +08:00
yetone 3b5a2f612d dsh: Max reaches GLM-5.3 as max, asked adaptively with its level
01huadalang on Discord (10-24): DSH Desktop on magpie-anthropic, zcode
GLM-5.3 at Max; magpie's Routing log showed 77 of 78 requests at low,
one at high, never max.

What DSH sends, from the real app (DSH Desktop 0.2.1-rc.3's app.asar,
pi-ai 1.1.0 and dsh-llm-pi-ai, run read-only through node with
magpie's GLM-5.3 entry): at Max and at High alike, max_tokens 128000
and thinking enabled, budget_tokens 16384. pi-ai's clampReasoning turns
xhigh and max into high before thinkingBudgetForLevel, so no
thinkingBudgets setting can give Max a budget of its own. At Low it
sends 2048; with reasoning off, no thinking field.

What magpie did with it: 16384 is read as high (effortOfBudget) and
sent as output_config.effort high, so Max could never reach max. The
"low" rows were not reproduced: no request DSH builds at Max reads as
low here, and Z.ai refused none of the shapes (live, below), so no
refusal memory lowered it. A 2048 budget (a session or a subagent DSH
runs at Low; dsh-tool-subagent lets the model pick reasoning_effort)
reads as low, and that is the likeliest source. It is asked of the
reporter.

The fix, zero-config: Z.ai's GLM-5.2 and GLM-5.3 (the GLM half of
effortInOutputConfig) are written into dsh's magpie-anthropic route
with compat.forceAdaptiveThinking (gateway.AdaptiveWithEffort, beside
AdaptiveThinking). MiniMax-M3.1-Flash, the other half, is left on its
budget: adaptive wasn't tried on MiniMax (no key), so it is on #3496. pi-ai then sends thinking adaptive and
output_config.effort from magpie's thinkingLevelMap, max as max
(checked against the real asar: low/high/max each go as themselves).
The gateway already passes adaptive thinking with output_config.effort
through for these models (fitted to their levels, withOutputEffort;
TestGLMEffortInOutputConfig pins it), so the gateway only gains
AdaptiveWithEffort. No client name is keyed on, and a budget alone is
read as before. An adaptive-to-budget rewrite in withOutputEffort was
tried first and dropped: TestGLMEffortInOutputConfig pins adaptive
passing through, and Z.ai takes it.

Live, Z.ai GLM-5.3 with the zcode key (sandbox script, key never
printed): adaptive and enabled+effort both accepted; effort max
thought 1237-1427 chars against 426 at high, so max is a real tier.

Run, at this head rebased on origin/main 3be1f14eb (head 7ae044226):
- go build ./...; go vet of gateway and agent for darwin, linux and
  windows; gofmt -l clean.
- go test ./internal/gateway/ ./internal/agent/ ./internal/plugin/
  -timeout 45m at this head: ok (655s, 469s, 187s)
  (an earlier run, with the dropped rewrite, was red on
  TestGLMEffortInOutputConfig only, which led to dropping it).
- Own GOCACHE: the shared one had files trimmed mid-build by another
  run (vet "could not import sort").
- A first run hit "no space left on device" from another session's
  disk use (18G free after); rerun in full.
Broken by hand: with dshKindConfig back on AdaptiveThinking alone,
TestDshMaxReachesOutputEffortModels is red for GLM-5.3 and GLM-5.2. TestAdaptiveOnOutputEffortModelAsksItsLevel (the
gateway end, through a fake zcode plugin) passes on the old gateway
too: it holds that DSH's new shape reaches the vendor and the Routing
log as max, not a gateway change.
Not tried: DSH Desktop itself against this build (the app isn't
installed here; its pi-ai was run from the asar instead); MiniMax with
adaptive (left out, #3496); the whole go test ./... and GUI suite (no GUI change).
Siblings left alone, filed as #3496: Pi and omp hit the same pi-ai
clamp, MiniMax-M3.1-Flash above, and dsh to a DeepSeek model on DeepSeek's host (#3298) still
goes as a 16384 budget, since dsh's compat is per model id.
2026-10-24 23:27:25 +08:00
yetone 40b5c2daf0 agent: say why Claude Desktop's 3p mode can't keep a Chinese language (Dx25 on Discord)
Dx25 (Windows) set Chinese and found %LOCALAPPDATA%\Claude-3p\config.json
back at "locale": "en-US" after every Desktop start. magpie doesn't write
it: config.json is touched only by desktopCarryLocale, at switch-on, and
only when it has no "locale" (TestClaudeDesktopKeepsThe3pLanguage,
TestClaudeDesktopUserEditsThenReapply). Desktop writes it.

Read from Desktop 3.6556.2's bundle (current RELEASES.json, 10-22): in 3p
mode the window is the bundled UI, Resources/ion-dist, with 11 catalogs
(en-US de-DE fr-FR ko-KR ja-JP es-419 es-ES it-IT hi-IN pt-BR id-ID) and
no Chinese; its locale is its localStorage, else navigator.languages
mapped onto those 11, else en-US. On mount it calls
electronIntl.requestLocaleChange(its locale), and the main process's
handler writes that value with store.set("locale", ...). The main process
has zh-Hans and zh-Hant catalogs (for the signed-in window), but the 3p
window asks for en-US on every start, so a Chinese locale, carried or
set by hand, is replaced each time. 2.7032 (this Mac) and 2.9939.2 (the
Windows box) have the same 11 in ion-dist. Nothing magpie can write
keeps Chinese in 3p mode; it is Desktop's missing translation.

This commit changes no behaviour: desktopCarryLocale's comment and
docs/subsystems/agent-wiring.md now say the above, where they implied the
carry kept a Chinese language.

Run at 3be1f14eb + this change: gofmt -l clean; go vet ./internal/agent
(darwin), GOOS=linux go vet -tags nogui and GOOS=windows go vet of it ok;
go test -run 'TestClaudeDesktop(CarriesTheLanguage|KeepsThe3pLanguage|
UserEditsThenReapply|LanguageOddValues)' ./internal/agent ok. Comment and
doc only, so no full suite.

Not tried: starting a real Desktop in 3p mode (no sandbox for its
userData on macOS); the mechanism is from its shipped code. The Windows
box's live Claude-3p/config.json holds "locale": "en-US", read only.
2026-10-24 23:17:04 +08:00
yetone 1184862583 agent: Codex background compaction writes the bare async_compaction = true where a Codex older than 0.163 reads the config (多喝热水)
多喝热水 (Discord #help, Windows, v0.1.1384, Codex desktop with ChatGPT
sign-in): Codex wouldn't open, "config.toml:154:1: invalid type: map,
expected a boolean". That line is the [features.async_compaction] table
1978eabe5 (#2490/#2493) writes.

Codex versions, from codex-rs source and the real binaries:
- up to 0.163.0-alpha.5 (0.160.0, 0.162.1 included) FeaturesToml is a
  flattened BTreeMap<String, bool>: any table under [features] fails the
  whole config; an unknown bool key is only a warning.
- from 0.163.0-alpha.8, async_compaction is FeatureToml<…>, bool or
  table, and model_async_compact_threshold_percent is read only from the
  table (the bool gives Codex's default 65).
- the provider table's capabilities = {...} is safe: 0.161 and older
  ignore unknown provider keys (schemars-only deny_unknown_fields),
  0.162 parses it. 0.160.0 and 0.162.1 load a config holding it.
- ChatGPT.app 26.1013.40934 bundles Codex 0.163.0-alpha.10.2
  (Contents/Resources/codex-cli/codex-package.json); the reporter's
  Windows app rejects the table, so it bundles one before alpha.8.

Fix: the table is written only when every Codex found here that reads
this config (the CLI on PATH, the desktop app's bundled codex on macOS,
the Store app on Windows, the editor extension, Codex in WSL) has a
version at or after 0.163.0-alpha.8. Otherwise, or when a version can't
be read (the Windows app, the extension), magpie writes the bare
[features] async_compaction = true with no share. A table magpie wrote
before is taken back through its stash (only the keys the stash names
as magpie's; an emptied table goes), so a config already broken opens
again on the next sync. A table or bool the user wrote stays. The stash
records a bool it wrote (`bool`), and the table comes back once every
reader is new enough. Settings' state carries codexAsyncHeld, and the
Codex row says which Codex holds the share back and that it needs
0.163. The note costs app.js 390 bytes; its budget and the core's are
raised by exactly that, the agent's own row in the core.

Run:
- real binaries, sandbox CODEX_HOME/HOME, `codex features list` on the
  config magpie writes (TestCodexAsyncConfigLoadsInRealCodex,
  MAGPIE_TEST_CODEX_BINS): 0.162.1, 0.163.0-alpha.8 and 0.164.0 load it;
  alpha.8 and 0.164.0 report async_compaction true. By hand before the
  fix: 0.160.0 and 0.162.1 exit 1 on the table ("invalid type: map,
  expected a boolean"), load the bool and nothing; alpha.8 and 0.164.0
  load all three.
- broken by hand (table always allowed): the real-binary test is red
  for 0.162.1 with Codex's own error, OldCodexGetsTheBareKey red in all
  four cases, TableTakenBackForOldCodex red ("magpie's table not
  mended"). Green again with the fix.
- go test -tags nogui ./internal/agent ./internal/gui ./internal/edit
  ./internal/settings: ok (gui after the budget, re-run alone: ok).
- GUI (node --test, chromium + webkit): codex-async-compact,
  agent-prefs, settings-general, segs-glide, i18n-keys: 100 pass, 0 fail.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...; go build for darwin, linux (nogui),
  windows: ok.

Not tried: the Windows box (Store-app detection, reading its bundled
codex's version, a non-Store install), a WSL distro, a real Codex run
past the share, the whole GUI suite. The full go test ./... is queued
behind other sessions' suites (one per machine) and wasn't waited for.
2026-10-24 22:02:49 +08:00
JoeyWu-tech 93435f27dc docs: the partner list is fetched on a process's first ask and hourly, and by the gateway's magpie unasked (#3362)
providers-accounts.md still said the list is fetched every 6 hours.
97902e93 made it a process's first ask and hourly after
(partnerEvery = time.Hour), and 7e0c0310 has the magpie serving the
gateway fetch it when it starts and whenever it is due, asked for or not
(KeepPartnersFresh).

Left out of this landing: the author's same fix to the privacy pages
(site/public/docs/privacy.html, zh/, ja/). A community change to site/
waits for the maintainer to look (docs/contributors.md); they stay on
JoeyWu-tech's branch, commit e46eee4b2, for that.

Landed by review from JoeyWu-tech's branch (posted on #3362 as
Coffemon's). The run record is in the stack's last commit.
2026-10-24 21:33:06 +08:00
JoeyWu-tech b18a6a080b gateway, cli: magpie goroutines writes the running magpie's goroutine stacks to a file (#3362)
#3362's second ask: an app stuck at something could only be read by
killing it, which ends what was stuck. magpie heap and magpie cpu
already ask the running gateway for a profile over loopback; magpie
goroutines asks it for every goroutine's stack. That works on Windows
too, where there is no SIGUSR1.

GET /v1/magpie/goroutines (goroutines.go) answers the callers
/v1/magpie/heap answers (profileRefused: a program on this computer
over loopback, no browser mark, a loopback Host; a gateway key lets
nothing else in) with runtime/pprof's goroutine profile at debug=2,
the form a crash prints: each goroutine's state and wait ("[select,
4320 minutes]"), its frames with source lines, and who started it. It
is text/plain and no-store, and X-Magpie-Goroutine-Stats names the
process (pid, program, version, window, uptime, goroutine count).
Arguments are words in hex, never what they point at, so the dump
holds no keys, prompts or messages; it does name magpie's source files
and the program's path, which the usage says.

magpie goroutines [<file>] writes it to <file>, else
magpie-goroutines-<date>-<time>.txt in this folder, 0600 and never over
a file there, then prints the file and the process. --help, -h and help
print the usage and ask nothing; a flag it doesn't take, "-", a blank
name or a second file are refused before the gateway is asked. A
magpie older than this one answers 404 and is told to update; with
none answering, it says so.

The refused callers TestHeapProfileOnlyToThisComputer listed move into
profileCallersRefused, which the CPU test and the new one share.

Run on b437e4ad, go1.26.8. internal/gateway and internal/cli are the
same here and at the branch's head (tree 613df3a9), where the checks of
them ran:
- gofmt -l and go vet as in the commit before: clean.
- go test ./internal/gateway -run 'Goroutine|Heap|CPU|Profile': ok;
  ./internal/cli -run 'Goroutines|Heap|CPU|Help': ok.
- Broken by hand: goroutinesRefused letting every caller in makes
  TestGoroutineDumpOnlyToThisComputer red ("Origin null with a key":
  200); debug=1 for 2 makes it red (the parked goroutine isn't in the
  dump); without the route it is red (404), and so is
  TestGoroutinesWritesTheRunningGatewaysDump ("older than this one").
  Restored, green.
- Full suite at this commit, go test -tags nogui -count=1 -timeout 45m
  ./... (tree e5cf04af, 498s): 62 packages ok. 14 reds in 7 packages,
  none in a file this commit touches, each red on b437e4ad without it:
    internal/agent TestInstalledVersion, TestOmpDetectedWithPiDir,
    TestCursorFolderFromTheEditorIsNotTheCLI and TestZedAppPath:
    proc.Look keeps "not found" for a tool written in the tick of its
    folder's last change (#3141).
    internal/agent TestCodexDriftReached: Drift answers from the read of
    Codex's log taken before the test's last insert (#3398).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).
Not tried: a real stuck app; magpie goroutines against the app on macOS
or Windows (the tests serve gateway.New().Handler() on loopback).
2026-10-24 21:33:06 +08:00
JoeyWu-tech a2cef8bf4f provider: partners.json keeps when the list was last tried and how it ended (#3362)
"partners":null} for three days, and nothing told a fetch that failed
every time from one that never came back, or from none being asked. A
failed fetch wrote nothing and logged nothing.

refreshPartners now keeps two fields with the list:
- tried: when the last fetch started, written before it is sent;
- error: how it failed (whitespace folded, cut at 500 runes), cleared
  when the next one starts.
Read together: error set, the last try failed; tried after at with no
error, a try is still out; tried long ago, nothing has asked since. A
failure is logged once until its error changes or a fetch gets the list
again, and the fetch that gets it after a failure is logged too. The
desktop app's log goes nowhere a user can read, so for the app the file
is what tells.

Checked for #3362 on the way: v0.1.1296's fetch, keep and save, given
the bytes /api/partners serves now (Kimi Code, listed from 10-23 00:00
+08:00) over the 10-20 file, writes the file, with the icon fetched or
not. So it isn't the save or the list.

Run on b437e4ad, go1.26.8. internal/provider is the same here and at
the branch's head (tree 613df3a9), where the checks of it ran:
- gofmt -l clean; go vet -tags nogui of internal/provider, gateway, cli
  and the root package with GOOS=linux, darwin and windows: clean.
- go test ./internal/provider -run Partner -count=1: ok.
- go test ./internal/provider -run '^TestPartners' -race -count=20: ok.
- TestPartnersKeepTheirLastTry on b437e4ad's partners.go: red at
  partners_test.go:511 (after a 503 there is no partners.json at all).
- Broken by hand, each red in TestPartnersKeepTheirLastTry: no write
  before the fetch (line 535: a try out shows no try since the last);
  the error not cleared when a try starts (535: a try out still shows
  the last error); the failure logged on every try (518: "logged 3
  times, want once"). Restored, green.
- Full suite at this commit, go test -tags nogui -count=1 -timeout 45m
  ./... (tree a661f529, 482s): 62 packages ok. 15 reds in 7 packages,
  none in a file this commit touches, each red on b437e4ad without it:
    internal/agent TestInstalledVersion, TestHowInstalled,
    TestOmpDetectedWithPiDir, TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI and TestZedAppPath:
    proc.Look keeps "not found" for a tool written in the tick of its
    folder's last change (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).
Not tried: a real app left running against usemagpie.ai, on macOS or
Windows.
2026-10-24 21:33:06 +08:00
JoeyWu-tech f252b403d3 provider: the icon prune leaves a listed partner's logo, so the add sheet keeps drawing it (#3424)
partnerIcon keeps a partner's logo in the icons folder beside
providers.json and, while its iconUrl stays the same, uses the file it
kept as it is (97902e93), so the file only ages. No provider points at
it until one is added from the partner, and pruneIcons, after every
save of providers.json, removes a picture no provider or plugin names
once it is an hour old. A logo kept from an earlier day is that old at
once, so the first save after a start (a key, a model picked, an order,
a sign-in, a sync's pull) took it: /api/icons/<name> answered 404 while
the partner still named file:<name>, the add sheet's img fell back to
the generic icon, and the next fetch, finding the file gone, downloaded
it again, for a save an hour on to take. Before 97902e93 every fetch
downloaded it again, six hours apart, and a save an hour after each
took it the same way.

Now pruneIcons also leaves the pictures of the partners listed now
(keptPartnerIcons), as it leaves a plugin's (keptPluginIcons). A
process that hasn't asked for the list reads it from partners.json, as
Partners does, so a save from the CLI leaves them too. A partner no
longer listed loses its logo at the next prune unless a provider added
from it names it, as before. With the list off (MAGPIE_PARTNERS=off,
and every test that names no list) nothing is kept for it.

Lock order: store, then pruneIcons, then partnerMu. Nothing under
partnerMu saves providers.json or takes a lock store holds, and no
fetch runs under it.

Old data: a logo pruned before this is fetched again by the list's next
fetch (at start, then hourly), as it was; nothing to move.

What was run (tree 0409d43e, on a93190ae, go1.26.8):
  broken by hand, with this change: pruneIcons without the
  keptPartnerIcons loop:
    partners_test.go:489: the listed partner's logo was pruned: stat
    .../icons/d1774929a9b62027.png: no such file or directory
    partners_test.go:496: the logo was downloaded 2 times, want once
  a real run: magpie web in a sandbox HOME with the real list
  (usemagpie.ai/api/partners, Kimi Code) and stats off. A first start
  kept Kimi Code's logo; its file was set two hours back, as one kept
  from an earlier day is; a second start's fetch used it as it was;
  then magpie provider add Local url=http://127.0.0.1:9/v1 saved
  providers.json:
    main (a93190ae): the file gone, GET /api/icons/<name> 404,
    /api/providers still naming file:<name>, and a new Chromium drew
    Kimi Code in the add sheet with the generic icon
    this change: the file kept, 200, and the add sheet drew the logo
    (128 px wide)
  gofmt -l internal/provider: nothing
  GOOS=linux, darwin, windows go vet -tags nogui ./internal/provider:
  exit 0; CGO_ENABLED=0 GOOS=darwin and windows go build -tags nogui
  .: exit 0
  full suite, go test -tags nogui -count=1 -timeout 45m ./...: a first
  run stalled, the test binaries of 14 packages sitting in close(2) for
  45 minutes until the timeout (internal/provider ok); run again with
  nothing changed (445 s): 62 packages ok, internal/provider among them.
  13 tests red in 8 packages, none in a file this change touches:
    internal/agent TestInstalledVersion, TestOmpDetectedWithPiDir and
    TestZedAppPath: proc.Look keeps "not found" for a tool written in
    the tick of its folder's last change (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).
    internal/middleware TestFailOpen: "spin took 1.508697807s", past
    its 1 s bound under the run's load; alone, -count=10: ok.
Not tried: the desktop app's webview (a browser that drew the logo
before keeps drawing it from its cache, since /api/icons answers
immutable for a year), macOS, Windows.
2026-10-24 21:33:06 +08:00
JoeyWu-tech ba4b754b22 gateway: a relayed Chat stream's tool call with no index is given its call's (#3386)
xianfeng-zhu (#3386): Cursor's Private Inference on magpie's
/v1/chat/completions, a Gemini model behind it, failed every turn that
made a tool call with AI_TypeValidationError at
choices[0].delta.tool_calls[0].index ("expected number, received
undefined"), then a 499 loop; turns without tools went fine. Gemini's
OpenAI-compatible API sends its calls with no index (Linka's frames in
gemini_compat_cut_test.go have none either), where the OpenAI contract
has one on every fragment, and a relayed stream went on without one.
The AI SDK's OpenAI provider, which the report names as what Cursor
reads Chat with, checks every chunk and turns that one away, so the call
is never made. OpenAI's own node SDK, through its stream helper, keeps
no call at all.

chatTidy, which already mends a relayed Chat stream's empty ids, empty
names and "stop" after calls, now gives a fragment with no index (none,
or null) the index of its call (streamCallIndexes.give). A fragment with
an id other than the open call's, or after the first in its delta,
starts the next call, as chatDecoder reads a new id; any other goes on
with the open one. So two calls in chunks of their own are 0 and 1.
Given both 0, as their place in the delta would give them, OpenAI's
node SDK merged them into one call with both arguments run together. A
fragment with an index keeps it, and a stream whose calls have theirs
goes as it came. It runs before the ids are mended, so a call with no id
either (#3386's chunk) gets both.

Not changed: the translations write an index already (chatEncoder,
chatWholeEvents), and a whole reply's message needs none. Nor is a call
given a type: Gemini's frames have "type": "function". The report's
chunk has neither an id nor a type, and is taken as cut short: magpie
gives a call with no id one (#2611, v0.1.1277), so the chunk it sent
would have had one.

What was run (tree e6023c66, on a93190ae, go1.26.8):
  a real run: magpie built at a93190ae and at this commit (go build
  -tags nogui), magpie serve in a sandbox HOME, its provider's Chat URL
  a local server replaying Linka's frames (the call, its signature and
  the usage in one chunk, then "stop", then [DONE]) under
  gemini-4-argon, so the Gemini paths run as for Google's host
  (geminiCompat). Clients on magpie's /v1/chat/completions, with the
  tool codemode:
    curl, the chunk magpie sends on: main, the call with no index; this
    change, index 0 (0 and 1 with the second call below)
    @ai-sdk/openai 2.0.136 (ai 5.0.281), streamText:
      main: AI_TypeValidationError, path choices, 0, delta, tool_calls,
      0, index, "Invalid input: expected number, received undefined";
      no tool-call
      this change: tool-call codemode {"code":"run()"}, finish
      tool-calls
    @ai-sdk/openai 2.0.48 and 2.0.122, older releases that turn away a
    new call with no id (2.0.48 one with no type too): main, the same
    validation error; this change, the call
    openai 5.23.2, chat.completions.stream and finalChatCompletion:
      main: no tool_calls (finish_reason tool_calls)
      this change: call_1 codemode {"code":"run()"}
    @ai-sdk/openai-compatible 1.0.59, which gives a missing index the
    call's place in its delta: the call, on main and with this change
    with a second call in a chunk of its own (made up from Linka's
    frame, id call_2):
      @ai-sdk/openai 2.0.48, 2.0.122 and 2.0.136: main, the validation
      error for each; this change, both calls
      openai: main, no tool_calls; this change, call_1 {"code":"run()"}
      and call_2 {"code":"two()"}
      @ai-sdk/openai-compatible: both calls, on main and with this
      change
    the replay sending both calls at index 0, as their place in the
    delta would give them: openai keeps one call, id call_2, arguments
    {"code":"run()"}{"code":"two()"}, on main and with this change,
    which keeps an index the upstream sent
    #3386's chunk as the report shows it, the call with no id and no
    type: this change sends it on with index 0 and an id (#2611's);
    @ai-sdk/openai 2.0.122 and 2.0.136 make the call, 2.0.48 throws
    "Expected 'function' type." and openai "tool call snapshot missing
    `type`"
    two such calls, each in a chunk of its own: nothing tells them
    apart, here as in chatDecoder, so both go with index 0 (the second
    is given its id after, where its signature is carried);
    @ai-sdk/openai 2.0.136 makes both calls, 2.0.122 the first only,
    2.0.48 and openai throw as above
  broken by hand, with this change: chatTidy without the give step:
    TestChatTidyGivesCallsAnIndex: no line's calls have an index
    ("line 4: indexes [[-1 -1]], want [[1 2]]")
    TestGeminiCompatRelayedCallsHaveAnIndex: every case, "call 0 went
    with index <nil>, want 0"
  go test -race -count=20 -cpu 1,2 of those two, TestChatTidy* and
  TestStreamedCallGivenAnID: ok
  gofmt -l internal/gateway: nothing; GOOS=linux, darwin, windows go vet
  -tags nogui ./internal/gateway: exit 0; CGO_ENABLED=0 GOOS=darwin and
  windows go build -tags nogui .: exit 0
  full suite, go test -tags nogui -count=1 -timeout 45m ./... (475 s):
  63 packages ok. 14 tests red in 7 packages, none in a file this
  change touches:
    internal/agent TestHowInstalled, TestOmpDetectedWithPiDir,
    TestZedAppPath, TestCopilotFolderFromAnIDEPluginIsNotTheCLI and
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI (qoder-cn): proc.Look
    keeps "not found" for a tool written in the tick of its folder's
    last change (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress (the
    package's only red), internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).
Not tried: Google's own endpoint with a key (the frames are Linka's, as
the repo keeps them), Cursor itself, macOS, Windows.
2026-10-24 21:33:06 +08:00
yetone 9a2106220c gateway: a background sub-agent's notification after tool results reaches the Claude run (stones_2026 on Discord)
Claude Code 2.1.310 runs Agent sub-agents in the background by default.
When one ends while the main agent is mid-turn, Claude Code tells its
model with a <task-notification> in a {role: "system"} message after the
tool results (several that end together share one text block), or as a
text block of the results' message. On the Claude subscription path
saidWithResults drops every system message that isn't the user's own
mid-turn words (#2060, c4f4aaaa9), and agentNotice matches
<task-notification> too, so the run's Claude Code got only the tool
results. Its model never heard the sub-agent finished and kept waiting.

withTaskNotices now appends each such notification to the last tool
result inside <system-reminder>, where Claude Code itself puts one when
a notification lands in a tool result. saidWithResults strips them
first; token counts and hooks' notices are still dropped, and the
user's mid-turn words still go through as theirs. The other two shapes
already got through: a notification after the main agent's reply (a new
turn) and one inside a tool_result string (what Sonnet 4.5 gets).

Captured with a real Claude Code 2.1.310 against a local fake upstream
in a sandbox HOME (no real account): the system message after the
results, the shared text block, and the notice beside the user's
mid-turn message.

Tests (internal/gateway/claude_task_notice_test.go):
TestClaudeTaskNotificationsGoOnWithTheResults (4 cases),
TestClaudeTaskNotificationBesideTheUsersMessage (5 cases: the user's
mid-turn message and the notification in one block, in both orders, in
a system message and in a reminder after the results, with and without
Claude Code's "IMPORTANT: ... address the user's message" line),
TestWithTaskNoticesLeavesOtherResults, TestClaudeTurnToldTheTaskNotification.
Broken by hand (call site passes the bare results, no stripping): all 9
cases of the first two fail, e.g. "the run was never told SUBRESULT-A
finished: call-1 was answered \"slept\"". Stripping alone turned off:
the two user-first cases fail, the notification written to Claude Code
as the user's words.

Run at this head, rebased on origin/main 83234fe92:
- gofmt -l internal: clean; go build ./...; go vet ./internal/gateway on
  darwin, GOOS=linux and GOOS=windows: ok
- go test -race on the new tests and the #2060 mid-turn/hook tests: ok
- go test -run 'TestClaude|Context' ./internal/gateway: ok (64.5s)
- guard packages internal/proc, internal/testenv: ok
Full gateway suite (-count=1 -timeout 45m, alone on the box): ok in
819.6s at 1dd279f69 (base e219f699c), with the first version of the
BesideTheUsersMessage test; the widened test was run on its own above
(-race -count=3 too). Not run again after the rebase onto 83234fe92
(gateway/gui context parts, no overlap with this file) because three
other sessions' suites were running; CI runs it at this head.

Not tried: a real Claude account; the other candidates for the report
(a lost stream tail, concurrent streams ending together) with a
concurrent fake upstream, since the captures show content being dropped,
not a cut stream; the Windows box; go test ./... beyond gateway and the guard packages.
2026-10-24 21:29:57 +08:00
yetone e219f699ca gateway: with no S3 bucket the request archive keeps calls on this computer, oldest removed past 1 GiB (CyberCaius)
CyberCaius on Discord: "请求存档只能存在 s3 存储桶里,不能保存在本地吗". The
Usage page's Request archive switch refused without an s3:// sync. Now,
with no bucket, the same switch keeps each call in
<settings.Dir()>/request-archive/<date>/<id>.json: the same file the
bucket gets, masked the same way (Archived, archiveRequest), written to a
temporary file beside it, synced and renamed, 0600 in a 0700 folder.
Past its size (RequestArchiveLocalMB, 1 GiB unless set) the oldest calls
go first, down to a tenth under it; the call just written is never
removed, empty day folders go, and a .part file an hour old is removed
on the next scan. The running total is counted once and then added to,
so a write walks the folder only once it is over.

On by default or a switch: a switch, still off unless turned on. Bodies
can hold secrets, so nothing is written to a disk where the user didn't
ask. The local switch is its own field, RequestArchiveLocal, in KeepOwn
with its size, so sync never turns it on at another computer, and
RequestArchive synced from a computer with a bucket keeps nothing on one
without (archiveDest). The GUI switch writes RequestArchive while sync
has a bucket and RequestArchiveLocal while it has none; the tooltip names
the folder and the size, and a failed write reads "Not saved" (en, zh,
zh-TW, ja, de). GET /api/archive reads this computer's copy first, then
the bucket. The Settings page's save keeps both fields (api.go).

Docs: sync-backup.md and gui-shell.md say where the archive goes and why
the switch is per computer; the privacy pages (en, zh, ja) say what the
folder holds, that it is off by default, and how large it grows. The
READMEs' Privacy is about what is sent and is unchanged.

app.js stays under TestCoreScriptBudget (its comment was shortened, and
one t() call folded); no budget raised.

Run (worktree diff on 5222a4b12, sandbox HOME):
- go test -tags nogui -count=1 ./internal/settings/ ./internal/gui/
  ./internal/gateway/: ok (29s, 73s, 507s)
- node --test request-archive, request-archive-usage, routing-bodies,
  gui-zh-tw, gui-ja, gui-de, i18n-keys (chromium and webkit): 37/37 pass
- gofmt -l internal/: clean; go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: clean; go build for darwin, linux
  (nogui), windows: ok
- TestCoreScriptBudget: ok

After rebasing onto origin/main 3840333c5: -run Budget|Archive|SaveKeeps|
RequestArchiveLocal in gui, gateway, settings ok; request-archive and
i18n-keys 8/8; gofmt clean; linux and windows vet clean.

Broken by hand, each red, then put back:
- archiveDest's local branch off: TestArchiveOnThisComputer red
- RequestArchive also writing to disk: TestArchiveNeverOnDiskUnasked red
- no pruning: TestLocalArchiveRemovesOldestPastItsSize red
- KeepOwn line removed: TestRequestArchiveLocalIsThisComputers red
- POST setting RequestArchive with no bucket:
  TestArchiveSwitchKeepsOnThisComputer red
- GET not reading the local copy: TestArchiveSwitchKeepsOnThisComputer red
- api.go not carrying the fields: TestSettingsSaveKeepsWhatItDoesNotSend red
- writing in place, not through temp+rename: TestArchiveOnThisComputer red
  (mode 0644, a .part left)

Not tried: the real app with a real agent's calls (the gateway tests
drive real requests through serve with a fake vendor); Windows' file
modes (0600 is skipped there); the full ./... suite before the push (the
machine had a queue of sessions' suites; it is queued after).
2026-10-24 21:01:18 +08:00
yetone b5d46acbed agent: Kiro Crew runs on a harness connected to magpie
Vincent on Discord asked for Kiro Crew (kirodotdev/KiroCrew v0.9.0: the
KiroCrew.app desktop app, the kirocrew CLI, its dashboard and the Gateway
on :5476). Crew has no model provider of its own. It runs each session on
an ACP harness picked by agent.acp_backend (and dispatched members by
agent.member_acp_backend) in $KIROCREW_HOME/config.json, default
~/.kiro/crew (src/kiro_crew/config/paths.py, loader.py, sections.py;
ACP_BACKENDS_MEMBER_DISPATCH in agent_sdk/backends.py).

Connecting sets those keys to an agent already connected to magpie,
tried in this order: Codex, Claude Code, OpenCode, Pi, Goose. One whose ACP
adapter is installed (codex-acp, claude-agent-acp, pi-acp) wins, so one
click is enough. magpie looks for the adapter where Crew does and installs
nothing; when it's missing, the notice gives the npm command. With no harness
connected the connect is refused with a message naming which agents to
connect. A harness set in config.local.json wins over config.json, so magpie
doesn't write it and the row says so. The previous values are stashed. On
Disconnect they are put back, but only for keys that still hold what magpie
wrote, and a file magpie created is removed once it's empty. The row reads as
connected only while its harness is still wired to magpie. deepseek is not
offered: Crew runs it as dsh --profile acp, which magpie's dsh wiring doesn't
reach. KIROCREW_HOME and the adapter path variables are read from the login
shell (agentenv).

Run (Go and the GUI files at base 137187a40, then again after the rebase onto 3d758d034):
- go test -tags nogui ./internal/agent ./internal/agentenv: ok, in a
  sandbox HOME
- gofmt -l is clean; GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/agent/... ./internal/agentenv/...: ok
- GUI: the new agent-kiro-crew-lang.test.cjs (refusals, notice and words in
  en, zh, zh-TW, ja and de; chromium and webkit; 1100 and 420px) 22/22. The
  agent*, gui-*, i18n* and header-relang files (45), concurrency 2 at load
  ~250: 632/633. The red was agent-models-own, chromium en 420, where the dsh
  row's model click timed out at 5s (#1666, filed). After the rebase that
  file and the new one, run alone: 38/38.
- After the rebase: go build ./...; the KiroCrew, Notice, FolderVars,
  EveryPicker and ListsModels tests: ok. go test ./internal/gui: everything
  passed except TestMainWindowCorners, which was killed at its 40s
  measurement at load ~200 (#1936, #2645, both filed; this change touches
  no window code).
- No go test ./... at the pushed head before the push: the machine is at
  load 200-300, other sessions are queued for the suite lock, and ships go
  out at once (owner, 10-22). Queued to run behind them at the pushed
  head.
- Real Kiro Crew: Crew v0.9.0 was installed from source into a sandbox venv,
  and its own loader (load_config_with_content_stamp, overlay_pins) read the
  config.json magpie wrote over the real Codex wiring in a sandbox HOME:
  acp_backend='codex', member_acp_backend='codex'. With a config.local.json
  pin it reads the pinned value and overlay_pins is True. Disconnect gave the
  user's file back as it was, and removed the file magpie had created.

Broken by hand, each red:
- restore off: Connect, PicksAHarness, HarnessPick, MakesItsFile
- the pin check off: LocalPin
- adapter preference off: PicksAHarness
- the member key always written: PicksAHarness, HarnessPick
- harness wiring unchecked in on(): FollowsItsHarness, OnRealCodexWiring
- the ja translation of the pinned refusal removed: the new GUI test, ja at
  both widths

Not tried: Crew's Gateway starting a real session through codex-acp
against magpie's gateway, and none of Crew's harnesses was run under it.
Adapter paths on Windows. A user who pinned agent.model to a kiro-only
model on a non-kiro harness.
2026-10-24 20:59:25 +08:00
yetone 7765f27fcc gateway: a model an account refuses goes on to the accounts not listing it yet
01huadalang (Discord): Antigravity with several accounts, only some can
use Gemini 4. The model and its bar showed only after the right account
was made preferred and probed, and a request failed with the preferred
account's error instead of going on to the account that serves it.
st3lland (Discord): on ZCode (plugin) accounts serve different models.
Owner: no manual setting, magpie knows per account and routes.

Two causes:
- perKeyBarred puts an account whose own saved list lacks the model in
  pl.unlisted / pl.left (Unlisted) and serve never asked it. So when
  the listing accounts refused the model (Antigravity's real 404
  NOT_FOUND "Requested entity was not found.", codeAssistModelMissing;
  plugins through modelRefused's unservedWords), the agent got that
  error even though an account whose list was simply stale serves it.
  Now, once every listing account of that subscription/model has been
  asked and one refused it as unserved (unservedTry), its unlisted
  accounts are asked next, right after it and before any other member
  or fallback (unlistedNext, askUnlisted for the trace). The refusing
  try rests as before (restAfterMarked, for that model). Not for a
  pinned account, a sealed conversation or strict affinity; a gateway
  key's account list narrows unlisted too (allowedCandidates). Other
  refusals (403 PERMISSION_DENIED, 429 RESOURCE_EXHAUSTED) don't open
  the unlisted accounts.
- Antigravity's per-account lists were refreshed only on the first
  listing, a probe, a sync or a Refetch, so a model granted later and
  its bar (chosenWindows filters by exposed models) stayed hidden. Its
  quota reading already fetches fetchAvailableModels per account; now
  it saves that account's list (noteAntigravityList) and re-merges the
  pooled list from every On account's list when it changed. An Off
  account's reading changes nothing.

Other vendors: the unlisted route only opens on the existing unserved
classifiers (Antigravity's 404, plugins' unservedWords), unchanged here;
TestUnlistedAccountNotAskedForOtherRefusals holds that the other real
Antigravity bodies don't open it.

Run (at the rebased head on origin/main 5222a4b12):
- go test ./internal/gateway -run TestUnlistedAccount (4 new) and
  ./internal/provider -run 'TestAntigravityQuotaReadingListsNewModels|
  TestAntigravityModelsAcrossAccounts': ok.
- Targeted: ./internal/gateway -run 'Unlisted|Antigravity|Fallback|Refus|
  Unserved|KeyModel|Lists|Plan|Rest' and ./internal/provider -run
  'Antigravity|Google|Gemini|Pool|Lists': ok (gateway 34.9s, provider 4.5s)
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- Full suite: queued behind three other sessions' full runs on this
  machine (load ~300); its result goes on this commit's follow-up, not
  claimed here.
- GUI: no asset changed; none run.

Broken by hand, each red, then restored:
- unlisted fallback off (false && unservedBy[key]): AskedAfterModelRefused
  404, BeforeFallback served a's fallback.
- unlisted appended after fallbacks instead of inserted: BeforeFallback red.
- key doesn't narrow unlisted: HeldFromKey got b's 200, want a's 404.
- quota reading keeps no list: QuotaReadingListsNewModels pooled list
  lacks Gemini 4.

Not tried: no real Antigravity accounts with and without Gemini 4 (the
404 body is the one on record from earlier reports); no real ZCode
"model not available" body is on record, so none was invented and ZCode
relies on modelRefused's existing words; the plugins repo is unchanged
(ZCode's models(provider,{auth}) already lists per account). Known
limit: a resting listed account that is the lone candidate is still
asked first on later turns until the unlisted account's list refreshes
at its next quota reading, one extra request a turn.
2026-10-24 20:32:33 +08:00
yetone 31275d0734 gateway: a history call to a tool the request doesn't declare gets a stub where it is refused (pi, T3 Code tool_search)
Gearclickist on Discord: pi and T3 Code, on magpie's /v1 chat/completions,
load tools on demand. The tools a tool_search found are called in the
history but not declared in the next request's tools, and pi sends
"tools": [] with history calls when it has no tools left.

Cause, per upstream (magpie forwarded the calls unchanged on every path,
seen in a probe through fakes):
- Anthropic Messages (API, Bedrock/Vertex Claude, relays): a call to a
  tool it isn't given is accepted, but calls with no tools at all get
  400 "Requests which include tool_use or tool_result blocks must
  define tools". anthropicBody dropped tools when the request had none,
  so pi's tools: [] turn failed. Now each tool the history called is
  declared as a stub (any object, "Called earlier in this conversation;
  not available now.") with tool_choice none, as LiteLLM's dummy tool
  and the Kiro plugin do.
- OpenAI Chat/Responses, ChatGPT backend, Gemini/Code Assist: take the
  history as it is; left as sent (TestUndeclaredHistoryToolTakenAsSent).
- Stricter Chat/Responses/Messages upstreams (relays in front of Kiro or
  Bedrock, vendors that check each call's name): a 400/422 that names an
  undeclared history tool as not found/unknown/not defined, or says tools
  must be defined beside the calls, is asked once more with a stub per
  missing tool, relayed or translated, and remembered per provider and
  API (historyToolsRefused). tool_choice none only where the client
  offered no tools. Namespaced Responses calls are left to the namespace.
- Claude subscription: runs real Claude Code with the history as text,
  not affected. Kiro plugin already stubs its history's tools.

Run, at 54874c9ee rebased on origin/main:
- the new tests and the gateway's ToolStrict/Anthropic tests: ok
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean (before the rebase)
- go test -tags nogui ./... -timeout 45m was running at the pre-rebase
  commit when this was pushed (ship-immediately); its result goes on the
  tag's report.

Broken by hand, each red, then restored green:
- the refusal matcher off: RefusedThenStubbed (chat, responses,
  anthropic) and ToollessHistoryRefusedOnChat red
- the remembered upfront stubs off: RefusedThenStubbed red (3 asks)
- anthropicBody's stubs off: ToollessHistoryToAnthropicDeclaresStubs red
- the stubs' tool_choice none off: same test red ("tool_choice \"\"")

Not tried: no real vendor was asked (fakes only); the refusal wordings
for stricter vendors are modelled, not captured from the reporter, who
named no upstream; the other community plugins' own translators
(Cursor, Devin, Qoder, ...) were not read for this; real pi/T3 Code not
run against this build.
2026-10-24 20:11:06 +08:00
yetone 48194bbee0 routing: an In order group's later members aren't said to go after a known allowance (bitssly on X)
bitssly on X (10-24) asked why, with a group set 按顺序 (In order), an
account whose quota isn't known "can't be used", quoting the Routing
page: "opencode:剩余额度未知,排在已知的之后。" and "腾讯-国际:剩余额度未知,
排在已知的之后。"

Cause: the gateway does what the mode says. planGroup/planLevel try an
In order group's members in the order given and never by what each has
left; each member's own accounts go as that member's provider routes
them (Smart by default, where an unknown allowance still comes before
any account at 90% or more and is tried when the known ones fail). The
explanation was wrong. weighed() gives an ordered group's rows their
member's routing (""), so the page's smart() judged each row against
every known row of the whole request: an In order group's later
members read as ranked behind a known allowance, and the first got a
Smart reason ("its allowance renews soonest ...") instead of In order.
A By weight group's first had the same fault.

Change:
- client.js: placeRouting/wholeMembers/weighedWith scope what a row is
  weighed against to its own member when the level that placed it takes
  members whole (order, weight). firstWhy says "In order: {who} is
  first ..." for such a group, and "By weight: it's {who}'s share ..."
  for a weighted one; the unknown, learns, spent and low asides are said
  only of an account weighed against another of its own member. Rebased
  onto 6d707af08 (Creat.wu, memberSplit): its member line now asks the
  scoped someKnown(x), so an unknown account alone in its member gets no
  line at all, and one beside a known account of its own member gets
  6d707af08's one line for the member.
- i18n.js: the By weight line in zh, zh-TW, ja, de.
- routing-order-unknown.test.cjs: In order, Smart and By weight groups
  over Codex (known), OpenCode Zen Free "opencode" (unknown) and two
  WorkBuddy AI accounts (one known, "腾讯-国际" unknown); chromium and
  webkit, en/zh/zh-TW/ja/de, 1100 and 420 wide.
- docs/reference.md: Smart's unknown account is still tried when the
  known ones fail; an In order group keeps its order whatever is known.

Why the quotas are unknown: OpenCode Zen Free is a free tier with no
allowance to report. Tencent Cloud Token Plan and Volcengine access-key
plans are read for the Usage page but not for routing; that class is
#3251. No plugin change.

Run:
- old client.js with the new test: red on the why line (chromium en/zh
  1100: "c@x.test goes first: of those with quota to spare, its allowance
  renews soonest ..." where "In order: c@x.test is first ..." was due).
- at the rebased head (origin/main 1f8f80e4a plus this):
  routing-order-unknown, routing-weight-member-low and i18n-* 64/64.
- go test -timeout 45m ./internal/gui/... at the rebased head: ok but
  TestMainWindowCorners (killed measuring windows at load ~80; red alone
  too; #1936, #2645, AppKit, not this change). Before the rebase: ok
  (112s).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. No Go file changed, so gofmt has nothing to check.
- whole GUI suite at ab287a839 (before the rebase), concurrency 4, load
  50 to 80: files a* to roughly o* ran; reds, all outside routing and
  filed: api-key-theme chromium system (#3307, also 1 of 3 alone),
  fonts webkit narrow (#3227), library-mcp-health-wsl ja (#3350),
  menu-input-scroll chromium en/zh (#3402). The rest of that run is void:
  my own rebase put conflict markers in client.js mid-run. The files from
  n* on are run again at the pushed head after this push.

Broken by hand: someKnown made global again (the old aside scoping):
red, the opencode aside is back under the In order group.

Not tried: the reporter's own trace and accounts (not shared); a Go
test for the gateway's order (unchanged here, covered by the existing
fallback tests); routing reading the access-key plans (#3251).
2026-10-24 19:09:41 +08:00
yetone 436bcc946d routing: a request whose vendor counts no cache tokens shows no hit rate, not 0% (zeewell on X)
zeewell on X: every Kiro request in a routing group showed cache 0%, for
claude-sonnet-5.5 and claude-opus-5.5 from Claude Code, with 148k to
182k tokens and consecutive calls.

The cause, from real Kiro calls on the owner's account (read-only, from
a sandbox): Kiro does cache. A repeated 900-line prefix cost 0.0912
credits and then 0.0484, with or without cachePoints, and with a fixed
conversationId too. But Kiro's reply holds only assistantResponseEvent,
metadataEvent {stopReason}, contextUsageEvent (a percent) and
meteringEvent (credits). There are no token counts at all, and
kiro-cli 2.32's own trace shows the same. The plugin wrote
cache_read_input_tokens: 0, which magpie showed as 0%.

opencode-kiro-auth 0.1.16 (plugins 9f6c4e8) now leaves the cache fields
out and says `magpie_cache_unknown: true`. This commit reads that field:
- aUsage reads it into Usage.cacheUnknown, ORed in Usage.add.
- routeUsage sets RouteUsage.CacheUnknown (cache_unknown, omitempty) on
  a try that counted no cache read or write.
- The Routing page's promptOf leaves such a try out of the hit rate. The
  row and its session then show no Cache metric, as for older history.

Clients are never told the field. Usage.anthropic() leaves it out, and
a passthrough forwards the plugin's bytes as they came. The gateway
already relays cache_control to an Anthropic-protocol plugin as Claude
Code sent it, so nothing was lost on the way to Kiro.

Left alone: the usage ledger. usage.Record has no such flag, so the
Usage page's aggregate hit rate still counts a Kiro prompt as a miss.
Filed as #3464.

Run at this head (rebased on origin/main 628e18987):
- gofmt -l internal/gateway internal/provider: clean.
- go vet ./internal/gateway ./internal/provider: clean on darwin, with
  GOOS=linux and with GOOS=windows.
- go test -timeout 45m ./internal/gateway ./internal/provider: ok, ok
  (465s, 126s).
- go test ./internal/gui -run Budget: ok.
- GUI: routing-request-metrics.test.cjs, chromium and webkit, en and zh:
  4 of 4 pass.
- Every routing-*.test.cjs, one base back, at load 130 to 150: the only
  reds were routing-intent-entry, routing-keys-fold and routing-manual.
  Run alone, those three files also go red on a fresh origin/main
  628e18987 worktree (8 reds there, 5 on this branch). They are already
  filed: #3408, #1612 and #3409. This change touches only promptOf's
  cache_unknown rows, which none of their fixtures have.

Broken by hand:
- With aUsage.usage() not carrying the field, TestCacheUnknownReachesTheRoute
  fails in its four Kiro cases (Claude Code whole and streamed, translated
  whole and streamed). The counted-miss case still passes, at 0%.
- With promptOf's skip removed, the GUI test fails in chromium for en and
  zh: "a vendor that counts no cache tokens has no hit rate, not 0%".

The test fixtures are the plugin's real reply bytes from Kiro, captured
10-24.

Not tried: a magpie build running the 0.1.16 plugin against Kiro from the
GUI. The plugin's own end-to-end run against Kiro gave
{"input_tokens":0,"output_tokens":19,"magpie_cache_unknown":true}.
2026-10-24 18:16:17 +08:00
yetone ef37b6fb76 gateway: an exhausted ChatGPT account no longer greys Codex app's Send while magpie can serve the turn (MasterYi on Discord)
MasterYi (#help, 1563467829687222343): with magpie wired into the Codex
app, a used-up ChatGPT account greys the Send button, so the third-party
models joined in Codex's picker can't be used either.

Cause, as far as the app's bundled code (ChatGPT.app 26.1013.40934,
read-only) shows: Send is gated in the app itself. It needs
authMethod == "chatgpt", the /wham/usage reading (fetched by the app
straight from chatgpt.com, not through magpie) saying not allowed, and
no credits. authMethod is read as the app opens or on account/updated,
which the app-server sends only on login/logout, not on a config change.
So the gate lifts only when model_provider is magpie AND the app has been
opened again. #540 already made magpie the provider while out, but only
when a magpie model was the default; on one of Codex's own models
(joined), nothing changed.

What changed:
- A (agent/codex.go Sync): joined on one of Codex's own models and the
  account out (not Always ChatGPT, not magpie API), magpie becomes the
  provider on that model as magpie serves it (codex/<model>), the model
  kept in codex.out_own. Once the account has room, Codex is put back
  joined on that model. A model picked meanwhile stays the user's. With
  no ChatGPT account in magpie to serve it, nothing changes. New
  Agent.AppOut says magpie is the provider for a used-up sign-in.
- C (provider/codex_app_out.go): a usage_limit_reached rest on the
  active Codex account (gateway routing) or an x-codex-* window heard at
  100% (NoteCodexLimits) has the account read again at once
  (CodexMayBeUsedUp: active account only, at most every 20s, only
  while a KeepOnAnAccountWithRoom loop has made its first reading and
  still runs), not only on the 5-minute look. A first cut turned this
  on for good as the loop started; every gateway test's Serve starts
  it, so later gateway tests had accounts read again behind them, and
  TestCodexOwnModelMovesToNextAccount and
  TestCodexSpentMovesToNextGroupMember went red in the package run
  (green alone 3 of 3). Now a counter, up after the first minute's
  reading, down as the loop ends; the package run is green with it.
- B (gui/codex_app_out.go): the app open when the account ran out is kept
  by its app-server's pid (provider.CodexAppOut; a new pid means it
  reopened and read the provider, standing in for "authMethod is still
  chatgpt"). On macOS, every 10s, magpie reopens it through the Agents
  row's ReopenCodexApp when: AppOut, the account still out, the app is a
  copy from before the config change, no turn in flight through the
  gateway and none ended in the last 30s. At most once per time the
  account runs out, success or not.
  Drafts: the app's code keeps composer drafts in a persisted store
  (composer-prompt-drafts-v2, 250ms debounce, flushed on quit), and
  threads are server-side, so an unsent draft and open threads should
  survive the quit. Not watched in a real app.
- D (GUI): Codex's accounts say "The Codex app can't send on {user}'s
  used-up account": on macOS that magpie reopens it once no turn runs;
  off macOS (no reopen path) or once tried, to quit and reopen it.
  en, zh, zh-TW, ja, de.

Tests (each red on the code without its part, broken by hand):
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp: red at "used up" with
  the out case off, at "allowance back" with the restore off.
  TestCodexOwnModelKeptOnChatGPT: Always ChatGPT stays.
- TestCodexMayBeUsedUpReadsAtOnce: red at "a window full: not read"
  with the NoteCodexLimits hook off. TestCodexAppOutEpisode.
- TestCodexUsedUpReplyAsksAtOnce (gateway): red, asked [], with the
  routing hook off.
- TestCodexAppOutReopenedOnce (gui, reopen stubbed): red at "a turn in
  flight" with the idle check off, and at "again" with the once checks
  off.
- codex-app-out.test.cjs: 40 of 40 (chromium, webkit; 900/480; five
  languages; both texts); 2 of 2 red with the notice's call site off.

What was run, at this tree:
- gofmt -l: none. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: exit 0.
- go test -tags nogui -timeout 45m: internal/agent ok (414s, before a
  comment-only reorder in Sync); internal/gateway ok (534s),
  internal/gui ok (78s), internal/provider ok (137s), after the
  live-check fix, at this tree before the previous commit's JS-only
  move (then with a budget raise since taken back); internal/gui
  again after the move.
- GUI (chromium, webkit), at this tree: codex-app-out, codex-app-stale,
  i18n-keys, gui-de, gui-ja, gui-zh-tw and the files reaching the
  previous commit's move: 164 of 164. Before the trim, every codex-*
  and account-* file: 447 of 448; the red, codex-predictions chromium
  ja 420 "picking a model scrolled the page", is #2624 and is red alone
  on origin/main 5a85a2a91 too (1 of 2); one codex-app-out case timed
  out launching chromium at load ~100 and passed on the rerun.
- TestCoreScriptBudget with the budgets unchanged: ok. The three Codex
  notices now share one box builder (codexNote), and the previous
  commit moved ledSaid out of app.js.

Not tried:
- No real Codex app was quit or reopened (the owner's live app is left
  alone); the reopen path is stubbed. Whether the reopened app's Send
  comes back, and whether a draft survives, is from reading its code.
- No real used-up account; the move was run in a sandbox HOME.
- The full suite: no suite lock on this machine, load ~75.
- A gateway served by another magpie process: the episode lives in the
  process that serves the gateway, so a GUI that doesn't serve it never
  reopens the app or shows the notice.
2026-10-24 17:38:50 +08:00
yetone 6d707af083 routing: a member behind another by weight or order isn't told as kept for last (Creat.wu)
Creat.wu on Discord (#general, 10-24): in a group routed by weight, a
sub-group whose accounts are all near their limit "is skipped however
high its weight". The screenshot is the Routing page's line
"<account> 已用 91%,其他账号都无法响应时才用。"

Cause: the routing itself already gives such a member its share.
weightedUnits leaves a unit out of the round only when its head is
resting; Smart's 90% band orders accounts inside the sub-group and
nothing in the parent reads it. A sandbox probe with the reporter's
shape (parent weighted, group/sb:4 with two Codex accounts at 91% and
92%, a key at 1) sent 16 of 20 new conversations to the sub-group and 4
to the key. What was wrong is the explanation. On a request whose turn
went to the key, the sub-group's accounts are listed after it, and the
page's asides (client.js) said of each one "used 91%, kept for when the
others can't", which reads as the member being passed over.

Change:
- client.js: memberSplit finds where a later account parts from the
  first one in the group tree. When that level is routed by weight (the
  first has the round's turn) or by order (no affinity kept, no rule),
  a low or not-yet-known account there gets one line per member instead:
  "{member} isn't passed over for being near its limit: by weight this
  request was {first}'s share, and {member} takes its own share of the
  requests while it can answer." or "... it comes after {first} in
  {group}'s order." Spent and resting lines are unchanged, and inside a
  Smart sub-group the low line stays, since the band does order those
  accounts.
- i18n.js: both strings in zh, zh-TW, ja and de.
- weighted_low_test.go: TestWeightedGroupGivesALowGroupItsShare holds
  the share (16/4 over 20, only the account with most left inside, and
  the sub-group's accounts behind the key not resting).
- routing-weight-member-low.test.cjs: weight, inner-Smart, order and
  plain Smart scenes, chromium and webkit, every language.
- gateway-routing.md: the weighted sentence says a unit near its limit
  keeps its share, and points at memberSplit.

Siblings: Smart, usage and pace parents weigh a nested group by its
head, so a low head goes later there by design and its line stays.
Manual picks a member and sorts the rest smartly (line stays). Rotate
is account-level.

Run (worktree at origin/main 7d9165d84; rebased on c30af359b, which changes
nothing under the routing plugin, weighted.go or fallback.go, and run
again there: go test ./internal/gui (budgets) ok, the new Go test ok,
routing-weight-member-low and i18n-keys 44/44):
- the new Go test -count=3 with the weighted tests: ok
- go test ./internal/gui/...: ok (112s)
- node --test routing-*, i18n-*, group-member-weight GUI files, both
  engines, all languages, at load 40 to 110: 1227 of 1285 pass. The 58
  reds are in the rule editor and manual and steady files
  (routing-pause, -rule-effort, -rule-remove, -intent-entry, -manual,
  -steady, -time, -rules-line, -busy-frames), all click timeouts.
  busy-frames and rules-line pass when rerun one at a time. The rest are
  red the same way on a clean origin/main 5a85a2a91 worktree, and are
  filed: #3408, #3409, #3410, #3411, #3412, #3094, #3096, and #3465
  (routing-time, new). routing-weight-member-low: 40/40.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: clean; gofmt -l on the changed files: clean
- go test ./internal/gateway/... -timeout 45m: ok (408s)

Broken by hand:
- weightedUnits with `|| heads[i].p.Account != nil` added to the skip:
  the Go test is red (0 of 20 to the sub-group). Restored.
- the old client.js: the weight and order scenes are red (10 failures
  on chromium), the inner-Smart and Smart scenes stay green.

Not tried: real accounts, or the reporter's own config (not shared);
the full ./... suite (another session's full suite held the machine).
2026-10-24 17:38:26 +08:00
yetone c8901d4723 gateway: auto mode's classifier asks a model of unknown levels for no reasoning
CyberCaius on Discord (#help): in Claude Code's auto mode every
classifier request ended 499 in magpie, on a new-api relay's
gpt6.1-sol (an OpenAI-compatible provider the user added), v0.1.1364.

Cause (likely; not confirmed against the reporter's relay): Claude Code
2.1.310 sends the classifier as a non-stream sideQuery, thinking off or
left out, 64 (or 2112) tokens, and waits 60s an attempt for it (WWt in
the bundle; 120s cap on large prompts). fitAutoModeClassifier asked for
the least reasoning only when magpie knew the model's levels. For a
relay's own name it sent no reasoning_effort / reasoning.effort, so a
reasoning model reasoned at its vendor's default over the whole policy
and transcript. That ran past Claude Code's wait, and Claude Code
closed the request (499).

Change:
- automode.go: with the levels unknown, the classifier is asked for
  effort none, marked as magpie's own ask (Request.OwnEffort).
- gateway.go forwardTranslated: a 400 to that own effort
  (ownEffortRefused) is asked again. If it named the level, it is
  asked at low (offRefused). If it named the field ("Unrecognized
  request argument supplied: reasoning_effort", "Unsupported
  parameter: 'reasoning.effort'"), it is asked without the effort, as
  before. Either is remembered in unfit until restart. Only the
  classifier gets OwnEffort, and no other request changes.
- docs/subsystems/gateway-routing.md: a bullet on the local
  classifier.

Run:
- TestAutoModeClassifierReasonsLeastOnAnUnknownModel covers Chat and
  Responses, non-stream, thinking off/64 and left out/2112. It is red
  on the old code: no effort was sent in any of the four cases.
- TestAutoModeClassifierEffortRefusedGoesWithout covers a named level
  going to low, and the Chat and Responses field refusals going
  without. Each next ask takes one request.
- TestAutoModeClassifierOnlyTheClassifier now expects none for unknown
  levels (the 7a3337dd2 decision, re-derived). It still checks that a
  title ask is untouched.
- gofmt -l is clean. go vet ./... passes on darwin, GOOS=linux
  -tags nogui and GOOS=windows.
- go test -tags nogui -timeout 45m ./internal/gateway/ (sandbox HOME, this
  tree on 9d6436311): ok in 541s.

Broken by hand:
- With the refusal branch off, both field cases go red.
- With the remembered-field check off, the next ask takes 2 requests.

Not tried:
- the reporter's relay or a real reasoning model's timing. The 60s
  wait is read from Claude Code's bundle, and no fake measures time.
- Sibling side queries (agent_namer, hook_prompt,
  subagent_config_classifier, titles) that send thinking off to such a
  model still leave reasoning to the vendor. They aren't recognisable
  as the classifier is, and the main turn shares their shape.
- Responses still drops the classifier's stop sequence. Its verdict
  regex reads <block>no without it.
2026-10-24 17:25:01 +08:00
yetone 3e9efe1d51 gateway: a Codex turn chatgpt.com's WebSocket refuses as too big goes over HTTP (Lamrfu)
Lamrfu on Discord, after updating: the Codex desktop app through magpie
kept showing "正在重新连接 2/5" with
  unexpected status 502 Bad Gateway: Codex: Post ".../backend-api/codex/responses":
  codex websocket: failed to get reader: received close frame:
  status = StatusMessageTooBig and reason = ""

Cause. a2e98cd79 (v0.1.1349) sends a streamed Codex turn to chatgpt.com
over its WebSocket as one message, the whole request body. magpie's read
limit is -1, so the 1009 close came from chatgpt.com, after our message.
Codex's own client (codex-rs core/src/client.rs at openai/codex 970111f,
get_incremental_items / previous_response_id) keeps its socket and sends
each later request as a delta after previous_response_id, so its
messages stay small; it sets no outgoing size cap of its own
(responses_websocket.rs websocket_config: tungstenite defaults plus
permessage-deflate), and after its retry budget it falls back to HTTP for
the session (responses_retry.rs, try_switch_fallback_transport). Codex
speaks HTTP to magpie (magpie answers its handshake 426), so magpie gets
the whole conversation every turn and opens a socket per turn. That the
server's message size limit is what Lamrfu's long conversation passed is
likely but not confirmed: the limit isn't in codex-rs and I don't know
its value. Before this change the socket's close before the reply was a
502, and Codex retried into the same 502.

What changed (internal/gateway/codex_socket.go):
- codexSocketEnded: when the socket ends, or the message's write fails,
  before any frame of the reply was handed on (any close status, a
  dropped connection, a normal close with no reply, also after only the
  codex.rate_limits / metadata frames), the same body goes over HTTP
  (t.next), which answers as the route does. Nothing has reached the
  caller then and the backend has begun no reply. This replaces the 502
  for 1009 and its siblings (1001, 1008, 1011, 1012, 1013, 1006, 1000
  with no reply).
- codexTooBig: a 1009 records the message's size for that host; a
  message at least that big goes straight over HTTP to it for
  codexSocketShun (10 min), so a long conversation isn't uploaded twice
  each turn. Smaller turns keep the socket. Logged once per host.
- A close after the reply began is still a cut stream and is not asked
  again (no double turn).
- No Codex prompt, instructions or identity is touched.
- docs/subsystems/providers-accounts.md says the new fallback.

Tests (internal/gateway/codex_socket_test.go), fake WS server, no network:
- TestCodexSocketTooBigGoesOverHTTP: the fake's read limit closes 1009
  on a big turn; the turn is served over HTTP, a second big turn doesn't
  open a socket, a small turn still goes over the socket.
- TestCodexSocketEndedBeforeReplyGoesOverHTTP: 1009 after the message,
  1009 after the limits frames, 1011, 1012, 1013, 1008, 1001, and a
  normal close with no reply: each served over HTTP.
- TestCodexSocketTooBigMidReplyIsCut: 1009 after response.created and a
  delta is a cut stream with no HTTP post.

Broken by hand: with origin/main's codex_socket.go, TooBig and all eight
EndedBeforeReply subtests go red with 502, the first with Lamrfu's own
text ("received close frame: status = StatusMessageTooBig"). With only
the codexMessageTooBig check removed, TooBig goes red ("2 posts, 2
sockets"). MidReplyIsCut passes on both (it guards against asking twice).

Run at this head: gofmt -l (clean), go vet ./..., GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./..., go build; go test -run Codex
-count=1 ./internal/gateway/ in a sandbox HOME: ok (30.2s), every Codex
test in the package. Pending: go test -timeout 45m ./internal/gateway/...
is queued behind the machine's full suites and runs after this push, as
the owner's ship-at-once rule asks; its result goes on the release.

Not tried: a real chatgpt.com turn big enough to be refused 1009 (the
limit isn't known); Lamrfu hasn't confirmed yet. Not run: the full ./...
suite (only the gateway packages this touches).
2026-10-24 16:15:28 +08:00
yetone ef1a203df9 gateway: an Antigravity account out of quota rests until the reset its 429 names, not 15 minutes (Dani Ariyanto)
Dani Ariyanto (Discord #feedback, 10-24): seven Antigravity accounts,
several ticked, one First, OpenCode on Gemini 3.8 Flash. With the First
account out, requests kept going to it instead of the next account, which
had all its quota.

Cause: Antigravity's 429 for a model's quota used up says when it is back
as a Go duration: "You have exhausted your capacity on this model. Your
quota will reset after 3h19m30s." (QUOTA_EXHAUSTED; the fixture
antigravityQuota, already in the tests since ea1c5d045). Nothing read
that form. The try was failQuota and the request failed over to the next
account, but the account rested only quotaRest (15 minutes). The
per-model window fetchAvailableModels gives is the 5-hour figure, so when
the weekly pool is the one spent, no window reads full either. Every 15
minutes for hours or days, the First account was asked again, refused,
and only then passed over.

What changed:
- routing.go: quotaResetAfter reads "quota will reset after <duration>",
  and resetsAfter returns it (beside Factory's "resets in ...") when it is
  above zero and no more than longestWritten. The rest is By "resets" for
  that long. As before, pooled decides whether the account or only that
  model rests. keepRetry passes it on as Retry-After when no account is
  left.
- docs/subsystems/gateway-routing.md: a bullet on the form.

Checked and not changed:
- Failover within one request already worked. A probe with two accounts,
  OpenCode's system prompt on /v1/chat/completions, streamed and not, with
  the literal 429, had u1 fail as quota and u2 answer 200. A per-model
  window the vendor reports at 0 (remainingFraction left out) benches the
  account until that window's reset after one try.
- Routing doesn't read the pool windows from retrieveUserQuotaSummary
  (Aside). That is unchanged.

Run, in a worktree at ed91aa04e:
- TestAntigravityQuotaRestsUntilItsReset is red on the old routing.go
  ("u1 rests 14m59.98s by "quota", not the 3h19m30s its quota resets
  after") and green with the change. It also checks that the next request
  asks only u2, plus reader cases: 45m2s, 26s, 155h2m1s, past 7 days (0),
  cut short (0), and the "check quota" 429 with no time (0).
- go test ./internal/gateway -count=1 -timeout 45m: ok (598s)
- go test ./... -timeout 45m: not run before this push. Another
  session's full suite was running here; it runs after the push.
- gofmt -l clean. GOOS=linux go vet -tags nogui ./... and GOOS=windows go
  vet ./... clean.

Not tried: a real Antigravity account out of quota (none spent locally),
so the 429's words come from the existing fixture, not a fresh capture.
RetryInfo's retryDelay detail isn't read.
2026-10-24 15:31:51 +08:00
yetone 1d6b72ada8 gateway: a search magpie runs for a model cites its pages in Anthropic text blocks (H20)
H20 on Discord (#general, 10-24): a client offering web_search_20250305
to auto/deepseek-v4.1-flash or deepseek/deepseek-flash got its text
blocks back with no citations, where Anthropic's API gives
web_search_result_location entries pointing at the
web_search_tool_result pages.

magpie's web_search tool asks the model to "Cite the URLs you use", so
the answer names pages by URL. After a KSearch event (or a Search part),
the Anthropic encoder and renderAnthropic now cut the following text
into lines (citer, search_cite.go). A line naming a found page's URL
whole (urlIn: not a longer path, a query or another host; Chinese
punctuation, markdown links and bold end a URL) is its own text block
with citations {type, url, title, encrypted_index, cited_text}; the
lines between run together in one uncited block, and whitespace-only
lines are held for the next, so no block is whitespace alone (Anthropic
refuses one sent back). Streamed, a cited block's citations_delta come
before its text_delta; text is buffered to the line end, only after a
search. The text is the model's, unchanged. A reply with no search is
said exactly as before.

encrypted_index is "", as the results' encrypted_content already is:
it is Anthropic's sealed pointer, which magpie can't make (Claude Code
2.1.310 knows "invalid encrypted_index in text block" and strips these
citations when that comes back). cited_text is Hit.Cited cut to 150
characters: a search API's page text, or the cited_text of an Anthropic
searcher's own citation (searchWith now reads it), else "". No prompt
text sent upstream changed; no Codex prompt touched.

Sibling filed: Responses and Chat replies still carry no url_citation
annotations (#3455). docs/subsystems/gateway-routing.md has a new
"Citations in translated Anthropic replies" section.

Run (at c579609d9 on ed91aa04e, sandbox HOME, pinned caches):
- go test ./internal/gateway -run 'TestSearchCitedAsAnthropics|
  TestNoSearchNoCitations|TestCitesOnlyTheWholeURL|
  TestWebSearchForAModelThatCannot|TestSearchToldAsAnthropics': ok
- go test ./... -timeout 45m -count=1: exit 0, 70 packages ok,
  internal/gateway ok 647s
- gofmt -l internal/gateway: empty; go vet ./internal/gateway,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
  go build ./...: ok

Broken by hand: with anthropic.go put back to main,
TestSearchCitedAsAnthropics/stream and /body both FAIL ("blocks [text
server_tool_use web_search_tool_result text]": one text block, no
citations); restored, both pass. TestNoSearchNoCitations holds a reply
with no search to one uncited block, streamed and whole.

Not tried: a real DeepSeek model through a running magpie (whether it
writes the URLs the tool asks for, and how often); a real Anthropic API
taking such a reply back in history; [n] markers (a search API's
numbered pages) are not matched, since numbers repeat across searches.
2026-10-24 15:31:05 +08:00
yetone ccbbcbffcb gui: a restart to update leaves the Mac's menu bar icon for the next magpie (Mitsuha, audie)
From v0.1.1354 a restart to update hands the gateway over, and the old
magpie hides its own menu bar item with Wails' Hide, which is
[statusItem setVisible:NO]. AppKit keeps that in the app's defaults by
the item's autosave name ("NSStatusItem VisibleCC Item-0" = 0 on macOS
26), and the next item made under that name starts hidden. So after the
update the icon was gone, and quitting and reopening didn't bring it
back (Mitsuha on v0.1.1364; audie on two Macs, macOS 27.0.1).

Evidence: a 30-line Cocoa probe made a status item, setVisible:NO, and
every later launch of the same program started with visible=0 and the
key = 0; removeStatusItem kept nothing; removing the key brought it back
on the next launch. This machine's com.yetone.magpie.sbhandover.plist
(the handover commit's own sandbox run) holds
"NSStatusItem VisibleCC Item-0" => false.

Fix (internal/gui/trayshown_darwin.go, app.go):
- leaveMenuBar (was the onHandedOver closure) queues forgetTrayHidden
  on the main thread after Wails' hide block, so the hide is made on
  screen but not kept.
- bringTrayBack, once per computer (a flag in the Mac's defaults, never
  in a WebDAV backup), forgets a kept hide before the tray is made: that
  repairs everyone an older magpie already hit. A hide kept after that
  is the user's and is left alone.
- A magpie handed over to by an older one (which still hides for good)
  forgets the hide once that pid has quit and shows its item, unless a
  hide was already kept when it started.
docs/subsystems/gui-shell.md says so under the handover.

Run (worktree at origin/main ed91aa04e):
- TestHandoverLeavesTheMenuBarIconForTheNextMagpie (AppKit child with a
  real Wails tray, CFFIXED_USER_HOME sandbox): ok, -count=3.
- Broken by hand: leaveMenuBar without forgetTrayHiddenLater -> "handing
  over kept the menu bar icon hidden for the next magpie (1 kept)";
  bringTrayBack without forgetTrayHidden -> "the icon an older magpie hid
  wasn't brought back (still hidden true, 1 kept)".
- go test ./internal/gui/ -count=1: ok 86.7s; go test -tags nogui
  ./internal/gui/: ok 67.2s.
- gofmt -l: nothing. go vet ./internal/gui/ (darwin), GOOS=linux go vet
  -tags nogui, GOOS=windows go vet: ok. go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.
- No GUI asset changed, so no Playwright run.

Not tried: a real signed update from v0.1.1367 to this build on the
user's bundle id; whether Control Center hides the new version's running
item live when the old one writes the key (the probe's running item kept
visible=1; the on-screen window list needs screen recording rights). Not
run: the full go test ./... (one package touched; other sessions are
queued for the suite). audie's WebDAV sync carries no tray setting and
doesn't restart magpie; the icon going there is taken to be the same
update's restart, not confirmed with them.
2026-10-24 15:20:37 +08:00
yetone ed91aa04ef checkin: an inactive or ineligible check-in shows the plugin's reason (plugins#304)
Qoder's plugin 0.2.32 (magpie-community/plugins 74be632) says why no
check-in was offered: it asked with this machine's own device identity
and Qoder offered no campaign, and Qoder desktop can claim one it shows.
magpie dropped a hook's message for inactive and ineligible and showed
only "No check-in event now". Now:

- GUI: the Usage card's row reads "<label> · <message>", wrapped under
  the label rather than cut off with "…" (data-why, as a failed row's
  reason wraps, #821); Settings' check-in line under the plugin's switch
  carries it too. A result without a message reads as before. No new
  i18n keys: the message is the plugin's own text, as for failed rows.
- TUI: the Usage cell is too narrow, so it adds "c says why"; c's flash
  carries the message (checkinWhy).
- CLI: `magpie accounts checkin` prints it after the label.
- The Qoder mover's min is 0.2.32 (npm view --prefer-online: 0.2.32).
- docs/subsystems/provider-plugins.md says how the message is shown.

Run at this tree (based on origin/main dd1e8822d):
- go test -timeout 45m ./... (tee'd, grepped): every package ok
  but internal/handoff, whose TestTakeOnlyAFreshOfferForThisProgram
  could not bind a unix socket under my long scratch TMPDIR (path over
  104 bytes); with the default TMPDIR internal/handoff is ok.
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean.
- GUI, chromium and webkit: checkin-reason (new: en, zh, zh-TW, ja, de;
  900 and 440px), plugin-checkin, qoder-checkin-recheck, usage-checkin,
  checkin-account, checkin-early-done, usage-quota-head, i18n-keys:
  155/157. The 2 reds are usage-checkin's "webkit en/zh: Settings has a
  Qoder check-in tab", red the same on a fresh origin/main a9a001a7a
  (#2549, #3091).
- TestCoreScriptBudget: app.js 1,343,313 of 1,343,324, no raise.

Rebased on origin/main 4683a0382 (a9a001a7a's app.js line, 4683a0382's
provider change) and run again at this head: internal/gui (budget:
1,343,323 of 1,343,324), internal/cli, internal/tui and the whole
internal/provider ok; the same 8 GUI files in both engines, 155/157,
the same two #2549/#3091 reds.

Broken by hand: app.js's change reverted, checkin-reason goes red on the
reason; app.css's reverted, red on the wrap; checkinWhy returning "" in
internal/cli and internal/tui, TestCheckinSaysWhyNoneWasOffered red in
each.

Not tried: a real Qoder account offered no campaign (the fixture is the
plugin's own text); the real Linux app (WebKitGTK).
2026-10-24 14:52:13 +08:00
yetone a3b45eb91e provider: a re: pattern matches in any case, as a glob does (usrname1833 on Discord)
A routing group's patterns (Group.Match) and a provider's auto-include
rules both compile through compilePattern. A glob compiled with (?i)
and a re: pattern without it, so re:gpt-.* missed GPT-5.5 while gpt-*
took it. A re: pattern now compiles as (?i)^(?:…)$; (?-i) inside it
makes case matter again from there on (re:(?-i)gpt-.*).

The Routing page's editor works out a pattern's models in JS
(patternRe in plugins/routing/client.js) and refused what JS can't
read. It now reads re: with the i flag too, and takes Go's leading
flag group ((?-i), (?s), ...) as JS flags, so re:(?-i)OR/B is taken
and matches as the gateway will. A flag group further in is still
refused there (JS has no bare (?-i)); the CLI takes it.

Said in groupmatch.go's comments, magpie group's and magpie provider
auto-include's help, and providers-accounts.md (Routing groups, List
schedule and rules). No GUI hint said a pattern's case, so none
changed and no string was added.

Run:
- TestRegexpPatternIgnoresCase (new): ok. With compilePattern's (?i)
  taken off by hand: FAIL, "re:GPT-.* ~ gpt-5.5: false, want true" and
  three more cases.
- group-patterns.test.cjs, chromium and webkit, en and zh: 4 of 4 ok.
  With patternRe put back to the old re: line by hand: 4 of 4 red,
  "(?-i) keeps case 0 !== 1" (old JS refused re:(?-i)OR/B).
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean.
- go test -tags nogui -timeout 45m ./internal/provider ./internal/cli
  ./internal/gateway under a sandbox HOME at 1a956129c's tree: ok,
  ok, ok (380s). go build for darwin, linux (nogui) and windows: ok.
- A full ./... run was started and stopped: the machine's disk was
  full (1GB free), and internal/agent's tests failed on "no space
  left on device" in TempDir, not on this change. No full suite ran.

Not tried: the full suite (above); a real provider's auto-include fetch with mixed-case ids;
the Linux app's WebKitGTK; a (?-i) further into a re: in the GUI.
2026-10-24 07:07:57 +08:00
yetone edff2f819a provider: levels kept of a model's own narrow only what is offered again (#92)
4a3e07f1c made provider.Efforts return the levels a user kept, so the
gateway fitted every request to them. That reversed #92 (47e12df41),
which was explicit that narrowing a model's levels changes only what is
shown and "the levels the vendor is asked at stay as they were": a user
who had trimmed a picker with `magpie model efforts` or Names & levels
would have had their agents' xhigh and max asks lowered unasked. Dani's
request (magpie model spec) needs levels to count only where magpie
knows none for the model.

- Efforts is back to what it was before 4a3e07f1c: the vendor's list's
  or models.dev's levels when known, else the ones the user declared
  (`magpie model spec --reasoning` on a custom provider's model), which
  a request is then fitted to. --reasoning off (reasonless) is as
  4a3e07f1c built it.
- TestModelEfforts' "the vendor is still asked at any level it has" is
  restored as it was.
- TestKeptLevelsBoundTheAsk becomes TestNarrowedVendorLevelsAskAsBefore:
  a models.dev-known model narrowed to low-high is offered low..high and
  still sends xhigh, max and low as asked.
- gateway-routing.md, reference.md, the settings.go comment and spec's
  usage say so: narrowing is display-only, declared levels are fitted.

Run at this tree (base 4a3e07f1c):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/provider
  ./internal/cli ./internal/settings: ok (gateway 386s).
- gofmt -l empty; go vet darwin, linux -tags nogui, windows clean.
- Broken by hand, each red: 4a3e07f1c's Efforts (TestNarrowedVendor-
  LevelsAskAsBefore: xhigh and max went as high; TestModelEfforts:
  [low high]); declared levels ignored (TestModelSpecReachesTheGateway:
  xhigh sent as xhigh with low-high declared).
- Every other p.Efforts caller (gateway fit, decide, classify, automode,
  rules, side effort) is on the request path and is back to its
  behaviour before 4a3e07f1c.

Not run: the GUI suite (no GUI file changed; the GUI reads entry
Efforts, which still carry the kept levels) and a full go test ./....
2026-10-24 05:51:22 +08:00
yetone 4a3e07f1cf model: magpie model spec sets a model's window, output, vision and levels at once
Dani Ariyanto on Discord (#feedback, 10-24): a custom provider's models
(kenari/*:free) had no window, reply limit, vision or reasoning known,
and there was no one place to say them.

  magpie model spec <provider/model>                 what it has, and whose each value is
  magpie model spec <provider/model> [--context <n>] [--output <n>] [--vision on|off|auto] [--reasoning <levels>|off|auto]
  magpie model spec '<provider>/*' --context <n> --output <n>
  magpie model spec <provider/model> --reset
  magpie model specs

It writes the stores magpie model context/output/images/efforts write
(providers.json contexts; settings.json modelOutputs, modelImages,
modelEfforts, modelReasonless), so every reader that went by those goes
by a spec: entryFor/EntryOf/Served, /v1/models, max_tokens, the GUI's
/api/providers badges and chips, and the agents' model lists. Every
part is checked before anything is written; a refused command writes
nothing. Agents are told once.

Readers that bypassed the stores and now honour them:
- provider.Efforts returns the kept levels, so the gateway fits a
  request to them (fitEffort): xhigh asked of a model kept to low-high
  goes as high. This reverses #92 (47e12df41), which narrowed only the
  lists handed out; docs/subsystems/gateway-routing.md says so.
- entryFor: levels given a model with none known make it Reasoning.
- gateway AutoVision picks by the user's ModelImages (seesAt).
- GUI gateway client: a reasonless model offers no level chips.

Run at this tree (base a93190ae1):
- go test -count=1 -timeout 45m ./internal/{provider,cli,gui,gateway,
  settings,tui,agent,catalog}: all ok (gateway 505s, agent 360s).
- GUI: gateway-*.test.cjs, model-reasonless, plugin-gateway, i18n-keys
  (25 files, both engines, the new file at 1100 and 420 in en, zh,
  zh-TW, ja, de): 225/225 pass. app.js untouched.
- gofmt -l empty; go vet darwin, linux -tags nogui, windows clean.
- Sandbox HOME, built binary, `magpie web` on 47821/47820 and a fake
  Chat vendor on 47811: before, kenari/glm-5:free had no window or
  levels; after spec 128k/16k/on/low-high, /v1/models said 128000,
  16000, image input, [low medium high]; max_tokens 100000 went as
  16000, xhigh as high, low as low; qwen-x with --reasoning off was
  sent no reasoning field; /api/providers had context 128000, output
  16000, images/imageSet, kept [low medium high], reasonless for qwen-x.
  A models.dev sync during the run (GLM-5 202752/131072) didn't move
  the spec; after --reset the vendor's values came back. Bad values,
  an unknown flag and --help wrote nothing (files hashed).

Rebased onto a6a3dbde8 (the ZCode mover's min, one line): at the
pushed head 5af093d8b's tree, ./internal/provider and ./internal/cli
-timeout 45m ok, and the spec tests in gateway and gui ok.

Broken by hand, each went red: AutoVision on raw sees; Efforts on the
full list; the Reasoning line removed; output, vision or context not
written; ParseLevels skipped; agents told twice; --context 0 taken;
help printing modelUsage; old client.js; the GUI named() image and
reasonless branches.

Not tried / not changed: no full go test ./... (another session's
full GUI suite was running). Codex's ChatGPT-model /models pass-through
and the Codex effort dropdown read catalog.Codex(), not a spec. The
TUI shows no spec badges. A Context-tab trace keeps the window it was
recorded with. Pre-existing and the same on origin/main a6a3dbde8: a
GLM-5 relay with no levels known has xhigh sent as high.
2026-10-24 05:31:59 +08:00
yetone ea9454d2d8 usage: count two ids of one model as one, magpie model alias (SlouchyQuill507 on Discord)
A vendor names one model two ways (deepseek-v4.1-flash and deepseek-flash),
and Usage, Usage > Sessions and `magpie usage` showed two rows. Now:

  magpie model alias deepseek-v4.1-flash deepseek-flash
  magpie model alias deepseek-v4.1-flash            (what it is counted as)
  magpie model alias deepseek-v4.1-flash --reset
  magpie model aliases

kept as settings.json "usageAliases" {from: to}. Off until one is written.
Ids match as routing groups match them (provider.sameModel: vendor/ prefix,
case, "_", snapshot date), at every provider; a chain is followed to its
end; an alias to itself, a loop, or a flag as an id is refused. A loop
written into the file by hand counts each model under its own id.

Display only: requests, agents' model lists, /v1/models, routing groups,
Same as and prices never read it. Each call is priced by the id it was
made under and only then counted under the alias; the alias's own price
is never put on the other id's calls, and a merged row is priced only
when every id in it is. Applied in usage summarize/direct (Models
groups), the gateway sessions projection (alias read before
gatewayCache's lock; the cache key hashes usageAliases), and
sessions.List/Get/Find/Stats (read before storeMu/mu, merged into new
slices so the memo is untouched; ModelEffort rows merged too). A failed
settings.json read keeps the last aliases read, and SetUsageAlias refuses
to write over an unreadable file (EditUsageAliases under fileMu). The GUI
settings save carries usageAliases. No GUI control.

Not aliased: the Requests ledger's per-request model and its model
filter, which show each call's own id.

Run (worktree at f4640c0ae, rebased onto 2b4c0664e with no overlap):
- gofmt -l: clean. go vet ./... darwin, GOOS=linux -tags nogui, GOOS=windows: ok.
- go test -count=1 -timeout 45m (sandbox HOME) internal/usage,
  sessions, provider, cli, settings, gui, tui: all ok.
- Real binary in a sandbox HOME: two usage.jsonl calls priced $2 and
  $100 per M: `magpie usage` showed two model rows ($2.00, $100), and
  after `magpie model alias` one row, 2.0M, 2 calls, $102; the session
  row too. alias/aliases/--reset/loop/self output checked by hand.

Broken by hand, each red then restored:
- no alias in summarizeFrom: TestUsageAlias* red
- nil alias into the gateway projection: TestUsageAlias* red
- statsIn without aliasStats / List without aliasSession:
  TestSessionsCountAliasedModelsAsOne red
- merged usage row keeps Priced true: TestAliasStatsLeavesItsInputAlone red
- loop check off / self check by == / last-good read off / flag check off:
  TestUsageAliasRefusesSelfAndLoops, TestUsageAliasUnreadSettings,
  TestModelAliasCmd red
- GUI save drops UsageAliases: TestSettingsSaveKeepsWhatItDoesNotSend red

Not tried: the GUI pages in a browser (no app.js change; the Usage and
Sessions pages read the same rows), the full go test ./... before push,
Windows box.
2026-10-24 02:48:50 +08:00
yetone f4640c0aee sessions: an agent's folders are one list, newest first, the temporary ones folded at the end
The Sessions page drew each folder as a boxed group with its checkbox,
path and buttons always showing. Now it is one list, the way Finder's
recents read: a row says the folder's name, where it is (home as ~, from
the manage reply's new `home`), its newest session's title, when, and how
many. Temporary folders, the disk's root and apps' hidden folders under
home wait folded under Other folders at the end; a search or a session
opened from elsewhere unfolds them. Checkboxes and the Delete bar come
only with Select, and Done lets the pick go. Relocate project and Delete
all sessions move into a folder's ⋯ menu (hover, always on touch, and
right-click); Delete all asks in magpie's own dialog.

Asked for by the owner ("这个会话页面其实特别丑"), who approved the design.

Tests: sessions-folder-list.test.cjs (new) checks the order, the ~ path,
the fold and its count, Select/Done, the ⋯ menu's Delete all and its ask,
and no horizontal scroll, in Chromium and WebKit, en/zh/zh-TW/ja/de, at
1000 and 420px. The other sessions tests follow the ⋯ menu and Select.

Run at this head (rebased on 17a2b00ef):
- node --test, 37 GUI files (every sessions*/session*, i18n*,
  checkbox-look, account-mask-sessions, routing-session*,
  usage-session*): 493 pass, 0 fail.
- gofmt -l internal/gui: clean; go vet -tags nogui ./internal/gui: ok;
  go test -tags nogui ./internal/gui: ok (budgets included).
Not run: the whole GUI suite at this head. The last full run (183fa169b,
10-23) had its reds filed (#3402 to #3416 and earlier issues); none is a
sessions file. Not tried in the Wails window on a real machine's sessions.
2026-10-24 02:31:17 +08:00
yetone 17a2b00efb gui: the sidebar's open page moves from row to row on a spring, as iOS's selection does
The owner asked for the sidebar's pages (Providers, Routing, Gateway…)
to slide from one to the next like their sub-tabs do, "like iOS".

The open page's row is now marked by one shape (.nav-top-hl) that
navTopGo moves on a damped spring (NAV_SPRING: SwiftUI's response
0.42s, damping 0.84; navTopStep, four sub-steps a frame, dt capped):
- it sets off as the row is pressed, and comes back if the press
  leaves the row or the page refuses to be left;
- being physics, a press that changes its mind turns it with the speed
  it has, never a jump;
- it follows its row while Usage's tab list folds above it and lands
  where the row ends up;
- it is put in place, not sent, when the window opens on a kept page or
  the rows move under it at rest (ResizeObserver); away while Settings
  is open, it fades back in on its row; reduced motion jumps; the
  header's tabs keep their .thumb and draw none.
The rows give up their own ground (open, hovered, pressed) to it.
#nav is position: relative in the sidebar for it, so .seg's centring
left/top are reset (without that the whole list sat 105px right).

Tests:
- sidebar-glide.test.cjs (new): Chromium + WebKit, en + zh, 1024 and
  1440, plus 900 (header): at rest on its row and the list in the
  sidebar, no ground hovered, press sets off before release and comes
  back off the row, Providers→Usage→Agents by frames (≥3 moving
  frames, overshoot < 3px) landing on the row, Settings hides it and
  Routing brings it back, reduced motion jumps, no page errors.
  Broken by hand: without the left/top reset the list check goes red;
  before the "not seen yet" rule the boot slid from Agents (red).
- sidebar.test.cjs: a pressed page row no longer darkens itself (the
  shape comes to it); Settings still must.
- routing-idle-frame.test.cjs counted every self-asking rAF callback as
  Routing's loop, so navTopStep after the click read as 33 Routing
  frames. It now counts only callbacks no global holds (app.js's are
  globals; Routing's frame is in its plugin's scope). Broken by hand:
  Routing's loop made to always ask again → 4 red; green on main's
  assets and on this change.
- TestCoreScriptBudget: app.js 1,343,324 / core 1,535,084 with no room
  added; the sidebar is the window's shell, not a page a plugin can take.

Run:
- Full GUI suite at 183fa169b (this change on 3b10a403d), alone on the
  machine but at load ~216: 11942 pass, 104 fail. The 25 red files
  rerun at load ~10 on this change and on 3b10a403d: the same reds on
  both except routing-idle-frame (fixed above); plugin-card-update,
  segment-press-dialog and sidebar-overlay-scrollbar pass alone here
  (segment-press-dialog red alone on main: #3416). Reds on main, filed:
  #3402 #3403 #3404 #3405 #3406 #3407 #3408 #3409 #3410 #3411 #3412
  #3413 #3414 #3415; already filed: #3350 #3099 #3096 #3094 #3091
  #3104 #3001. codex-predictions and codex-auto-reset were red only at
  load ~216 and passed in both reruns.
- At the pushed head (rebased on f3eb92924): sidebar, sidebar-glide,
  nav-sub-unroll, side-toggle, side-width, header-relang,
  sidebar-tab-top, settings-tabs-stick, omarchy,
  sidebar-overlay-scrollbar, click-scroll, routing-idle-frame,
  plugin-card-update, segment-press-dialog, i18n-keys: 230/230;
  go test -tags nogui -run 'TestCoreScriptBudget|I18n|Docs'
  ./internal/gui: ok; gofmt -l clean.

Not tried: the real Linux app (WebKitGTK); this uses only rAF and
transforms, no view transition. Not run: the full Go suite (only
internal/gui's budget/docs tests; no Go code changed).
2026-10-24 02:21:45 +08:00
yetone a95f0b83ff gui: a restart to update hands the gateway to the new version (xuanwo on X)
Before, a restart to update ended the gateway, so it waited until no
agent request was in flight (#577). An agent busy for hours held the
update back, and Restart now cut its replies off. On a Mac and on Linux
the restart now starts the new version beside the old one and hands it
the gateway's listening socket. The new version takes every new
connection at once. The old one stops accepting, finishes the requests
it has (up to 15 minutes, as `make dev` already gave), then quits.
Nothing an agent sends is refused or cut short.

How (docs/subsystems/gui-shell.md, "A restart to update hands the
gateway over"):
- internal/handoff, new, darwin and linux. The old magpie opens a unix
  socket in a 0700 temporary folder and writes handover.json (fresh for
  2 minutes) in its config folder. The new one finds it, says Hello, and
  gets the listening socket by SCM_RIGHTS with the address, its pid and
  a callbacks socket. Only the same program (same path, same uid) is
  given it. When TMPDIR is too long for a socket path (sun_path is 104
  bytes on a Mac), the folder goes in /tmp (sockDir).
- gateway: Inherit/Listen serve on the socket given, and acknowledge
  once serving. HandOff gives the old one handedOffDrain (15m) instead
  of the 2s an ordinary end gives. A Claude Code run of the old magpie
  whose helper calls its tools on the port gets those calls passed back
  to the old one over the callbacks socket (forwardCallback, mcpCall,
  ownCallback). The bridge's turns are counted on their own
  (Busy.Bridge, BridgeLast).
- gui: restartInto calls beginHandover (OpenBeside `open -n` on a Mac,
  StartBeside for the binary on Linux). On the new version's ack, the
  old one hides its menu bar icon, panel, window and Dock icon (Mac),
  ends its backend, waits for its requests, and quits. OnShutdown
  leaves Codex's failover, the thread port and the install to the new
  one, which serves the gateway they point at.
- Never two on screen. Mac: the old one lets go of its instance lock
  just before giving the socket and takes it back if the handover
  fails, then hides on the ack. Linux: Wails holds the D-Bus name until
  exit, so the new one serves the gateway at once but puts its tray up
  only once the old pid has exited (awaitExit, 16m at most). Until
  then the old tray stays.
- What a handover can't carry: the subscription bridge's Claude Code
  turns live in the old process, so the restart still waits for those
  (restartBusy = blocking(Busy, true)), along with turns parked on
  tools. Every other request is not waited for. The update badge, the
  Updates page and Settings' "Restart automatically" say so, in every
  language in i18n.js.
- A handover that isn't made restarts as before: socket not opened,
  new version not started, no hello in 60s, no ack in 90s. Because the
  restart didn't wait for the requests in flight, it now waits for
  gatewayBusy to be idle (fallbackWait, 15m at most) before it quits
  and relaunches, so a failed handover never cuts a request.
- The overlap. The instance lock is handled as above. Both processes
  write: the sticky routing is flushed before the hand (FlushSticks),
  and files go through the existing locked or atomic writes. Counters
  (RPM, concurrency) are per process for the overlap (gateway-routing
  Constraints). OAuth refresh: the previous commit locks Codex's and
  the ChatGPT API's refreshes across processes. The rest were already
  locked or don't rotate (providers-accounts Constraints).
- Not changed: Windows (no SCM_RIGHTS; it restarts as before and still
  waits for idle, #577), `magpie web` (re-execs in place), and
  `make dev` (its own Handover). MAGPIE_NO_HANDOVER=1 turns it off.

Found by the sandbox run, fixed here: in run 2 the sandbox's long TMPDIR
made the socket bind fail ("bind: invalid argument"). The restart fell
back at once, cut the stream at chunk 6 (curl exit 18), and 4 of 381
requests got no answer over ~2s. Two fixes: sockDir (/tmp fallback), and
the fallback that waits for idle.

Tests (each red when broken by hand or on the old code):
- gateway/handover_test.go: TestHandedOverGatewayFinishesItsStream
  (drainFor without handedOff: "the old one ended with a stream in
  flight"; takeAck off: "the new one never said it serves").
  TestToolCallOfTheMagpieBeforeGoesToIt (mcpCall forward off: 404;
  ownCallback forwarding off: 401). TestInheritedForAnotherAddressIsLetGo,
  TestCallbacksSocketServesOnlyToolCalls, TestBridgeTurnsCount,
  TestSameAddr.
- handoff/handoff_test.go: TestHandOverListener, TestNoAckKeepsTheSocket,
  TestTakeOnlyAFreshOfferForThisProgram, TestCloseRemovesOnlyItsPointer,
  and TestOpenWithALongTemporaryFolder (red on the old Open: "bind:
  invalid argument").
- gui/handover_unix_test.go: TestRestartHandsTheGatewayOver, cross-
  process. The test binary re-execs as the new magpie. A stream through
  the old one finishes whole, requests during the restart are all
  answered, the next ones reach the new pid, and the old one quits only
  after its stream. On the old restart it is red: "quit with a reply
  streaming". TestHandoverNotMadeRestartsAsBeforeOnceIdle ("never says
  hello", "doesn't start") is red on the code before the fallback
  drain: "quit with a reply streaming" / "the restart didn't try to
  hand over".
- gui/handover_test.go: TestRestartWaitsForWhatAHandoverCantCarry,
  TestHandsOverOnlyWhereItCan.
- update/relaunch_open_test.go: TestOpenBeside,
  TestStartBesideWaitsForNothing.
- GUI: update-wait.test.cjs (the handover wording on the badge and
  page), update-restart.test.cjs (Settings' description).

Real run, Mac, sandbox (env -i, HOME and XDG_CONFIG_HOME in a scratch
folder, a long TMPDIR, MAGPIE_ADDR 127.0.0.1:63249, MAGPIE_UPDATE_FEED
pointed at a fake feed). The app is -tags production, ad-hoc signed,
bundle id com.yetone.magpie.sbhandover, built as 0.1.9001 and 0.1.9002.
autoRestart is on. A fake upstream streams 100 one-second chunks. The
real app found the update, downloaded and staged it, and restarted with
the stream in flight (run 3, at this change's tree before the rebase):
- 18:31:43, pid 59833 serves. 18:31:51, the new pid 60477 serves; v1
  logged "magpie 0.1.9002 (pid 60477) serves the gateway now".
- Requests: 375, failed 0. 19 were answered by 59833, then 356 by 60477.
- The stream got all 100 chunks, END and [DONE] at 18:33:24, curl exit
  0, 92s after the hand. 59833 exited within 3s of the stream's end.

Run at the pushed head (7a5bca443's tree, on origin/main f3eb92924),
one suite at a time, each log tee'd:
- gofmt -l internal/ cmd/: none. go vet ./... (darwin), GOOS=linux go
  vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -count=1 -timeout 45m: internal/handoff ok, internal/update
  ok, internal/gui ok (95s), internal/provider ok, internal/gateway ok
  (367s).
- TestCoreScriptBudget: app.js is 1,338,901 of its 1,338,929. My
  additions first went 372 bytes over after the rebase; the badge's two
  wordings now share one args object and the comments I added were cut,
  with no budget raised.
- GUI (NODE_PATH playwright 1.62.0, both engines): i18n-keys, every
  update-*.test.cjs (update-wait 22/22, update-restart 22/22, update-stuck
  40/40 among them), gui-de, gui-ja, gui-zh-tw: all pass.
- f3eb92924 (the Mac relaunch's exec fallback) landed under this. A
  handover that never gets its hello falls back to update.Relaunch, which
  now carries that fallback; OpenBeside keeps open's tries only, since
  the old one is still running then and the fallback follows.
- Linux, Docker golang:1.26.8 with -tags gtk3 (before the rebase): the
  handoff package, the gui handover tests including the cross-process
  TestRestartHandsTheGatewayOver, and the gateway handover tests pass.
- Full GUI suite at f09e9a066 (before the rebases, load ~250 from other
  sessions): 11958 tests, 61 failed in 22 files. 13 pass alone (fonts,
  plugin-updates, rail-tip, routing-keys-fold, routing-mode-goes,
  routing-model-rest, routing-rule-remove, routing-went-on, search-keys,
  segment-press-dialog, sidebar-overlay-scrollbar, usage-overview-fold,
  usage-pack); load reds of this kind are #3393. 9 fail the same on
  origin/main 843417957, each filed: library-mcp-health-wsl #3350,
  quota-count-wrap and quota-name-translated #2228, quota-reads #2150,
  s3-sync #2448, usage-agents-hide #2276, usage-checkin #2549/#3091,
  usage-fold #2163, usage-ledger #3104.

Not tried:
- Windows: unchanged by design, nothing to run there beyond vet.
- A real Linux desktop app. The tests ran in Docker (above); the D-Bus
  wait (awaitExit) was not seen in a real tray.
- Whether the menu bar showed two birds for a moment on the Mac. B's
  tray goes up as it starts, and A hides on the ack, which follows B's
  first listen. They are close, but not ordered, and I didn't capture
  the screen.
- The Mac's real bundle id and LaunchServices registration
  (com.yetone.magpie), the real signed and notarised update, and real
  accounts (the run used a fake upstream).
2026-10-24 02:20:38 +08:00
yetone 85cde4a4de provider: Codex and ChatGPT API refreshes lock across magpies
Two magpies can now run at once: a restart to update hands the gateway
over and the old one finishes its requests for up to 15 minutes (next
commit), and a magpie run from a terminal can sit beside the app. Codex's
auth.json and the ChatGPT API sign-in rotate their refresh token on every
refresh. Their refresh locks (codexMu, siwcRefreshing) were a sync.Mutex,
held in one process only. So both magpies could refresh with the same
refresh token, and the second got refresh_token_reused, which signs the
account out.

Both are now a filelock.Mutex beside logins.json (.codex.lock,
.siwc.lock). The sign-in is read again once the lock is held, so a magpie
that waited uses the tokens the other one wrote instead of refreshing
again. Claude's saved tokens, MCP servers' and plugins' were already
locked across processes. Google's, Vertex AI's and Copilot's refresh
tokens don't rotate. Docs: providers-accounts.md, Constraints.

Tests: TestCodexRefreshWaitsForAnotherMagpie and
TestChatGPTAPIRefreshWaitsForAnotherMagpie. Each holds the file lock as
another magpie would, mid-refresh, writes that magpie's rotated tokens,
then lets go. The refresh must return those tokens and send nothing to
the token endpoint.

Broken by hand: with both locks put back to sync.Mutex, both tests are
red ("refreshed 1 times beside another magpie").

Run: see the next commit's body. The provider package ran at the pushed
head with -timeout 45m.

Not tried: a real Codex or ChatGPT API account refreshing in two magpies
at once. The tests use fake token endpoints.
2026-10-24 02:11:14 +08:00
yetone a2e98cd799 gateway: a streamed Codex turn goes to ChatGPT over its WebSocket (brickhao)
brickhao on Discord: long Codex turns through magpie died with "stream
closed before response.completed". Their network (FlClash) cuts a
streamed HTTP reply from chatgpt.com at about 120 s: 120.7 s through
magpie, 121.5 s over HTTP without magpie. Codex's own WebSocket to the
same backend ran to the end twice (124.5 s, 131.4 s). magpie has no
120 s timer of its own (no WriteTimeout, 10 min to the first header).
The cut is on the leg from magpie to chatgpt.com, which was always
HTTP. Codex answers magpie's 426 by falling back to HTTP, and over
loopback that is harmless.

What changed: codexSocket, first in upstreamTransport, sends a POST to
CodexBase/responses with "stream":true over the backend's WebSocket, as
codex-rs does (ResponseCreateWsRequest, build_websocket_headers).
- Handshake: the turn's headers plus OpenAI-Beta:
  responses_websockets=2026-02-06. x-codex-turn-state and the
  responses-lite header go in client_metadata instead. The message is
  the body (zstd decoded) with "type":"response.create" ahead of it.
- Frames come back as the SSE the HTTP route sends.
  codex.rate_limits and codex.response.metadata are also given as the
  x-codex-* and x-codex-turn-state headers. websocket_timing is dropped.
- An error frame ahead of the reply becomes its HTTP status and body,
  so account rests and failover work as before.
- These go over HTTP: a refused handshake (and the host stays on HTTP
  for 10 min, unless the refusal was 401/429/5xx),
  websocket_connection_limit_reached, and a body that isn't a streamed
  turn.
- A socket closed before the end reads as a cut stream.
- Both Codex's own sign-in passthrough and magpie's ChatGPT accounts
  take this path. Codex identity, instructions and prompts are
  unchanged. coder/websocket is now a direct dependency (it was
  indirect).

Run:
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- go test -race -count=3 of the five new tests: ok.
- go test -timeout 45m at 1a5911612 (rebased on origin/main c551a2299),
  sandbox HOME: internal/gateway ok 760.9s, internal/agent ok 596.8s,
  internal/provider ok 172.5s. The rest of ./... was not run before the push.
- Real: a sandbox magpie (this tree, 127.0.0.1:3488, sandbox HOME and
  CODEX_HOME, a copy of the Codex access token with the refresh token
  blanked so nothing could rotate). A curl turn on gpt-6-luna came back
  200 with codex.rate_limits in the SSE (which only the socket sends)
  and the x-codex-* headers. Real Codex CLI 0.162.1 (codex exec,
  xhigh) through it: a 6121-word reply over 165 s ended whole, exit 0.
  Codex logged its own 426 from magpie and fell back, as expected.

Broken by hand:
- socket off in the tests: all four socket tests red (the reply cut
  before response.completed, no handshake, 200 not 429).
- error-frame mapping off: TestCodexSocketErrorIsItsStatus red.
- turn-state into client_metadata off: TestCodexTurnGoesOverWebSocket
  red.

Not tried:
- brickhao's network: this network doesn't cut at 120 s, so the 165 s
  turn shows the socket carries a long turn whole, not that it gets
  past their cut.
- A real turn on a magpie-saved ChatGPT account (fake only).
- Through an HTTP or SOCKS proxy for real.
- Windows/Linux runs.
2026-10-23 23:59:55 +08:00
yetone 34f9686bd2 agent: dsh's desktop app is DeepSeek's own DeepSeek Harness; the community DeepSeek Hermes is not it
WuSix on Discord (Windows 11), on v0.1.1337: the desktop app still isn't
in magpie's Agents, and the repo 0c679c640 built on
(motongv/deepseek-hermes-desktop, "DeepSeek Hermes") is not DeepSeek's.
The official one is github.com/deepseek-ai/deepseek-harness.

What was wrong: 0c679c640 took a community Electron wrapper around
`dsh web` for the app WuSix runs, and listed dsh, wrote the web profile
and dropped dsh's key store for it. That is taken out whole (dshHermes,
the store switch, the web-profile app file, noticeDsh6 and its zh, zh-TW,
ja and de strings, the Running pattern, dsh_hermes_test.go). A user that
v0.1.1337 wired this way keeps profiles/web, which is dsh web's own
profile; the next Apply or Sync writes the key store again.

The official app, read from its source (deepseek-harness at 687f282e8,
dsh-v0.2.1-rc.2) and its real release files:
- apps/desktop/scripts/electron-builder-config.mjs: productName
  DeepSeek Harness, appId from DSH_DESKTOP_APP_ID; first config
  19444907f0 hard-codes com.deepseek.dsh. NSIS per-user
  (perMachine false), a folder the user may pick; installer.nsh writes
  HKCU ${INSTALL_REGISTRY_KEY} InstallLocation and refuses all-users.
- deepseek-harness-0.2.1-rc.2-mac-arm64.zip (sha512 as the feed
  download.deepseek.com/dsh-desk/feeds/mac-arm64/nightly-mac.yml says):
  DeepSeek Harness.app, CFBundleIdentifier com.deepseek.dsh, 0.2.1-rc.2,
  team NAN929V4UM.
- deepseek-harness-0.2.1-rc.2-win-x64.exe installed with /S on the
  Windows 11 box (26200): %LOCALAPPDATA%\Programs\DeepSeek Harness\
  DeepSeek Harness.exe, HKCU\Software\1bf39983-50d0-5fe0-9ef4-
  cece76f67c5e InstallLocation, Uninstall entry DisplayVersion
  0.2.1-rc.2, DisplayIcon <exe>,0. Nothing under HKLM.
- packages/util/home-paths/src/index.ts (defaultDshHome = ~/.dsh,
  DSH_HOME) and apps/desktop/src/paths.ts (profiles/desktop, "shared
  with npm-installed dsh"): the same ~/.dsh as the CLI on every OS.
- No Linux desktop build is published (UPDATE_TARGETS is mac-arm64,
  mac-x64, win-x64; dsh-latest-linux-x64.AppImage is 404); Linux has
  the npm CLI only.
magpie's desktopApps["dsh"] already had all of these (#2279, #2325);
the row is named DeepSeek Harness, the app's own name.

Run:
- Windows box, sandbox USERPROFILE/APPDATA/LOCALAPPDATA (Programs a
  junction to the real one, where the installer put the app), no ~\.dsh:
  the released v0.1.1337 magpie-cli-windows-amd64.exe and this commit's
  build both list "DeepSeek Harness ... ~\.dsh\profiles\desktop\
  cordis.patch.yml" in `magpie ls`. So on a default install v0.1.1337
  already listed it; what WuSix sees isn't reproduced. An unconnected
  agent sits under the Agents page's 未设置 (Not set up) fold; WuSix's
  screenshot and install folder are still to be asked for.
- macOS: the real 0.2.1-rc.2 .app in a sandbox HOME's Applications:
  HasApp true, version 0.2.1-rc.2, `magpie ls` lists it.
- New tests: TestDshOnlyTheOfficialApp (red on 0c679c640's dsh.go:
  "DeepSeek Hermes taken for DeepSeek Harness: detected true") and
  TestDshWindowsAsTheInstallerRegistersIt (the registry values above,
  and the GUID as UUID v5 of com.deepseek.dsh in electron-builder's
  namespace).
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- GUI: i18n-keys, agent-notice-lang, gui-de, gui-ja, gui-zh-tw: 34/34.
- Full suite: not run at push time (queued behind the suite lock;
  pushed per the owner's ship-at-once rule). TestDsh*, TestDesktop*,
  TestCLIMissing*, TestRegistered* rerun ok at the rebased head on
  origin/main 03951798a; the full run follows through the lock, reds filed.

Not tried:
- The real app opened (neither the .app nor the .exe was started), so
  no request from it through the gateway.
- WuSix's own machine: why their row doesn't show is still unknown.
2026-10-23 22:26:33 +08:00
yetone d3f3df746e routing: the page's head has Routing groups, which brings the groups at the page's foot into view (shihh on Discord)
The routing groups sit below the stage, the story and every request; with
many models (shihh on Discord) they are a long scroll down. The Routing
page's head now has Routing groups (#rtGoGroups) beside New group: a down
arrow, its name, and a tooltip saying where they are. Its click goes
through scrollOnPurpose, brings .rt-gsec to the top of the view and moves
the focus into it. The page's layout is unchanged (no #1354-style move):
the groups stay last in #rtMore. fitGo gives the button only the head's
spare room (the .grow spacer): named, its arrow alone (still named to a
screen reader), or left out, so nothing else in the head moves or wraps.
Strings in zh, zh-TW, ja and de. app.js untouched (plugin files only).

Test: routing-groups-jump.test.cjs, Chromium and WebKit x en/zh/zh-TW/ja/de
x 1000px web, 480px web, 640px window: 30/30. It is red on main's assets (no
button), red with the scrollOnPurpose check removed (the app's guard pulls
the view back), red without the focus move, and red with fitGo removed
(de at 480px web: Hide accounts moves).

Run at this change on 50f52b540 (de281760e, rebased under it, touches only internal/gateway):
- go test -tags nogui -timeout 45m ./...: 69 packages ok, no FAIL
- gofmt -l: clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: ok
- TestCoreScriptBudget and the other budget tests: ok
- GUI files the change can reach (routing*, group*, i18n-keys,
  click-scroll, title-bar-tools; 125 files, both engines): 1495/1495

Not run: the whole GUI suite. Another session's full GUI run held the
machine for 2h45m+, and this touches only the routing plugin's files.
Not changed: on a phone the web head already shrinks to its 40px
min-height on main, so wrapped buttons slide under the first card (Hide
accounts at 360px in German). Where the head has no spare room, the button
is left out rather than wrapped.
2026-10-23 21:37:16 +08:00
yetone de281760e2 gateway: a conversation going round one tool call with the same result is answered by magpie after 8 turns (audie on Discord)
audie on Discord: on 10-21 Codex Desktop, routed to WorkBuddy's
deepseek-v4-pro, ran the same read-code tool call 308 times between 13:24
and 13:52 (316 requests, 212.65 credits). That evening it did it 340 more
times between 19:58 and 20:22 (343 requests, 324.52 credits). loopGuard
only catches a loop inside one streamed reply. Here every reply was a
short, valid call. The loop runs across turns, so it shows in the
request's own history.

stoppedToolLoop (internal/gateway/tool_loop.go) runs in serveAgent after
the session is recorded and before hooks, middleware and routing. It also
runs in the Codex backend's passthrough on Codex's own ChatGPT sign-in. It
needs the last 8 turns to be the same exchange:
- the same calls: name plus arguments, key order ignored, call ids ignored;
- answered with the same results: text, error flag and images, with
  Codex's "Wall time", "Chunk ID" and "duration_seconds" taken out
  (runNoise);
- with nothing else said on the user's side.
When it finds one, it answers the turn in the agent's own protocol,
streamed or whole (Responses, Chat, Anthropic, Gemini through
relayStatus), with a notice that names the call. Nothing goes upstream, and
no prompt, base_instructions or identity text sent to a vendor changes.
A different result, or any word from the user, starts the count again.
The notice is a turn without calls, so the user's next message carries
on. The check keeps no state, so it is per conversation, and a retried
request doesn't count twice.

The turn is recorded the way Codex's title turns are. sentNowhere's body
becomes answeredHere (from-protocol aware): the Routing trace shows "Tool
loop stopped", and a usage row has provider magpie, rejected, the
conversation's session and native session, and an error starting
"tool loop:". So Usage and Sessions both show why.

Cost: a body with fewer than 8 tool results isn't parsed (a
bytes.Count). For a longer one, only the newest 64 items are parsed,
found with gjson (tailOf). For a 1.5MB Codex turn that is 1.1ms and
2.5MB, against 30ms and 20MB for a full parse (BenchmarkToolLoopCheck).

There is no new setting. Settings › Models › Replies › Stop looping
replies (noLoopGuard, on by default) turns this off together with the
reply guard, and the notice says so. The GUI sub-text is unchanged.
docs/subsystems/gateway-routing.md has a bullet on it.

Run at this commit (vet/build/race at parent bf2e067ef; the full suite
after the rebase onto 50f52b540, at 558b21b7e):
- gofmt -l clean.
- go vet ./... on darwin, GOOS=linux go vet -tags nogui ./..., and
  GOOS=windows go vet ./....
- go build on darwin, linux (-tags nogui) and windows.
- TestToolLoop* and the Codex title/description/prediction tests under
  -race (TestToolLoop* -count=3).
- The tests, in a sandbox HOME against fake vendors:
  - TestToolLoopIsStoppedOnEveryProtocol: 60 poll turns then 8 Codex
    reads with a varying chunk id and wall time, on Responses (stream and
    whole), Codex's backend path, Chat (stream and whole), Anthropic
    (stream and whole) and Gemini. The vendor is asked 0 times, the
    notice and the protocol's done marker reach the agent, and the usage
    row is magpie, rejected, "tool loop", with the session.
  - TestToolLoopStoppedOnCodexsOwnSignIn: gpt-5.5 on the passthrough,
    with a fake CodexBase.
  - TestToolLoopShortOrOffGoesOn: 7 turns, and 40 with the setting off.
  - TestToolLoopLetsProgressBy: 200 polls whose answer moves, and a loop
    followed by the notice and a word from the user. Neither is stopped.
  - TestToolLoopSums.
- Broken by hand, each red, each restored:
  - The guard skipped: every protocol subtest and the Codex sign-in test
    fail ("the agent wasn't told of the loop").
  - runNoise removed: the same tests fail, plus TestToolLoopSums.
  - Results left out of the sum: every progress subtest fails ("a poll
    whose answer moves was stopped").
- Full suite: set -o pipefail; go test -tags nogui -timeout 45m ./...
  through suite-lock, in a sandbox HOME, at 558b21b7e on 50f52b540:
  exit 0, 69 packages ok, no FAIL (internal/gateway 854s, internal/agent
  812s, internal/provider 393s, internal/gui 291s).
- No GUI file changed, so the GUI suite wasn't run.

Not tried:
- A real Codex Desktop or WorkBuddy loop, or any real account. The
  fixture's shape is Codex's exec_command output; audie's literal bytes
  weren't available.
- The Windows box.
- Codex over websocket (magpie answers it 426).
- Responses conversations that use previous_response_id. They carry only
  the newest turn, so they are never stopped.
- Loops with more parallel calls a turn than fit in 64 items.
- A poll that gets the same answer 8 times in a row is stopped too. The
  user's next word, or the setting, carries on.
- dsh's two ~1M-token requests to DeepSeek on 10-23 are a different
  problem, not addressed here.
2026-10-23 21:36:51 +08:00
yetone 50f52b540b redact: a text masked for a vendor before is masked as it was then, so a cached prompt stays cached
With Privacy masking on, a value masked once is "known" and masked
wherever a later request has it (redact/known.go). When a rule first
finds a value in a later turn (a tool printing DB_PASSWORD=...), that
value was masked from then on in the system prompt and the turns already
sent with it as written. The prefix the vendor had cached changed, so
the whole prompt was written to the cache again and none of it was read.

Reported by audie on Discord: DeepSeek Harness on a routing group served
by a custom Anthropic-compatible provider. Adjacent turns 10s apart had
cache_read 0 and cache_write 412K to 427K.

Fix: Mask and MaskJSON (the vendor-bound paths, via masking.Masker) now
use sentKnownSpans. A text masked before gets the known values it had
the first time, keyed by a sha256 of the text and the options. Only
hashes and spans are kept, never a value, in two generations of 65536.
New text still gets every known value masked. Scrub (archives, sessions,
OTel; local only) keeps the latest known set.

Unchanged: if magpie restarts, or a text falls out of both generations,
the text is masked under the current known set once, as before.

What was run:
- internal/redact TestSentTextKeepsItsMasking and internal/gateway
  TestMaskedConversationKeepsItsCachedPrefix. The gateway test sends a
  dsh-shaped Chat Completions conversation to a group with an Anthropic
  member, and a Claude Code-shaped /v1/messages one. It checks that each
  turn's system, tools and earlier messages reach the fake upstream byte
  for byte. Both tests are red with sentKnownSpans forced back to
  knownSpans: the system prompt became "{{SECRET_...}}" on turn 3. Both
  are green with the fix.
- With masking off, a probe of the same dsh shape had the system, tools
  and earlier turns byte-identical on every turn.
- gofmt -l: clean. go vet: darwin, GOOS=linux -tags nogui ./...,
  GOOS=windows ./...: clean.
- Full suite at 8187919d7 (this tree, on origin/main bf2e067ef):
  set -o pipefail; go test -tags nogui -timeout 45m ./..., through the
  suite lock. 69 packages ok, none red (gateway 519s, agent 393s).

Not tried: audie's real setup. Their Privacy setting isn't known; with
masking off this is not the cause, and every breakpoint reading 0
(even the unchanged system block) points at the provider's own cache or
pool. Not tried against a real Anthropic or relay account. GUI not
touched, so the GUI suite was not run. Windows tests not run.
2026-10-23 20:53:53 +08:00
yetone bf2e067ef6 gateway: a Codex account with credits is asked again at its allowance's edge, never benched (豆子, Zhenzhen)
Two Discord reports about ChatGPT accounts left to spend their credits
(the default):
- 豆子: an account whose allowance is used up but which still holds
  credits got a long rest. It should go ahead of accounts with neither.
- Zhenzhen: a Pro lite account ran out mid-session and the running
  session failed with "usage exhausted", while a new session worked.

The cause: when a window fills, ChatGPT can answer that turn 429
usage_limit_reached before it spends the credits, and serve the next
turn on them. magpie took the 429 as quota. On the routed path it
rested the account until the window renewed (candidate.full drove
those rests). On the relay (Codex's own sign-in) it passed the 429 to
Codex, which ended the session.

- /wham/usage's credits (has_credits with a balance over 0, or
  unlimited) are now read into QuotaWindow.Credits, Limit.Credits and
  Allowance.OnCredits.
- Routed path: a 429 quota refusal from such an account (and one let
  spend them, CodexCredits) is asked again at once, once per request,
  before a reset is looked at (creditsAgain, Try.Credits). If it is
  refused again, it rests fallbackCooldown (Rest.By "credits") and its
  usage is read again. full() is zero for it, so a full window rests it
  nowhere else (spendsCredits).
- Relay: the same ask-again, once (relayOnCredits).
- Order: Smart, Pace and Least used put a credits account first of the
  98%+ tier (Seat.Credits, spentBefore). That is after accounts with
  allowance left and ahead of those with nothing left.
- Routing page: says why such an account went first or where it waits,
  tells the asked-again try ("{n} used · on credits"), and the "credits"
  rest. Strings in zh, zh-TW, ja and de.
- Not a plugin path: Codex has no plugin.

Zhenzhen's suggestion to switch to credits early (~3% left) was weighed
and not done: the vendor spends credits only once the allowance is used
up, so switching early only wastes what is left. Retrying at the edge
keeps the running session alive. Codex identity, base_instructions and
prompts are untouched.

Tests, each red on the old code (the GUI test against the old
client.js, the Go ones with spendsCredits/relayOnCredits forced false
or the old strategies.go):
- TestCodexCreditsAskedAgainAtTheEdge: relayed, routed, set not to
  spend. Fake ChatGPT backend that refuses the edge turn and then
  serves on credits.
- TestCodexCreditsNoLongRest: refused again gets a rest of at most
  fallbackCooldown; a 500 gets backoff; no credits keeps the long rest.
- TestCodexCreditsFirstOfTheSpent (gateway) and TestCreditsFirstOfTheSpent
  (routes, Smart/Pace/LeastUsed).
- TestCodexCreditsBalance gains the onCredits column.
- routing-codex-credits-again.test.cjs: en/zh/ja/de, Chromium and
  WebKit, 8/8.

Run at this head (rebased on origin/main e96d577f2):
- gofmt -l clean.
- go vet ./... on darwin, linux (-tags nogui) and windows.
- go test -tags nogui -timeout 45m ./...: 69 packages ok, exit 0.
- GUI: routing-*.test.cjs, panel-routing-*, codex-credits, plan-credits
  and i18n-keys (103 files, both engines), before the rebase. 1251 of
  1253 passed at load ~50-70. The two reds each pass alone (3 of 3):
  routing-effort-change, filed as #3376, and routing-model-rest, #2115.

Not tried:
- The real ChatGPT backend. The 429 at the edge is inferred from
  Zhenzhen's report; no account was run out live.
- The live x-codex-credits-* response headers are not read.
- A workspace plan still within its overage is not treated as on
  credits.
- Affinity between two credits accounts is unchanged.
2026-10-23 20:11:17 +08:00
yetone a77b5b4fc9 gui: Check in now says what the press came to, not "refreshed" (#3326)
Promised to connoryang331 on #3326: a press of Check in now said "Check-in
status refreshed" whatever happened. It now says, in the same toast, a
count per kind (checkinPressSaid): "Claimed: 1 (+200 credits)",
"Already checked in today: N", "Not available yet: N" (inactive,
ineligible, or an "already" magpie asks again), "Check in in its own app:
N" (captcha, Trae's 9074), "Check-in failed for N account(s)" (red, as
before). No layout change. en, zh, zh-TW, ja, de.

A result counts as claimed now only when the vendor was asked on this
press: WorkBuddyCheckin.Asked is now sent as "asked" (omitempty). It is
still never kept: checkinNow writes the file before setting it. An
account claimed earlier today, settled and not asked, counts as already.
The TUI and CLI already say each account's result ("+N", "· already"),
unchanged.

app.js and the core budget: +771 bytes over the previous commit, 349 over
the budget after compacting the helper, raised by exactly that with the
reason in core_budget_test.go (the check-in row is the core's, the tray
panel draws it too).

Tests:
- checkin-early-done.test.cjs: the press's toast is "Claimed: 1 (+200
  credits)" in each language, and checkinPressSaid's text for already,
  not yet and a mix (claimed x2 +150, already, failed), bad = 1 for a
  failure. qoder-checkin-recheck.test.cjs now wants "Not available yet:
  1" for its inactive press.
- Red on the previous commit's app.js: both files 0/20 in Chromium.

Run at this tree:
- GUI: checkin-account, checkin-early-done, i18n-keys, plugin-checkin,
  qoder-checkin-recheck, usage-card-refresh, usage-checkin, Chromium and
  WebKit: 177/179; the 2 reds are usage-checkin's WebKit Qoder check-in
  tab, red alone on origin/main 0815c9186 (#2549, #3091).
- go test -tags nogui ./internal/gui/ -run Budget, ./internal/provider/
  -run 'Checkin|CheckIn': ok.
- Full suite: set -o pipefail; go test -tags nogui -timeout 45m ./...
  at 70c6bb072 (this tree on the previous commit), sandbox HOME: 69
  packages ok, exit 0. go vet of internal/gui and internal/provider on
  darwin, linux (nogui) and windows clean; gofmt -l clean.

Not tried: a press against a real vendor account.
2026-10-23 19:03:58 +08:00
yetone 45fa29973c checkin: an early "already checked in" is asked again, not kept for the day (#3326)
connoryang331 (v0.1.1328, Windows): at 00:00:28 Beijing 14 of 29 plugin
check-ins (AutoClaw CN x5, WorkBuddy x2, CodeArts, Trae x3, MiniMax,
Raccoon x2) answered "already" (done). magpie kept that as the day's
result and never asked again, and Check in now answered from the record
without asking. A real claim at 10:54 paid +200: the vendors' days turn
later than Beijing midnight, so 00:00's "already" was yesterday's.

The class, in the checkiner every check-in shares (built-in and plugin):
- A done, inactive or ineligible answered before noon Beijing
  (checkinSureHour) for an account magpie hasn't seen claim that Beijing
  day is provisional. The loop asks it again 30 minutes (wbCheckinEvery)
  after the answer, until a claim or an answer from noon on: at most 24
  more asks a day per such account, none once magpie claims.
- A press (soon) asks again at once for done, inactive and ineligible,
  whatever the hour. own-app (Trae 9074) and captcha still stand.
- A claim stamps Claimed, carried over while later answers that day say
  done, so a done after magpie's own claim is settled (Qoder's claim then
  done case).
- The record goes out with again: true (worked out when shown, never
  kept). The card says "{name} says already checked in; its day may not
  have turned yet, so magpie asks again later" and keeps Check in now;
  Settings, TUI and CLI say the same. en, zh, zh-TW, ja, de.
- Qoder's recheck (#2696, pluginRechecks) is unchanged: its tests pass
  as they were.

The plugins repo does not cache "already": autoclaw reads the task list
or calls dailySignin each time, codearts, minimax, raccoon and trae ask
the server each call (read at magpie-community/plugins origin/main
652f06d). No plugin change, publish or mover min.

Tests:
- TestPluginCheckinEarlyDoneAskedAgain (the reporter's 00:00:28: loop at
  +29m no ask, +30m asks then claims; a press at 10:54 claims; done all
  day is 25 asks and settles at noon; done after magpie's claim settled)
  and TestWorkBuddyCheckinEarlyDoneAskedAgain.
- TestPluginCheckinOthersSettledForTheDay now answers at 12:00 Beijing
  and checks a press asks again (claimed still settled);
  TestPluginCheckinRunsAsTheBuiltinsDo, TestTraeCheckinAnswers and the
  WorkBuddy nothing-to-claim/refused tests follow the new rule.
- TestCheckinAgainNotShownAsToday (TUI words and cell).
- checkin-early-done.test.cjs: again card's wording, data-state wait,
  Check in now asks plugin-checkin {provider: autoclaw-cn}; a kept done
  is "Checked in today +50" with no press. Chromium and WebKit, 5
  languages, 900 and 440px, 20/20.

Red on the old code: with the non-test change reverse-applied (fields
kept so it compiles), TestPluginCheckinRunsAsTheBuiltinsDo,
TestPluginCheckinOthersSettledForTheDay (inactive, done, ineligible) and
all 4 subtests of TestPluginCheckinEarlyDoneAskedAgain fail; with
origin/main's app.js, checkin-early-done fails ("Checked in today").

Run at this tree:
- gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./... clean.
- go test -tags nogui ./internal/provider/ -run 'Checkin|CheckIn',
  ./internal/tui/ -run 'Checkin|OwnApp': ok.
- GUI: checkin-account, checkin-early-done, i18n-keys, plugin-checkin,
  qoder-checkin-recheck, usage-card-refresh, usage-checkin: 177/179. The
  2 reds are usage-checkin's "webkit en/zh: Settings has a Qoder check-in
  tab", red the same alone on origin/main 0815c9186 (filed #2549, #3091).
- Full suite: set -o pipefail; go test -tags nogui -timeout 45m ./...
  at c1a72f2b4 (this tree on origin/main 0815c9186), sandbox HOME: 69
  packages ok, exit 0.

Not tried: real vendor accounts (no early-morning "already" to replay),
Linux and Windows at run time. A vendor whose day turns after noon
Beijing (a US day) is not covered.
2026-10-23 19:03:58 +08:00
yetone 0815c91864 claude: a reply that writes its tool calls as "[tool call …]" text makes them for real instead of showing the lines (Zhenzhen on Discord)
Claude Desktop 3.1623.0 on a Claude subscription ("Fable 5.1 High",
magpie 0.1.1327) showed replies holding lines like
  [tool call mcp__magpie__mcp__ccd_turn__update_plan id=toolu_0Validate args={"advance":true}]
  [tool call mcp__magpie__Bash id=toolu_0Validate bash args={"command":"cd /Users/... && git diff --check ..."}]
and nothing ran. That is the form renderCachedParts gives past calls when
a run is told the conversation as text (renderClaudePrompt for a run
started anew, renderClaudeTurn for a turn with the client's own calls).
The model copied it: Claude Code had no call to make, the turn ended
end_turn, and the client showed the lines as words.

- readOutput holds a reply's words back from the first line that opens
  with "[tool call " (textCalls); words before it, and lines that only
  start like it, go on as they come. A reply that ends there with
  end_turn and calls none of the client's tools isn't ended: once the
  turn's result is in, the run is told textCallsAsk as a user message on
  its input, and the reply goes on in the next message (one
  message_start, as after Claude Code's own call). The client gets the
  real tool_use, registered by mcpCall, so its results go on in the run.
  Asked once per reply; written as text again, the words reach the
  client as before. No input (a run that ends by itself) or a reply that
  also called a client tool: not asked.
- A prompt that tells past calls as text ends with pastCallsNote: the
  lines record earlier calls, and writing one calls nothing. Placed after
  the messages (before </current_turn>), so the history chunks and their
  cache marks are unchanged. A prompt with no call is told as before.
- Neither text names magpie, Claude or Anthropic (checked in the test).
  Claude Code's own prompt and identity are untouched.

docs/subsystems/claude-subscription-bridge.md: new section "Tool calls
written as text", tests added to Verification.

Run at base 34ad18ed8 (origin/main) + this change, sandbox HOME with
pinned caches:
- New tests in claude_text_calls_test.go, built from the report's lines.
  With claude_subscription.go put back to 34ad18ed8 (claude_text_calls.go
  kept so it builds): TestClaudeTextToolCallsAreMadeForReal FAILs "the
  client was shown the calls written as text" (the raw [tool call …]
  deltas in the stream), TestClaudeTextToolCallsAskedOnce FAILs (reply
  ended end_turn after the first text call, run never asked),
  TestClaudeTextToolCallsUnstreamed and
  TestClaudePromptSaysPastCallsAreARecord fail too. Restored: all pass,
  also -race -count=3.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m -count=1 ./internal/gateway/ (log
  teed): ok 515.4s. The first such run failed
  TestClaudeTurnWithItsImagesTakenOutGoesOnInItsRun (passes at
  34ad18ed8): push built each line from string(byte), which turns
  UTF-8 into Latin-1 runes, so "一只猫" reached the client garbled. Now
  s[i:i+1]; TestClaudeTextCallsHoldsOnlyTheLine has a CJK case that
  fails with string(ch) put back (shown "ä\xb8\x80只猫…") and passes
  without.
- Rebased on origin/main 8ef9fc578 (it changed internal/gateway's
  redact paths), then again at the pushed head: gofmt, the three vets
  ok, go test -tags nogui -timeout 45m -count=1 ./internal/gateway/:
  ok 385.4s. Rebased once more on 3b8bcc365 (Codex sign-in refresh,
  internal/gateway's signin_revoked.go): go vet of gateway and
  provider, and -run 'Claude|CodexRefresh' ./internal/gateway/: ok
  39.9s; the whole package not run again at that head.
- Full suite: not run; another session's go test ./... (pid 72083) was
  running on this machine.

Not tried: a real Claude Code or a real Claude subscription. Writing a
user message to an idle run after its result is the path resume already
takes for each next turn; that the model then makes the call it wrote
as text is not shown on a real model. Not tried with Claude Desktop.
2026-10-23 18:19:59 +08:00
yetoneandggbdpq 3b8bcc3654 provider: a ChatGPT token the backend calls expired before its exp is refreshed once and read again (willz on Discord, #2973)
willz on Discord (macOS, v0.1.1330): two saved Team Codex accounts showed
only "Unauthorized". /backend-api/wham/usage answered 401 "authentication
token has expired. Please try refreshing it." while each access token's
JWT exp was still ahead, so codexToken and savedLoginToken handed the
same token back on every read, and on every request, until the account
was signed in again. #2973 is the same 401 on the request path.

What changed
- SignInExpired (codex_expired.go) tells such a 401 by its words:
  token_expired, "authentication token is/has expired", "Please try
  refreshing it". It never matches refresh_token_expired, which is a
  revoked sign-in. accountJSON now keeps the first 4KB of a refusal's
  body on accountStatusError for it.
- Refreshes are keyed on the token that was turned away:
  codexTokenRenewing(dir, stale) for Codex's own sign-in and
  renewSavedLoginFrom(user, stale) for a saved one. Under the lock that
  signing waits on, each reads its store afresh. If the store holds
  another token by then (renewed by Codex or by another reply), that
  token is used and no refresh is spent, so two replies for one token
  spend one rotation. Otherwise they refresh. Codex's own sign-in is
  written back through codexStore.write (temp and rename, every other
  field kept). A saved one goes through writeLogins and only its own
  row is changed; nothing is matched by name.
- The usage read (codexWindowsRenewing) refreshes once on such a 401 and
  reads once more, never again. It is used by loginQuota (saved and
  current accounts), codexSubscriptionUsage, and the reset spenders
  through codexUserWindows (autoreset, expiring, stillExpiring), which
  read the same windows with the same tokens.
  - A refresh that is refused shows its own words on the card: a saved
    account is marked lapsed, "add the account again to use it"
    (savedRefreshFailed); Codex's own says "run codex login".
  - A token that was refreshed and is still called expired says "sign in
    to this account again" (errCodexStillExpired).
  - A refresh that got no answer is shown as that, not as signed out.
- Request path: noteSignIn renews the account a request went with
  (NoteExpiredSignIn, at most 20s, through Account.renew, which is set
  on Codex's own account and each saved one). Nothing is marked. The
  request fails over as a 401 did before, and the next one goes with
  the new token.
- Docs: providers-accounts.md ("A token called expired") and
  gateway-routing.md.

The request-path hook and its gateway tests (codex_refresh_401_test.go,
taken as written) are ggbdpq's patch on #2973. Here they rest on the
stale-keyed refresh. The patch's forced refresh skipped the fresh
keychain read, so it could spend a refresh token Codex had already
rotated.

Tests
- TestCodexUsageRenewsTokenCalledExpired: a saved and a current account,
  both with an hour left, get 401 token_expired. Each is refreshed once,
  read once more, and kept where it lives (auth.json in the sandbox
  HOME, logins.json). A second read refreshes nothing.
- TestCodexUsageExpiredOnce: a refused refresh says to sign in again; a
  token still called expired is read no third time.
- TestCodexUsageOther401NotRenewed, TestSignInExpiredWords,
  TestNoteExpiredSignIn (two replies for one token make one refresh).
- ggbdpq's TestCodexExpired401RefreshesLogin and
  TestCodexOther401DoesntRefresh.

Run at 482d6707a (this change) (rebased on 8ef9fc578):
- gofmt -l internal clean; go vet ./... (darwin), GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./... clean
- set -o pipefail; go test -tags nogui -timeout 45m -count=1 ./... in a
  sandbox HOME, log teed: every package ok (69 ok, no FAIL), provider
  221.1s, gateway 574.4s, agent 434.4s. No other full suite was running
  (another session's gateway-only run was).
Broken by hand: with codexWindowsRenewing's retry and NoteExpiredSignIn
turned off (the old behaviour), TestCodexUsageRenewsTokenCalledExpired,
TestCodexUsageExpiredOnce, TestNoteExpiredSignIn and
TestCodexExpired401RefreshesLogin are red. The card read "Unauthorized",
the reporter's words, and the gateway test's sign-in was "renewed 0
times, want once". The new tests passed under -race.
Not tried:
- the real ChatGPT backend or a real Team account; the live ~/.codex and
  logins.json are off limits to this session;
- a keychain-stored Codex sign-in (the fresh keychain read is the
  existing codexToken path, run here only through file stores);
- Windows and Linux beyond go vet.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-23 18:15:15 +08:00
yetone 44d8c742bf remote magpie: the guide names Settings → Network and sharing → Share on local network
The Remote magpie provider's guide, its "isn't shared" message and the
gateway's LAN errors said "Settings → Share on local network", but that
switch sits under Settings → Network and sharing. Every place now names
the real path: the en key and its zh, zh-TW, ja and de words in i18n.js,
app.js's message key, the preset's EndpointHint, the gateway's and
agent's English errors, docs/reference.md, docs/integrating.md,
README.zh-CN.md and the remote and docker pages of the site (en, zh, ja).
errRemoteNotShared names no Settings path and app.js matches its prefix,
so it is left as it is.

Run at base 673651e8d with this change:
- gofmt -l: clean. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: clean.
- GUI (playwright 1.62.0, chromium and webkit, every language): 12 files
  that reach the strings, 121 of 122. The red, quota-name-translated
  (webkit en, 2px past its quota at 440px), fails the same at
  673651e8d without this change; it is #2228.
- go test -timeout 45m ./...: every package ok but internal/gui,
  where TestCoreScriptBudget failed: app.js was 1,338,819 bytes at
  673651e8d itself, over its 1,337,735 budget; origin/main 34ad18ed8
  (#3367) moved code out. This change adds 24 bytes to app.js.

Run again after the rebase onto origin/main 34ad18ed8: gofmt -l clean,
go vet of internal/gui, gateway, provider, agent and tui clean,
go test ./internal/gui/ ok (TestCoreScriptBudget passes), and the same
12 GUI files 121 of 122 with the same #2228 red.
2026-10-23 18:01:03 +08:00
yetone 56418ac5cb gateway: a client's reasoning effort "off" is magpie's none (plugins#334)
A raw reasoning_effort "off" to the gateway wasn't read as off: no check
knew the word, so a Command Code DeepSeek (plugin 0.1.15) was asked with
no off level and still thought, while "none" turned thinking off
(CHENJIAMIAN on plugins#334).

serve now reads a Chat or Responses body's effort spelled "off"
(reasoning_effort, or reasoning.effort; any case, spaces trimmed) as
"none" before anything else reads the body (offAsNone), so every route,
retry and check downstream (bodyEffort, agentEffort, ThinkOff, the IR's
effortOf, fitEffort) sees magpie's own none. A model asked "<model>:off"
is asked as "<model>:none" (askedAt). What goes upstream is then what
"none" gives today: a model with an off level gets its provider's own
spelling of it (the Command Code plugin's "off"), and one without one
goes at its least level (fitEffort). A literal "off" is never forwarded.
saysOff scans for the word without parsing, so only a body naming it is
decoded; the rest of the body (numbers included) is kept as it came.
Anthropic's output_config.effort and Gemini's thinking level are left
alone: neither API has an "off" level. docs/subsystems/gateway-routing.md
says so.

Run at 85534cd07 (origin/main fetched) plus this change; the package run
below was at 68fb6b6d8 plus this change, rebased onto 85534cd07 with no
conflict (the four commits in between touch agent, sessions, provider's
partners, README and site only):
- gofmt -l internal/gateway: clean.
- go vet ./internal/gateway ./internal/provider (darwin), GOOS=linux
  -tags nogui, GOOS=windows: ok (at 85534cd07+this). go build ./... for
  darwin, linux -tags nogui, windows: ok.
- go test -tags nogui -timeout 45m ./internal/gateway/...
  ./internal/provider/... ./internal/catalog/...: ok (gateway 366s,
  provider 93s, catalog 5s). Not the full ./... suite: another session's
  go test -race -count=20 on internal/gateway and a go test on
  internal/agent and internal/sessions were running on the machine.
- After the rebase: TestPluginThinkingOff, TestOffAsNone, TestAskedAtOff
  and TestLoop* (which reads gateway-routing.md): ok.

Broken by hand: with the offAsNone call in serve and askedAt's :off
branch taken out, TestPluginThinkingOff's chat off, chat OFF spaced,
responses off and suffix off rows fail ("reasoning_effort sent [<nil>],
want none") and "no off, off" fails (sent [<nil>], want low);
TestAskedAtOff fails (askedAt("group/g:off") = "group/g:off", "").
The "chat low" and "chat none" rows pass either way.

Not tried: no real Command Code account; the plugin's off behaviour rests
on the reporter's measurements. The Codex backend path's direct relay to
ChatGPT (Codex's own models, not through serve) is unchanged; Codex never
sends "off".
2026-10-23 16:30:58 +08:00
Yang Yu a1cce7faa1 gateway: the decision model's timeout is a setting (#2934, reyoung)
A routing group's intent classifier (askChat) and System One (askJev)
were each given a fixed 8s. A slow subscription classifier can now be
given longer in Settings > Models > Replies > Intent classifier timeout.
settings.json's classifyTimeout takes 1..60 seconds; 0 or missing keeps
8s. save() refuses below 0 or above 60, and ClassifyWait clamps a value
edited by hand (below 1 gives 8s, above 60 gives 60s). A settings file
that can't be read gives Shared()'s defaults, so 8s, never no timeout.
Both askChat and askJev read it per call. The GUI row is the app's own
segmented control (8, 15, 30, 60, plus a value set by hand), and other
saves carry the value on (prefsKeep, api.go). zh, zh-TW, ja and de
strings; the routing reference and the en, zh, ja docs say it.

Ported from reyoung's classify-timeout-2934 (author kept). On top:
- askJev's defer reworded any error once ctx had expired, so a refusal
  (decideRefused) or an answerError read as the wait ran out lost the
  type askDecideTries rests an account by. Now only errNoAnswer, which
  systemOne returns when postDecide failed with ctx done, is reworded
  to "<provider> gave no answer in <wait>".
- ja intent.html: a stray space in "遅いモデルだと 設定した".
- app.js: the Image generation timeout row and the new row share
  waitRow (~350 bytes less). TestCoreScriptBudget was red (app.js
  1,337,982 > 1,337,000); budgets raised to the exact sizes, app.js
  1,337,633 and core 1,529,393, no room added.

Run (macOS, Go env pinned, sandbox HOME):
- Full go test -tags nogui -timeout 45m ./... at 766cf1cf9: 68 packages
  ok; internal/gui red on TestCoreScriptBudget only, fixed above.
- At ed008ca9f and again after rebasing on 65e80405b: internal/gateway,
  internal/settings, internal/gui ok; gofmt -l clean; go vet (darwin),
  GOOS=linux go vet -tags nogui, GOOS=windows go vet all ok.
- Whole GUI suite at ed008ca9f, chromium and webkit, 4 wide at load
  ~30: 11,930 tests, 52 red, none in the files this change reaches
  (classify-timeout-setting, image-timeout, i18n-keys all pass). The
  red files rerun alone: 44 red in 10 files, the same 44 on origin/main
  65e80405b. All have issues (#2228, #2399, #2150, #2448, #2276, #3091,
  #2549, #2163, #3099, #3104) except library-mcp-health-wsl's ja case,
  filed as #3350.

Broken by hand, each red then restored:
- classifyTimeout fixed at 8: TestClassifierTimeoutSetting and
  TestJevGivenTheClassifierTimeout red.
- askJev fixed at 8: TestJevGivenTheClassifierTimeout red.
- save()'s bound removed: TestClassifyTimeoutKeptAndBounded (-1
  accepted) and TestSettingsClassifyTimeout (61 gives 200) red.
- ClassifyWait's clamp removed: red (600 waits 10m0s).
- api.go's keep removed: TestSettingsClassifyTimeout red.
- prefsKeep's classifyTimeout removed: the GUI test's "sent on with
  other saves" red in chromium and webkit.

Not tried: a real slow classifier or account; Linux and Windows at
run time; the native Linux desktop build; a test that pins the askJev
refusal-at-deadline race (it is timing-only, so no deterministic red
was written for it).
2026-10-23 15:03:08 +08:00
yetone a6efe07cd7 davsync: a GitHub backup too large for one request goes up in parts (Zhang-Wei, Discord)
Zhang-Wei (Discord, v0.1.1327) saw every GitHub sync fail with "GitHub
sync: HTTP 422: Sorry, your input was too large to process. Consider
creating the blob in a local clone of the repository and then pushing it
to GitHub." Their exported backup is 50.8 MB; with the library's sync off
it works. 93b87d000 sends a backup as one base64 blob in one POST
/git/blobs, so 50.8 MB is about 68 MB of request body. GitHub documents
100 MB per blob (on read) but no request size for creating one; a 19 MB
file's Contents PUT (about 25 MB of body) did go through.

A backup over 16 MiB (githubPart) now goes up in parts, in the same one
commit: magpie.magpie-backup.parts/1, /2, ... beside it, and at the
backup's own path a short list (format magpie-backup, version 2, split
github-parts, total size, each part's blob SHA and size). The version is
the list's blob SHA, and the list names each part by blob SHA, so one
version pins one whole set. get() reads the list, downloads each part by
that SHA (as large single files already were), checks each part's git
blob SHA and the sizes, and returns the backup whole; a list that doesn't
add up or a part that isn't the one named is an error. A write removes
the parts the list at the head named and the new backup doesn't use, in
the same commit (only paths known to be there, so the tree never names a
missing path). Blobs already sent are kept across a non-fast-forward
retry. The errChanged check at the head, the ref update without force and
the three rebuilds are unchanged. Backups up to 16 MiB stay one file; the
64 MiB total (four parts) stays, the bound the library's skill budget is
sized for. An empty repository's first backup in parts skips the Contents
API and follows the README note commit.

Why parts, not compression: the sealed bundle is uncompressed JSON with
skill files base64 inside, so compressing would shrink it, but that is a
backup format change for every backend and every export, every other
computer would need the new magpie even for WebDAV and S3, and it still
bounds nothing on GitHub's side. Parts keep the format and touch GitHub
only.

Older magpies: the list opens in backup.Open (unchanged since efbe5660b)
as format magpie-backup with no kdf and version 2, so it says "this backup
was made by a newer magpie; update magpie to open it" and stops: not
ErrCorrupt or ErrNotBackup, so no rebuild over it and no replace offered.
A backup in one file, from any magpie, still reads.

Library: nothing found that shouldn't be carried, so no second commit.
readSkills already skips .git and caps skill files at 32 MiB (about
57 MiB sealed). The skills on this machine (~/.claude/skills, 64 skills,
43 MB; ~/.agents/skills) hold no node_modules, __pycache__ or .venv; the
large files are real assets (images). Leaving node_modules out could break
a skill that ships its dependencies. Zhang-Wei's folders weren't seen.

Tests (fixture only, no network): the fixture refuses a blob POST over
24 MiB with GitHub's text, and serves any blob by SHA. New in
github_parts_test.go: TestGitHubSplitBackup (50.8 MB in four parts, one
commit, byte for byte back, errNotModified, stale put errChanged, then
two parts and back to one file with no part left),
TestGitHubOneFileBackupStillReads (old small and 30 MB single files read;
parts replace one), TestGitHubPartsOlderMagpie, TestGitHubPartsDamaged,
TestGitHubPartsBranchMovedMeanwhile, TestGitHubEmptyRepositoryPartsBackup
and TestGitHubSyncLargeLibrary (a ~38 MB instruction text syncs to a
second computer through Now). TestGitHubLargeBackup now uses 15 MB, to
keep covering one blob over the Contents API's limit.
docs/subsystems/sync-backup.md says how parts work and names the tests.

Record, at base origin/main e435b8867 plus this change (Go 1.26.8,
GOMODCACHE/GOCACHE pinned):
- gofmt -l internal/davsync: nothing. go vet ./... (darwin): clean.
  GOOS=linux go vet -tags nogui ./internal/davsync/...,
  GOOS=windows go vet ./internal/davsync/...: clean.
- go test -tags nogui -count=1 ./internal/davsync/... ./internal/settings/...
  ./internal/cli/... ./internal/backup/... ./internal/library/...: all ok
  (davsync 58s, settings 30s, cli 47s, backup 8s, library 127s).

Red on the old github.go (new tests, a shim for the new names): every new
test fails, the split ones with the reporter's 422 text, OlderMagpie with
"not a magpie backup" (the old code wrote the backup as is).

Broken by hand on the new code, each red:
- stale parts kept: TestGitHubSplitBackup
- part SHA not checked: TestGitHubPartsDamaged/a_part_changed
- blobs sent again on retry: PartsBranchMovedMeanwhile/another_file
- version check at the head skipped: SplitBackup, PartsBranchMoved/
  the_backup, and the older Remote, LargeBackup, BranchMoved tests
- no split (threshold at 64 MiB): SplitBackup, OneFileBackupStillReads,
  PartsOlderMagpie, PartsDamaged
- sizes not added up: PartsDamaged/sizes
- list's format "magpie-backup-parts": PartsOlderMagpie
- empty repository tries the Contents API first: EmptyRepositoryPartsBackup
- list's version 1: OlderMagpie still passes, since old Open also stops
  on the missing kdf; version 2 is a second guard, not the only one.

Not tried: the real GitHub API (no test repository here); the 16 MiB part
is chosen under the largest body seen accepted, not a documented limit.
The full go test ./... and internal/gui's tests were not run: the disk had
under 500 MB free. -race not run; no goroutine was added.
2026-10-23 10:35:44 +08:00
yetone f81913994a gateway: a Responses Lite compaction's summary request offers no tools, and a reply without a summary says what it held (WuSix on Discord)
WuSix (Discord) got "compaction: codex/gpt-6-astra failed to summarise
this conversation 3 times in a row (last: the model wrote no summary)".

codex/gpt-6-astra's catalog entry is Codex's own (codexcat.ownEntry), and
Codex's entry puts gpt-6 on Responses Lite: its tools go as an
additional_tools input item, none in tools. codexInputAs set "tools": []
for magpie's summary request but left that item in, so the model was
asked for the summary with every Codex tool still offered (tool_choice
auto, which codexBody sets anyway). A reply that is a function_call and
no message is "the model wrote no summary". codexInputAs now leaves the
additional_tools item out when it turns the trigger into the summary
prompt; calls in the history stay as they came.

The 502 and the held message now say what the reply held instead
(answeredWith: "(it answered with function_call shell)", "reasoning",
"nothing"), so the next report says which it was.

Hypothesis, not confirmed on a real reply (see below): the fake backend in
TestCodexLiteCompactionOffersNoTools answers a call whenever any tool is
offered, as an agentic model mid-task may. What the test holds is that
the request offers none.

Run at base 398803e3f (origin/main), in this worktree:
- TestCodexLiteCompactionOffersNoTools red before the fix (502
  "compaction: the model wrote no summary"), green after
- gofmt -l internal/: clean
- go vet ./internal/gateway/, GOOS=linux go vet -tags nogui, GOOS=windows
  go vet: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway/: ok
  (366.6s); only comments and docs changed after it started

Real ChatGPT backend, the owner's Codex sign-in (access token read
from ~/.codex/auth.json, not refreshed), 2026-10-23: the exact body
magpie sends upstream, captured from the gateway with a fake backend
(before and after this change), then POSTed to
chatgpt.com/backend-api/codex/responses with Codex's headers and
X-OpenAI-Internal-Codex-Responses-Lite: true. gpt-6-astra, effort low,
reasoning.context all_turns; a developer prompt, a user ask, a
function_call shell (namespace "functions") and its output, then the
compaction prompt. Three tries each:
  (a) old: additional_tools kept, tool_choice auto  200 x3, message
      (978/1010/1037 chars)
  (b) this change: additional_tools left out        200 x3, message
      (1176/1003/991 chars)
  (c) additional_tools kept, tool_choice none       200 x3, message
      (972/1009/1026 chars)
So the backend takes a Lite request whose history calls the "functions"
namespace with no additional_tools item: the fix doesn't 400. The old
request also summarised on this short history, so the cause of WuSix's
reports isn't reproduced on the real backend; with a long tool-heavy
conversation at a higher effort it may still be, and answeredWith will
say.

Not tried: a long conversation, efforts above low, and WuSix's own
conversation.
2026-10-23 09:20:23 +08:00