Skip to content

Validate AI feedback points against PR files before posting review comments #16

@chinar-amrutkar

Description

@chinar-amrutkar

Problem

When the AI returns feedback points, the file_name and line_numbers values aren't validated against the actual PR diff before being sent to the GitHub API. This causes silent failures:

  • If the AI references a file not in the PR, GitHub rejects the review
  • If the AI returns a line number outside the valid range, GitHub rejects the review
  • When this happens, the POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews call returns 422 and no comments get posted at all -even valid ones are lost

Steps to reproduce

  1. Trigger a review on a PR where the AI returns a feedback point referencing a file not in the diff, or a line number beyond the file length
  2. The review request to GitHub fails with 422
  3. No review comments appear on the PR

Suggested fix

In handleLabeled.ts, after getting the AI feedback and before calling postInlineComments, filter each feedback point:

  • Verify point.file_name matches a file returned by getPRFiles
  • Verify each line number in point.line_numbers is within the range of lines in that file's patch

This could be a utility function like validateFeedbackPoints(points: FeedbackPoint[], files: PRFile[]) that returns only the valid points. Invalid points could be logged to console for debugging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions