`Path.read_text()`/`write_text()` called without `encoding=` — 4 test failures on non-UTF-8 locales
Severity: Medium
Type: Portability / Correctness
Files: agent/integrations/local.py:32, agent/prompt.py:28, and 12 call sites under tests/
Description
Python's Path.read_text() and open() default to locale.getencoding(), not UTF-8. On
Windows that is typically cp1252. The repository's source and Markdown files are UTF-8 and use
non-ASCII characters liberally (em dashes, curly quotes, arrows), so any encoding-less read of a
repo file fails on a non-UTF-8 locale.
Call sites missing encoding=:
agent/integrations/local.py:32 scoped.write_text(...)
agent/prompt.py:28 Path(DEFAULT_PROMPT_PATH).read_text().strip() # see the separate DEFAULT_PROMPT_PATH issue
tests/agent/test_desktop.py:33,35,53
tests/agent/test_structured_input_hygiene.py:37
tests/e2e/fakes.py:165
tests/e2e/harness.py:608,613
tests/sandbox/test_langsmith_sandbox_config.py:55
tests/sandbox/test_local_integration.py:47,55,56
tests/tools/test_background_execute.py:76Impact
Four tests fail on Windows purely because of this:
tests/agent/test_structured_input_hygiene.py::test_no_module_hand_rolls_a_user_messagetests/sandbox/test_langsmith_sandbox_config.py::test_nothing_deletes_sandboxestests/sandbox/test_local_integration.py::test_create_local_sandbox_scopes_global_git_config- (plus the
test_desktop.pysites, which are latent)
Observed failure:
lines = _role_user_literals(ast.parse(path.read_text()))
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 204:
character maps to <undefined>The three failing tests are all repo-wide invariant guards — they walk agent/**/*.py and assert
properties across every module (no hand-rolled user messages; nothing deletes sandboxes). They
are exactly the checks you least want silently unavailable to a contributor, and they are the
first thing to break on a non-UTF-8 developer machine.
Suggested fix
Pass encoding="utf-8" at every site. The codebase already does this correctly elsewhere
(agent/prompt.py:32 uses .read_text(encoding="utf-8")), so this is an inconsistency rather
than a new convention. A ruff rule (PLW1514 / flake8-encodings) would prevent regressions.
Found during a full-repo audit (ruff + basedpyright + pytest on a Windows host, plus manual review). Filing each finding separately so they can be triaged independently.
Source: langchain-ai/open-swe