fix(copilot_acp): read/write ACP files as UTF-8 - #62090
Closed
solyanviktor-star wants to merge 1 commit into
Closed
Conversation
The fs/read_text_file and fs/write_text_file handlers in the ACP JSON-RPC client used path.read_text() / path.write_text() with no encoding. Both fall back to the system locale (cp1252/GBK on Windows) and the content here is arbitrary peer-supplied file text — source code, docs, any language. On a non-UTF-8 host, writing a file with non-ASCII content raises UnicodeEncodeError and reading one raises UnicodeDecodeError, so the handler returns a JSON-RPC error instead of editing/reading the file. The codebase treats all text files as UTF-8. Pin encoding='utf-8' on both calls. Adds round-trip regression tests with Cyrillic/CJK/emoji content (both fail on the pre-fix handlers). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Duplicate of #38121 (earlier open fix, 2026-06-03) — both pin |
Contributor
Author
2 tasks
This was referenced Aug 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The ACP JSON-RPC client's file handlers in
agent/copilot_acp_client.pyread and write with no explicit encoding:This is the file-I/O surface the ACP peer uses to read and edit real project files —
contentis arbitrary text (source code, markdown, any language).read_text()/write_text()with noencodingfall back to the system locale (cp1252/GBK on Windows). On a non-UTF-8 host:UnicodeEncodeError;UnicodeDecodeError.Both are caught by the handler's
except Exceptionand returned to the peer as a JSON-RPC-32602error — so the agent simply fails to read or edit non-ASCII files on Windows. The codebase treats all text files as UTF-8 (seehermes_cli/doctor.py/config.py), and the tool-side file I/O intools/already pinsencoding="utf-8"; these two ACP handlers diverged.Repro (Windows, cp1251)
Fix
Pin
encoding="utf-8"on both calls.Tests
Added round-trip regression tests to
tests/agent/test_copilot_acp_client.py:test_write_text_file_writes_utf8— Cyrillic/CJK/emoji content persists as UTF-8;test_read_text_file_reads_utf8— a UTF-8 file with non-ASCII content decodes back intact.Both fail on the pre-fix handlers and pass after.
python -m pytest tests/agent/test_copilot_acp_client.py— 13 passed.🤖 Generated with Claude Code