fix(server): bound preview snapshot metadata - #7408
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
ApprovabilityVerdict: 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. |
|
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. |
Problem
preview_snapshotforwards 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.tsvp run --filter t3 typecheckImplemented with GPT-5 via Codex desktop.
Note
Bound preview snapshot metadata to 64,000 bytes in
preview_snapshottoolpreviewSnapshotMetadatahelper in McpHttpServer.ts that serializes snapshot metadata (excluding screenshot data) and truncates it if it exceeds 64,000 bytes.accessibilityTreeand marks truncation with reasonmetadata_size_limit; if still over, it falls back to truncating strings (visibleTextto 8,000 chars, URL/title) and clearing list fields.preview_snapshothandler now uses this helper for both the text content (serialized JSON) andstructuredContent(bounded metadata object).Macroscope summarized 3cdc4c5.