You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
code_search searches . plus the existing included hidden directories. With --hidden or -uu, ripgrep can visit the same hidden file through both roots. JSON results currently group those paths separately, duplicating matches and context and consuming result/output budgets twice. A fixture with three matching lines reports five matches; with a global limit of four it stops early even though only three distinct matches exist.
Changes
Normalize the redundant leading ./ or .\ before grouping JSON records, so per-file limits apply across overlapping roots.
Track retained records by normalized path, record type and byte offset (falling back to line number), in both streaming and final-buffer parsing. Distinct records in the same file remain separate; rejected per-file matches do not grow the deduplication set.
Add one regression using the bundled ripgrep and real files, including multiple matches in one hidden file, context and a visible-file control. It requires three matches and a normal exit under a four-result budget.
Verification
New regression fails on main (Found 4 matches under that budget), then passes after the change: 1 passed, 0 failed.
SDK typecheck, SDK build, Freebuff Windows binary build, version check and official binary smoke test passed.
Built ESM SDK exercised under Node 24.20.0 with real ripgrep: default search, --hidden, -uu, per-file limits, -l and -c passed.
Related SDK tests on Windows: 65 passed, 30 failed. Before the production change: 64 passed, 31 failed including the new regression. Failure-name comparison removes only the new regression; all remaining failures are unchanged baseline failures.
New test passes Prettier. Production Prettier reports the same three unchanged hunks as main. ESLint exits 0 with no errors: 14 unchanged production warnings and two resolver warnings in the new test.
Scope
Keeps the search roots, flag policy and ignore/env filtering. JSON output paths now omit the redundant leading dot-directory prefix. This is lexical overlap deduplication, not inode/symlink identity tracking. It does not change cancellation or the context-budget behavior addressed separately in #1737. No new dependency or public API was added. Dependencies were reused; Linux CI and a fresh frozen-lockfile install were not run locally.
This is a well-scoped fix for a real bug: searching with --hidden/-uu can cause ripgrep to visit the same hidden file through both . and the explicitly-included hidden directory root, so JSON match/context records get counted twice, inflating result counts and burning the global match budget. The reproduction in the PR body (3 real matches reported as 4-5, causing early truncation under a tight globalMaxResults) is credible and the included regression test in code-search-overlapping-roots.test.ts demonstrates it concretely with a hidden file plus a visible-file control.
The fix itself is minimal and surgical: normalize the leading .//.\\ prefix before building the dedup key, and track seen records by (path, type, absolute_offset ?? line_number) in both the streaming and final-buffer parse paths. Applying the same logic in both code paths (lines ~403 and ~493) is correct and avoids the common bug of fixing only one branch. The PR explicitly scopes down what it isn't doing (no inode/symlink identity tracking, no change to cancellation/context-budget handled in #1737), which suggests good judgement about blast radius.
One thing worth double-checking before porting: using absolute_offset ?? lineNumber as part of the key assumes ripgrep reliably emits absolute_offset for both match and context events across its JSON format versions - if that's ever a diffs-only count rather than a true byte offset in some rare path, this could silently drop legitimate duplicate-looking-but-distinct lines (e.g., two identical empty lines). Given the line-number fallback, this risk seems low.
Solid, testable change. Recommend porting after a reviewer confirms the absolute_offset semantics hold across the ripgrep versions you bundle.
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
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.
Problem
code_searchsearches.plus the existing included hidden directories. With--hiddenor-uu, ripgrep can visit the same hidden file through both roots. JSON results currently group those paths separately, duplicating matches and context and consuming result/output budgets twice. A fixture with three matching lines reports five matches; with a global limit of four it stops early even though only three distinct matches exist.Changes
./or.\before grouping JSON records, so per-file limits apply across overlapping roots.Verification
Found 4 matchesunder that budget), then passes after the change: 1 passed, 0 failed.--hidden,-uu, per-file limits,-land-cpassed.Scope
Keeps the search roots, flag policy and ignore/env filtering. JSON output paths now omit the redundant leading dot-directory prefix. This is lexical overlap deduplication, not inode/symlink identity tracking. It does not change cancellation or the context-budget behavior addressed separately in #1737. No new dependency or public API was added. Dependencies were reused; Linux CI and a fresh frozen-lockfile install were not run locally.