anomalyco / anomalyco/opencode

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

Open
#39,388 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Jul 28, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

PR #31798 fixed snapshot hangs in huge repos by seeding the snapshot repo with the source
repo's git objects and index. However, the fix only works when opencode is started from the
main repository. Starting from a linked worktree still hangs.

The root cause is in packages/opencode/src/snapshot/index.ts:

const commonDir = yield* git(["rev-parse", "--path-format=absolute", "--git-common-dir"], {
  cwd: state.worktree,
})
// ...
const sourceIndex = path.join(source, "index")  // source = commonDir

--git-common-dir always resolves to the main repo's .git, even from inside a linked
worktree. 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 minutes-long hang that
#31797/#31798 fixed.

Steps to reproduce
  1. Clone a large repo (e.g. git clone --depth 1 https://chromium.googlesource.com/chromium/src chromium)
  2. cd chromium && git worktree add ../chromium-wt HEAD
  3. cd ../chromium-wt && opencode run "say hi"
  4. The first Snapshot.track() hangs (git re-hashing the entire worktree).

The --git-common-dir and --git-dir paths differ in a worktree:

rbabichev@PC6:~/build/opencode_fix/chromium_wt$ git rev-parse --git-common-dir
/home/rbabichev/build/opencode_fix/chromium/.git
rbabichev@PC6:~/build/opencode_fix/chromium_wt$ git rev-parse --git-dir
/home/rbabichev/build/opencode_fix/chromium/.git/worktrees/chromium_wt
Suggested fix

Resolve the index from --git-dir instead of --git-common-dir, falling back to the
common dir when rev-parse fails:

const gitdir = yield* git(["rev-parse", "--path-format=absolute", "--git-dir"], {
  cwd: state.worktree,
})
const sourceIndex = gitdir.code === 0
  ? path.join(gitdir.text.trim(), "index")
  : path.join(source, "index")
Plugins

No response

OpenCode version

1.18.4

Steps to reproduce
  1. Clone big repo:
rbabichev@PC6:~/build/opencode_fix$ git clone https://github.com/chromium/chromium.git --depth=1
Cloning into 'chromium'...
remote: Enumerating objects: 508084, done.
remote: Counting objects: 100% (508084/508084), done.
remote: Compressing objects: 100% (341185/341185), done.
remote: Total 508084 (delta 134157), reused 480884 (delta 131260), pack-reused 0 (from 0)
Receiving objects: 100% (508084/508084), 1.32 GiB | 3.57 MiB/s, done.
Resolving deltas: 100% (134157/134157), done.
Updating files: 100% (499905/499905), done.
  1. Create a worktree:
rbabichev@PC6:~/build/opencode_fix/chromium$ git worktree add ../chromium_wt HEAD
Preparing worktree (detached HEAD e833d5f56a)
Updating files: 100% (499905/499905), done.
HEAD is now at e833d5f56a [Signin][Android] Never show text button for NTP signin button
  1. Compare results to start opencode session in main repo vs worktree:
babichev@PC6:~/build/opencode_fix/chromium$ time opencode run "say hi"

> build · glm-5.2

hi


real	0m9.781s
user	0m9.746s
sys     0m7.279s

rbabichev@PC6:~/build/opencode_fix/chromium$ cd ../chromium_wt/
rbabichev@PC6:~/build/opencode_fix/chromium_wt$ cat .git
gitdir: /home/rbabichev/build/opencode_fix/chromium/.git/worktrees/chromium_wt
rbabichev@PC6:~/build/opencode_fix/chromium_wt$ time opencode run "say hi"

> build · glm-5.2

^C
real	1m50.168s
user	0m33.848s
sys	   0m12.387s

Git process hanging:

rbabich+  679902 1437  4.6 5530692 3056008 ?     Ssl  11:11  59:10 git -c core.autocrlf=false -c core.longpaths=true -c core.symlinks=true --git-dir /home/rbabichev/.local/share/opencode/snapshot/4542c0c852d6d0b2ebacab2a934aa8353ae419f4/6c86b26b87c49c392cdf9aa7f68ecf2de85f1d08 --work-tree /tmp/opencode/chromium-wt add --all --sparse --pathspec-from-file=- --pathspec-file-nul


rbabichev@PC6:~/build/opencode_fix/chromium_wt$ top -p 679902

top - 11:16:24 up 1 day,  1:18,  0 users,  load average: 30.96, 18.14, 9.55
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s): 96.5 us,  3.5 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  64020.2 total,   2578.3 free,  34090.9 used,  27351.0 buff/cache
MiB Swap:   8192.0 total,   8143.5 free,     48.5 used.  28461.5 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                                       
 679902 rbabich+  20   0 5530692   2.9g   4500 S 650.0   4.7  64:36.55 git

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.