Skip to content

fix(copilot_acp): read/write ACP files as UTF-8 - #62090

Closed
solyanviktor-star wants to merge 1 commit into
NousResearch:mainfrom
solyanviktor-star:fix/copilot-acp-fs-utf8
Closed

fix(copilot_acp): read/write ACP files as UTF-8#62090
solyanviktor-star wants to merge 1 commit into
NousResearch:mainfrom
solyanviktor-star:fix/copilot-acp-fs-utf8

Conversation

@solyanviktor-star

Copy link
Copy Markdown
Contributor

Problem

The ACP JSON-RPC client's file handlers in agent/copilot_acp_client.py read and write with no explicit encoding:

# fs/read_text_file
content = path.read_text()                              # L706
# fs/write_text_file
path.write_text(str(params.get("content") or ""))       # L735

This is the file-I/O surface the ACP peer uses to read and edit real project filescontent is arbitrary text (source code, markdown, any language). read_text()/write_text() with no encoding fall back to the system locale (cp1252/GBK on Windows). On a non-UTF-8 host:

  • writing a file whose content has any non-ASCII char (unicode identifiers, comments, emoji, CJK) raises UnicodeEncodeError;
  • reading such a file raises UnicodeDecodeError.

Both are caught by the handler's except Exception and returned to the peer as a JSON-RPC -32602 error — so the agent simply fails to read or edit non-ASCII files on Windows. The codebase treats all text files as UTF-8 (see hermes_cli/doctor.py / config.py), and the tool-side file I/O in tools/ already pins encoding="utf-8"; these two ACP handlers diverged.

Repro (Windows, cp1251)

p.write_text("完了 ✅")                       # UnicodeEncodeError: 'charmap' codec can't encode
p.write_bytes("完了".encode("utf-8")); p.read_text()   # UnicodeDecodeError
p.write_text("完了 ✅", encoding="utf-8")     # ok

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

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>
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/acp Agent Communication Protocol adapter platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows duplicate This issue or pull request already exists labels Jul 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #38121 (earlier open fix, 2026-06-03) — both pin encoding="utf-8" on the same two ACP fs handlers (fs/read_text_file / fs/write_text_file) in agent/copilot_acp_client.py with the same regression tests. Canonical is the earlier #38121; both address issue #38119.

@solyanviktor-star

Copy link
Copy Markdown
Contributor Author

Thanks for the triage — you're right, #38121 (opened 2026-06-03) pins encoding="utf-8" on the same two ACP fs handlers with the same regression tests and predates this by a month. Deferring to it and closing this in favor of the canonical #38121 to keep the queue clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/acp Agent Communication Protocol adapter comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants