Skip to content

fix(snapshot): reuse source git objects to avoid re-hashing huge repos#31798

Merged
thdxr merged 1 commit into
anomalyco:devfrom
dmtrKovalenko:fix/chrome-slowdown
Jun 11, 2026
Merged

fix(snapshot): reuse source git objects to avoid re-hashing huge repos#31798
thdxr merged 1 commit into
anomalyco:devfrom
dmtrKovalenko:fix/chrome-slowdown

Conversation

@dmtrKovalenko

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #31797

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Opening a session in a huge repo (chromium, ~500k files) hangs because the first Snapshot.track does git add --all into 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:

  • point objects/info/alternates at the source repo's object dir (so git reuses blobs it already has)
  • copy the source repo's index (so add becomes 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?

  • On a full chromium checkout (~500k files, 69G): before this change git add --all did not finish within 90s and session.prompt hung (process had to be killed). After, the first snapshot completes in ~5s and opencode run exits cleanly.
  • Confirmed the snapshot produces the same valid tree hash as before (all 500,259 entries resolve).
  • bun typecheck passes.
  • bun test test/snapshot/snapshot.test.ts passes (52 pass, 0 fail).

Screenshots / recordings

Not a UI change.

Checklist

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

## 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

Copy link
Copy Markdown
Contributor Author

Heads up: test, typecheck, and nix-eval are sitting in action_required (first-time fork contributor approval gate). Everything else (pr-standards, compliance, duplicates) is green. Locally bun typecheck passes and the snapshot/session/git suites pass (61 pass, 0 fail). Ready to run once a maintainer approves the workflows.

@thdxr thdxr enabled auto-merge (squash) June 11, 2026 00:14
@thdxr thdxr merged commit 51891d5 into anomalyco:dev Jun 11, 2026
10 checks passed
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.
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.

Session hangs in very large repos (chromium) due to snapshot git add --all

2 participants