fix(parallel): use truncateUtf16Safe for MCP error JSON truncation#102592
Conversation
The extractMcpToolPayload function and error messages use naive .slice(0, 500) on JSON-serialized errors and results which can split surrogate pairs. Replace with truncateUtf16Safe().
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 5:30 AM ET / 09:30 UTC. Summary PR surface: Source +3. Total +3 across 1 file. Reproducibility: yes. source-level reproduction is high confidence: construct a JSON-RPC error or result whose JSON string places a surrogate pair across the 500-code-unit boundary and the current raw slice can leave a dangling surrogate. I did not run a live Parallel MCP repro in this read-only review. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this narrow helper reuse after redacted real behavior proof is added for the Parallel MCP error truncation path, then close or supersede the duplicate branch. Do we have a high-confidence way to reproduce the issue? Yes, source-level reproduction is high confidence: construct a JSON-RPC error or result whose JSON string places a surrogate pair across the 500-code-unit boundary and the current raw slice can leave a dangling surrogate. I did not run a live Parallel MCP repro in this read-only review. Is this the best way to solve the issue? Yes, this is the best code shape for the reported bug: use the existing public plugin-SDK UTF-16 truncation helper at the three local error-message boundaries. A new local helper would reduce little duplication and add unnecessary surface for this small runtime path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4ad94febcb31. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +3. Total +3 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Land-ready proof for exact head
No changelog entry is required because this only repairs bounded diagnostic error text. No known proof gaps. |
|
Merged via squash.
|
…penclaw#102592) * fix(parallel): use truncateUtf16Safe for MCP error JSON truncation The extractMcpToolPayload function and error messages use naive .slice(0, 500) on JSON-serialized errors and results which can split surrogate pairs. Replace with truncateUtf16Safe(). * test(parallel): cover UTF-16-safe MCP errors --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
The free Parallel MCP client includes bounded JSON details in three thrown errors: protocol-level JSON-RPC failures, tool results with
isError, and successful envelopes without parseable content. All three usedslice(0, 500), so externally supplied error data could leave a dangling UTF-16 surrogate at the boundary.Why This Change Was Made
Use the existing
truncateUtf16Safeutility at each error-rendering boundary. This preserves the exact prefixes and 500-code-unit cap without changing MCP parsing or transport behavior.The follow-up tests drive all three branches through
extractMcpToolPayload. Each builds its real JSON shape with an emoji crossing code unit 500 and asserts the complete thrown message, not merely helper output.This matches the MCP contract's distinct protocol-error and tool-error forms: tool-level failures use
isErrorin the call result, while exceptional protocol failures use JSON-RPC error envelopes. See the official MCP tool-result documentation and Parallel Search MCP documentation.User Impact
Parallel free-search failures remain bounded and diagnostic, but no longer contain malformed Unicode at the error limit. No provider selection, request, response, config, or cache behavior changes.
Evidence
node ../../node_modules/vitest/vitest.mjs run --config test/vitest/vitest.extension-misc.config.ts extensions/parallel/src/parallel-mcp-search.runtime.test.ts— 18 tests passed.oxfmtcompleted on the runtime and test.git diff --checkpassed.https://search.parallel.ai/mcpaccepted the implemented 2025-06-18 initialize request with HTTP 200 and a negotiated session, acceptednotifications/initializedwith HTTP 202, and returned a successful JSON-RPCtools/callresponse forweb_searchwithcontent,isError: false, results, usage, and session data.Risk
Low. Three existing error strings now share the established UTF-16 truncation invariant; successful MCP behavior is unchanged.
AI-assisted
This PR was generated with Claude Code and improved/reviewed by a maintainer agent.