Skip to content

docs(collect): document cache design across .git/wt/cache/ - #2097

Merged
max-sixty merged 2 commits into
mainfrom
uncacheable-tasks
Apr 11, 2026
Merged

max-sixty merged 2 commits into
mainfrom
uncacheable-tasks

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Adds a ## Caching section to src/commands/list/collect/mod.rs as a peer to the existing ## Skeleton Performance and ## Unified Collection Architecture sections. The new section covers:

  • The four sibling caches under .git/wt/cache/ (merge-tree-conflicts, merge-add-probe, ci-status, summaries) with their modules, key schemes, and staleness rules in one table.
  • The three key-design schemes in use — SHA-pair (content-addressed, never stale), branch + TTL + HEAD check (external mutable state), branch + content hash (deterministic function of a mutable input) — and when to reach for each.
  • Which TaskKind variants hit which cache today.
  • Cacheable-but-uncached candidates: IsAncestor, HasFileChanges, BranchDiff (pure functions of a SHA pair), plus AheadBehind, CommittedTreesMatch, Upstream (ref-resolve then SHA pair — same pattern, same cache).
  • What is fundamentally uncacheable by SHA and why: WorkingTreeDiff, WorkingTreeConflicts, GitOperation, UserMarker, UrlStatus.

probe_cache.rs already 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 outside collect/ can find it.

No behavior change — docs only.

This was written by Claude Code on behalf of Maximilian

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]>
Comment thread src/commands/list/collect/mod.rs Resolved
`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]>
@max-sixty
max-sixty merged commit 523bae2 into main Apr 11, 2026
27 of 28 checks passed
@max-sixty
max-sixty deleted the uncacheable-tasks branch April 11, 2026 23:28
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]>
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.

2 participants