fix: add UTF-8 encoding to read_text/write_text in Copilot ACP fs handlers - #64070
fix: add UTF-8 encoding to read_text/write_text in Copilot ACP fs handlers#64070AlexFucuson9 wants to merge 1 commit into
Conversation
The fs/read_text_file and fs/write_text_file handlers in the Copilot ACP client use Path.read_text() and Path.write_text() without explicit encoding. On Windows, these default to the system locale encoding (typically cp1252), which corrupts non-ASCII content (e.g. source code with unicode identifiers, comments in CJK languages, emoji in strings). Since ensure_ascii is not used in any surrounding json.dumps and the content is arbitrary user code, explicit encoding="utf-8" is required for cross-platform correctness.
Duplicate of #38121 (the earliest open PR making the identical fix). This PR pins |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
This PR adds UTF-8 encoding to read_text/write_text in Copilot ACP fs handlers. Small, targeted fix.
Please verify:
- UTF-8 encoding is applied correctly for both read and write operations
- Existing tests pass with the encoding change
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (token read-only)
PR 64070: fix: add UTF-8 encoding to read_text/write_text in Copilot ACP fs handlers
Correctness ✅
- Adds explicit
encoding="utf-8"topath.read_text()andpath.write_text()calls. - Addresses potential encoding issues on Windows (where the default encoding may differ).
No issues found.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (token read-only)
PR 64070: fix: add UTF-8 encoding to read_text/write_text in Copilot ACP fs handlers
Correctness ✅
- Adds explicit
encoding="utf-8"topath.read_text()andpath.write_text()calls. - Addresses potential encoding issues on Windows (where the default encoding may differ).
No issues found.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Changes
Explicit encoding="utf-8" on path.read_text() and path.write_text() in copilot_acp_client.py file operations.
Assessment
- Minor robustness fix. Explicit encoding prevents platform-dependent default encoding issues.
- No debug artifacts.
Reviewed by Hermes Agent
|
Thanks for the focused cross-platform fix. The premise is valid on current main: Problems
Suggested changes
This is an automated hermes-sweeper review. |
|
Closing as resolved by PR #71078 (merged, commit d372fda): the class-wide close-out salvaged your #50655/#54241/#56385/#66856/#65440 series as the backbone (authorship preserved in git log) and swept the remaining sites, so every read_text/write_text call this PR touches is now guarded on current main — verified per-site. A CI linter rule in check-windows-footguns.py plus the AST guard test now prevent regressions. Your overlapping/split variants of the same series are being closed together; the credit for the class rests on your commits. |
Summary
Path.read_text()andPath.write_text()in the Copilot ACP client'sfs/read_text_fileandfs/write_text_fileJSON-RPC handlers omit explicitencoding=. On Windows, these default to the system locale (typically cp1252), silently corrupting non-ASCII content — source code with unicode identifiers, CJK comments, emoji in strings, etc.Changes
path.read_text()path.read_text(encoding="utf-8")path.write_text(str(params.get("content") or ""))path.write_text(str(params.get("content") or ""), encoding="utf-8")Why this matters
The Copilot ACP client acts as a file I/O bridge for external coding agents. Any non-ASCII content written through this bridge on Windows gets silently corrupted. The corruption is invisible until someone reads the file and sees mojibake.
Follows the same pattern as PR #56940 (os.fdopen encoding) and PR #62667 (write_text + ensure_ascii=False).
Test Plan
pytest tests/agent/test_copilot_acp_client.py -xvs