Skip to content

perf(browser): reuse snapshot refs and screenshot metadata - #133598

Merged
steipete merged 1 commit into
mainfrom
codex/perf-browser-preparation
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-browser-preparation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Browser snapshots currently keep parallel duplicate-ref arrays and maps, then clean them up after construction. Delta finalization parses the same formatter-owned lines twice. Labeled screenshot routes also probe source dimensions already read by normalization, and probe unchanged output again.

This PR removes that repeated preparation at the existing owners. Duplicate-group counts retain each backend’s omitted-versus-zero nth contract, including stored ARIA’s final-record lookup for overwritten input refs. Delta requests carry parsed refs and the truncator’s accepted source-line count into visibility filtering; ordinary capped requests still parse only retained lines. Screenshot normalization carries its private source dimensions to both annotation routes, and identical output buffers retain the original annotations without another metadata probe. No public SDK, config, schema, dependency, navigation authority or cache lifecycle changes.

Three distinct mechanisms are proposed, with four snapshot backends sharing one grouping mechanism. The formatted production delta is +88/-191, net -103; four existing test mocks add the new private return field (+4 test/support lines). An iframe-assembly proposal was rejected because a malformed raw-role control changed output; it is excluded.

The snapshot proof passed 1,299 scenarios / 3,897 exact comparisons across complete copied owners. The native image proof passed 34 cases across complete routes and actual Rastermill/Photon processing, including exact bytes, EXIF orientation, budgets, annotation geometry and output identities. Twelve fresh serial timing children retained all 5,508 samples across 90 workloads in both process orders. Source/dependency bindings and process cleanup were checked; all preflight output projections matched.

Representative warm local results: unique ARIA ref construction 1.55–1.77× faster; complete 32-row Playwright delta snapshots 1.36–1.41×; uncapped delta finalization 1.45–1.53×; labeled unchanged screenshot preparation 2.73–3.36×. The heavily capped large delta control and real native resizing (about113 ms) were approximately neutral. These are local owner costs with explicit browser/transport/storage substitutions, not end-to-end browser or provider latency, and ablation gains must not be multiplied.

Negative controls are retained: ordinary unlabelled screenshot POST cost 10.708→12.215µs /10.979→12.029µs (+1.05–1.51µs). Empty-label cases were mixed, including a medium-image +10.14%/+0.52% cost. The canonical source-dimension owner is retained without fixture-specific tuning branches. No retained-memory or whole-turn speedup claim.

The integrated owners exactly match the measured candidates. All260 existing tests across15 files pass; after rebasing onto current main,267 tests across16 files (including the updated pinned-transport suite) pass, as do the full build and full changed-file checks (including production/test types, lint, dead exports and boundary checks). Independent complete-owner review and managed Codex review are clean. No user-visible shape or behavior change requires a docs/changelog update under the current release-only policy.

Live verification passed through29 normal CLI/Gateway calls against a task-owned authenticated development Gateway and signed managed Chrome. It proved duplicate-reference targeting and ordered clicks, unchanged/added-node deltas, ordinary raw and exact element screenshots, both labeled GET/POST normalization paths, scaled annotation geometry, overlay teardown and absence of the private metadata field from public responses. The960×640 element image and both1000×2000 labeled images were visually inspected; raw capture remains756×469 as permitted by its native-surface contract. All owned processes exited, both ports closed, and final source/build bindings matched.

Failed attempts remain recorded. Fresh-profile startup intermittently failed in the unchanged ownership check before the fixture; passive transport/event-loop observations and a local V8 profile do not yet establish its underlying cause. Ownership, SSRF, timeouts and retries were not changed. An early helper assertion incorrectly equated raw native capture size with an emulated CSS viewport; the revised proof follows the documented route contract and separately checks a supported exact element clip. These are after-only behavior checks, not browser startup/whole-turn speed measurements. Chrome-MCP, iframe navigation/reset and raw-CDP snapshot fallback are covered by canonical tests/copied-owner proofs, not claimed as live here.

Rebase note: all six measured production owners remain byte-identical on main7504a3b3 plus this change. The upstream transport fix preserves nested contextless worker/iframe sessions; its complete owner/dependency path was reviewed and added to the canonical test run. The recorded live fixture contains neither workers nor iframes. Build/live receipts retain their original343fe909-plus-candidate provenance; they are not relabeled as a new build.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 30, 2026 22:34
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:42 PM ET / 22:42 UTC.

ClawSweeper review

What this changes

This PR removes repeated duplicate-reference bookkeeping in browser snapshot builders and reuses screenshot normalization metadata when returning labeled image annotations.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The performance refactor remains necessary and has no discrete correctness or security defect from the introduced hunks. It is a maintainer-authored, maintainer-labeled PR, so it should remain open for the browser owner’s normal landing decision after exact-head CI completes.

Priority: P3
Reviewed head: 2e16be74d9c459c6dd78188d3ae18377f92d0f8d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative owner-boundary refactor with source-preserved contracts and a detailed maintained-environment validation record.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The PR is authored by a repository MEMBER, so the external-contributor proof gate does not apply. Its body nevertheless records a task-owned Gateway and managed-Chrome after-fix run covering duplicate targeting, delta output, labeled screenshots, annotation scaling, and private-field non-disclosure.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is authored by a repository MEMBER, so the external-contributor proof gate does not apply. Its body nevertheless records a task-owned Gateway and managed-Chrome after-fix run covering duplicate targeting, delta output, labeled screenshots, annotation scaling, and private-field non-disclosure.
Evidence reviewed 6 items Verified introduction scope: The pinned merge-base-to-head comparison contains only the browser snapshot, screenshot, and supporting test-harness changes reviewed here; current main is the PR base, so the repeated preparation remains present on main and is not already implemented there.
Snapshot reference contract: The finalizer parses formatter-owned reference tokens once for delta requests, carries the number of complete retained lines through truncation, and retains only references from those accepted lines. The role tracker promotes the first reference to index zero only when a duplicate is encountered, preserving singleton-versus-duplicate semantics.
Sibling snapshot backends: CDP continues to expose an nth value only after the first duplicate, Chrome MCP retains its first-reference omission behavior, and stored ARIA references preserve duplicate index zero while handling overwritten input references by final reference lookup.
Findings None None.
Security None None.

How this fits together

Browser snapshot routes turn page accessibility data into targetable references for agent actions and produce normalized screenshots for media responses. The changed code constructs those references across CDP, Playwright, and Chrome MCP paths, then preserves annotation geometry when screenshots are resized.

flowchart LR
  A[Browser page] --> B[CDP Playwright and Chrome MCP snapshots]
  B --> C[Reference metadata]
  C --> D[Agent snapshot response]
  A --> E[Screenshot capture]
  E --> F[Image normalization]
  F --> G[Annotation rescaling]
  G --> H[Saved media response]
Loading

Decision needed

Question Recommendation
Should the browser owner land this maintainer-authored performance refactor once the exact-head build check completes? Land after exact-head CI: Merge once the remaining build-artifacts check completes successfully for the reviewed head.

Why: The patch is clean in source review, but the maintainer label and MEMBER authorship require an explicit maintainer landing decision rather than automated cleanup.

Before merge

None.

Agent review details

Security

None.

PR surface

Source -102, Tests +3. Total -99 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 89 191 -102
Tests 3 3 0 +3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 92 191 -99

Review metrics

Metric Value Why it matters
Production versus test LOC production +88/-191 (net -103); test support +4/-0 The refactor removes substantially more production bookkeeping than it adds, while test edits only align mocks with a private return field.

Technical review

Best possible solution:

Keep the producer-local refactoring: retain backend-specific nth semantics, use the normalizer as the sole source-dimension owner, and land only after the exact-head build check is green.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR optimizes existing browser paths rather than reporting a user-facing defect. The submitted body describes after-fix Gateway and managed-Chrome runs, while source review independently confirms the affected owner paths.

Is this the best way to solve the issue?

Yes. Removing redundant bookkeeping at the snapshot and normalization owners is preferable to caching or compensating later in route consumers; the backend-specific reference semantics remain explicit in their respective owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7504a3b3c453.

Labels

Label changes:

  • add P3: This is a bounded internal browser performance refactor with no user-visible contract, configuration, or security change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is authored by a repository MEMBER, so the external-contributor proof gate does not apply. Its body nevertheless records a task-owned Gateway and managed-Chrome after-fix run covering duplicate targeting, delta output, labeled screenshots, annotation scaling, and private-field non-disclosure.

Label justifications:

  • P3: This is a bounded internal browser performance refactor with no user-visible contract, configuration, or security change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is authored by a repository MEMBER, so the external-contributor proof gate does not apply. Its body nevertheless records a task-owned Gateway and managed-Chrome after-fix run covering duplicate targeting, delta output, labeled screenshots, annotation scaling, and private-field non-disclosure.

Evidence

What I checked:

  • Verified introduction scope: The pinned merge-base-to-head comparison contains only the browser snapshot, screenshot, and supporting test-harness changes reviewed here; current main is the PR base, so the repeated preparation remains present on main and is not already implemented there. (extensions/browser/src/browser/pw-role-snapshot.ts:137, 2e16be74d9c4)
  • Snapshot reference contract: The finalizer parses formatter-owned reference tokens once for delta requests, carries the number of complete retained lines through truncation, and retains only references from those accepted lines. The role tracker promotes the first reference to index zero only when a duplicate is encountered, preserving singleton-versus-duplicate semantics. (extensions/browser/src/browser/pw-role-snapshot.ts:137, 2e16be74d9c4)
  • Sibling snapshot backends: CDP continues to expose an nth value only after the first duplicate, Chrome MCP retains its first-reference omission behavior, and stored ARIA references preserve duplicate index zero while handling overwritten input references by final reference lookup. (extensions/browser/src/browser/cdp.ts:825, 2e16be74d9c4)
  • Screenshot geometry owner: Normalization returns the already-read display dimensions; both labeled screenshot routes use them only when output bytes differ, then probe the normalized image for the scale factors. The shared image owner accounts for EXIF orientations that swap display axes. (extensions/browser/src/browser/routes/agent.snapshot.ts:258, 2e16be74d9c4)
  • Existing behavioral coverage: Current tests cover duplicate role references, complete-line truncation, hostile ref-like page text, CDP reference construction, and stored ARIA duplicate fallback metadata. The changed test files only update mocks for the new private return field. (extensions/browser/src/browser/pw-role-snapshot.test.ts:137, 2e16be74d9c4)
  • Routing history: The current-main implementation around the CDP snapshot owner was last modified in commit f1d2c5b by Vincent Koc; the local partial clone could not retrieve its parent blob, so this is routing evidence rather than an introduction claim. (extensions/browser/src/browser/cdp.ts:825, f1d2c5b91f80)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • gaoanze888: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 5835fbe into main Aug 30, 2026
174 checks passed
@steipete
steipete deleted the codex/perf-browser-preparation branch August 30, 2026 22:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to shojikumaru/openclaw that referenced this pull request Aug 30, 2026
…cked-delivery

* origin/main:
  fix(ui): wait for restored draft before clearing (openclaw#133575)
  fix(deps): update fast-uri security patches (openclaw#133572)
  test: reduce workflow sanity fixture cleanup time (openclaw#133588)
  fix(media): normalize detected Matroska MIME (openclaw#133383)
  refactor(docker): retire ClawDock shell helpers (openclaw#133594)
  perf(browser): reuse snapshot refs and screenshot metadata (openclaw#133598)
  perf: load web chat history in larger, faster batches (openclaw#133565)
  fix(plugins): keep bundled plugins bundled when selected by plugins.load.paths (openclaw#133584)
  test: isolate shared /tmp session-store paths in runner and health suites (openclaw#133568)
  fix(cron): avoid no-op schedule repair writes (openclaw#133552)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant