Commit Graph
11 Commits
Author SHA1 Message Date
yetone 75d40ba48b ci: race gateway tests run in chunks taken in turn; 64 MB bodies are 20 MB under -race
The macOS -race gateway step split 3772 tests by sorted name into one
fixed share per core (3 on macos-latest), and the shares ran out of their
20 minutes with no test hung: run 42354008450 at 191f3c0af ended at 12m,
16m and over 20m (shard 2 in TestMediaJSONPastOldBodyLimit/images), and
42350695944 ran all three at ~19m20s. Two causes: the shares were uneven,
and a few tests scan tens of MB byte by byte, which the race detector
makes 14 to 30 times as slow.

Measured on mote (M5 Pro), -race, -test.v, old script, per test (plain
run in brackets): TestLoopGuardLeavesOrdinaryRepliesAlone 104s (7.6s),
TestLargeRequestEndpoints 104s (3.6s), TestRequestTailAfterOldLimit 33s
(4s), TestCodexBodyReadsPastOldLimit 14.6s (0.55s),
TestMediaJSONPastOldBodyLimit 10.7s (0.7s), TestCodexCompressedTailError
10.2s. Sums of test time per share: 487s, 641s, 761s.

- build/race-shards.sh: the tests go in ~118 chunks of about 32 (test N
  in chunk N mod m, so TestCodex..., TestCompaction... spread out), and
  each of the N workers takes the next chunk when it is done (xargs -P).
  Workers end within a chunk of each other. Each chunk logs in its own
  ::group:: with its time; the five slowest are printed at the end. A
  chunk whose process didn't finish counts as failed.
- oldBodyLimit (the pre-#118 64 MB) is 20 MB under -race
  (race_on_test.go), 64 MB in the plain run. 20 MB still passes every cut
  below 64 MB (bodyKept's 4 MB, the 8 MB and 16 MB reads); the plain Test
  step on ubuntu and macOS still sends the full 64 MB.
- TestLoopGuardLeavesOrdinaryRepliesAlone is skipped under -race: one
  goroutine feeds one loopGuard (loop_guard.go starts none), so there is
  no race to find; the plain run reads the whole corpus.

After, per test on mote under -race: TestLargeRequestEndpoints 40.7s,
TestRequestTailAfterOldLimit 13.05s, TestCodexBodyReadsPastOldLimit
5.1s, TestMediaJSONPastOldBodyLimit 4.46s, TestCodexCompressedTailError
3.1s, TestLoopGuard skipped: ~210s less race time.
A/B in one window on mote (same commit, binaries built from base and
change, 3 workers, load 15 to 30): old script with old tests 12m59s
wall (red: TestTranslatedStreamKeepsClientAlive, the load-timing test
of #2711/#2737); new script with new tests 10m57s, green, slowest
chunk 62s. On 3-core CI the wall should be about the total over three
plus a chunk, instead of the slowest share.

Broken by hand (wsl-run, Linux): defaultBodyLimit 16<<20 under -race
turns TestCodexBodyReadsPastOldLimit, TestLargeRequestEndpoints and
TestRequestTailAfterOldLimit red (body rejected / 413); defaultBodyLimit
48<<20 in the plain run turns the same three red. So the race run guards
the read-whole path past 16 MB and the plain run still guards 64 MB.
TestCodexCompressedTailError and TestMediaJSONPastOldBodyLimit stay green
with either cap: they never guarded the limit (true before this change).

Run: gofmt -l; on mote GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./..., go vet ./..., go vet -race ./internal/gateway; the seven
touched tests plain on mote (all pass, 21.9s); the whole gateway package
under -race through the new script on mote twice (one red,
TestBurstTellsNoSpeed/responses_from_chat_burst, the load timing of
#2719; the second run green).
Not tried: the race run with a 48 MB cap (it would pass: under -race
nothing now covers 20 to 64 MB, the plain step does); a CI run before
the push.

Fixes #5361
Fixes #5320
2026-11-07 19:45:30 +08:00
yetone b7ceb53fe4 provider: WorkBuddy's built-in is retired; its plugin serves it
workbuddy and workbuddy-ai join retiredBuiltins, as Zed did in c0605abc2
and Qoder in 43cc3171d. @magpie-community/opencode-workbuddy-auth serves
both, moved or not.

Removed (built-in only):
- provider: workbuddy_models.go (the model list); in workbuddy.go the
  sign-in, token renewal, usage/credits reading, request signing and the
  site's model fetch; the WorkBuddy cases in account.go (Accounts),
  logins_on.go, logins.go (list/switch/forget), login_usage.go,
  subscription_usage.go and signin.go; WorkBuddyBaseForTest, now unused.
- The built-in tests: workbuddy_test, workbuddy_signin_test,
  workbuddy_accounts_test, workbuddy_ai_test, workbuddy_body_test,
  workbuddy_enterprise_test, workbuddy_free_test, workbuddy_names_test,
  workbuddy_spare_free_test, workbuddy_refused_test (provider), and
  gateway/workbuddy_refused_test.

Kept, and why:
- migrate_workbuddy.go (the mover) with what it reads: wbSite, wbCreds,
  wbOwn/wbAuthPath (the desktop's file, sent as a marker), wbLogins,
  wbTokens (back drops a renewed pair).
- workbuddy_checkin.go: the daily check-in now walks the plugin's
  accounts only and sends through the plugin's fetch (a.via); wbCallVia,
  wbNum and the site's api() serve it, and plugin_usage's host.
- WBRestricted/WBRestrictedHint: the gateway reads the plugin's 11140 by
  them. textOnly: applied to the plugin's lists.
- draw_workbuddy and search_workbuddy in the gateway: they serve the
  plugin's provider. The PLUGIN-SERVED notice in workbuddy.go.
- The WorkBuddy agent target (internal/agent) is untouched.

Tests changed in meaning:
- TestFetchNewAccount, TestFetchNewRetriedSoon and
  TestFetchingNewOnceStarted used WorkBuddy as the built-in signed in;
  they use Codex now (codexSignedIn, codexListedAt), same assertions.
- TestFetchPlanWithoutList uses local models; TestWorkBuddyFetchModels,
  TestWorkBuddyAIGLMIsTextOnly and TestOwnStoreSignInAgainDropsTheReading
  (WorkBuddy case) are gone with the code.
- Check-in: TestWorkBuddyCheckinSignedIn is gone; the fixture's account
  is a plugin account signing through via; PluginUnderItsOwnID became
  TestWorkBuddyCheckinPluginAccounts (plugin accounts listed, a built-in
  login left out). TestCheckinAccountsListed reads a moved plugin.
- TestWorkBuddyMover seeds the desktop's logins.json row: retired, the
  built-in no longer writes it, and an existing user's row is what moves
  (red without the row).
- Gateway: the WorkBuddy draw and search tests run through the fake
  plugin (besideFake), without the built-in's header checks;
  TestWorkBuddySearchesForItsModels folded into
  TestWorkBuddyPluginSearches (refusal and search-off checks kept);
  TestLoopEndsWorkBuddysReply is the plugin route only;
  TestWorkBuddyRestrictedRestsHours lost its built-in translation case.

Run:
- gofmt -l internal: empty
- go vet -tags nogui ./...; GOOS=linux and GOOS=windows the same: clean
- go test -tags nogui -count=1 -timeout 45m -run 'WorkBuddy|workbuddy|Checkin|CheckIn|FetchNew|FetchingNew|FetchPlan|Migrat|migrat|Mover|Moved|Retired|Retire|SignIn|Plugin|Draw|Search|Loop|Redact|Restricted|Images|TextOnly|Qoder|BuiltinsSay|AsksOwn|Loopback' ./internal/provider ./internal/gateway ./internal/cli ./internal/gui ./internal/qoder
  first run: gateway, cli, gui ok; provider red on TestWorkBuddyMover
  (above); after the fix provider ok (99s).
- Not run: whole packages, the full suite, the GUI node suite.
2026-10-17 23:11:00 +08:00
yetone a0a4d55ef7 gateway: a passed-through reply whose reasoning loops before it says anything is asked again once, and its tries counted (#2436)
lqisgod's five looped replies (pi → WorkBuddy, Chat in and out) each
ended at once with empty tries and status 200. The once-only re-ask of a
reasoning loop (loopReasks) lived only in streamTranslated's onLoop, so a
same-protocol passthrough had holdWriter.reask nil and cutLoop ran on the
first trip. A re-ask that did happen in place wasn't counted in the usage
record's tries either (tries came from route.Tries alone).

Now holdWriter lets such a try go (mayReloop/letGoLoop) when its
reasoning looped, nothing has spoken (loopGuard.spoke: no text or call),
the request has its re-ask left and its context is alive, and either
nothing of the try reached the agent (held bytes dropped, any protocol)
or the agent speaks Chat (bytes written up to the end of the tripping
event, the next try's chunks follow). The fallback loop records the try
as failLoop with reloopedError and asks the same provider again after
retryPause. In-place re-asks add to tries too. An Anthropic or Responses
stream whose reasoning already reached the agent still ends with the
loop error: a second message_start/response.created can't follow. The
plugin host's fetch goes through the same holdWriter
(TestLoopEndsWorkBuddysReply's plugin subtests).

Tests: loop_guard_test.go's chat case now expects 2 asks and an answer;
every passed-through `data:` line is valid JSON; the usage record has
Tries == asks and no error. docs/subsystems/gateway-routing.md updated.

Broken by hand, each red:
- hw.reloop = false (old behaviour): TestLoopEndsTheReplyOnEveryProtocol,
  TestLoopEndsWorkBuddysReply, TestReasoningLoopIsAskedAgain fail.
- reasked not added to tries: the same three fail with "usage record's
  tries 0, the vendor asked 2 times".
- spoke never set: TestLoopAfterTextIsNotAskedAgain fails.

Run: gofmt -l clean; go vet -tags nogui ./internal/gateway ./internal/usage
with GOOS=darwin, linux, windows ok; go test -run Loop ./internal/gateway ok.
Not tried: a real WorkBuddy account looping (the loop can't be forced).

Full suite: go test -tags nogui -count=1 -timeout 45m ./... on base
b03031738, every package ok, no FAIL line.
2026-10-16 01:55:47 +08:00
yetone eb7199e120 gui: Routing is a plugin's page, its script, style and words in plugins/routing (P2)
P2 of docs/subsystems/plugin-runtime.md, the third page after Sessions
and Library.

- routing.js and routing.css move to assets/plugins/routing/ (client.js,
  routing.css). Its part's html is the page's head and boxes that were
  index.html's <main id="view-routing">; the rest is drawn by
  routingPage, run at mount since it builds on app.js. It keeps itself
  after that as it did (its own hidden, the language, focus), so its
  hooks are dirty and discard, a routing group being edited, which
  show() and the window's close ask through magpie.call:
  window.routingDirty and discardRouting are gone.
- plugins/routing: Essential, Requires window and gateway, in use while
  the user has a routing group (not Auto, not Hidden), since the page is
  where it is edited. The gateway routes the same with it off.
- With it off, what leads to the page goes too: the nav and panel tabs
  and the panel's section (data-feature="routing"), the guide's Open
  Routing, Providers' "Make a routing group of …", the Usage list's
  View routing and its time as a link, the context card's Latest
  request. A panel left on its Routing tab shows Agents.
- What other pages use of it stays on window: openRoute (context.js),
  kindName, swapWhy, routedWhy (Usage's Requests), newGroupWith
  (Providers), panelRoutingShown (the panel).
- The 505 strings only Routing says move from i18n.js to
  plugins/routing/i18n.js (4 languages); i18n.js 17048 → 15032 lines.
  The plugin's own name and line stay in i18n.js: the Plugins page
  says them with the plugin off (TestBuiltinsTranslated).
- Tests and comments that named routing.js name the new path (gateway's
  antigravity_rest and loop_guard, codeassist.go, usage.go,
  web_compress, group_member_info, assets_revalidate, font-cascade,
  win-fonts, three routing-*.test.cjs). builtins.test.cjs and
  builtins_test.go count seven built-ins and switch Routing off: its
  tabs go, the page shown stays.
- docs: plugin-runtime.md, gui-shell.md, gateway-routing.md.

Run, first on origin/main 3ec45e715, then after rebasing onto af27b70b4
(main's routing.js, css, app.js and i18n.js changes since were carried
into the moved files; its new Routing words, as the rules' conditions,
are in the plugin's i18n.js):
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- go test -count=1 ./internal/gui ./internal/gateway ./internal/usage
  ./internal/pluginrt ./plugins/...: ok (gateway 1800s under load,
  -timeout 45m; gui with -skip TestMainWindowCorners, #1936).
- All 193 GUI test files, 3 at a time at load ~250, Chromium and WebKit,
  at the Usage commit on 743fcc035: 185 and 186 green. Every red run
  alone here and on a just-fetched origin/main c524bc018:
  - the same on main: routing-model-rest (#2115), routing-wb-restricted
    (#1905), usage-agents-hide (11 of 16 in both, #2211), usage-fold
    (#2163: 12 of 14 here, 9 of 14 on main over 7 runs, the same 4px),
    quota-count-wrap and quota-name-translated in WebKit (#2228);
  - red only under load, green alone on both: routing-flood (#2215),
    routing-log-icons, usage-ledger (#2211), and three plugin-* files
    whose tree was rebased under them mid-run.
- days-fit, failed-open, side-calls and burst-speed, red on main after
  cf455ebd5, are fixed before this commit (#2134, d692b2548).
2026-10-15 01:32:12 +08:00
yetone 1eaf1e890a gui: Sessions is a plugin's page, its script, styles and words under assets/plugins/sessions (P2)
The first page of P2 to leave app.js's core. sessions.js and sessions.css
move to assets/plugins/sessions/ (client.js, sessions.css). The page
registers through the kernel as magpie.plugin("sessions"): mount takes its
<main>, which the kernel now makes, open and relang read it again, and
reveal is the Usage page's way in. window.loadSessionsPage and
window.openSessionOnPage are gone. app.js reaches the page only through
magpie.call, and show() takes a page's title from its part. The plugin's
manifest lists i18n.js, sessions.css and client.js.

Words: the kernel's magpie.strings(dict) adds a plugin's words to I18N.
A key that is already there is logged and not taken, since the later one
would silently win. The 65 keys only the Sessions page says (own-keys over
every asset, Go and index.html) move, as written, from i18n.js to
plugins/sessions/i18n.js. tests/strings.cjs reads i18n.js and every
plugin's i18n.js as the page has them. gui-de/ja/zh-tw use it, and
i18n-keys now checks that no key is said twice across files and that a
plugin's words are in every language. TestBuiltinClientsLoaded takes a
.css entry as a <link> in <head>, and a script between kernel.js and
app.js.

Docs: plugin-runtime.md (Words, Pages moved out: Sessions), gui-shell.md,
gateway-sessions.md.

Run:
- go test ./internal/gui/ ./internal/pluginrt/ ./internal/gateway/: ok.
- gofmt clean. go vet darwin, GOOS=linux -tags nogui and GOOS=windows on
  gui, pluginrt and plugins: clean.
- GUI, in both chromium and webkit, 40 files, all green:
  - the sessions-* and sess-* tests, session-identity, routing-sessions,
    account-mask-sessions, usage-session*, gateway-conversations;
  - plugin-kernel, the plugin-move* tests, font-cascade, win-fonts;
  - i18n-keys, gui-de, gui-ja, gui-zh-tw.
- session-terminal's red under parallel load is the same on origin/main
  591ed58b5. It is fixed at its cause in the commit before this one.
2026-10-14 08:33:24 +08:00
yetone 6d1c7df9e7 gateway: a reply looping on the same few words with no line or sentence's end ("mcp mcp mcp …") is found and ended, as a loop of lines is (#1489, bfxh)
bfxh: the model loops, saying "mcp" over and over. The loop guard cuts a
reply into lines and sentences and finds a loop in 256 of them. Words
repeated with no line break and no sentence stop form no such unit: the
text is cut only every unitMost (4096) bytes, so 256 units would be about
1 MB, far past any reply's output limit. A loop like that ran on to the
limit.

A unit cut at unitMost, with no break in it, is now read by itself
(runOnWords). It is a loop when it is one piece repeated (period of at
most 64 bytes, "mcpmcp…" or "重复说mcp重复说mcp…"), or when its words, at
least one per 32 bytes, are no more than 8 different ones. Two such units
in a row, about 8K characters or 2,000 tokens, end the reply. Text and
reasoning are both read. Reasoning that loops before anything is said is
asked again once, as 8424a004 does for a loop of lines. A loop broken
into lines longer than a unit still counts. The error says "the same over
and over without a break" and quotes the words.

Run:
- TestLoopGuardFindsARunOnLoop (new): spaced, comma, unspaced, a few
  words, Chinese; as text and as reasoning; found within 3 units.
- TestLoopGuardLeavesOrdinaryRepliesAlone also feeds, with no break at
  all: gateway.go, LESSONS.md, i18n.js, a log, a CSV, hex, table rules,
  and a one-line JSON array of 2,000 records. None trips.
- Break checks: runOnUnits = 1000 turns the new test red. No distinct
  limit and no word density check turns 10 of the ordinary texts red.

- TestArchiveWholeBodies' long vendor streamed "lorem ipsum dolor "
  25,000 times with no break, which is such a loop and is now ended.
  Its words are now word0 word1 …, still 450 KB, so it tests the
  archive again, not the guard.
- go test -tags nogui ./internal/gateway ./internal/provider: ok.
  gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui clean.
2026-10-10 18:54:16 +08:00
yetone 3a1ade9729 gateway: TestReasoningLoopIsAskedAgain takes the two tries' let-go in either order
The gateway cancels the looping try and asks again at once, so the next
try can end and report before the first try's handler sees its write fail.
macOS CI got them in that order (ddd4f431's run: "let go: the looping try
false, the next true"). The next try only ever reports false, and the
looping one reports false only after 20s unreleased, so one true and one
false in any order still proves the looping try was let go.

Run: reproduced CI's message on the old test by sleeping 300ms before each
let-go of true; the new test passes with that delay and without it
(-run 'TestReasoningLoop|TestLoop' -count=5).
2026-10-10 17:26:26 +08:00
yetone 8424a004e2 gateway: a reply whose reasoning loops before it says anything is asked again once in place, not ended (cdredfox on X)
cdredfox (X, 2108799237324701897): WorkBuddy AI's DeepSeek v4 flash through
magpie often stops half way with "magpie ended this reply: the model's
reasoning was stuck in a loop ... ("OK." "Writing." "Now." "Producing."
"Let me output." ...)". That is the #1359 loop, found correctly; nothing
magpie sends causes it (12 direct runs on the real account, effort
high/max, temperature 0/1/unset, a 900-line file: no loop, the same
"OK. Writing." precursors at the tails), so the model does it on its own
now and then, and the agent's turn ended on it.

When magpie translates the reply into the agent's protocol
(streamTranslated: Claude Code, Codex, Gemini clients) and the loop is in
the reasoning, before any text or call and not on a continuation, the
try is let go and the same request asked again once (loopReasks), the
way an empty reply is (#667): the agent keeps the reasoning it has, the
next try's follows in the same stream. A loop on that try ends the reply
with the error as before. holdWriter.onLoop lets streamTranslated take a
trip before cutLoop ends the stream. A text loop, a loop after a text or
call, and a Chat stream passed through stay ended at once.

Run: go test ./internal/gateway (ok); -race on the loop and empty-reply
tests -count=3 (ok); gofmt; GOOS=linux,windows go vet. On old code
TestReasoningLoopIsAskedAgain and the updated
TestLoopEndsTheReplyOnEveryProtocol/TestLoopEndsWorkBuddysReply fail
(the vendor is asked once). Real account: a sandbox gateway in front of
a proxy signing for WorkBuddy AI (deepseek-v4.1-flash); the proxy
injected the reporter's units into the first real stream, the guard let
it go after 257 lines, the second real request answered, and the agent
got one whole message (Anthropic: message_stop, no error; Responses:
response.completed).
2026-10-10 14:51:42 +08:00
yetone 229ce19acc gateway: the loop guard's end-to-end tests bound how soon the loop was cut by what reached the agent, not by how far the fake vendor wrote ahead of a slowed gateway (#1443)
Cause: loopCut failed when the fake vendor had sent more than 2000 lines
by the time it saw its request let go. That count isn't the guard's: the
cut is made in holdWriter.Write, on the write that trips it, and cancels
the vendor's request there. But the vendor's writes succeed as long as the
sockets' and transports' buffers take them, so it runs ahead of a gateway
that reads slowly. Under load (CI macOS -race, a full run at load ~35) it
got ~2,800-3,200 lines ahead of a cut the agent saw at the 259th line.

Fix (test only, the guard was already deterministic): loopingVendor sends
at most 2000 lines of its loop, then holds its stream open until its
request is let go (20s, else it says it wasn't). Being let go therefore
means the guard found the loop within those 2000 lines, however the test
is scheduled. How soon it cut is now checked on what reached the agent:
the loop lines in the stream are at most the guard's window (256) plus one
32K read of the vendor's stream, which the cut's write sends whole.

Run:
- Reproduced by injecting a 300us sleep into holdWriter.Write (not
  committed): the old test failed 140 of 180 subtests (-race -count=5
  -cpu 1,2,4, 16 busy loops beside it), every route and protocol but chat,
  "let go only after 2754..3082 lines", the vendor up to 8322. The agent
  got ~259 loop lines in each.
- The new test with the same sleep and load: -race -count=50 -cpu 1,2,4,
  1800/1800 subtests pass (built-in and plugin, chat/anthropic/responses/
  gemini, and TestLoopEndsTheReplyOnEveryProtocol). At most 470 loop lines
  reached the agent (the bound is 583; 256 + 32768/141 is ~490).
- Without the sleep, under load: -race -count=20 -cpu 1,2,4 of these plus
  TestLoopGuardOff and TestLongReplyThatDoesNotLoopGoesThrough, all pass.
- The test goes red when the guarantee breaks: with cutLoop's h.stop()
  disabled ("the vendor's request was not let go", built-in anthropic,
  responses, gemini; chat is still let go when the failed write ends its
  copy), and with the guard's trips dropped for its first 800 writes ("the
  loop was cut only after 1038 of its lines reached the agent").
- gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows) ./internal/gateway,
  go test -race ./internal/gateway under a temp HOME.
2026-10-10 08:36:30 +08:00
yetone 319b72c7a5 gateway: the loop guard's long-reply test streams 1000 lines, not all of gateway.go, and waits a minute (69c21cdd's macOS -race CI red)
TestLongReplyThatDoesNotLoopGoesThrough/gemini failed on macOS -race in
run 37946485821: "the stream never ended". It streamed all of gateway.go
(199KB, ~20k events of 11 bytes) through the gateway on each protocol, and
askStream waited 20s. Locally under -race each protocol took ~5s with the
guard and ~5s without it (5.0s off, 6.0s on for gemini), so the time is
the gateway translating 20k events, and CI's runner is ~4x slower: a
bound with no room, not a slow guard.

- The test streams gateway.go's first 40KB, cut at a line end (1001
  lines, several times the guard's 256-unit window).
- askStream waits a minute.
- TestLoopGuardLeavesOrdinaryRepliesAlone feeds the first 256KB of each
  file (app.js and i18n.js run to megabytes): 72s -> 37s under -race.

Ran: gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows), go test -race
-run 'TestLong|TestLoop' ./internal/gateway (long reply 3.9-4.7s per run
for all 4 protocols).
2026-10-09 23:14:39 +08:00
yetone 69c21cdd77 gateway, settings, gui: a reply whose reasoning or text has become a loop of the same few lines is ended with an error the agent can act on, instead of running on to its output limit (#1359, Moody-Sin: WorkBuddy's DeepSeek v4.1 flash at max effort reasoned "Now." "Writing." "Go." "Let me write." "OK." "Producing." … until max tokens, while dsh waited and Pi hung)
holdWriter.Write, which every streamed try goes through (passed through or translated; a key's, a built-in subscription's, or a plugin's fetch, as a moved WorkBuddy's), feeds a loopGuard (loop_guard.go). It reads the reasoning and the text of each protocol's deltas (Anthropic, Chat, Responses, Gemini) and cuts each into units: lines and sentences, compared without case or a closing stop. A list's "1." or a decimal doesn't end a sentence. A unit with no word in it (braces, rules, 0x00, hashes, rows of numbers) isn't counted. When the last 256 counted units of either are among 24 or fewer distinct ones, the try is cut. What came with that write goes out, then the protocol's stream error (Anthropic error event, Chat error chunk, Responses response.failed server_error, Gemini 502 UNAVAILABLE), naming the loop and quoting its units, and the vendor's request is cancelled. The cycle needn't be exact; the reporter's has 9 units in two variants. It falls back to nobody and rests nobody (fail "loop"), and the usage record's err_type is reply_loop. A reply sent whole (no stream, or Gemini without alt=sse) isn't read. Settings › Models › Replies › Stop looping replies (noLoopGuard, on by default) turns it off; new strings in zh, zh-TW, ja and de.

Tested:
- loop_guard_test.go, with the screenshot's 28 lines cut into random 1–7 byte pieces, as one line, and in Chinese. It trips within the window. It reads every protocol's shapes, and tool-call arguments never trip it.
- No trip on magpie's own sources fed as both reasoning and text: gateway.go, fallback.go, anthropic.go, app.js, i18n.js, app.css, routing.js, sessions.js, index.html, docs, LESSONS.md and go.sum. Nor on generated numbered lists, logs, CSV, hex, rules and base64.
- Through the gateway on all 4 protocols with a fake DeepSeek, and on WorkBuddy both built-in and through the community plugin's fetch in the plugin host (TestLoopEndsWorkBuddysReply). In each case the agent gets the reasoning and then the error, the vendor is let go within 2000 lines, nobody rests, and usage keeps reply_loop.
- gateway.go as 4,900 lines of reasoning passes whole on every protocol. With the setting off, a loop runs to its end.
- With the guard removed, the end-to-end and WorkBuddy tests fail on every route.
- The built binary (magpie serve on 127.0.0.1:3592, temp HOME, fake DeepSeek upstream), checked with curl on chat, messages, responses and gemini alt=sse. Each loop ended with that protocol's error, the upstream was let go after 256–271 lines, and the usage log had err_type reply_loop and routing fail "loop". The long gateway.go reasoning came through to [DONE], message_stop, response.completed and STOP. With noLoopGuard, all 100,000 lines passed.
- GUI: loop-guard-setting.test.cjs in Chromium and WebKit, en/zh/ja/de, at 1100 and 420 wide. gui-ja, gui-de, gui-zh-tw, i18n-keys, member-model-setting, click-scroll and settings-sections/groups pass.
- go vet, GOOS=linux/windows vet and builds, go test -race ./internal/gateway ./internal/settings, and the full go test -tags nogui ./... all pass.

Not tried with the real WorkBuddy or DeepSeek model.
2026-10-09 22:32:31 +08:00