Skip to content

fix(pr-review-toolkit): translate merge-result line numbers to PR HEAD before posting#71

Merged
cblecker merged 1 commit into
mainfrom
fix/pr-review-line-translation
Jul 4, 2026
Merged

fix(pr-review-toolkit): translate merge-result line numbers to PR HEAD before posting#71
cblecker merged 1 commit into
mainfrom
fix/pr-review-line-translation

Conversation

@cblecker

@cblecker cblecker commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add "Translate Line Numbers for Posting" section to SKILL.md that diffs HEAD^2 vs HEAD to translate merge-result line numbers to PR HEAD before posting comments, and moves unmappable findings (merge-only lines or lines outside PR diff hunks) to the review body
  • Update patchInstructions() prompt strings in review-pr.js to inform agents that their line numbers correspond to the merge-result checkout and will be translated before posting
  • Bump version from 1.8.1 to 1.9.0

Fixes the issue where add_comment_to_pending_review calls fail with "line doesn't exist in PR diff" when the base branch has diverged and lines have shifted between the merge result and PR branch HEAD.

Test plan

  • Run a PR review on a repo where main has diverged, touching files the PR also modifies
  • Verify files with identical content between HEAD and HEAD^2 skip translation
  • Verify files that differ get translated line numbers
  • Verify comments land on the correct lines in the GitHub UI
  • Verify unmappable lines (merge-only code) go to the review body
  • Verify the existing "Invalid locations" fallback still catches any remaining edge cases

Summary by CodeRabbit

  • New Features

    • Improved review comment posting so line references are translated correctly to match the pull request view.
    • Added clearer handling for cases where a change doesn’t appear in the main diff, keeping line references accurate.
  • Bug Fixes

    • Reduced the chance of review comments landing on the wrong line when reviewing merge-based changes.
  • Chores

    • Bumped the plugin version to 1.9.0.

Copilot AI review requested due to automatic review settings July 4, 2026 03:25
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cblecker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d40579a9-0914-41b0-8b00-854fbf498b62

📥 Commits

Reviewing files that changed from the base of the PR and between 2f811cb and dd8db72.

📒 Files selected for processing (3)
  • pr-review-toolkit/.claude-plugin/plugin.json
  • pr-review-toolkit/skills/review-pr/SKILL.md
  • pr-review-toolkit/skills/review-pr/review-pr.js
📝 Walkthrough

Walkthrough

Adds documentation and prompt updates for translating finding line numbers from the merge-result checkout to PR HEAD line numbers before posting review comments, and bumps the plugin manifest version from 1.8.1 to 1.9.0.

Changes

Line-number translation for PR review comments

Layer / File(s) Summary
Translation algorithm documentation
pr-review-toolkit/skills/review-pr/SKILL.md
Adds a pre-check to skip translation when PR HEAD matches the merge-result checkout, plus a hunk-based algorithm to map merge-result lines to PR HEAD lines, handle merge-only lines, and validate translated lines fall within PR diff hunks.
Prompt wiring
pr-review-toolkit/skills/review-pr/review-pr.js
Updates patchInstructions(prContext) prompt text in two branches to instruct that finding line numbers must be translated before posting.
Plugin version bump
pr-review-toolkit/.claude-plugin/plugin.json
Bumps manifest version from 1.8.1 to 1.9.0.

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: translating merge-result line numbers to PR HEAD before posting review comments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr-review-line-translation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI 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.

Pull request overview

This PR fixes a real failure mode in the pr-review-toolkit review-pr skill: when the PR's base branch has diverged, line numbers derived from the local merge-result checkout (HEAD^1..HEAD) no longer match the PR branch HEAD (HEAD^2), causing add_comment_to_pending_review to fail with "line doesn't exist in PR diff". It adds a documented procedure to translate merge-result line numbers back to PR HEAD before posting, updates the analysis prompts to signal that translation happens, and bumps the plugin version.

The translation algorithm itself is sound: it correctly interprets git diff HEAD^2 HEAD hunk headers (- side = PR HEAD, + side = merge result), correctly moves merge-only (+) lines to the review body, correctly counts context/- lines within a hunk, and correctly accumulates (b - d) offsets between hunks.

Changes:

  • Add a "Translate Line Numbers for Posting" section to SKILL.md describing how to map merge-result lines to PR HEAD and move unmappable findings to the review body.
  • Update patchInstructions() in review-pr.js to tell local-git-mode agents their line numbers will be translated before posting.
  • Bump plugin version 1.8.1 → 1.9.0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pr-review-toolkit/skills/review-pr/SKILL.md Adds the line-number translation procedure between preview/approval and posting.
pr-review-toolkit/skills/review-pr/review-pr.js Adds a "will be translated" note to the two local-git diff-context prompts.
pr-review-toolkit/.claude-plugin/plugin.json Version bump to 1.9.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pr-review-toolkit/skills/review-pr/SKILL.md Outdated
Comment thread pr-review-toolkit/skills/review-pr/SKILL.md Outdated
Comment thread pr-review-toolkit/skills/review-pr/SKILL.md Outdated
…D before posting

Review agents analyze the merge-result checkout for quality, but GitHub's
add_comment_to_pending_review API expects line numbers from the PR branch
HEAD (HEAD^2). When the base branch has diverged, lines shift between the
two, causing API rejections for valid findings.

Add a translation step in SKILL.md before posting that diffs HEAD^2 vs HEAD
to compute the offset, and moves unmappable findings to the review body.
Update workflow prompt strings to note that agent line numbers correspond to
the merge result.

Assisted-by: Claude:claude-opus-4-6

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@cblecker cblecker merged commit a595f4b into main Jul 4, 2026
14 checks passed
@cblecker cblecker deleted the fix/pr-review-line-translation branch July 4, 2026 03:58
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