warp icon indicating copy to clipboard operation
warp copied to clipboard

Git diff chip flickers between tracked-only and all-files count when untracked files are present

Open vkodithala opened this issue 7 months ago • 2 comments

Summary

When running a terminal command in a repo that has both modified tracked files and untracked files, the git diff chip flickers between two values: the correct one that counts all changes (2 files | 8 edits) and an incorrect one that omits untracked files (1 file | 4 edits). The flicker is consistent and reproducible on every command run.

Problem

The GitDiffStats chip has two update paths that compute the file/edit counts differently:

  1. GitRepoStatusModel (filesystem watcher): calls DiffStateModel::diff_metadata_against_head(), which runs git status --untracked-files=all and reads line counts from untracked files directly. Includes untracked files.
  2. shell_git_line_changes() (shell fallback): runs GIT_OPTIONAL_LOCKS=0 git -c diff.autoRefreshIndex=false diff --shortstat HEAD. Excludes untracked files.

When a command completes, the shell-command fallback fires and briefly overwrites the filesystem-watcher value with a count that omits untracked files. The filesystem watcher then fires again and restores the correct value, producing the visible flicker.

Expected behavior

The chip consistently shows the correct count that includes both modified tracked files and untracked files (2 | 8 in this reproduction case).

Actual behavior

Every time a command is run, the chip briefly flickers to the incorrect value (1 | 4), which excludes untracked files, before snapping back to the correct value (2 | 8).

Reproduction steps

  1. Open Warp in a local git repository.
  2. Create at least one modified tracked file with a few edits (e.g., add 4 lines to any tracked file).
  3. Create at least one untracked file in the same repo (e.g., touch scripts/repro.sh and add 4 lines).
  4. Observe the git diff chip in the prompt — it should show both files/edits (e.g., 2 | 8).
  5. Run any terminal command (e.g., echo hello, ls, git status).
  6. Watch the git diff chip: it briefly shows the lower, tracked-only value (e.g., 1 | 4) then corrects to 2 | 8.
  7. The flicker repeats every time a command is run.

Specific repo state used during reproduction:

  • Modified tracked file: .mcp.json (+4 lines, 0 deletions)
  • Untracked file: scripts/repro-mcp.sh (4 lines)
  • Correct chip value: 2 | 8
  • Incorrect (flickered) chip value: 1 | 4

Artifacts

Video with a repro: https://www.loom.com/share/b0f148fe1c004eb591ec82e4149fcace.

Warp version

Unknown (please fill in from Warp → About Warp)

Operating system

macOS

Possible source references

  • app/src/context_chips/builtins.rs (162-180): shell_git_line_changes() runs git diff --shortstat HEAD, which only counts tracked file changes and excludes untracked files — this is the source of the incorrect lower value.
  • app/src/code_review/diff_state.rs (1624-1665): diff_metadata_against_head() uses git status --untracked-files=all and reads line counts from untracked files — this produces the correct higher value.
  • app/src/context_chips/current_prompt.rs (1428-1472): filesystem-watcher update path that calls GitLineChanges::from_diff_stats(&metadata.stats_against_head) — correct path, but races with the shell command path on block completion.
  • app/src/context_chips/current_prompt.rs (1480-1492): is_updated_externally() guard that should suppress the periodic 30-second timer when GitRepoStatusModel is live — but does not appear to suppress the block-completion shell command trigger.

vkodithala avatar Apr 28 '26 14:04 vkodithala

@vkodithala

You can view the triage session on Warp.

Here's what I found while triaging this issue:

The current code appears to support this report: the git diff chip can briefly use a tracked-only fallback calculation before the repository watcher refreshes the all-files value. This looks actionable without additional reporter info.

Maintainer details

I concluded that gitDiffStats prompt chip can flicker because the prompt refresh path briefly uses a shell git diff count that excludes untracked files before watcher metadata restores the all-files count..

Automated triage

Type: Bug

Reproducibility: High. The report includes a concrete local git state and repeatable command-completion trigger, and the current code supports the described mismatch.

Likely root cause: There are two GitDiffStats update sources with different semantics. The repository watcher path ultimately calls DiffStateModel::diff_metadata_against_head(), which uses git status --untracked-files=all and counts untracked file lines. The prompt refresh path still runs a one-shot shell generator for GitDiffStats when the chip is externally driven, and that generator runs git diff --shortstat HEAD, which only reports tracked changes. After a command completes and the prompt context refreshes, the shell result can briefly overwrite the watcher-provided structured value until watcher metadata updates it again.

Relevant files:

  • app/src/context_chips/current_prompt.rs — externally driven chip refresh behavior and watcher subscription updates
  • app/src/context_chips/builtins.rs — shell_git_line_changes() fallback command
  • app/src/context_chips/mod.rs — GitDiffStats chip generator configuration
  • app/src/code_review/git_status_update.rs — GitRepoStatusModel metadata loading
  • app/src/code_review/diff_state.rs — untracked-file-inclusive diff metadata calculation

Suggested SMEs: @moirahuang for context chip ownership, with @kevinchevalier as a secondary reviewer for the diff metadata path.

Duplicate check: No likely duplicate was found among the provided recent/open issues.

This is my automated analysis and may be incorrect. A maintainer will verify the details.

Powered by Oz

warp-for-oss[bot] avatar Apr 28 '26 14:04 warp-for-oss[bot]

Opened #9412 with a candidate fix.

Diagnosis matches the writeup here — is_updated_externally already suppresses the 30-second periodic timer for GitDiffStats when GitRepoStatusModel is live, but the same branch in run_chips was still doing one shell-fallback fetch via chip.generator() because GitDiffStats has no contextual initial_value_generator. So every update_states_with_new_context (which fires on block completion via the active-block update) ran git diff --shortstat HEAD once, and that's the value that briefly overwrites the watcher's value before the watcher's next MetadataChanged event races back in.

The PR keeps the contextual initial fetch for ShellGitBranch (its initial_value_generator reads from PromptContext and can't disagree with the watcher) but skips the fetch entirely when no contextual initial generator exists. The watcher's existing refresh_metadata call after block completion already covers the refresh path.

anshul-garg27 avatar Apr 29 '26 12:04 anshul-garg27