Skip to content

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

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

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

@Hyyy6 Hyyy6 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):

Binary Location Time Result
Official 1.18.4 main repo 9.8s completes
Official 1.18.4 worktree 1m50s+ (killed) hangs — git add --all re-hashing
This fix worktree 38.5s completes, model responds

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

Scenario Index source Time Tree hash
A: no seeding (pre-#31798) none >180s (timeout) 4b825dc6... (empty)
B: common-dir index (bug) main repo 166s 36e0ef8a...
C: git-dir index (fix) worktree 6s 36e0ef8a...

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
Hyyy6 force-pushed the snapshot-worktree-index branch from 88efcb6 to 2f39e7c Compare July 28, 2026 21:26
@Hyyy6

Hyyy6 commented Jul 28, 2026

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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

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