Commit Graph
4 Commits
Author SHA1 Message Date
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00
yetone d18d48e90f routing: a flight's points along a wire are read from its d, not asked of the browser each frame (#3164)
getPointAtLength walks a path from its start on every call. The flights
pose three points a frame, and along the wires to keys hundreds of rows
down (two groups of 500 and 300 keys open) WebKit spent 810-860 ms of
every 5 s in it, over half of the page's time in frames (1.43-1.51 s).

pointAt now flattens a d once, into points no more than 2 px apart along
its curve's control points, with the length along it to each, and finds
a point by a binary search between two of them. Only what the stage
draws with is read so (an absolute M, then L, Q and C); any other d is
still asked of the browser, a point every ptStep, as before. The wire
ends (tips) are still asked of the browser, once a d.

Run:
- the sandbox app (bin3164, fake upstream, 501 + 301 keys, a request
  every 0.3 s), WebKit, both groups open, 5 s, 2 runs each: points asked
  4759-5845 -> 104-132, their time 854-860 ms -> 19-38 ms, time in frame
  callbacks 1461-1507 ms -> 860-874 ms.
- accuracy, every wire and flight path on that page (815 paths, 162k
  points): the flattened point is within 0.12 px of Chromium's
  getPointAtLength and 0.76 px of WebKit's; WebKit's own getTotalLength
  is 1.39 px off Chromium's on the longest, so most of that is WebKit's.
- frames in 10 s (4 runs, alternating): 462-541 before, 446-463 after,
  within the noise of a machine at load ~6. The frames are bound by
  WebKit's painting now, not the script; this saves CPU, not frames.
- routing-busy-frames now counts points asked of the browser per d
  measured (<= 2): 6 of 6 pass here, 6 of 6 red on origin/main
  ("5737 points asked of the browser along the 1749 d's measured").
