You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): device host errors no longer cut an emoji in half - #42628
When a device MCP tool gets a host it cannot find, or a host label shared by several hosts, resolveHostId in apps/server/src/mcp/toolkits/device/handlers.ts cuts host labels at 64 UTF-16 code units and the requested hostId at 128. If an emoji sits right on that cut, slice leaves a lone surrogate half in the error text, and provider JSON parsers reject that text.
Change
I added a slicePrefix helper in apps/server/src/mcp/toolkits/device/handlers.ts that cuts one code unit earlier when the cut would split a surrogate pair, using the existing splitsSurrogatePair helper, and applied it to both the 64-unit host label cut and the 128-unit hostId cut. I added regression assertions to the existing unknown/ambiguous host test in apps/server/src/mcp/toolkits/device/handlers.test.ts, with one unknown-host error that runs through both cuts.
Scope
This is a small, self-contained bug fix for an obvious UTF-16 truncation bug in one server helper and its test, so it needs no separate issue.
Verification
No screen changes because the text is MCP tool error text sent to the agent, so the evidence is text.
Reviewing files that changed from the base of the PR and between bad5dee and f0b95c0.
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
Host labels and selectors in resolveHostId errors now use surrogate-safe truncation. A regression test checks the displayed text for an unknown selector containing an emoji.
Changes: Host error text
Layer / File(s)
Summary
Surrogate-safe error text apps/server/src/mcp/toolkits/device/handlers.ts, apps/server/src/mcp/toolkits/device/handlers.test.ts
resolveHostId now truncates host labels and selectors without splitting UTF-16 surrogate pairs. The 64- and 128-character limits remain unchanged. A regression test checks the displayed text for an emoji selector.
This change stops device host error messages from containing a broken emoji character that could be rejected by provider JSON parsers. It is a small, localized fix to error text with a regression test, and no merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the actual change: device host error text in the server no longer cuts an emoji in half. It matches the raw summary, which describes the slicePrefix helper that avoids splitting UTF-16…
Description check
The description covers every required template section. Problem explains the lone surrogate issue with the 64 and 128 UTF-16 code unit cuts. Change describes the slicePrefix helper and the splitsSurro…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the actual change: device host error text in the server no longer cuts an emoji in half. It matches the raw summary, which describes the slicePrefix helper that avoids splitting UTF-16 surrogate pairs in resolveHostId host labels and selectors. The title uses the conventional commit form and is specific.
Full details: Description check
Explanation
The description covers every required template section. Problem explains the lone surrogate issue with the 64 and 128 UTF-16 code unit cuts. Change describes the slicePrefix helper and the splitsSurrogatePair reuse. Scope says this is a small bug fix and why no issue is needed. Verification gives a runtime probe before and after, a failing test on base, three passing runs on head, and a passing check:changed run. It also notes that no screen changes apply and that an AI agent ran the checks, which matches the template's agent note. The template's Scope section asks for a linked issue or a reason for none, and the author gave a reason. No required information is missing.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Real T3 servers and Codex CLI 0.172.0, Linux, gpt-6.1-sol, fresh synthetic databases. Enable device support and agent access; configure two hosts labelled 63 a characters + 😀. Call device_list with 127 b characters + 😀, 63 a characters + 😀, then nope. Repeat the first selector with ASCII host labels to isolate selector truncation. All four calls fail in Codex's JSON parser on base; all four return readable host errors on head. Captures show the isolated selector case.
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
size:XS0-9 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
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.
Problem
When a device MCP tool gets a host it cannot find, or a host label shared by several hosts,
resolveHostIdinapps/server/src/mcp/toolkits/device/handlers.tscuts host labels at 64 UTF-16 code units and the requestedhostIdat 128. If an emoji sits right on that cut,sliceleaves a lone surrogate half in the error text, and provider JSON parsers reject that text.Change
I added a
slicePrefixhelper inapps/server/src/mcp/toolkits/device/handlers.tsthat cuts one code unit earlier when the cut would split a surrogate pair, using the existingsplitsSurrogatePairhelper, and applied it to both the 64-unit host label cut and the 128-unithostIdcut. I added regression assertions to the existing unknown/ambiguous host test inapps/server/src/mcp/toolkits/device/handlers.test.ts, with one unknown-host error that runs through both cuts.Scope
This is a small, self-contained bug fix for an obvious UTF-16 truncation bug in one server helper and its test, so it needs no separate issue.
Verification
No screen changes because the text is MCP tool error text sent to the agent, so the evidence is text.
An AI agent ran each check below.
Runtime probe
Inputs: label
"a"×63+😀, hostId"b"×127+😀.Base (
fbd939eb4cb6):Head (
bad5dee8):Tests and checks
An AI agent ran the updated test against base (
fbd939eb4cb6, withhandlers.tsrestored to base):An AI agent ran
cd apps/server && vp test run src/mcp/toolkits/device/handlers.test.ts3 times on head (bad5dee8):An AI agent ran
vp run check:changed(exit 0):Generated with Gemini 4 Neon in T3 Code Nightly