Skip to content

fix(server): detect file renames in review diffs - #8086

Open
jakeleventhal wants to merge 1 commit into
pingdotgg:mainfrom
jakeleventhal:t3code/detect-file-renames-v2
Open

fix(server): detect file renames in review diffs#8086
jakeleventhal wants to merge 1 commit into
pingdotgg:mainfrom
jakeleventhal:t3code/detect-file-renames-v2

Conversation

@jakeleventhal

@jakeleventhal jakeleventhal commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Supersedes #3916 with a smaller implementation rebased onto the current UI and server architecture.

Problem

A filesystem rename appears as an unrelated deletion and addition in the Working tree review because tracked and untracked patches are generated separately.

Fix

  • Generate one unified working-tree patch when untracked files are present by copying the real Git index to a scoped temporary index.
  • Add untracked paths as intent-to-add only in that temporary index, then run git diff --find-renames once across tracked and untracked changes.
  • Preserve staged deletions and fall back to the existing separate-diff path if temporary-index setup fails.

The temporary index is necessary because Git cannot correlate a tracked deletion with an untracked destination unless both paths participate in the same diff. The user's real index is never modified, and the temporary file is removed when the scoped operation finishes.

Before

The current UI renders an exact filesystem rename as a deletion plus an addition:

Before: separate deleted and added files

After

The same fixture renders as one rename:

After: one detected rename

Rename with a minor edit

Rename detection is preserved when the destination also changes—in this fixture, one line is edited after the file is moved:

After: detected rename with a one-line edit

Performance

The normal path with no untracked files still uses two Git processes. When untracked files exist, the previous implementation used N + 2 processes (one diff --no-index per untracked file); this implementation uses a fixed five, with the independent staged-deletion and index-path lookups run concurrently. That is two extra processes for one untracked file, equal at three, and fewer for four or more.

On a tiny exact-rename fixture over 100 measured runs after 10 warmups, the one-file worst case increased from 16.6 ms median / 19.7 ms p95 to 33.9 ms median / 38.4 ms p95. In exchange, the cost no longer grows one Git process per untracked file and Git can detect renames correctly.

Validation

  • vp test run apps/server/src/vcs/GitVcsDriverCore.test.ts (54 tests)
  • targeted lint and formatting checks
  • server typecheck
  • current web UI integrated pass with a disposable rename fixture

Generated with GPT-5.6-Sol via T3 Code's Codex harness.

Note

Fix file rename detection in GitVcsDriverCore review diffs

  • Replaces the manual tracked+untracked diff concatenation in getReviewDiffPreview with a unified diff pipeline that adds --find-renames to all tracked git diff calls
  • readUnifiedWorkingTreeReviewDiff stages untracked files with --intent-to-add into a temp copy of the index (via GIT_INDEX_FILE) so the real index is never mutated, and filters untracked paths that have staged deletions
  • readWorkingTreeReviewDiff prefers the unified path and falls back to the old concatenated approach on failure; truncation state is propagated through all paths
  • Adds integration tests for unstaged rename detection, staged deletion preservation, and untracked file visibility before the first commit
  • Risk: readUnifiedWorkingTreeReviewDiff sets GIT_INDEX_FILE to a temp file; if cleanup fails, subsequent git commands in the process could target a stale index. The scoped context should restore the env var, but reviewers should confirm the temp file is removed on all exit paths

Macroscope summarized 49a8e8e.


Note

Medium Risk
Touches Git review-diff generation and uses a copied index plus GIT_INDEX_FILE/intent-to-add. The real index is not modified and failures fall back to the old path, but incorrect path filtering could still mis-render staged deletions or untracked files.

Overview
Working-tree review diffs now treat filesystem renames as a single rename (including edits) instead of an unrelated delete plus add.

When untracked files exist, the driver copies the Git index into a scoped temp file, intent-to-adds those paths there, and runs one git diff --find-renames against HEAD. The real index is never written. Staged deletions whose paths still exist on disk are excluded from that add so they stay deletions. If temp-index setup fails, it falls back to the previous separate tracked/untracked patches.

Tests cover rename-with-edit without mutating a split index, staged deletions, and untracked files before the first commit.

Reviewed by Cursor Bugbot for commit 49a8e8e. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00c0667c-fdb7-414e-8655-04e623c1fcc4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 24, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4234e41. Configure here.

Comment thread apps/server/src/vcs/GitVcsDriverCore.ts
Comment thread apps/server/src/vcs/GitVcsDriverCore.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — The server-side review-diff pipeline is substantially reworked for worktrees with untracked files, including temporary Git-index handling, staged-deletion filtering, fallback logic, and new rename rendering. Although the scope is confined to review previews and includes regression coverage, the runtime behavior and implementation complexity merit human review.

You can add or adjust custom eligibility rules. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant