Skip to content

feat(review): branch and pr reviews compute their own base-vs-head symbol delta #593

Closed

Description

@dan-petty

Context & Rationale

Part 1 of this issue shipped in v0.2.23 (CHANGELOG.md:98). compute_symbol_delta (ai/analyze/symbols.py:32-42) records the symbols each file added, removed and kept on FileAnalysisMeta (models/ai.py:43-45). When the construct validator gets that removed set, a finding that cites a removed symbol is labelled "cites removed symbol" and moved to the nearest diff hunk instead of being invalidated (ai/review/construct_validator.py:396-414, :466-467). A symbol missing from both base and head is still invalidated (:469).

The exemption works when it gets the removed set. A scratch repo at ef21785 had a branch that deletes legacy_helper from mod.py. Against that branch, the finding "removal of legacy_helper breaks callers" came back INVALIDATED without the set. With the set it came back UNVERIFIED, noted "cites removed symbol".

Real reviews never get the set:

  • Only devops ai analyze branch computes a delta (commands/analyze.py:179-205, called at :214, :251 and :303). Nothing runs it before a review. The review's own pre-analysis calls analyze_single_file with no base (ai/review/pipeline.py:892-903). On the scratch repo, the branch review's pre-analysis recorded ([], [], []) for mod.py.
  • The base read is broken. git --no-pager show -- <rev>:<path> (commands/analyze.py:150-152) treats the argument as a pathspec. It prints the HEAD commit header, which never parses, so every head symbol counts as added. This is fix(review): the symbol delta is always empty because git show reads the base revision as a path #787, introduced by f93231b.
  • Branch reviews do not know each file's status. The review diff is git diff base...target (ai/review/runner.py:1822), and nothing records which files were added or renamed. devops ai analyze branch parses git diff --name-status (commands/analyze.py:504-516), but git prints a rename as R088<TAB>old.py<TAB>new.py. The parser keeps old.py<TAB>new.py as one path, which does not exist, so the renamed file is handled as deleted.
  • PR reviews have no base. _materialize_pr_head (ai/review/runner.py:1897-1944) writes the head version of each changed file. It reads the base only for convention files (:1917-1929).
  • Pre-analysis reuses cached deltas. _collect_paths_to_analyze (pipeline.py:953-981) reuses a cached FileAnalysisMeta whose file is unchanged, symbol lists included. A delta that devops ai analyze branch computed against another base therefore rides into the review.
  • Verification reads the wrong metadata and the wrong text. The orchestrated path calls _validate_segment_findings without metadata (ai/review/pipeline.py:2589-2595). That function then loads the newest *-metadata.json under the target, whichever review or branch wrote it (ai/review/verification.py:2029-2032, ai/analyze/cache.py:164-180). Its segments are the file's numbered source (pipeline.py:2585), which has no @@ headers. So no hunk is ever found to move the finding to.
  • The summary can show another branch's numbers. When the reviewed files have no delta, the summary adds up every file in the newest cached analysis (pipeline.py:3542-3546).

Nobody has measured how often reviews raise findings about removed symbols. This item makes removed_symbol_findings_count (ai/review_schema.py:1133) a real number, which #607's run history can then track.

Two parts of the earlier plan are no longer in this item:

  • Per-function complexity before and after is now its own backlog item (split off).
  • A scalar drift score stays out. vibes' EmbeddingDriftAuditor (examples/valkey-l2-repomap-cache/repomap_cache.py:326-400, bands at README.md:42-44) was re-run at ef21785 on two unrelated modules, commands/devcontainer.py and ai/gateway.py. It gave D_C = 0.0048, which it labels PRESERVED. The line-count dimensions make up 0.81 and 0.86 of the two unit vectors.