- every routing*.test.cjs and panel-routing*.test.cjs (112 files,
  --test-concurrency=6, load ~8): 1418 tests, 1365 pass, 53 fail. The
  reds are those of 3173440ca and 9fc382e66 (#3408-#3412, #3094, #3096,
  #3637) and three that pass alone at this head: routing-mode-goes 40/0
  (#2151), routing-model-rest 20/0 (a read before the frame, fixed in the
  next commit), routing-log-icons 14/0 (#3645).

Not tried: the macOS app's own WKWebView (Playwright's WebKit here).
2026-10-26 03:45:23 +08:00
yetone 81a58d2f35 gui tests: routing-busy-frames counts paths measured again for the same d, not lengths against frames (#3557)
The bar was path lengths < 8 × frames drawn. The lengths follow the
paths the flights and the moving rows make (~1,800 in the 3s), not the
frames, so a busy machine that drew 228 frames instead of ~300 went red
with the page doing just what it should.

What the test is about is that a path is measured once for each d it
has. The page's getTotalLength and getPointAtLength are now wrapped to
remember the d each path was last measured at: a length measured again
for the same d, or a point again at the same distance along the same d,
is counted. The bars: lengths again ≤ 1/20 of lengths, points again ≤ 2
for each d measured (a wire's two ends are asked for by its tips and
among its points). Neither depends on the frame count.

Run at this head (frames3557 worktree on origin/main 8299409e4):
- routing-busy-frames.test.cjs: 6/6 pass, chromium and webkit, en/zh/de:
  ~1,750 lengths, 0 again; ~5,800 points, ~320 again (bar ~3,500).
- Broken by hand: measure() measuring every call: 6/6 red (9,807 of
  11,574 lengths again). The point cache alone off: webkit 3/3 red
  (6,892 points again against a bar of 3,534).

Not tried: the file under the whole GUI suite at load ~40 where #3557
was seen.
2026-10-26 00:14:31 +08:00
yetone 588f87a126 gui: the Routing page measures a path again only when it moves (yg6888 on X: "打开页面很卡")
yg6888 on X: the Routing page lags, with 29 accounts in a group, nested
sub-groups and three agents sending at once.

Cause: every frame posed every flight, and each pose measured the paths
it flies along and the wire ends it meets with getTotalLength and
getPointAtLength, again on every frame. Each render also re-set every
via's "d" and formatted every row's token counts with a new
Intl.NumberFormat (toLocaleString).

Fix:
- measure() keeps a path's length in a WeakMap and measures again only
  when its "d" changes.
- tip() keeps its result.
- A via's "d" is set only when it changed.
- pointAt() reads points measured every 8 px along a path, cached per
  "d", and interpolates between them. The chord is off by under a
  pixel.
- ledNum uses one Intl.NumberFormat per language.
- metaFit runs only when rows were redrawn.

Numbers: CPU profile of the page for 40 s under a busy sandbox gateway,
machine load ~250:

                    main thread  rAF calls  per call  getPointAtLength  getTotalLength  ledNum
  before            28.0 s       4047       6.9 ms    5.58 s            5.04 s          1.13 s
  after             15.9 s       3635       4.4 ms    1.50 s            0.50 s          0

The GUI test counts per frame: ~15 lengths and ~27 points before, ~4
lengths and 13-16 points after. Paths still move during the rows' FLIP
slide and the agent tick, and they are measured again then.
renderHist's own time (~1.8 s) and getBoundingClientRect (~1.2 s) are
not changed here.

Test: routing-busy-frames.test.cjs, in Chromium and WebKit, en/zh/de.
It pumps three agents' requests and asserts fewer than 8 lengths a
frame, fewer than 200 formats, and token titles grouped in the page's
language. Red on the old client.js and app.js. Example green:
"chromium en 382 frames, 1519 lengths, 4864 points, 0 formats".

Run record, the three commits on origin/main d9c6a60d8 (machine load
~270-480, with other sessions' GUI suites running):
- gofmt -l: clean. go vet ./... on darwin, GOOS=windows and
  GOOS=linux -tags nogui: exit 0.
- go test ./... -count=1 -timeout 45m (sandbox HOME, 11:02-11:34): 64
  ok, 1 FAIL: internal/gui TestCoreScriptBudget, app.js 155 bytes over
  from the first ledNum. ledNum was made smaller (1,268,907 of
  1,269,000 bytes), then internal/gui -count=1 alone: ok (329 s).
- Before the rebase (723f40778 on 9588501c0): internal/gateway ok
  (2064 s), internal/agent ok at -timeout 120m (it timed out at 45m
  at load ~700, #2869), internal/gui red only in
  TestSetAnswersWhileDevinAndProvidersHang (#1375).
- GUI suite, all 140 files, Chromium and WebKit, every language, at
  load 400-840 on 723f40778. Every red was run alone against
  9588501c0, and none comes from this change: routing-bodies
  (#2559/#2658), routing-keys-fold and routing-model-rest (#2658),
  routing-mode-goes WebKit (#2151, head 2/20 vs base 3/20),
  routing-request-metrics (#2571), routing-wb-restricted (#1905),
  usage-agents-hide (#2276/#2399), usage-fold (#2399), usage-checkin
  WebKit Qoder (#2549), usage-refresh (#2184). 5 s first waits under
  load were added to #2900. The usage-ledger route-callback race at
  page close was filed as #3001.
- After the rebase, each alone in both engines: routing-busy-frames,
  routing-intent-entry, routing-key-windows, routing-pause and
  usage-ledger were green.
- After the smaller ledNum, each alone, both engines, all languages:
  routing-busy-frames 6/0 (one later run lost Chromium's launch at
  180 s twice; Chromium alone right after: 3/3), usage-ledger
  Chromium 16/16 and WebKit 17/0. usage-ledger-leave and
  routing-request-metrics were red in browser launch and 5 s waits on
  this head and on d9c6a60d8 alike (#2900, #2571). Added to #2900:
  a WebKit zh usage-ledger run hung after a 5 s timeout.
2026-10-20 13:26:12 +08:00