Skip to content

fix(github): honor line references in ?plain=1 links in github_files_tool - #2525

Merged
rapids-bot[bot] merged 1 commit into
NVIDIA:developfrom
abhishekacharya200:fix/github-files-tool-line-links
Oct 31, 2026
Merged

rapids-bot[bot] merged 1 commit into
NVIDIA:developfrom
abhishekacharya200:fix/github-files-tool-line-links

Conversation

@abhishekacharya200

@abhishekacharya200 abhishekacharya200 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

GitHub adds ?plain=1 to line links for rendered files such as Markdown. The URL pattern in github_files_tool stopped at the ?, so the line reference was lost and the tool returned the whole file. The pattern now skips the query string.

While in the same code, two line references returned wrong output with no error. #L0 returned the last line of the file, and a reversed range returned an empty block. Both now return an Error: message, like line numbers past the end of the file already do.

Real calls through the tool's function, for links to README.md at 349aacd:

Link suffix On develop (349aacd) With this change (c2a00e7)
?plain=1#L18 whole file, 258 lines line 18
?plain=1#L18-L19 whole file, 258 lines lines 18 and 19
#L0 last line of the file Error: Line 0 is out of range for the file ...
#L19-L18 empty code block Error: Line range 19-18 is reversed
#L18 line 18 line 18

Added test_get_file_handles_line_references in packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py, using the same httpx.MockTransport setup as the other file tool test. Four of its five cases fail on develop. The fifth, a ?plain=1 link with no line, passes on both and guards the whole file path.

Validation:

  • pytest packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py: 34 passed (4 failed, 30 passed on develop).
  • yapf --diff and ruff check on both changed files: no changes or findings.

Closes #2524

Maintainer metadata: please add the bug and non-breaking labels.

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • Bug Fixes
    • GitHub file links with query strings and line references are now handled correctly.
    • Invalid line numbers and reversed line ranges now return errors.

…tool

GitHub adds ?plain=1 to line links for rendered files such as Markdown.
The URL pattern stopped at the query string and lost the line reference,
so the tool returned the whole file. Also report #L0 and reversed ranges
as errors instead of returning the last line or an empty block.

Signed-off-by: abhishekacharya200 <abhishekacharya200@users.noreply.github.com>
@abhishekacharya200
abhishekacharya200 requested a review from a team as a code owner October 31, 2026 05:35
@copy-pr-bot

copy-pr-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

github_files_tool now accepts query strings before line fragments and validates requested line ranges. Parameterized tests cover selected lines, full-file output, and invalid ranges.

Changes

GitHub file line references

Layer / File(s) Summary
URL matching and line-range handling
packages/nvidia_nat_core/src/nat/tool/github_tools.py, packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py
The URL pattern accepts a query string before a line fragment. The tool rejects start line 0 and reversed ranges. Tests cover selected lines, full-file output, and range errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to c2a00

No actionable merge-blocking risk is established by the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the GitHub line-reference fix and uses imperative mood. At 73 characters, it is approximately within the 72-character target.
Linked Issues check Passed Issue #2524 requires three coding outcomes. The URL pattern now accepts query text before the fragment, so ?plain=1#L... references remain available. The implementation rejects start lines below 1 a…
Out of Scope Changes check Passed The diff changes only github_tools.py and its focused test file. The production changes implement issue #2524. The added tests directly verify the requested behavior. No unrelated change is demonstr…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #2524 requires three coding outcomes. The URL pattern now accepts query text before the fragment, so ?plain=1#L... references remain available. The implementation rejects start lines below 1 and rejects reversed ranges with Error: messages. The added parameterized test covers a query-string line, a query-string range, a query string without a line, #L0, and a reversed range.

Full details: Out of Scope Changes check

Explanation

The diff changes only github_tools.py and its focused test file. The production changes implement issue #2524. The added tests directly verify the requested behavior. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 1
packages/nvidia_nat_core/src/nat/tool/github_tools.py-508-508: 1

508-508: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Use GitHub-compatible line boundaries.

splitlines() treats form feeds as line boundaries, unlike GitHub Markdown line endings. (docs.python.org) For alpha\fbravo\ncharlie\n, a newly supported ?plain=1#L2 link returns bravo instead of charlie. Split on CR, LF, and CRLF boundaries instead.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 349aacd and c2a00e7.

Files selected for processing: 2
  • packages/nvidia_nat_core/src/nat/tool/github_tools.py
  • packages/nvidia_nat_core/tests/nat/tools/test_github_tools.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@willkill07 willkill07 added bug Something isn't working non-breaking Non-breaking change labels Oct 31, 2026
@willkill07

Copy link
Copy Markdown
Member

/ok to test c2a00e7

@willkill07

Copy link
Copy Markdown
Member

/merge

1 similar comment
@willkill07

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit 8cff34f into NVIDIA:develop Oct 31, 2026
15 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 non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: github_files_tool ignores the line in ?plain=1 links and mishandles #L0 and reversed ranges

2 participants