Skip to content

perf(review): dedupe full-file grounding fetch for modified files #4009

Description

@JSONbored

Context

fetchFullFileContents() (src/review/review-grounding.ts:130) sends a changed file's full post-change body to the AI reviewer in addition to its diff hunk. A prior fix (#3918) correctly excluded newly-added files (100% provable overlap with the diff), but the far more common case — a modified file whose diff hunk already covers the whole file (e.g. a small file rewritten in one hunk) — still pays for both the diff and an overlapping full-file block, unconditionally, whenever GITTENSORY_REVIEW_GROUNDING is enabled.

Currently bounded in blast radius since grounding defaults off (src/review/grounding-wire.ts:30), but will cost real, avoidable tokens on any repo where an operator turns it on.

Requirements

  1. Extend the existing added-file dedup logic in fetchFullFileContents to also cover modified files: if a modified file's diff hunk header(s) show the changed line range already spans (or nearly spans) the file's total line count, skip the redundant full-file fetch, exactly as is already done for added files.
  2. Preserve the existing budget caps (MAX_SINGLE_FILE, FILE_CONTENT_BUDGET) and behavior for files that are only partially changed (where the full-file context still adds real value).

Deliverables

  • Updated fetchFullFileContents in src/review/review-grounding.ts.
  • Test coverage for: a fully-rewritten-in-one-hunk file (should skip the full-file fetch), a partially-changed file (should still include it), and the existing added-file case (should remain unaffected).

Expected outcome

Reduced token cost per review on any repo with grounding enabled, with no loss of reviewer context quality (a file whose diff already shows its entire content gains nothing from also seeing that same content as a separate block).

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.orbGittensory Orb related - maintainer self-hosting analytics.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions