Repository navigation
Backfill every worktree of a repository, live or removed - #6
Merged
Merged
Conversation
Most agent work happens in a worktree that is merged and then deleted, and backfill only looked at sessions inside the checkout it was pointed at: on claude-harness it found 17 turns, and blame credited none of src/main/loch.ts, written in a since-removed worktree. A backfill from any checkout now covers sessions whose cwd was in any worktree `git worktree list` names, and those in a worktree since removed. A removed one is recognized by what the session wrote rather than where it was, so no layout is assumed: each prefix of the gone cwd is a candidate root, and wins if at least 5 distinct substantive lines the session wrote are in the repository's files at the same relative paths, at some ref's tip, strictly more than any other prefix. A cwd inside another repository's checkout is never considered. Edit paths are made relative to the worktree they were written in. On claude-harness: 185 turns across 45 sessions in 39 worktrees, and loch.ts goes from 0 to 383 of 439 lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review on #6: - Blobs are sized with `cat-file --batch-check` first; anything over 1MB is skipped as evidence and the rest are read 16MB at a time, so a lockfile at hundreds of tips is never held whole. - A cwd that still exists but is no checkout of this repository is `Elsewhere`, as the docs said: only a gone directory can be a worktree git has forgotten. - Tests for a removed worktree nested in the main checkout (`.claude/worktrees/<x>`), for a tie deciding nothing, and for an existing non-checkout directory, the last two with a positive control so neither can pass vacuously. - CLAUDE.md names the Bash-only-session limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
Most agent work happens in a worktree that is merged and then deleted.
loch backfillonly saw sessions whose cwd was inside the checkout it was run from. On claude-harness that meant 17 turns, andloch blame src/main/loch.tscredited 0 of 439 lines, even though a Claude session in a since-removed worktree wrote the whole file.What
Backfill run from any checkout now covers sessions whose cwd was in:
git worktree list --porcelainnames, wherever it lives,Removed worktrees are recognized by what was written, not by where. This assumes no path layout (
<repo>-worktrees/, Ness's nestedfeat/xdirs,.claude/worktrees,/tmp/...are all just paths):Edit paths are made relative to the worktree they were written in. Records use the repo's project id, which is shared across worktrees, and blame matches by
project+ path + line hash. So a turn from any worktree blames inmainonce its lines are merged;tests/backfill.rschecks this through a squash merge.Performance on this machine (3800 transcripts): about 8s for claude-harness.
cat-file --batch, instead of 7s for onels-tree -rper tip.file_pathin its raw text could land on a path the repo has.JSON: each entry in
sessionsgains arootfield (the worktree it worked in, which may no longer exist). That field is additive, soschemastays the same.Not done
(#N)suffix on the subject would never match anyway. Those lines come from the session's tool edits. Commits still on any ref were already matched viagit log --all.Results on claude-harness
src/main/loch.ts: 383 of 439 lines attributed (was 0)./private/tmp/ev-hotfix, is outside the Ness layout. I checked it: it was a real worktree onfix/evidence-fork-checkout.Ness
No change is required, since
--cwdsemantics are unchanged (any checkout of the repo works). Already opted-in repos do needloch backfillrun once more after this ships. Re-runs only replace earlier backfilled turns, never hook-recorded ones.Tests
New in
tests/backfill.rs:src/feature.py),cargo fmt --check,cargo clippy --release --all-targets -D warningsandcargo test --releasepass.🤖 Generated with Claude Code