Repository navigation
Persistent cache for merge-tree and integration probe results - #2085
Merged
Merged
Conversation
worktrunk-bot
previously approved these changes
Apr 11, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
CI failed on all three platforms (linux, macos, windows) with the same error in cargo doc --no-deps --document-private-items:
error: unresolved link to `rev_parse_tree`
--> src/git/repository/integration.rs:418:18
|
418 | /// Unlike [`rev_parse_tree`], this returns the commit SHA rather than the
| ^^^^^^^^^^^^^^ no item named `rev_parse_tree` in scope
Rustdoc intra-doc links to methods need a Self:: prefix. Inline suggestion below — happy to push the fix if you'd like.
worktrunk-bot
dismissed
their stale review
April 11, 2026 20:15
CI failed — rustdoc intra-doc link error in src/git/repository/integration.rs:418
Cache expensive SHA-keyed git operations (merge-tree conflicts, merge-add
probe) to disk under `.git/wt/cache/{kind}/`. Because commit SHAs are
content-addressed, cached entries never go stale — only an LRU size bound
(5000 entries per kind) prevents unbounded growth.
The cache is transparent to callers: `has_merge_conflicts` and
`merge_integration_probe` check/populate the cache internally, so all
code paths (list, picker, merge, remove) benefit without changes.
Key design decisions:
- File-per-entry layout (same as ci-status cache)
- Symmetric keys for conflict detection, asymmetric for integration probe
- Refs resolved to SHAs before all git commands, ensuring cache key matches
the actual computation
- No tmp-and-rename: corrupt entries degrade to cache miss
- Cleared by `wt config state clear`
Co-Authored-By: Claude <[email protected]>
Fix `[rev_parse_tree]` → `[Self::rev_parse_tree]` for intra-doc link resolution. Add merge-tree-conflicts cache entry to the comprehensive state clear test so codecov covers the new clear path. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 11, 2026
max-sixty
force-pushed
the
list-cache-keys
branch
from
April 11, 2026 20:26
0db17d8 to
11196a4
Compare
worktrunk-bot
approved these changes
Apr 11, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 11, 2026
Now that merge-tree and integration probe results are cached on disk (SHA-keyed, instant on cache hit from #2085), `WouldMergeAdd` and `MergeTreeConflicts` no longer need to be in the `EXPENSIVE_TASKS` skip list. Stale branches now get full integration detection in both `wt list` and the picker. The first invocation may be slightly slower for repos with many stale branches (cache cold), but the picker's 500ms collect deadline provides a safety net, and all subsequent invocations are instant from cache. > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[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]>
max-sixty
added a commit
that referenced
this pull request
Apr 13, 2026
The `TaskInput<T>` enum TODO predicted that persistent caching would force the refactor — a "fourth source" needing real-vs-fabricated distinction. Caching has since landed (#2085, #2098) without bugs: the cache is content-addressed (SHA-keyed), so a cache hit is a real measurement, not a fabrication. The fabrication risk it warned about is already mitigated case-by-case in `seed_skipped_task_defaults`, where each "do/don't seed" decision is documented inline (e.g., the explicit non-seed for `WorkingTreeDiff` that would otherwise misreport dirty worktrees as clean). The companion TODO about stale-branch seeding is dormant — no signal that the current trade-off is wrong. Drop both. If the type-system pressure ever becomes real, the design can be re-derived from first principles. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 13, 2026
The `TaskInput<T>` enum TODO predicted that persistent caching would force the refactor — cached values becoming a "fourth source" needing the same real-vs-fabricated distinction as live tasks. Caching has since landed (#2085, #2098) without surfacing the bug class the TODO warned about: the cache is content-addressed (SHA-keyed), so a cache hit *is* a real measurement, not a fabrication. The "natural inflection point" came and went. The fabrication risk that motivated the TODO is already mitigated case-by-case in `seed_skipped_task_defaults` — each "do/don't seed" decision documented inline (e.g., the explicit non-seed for `WorkingTreeDiff` that would otherwise misreport dirty worktrees as clean). The companion TODO about stale-branch seeding is dormant — no signal the current trade-off is wrong. Drop both. If the type-system pressure ever becomes real, the design can be re-derived from first principles. > _This was written by Claude Code on behalf of Maximilian_ 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.
Caches expensive SHA-keyed git operations (merge-tree conflicts, integration probe) to disk under
.git/wt/cache/{kind}/. Commit SHAs are content-addressed, so cached entries never go stale — only an LRU size bound (5000 per kind) prevents unbounded growth.The cache is transparent:
has_merge_conflictsandmerge_integration_probecheck/populate it internally, so list, picker, merge, and remove all benefit without code changes. Refs are resolved to SHAs before all git commands, ensuring the cache key matches the actual computation.Layout: one JSON file per entry at
.git/wt/cache/{kind}/{sha1}-{sha2}.json, with symmetric keys for conflict detection and asymmetric keys for integration probe. Corrupt entries degrade to cache miss (no tmp-and-rename needed). Cleared bywt config state clear.