Commit 38f8d5b
fix(context_chips): stop GitDiffStats flicker from shell fallback (#9244)
## Summary
Fixes #9228.
When a per-repo `GitRepoStatusModel` is attached to `CurrentPrompt`, the
`GitDiffStats` chip is updated via filesystem-watcher events whose
`DiffStateModel::diff_metadata_against_head()` count includes untracked
files (it walks `git status --untracked-files=all`).
However, every time the prompt context is rebuilt (e.g. when a new
block's metadata arrives after a command completes), `run_chips` was
still firing the chip's periodic shell-based generator once. For
`GitDiffStats` that fallback is `shell_git_line_changes()`, which runs
`git diff --shortstat HEAD` and counts only tracked changes. Its result
was overwriting the watcher's structured `GitLineChanges` value until
the next watcher `MetadataChanged` event restored it — causing the chip
to visibly flicker between the tracked-only count and the all-files
count whenever untracked files were present.
## Fix
In `CurrentPrompt::run_chips`, when a chip is `is_updated_externally`,
only run an `initial_value_generator` if one is provided. The
shell-based `chip.generator()` is no longer used as a fallback for
externally-driven chips:
- `ShellGitBranch` continues to seed its initial value from
`current_environment.git_branch()` via `initial_value_generator`, then
receives updates from the watcher.
- `GitDiffStats` has no `initial_value_generator`, so the periodic shell
command is now skipped entirely. Initial population is handled by the
watcher: `GitRepoStatusModel::new()` kicks off `refresh_metadata`
immediately and emits `MetadataChanged` once metadata is computed, which
`set_git_repo_status` handles by updating `GitDiffStats` with the
structured `GitLineChanges`. Existing chip values survive across
`clear_chips()` (which only aborts in-flight generators), so there is no
transient empty state on subsequent prompt refreshes.
This keeps the diff-count semantics consistent (always all-files)
without changing the behavior of remote/non-watched sessions, which
still fall back to the shell generator via the periodic timer branch.
## Test plan
- [ ] In a repo with both modified tracked files and untracked files,
run a command (e.g. `ls`) and observe the `GitDiffStats` chip — it
should stay on the all-files count without flickering down to the
tracked-only count.
- [ ] In a repo without the watcher available (e.g. remote session),
confirm the chip still updates periodically via the shell fallback
(unchanged code path).
- [ ] `ShellGitBranch` continues to update on branch changes via the
watcher and shows the correct branch on first paint.
CHANGELOG-BUG-FIX: Fix git diff chip flickering between tracked-only and
all-files count when untracked files are present
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: vkodithala <varoon@warp.dev>1 parent 0964e69 commit 38f8d5b
1 file changed
Lines changed: 25 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1041 | 1041 | | |
1042 | 1042 | | |
1043 | 1043 | | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1053 | 1069 | | |
1054 | 1070 | | |
1055 | 1071 | | |
| |||
0 commit comments