Skip to content

fix: determinism in file order#103

Merged
stephantul merged 2 commits into
mainfrom
determinism
May 18, 2026
Merged

fix: determinism in file order#103
stephantul merged 2 commits into
mainfrom
determinism

Conversation

@stephantul

Copy link
Copy Markdown
Contributor

This PR fixes a low-key determinism bug. Due to python's HASHSEED behavior, it was possible that two chunks from the same file with the same score would get a different tie break. Because of the way we calculate boosting, this would result in different rankings, and slightly different NDCG@10 scors.

The fix is just sorting the chunks, leading to a stable key which does not rely on a specific hash seed.

@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/semble/index/file_walker.py 100.00% <100.00%> (ø)
src/semble/search.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ignored = []
extensions_as_patterns = [f"!*{ext}" for ext in extensions]
ignored.extend(extensions_as_patterns)
ignored.extend(_DEFAULT_IGNORED_DIRS)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also a possible source of errors, although I think it actually wasn't causing an issue.

]

for item in directory.iterdir():
for item in sorted(directory.iterdir()):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem, this could result in issues, so just to rule it out, we sort here.

spec = _load_ignore_for_dir(directory)
if spec is not None:
active_specs = [
inherited_specs = [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done like this to avoid an in-place edit of inherited_specs.

Comment thread src/semble/search.py
# Sort by the file path and start line to
# counteract randomness introduces by hashing.
all_candidates = sorted(
{*normalized_semantic, *normalized_bm25},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the actual bugfix

@stephantul
stephantul merged commit ae39ec5 into main May 18, 2026
16 checks passed
@stephantul
stephantul deleted the determinism branch May 18, 2026 06:52
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.

2 participants