Skip to content

perf(review): skip duplicate full-file-content fetch for added files already covered by the diff #3897

Description

@JSONbored

Context

GITTENSORY_REVIEW_GROUNDING=true is set in the recommended self-host starter env (.env.selfhost.example), and the single flag drives both CI grounding and full-file-content fetching together (src/review/grounding-wire.ts).

fetchFullFileContents (src/review/review-grounding.ts) fetches the full post-change body of every changed file whose status !== "removed" — including newly ADDED files — via a separate GitHub Contents API call per file, and splices it into the prompt as a "FULL FILE CONTENT" block. But the diff itself (sent in the same prompt, up to 120,000 chars) already contains every line of a newly added file, since every line of a new file is a + in the patch. So for added files, the full-file fetch is a byte-for-byte duplicate of content already in the diff — a wasted network round-trip and wasted prompt tokens on every AI-reviewed PR under the recommended self-host config.

Requirements

  • Skip the full-file-content fetch for files with status === "added" (the diff already is the full file for those).
  • For modified files, consider only fetching when the patch's changed-line count is a small fraction of the file's total lines, so grounding adds real surrounding context instead of re-sending lines already in the diff.

Acceptance criteria

  • An added file's content appears in the prompt exactly once (via the diff), not twice.
  • A test asserts no Contents API fetch is made for an added-file entry in the changed-files list.
  • Existing grounding coverage for genuinely-needed full-file context (large modified files) is unaffected.

Parent: #1667

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions