Repository navigation
fix(file-reads): read UTF-16 text files in read_file, summarize_file, and grep_code - #122
Merged
Merged
Conversation
… and grep_code After #118, UTF-16 files were indexed, but read_file treated them as binary ("Cannot read binary file") because any NUL byte meant binary, and summarize_file then reported "File not found". grep_code, local storage, topology snippets, and ADR parsing also read them as UTF-8. - text_decoding: is_binary_sample/is_binary_file treat NUL bytes as binary only when the bytes are not UTF-16/UTF-32 text (BOM or UTF-16 zero pattern). - FileReaderService, the grep scanner, local storage, topology snippets, and ADR parsing read files with read_source_text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #118. UTF-16 files are now indexed, but the read paths still failed for them:
read_file→Cannot read binary file: StoredProcedures/.../GetLatestAssistantPublishedVersion.sql:is_binary_filetreated any NUL byte as binary, and UTF-16 text has a NUL in every other byte.summarize_file→File not found on disk or storage(it reads throughread_file).grep_codeskipped the file (same binary check), and local storage, topology snippets, and ADR parsing read files as UTF-8.Change
app/services/text_decoding.py:is_binary_sample/is_binary_file— NUL bytes mean binary only when the bytes are not UTF-16/UTF-32 text (BOM, or the UTF-16 zero pattern). A UTF-8 BOM with NUL bytes stays binary.FileReaderService.read_file/is_binary_file,code_grep_scanner,local_storage(read and re-index),topology/helperssnippets, andadrparsing read withread_source_text(encoding detection, no NUL).Tests
tests/test_utf16_file_reads.py: UTF-16 LE/BE (with and without BOM), UTF-32, and UTF-8 samples are text; PNG-like data and UTF-8-BOM-with-NUL are binary;read_filereturns the decoded lines of a UTF-16 stored procedure; real binary files are still refused.tests/test_text_decoding_and_nul_safety.py, and the style guardrails pass. (tests/test_file_reader.py::test_read_text_file_full_and_line_slicingfails on Windows onmaintoo:write_textwrites CRLF, sosize_bytesdiffers; CI runs on Linux.)search_codehit, butread_fileandsummarize_filefailed on it.🤖 Generated with Claude Code