fix(snapshot): reuse source git objects to avoid re-hashing huge repos#31798
Merged
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
Contributor
Author
|
Heads up: |
13 tasks
Astro-Han
added a commit
to Astro-Han/pawwork
that referenced
this pull request
Jun 11, 2026
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.
Moixia
pushed a commit
to Moixia/Sonder
that referenced
this pull request
Jun 11, 2026
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.
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