Skip to content

fix(snapshot): seed index from the worktree's git dir - #39398

Open
Hyyy6 wants to merge 1 commit into
anomalyco:devfrom
Hyyy6:snapshot-worktree-index
Open

fix(snapshot): seed index from the worktree's git dir#39398
Hyyy6 wants to merge 1 commit into
anomalyco:devfrom
Hyyy6:snapshot-worktree-index

Conversation

@Hyyy6

@Hyyy6Hyyy6 commented Jul 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#39388

Type of change

  • Bug fix

What does this PR do?

#31798 seeds the snapshot repo with the source repo's git index so git add --all
reuses already-hashed entries instead of re-hashing the whole tree. In a linked worktree
--git-common-dir resolves to the main repository's .git, so the copied index is the
main repo's, which does not match the worktree's working tree. git add --all then
re-hashes every file, reintroducing the hang on large worktrees.

Resolve the index from --git-dir (cwd = the worktree) instead, which in a linked worktree
points at the worktree's own .git/worktrees/<name> (whose index matches its working tree).
Falls back to the common dir's index when rev-parse fails, preserving the existing
best-effort behavior.

How did you verify your code works?

End-to-end (opencode run "say hi" in a chromium --depth 1 worktree, ~500k files):

BinaryLocationTimeResult
Official 1.18.4main repo9.8scompletes
Official 1.18.4worktree1m50s+ (killed)hangs — git add --all re-hashing
This fixworktree38.5scompletes, model responds

Isolated git-level reproduction (replicating Snapshot.seed() at packages/opencode/src/snapshot/index.ts:198-239):

ScenarioIndex sourceTimeTree hash
A: no seeding (pre-#31798)none>180s (timeout)4b825dc6... (empty)
B: common-dir index (bug)main repo166s36e0ef8a...
C: git-dir index (fix)worktree6s36e0ef8a...

B and C produce identical tree hashes — the fix preserves correctness. C is 27x faster.

  • bun test test/snapshot/snapshot.test.ts from packages/opencode — 55 pass, 1 skip, 0 fail.
  • bun typecheck from packages/opencode — clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@Hyyy6
Hyyy6force-pushed the snapshot-worktree-index branch from 88efcb6 to 2f39e7cCompareJuly 28, 2026 21:26
@Hyyy6

Copy link
Copy Markdown
Author

test, typecheck, and nix-eval are queued behind the first-time fork contributor approval gate. Everything else is green. I've already run bun typecheck and bun test test/snapshot/snapshot.test.ts locally in packages/opencode (55 pass, 1 skip, 0 fail) — happy to re-run anything once workflows are approved.

@Hyyy6

Hyyy6 commented Aug 4, 2026

Copy link
Copy Markdown
Author

@nexxeln — you self-assigned #39388; this PR is the fix. It's a ~3-line change, reproduced and verified on a ~500k-file Chromium worktree as in original related PR. Happy to rebase onto current dev if needed.

Sign up for freeto 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.

Snapshot seeding hangs in git linked worktrees (copied index is the main repo's)

1 participant

@Hyyy6