perf(server): text-only browser snapshots skip the PNG encode (66 ms → 20 ms median) #30305
main fromrefs/pull/30305/head·merged by juliusmarminge View on GitHubProblem#
Every preview_snapshot call encodes a full-resolution PNG, even though most calls only need the page text and refs. By default the tool returns only the screenshot's width and height. To get those numbers, the server browser captures a 2560×1600 PNG, decodes it in the page, shrinks it to 1280×800, re-encodes it, and then drops the pixels. Agents take snapshots after nearly every browser step, so they pay this cost each time.
Change#
When the call sets neither includeImage nor save, the MCP handler now sends pixelsRequired: false to the host:
ServerBrowserPage.snapshotMetadatatakes a quality-10 JPEG of the same viewport and reads the size from its frame header. It reports the size the PNG path would have shrunk to. The rest of the snapshot is unchanged: tree, refs, text, masking, retry and deadline.- It still takes a real capture. The audit tried computing the size from page metrics, but that size drifted from the PNG's. Capturing the frame at a smaller scale broke
backdrop-filterrendering. includeImageandsavestill get the same PNG as before. If a host returns no pixels when pixels were requested, the call fails with a clear error. It never saves or returns an empty image.- The text the model sees does not change. The structured result still reports
mimeType: "image/png"and the same size, and the tool's description and input schema are unchanged. - Older hosts ignore the new field and return a PNG, which the handler accepts. That covers mixed versions across linked environments.
Server only. Desktop tabs go through the same ServerBrowser path over CDP, with renderScale: "display". Web and mobile clients don't change.
Scope and approval#
This qualifies for the small, focused bug-fix exception in CONTRIBUTING.md. Encoding an image only to throw it away is an obvious performance defect. There is no feature, product default, or model-facing tool text change. The new contract field is optional, so older hosts are unaffected.
Verification#
Benchmark: 20 back-to-back snapshot calls on one page in headless Chromium, using the same launch flags and 1280×800 @2× context as ServerBrowserContexts. main and this branch ran 7 times each per page, alternating which went first. Each value is the median per-call time of one run.
| Page | main median | This branch median |
|---|---|---|
| Plain white page, 120 text cards | 66.4 ms | 19.9 ms (3.3×) |
Gradients, shadows, sticky backdrop-filter header | 703.1 ms | 24.9 ms (28×) |
Node CPU per call fell from 5.6 to 2.2 ms on the plain page and from 17.9 to 2.4 ms on the gradient page. In all 28 runs, both sides reported the same screenshot size (1280×800), ref count (208) and visible text length.
Tests:
ServerBrowserPage.test.ts›captures a plain page at the shrunk sizenow also checks thatsnapshotMetadatareports the same 1280×800 as the PNG path, in real Chromium. A newJPEG screenshot dimensionscase covers frame-header parsing and rejects truncated or invalid frames.McpHttpServer.test.ts:preserves PNG output for snapshot optionscovers all fourincludeImage/savecombinations.rejects a metadata-only response when pixels are requestedcovers a host that returns no pixels. The existing image-option test now asserts which requests sendpixelsRequired: false.vp run check:changedpasses.
Not checked here: desktop (Electron) tabs at non-default zoom. The audit checked capture, size and ref clicks at 100% and 125% zoom over direct CDP. I didn't repeat that on this branch. I also didn't time whole agent turns.
Made with Claude Opus 5.5 via Claude Code in T3 Code, from an audit by GPT-6.1 Sol via Codex.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
Approvability#
Verdict: Approved at
0bbb158Macroscope's review found this PR approvable — Text-only browser snapshots avoid PNG encoding while preserving page metadata; image and save requests retain PNG capture. The change is limited to internal snapshot processing without changing user-facing defaults or expanding data exposure.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 44901729c720636dd74350d2354dc4241106f9b8
- Latest commit, not reviewed: dcbf79281e81e71dc09e30ee1ca6abababc0eedb
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- Resume reviews
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
Preview snapshots can return screenshot dimensions without PNG pixels when images are not requested. Requests to save or include an image require PNG data. Metadata-only capture uses JPEG dimensions.
Changes: Metadata-aware preview snapshots
Layer / File(s) Summary Snapshot contract and routing
packages/contracts/src/previewAutomation.ts,apps/server/src/mcp/toolkits/preview/*,apps/server/src/preview/ServerBrowser.tsSnapshot inputs include the optional pixelsRequiredflag. The preview operation returns metadata when pixels are not required, and the result contract accepts metadata or a full snapshot.Metadata-only capture
apps/server/src/preview/ServerBrowserPage.ts,apps/server/src/preview/ServerBrowserPage.test.tsMetadata-only capture uses a JPEG to determine scaled dimensions without returning image data. Both capture modes use shared snapshot orchestration and retry handling. MCP PNG output and validation
apps/server/src/mcp/McpHttpServer.ts,apps/server/src/mcp/McpHttpServer.test.tsThe MCP handler decodes and saves PNG pixels only when requested. It returns an invalid_requestfailure if requested pixels are missing or not PNG. Tests cover image output, saved bytes, and metadata-only responses.Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant MCPCaller participant PreviewSnapshot participant ServerBrowser participant ServerBrowserPage MCPCaller->>PreviewSnapshot: Request snapshot without save or image inclusion PreviewSnapshot->>ServerBrowser: Set pixelsRequired to false ServerBrowser->>ServerBrowserPage: Call snapshotMetadata ServerBrowserPage-->>ServerBrowser: Return screenshot dimensions ServerBrowser-->>PreviewSnapshot: Return snapshot metadata PreviewSnapshot-->>MCPCaller: Return snapshot responsePossibly related PRs
- pingdotgg/t3code#35649: Both changes update how
preview_snapshotexposes screenshot-save errors. - pingdotgg/t3code#28271: Both changes modify the
preview_snapshotsave path and screenshot capture behavior. - pingdotgg/t3code#28255: This change uses the
fullScreenshotcontract introduced for preview snapshots.
Suggested reviewers:
t3dotgg - pingdotgg/t3code#35649: Both changes update how
Merge Risk:
Minimal · previous review44901-
Text-only preview snapshots skip the PNG encode and still return screenshot dimensions. Image and save requests keep PNG output. No actionable merge-blocking risk remains. The author did not check Electron zoom or whole-turn performance.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: text-only browser snapshots skip the PNG encode when pixels are not requested, which is the core performance fix. It follows the conventional commit format and gives t… Description check The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and it includes the conventional commit style title context. Scope explains why the change is… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: text-only browser snapshots skip the PNG encode when pixels are not requested, which is the core performance fix. It follows the conventional commit format and gives the benchmark result. It is accurate to the changeset.
Full details: Description check
-
Explanation
The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and it includes the conventional commit style title context. Scope explains why the change is a small bug fix and links no issue. The Verification section gives benchmark data, test names, and untested areas, and it names the model and harness used. The description is complete enough to pass.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 613d1ac
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1450ab38-aba6-4fe6-8e9d-6f8ed9587482
Commits-
Reviewing files that changed from the base of the PR and between 076d3fa1283563a8a9844a36dde6e0ae8738c79d and 44901729c720636dd74350d2354dc4241106f9b8.
Files selected for processing: 2-
apps/server/src/mcp/McpHttpServer.tsapps/server/src/preview/ServerBrowser.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
Note
Written by
claude-opus-5-5on behalf of MariaMerged main (
b68c956d61)#main added a full-resolution
fullScreenshotforsave, which conflicted with this PR'spixelsRequiredpath. both are kept:savestill requestsfullScreenshotand writes the full-res PNG, and text-only snapshots still sendpixelsRequired: falseand skip the PNG encode. the screenshot test now checks the full size and the metadata size together. no other changes. no bot findings were open.blacksmith: vp run check:changed (format, lint, knip, typecheck, 6 test files) pass blacksmith: vp test run src/preview/ServerBrowserPage.test.ts src/mcp/McpHttpServer.test.ts 62 passedthe runtime verification below was done on the previous head
0bbb1586c3and was not repeated after the merge.Verified in a real dev environment#
verified unchanged head
0bbb1586c345c9acf6268d0fa7fe21a4a8f588d6on linux, after reproducing the wasted png capture ongithub/main(15707a84b03e). separate checkouts, fresh isolated state,vp iin both, one background dev server at a time. no source changes, mocks, fixtures, or seeded conversations.repo playwright with
/usr/bin/google-chromedrove pairing, adding a real git project, selecting codexgpt-6.1-sol, and submitting real provider turns. those turns exercised the actual t3-code mcp preview tools.- ten sequential default snapshots on the same real
https://example.com/page retained text, refs, and 1280×800 metadata with no image blocks or errors. a non-pausing node inspector logpoint confirmed main captured png for these calls; the pr captured jpeg at quality 10. - elapsed time around each awaited mcp call had a median of 121 ms on main and 46 ms on the pr. this measures this vm and page, not whole-turn performance.
includeImage,save, and both together retained real png output. matching main/pr captures were byte-identical: 168,230 bytes, valid png signature, sha256a73e96f9bcad5872bf6a52c4029c237701add5666b0b09cf230f3aff9e07f2e9.- fresh snapshot refs navigated to the iana page with http 200; browser back restored the original content and usable refs. text/image dimensions also matched at an 800×600 viewport (both reported 1280×960 under the existing scaling), then returned to 1280×800 after restoring the viewport.
blacksmith: vp test run apps/server/src/mcp/McpHttpServer.test.ts apps/server/src/preview/ServerBrowserPage.test.ts 2 files passed; 61 tests passed main default mcp ms: 184,125,117,130,110,106,137,129,103,116 pr default mcp ms: 43,41,49,43,57,45,59,44,63,47

Not verified#
native electron tabs, browser zoom, native ios/android clients, and mixed-version linked hosts were not exercised on this linux web setup. deadline, retry, and masking coverage here comes from the existing focused tests. whole-agent-turn performance was not measured.
- ten sequential default snapshots on the same real
juliusmarminge added labelstakeover:in-progress
Evidence#
Measured through the real T3 server on the same Linux machine, Chromium 157.0.8103.78, 1280×800 @2, with fresh state and an active approval replay thread. Served 120 plain cards and the same cards with gradients, shadows and a sticky backdrop-filter header. Alternated page order over seven batches per page; each batch warmed up once, then timed 20 sequential
preview_snapshot {}calls.Before After 

88c42f471b dcbf79281e Plain: 81.7 ms, run range 77.9–100.1 ms Plain: 49.0 ms, run range 48.3–51.0 ms Styled: 485.9 ms, run range 452.8–505.6 ms Styled: 67.5 ms, run range 65.9–71.6 ms Live measurement recording Live measurement recording Plain improved 1.67× and styled improved 7.20×. Both reductions exceed the sum of the before/after run spreads. Text, all 125 refs and boxes, and 1280×800 dimensions matched after normalizing generated snapshot scope IDs. Text-only responses contained no image parts. Explicit image and save requests retained PNG output, byte-identical across commits.

Measurement driver and page seed · Setup script · Capture-generation script · Reproduction instructions
Base raw timings and output · Head raw timings and output · Complete evidence bundle, including page PNGs and saved PNGs · Exploratory data
Not shown:
- The absolute 19.9/24.9 ms claims were not reproduced: this machine measured 49.0/67.5 ms on head, while demonstrating improvements beyond run spread.
- The original triage HTML was not supplied. This reconstruction uses 120 short-label cards and returns 125 refs rather than 106.
- The example.com benchmark was not repeated.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this5c85e93
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes