Skip to content

Decouple DiffStateModel and CodeReviewView#10314

Merged
MaggieShan merged 3 commits intomasterfrom
maggs/decouple-diffstatemodel
May 7, 2026
Merged

Decouple DiffStateModel and CodeReviewView#10314
MaggieShan merged 3 commits intomasterfrom
maggs/decouple-diffstatemodel

Conversation

@MaggieShan
Copy link
Copy Markdown
Contributor

Description

  • Built on Simplify DiffStateModel to have one repo #10283
  • Part of the work needed to support the code review pane and git states on remote environments includes simplifying the contract between the DiffStateModel and CodeReviewView
  • This decouples the model and view such that the model is the main orchestrator for when to refresh/load the new diffs and metadata, while the view simply consumes the changes it needs to render
    • Main change moves the invalidation queue to the model

Linked Issue

APP-4352

Testing

Verified code review pane locally --> should be a no-op

  • Tested multiple repos on the same tab + different tabs
  • Tested switching branches
  • Tested file changes

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

@cla-bot cla-bot Bot added the cla-signed label May 6, 2026
Copy link
Copy Markdown
Member

@kevinyang372 kevinyang372 left a comment

Choose a reason for hiding this comment

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

This looks good! I didn't review very closely given this is mostly a refactor. Lmk where there are major logic changes you want me to take a closer look at

Comment thread app/src/code_review/code_review_view.rs Outdated
// After the view state is refreshed with fresh diffs, re-evaluate
// the git operations button (Commit / Push / Create PR) so that
// e.g. committing shows "Push" instead of staying on "Commit".
DiffStateModelEvent::MetadataRefreshed => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of having a separate MetadataRefreshed event (which goes back to look it up in DiffStateModel), can we bundle the aggregated diff stats update into DiffStateModelEvent::SingleFileUpdated and DiffStateModelEvent::NewDiffsComputed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think there are still cases when MetadataRefreshed would fire outside of both DiffStateModelEvent::SingleFileUpdated and DiffStateModelEvent::NewDiffsComputed that we still need to cover - to avoid the roundtrip we can instead pass the updated metadata with the event itself?

impl SyncQueueTaskTrait for FileInvalidationTask {
type Error = FileInvalidationError;
type Result = (PathBuf, Option<FileDiffAndContent>);
type Result = (PathBuf, Option<Arc<FileDiffAndContent>>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to wrap this in Arc now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The main change is in https://github.com/warpdotdev/warp/pull/10314/changes#diff-2fcff7c4f4f049e80ea75516a1e9b2a59974bc492260ebf01661419d372eb022R493-R503

On master, the Arc::try_unwrap failure triggered a full reload but I've changed it to instead borrow + clone the value and since FileDiffAndContent is an expensive clone, I wrapped it with an Arc

@MaggieShan MaggieShan marked this pull request as ready for review May 7, 2026 13:53
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 7, 2026

@MaggieShan

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR moves diff invalidation orchestration from CodeReviewView into DiffStateModel and changes the view to consume model events for full and single-file diff updates.

Concerns

  • The new index-lock handling treats every index_lock_detected event as a reason to keep suppressing the per-file queue, but the repository watcher sets that flag for both .git/index.lock creation and removal. This can leave invalidate_all_pending stuck after the lock clears.
  • Manual testing is required for behavior that can be manually tested. Please include screenshots or a screen recording showing the code review pane working end to end across the tested repo/branch/file-change scenarios, or justify why visual evidence is not possible.

Verdict

Found: 0 critical, 1 important, 1 suggestion

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread app/src/code_review/diff_state.rs
@MaggieShan MaggieShan force-pushed the maggs/decouple-diffstatemodel branch from 662eafa to 2d93c80 Compare May 7, 2026 16:37
@MaggieShan
Copy link
Copy Markdown
Contributor Author

This looks good! I didn't review very closely given this is mostly a refactor. Lmk where there are major logic changes you want me to take a closer look at

Addressed your pr comments in ad0500a!

The main logic change I'll call out is in handle_file_update which converts InvalidationBehaviour to an actual action that the DiffMetadataModel now handles 🙏

@MaggieShan MaggieShan merged commit 09a35b5 into master May 7, 2026
24 checks passed
@MaggieShan MaggieShan deleted the maggs/decouple-diffstatemodel branch May 7, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants