Skip to content

fix(parallel): use truncateUtf16Safe for MCP error JSON truncation#102592

Merged
steipete merged 2 commits into
openclaw:mainfrom
Pandah97:fix/truncateUtf16Safe-parallel-mcp
Jul 9, 2026
Merged

fix(parallel): use truncateUtf16Safe for MCP error JSON truncation#102592
steipete merged 2 commits into
openclaw:mainfrom
Pandah97:fix/truncateUtf16Safe-parallel-mcp

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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 used slice(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 truncateUtf16Safe utility 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 isError in 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.
  • oxfmt completed on the runtime and test.
  • git diff --check passed.
  • Live public endpoint proof on 2026-07-09: https://search.parallel.ai/mcp accepted the implemented 2025-06-18 initialize request with HTTP 200 and a negotiated session, accepted notifications/initialized with HTTP 202, and returned a successful JSON-RPC tools/call response for web_search with content, isError: false, results, usage, and session data.
  • Official-source review confirmed the error forms exercised by the three regressions.

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.

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().
@openclaw-barnacle openclaw-barnacle Bot added extensions: parallel size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 5:30 AM ET / 09:30 UTC.

Summary
This PR imports truncateUtf16Safe into the Parallel MCP search runtime and uses it instead of raw .slice(0, 500) for three JSON-stringified MCP error messages.

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
Persistent data-model change detected: serialized state: extensions/parallel/src/parallel-mcp-search.runtime.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body provides compilation/helper-test rationale and explicitly says no real Parallel Search MCP invocation was tested; the contributor should add redacted terminal/live output or logs showing the changed error path after the fix, with private data such as IPs, API keys, phone numbers, and non-public endpoints removed. Updating the PR body should trigger a fresh ClawSweeper review; if it does not, a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The PR does not yet show a real after-fix Parallel MCP or runtime error-path transcript, so the contributor proof gate is not satisfied.
  • [P1] A newer duplicate PR proposes the same change; maintainers should pick one branch and close or supersede the other before landing.

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] No ClawSweeper code repair is needed because source review found no patch defect; the remaining blocker is contributor real behavior proof and duplicate-PR coordination.

Security
Cleared: Cleared: the diff only reuses an existing text utility in a plugin runtime and does not touch dependencies, workflows, lockfiles, secrets, auth, or network policy.

Review details

Best 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 changes

Label changes:

  • add P3: This is a small provider-plugin error-message formatting bug with low runtime blast radius and no blocked user workflow.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides compilation/helper-test rationale and explicitly says no real Parallel Search MCP invocation was tested; the contributor should add redacted terminal/live output or logs showing the changed error path after the fix, with private data such as IPs, API keys, phone numbers, and non-public endpoints removed. Updating the PR body should trigger a fresh ClawSweeper review; if it does not, a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P3: This is a small provider-plugin error-message formatting bug with low runtime blast radius and no blocked user workflow.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides compilation/helper-test rationale and explicitly says no real Parallel Search MCP invocation was tested; the contributor should add redacted terminal/live output or logs showing the changed error path after the fix, with private data such as IPs, API keys, phone numbers, and non-public endpoints removed. Updating the PR body should trigger a fresh ClawSweeper review; if it does not, a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +3. Total +3 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 6 3 +3
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 6 3 +3

What I checked:

Likely related people:

  • NormallyGaussian: Merged PR history shows this account authored the parallel-free Search MCP provider and added parallel-mcp-search.runtime.ts, parallel-mcp-search.runtime.test.ts, and parallel-search-normalize.ts. (role: feature owner; confidence: high; commits: 983b65b0e011; files: extensions/parallel/src/parallel-mcp-search.runtime.ts, extensions/parallel/src/parallel-mcp-search.runtime.test.ts, extensions/parallel/src/parallel-search-normalize.ts)
  • steipete: Recent merged UTF-16 bounded-text work touched extensions/parallel/src/parallel-search-normalize.ts and similar provider error truncation paths, making this account a strong reviewer for consistency and landing direction. (role: recent adjacent contributor and merger; confidence: medium; commits: 87fe266c5e4d, 3ac7729f4c5f; files: extensions/parallel/src/parallel-search-normalize.ts, packages/ai/src/providers/mistral.ts)
  • zhangguiping-xydt: Local blame on the current raw-slice lines points at a recent merged UTF-16 cleanup commit, but the checkout is shallow/grafted and the feature origin is better represented by the earlier Parallel MCP PR. (role: recent current-main line carrier; confidence: low; commits: b23fdcfac953; files: extensions/parallel/src/parallel-mcp-search.runtime.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 3f5f51fa978d0deab2195dd4b7a6e619192c75f2:

  • Reviewed all three MCP failure projections in extractMcpToolPayload: JSON-RPC errors, tool-level isError, and unparseable successful content now share UTF-16-safe bounded serialization.
  • Strengthened the existing focused cases to assert complete boundary error messages; parallel-mcp-search.runtime.test.ts passes all 18 tests.
  • Verified the upstream contracts against the official MCP CallToolResult documentation and Parallel Search MCP documentation.
  • Live Parallel MCP proof on 2026-07-09: initialize returned HTTP 200 and protocol 2025-06-18; initialized notification returned HTTP 202; tools/call returned HTTP 200 with isError: false, content, results, usage, and session metadata.
  • oxfmt, git diff --check, and a fresh branch autoreview pass clean with no actionable findings.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 102592 accepted exact-head hosted CI/Testbox.

No changelog entry is required because this only repairs bounded diagnostic error text. No known proof gaps.

@steipete
steipete merged commit c87b9a7 into openclaw:main Jul 9, 2026
103 of 105 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: parallel P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants