Skip to content

docs(search): note last_n_commits range can include extra merged-branch commits - #558

Merged
HananKavitzAmat merged 3 commits into
chunkhound:mainfrom
tharunsridhar:docs/last-n-commits-merge-note
Nov 23, 2026
Merged

HananKavitzAmat merged 3 commits into
chunkhound:mainfrom
tharunsridhar:docs/last-n-commits-merge-note

Conversation

@tharunsridhar

@tharunsridhar tharunsridhar commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #530.

What

  • Document that last_n_commits can return substantially more than N commits when merged branches sit at the edge of the window (up to about 100 extra in a large repository). The extras can come from the merged branches or from the mainline.
  • Say plainly that a value above the available history is clamped to the full history. The CLI prints a warning; MCP callers see no notice.
  • Add a test that runs the MCP resolver against a real merge repo and checks it matches resolve_last_n_commits_range.

Why

  • On this repo (1374 commits), most small N gave exactly N, but not all (N=82 to 84 gave 85).
  • N=500 gave 532, because of merge commits at the window edge.
  • A reviewer measured a worst case of N=354 returning 455 commits (+101) on the current head.
  • The help text and tool descriptions did not mention this.

Testing

  • tests/unit/test_last_n_commits_range.py: 11 passed (run before the latest wording-only commit).
  • Changes are help text, tool descriptions and one test only.

@HananKavitzAmat HananKavitzAmat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Changes Requested (2 blocking issues, 2 warnings, 3 suggestions)

PR: #558 — docs(search): note last_n_commits range can include extra merged-branch commits
Author: @tharunsridhar
Files changed: 3 (+28 -5)

Thanks for following up on the #530 review — documenting the clamp and the ragged window edge is the right direction, and the CLI help and the MCP tool descriptions now agree with each other.

Two points on the wording before this lands. I verified both by running the PR's own resolve_last_n_commits_range (loaded directly from runner.py) against this repository, at the PR head (d886ffc9, 1385 commits) and at the 1374-commit revision cited in the PR body (09119a22).

🔴 Blocking

  • chunkhound/mcp_server/tools.py:512, 552, 733, 854 and chunkhound/api/cli/parsers/common_arguments.py:192 — "a few extra commits" understates the measured behaviour. At the head the worst case is N=354 → 455 commits (+101 extra); at the revision quoted in the PR body it is N=343 → 444 (+101 extra). 379 of 1385 N values (27%) do not return exactly N. At N=354 all 101 extras are older than every commit in the requested window, so the range reaches back before the window rather than only sitting at a ragged edge. Suggestion: say "can include substantially more than N (up to ~100 extra in this repository)" and drop "a few".

  • Same lines — "extra commits from those branches" is not always accurate. 311 of 1385 N values (22%) at the head pull in at least one first-parent mainline commit, and a single window can carry up to 19 of them. At N=600 on the head, all four extras are mainline commits. Suggestion: "may include extra commits, from the merged branches or from the mainline between the branch point and the window".

⚠️ Warnings

  • tools.py:512 etc. — "clamped to the full history without notice" is accurate for MCP but not for the CLI. runner.py:198 emits a loguru WARNING and the CLI installs a stderr sink at WARNING level, so chunkhound search --last-n ... does surface it; mcp_server/stdio.py::_silence_loguru removes all sinks, so MCP callers do not. Since the sentence is now shared between both, please split it — e.g. "is clamped to the full history (the CLI prints a warning; MCP callers see no notice)".

  • tests/unit/test_last_n_commits_range.py:262 — the new test asserts commit_range == await resolve_last_n_commits_range(5, merge_repo) and then the file set {c2.py, f1.py, f2.py, m3.py}, which is identical to the existing assertion at line 129. The unmocked wiring is a genuine improvement, but .chunkhound/db is created at the repo root, so the test never exercises the git rev-parse --show-toplevel walk-up in _git_cwd_from_services — the part that actually needs coverage. Putting the DB directory in a subdirectory would test the intended path; as written the test would still pass if the walk-up regressed.

💡 Suggestions

  • The new sentence is duplicated verbatim at four sites in tools.py plus a variant in common_arguments.py. A shared constant would make future wording changes one edit.
  • site/src/pages/docs/cli-reference.md:108, 220 and components/Capabilities.astro:45 still describe --last-n with no clamp or overshoot note; the published docs are what users read.
  • The PR body says "N from 1 to 100 gave exactly N commits". On the 1374-commit revision, N=82, 83 and 84 return 85. Worth correcting so the record matches.

✅ Looks Good

  • Correct direction on the #530 feedback, and the CLI help and MCP descriptions are now consistent with each other.
  • The clamp, empty-tree and shallow-clone behaviour the text documents is real and reproduces: N=1385 at the head yields the empty-tree range covering exactly 1385 commits, with one warning.
  • The test count and the N=500 → 532 figure in the PR body are accurate.

CI: read from the API on d886ffc9 — 27 check runs, 23 success, 4 skipped (release/deploy, expected), 0 failures. Note the repository has no Python lint or type-check job, so CONTRIBUTING's ruff/mypy gate is not enforced by CI.


Reviewed by Hanan's bot

Comment thread chunkhound/mcp_server/tools.py Outdated
- commit_range: Optional git revision range (e.g. 'HEAD~10..HEAD', 'v1.0..v2.0'). When provided with type='semantic', searches changed code in that range.
- commit_hash: Single commit hash — searches only that commit's diff (equivalent to '<hash>^..<hash>').
- last_n_commits: Integer shorthand — searches the last N commits reachable from HEAD (merge commits count; a value above the available history covers the full history).
- last_n_commits: Integer shorthand — searches the last N commits reachable from HEAD (merge commits count; a value above the available history is clamped to the full history without notice; when merged branches leave a ragged window edge, the range may include a few extra commits from those branches).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔴 Blocking: "a few extra commits" understates the measured behaviour, and the extras are not always from a branch.

Running this PR's resolve_last_n_commits_range against this repo at the head (d886ffc9, 1385 commits): worst case is N=354 → 455 commits (+101); 379 of 1385 N values (27%) do not return exactly N. At N=354 all 101 extras are older than every commit in the window, so the range reaches back before the window.

Separately, 311 of 1385 N values (22%) pull in at least one first-parent mainline commit, up to 19 in one window; at N=600 all four extras are mainline commits.

Suggestion: "can include substantially more than N (up to ~100 extra in this repository), from the merged branches or from the mainline between the branch point and the window".

"Last N commits reachable from HEAD (merge commits count). "
"A value above the available history covers the full history."
"A value above the available history covers the full history. "
"With merged branches the range may include a few extra commits."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Warning: the sibling sentence in the MCP descriptions says the clamp happens "without notice", but for the CLI that is not true — runner.py:198 emits a loguru WARNING and the CLI installs a stderr sink at WARNING level, so chunkhound search --last-n ... does surface it. Only the MCP stdio path silences it (_silence_loguru). Since the wording is now shared, please make the two cases explicit.

db_dir.mkdir()
services = SimpleNamespace(provider=SimpleNamespace(db_path=db_dir / "db"))

commit_range = await _resolve_commit_range(None, None, 5, services) # type: ignore[arg-type]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Warning: this test does not exercise the part it appears to target. .chunkhound/db is created at the repo root, so _git_cwd_from_services resolves the root without ever taking the git rev-parse --show-toplevel walk-up — the behaviour that exists for the DB-in-a-subdirectory case. The file-set assertion is also identical to the one already at line 129. Putting the DB directory in a subdirectory would cover the walk-up; as written the test would still pass if it regressed.

@HananKavitzAmat HananKavitzAmat added the bug Something isn't working label Nov 22, 2026
@tharunsridhar

Copy link
Copy Markdown
Contributor Author

Pushed a wording update: the overshoot is now described as substantially more than N (up to ~100 extra in a large repository, from merged branches or the mainline), and the clamp note says the CLI prints a warning while MCP callers see no notice. Left the test and site-docs suggestions out to keep this PR docs-only and small.

@tharunsridhar

Copy link
Copy Markdown
Contributor Author

@HananKavitzAmat thanks for the detailed review. The wording points are addressed in 6db960f: the overshoot is now described as substantially more than N (up to ~100 extra), with extras from merged branches or the mainline, and the clamp note says the CLI warns while MCP callers see no notice. The PR body is corrected too, and CI is green. I left the walk-up test, shared constant and site docs out to keep this PR docs-only. Could you take another look when you have a moment?

@tharunsridhar

Copy link
Copy Markdown
Contributor Author

I added the walk-up test after all (2454c68). It puts the DB in a subdirectory of the repo and runs from an unrelated cwd, so it only passes if the git rev-parse --show-toplevel walk-up works. I still left the shared constant and the site docs out to keep this PR small. Could you take another look when you have a moment?

@HananKavitzAmat
HananKavitzAmat self-requested a review November 23, 2026 13:44

@HananKavitzAmat HananKavitzAmat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good. Thanks!

@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Nov 23, 2026
Merged via the queue into chunkhound:main with commit 9ddcbdd Nov 23, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants