~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.13.0 Latest 2 packages, 1 image

1
10

Code search's next page can repeat the last one's file

Closed
Closed chadtmiller.com opened this issue 1 comment
kind/bugarea/serve

What happened

searching_code in crates/knotless-serve/tests/web.rs fails now and then, on the spaces net. The second page of needle_&limit=1 repeats the first page's repository:

thread 'searching_code' panicked at crates/knotless-serve/tests/web.rs:3527:5:
assertion `left != right` failed

That line is assert_ne!(next["files"][0]["repo"], first["files"][0]["repo"]).

It failed once and then passed at one head of knotless-serve answers repositories' sites on their own domain, and failed twice in a row at its next head, 8c5a70cce2b3. Neither head touches code search.

The cause is that the cursor is an offset into an ordering that is not stable:

  • Code::search (crates/knotless-serve/src/code.rs) asks Zoekt for MaxDocDisplayCount = skip + limit files, and web/search.rs skips skip of them.
  • Zoekt sorts files by score alone. Files with equal scores, as the test's two repositories' needle_ files are, come back in whatever order its shards finish.
  • So the first page (1 file asked for) and the second (2 asked for, the first skipped) can rank the same two files differently.

How to see it

Run searching_code a few times on the spaces net, or read the test log of that pull at 8c5a70cce2b3. It's quarantined meanwhile in harness/quarantine.json.

What you expected

Each page continues the last, with no file shown twice. That takes a stable order: score, then repository and path. A tie at a page's edge is settled only by seeing every file that ties, so a fix asks past upto (to DEEPEST, or until the score drops), then sorts and slices. Measure what that costs first.

Where

knotless-serve's dev.knotless.searchCode, as main has it at 54981405.

Fixed by 45bb6590, "A code search's pages go on from the one before": every page now asks Zoekt for all 200 files and slices them in a fixed order (score, repository, path), so the next page no longer repeats a file from the one before. The searching_code quarantine that was meant to go with that fix is still in harness/quarantine.json, but it expires on 2026-11-10.