HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
aider: a small binary file is not taken for text (#489)
Rudy Mizrahi Celekli85d54b68fa56
diff --git a/runner/aider_driver.py b/runner/aider_driver.pyindex a9cbabea..ed2a6679 100644--- a/runner/aider_driver.py+++ b/runner/aider_driver.py@@ -32,6 +32,7 @@ normalised by _aider_to_claude in server.py."""from __future__ import annotations+import codecsimport contextlibimport jsonimport os@@ -138,13 +139,12 @@ def is_text_file(path: str, sniff: int = 65536) -> bool:if b"\x00" in head:return Falsetry:- head.decode("utf-8")+ # A cut inside a multi-byte sequence at the sniff boundary is not a binary file, so a head+ # that filled the sniff may end mid-character. A file read whole may not: dropping its last+ # bytes passed any file of four bytes or fewer, and any whose only bad byte was near its end.+ codecs.getincrementaldecoder("utf-8")().decode(head, final=len(head) < sniff)except UnicodeDecodeError:- # a cut inside a multi-byte sequence at the sniff boundary is not a binary file- try:- head[:-4].decode("utf-8")- except UnicodeDecodeError:- return False+ return Falsereturn Truediff --git a/runner/tests/test_aider_driver.py b/runner/tests/test_aider_driver.pyindex 82614bc2..6ffceb1e 100644--- a/runner/tests/test_aider_driver.py+++ b/runner/tests/test_aider_driver.py@@ -748,6 +748,24 @@ def test_the_harness_own_files_stay_out_of_the_repo_map():assert '"--aiderignore", str(ignore),' in src+def test_a_small_binary_file_is_not_taken_for_text():+ """The leeway for a character cut at the sniff boundary (decode all but the last four bytes)+ also ran on a file read whole, so a file of four bytes or fewer, or one whose only invalid+ UTF-8 was in its last bytes, was called text and failed in aider's UTF-8 read."""+ d = tempfile.mkdtemp()+ for name, data in (("bom16.txt", b"\xff\xfe"), ("tail.bin", b"hello\x80"), ("one.bin", b"\xc3")):+ pathlib.Path(d, name).write_bytes(data)+ assert aider_driver.is_text_file(os.path.join(d, name)) is False, name+ # a head that fills the sniff and ends inside a multi-byte character is still text+ big = pathlib.Path(d, "long.md")+ big.write_bytes(b"a" * 65534 + "€".encode() + b"more") # the euro sign straddles byte 65536+ assert aider_driver.is_text_file(str(big)) is True+ pathlib.Path(d, "accents.md").write_text("café\n", encoding="utf-8")+ assert aider_driver.is_text_file(os.path.join(d, "accents.md")) is True+ pathlib.Path(d, "empty.md").write_bytes(b"")+ assert aider_driver.is_text_file(os.path.join(d, "empty.md")) is True++def test_a_binary_file_the_model_names_is_refused_at_aiders_add_prompt():"""Asked to restyle hello.pptx (hr-test, 2026-09-19), the model named it, aider added it, theUTF-8 read failed ("Use --encoding…"), the file was dropped and added again on the next