perf(web): measure snapshot geometry in batched backend calls, decided per entry

Merged
TH
1mo ago
+744-117

Summary

is visible, is hidden and every interaction that aims by ref asked the web backend for one ref's box at a time, and each agent-browser get box is a fresh Node process — 381 spawns for one check on a 408-ref page. That is why is visible on such a page died at the request envelope (ready timed out after 4500ms): 90 s of answers against a 45 s deadline, and is/wait accept no --timeout, so it could not be raised.

Geometry now goes through the backend's batch: the command list is written to stdin and the answer carries one entry per command. stdin reaching the spawn is the whole plumbing cost — ExecOptions already supported it, so runManagedAgentBrowser forwards it and runAgentBrowserCommand passes it through. Grouping lives in the provider: the projection asks for every ref it published, the fetcher decides how many per call.

A ref the backend could not measure is an ordinary answer about that ref, decided by the entry's own success — never by error wording, which is why isIgnorableBoxError is deleted. --bail is deliberately not requested: measured, it truncates output at the first failed entry. An answer that can't be paired back is refused typed, keyed by reason: batch-result-not-a-list, entry-count, entry-shape, entry-command; a capture whose refs all went unmeasurable refuses with snapshot-refs-unmeasurable (requestedRefs = the capture, groupRefs = the group).

Stacked on #3515. 6 files, 861 gross, three commits.

Review round

Round 1's three threads are replied to and resolved: the group-timeout question is answered by the live bound (see the evidence comment) and produced the grouping move that makes the all-unmeasurable refusal a claim about the capture; the {}-as-an-entry finding was taken and led to the echoed-command check; the per-group abort was deferred to the whole capture. Round 2 (6e67dcf22) is test discrimination and reporting precision and changes no dispatch behavior.

Validation

Tested at 72386de6e (rebased: #3547 e67b761af → #3515 20b6693ae → this). The restack onto the merged #3541/#3542 crossed the provider test file, and the resolution is a base move, not a behaviour change: the file's per-ref geometry tests stay deleted here because agent-browser-provider-rects.test.ts owns the batch contract, and snapshotExecutor keeps the capture-only answers (no get box branch, no allowFailure assertion) with main's extracted helpers — agentBrowserJsonResult, managedAgentBrowserCliArgs, withManagedAgentBrowserProvider from __tests__/test-utils.ts — rather than the local copies #3541 hoisted away. pnpm check:affected --run --base fix/web-snapshot-refless-text on that head under the machine-wide gate lock. Every way the batch answer can break the pairing now has a case only that check rejects, including an entry that echoes the right command with a box but states no success — reverting isBatchEntry to plain isJsonObject fails that case alone.

Earlier heads: tested at 6e67dcf22 (stack: #3547 0c4af434c → #3515 4adcae06b), restacked onto #3515 ddf73fdc5 as 9db4fb047 after #3547's review-round-2 kernel fix; the restack is a base move only — git diff 4adcae06b..6e67dcf22 and git diff ddf73fdc5..9db4fb047 are byte-identical patches, so every number below still describes this head. Managed agent-browser 0.27.1, base and head interleaved in the same loop iteration (host load 125–223 throughout, n=5 medians), each build behind a fresh daemon — full method in the "Measurement method and evidence" comment.

page (refs)opbeforeafter
index.html (408)is visible90.1 s, 3 of 5 runs refused outright5.9 s
index.html (408)fill90.2 s, 3 of 5 refused10.1 s
light.html (8)is visible3.9 s2.5 s
bothbackend spawns, one geometry pass385 (381 get box)4

The per-group bound the review asked about, measured the same way: 200 get box in 0.28 s, all 408 in 0.33 s, against the 30 s per-command budget. Verdicts unchanged: on a page with an on-screen button and one at top:-9000px, both builds answer identically.

14 tests in agent-browser-provider-rects.test.ts (the geometry seam, split out of the provider test file — the ratchet named that split as its fix) run through the real entry point with the command list read back from recorded stdin, each refusal asserting its own reason. Mutation-checked: deleting the list guard or the shape guard fails exactly one test each; dropping the signal threading fails the cancellation test. pnpm format clean, pnpm check:affected --run under the machine-wide gate lock on the tested SHA.

Closes #3516