Skip to content

fix: give each detached worktree its own summary cache directory - #4840

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-4838
Nov 18, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-4838

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Every detached worktree wrote its LLM summary to the same cache directory, summary/(detached)/, because the directory was keyed by the branch string and both wt list --full and the picker pass (detached) for a row without a branch. CachedSummary::write trims that directory to one entry after each write, so two detached worktrees with changes evicted each other, and the next run called the LLM for both again. A detached row's directory key now includes a hash of its worktree path. Named branches keep their existing directories, so no cached summary has to be regenerated. The JSON branch field still reads (detached), so wt config state get displays these rows the same way, with one row per detached worktree instead of one shared row.

test_detached_worktrees_keep_separate_cached_summaries creates two detached worktrees with different uncommitted changes and summarizes each one twice. On the old code, the second summary of the first worktree re-ran the LLM command (left: "regenerated", right: "Summary A"). It passes with the fix.

Detached summaries cached by earlier releases sit in the shared summary/(detached)/ directory. A detached write now removes that directory, so wt config state get doesn't keep listing the pre-upgrade summary beside the current one. It is kept when a local branch named (detached) exists, because Git allows that name and its summaries use the same directory. test_detached_summary_prunes_legacy_shared_entry and test_detached_summary_keeps_real_detached_named_branch start with that directory populated and cover both cases.

The callers now pass Option<&str> for the branch instead of the "(detached)" sentinel, and summary.rs maps None to the display name.

Not covered: two worktrees on the same branch (git worktree add --force) still share a directory and can still evict each other. Fixing that means putting the worktree path in every row's key, which forces a one-time regeneration of every cached summary. The issue leaves that trade-off to a maintainer.

Refs #4838 — automated triage

The summary cache directory was keyed by the branch string, so every
detached worktree wrote to summary/(detached)/. Each write trims that
directory to one entry, so two detached rows with changes evicted each
other and every `wt list --full` or picker Summary tab re-ran the LLM
for both. A detached row's key now adds a hash of its worktree path;
named branches keep their existing directories, so no cached summary is
invalidated.

Two worktrees on the same branch (`git worktree add --force`) still
share a directory.

Refs #4838
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Nov 18, 2026
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot The new per-worktree key leaves a cached detached summary in the legacy shared directory. After that checkout’s diff changes and a new summary is generated, CachedSummary::list_all still enumerates both directories, so wt config state get shows the stale pre-upgrade summary alongside the current one indefinitely. Please handle the legacy entry and add an upgrade regression starting with that directory populated. Preserve a real branch named (detached), which Git permits.

This was written by Codex on behalf of max-sixty

Before per-worktree keys, every detached worktree cached its summary under
summary/(detached)/. After upgrading, that entry stayed listed by
wt config state get next to the current per-worktree one indefinitely.

A detached write now removes the legacy directory, unless a local branch
named (detached) exists — Git permits that name, and its summaries live in
the same directory.

Co-Authored-By: Claude <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Handled in 920cf24. After a detached summary is written under its per-worktree key, the legacy summary/(detached)/ directory is removed, unless a local branch named (detached) exists. That branch keys the same directory, and the pre-upgrade files can't be told apart from its entries (both record branch: "(detached)"), so the directory is left alone in that case.

New tests, both starting with a pre-upgrade entry in the legacy directory:

  • test_detached_summary_prunes_legacy_shared_entry: after a detached summary is generated, list_all returns only the current summary. With the prune disabled it fails with ["Current summary", "Pre-upgrade summary"].
  • test_detached_summary_keeps_real_detached_named_branch: with git branch '(detached)' present, both entries remain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants