Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): bound preview snapshot metadata #7408

Closeddevhims(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7408/headopened View on GitHub

Problem

preview_snapshot forwards Chrome's full accessibility tree to the provider. On large pages, this can add hundreds of kilobytes of JSON to one tool result and consume most of the thread's context window.

Fix

Cap snapshot metadata at 64 KB. If it exceeds the limit, omit the accessibility tree and mark the result as truncated. If the remaining fields are still too large, return a compact page summary. Normal snapshots are unchanged.

Added a regression test that sends an oversized snapshot through the MCP tool and verifies that the returned metadata stays within the limit.

Validation

  • vp test run apps/server/src/mcp/McpHttpServer.test.ts
  • vp run --filter t3 typecheck
  • Targeted lint and formatting checks

Implemented with GPT-5 via Codex desktop.

Note

Bound preview snapshot metadata to 64,000 bytes in preview_snapshot tool

  • Adds a previewSnapshotMetadata helper in McpHttpServer.ts that serializes snapshot metadata (excluding screenshot data) and truncates it if it exceeds 64,000 bytes.
  • When over the limit, it first drops accessibilityTree and marks truncation with reason metadata_size_limit; if still over, it falls back to truncating strings (visibleText to 8,000 chars, URL/title) and clearing list fields.
  • The preview_snapshot handler now uses this helper for both the text content (serialized JSON) and structuredContent (bounded metadata object).
  • Behavioral Change: oversized snapshot responses will now be truncated with truncation metadata rather than returned as-is.
Macroscope summarized 3cdc4c5.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: c8af7b0b-054e-429a-b1f6-470394f1cc1b

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a straightforward defensive fix that bounds preview snapshot metadata to 64KB with progressive truncation. The logic is clear and well-tested, but the author is a first-time contributor to this codebase, warranting human verification of the truncation approach.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.

      Closing in favor of #9505, the retained snapshot-size fix. It declares truncation in the contract and keeps interactive locators longer. Its latest code also caps title and URL, so this branch adds no unique limiter behavior. Review continues there.

Sign in to join this conversation.