Skip to content

fix(mcp): keep preview error text valid at the character limit - #47559

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-236c7254a0
Dec 2, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-236c7254a0

Conversation

@saphid

@saphid saphid commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The preview automation broker can split an emoji when it clips a server-browser error reason to 500 UTF-16 code units. The MCP caller then receives error text with an unpaired surrogate.

Deterministic repro on origin/main (8efa474ffcfd6e56d6e195af5401c0e161ab535d)

  1. Open a new server-browser tab with preview_open and omit url to get a blank page. On that tab, call preview_evaluate with the expression throw new Error("a".repeat(492) + "😀").
  2. For a broker fixture, use "Error: " + "a".repeat(492) + "😀\n at <anonymous>:1:7" as PreviewAutomationExecutionError.message, or as detail.reason on PreviewAutomationTimeoutError.

Observed: Chromium’s exception description reaches ServerBrowserPage.evaluate, then ServerBrowser.handleRequest forwards it to PreviewAutomationBroker.respond. The bound MCP preview_evaluate handler returns the resulting error text, which still ends in \ud83d after a JSON round trip. Both broker fixtures fail error.message.isWellFormed().

Expected: Omit the whole emoji when it cannot fit, keeping the preceding 499 code units and returning well-formed text.

Change

Use the same prefix helper for execution and timeout reasons. It backs off one code unit only when the 500-unit cut would split a surrogate pair, preserving the existing cap and the omission of remote desktop reasons. No client or protocol changes are needed.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • On base, both boundary fixtures failed with AssertionError: expected false to be true // Object.is equality. On the patch, all 34 broker tests passed.
  • vp run check:changed exited 0; 36 affected tests passed across two files.
  • Before/after transcript: real local Chromium through T3’s in-process MCP toolkit; isWellFormed() changed from false to true.
  • Not shown: A live Chromium timeout with a boundary-length reason (covered by the broker fixture), external HTTP transport, or client rendering.

Authored by GPT-6.2 Sol (Codex); reviewed by Gemini 4 Neon (Antigravity).

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Dec 2, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at bc5b95b

Macroscope's review found this PR approvable — Preview error text now avoids splitting a Unicode surrogate pair at the existing length limit. The change is confined to error-message formatting, with execution behavior and client guards unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bc5b95b and 1bcff56.

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

No actionable comments were generated in the recent review.

Walkthrough

The broker now truncates server-browser timeout and execution-error reasons to 500 UTF-16 code units without splitting valid surrogate pairs. Tests cover long reasons and verify error message formatting.

Changes: Server-browser reason truncation

Layer / File(s) Summary
Truncate reasons and validate error messages
apps/server/src/mcp/PreviewAutomationBroker.ts, apps/server/src/mcp/PreviewAutomationBroker.test.ts
A shared helper limits reasons to 500 UTF-16 code units without splitting valid surrogate pairs. Server-browser timeout and execution-error paths use the helper. Tests cover long reasons, well-formed messages, and displayed reasons.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · previous review bc5b9

This change keeps server-browser error text well-formed when a reason is cut at 500 code units. It has a narrow scope and boundary tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(mcp): keep preview error text valid at the character limit" describes the main change: clipping server-browser error reasons at 500 UTF-16 code units no longer splits a surrogate pair, …
Description check Passed The description follows the repository template. It has Problem, Change, Scope, and Verification sections with substantive content. The Problem section gives a reproduction and expected behavior. The …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(mcp): keep preview error text valid at the character limit" describes the main change: clipping server-browser error reasons at 500 UTF-16 code units no longer splits a surrogate pair, so the error text stays well formed. It is a conventional commit title in plain language and matches the changeset in PreviewAutomationBroker.ts and its tests.

Full details: Description check

Explanation

The description follows the repository template. It has Problem, Change, Scope, and Verification sections with substantive content. The Problem section gives a reproduction and expected behavior. The Change section explains the shared prefix helper and why no client or protocol changes are needed. The Scope section states why no issue is linked, which the template allows for small obvious bugs. Verification lists focused tests, a before/after transcript, and what was not checked. The description also names the model and harness used, as the template asks. A minor gap is that the Scope section does not link an issue, but the template permits an explanation instead.

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

Commits

Reviewing files that changed from the base of the PR and between 72c5a9e and bc5b95b.

Files selected for processing: 2

  • apps/server/src/mcp/PreviewAutomationBroker.test.ts
  • apps/server/src/mcp/PreviewAutomationBroker.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 2, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Reproduced in the real web app on fresh, separate dev databases with OpenCode 2.4.3 and Claude Haiku 5.5; light theme, 1280×800 CSS viewport (PNG captures at 2×). No provider stub or copied database was used.

Steps on both commits: start an OpenCode thread; ask it to call preview_open without a URL, evaluate throw new Error("a".repeat(492) + "😀"), and quote the error. Repeat the identical prompt while recording. Expand the actual tool activity and inspect its persisted output read-only.

Before After
758f73a710 1bcff56e0c
Before: actual tool output ends with a broken surrogate glyph After: live tool inspection reports 535 units, 492 a characters and no surrogates
Before recording After recording
Stored base tool results: both runs have 536 UTF-16 units, reason length 500, tail 0x0061 0x0061 0xD83D, well-formed false. Stored head tool results: both runs have 535 UTF-16 units, reason length 499, tail 0x0061 0x0061 0x0061, well-formed true.

All 492 a characters remain on both sides. The head omits the entire emoji at the boundary. Verdicts use the stored tool results, not the model's imperfect verbatim quotations. Stills were visually inspected and byte-identical across captures more than 500 ms apart; recordings were inspected through extracted frames.

Reproduction driver · Read-only runtime extractor

The timeout path was not exercised live.

Not shown:

  • Timeout-error truncation was not driven live; only the reported execution-error path was exercised.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 2, 2026
@juliusmarminge
juliusmarminge merged commit d75aa2a into pingdotgg:main Dec 2, 2026
36 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants