Repository navigation
fix(tools): read UTF-16 text as text and show search hits on long lines - #4686
Conversation
A UTF-16 file (what PowerShell 5.1 `>` writes) came back from read_file as "[Binary file, N bytes]" and never matched in search, so the agent fell back to run_python and a DESTRUCTIVE approval prompt just to read a text file. Both read_file mixins, search_file_content, search_code and get_file_info now decode by byte-order mark; a BOM-marked file that decodes to NULs is still reported binary. A search hit deep in a long line (minified JS, single-line JSON, logs) came back as the line's first 200 chars, without the match. search_file_content now returns a 200-char window centred on the match, and search_code, which returned whole lines unbounded (5 MB for one hit), is bounded the same way.
|
Verdict: Approve with suggestions Windows text files saved as UTF-16 (PowerShell 5.1
Real-world evidenceN/A: no evidence bundle was produced for this run. The change is inside agent file tools with no new CLI/API/UI surface. The verdict rests on static review plus the author's reported unit-test runs. I could not re-run pytest here because it isn't installed on this runner. The PR's one manual check is still unticked: reading a 🔍 Technical detailsIssues 🟢 Case-insensitive excerpt offsets can drift on the plain-substring fallback ( (This also lets you drop the 🟢 Strengths
|
…es (amd#4697) Running a `gaia_*` eval locally used to mean copying a few environment variables out of `eval_flagship.yml`, and it was easy to get it subtly wrong. Started from the checkout, the backend can't see the staged fixtures. Without the fake `gh` first on PATH, auto-approved triage scenarios send writes to real GitHub. The agent under test inherits the judge's credentials. `util/run_eval_lane.py --lane <lane>` reuses `eval_lane_matrix.py`'s lane environment and repeats the workflow's setup, so a local score means what a CI score means. `util/stress_corpus.py` generates the large and hostile files used to validate v0.25: a 1,667-page PDF with one buried fact, a 400k-row CSV, a 120 MB log, injection, UTF-16, a 5 MB single line, and hostile filenames. They found amd#4679, amd#4686 and amd#4688. Its answer key is refused if placed inside the corpus, because the agent's content search would otherwise find the answers there. CLAUDE.md and the testing skill point at both. CLAUDE.md also notes that worktrees share one stash list. ## Test plan - [x] `pytest tests/unit/eval/test_run_eval_lane.py tests/unit/eval/test_eval_lane_matrix.py` (67 passed) - [x] `python util/stress_corpus.py --out <dir> --answers <file>` builds 110 MB, and refuses `--answers` inside `--out` - [x] `python util/check_doc_links.py`, `python util/lint.py --black --isort` - [ ] `python util/run_eval_lane.py --category gaia_honesty` on a Strix Halo box produces a scorecard
On Windows, a text file saved as UTF-16 (PowerShell 5.1
>and some Notepad saves do this) came back fromread_fileas[Binary file, 110 bytes], and searches never matched inside it. The agent then fell back torun_python, so the user had to approve a "DESTRUCTIVE" code prompt just to read a text file. Separately, a search hit deep in a long line (minified JS, single-line JSON or CSV, log lines) came back as the line's first 200 characters, so the model never saw the match. Onesearch_codehit on a 5 MB line also returned the entire 5 MB line.Now file reads and searches detect UTF-16, UTF-32 and UTF-8 byte-order marks and decode the text. Genuinely binary files are still reported as binary. A long matching line comes back as a 200-character window centred on the match, with
...where it was cut.Test plan
python -m pytest tests/unit/agents/test_file_tools_text_encoding.py: 45 pass. With only thesrc/changes reverted, 34 of them fail; the 11 that still pass are the binary and plain UTF-8 guards and the pure excerpt-helper tests.python -m pytest tests/unit/agents/test_read_file_line_ranges.py tests/unit/agents/test_chunk_index.py tests/unit/test_file_tools.py tests/unit/agents/test_read_before_edit.py tests/unit/agents/test_file_edit_semantics.py tests/unit/test_tool_tilde_expansion.py: all 462 pass.python -m pytest tests/unit/ -k "file or search or read": no new failures. The 20 failures there also happen onmain(profilespec goldens, diarize/speech, email sidecar, shell guardrails, and an order-dependent tool-label test polluted by other suites).python util/lint.py --black --isort --pylint: black and isort pass. The only pylint errors are the existing POSIX-onlyos.getuid/signal.SIGKILLhits on Windows, in files this PR doesn't touch.Set-Content -Encoding Unicodein PowerShell 5.1 and confirm it reads it without arun_pythonapproval.🔍 Technical details
gaia/agents/tools/text_files.py(text_encoding,read_text,match_excerpt). It's used by bothread_filemixins (full read,offset/limitpaging,start_lineranges),search_file_content,search_codeandget_file_info.get_file_info'slatin-1fallback used to accept UTF-16 bytes and return aÿþL\x00e\x00…preview.read_fileincludes"encoding"in its result. Plain UTF-8 results are unchanged.search_file_contentused to open every file twice whencontext_lines=0and leaked the inner handle. It now opens each file once.read_fileon a 5 MB single-line file alone because the result isn't silent. The agent already condenses it withtruncated: true,original_chars, an archived artifact and a pagedread_tool_outputcontinuation.edit_fileon a UTF-16 file still fails with a UTF-8 decode error and leaves the file unchanged, same as onmain. Making writes keep the original encoding is a separate change.