feat: enhanced binary detection with full-content scanning and per-chunk validation #178 - #179
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughBinary content detection is enhanced at two levels: ChangesBinary Detection Hardening and binarySkipped Reporting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
Summary
Enhanced binary detection during ingest to prevent binary content from being indexed. The previous 256-byte initial scan was insufficient for larger files.
Changes
1. Enhanced
isBinaryContent()insrc/ingest/loader.tsisBinaryRegion()helper for reusable region scanningBINARY_SCAN_BYTES→FULL_SCAN_SIZE(64KB threshold)2. Added per-chunk binary validation in
src/ingest/chunker.tsisBinaryChunk()helper that validates decoded text for null bytes or >30% non-printable charschunkContent()catches binary chunks regardless of which sub-function produced themchunkContent()now returnsChunkResult { chunks, binarySkipped }for caller visibility3. Added
binarySkippedtoIngestResultinsrc/ingest/index.tsisBinaryContent()returns true for a filechunkContent()result for per-chunk binary skips4. Added tests in
test/ingest.test.tsisBinaryContenttest block: plain text, null byte at position 300, large file with binary middle, large file with binary end, >30% non-printable, empty file, UTF-8 BOM, control charsisBinaryChunktest block: normal text, embedded null byte, >30% non-printable, empty chunk, whitespace-onlyTesting
Summary by cubic
Improved binary detection during ingest by scanning full small files, sampling large files, and validating each produced chunk. This prevents binaries from being indexed and records how many were skipped.
New Features
isBinaryContentnow fully scans files ≤64KB and samples first/middle/last 4KB for larger files; flags null bytes or >30% non‑printable chars.isBinaryChunk; binary chunks are dropped with a warn log and processing continues.chunkContentnow returnsChunkResult { chunks, binarySkipped }to expose skipped chunk count.IngestResultincludesbinarySkipped, covering both file-level and chunk-level skips; tests added for edge cases.Migration
chunkContent(...)to handleconst { chunks, binarySkipped } = await chunkContent(...);.IngestResult.binarySkipped.Written for commit 0eb0280. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests