fix(server): bound preview_snapshot metadata sent to the agent - #9505
Open
ylcn91 wants to merge 2 commits into
Open
fix(server): bound preview_snapshot metadata sent to the agent#9505ylcn91 wants to merge 2 commits into
ylcn91 wants to merge 2 commits into
Conversation
Contributor
ApprovabilityVerdict: Would Approve Macroscope's review found this PR approvable — This is a focused, well-tested guardrail bug fix that bounds oversized preview metadata while preserving normal snapshots, screenshots, and interactive elements. The follow-up caps oversized URLs and titles with regression coverage; the supplied unresolved high-severity bound concern remains an independent policy block. Not approved because:
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
packages/contracts/src/previewAutomation.ts:PreviewAutomationSnapshotgains an optionaltruncationfield (originalBytes,omitted,trimmed) so a reduced result stays inside the tool's advertised output schema.apps/server/src/mcp/McpHttpServer.ts: thepreview_snapshotmetadata handed to the agent is bounded at 100 KB byboundPreviewSnapshotMetadata. Over the limit, the title and URL are first capped at 2,048 characters (they are identifiers, and a data: URL can be the whole overrun by itself), then fields go least useful first: the accessibility tree, then the network, console, and action logs (only when they hold anything), then the visible text is cut short, and only then the interactive elements, which carry the locators the other tools need. The screenshot rides beside the metadata as an image and is never reduced. A truncated result adds a plain-language text block saying what was omitted or cut and pointing atpreview_evaluate.apps/server/src/mcp/toolkits/preview/tools.ts: the tool description says the metadata is bounded and where to look.Tests: the reduction order and its bookkeeping on synthetic snapshots (including multi-byte text), and the tool result through the broker: bounded JSON, image kept, note present,
textequal tostructuredContent.Why
Fixes #7410.
The snapshot forwarded Chrome's full accessibility tree with no limit. On content-heavy pages that alone ran to hundreds of kilobytes per tool result, enough to crowd out the thread's context; the reporter saw a later turn fail with an internal provider error once such a result entered the conversation. The producer already caps visible text (20k characters) and interactive elements (200), so the tree is the only unbounded field, and the limit is placed at the MCP boundary so every provider is covered. 100 KB sits above what the producer's own caps add up to on an ordinary page, so a snapshot without the tree is normally sent whole.
The marker lives in the contract rather than as an extra key because MCP clients may validate
structuredContentagainst the tool's output schema, which rejects unknown properties.#7408 proposed a fix for the same issue earlier (64 KB limit, drop the tree then fall back to a compact summary) and has not moved since mid-August. This one differs in two ways that seemed worth a separate PR rather than a comment: the truncation marker is declared in the output schema instead of added as an undeclared key, and the reduction is an ordered ladder that keeps the interactive elements for as long as possible. Happy to fold either PR into the other if a maintainer prefers.
Model and harness: Claude Fable 5.1 in Claude Code.
Note
Bound
preview_snapshotmetadata to 100,000 bytes inMcpHttpServerboundPreviewSnapshotMetadatain McpHttpServer.ts to limitpreview_snapshotJSON metadata to 100,000 bytes (PREVIEW_SNAPSHOT_METADATA_MAX_BYTES).PreviewAutomationSnapshotcontract in previewAutomation.ts with an optionaltruncationobject. The MCP response now includes an explanatory text note when metadata is reduced.preview_snapshotnow returns truncated metadata and an extra text item when the byte budget is exceeded. Callers must check thetruncationobject to detect omitted fields.Macroscope summarized d7633d8.