Repository navigation
docs(collect): document cache design across .git/wt/cache/ - #2097
Merged
Merged
Conversation
Adds a `## Caching` section to `collect/mod.rs` alongside the existing skeleton and collection-architecture sections. Covers the four sibling caches (merge-tree-conflicts, merge-add-probe, ci-status, summaries), the three key schemes in use, which tasks are cached today, tasks that are cacheable-but-uncached (IsAncestor, HasFileChanges, BranchDiff, plus the ref-resolve-then-SHA group), and which tasks are fundamentally uncacheable by SHA. Motivation: the three caches each have their own module docstring, but there was no cross-cutting spec — a contributor adding a cacheable task had to find `probe_cache.rs` by luck. `probe_cache.rs` already name-checked its siblings; updated it to point at the new overview instead. Co-Authored-By: Claude <[email protected]>
`detect_active_git_operation` goes through `is_rebasing()`, which checks both `.git/rebase-merge` and `.git/rebase-apply`. The latter is what `git am` and `git rebase --apply` (the older backend) create, so the caching overview should list it alongside the others. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 11, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 11, 2026
Addresses worktrunk-bot review feedback on PR #2098: - Updates `collect/mod.rs` caching docs (from PR #2097) to reflect that `IsAncestor`, `HasFileChanges`, and `BranchDiff` are now cached via `probe_cache` (no longer "cacheable but uncached") - Fixes the cross-task inconsistency where `IsAncestorTask`, `BranchDiffTask`, `MergeTreeConflictsTask`, and `CommittedTreesMatchTask` used `ctx.branch_ref.commit_sha` (the worktree's transient HEAD during a rebase-in-progress) instead of the branch name. This caused a contradictory row during rebase: `is_ancestor=true` + `1 ahead / 1 behind`. All five tasks now prefer the branch name when present, with commit_sha as a fallback for detached HEAD items. The snapshot for `test_list_maximum_status_with_git_operation` updates accordingly — the feature worktree mid-rebase now shows `✗` (real conflicts with main) instead of `↕`, plus `+3 -2` diff stats reflecting the branch's actual changes rather than an empty diff from the transient HEAD. > _This was written by Claude Code on behalf of @max-sixty_ Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 11, 2026
Adds persistent SHA-keyed caching for `is_ancestor`, `has_added_changes`, and `branch_diff_stats` — the last three operations still running unconditionally in both `wt list` and the `wt switch` picker. With all five merge-base-dependent tasks now cached (joining `merge-tree-conflicts` and `merge-add-probe` from PR #2085), the `stale_branches` skip mechanism becomes redundant: the picker's "skip tasks on branches > 50 behind main" optimization was papering over slow first-run cost that the cache now handles eternally. ## What changed **New caches** (`src/git/repository/probe_cache.rs`): three new asymmetric SHA-keyed kinds — `is-ancestor`, `has-added-changes`, `diff-stats` — all using the same LRU-swept persistent file layout as the existing kinds. `branch_diff_stats` skips its cache when sparse checkout is active (path filters make the result environment-dependent). **Dead plumbing removed**: `EXPENSIVE_TASKS` constant, `CollectOptions::stale_branches` field, `skip_expensive_for_stale` parameter on `collect()`, the env-var gate in `list/mod.rs`, and two obsolete tests + snapshots. Both `wt list` and the picker now run the same task set. **`batch_ahead_behind` unconditional**: previously only the picker called it. Making it unconditional replaces N `rev-list --count` calls with one `for-each-ref`, a pure win for `wt list` too. **Branch-ref semantics unified across all tasks**: all task implementations now prefer the branch name over `ctx.branch_ref.commit_sha` when one is present. Previously, `IsAncestorTask`, `BranchDiffTask`, `MergeTreeConflictsTask`, and `CommittedTreesMatchTask` used the worktree's current HEAD sha, which during a rebase-in-progress is transiently at the replayed commit rather than the branch tip. This produced contradictory rows: `is_ancestor=true` + `1 ahead / 1 behind`. Now all tasks consistently report the branch's state, matching `git status` semantics. Addressed worktrunk-bot review feedback. **Caching docs updated**: the `## Caching` section in `collect/mod.rs` (from PR #2097) now lists the three tasks as cached rather than "cacheable but uncached". Also addressed worktrunk-bot PR overlap observation. **Benchmarks**: `invalidate_caches_auto()` now clears `.git/wt/cache/` so cold-cache benchmarks exercise cold state. The `warm_optimized` variant in `real_repo_many_branches` collapsed since it no longer measures anything different from `warm`. ## Testing New probe_cache unit tests cover roundtrip + tamper-based cache consultation for each new kind, plus a `clear_all_covers_all_kinds` regression test. Snapshot updates for `test_list_maximum_status_with_git_operation` and `test_list_json_with_git_operation` reflect the branch-ref fix — mid-rebase worktrees now show `✗` (real conflicts) and actual diff stats instead of the transient HEAD's empty state. > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
## Cachingsection tosrc/commands/list/collect/mod.rsas a peer to the existing## Skeleton Performanceand## Unified Collection Architecturesections. The new section covers:.git/wt/cache/(merge-tree-conflicts, merge-add-probe, ci-status, summaries) with their modules, key schemes, and staleness rules in one table.TaskKindvariants hit which cache today.IsAncestor,HasFileChanges,BranchDiff(pure functions of a SHA pair), plusAheadBehind,CommittedTreesMatch,Upstream(ref-resolve then SHA pair — same pattern, same cache).WorkingTreeDiff,WorkingTreeConflicts,GitOperation,UserMarker,UrlStatus.probe_cache.rsalready name-checked its siblings (ci-status/,summaries/) without linking them into a shared design. Updated its layout paragraph to point at the new overview so contributors outsidecollect/can find it.No behavior change — docs only.