Skip to content

fix: over-fetch in find_usages so definition filtering doesn't shrink results - #101

Merged
GoodbyePlanet merged 1 commit into
mainfrom
fix/find-usages-overfetch
Jul 28, 2026
Merged

fix: over-fetch in find_usages so definition filtering doesn't shrink results#101
GoodbyePlanet merged 1 commit into
mainfrom
fix/find-usages-overfetch

Conversation

@GoodbyePlanet

Copy link
Copy Markdown
Owner

Fixes #74

Problem

find_usages asked the store for exactly limit fused hits, then filtered out any hit whose symbol_name equals the searched symbol — i.e. the symbol's own definition, which is not a usage.

Because the definition is almost always a top hit for the query "code that uses or references X" (it is the most semantically similar thing to its own name), the caller ended up with limit - 1 results even when more real usages existed just past the fetch window. At limit=1 it reported "No usages found" for symbols with plenty of usages.

Fix

Fetch limit + USAGE_OVERFETCH hits before filtering, then slice to limit.

The buffer is 5 rather than 1 because a single name can legitimately produce several definition hits — overloaded methods, or the same class name present in more than one indexed service.

Tests

tests/tools/test_search.py contained test_find_usages_can_undercount_when_all_fetched_hits_are_self_matches, which asserted the undercount as a documented known limitation. It is replaced by two tests:

  • the store is queried with limit + USAGE_OVERFETCH
  • a caller asking for 3 usages receives 3 even when the definition ranks first

Full suite: 293 passed.

🤖 Generated with Claude Code

… results

find_usages requested exactly `limit` fused hits, then filtered out the
symbol's own definition. Since the definition is typically a top hit for
the "code that uses or references X" query, callers received limit-1 (or
zero, at limit=1) results even when more usages existed just beyond the
fetch window.

Fetch `limit + USAGE_OVERFETCH` hits before filtering, then slice to
`limit`. The buffer is 5 rather than 1 because a single name can produce
several definition hits (overloads, same class name across services).

Replaces the test that asserted the undercount as a known limitation.

Fixes #74

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@GoodbyePlanet
GoodbyePlanet merged commit 273cad0 into main Jul 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_usages can return fewer than limit results

1 participant