Skip to content

chat: avoid splitting surrogate pairs in read_file - #331005

Merged
roblourens merged 1 commit into
microsoft:mainfrom
martincheck:fix/copilot-read-file-surrogate-boundary
Aug 16, 2026
Merged

roblourens merged 1 commit into
microsoft:mainfrom
martincheck:fix/copilot-read-file-surrogate-boundary

Conversation

@martincheck

Copy link
Copy Markdown
Contributor

Fixes #330999

This change keeps read_file line truncation from splitting a UTF-16 surrogate pair at the 2,000-code-unit boundary. When the boundary falls between a high and low surrogate, truncation moves back one code unit before appending the existing marker.

A regression test covers an astral character beginning at index 1,999.

Validation on 80b2a71e868059b3177b68b125310f2f690252b9 with Node.js 22.23.2 and @vscode/copilot-api 0.5.2:

  • Focused readFile.spec.tsx: 35 passed
  • npm run typecheck: passed
  • npm run compile: passed
  • Full Copilot unit suite: 406 files passed, 5 skipped; 8,916 tests passed, 129 skipped
  • git diff --check: passed

Copilot AI balanced review requested due to automatic review settings August 15, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents read_file truncation from producing malformed Unicode when the limit intersects a UTF-16 surrogate pair.

Changes:

  • Adjusts the truncation boundary to preserve surrogate pairs.
  • Adds regression coverage for an astral character at the boundary.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
extensions/copilot/src/extension/tools/node/readFileTool.tsx Safely adjusts the line truncation boundary.
extensions/copilot/src/extension/tools/node/test/readFile.spec.tsx Tests surrogate-pair boundary handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@roblourens roblourens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@roblourens
roblourens enabled auto-merge (squash) August 15, 2026 20:31
@roblourens
roblourens merged commit 09b07fe into microsoft:main Aug 16, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.134.0 milestone Aug 16, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot read_file truncation can split UTF-16 surrogate pairs and poison a chat session

5 participants