Commit Graph
2 Commits
Author SHA1 Message Date
yetone 8f9bc3fccf gui tests: the 37 other Settings tests act on rows once the page has drawn its last read of the settings, as the masking-rules tests do since #1653 (#1659)
Opening Settings reads the settings twice: the page's own read
(showView), then the window's load() once the state is in. Each read
redraws every row. A test that found a row after the first draw, and
then called scrollIntoViewIfNeeded or boundingBox on it, failed when the
second read landed in between. The errors were "Element is not
attached", or a null box. #1653 fixed the three masking-rules tests and
listed these 37 in #1659.

Each of the 37 now calls watchSettingsReads(page) before every
page.goto, and settingsDrawn(page) right after it. Right after goto is
exact for ?view=settings: at boot, show(view) asks for showView's read
before load() runs. load() sets load.done in the same run that then asks
for its own read, so settingsDrawn's "load.done and every read asked
for drawn" holds only once the second read is drawn. For a test opened
on another page that clicks into Settings later, load is done by then,
the click makes the only read, and the wait passes at once.
watchSettingsReads now watches a page once, however many times it is
opened, since some of these tests open one page several times. The
page is unchanged.

Reproduced with a generic injection (scratchpad inject1659.cjs, loaded
with NODE_OPTIONS=--require). A route added at each goto holds the
page's second GET /api/settings. It lets the read go just as the test
calls scrollIntoViewIfNeeded or boundingBox, or waits on the page with
waitForFunction (which settingsDrawn is), with a 4s timer as a backstop.
This is #1653's injection, made generic.

Before, injected, both engines, all languages:
- 5 files red with the issue's error:
  - github-token: null box.
  - member-model-setting, searcher-pick, search-first and update-wait:
    "Element is not attached to the DOM".
- 4 files red on a check of a row drawn from the first read:
  model-suffix-own, otel, readable-focus and warm-at-times.
- 28 green.

After, injected: 36 of the 37 files green, every held read let go by
settingsDrawn's wait. otel stays red in WebKit at 360px. It is red the
same way with no injection, on origin/main's own copy of the test. That
cause is separate (the narrow nav laid out after setViewportSize
returns) and has its own commit next.

Plain (no injection), both engines, all 37 files: 460 cases passed and
2 failed, both otel's WebKit 360px check above.

The 8 files red under injection before, injected again after,
5 rounds: 390 of 390 cases passed.
2026-10-12 03:25:47 +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