Skip to content

fix: harden git-backed change review - #175

Closed
Waishnav wants to merge 4 commits into
feat/show-changes-journalfrom
feat/show-changes-git-hardening
Closed

fix: harden git-backed change review#175
Waishnav wants to merge 4 commits into
feat/show-changes-journalfrom
feat/show-changes-git-hardening

Conversation

@Waishnav

@Waishnav Waishnav commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Hardens the git-backed review fallback (DEVSPACE_REVIEW_MODE=git).

What changed

  • Review checkpoints are now root commits built from a temporary index inside the git common directory (fsmonitor and untracked cache disabled). They no longer link to HEAD, so capture is isolated from the real index and works on repositories with no commits yet.
  • The manager records the HEAD used at capture and re-anchors both checkpoint refs when the repository's HEAD moves, so reviews never diff across unrelated histories. Checkpoints created before this change are left untouched.
  • Diffs ignore whitespace-only changes by default, use the standard 10 MB output cap, and degrade to a file list instead of failing when the patch exceeds it.
  • Docs describe the journal vs git review modes, DEVSPACE_REVIEW_MODE, and the checkpoint refs (refs/devspace/review/<workspace>/open and /baseline).

Why

The fallback is the path users choose when they want repository-backed review; it should be as robust as the journal. Root commits and re-anchoring remove the snapshot's coupling to a moving HEAD; the new unborn-repository behavior makes empty repos reviewable immediately.

Top PR of three; sits on #174.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: 45304cf3-15c1-4384-b1ce-b74ecfd061ca

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.

@Waishnav Waishnav changed the title feat/show changes git hardening fix: harden git-backed change review Aug 9, 2026
@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens git-backed change reviews by adding unborn-repository support, HEAD re-anchoring, whitespace filtering, and oversized-patch degradation.

  • Stores temporary review indexes inside the Git common directory.
  • Tracks repository HEAD changes and re-anchors persisted review checkpoints.
  • Ignores whitespace-only changes by default and documents the git review mode.
  • Adds coverage for unborn repositories, whitespace handling, and large patches.

Confidence Score: 2/5

This PR should not merge until re-anchoring preserves pending edits, persisted checkpoints restore HEAD tracking, and oversized numstat output degrades safely.

The new checkpoint flow can silently baseline unreviewed edits after HEAD movement, skip history-change detection after a manager restart, and fail outright on sufficiently large file lists.

Files Needing Attention: src/review-checkpoints.ts, src/review-checkpoints.test.ts

Important Files Changed

Filename Overview
src/review-checkpoints.ts Adds the git-hardening behavior, but re-anchoring can consume pending edits, persisted managers lose HEAD tracking, and numstat overflow bypasses degradation.
src/review-checkpoints.test.ts Adds useful regression coverage but omits HEAD movement with pending edits, restart-plus-HEAD movement, and numstat overflow.
docs/configuration.md Documents journal and git review modes, checkpoint behavior, whitespace filtering, and oversized-patch fallback.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[show_changes in git mode] --> B{HEAD moved?}
    B -- Yes --> C[Snapshot current working tree]
    C --> D[Set open and baseline refs]
    D --> E[Return empty review]
    B -- No --> F[Snapshot current working tree]
    F --> G[Generate patch with 10 MB fallback]
    G --> H[Generate numstat with 10 MB hard limit]
    H --> I[Summarize files]
    I --> J{Mark reviewed?}
    J -- Yes --> K[Advance baseline]
    J -- No --> L[Return review]
    K --> L
Loading

Reviews (1): Last reviewed commit: "docs: document change review modes and r..." | Re-trigger Greptile

Comment thread src/review-checkpoints.ts Outdated
Comment on lines +98 to +100
const snapshot = await createWorkingTreeSnapshot(state.gitRoot);
await git(state.gitRoot, ["update-ref", state.openRef, snapshot.commit]);
await git(state.gitRoot, ["update-ref", state.baselineRef, snapshot.commit]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Re-anchoring consumes pending edits

When HEAD moves while unreviewed working-tree edits are present, createWorkingTreeSnapshot includes those edits in both new checkpoints and returns an empty review, causing the pending edits to disappear from subsequent reviews.

Comment thread src/review-checkpoints.ts
Comment on lines 210 to 213
} else {
state.openRefAvailable = openCommit !== undefined;
state.baselineRefAvailable = baselineCommit !== undefined;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Persisted refs disable HEAD tracking

When a manager restarts with existing review refs, this branch leaves headTracked unset, so subsequent HEAD movement bypasses re-anchoring and can report committed or unrelated branch changes as pending workspace changes.

Comment thread src/review-checkpoints.ts Outdated
Comment on lines 134 to 136
const numstat = (await git(state.gitRoot, ["diff", ...whitespaceArgs, "--numstat", "-z", baseline, current.commit], {
maxBuffer: 10 * 1024 * 1024,
})).stdout;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Numstat bypasses oversized-diff fallback

When git diff --numstat -z produces more than 10 MB of output, this uncaught buffer limit makes show_changes fail instead of returning the documented file-list fallback.

@Waishnav
Waishnav force-pushed the feat/show-changes-git-hardening branch from 7395469 to 657bff7 Compare August 9, 2026 19:49
Review checkpoints were commits created with -p HEAD from an index in
the system temp directory, and the whole path failed on repositories
with no commits yet.

Snapshots are now root commits built from a temporary index inside the
git common directory with fsmonitor and the untracked cache disabled,
so capture is isolated from the real index, immune to HEAD ancestry,
and works on unborn repositories. The checkpoint manager records the
HEAD used at capture and re-anchors both refs to fresh snapshots when
the repository's HEAD moves, so reviews never diff across unrelated
histories. Existing checkpoints created before this change are left
untouched.

Diffs now ignore whitespace-only changes by default, use the standard
10 MB output cap, and degrade to a file list with a note instead of
failing when a patch exceeds it.
The unborn-repository test now asserts the improved behavior: an empty
repository is reviewable immediately, re-anchors after the first commit,
and continues reviewing from the new baseline. New tests cover
whitespace-only changes being ignored by default but visible on request,
and an oversized diff degrading to a file list.
Describe the journal-based review, the DEVSPACE_REVIEW_MODE=git
fallback, and how checkpoints are stored and re-anchored.
Re-anchoring used to bake the whole working tree, unreviewed edits
included, into the new baseline snapshot, which made pending changes
vanish from every subsequent review. The baseline now points at the new
HEAD commit itself, so unreviewed working-tree edits stay visible.

HEAD tracking is restored when a restart finds persisted review refs, so
a HEAD move after a restart is absorbed by re-anchoring instead of
reporting committed changes as pending workspace changes.

The degraded diff path no longer runs the 10 MB-capped numstat call that
could overflow and fail the whole review; oversized diffs now fall back
to a name-only file list, and a review that cannot list files either
reports the degradation instead of claiming there were no changes.
@Waishnav
Waishnav force-pushed the feat/show-changes-git-hardening branch from 657bff7 to a371fb3 Compare August 10, 2026 05:58
@Waishnav Waishnav closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant