Uh oh!
There was an error while loading. Please reload this page.
fix(snapshot): reuse source git objects to avoid re-hashing huge repos - #31798
Conversation
## The problem Internal git objects contains hash of every file in the git history, currently the snapshot opencode is performing can take MINUTES to recalculate hashes for every object in a repo like chromium source ## Instrumentation Reuse the intenal hashes from the original folder's git repo. This brings down the snapshot timing on my M4 max machine from 200 seconds to ~5s
dmtrKovalenko
commented
Jun 11, 2026
Heads up: |
Uh oh!
There was an error while loading. Please reload this page.
Port upstream anomalyco/opencode#31798 in PawWork's snapshot layer. - Seed initial snapshot repositories with source object alternates and a validated source index copy, including common-dir and secondary-worktree paths. - Preserve the existing full-add fallback when seeding, alternates, or copied-index validation is unavailable or fails. - Add focused snapshot coverage for normal repositories, secondary worktrees, relative alternates, and split-index fallback. - Address Gemini's Git compatibility feedback by avoiding new `rev-parse --path-format=absolute` usage in the seeded paths. Verification: - `bun test test/snapshot/snapshot.test.ts` from `packages/opencode` - `bun run typecheck` from `packages/opencode` - `git diff --check origin/dev...HEAD` - Terminal Claude review: no P0/P1/P2 findings. - Terminal Occam fresh-eye review: PASS, no P0/P1/P2 findings. - PR CI completed green, including `unit-windows-opencode-session` in `windows-advisory`. Risk: The reuse path is best-effort only. If the source Git data cannot be reused safely, snapshot creation falls back to the existing full add behavior.
Hyyy6
commented
Jul 9, 2026
Looks like this fix does not cover worktrees scenario. I have a large project with a bunch of worktrees, and starting opencode from any worktree hangs the terminal with no response This is models output after describing the issue and pointing to this PR: Looking at PR changes the proposed fix makes sense. |
Issue for this PR
Closes#31797
Type of change
What does this PR do?
Opening a session in a huge repo (chromium, ~500k files) hangs because the first
Snapshot.trackdoesgit add --allinto a brand-new, empty snapshot repo, so git re-hashes the entire working tree from scratch. That takes minutes, so the turn never finishes.The source repo already has every file hashed in its own object DB. So when we create the snapshot repo, this PR seeds it from the source repo:
objects/info/alternatesat the source repo's object dir (so git reuses blobs it already has)index(soaddbecomes a stat-only diff instead of hashing everything)It's all best-effort and guarded: non-git projects are skipped, and a missing/incompatible source index just falls back to the old full add. The resulting tree hash is identical to the old path, so snapshot/diff/revert behave exactly the same.
How did you verify your code works?
git add --alldid not finish within 90s andsession.prompthung (process had to be killed). After, the first snapshot completes in ~5s andopencode runexits cleanly.bun typecheckpasses.bun test test/snapshot/snapshot.test.tspasses (52 pass, 0 fail).Screenshots / recordings
Not a UI change.
Checklist