Scope & Deliverables

  • Deliverable: branch and PR reviews compute the delta for the files they review. They use it in verification and in the summary.
    • Move the base-read and merge-base helpers (commands/analyze.py:138-176, after fix(review): the symbol delta is always empty because git show reads the base revision as a path #787's fix) to git/operations.py as public functions. Add one more there: a changed-file lister that runs git diff --name-status -z over a range and returns each file's status, head path and, for a rename, its old path. devops ai analyze branch and the review both call these three, so the rename bug at commands/analyze.py:509-512 goes away.
    • Branch reviews: _prepare_branch_content (runner.py:1785-1856) also returns the base revision. For a branch, that is the merge base of effective_base and the target, the same base git diff base...target uses (:1822). If there is no merge base, the review already falls back to a two-dot diff (:1827-1833), and the base revision is effective_base. For a working-tree review it is HEAD (:1777, :1815). The file statuses come from the changed-file lister over the same range.
    • PR reviews: add one GitHubClient method that gets the merge base of pull.base.sha and pull.head.sha from the compare endpoint, next to get_file_at (github/client.py:140-149). For each modified or renamed .py/.pyi file, read the base text from the base repo at that commit. A renamed file is read at its previous_filename.
    • Pre-analysis records the delta on each changed Python file before it saves the session metadata. Every other file in the session metadata carries empty symbol lists, including files reused from the cache.
    • execute_finding_verification passes verification the session's metadata and each file's diff text. That diff text is the diff_map that persona review already gets (runner.py:2066-2071). Hunks come from the diff text, and the numbered source stays the verification context.
    • The summary counts only the reviewed files. Delete the fallback at pipeline.py:3542-3546.
    • Docs:
  • Acceptance criteria:
    1. A branch review's pre-analysis gets the delta with no earlier devops ai analyze branch run, and reads the right revision. Verified by a unit test with a fake base reader that logs each (revision, path) it is asked for and a fake merge-base resolver that returns a sentinel SHA:

      • The base mod.py defines legacy_helper and keep, and the head defines only keep. The session metadata for mod.py has added [], removed ["legacy_helper"] and retained ["keep"].
      • mod.py is read at the sentinel SHA, not at the base branch name.
      • A renamed file is read at its old path.
      • An added file is never read, and every one of its symbols is listed as added.
      • A working-tree review reads HEAD.
      • fix(review): the symbol delta is always empty because git show reads the base revision as a path #787's real-repo test covers the moved base-read helper. A second real-repo test covers the changed-file lister: a rename comes back as one entry with its old and new paths.
    2. A PR review reads the base at the merge base and uses it. Verified by a unit test whose _FakeGitHub (tests/test_review_scope.py:15-22) is keyed by (path, ref) and also answers the merge-base call. The test checks the fetch log:

      • the modified file is read from the base repo at the merge-base SHA;
      • the renamed file is read at its old path;
      • added and removed files get no base read;
      • no source file is read at pull.base.sha.

      It also checks that the PR session metadata for the modified file has removed ["legacy_helper"], and that the renamed file has the delta between its old and new text.

    3. Orchestrated verification exempts only real removals, with no model call. Verified by a unit test with a verification client fake that fails if it is called:

      • a finding that cites legacy_helper at mod.py:1 ends UNVERIFIED, noted "cites removed symbol", and its location is the file's diff hunk;
      • a finding that cites ghost_fn ends INVALIDATED.

      Neither fixture text contains an absence marker (config/constants.py:949-959), because those are checked before removed symbols (construct_validator.py:463-467).

    4. Only the session's own delta counts. Verified by a unit test that runs pre-analysis and then verification:

      • A newer cached analysis file that lists ghost_fn as removed from mod.py does not change criterion 3's results.
      • The cache on disk lists foo as removed from other.py, which is unchanged and outside the diff. The session metadata for other.py has empty symbol lists, and a finding on other.py that cites foo ends INVALIDATED.
    5. A failed base read leaves the delta empty. When the reader returns None for a modified file, that file's added, removed and retained lists are all empty. Verified by a unit test.

    6. The summary uses only the reviewed files. Verified by a unit test:

      • for criterion 3's fixture, findings.json has symbol_delta_summary == {"added": 0, "removed": 1, "retained": 1} and removed_symbol_findings_count == 1;
      • a review whose files have no delta shows no Symbol Delta row, even when a cached analysis on disk has one.
    7. The new tests make no network call (fix(test): the test network guard refuses loopback connects to services the test did not start #837's guard enforces this) and add under 1 s in total. The task file records the --durations figures. uv run devops ci passes.

    8. The docs are current. Verified in review of the diff:

      • grep -n Milestone docs/agent/tasks/task-593-*.md finds nothing;
      • the task file describes one PR;
      • if the PR edits docs/ROADMAP.md, grep -n lizard docs/ROADMAP.md finds no line for this item.
    9. A person runs this check with a live model. Worktrees share the main checkout's analysis cache (ai/analyze/cache.py:48-54, core/repo.py:194-200), so the check points the cache at an empty directory. It deletes a test helper, which the CLI never imports, so the code under test stays whole:

      git worktree add /tmp/probe-593 -b probe/593 main
      cd /tmp/probe-593
      # delete the _pull helper from tests/test_review_scope.py
      git commit -am "probe: remove a test helper"
      DEVOPS_CLI_DATA_ANALYSIS_DIR=$(mktemp -d) uv run devops review branch probe/593 --base main
      

      The summary table shows a Symbol Delta row with -1 or more. Then run uv run devops review pr <number>, without --post and with the same variable set, on an open PR that deletes a function. It shows the same row. Clean up with git worktree remove --force /tmp/probe-593 && git branch -D probe/593.

  • Key questions:
    • Which base does a branch review read? (proposed) The merge base of the effective base and the target, so the delta matches the reviewed diff. With no merge base, effective_base, matching the two-dot fallback diff. A working-tree review reads HEAD.
    • How does a branch review know which files were added or renamed? (proposed) From git diff --name-status -z over the same range as the reviewed diff, through the shared changed-file lister. Parsing the diff --git headers of the redacted, paged diff would be more fragile.
    • Which base does a PR review read? (proposed) The merge base from the compare endpoint, not pull.base.sha. base.sha is the base branch tip, which can be ahead of the merge base. A PR branched earlier would then list symbols added on main since as removed, which widens the exemption. The cost is one extra API call per review.
    • Which files get a delta? (proposed) Modified and renamed .py/.pyi files that exist at head:
      • Added files list every symbol as added and need no base read.
      • Deleted files get none. The validator returns a finding on a missing file unchanged (construct_validator.py:348-350, :479-480), and PR reviews do not write removed files (runner.py:1908-1912). So the review summary does not count a deleted file's symbols, unlike devops ai analyze branch.
      • Files outside the diff get none.
    • What does a failed base read mean? (proposed) The delta is unknown: it stays empty and a debug line is logged. compute_symbol_delta(None, head) would count every head symbol as added, which is the wrong number fix(review): the symbol delta is always empty because git show reads the base revision as a path #787 produces today. devops ai analyze branch follows the same rule, since it calls the same helper.
    • Where does verification get the delta? (proposed) From the session's own metadata in memory. The newest cache file can belong to another branch or to a review running at the same time.
    • Where do the git helpers live? (proposed) In git/operations.py. The ai layer imports from commands in only one place (ai/mcp/server.py:2844), and this item should not add a second.
    • Do path reviews change? (proposed) No. A path review has no base.
    • Does the fallback persona loop change (runner.py:1043)? (proposed) No. _make_review_clients always builds LLMClient (runner.py:1527-1561), so reviews take the orchestrated path.
    • What happens to the new GitHubClient method when refactor(github): one github session per identity owning token, quota and transport #767 removes PyGithub? (proposed) refactor(github): one github session per identity owning token, quota and transport #767 ports it with the other methods, with no shim.
    • Where does per-function complexity before and after go? It is now a separate backlog item. It uses refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773's mccabe entry, per owner decision D1 on feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586: ruff C901 is the definition, with no lizard, no radon and no new dependency.
  • Constraint:
    • The exemption stays narrow. A symbol missing from both base and head is invalidated.
    • This item ships no scalar score, threshold, persona routing or auto-apply verdict. Any score needs its own item and a labelled corpus.
    • No new dependency.
    • Tests use fakes for git and GitHub, apart from the two real-repo tests named in criterion 1. They make no network calls and use structural tuple asserts until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that.
    • The uv run devops ci gate stays within its 5-minute budget.

Strategic Alignment

Activity

  1. added this to the v0.2.23 milestone on Sep 25, 2026
  2. added
    type/feature
    scope/review
    priority/p1-high
    on Sep 25, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. modified the milestones: v0.2.23, v0.2.25 on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Retargeted from the shipped v0.2.23 to v0.2.25. It is still valid (checked 2026-10-01), and a P1 left open in a shipped release keeps precedence over P1 work committed later.

  6. changed the title [-]feat(review): base-vs-head symbol delta and removed-symbol finding exemption in reviews[/-] [+]feat(review): branch and pr reviews compute their own base-vs-head symbol delta[/+] on Oct 1, 2026
  7. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Closed by #932, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  8. added a commit that references this issue on Oct 3, 2026
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

    priority/p1-highscope/reviewtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions