Skip to content

Review gate loops re-review the whole range every push: no cross-push incremental reuse despite per-item fingerprints already existing #854

Open

Description

@Fanzzzd

Problem

In a PR review-gate loop (review → fix → push → review again), every round re-reviews the entire --from <merge-base> --to <head> range. The GitHub Actions posting helper already avoids re-posting duplicate comments (scripts/github-actions/post-review-comments.js, IoU-based incremental overlap dedupe), but the expensive part — the LLM re-reviewing files the new push did not touch — has no reuse path. On one iterative PR we measured 19 gate rounds at roughly 2M tokens per round; the large majority of that spend was files that were byte-identical between rounds.

The building blocks already exist, but are locked to same-range crash recovery

  • Every review item has a content fingerprint: sha256(mode + oldPath + newPath + diffText) (internal/agent/agent.go, reviewItemFingerprint). A file untouched by a new push keeps a byte-identical per-file diff against the same merge-base, hence the same fingerprint.
  • --resume <session-id> already reuses fingerprint-matched completed items (applyResume → RecordReviewItemReused), and the run manifest already has a coverage.reused bucket for exactly this.
  • But ResumeState.ValidateOptions (internal/session/resume.go) requires the resumed session's --from/--to to match the current run exactly, so the moment a new commit is pushed (--to moves) resume refuses, and the whole range is re-reviewed. Resume also needs the local session store, which an ephemeral CI runner has already thrown away.

Prior art: this is table stakes for PR reviewers

qodo-ai/pr-agent has incremental review (/review -i), and its design maps cleanly onto what is missing here (all verified against pr_agent/tools/pr_reviewer.py and pr_agent/git_providers/github_provider.py):

  • State lives in the PR, not on the runner. get_previous_review finds the bot's last review comment by its header prefix; no server-side storage is needed.
  • Delta detection: get_commit_range splits the PR's commit list at the previous review's timestamp → first_new_commit / last_seen_commit.
  • Scope = files touched by the new commits: unreviewed_files_map is the union of commit.files over the new range (merge commits from the default branch skipped); get_files() returns only those in incremental mode — i.e. file-granularity increments, exactly the granularity OCR's fingerprints already encode.
  • Safety: no previous review → automatic fall back to full review; optional thresholds (minimal_commits_for_incremental_review, minimal_minutes_for_incremental_review) gate auto-triggered incremental runs; the review output marks where the increment starts ("Starting from commit …").

CodeRabbit likewise reviews each push incrementally rather than re-reviewing the full PR every time.

Proposal

Two composable pieces:

  1. Cross-push reuse for range mode. Allow resuming with the same --from but a moved --to (either by relaxing ValidateOptions, or under a distinct flag so classic resume semantics stay strict). Selection stays exactly as today — compute the current merge-base..new-head diff and each item's fingerprint; items whose fingerprint matches a completed item in the reuse source are recorded as reused (with their previous comments, as applyResume already does), everything else is reviewed fresh. The fingerprint definition makes this safe by construction: any change to a file's diff — including base drift after a rebase, since the diff text changes — invalidates the match and forces a fresh review.

  2. An ephemeral-CI-friendly reuse source. Accept a previous run's output as the reuse source (e.g. --reuse-from <ocr-result.json>) instead of requiring the local session store. The JSON result and manifest already carry everything needed: per-item fingerprints in coverage.completed and per-file comments. The reference GitHub Actions flow already uploads that artifact and stamps the producing run id into the sticky summary (<!-- ocr-summary-run:… -->), so a workflow can locate the previous artifact the same way pr-agent locates its previous review comment — from the PR itself.

Mirroring pr-agent's safety behavior: no reuse source (or an unusable one) → silently fall back to today's full review; reused items are already visible in the manifest's coverage.reused, so a consumer can always tell a reused verdict from a fresh one.

Happy to work on this if the direction sounds right — starting with piece 1, which is small and keeps the current CLI surface.

Activity

  1. Fanzzzd commented on Aug 12, 2026

    @Fanzzzd
    ContributorAuthor

    One more motivating datapoint, from this repository's own dogfooding: .github/workflows/ocr-review.yml triggers on pull_request_target: types: [opened] only — a PR is reviewed exactly once, when it is opened, and never again on synchronize. On a PR that is reworked after review (e.g. #823, which was substantially restructured after its only OCR run), the standing verdict describes a head that no longer exists.

    That trigger choice is the other horn of the same dilemma this issue is about: re-reviewing the full range on every push is too expensive to enable, so the workflow doesn't re-review at all — trading stale verdicts for cost. Cross-push reuse is what would dissolve the dilemma: with unchanged files reused, a synchronize-triggered re-review costs roughly one changed file's worth of tokens, which makes keeping verdicts current affordable — here and in every downstream review-gate setup.

  2. Airport233 commented on Aug 13, 2026

    @Airport233
    Contributor

    I don’t really see it that way. OCR's review conclusion for a file doesn't just depend on that file's own diff — it also depends on whatever other context the agent dynamically reads at the time. The context beyond the diff is dynamic, so you need to consider whether the reviewed file's content still fits with other context that may have changed. A fingerprint can only tell you whether the file itself has changed compared to the last version. It can't guarantee that an unchanged file is still correct within the project, and the validity of existing review comments on that file might shift too.

  3. Fanzzzd commented on Aug 14, 2026

    @Fanzzzd
    ContributorAuthor

    That's a fair point, and worth being precise about: a reused verdict is the round-N verdict for that file, not a fresh judgment against the current tree — the fingerprint proves the diff didn't change, nothing more.

    What makes the trade-off workable in practice: the files whose context actually moved are exactly the ones re-reviewed fresh; the manifest already separates coverage.reused from completed, so inherited verdicts are always distinguishable; and the match could be tightened by folding in the rule/runtime config hashes the manifest already records, with an explicit fresh full pass available before merge. And the realistic alternative today isn't "always fresh" — it's full-cost re-review or, as with the opened-only trigger, no re-review at all.

    But you're right that this should be opt-in and clearly labeled, never silent.

  4. Airport233 commented on Aug 17, 2026

    @Airport233
    Contributor

    Never questioned the precision of single-file fingerprint matching. But that's a different question from what I raised — matching precisely only proves the file's own diff hasn't changed, not that its old verdict still holds up in a context that has since changed. Two different levels of correctness.
    Also, from what I can tell, resume's original intent in OCR isn't reusing prior work in a normal review flow — it's resuming after an abnormal interruption, same from/to, picking up where a crashed run left off. Repurposing it for cross-push reuse feels like using it for something it was never built for.

  5. Fanzzzd commented on Aug 20, 2026

    @Fanzzzd
    ContributorAuthor

    Agreed on both points. Resume should stay strict crash-recovery — dropping the "relax ValidateOptions" half of the proposal; shipping reviewers all treat incremental as a separately-named mode with full review as the fallback (CodeRabbit, pr-agent /review -i). Cross-push reuse, if ever wanted, would be the --reuse-from opt-in only.

    And yes — a fingerprint match proves the diff didn't change, not that the verdict still holds in changed context. The honest framing is an opt-in cache with known staleness, with the manifest's rule/runtime config hashes folded into the match key — the way build caches hash declared context (Bazel action keys, Turborepo).

  6. added a commit that references this issue on Sep 19, 2026
    ced7c0a
  7. added 3 commits that reference this issue on Nov 13, 2026
    27854e6
    e40de4f
    0403a04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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