Files
codegraph/__tests__
Colby MchenryandClaude Opus 5.5 c46523079f fix(context): the busiest file is found even when 20 test or generated files outrank it (#2785)
Root cause: getDominantFile and getTopRouteFile took the top 20 files in
SQL and only then dropped test and generated files in code. Twenty test
files busier than the app's busiest file left nothing, so getDominantFile
returned null and the context builder's core-directory boost never applied.
Nineteen left the dominant file without its runner-up, and nextEdgeCount 0
passes the "3x the next file" test for a file that is not dominant at all.
getTopRouteFile returned null the same way, and measured its 30% share
against the routes of the 20 files in the window, not the project's.

Fix:
- DOMINANT_FILE_SQL ranks every file. The window saved no work: ORDER BY
  needs every group, so the aggregate runs to the end either way, and only
  one row per file comes back.
- computeDominantFile filters the ranking 20 rows at a time until it has
  the dominant file and its runner-up. The generated-file lookup stays a
  bounded probe per batch.
- getTopRouteFile counts every route file, with ties broken by path.

Validation:
- New dominant-file-window.test.ts, 6 tests, all failing on main: the
  issue's layout with 20 and with 19 test files, 25 header-declared
  generated files (past the first batch), and three route shapes.
- The dominant-file cache, plan and allocation suites and the route-file
  detector test pass.
- Seven of the eight real repos give the same dominant file before and
  after (express, flask, excalidraw, django, airflow, grpc-go, etcd). The
  closest to the window was airflow, with the runner-up at rank 16.
- envoyproxy/go-control-plane crosses the window: 254 generated and test
  files outrank its first hand-written file. Main returns null; the fix
  returns xdsmatcher/pkg/matcher/matcher.go (167 edges, runner-up 165).
- getTopRouteFile on main reported django's admin/sites.py at 8 of 16
  routes and airflow's ui router at 65 of 65. Counting every route file
  gives 8 of 32 and 65 of 332, both under 30%, so null as documented.
- Cost, median of 3 interleaved rounds of 5: getDominantFile on airflow
  (8,564 ranked files) 581 -> 587 ms, django 189 -> 181 ms,
  go-control-plane 277 -> 284 ms. getTopRouteFile on airflow 1.3 -> 2.5 ms.
- Explore A/B, main vs fix: 996 queries on express, flask, excalidraw,
  django, airflow and go-control-plane, all byte-identical.

Fixes #2578

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 06:45:02 +00:00
..