Skip to content

perf(list): cache push-remote URL and share local-branch scan with capture_refs - #2673

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-2672
May 10, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-2672

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

wt-perf cache-check against wt list statusline --claude-code reported two same-context git for-each-ref duplicates per render (#2672), one in the per-branch CI-status fan-out and one across the skeleton/slow phases.

Root cause

  1. for-each-ref %(push:remotename) refs/heads/<branch> ran twice for the same branch when no open PR matched. Branch::push_remote_url (the only call site of github_push_url) had no cache: detect_github calls github_owner_repo_for_branch for the PR fetch, and when that returns no match detect_ci falls through to detect_github_commit_checks, which calls it again.
  2. for-each-ref refs/heads/ with the local-branch format ran twice across phases. populate_item (the statusline path's blocking entry point) calls capture_refs_with_ahead_behind on the main thread, which scans refs/heads/ independently of RepoCache.local_branches. A worker thread then runs UpstreamTask, which calls Branch::upstream → Repository::local_branch → first scan of the (still-empty) inventory cache.

Solution

  1. Cache Branch::push_remote_url on RepoCache.push_remote_urls keyed by branch name (mirrors the existing effective_remote_urls DashMap pattern).
  2. Have RefSnapshot::scan_locals populate RepoCache.local_branches as a side-effect — OnceCell::set is a no-op once populated, so subsequent capture_refs calls still scan fresh and mutating commands like wt merge's post-update snapshot in worktree::finish keep their fresh-snapshot semantics.

Testing

  • New unit tests capture_refs_populates_local_branch_cache and capture_refs_scans_fresh_when_cache_already_populated document both sides of the invariant — the side-effect populates the cache, but a later capture_refs reading post-mutation refs still sees the new SHA.
  • New integration test test_github_push_url_is_cached removes branch.<name>.remote between calls and asserts the cached URL persists.
  • Full cargo test --lib --bins (1109 + 643 unit) and cargo test --test integration (1637) pass.
  • Reran the wt-perf cache-check recipe from the issue against RUST_LOG=debug ./target/release/wt list statusline --claude-code — extra_calls: 0, same_context_duplicates: [] (was extra_calls: 2).

Closes #2672 — automated triage

…pture_refs

`wt list statusline --claude-code` ran two avoidable git for-each-ref
subprocesses per render (worktrunk#2672):

1. `for-each-ref %(push:remotename) refs/heads/<branch>` ran twice
   when no open PR matched: detect_github calls github_owner_repo_for_branch
   for the PR fetch, then detect_github_commit_checks calls it again for
   the branch fallback. Cache the resolved push URL on RepoCache keyed
   by branch name (mirrors the existing effective_remote_urls cache).

2. `for-each-ref refs/heads/` ran twice across phases: capture_refs
   scanned on the main thread, then a worker-thread Branch::upstream
   triggered the local-branch inventory scan. capture_refs now populates
   the RepoCache.local_branches OnceCell as a side-effect — every later
   capture_refs still scans fresh, so wt merge's post-update snapshot
   semantics are unaffected.

Closes #2672

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 2905534 into main May 10, 2026
31 checks passed
@max-sixty
max-sixty deleted the fix/issue-2672 branch May 10, 2026 15:00
@max-sixty max-sixty mentioned this pull request May 13, 2026
max-sixty added a commit that referenced this pull request May 13, 2026
Release v0.50.0.

Highlights:

- Experimental Azure DevOps support (#1256, thanks @mikeyroush; fixes
#1144 from @dlecan) — `wt switch pr:<N>`, `wt list --full`, and `wt
config show --full` recognize Azure DevOps via the `az` CLI.
- Experimental Gitea CI-status detection (#2702) on top of the Gitea
`pr:` shortcut (#1320, thanks @SjB).
- Hooks now resolve `.config/wt.toml` from the worktree they act on —
the primary-worktree fallback is gone, and `post-remove` reads the
removed worktree's config (snapshotted before removal). Approval prompts
collect hook commands from the same worktree. Breaking change for setups
that relied on the primary-worktree fallback; the changelog entry has
the recovery action. (#2690, #2703, #2714, #2717, #2701, #2708, #2727,
#2736, #2748)
- The `wt switch` picker's `alt-r` removal no longer runs unapproved
project hooks (#2746) — the picker's removal path is now routed through
`handle_remove_output` and consults the existing approval state
read-only.
- `wt config alias show` with no name lists every alias's full
definition (#2684, #2691); `wt --help` switches to a compact aliases
pointer (#2688).
- `wt list --branches` warm-run perf: SHA-keyed cache for `main↕` and
`Remote⇅` ahead/behind counts; shared push-remote URL and local-branch
scan (#2704, #2718, #2673).
- Claude Code plugin ships the `wt-switch-create` skill (#2737, thanks
@onetom for #2631).

See `CHANGELOG.md` for the full list (8 Improved, 5 Fixed, 5 Internal).

semver-checks reports breaking library-API changes (new enum variants
without `#[non_exhaustive]`, removed `Branch::github_push_url`, new
trait method on `RemoteRefProvider`), which mandates at minimum a minor
bump pre-1.0.
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.

Statusline cache-check: 2 same-context git for-each-ref duplicates (push:remotename, local-branch inventory)

2 participants