Skip to content

fix(snapshot): prune stale tmp pack files and recover from broken snapshot stores - #46037

Closed
arthurjd wants to merge 3 commits into
anomalyco:devfrom
arthurjd:tmp-pack-cleanup
Closed

arthurjd wants to merge 3 commits into
anomalyco:devfrom
arthurjd:tmp-pack-cleanup

Conversation

@arthurjd

Copy link
Copy Markdown

Issue for this PR

Closes #46034

Type of change

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

What does this PR do?

The hourly snapshot cleanup runs git gc --prune=7.days. When gc fails or is interrupted it leaves tmp_pack_* files in objects/pack/ that are never removed: git only cleans them at the end of a successful gc, and cleanup() returned early on failure. This adds pruneStale(), which removes repack temp files older than an hour after every gc run, success or failure.

gc also fails permanently when the project's own git gc prunes objects the snapshot store references through its alternates (seed()). The same missing object makes every hourly gc fail, leaking a new tmp_pack each time, forever. This PR detects those failures (unable to read / bad object / bad tree in gc stderr) and drops the broken store so the next track() rebuilds it from scratch.

How did you verify your code works?

  • New unit tests: cleanup removes stale tmp pack files (stale files removed, recent ones and real packs kept) and cleanup rebuilds snapshot store when gc fails on missing objects (store dropped on missing-object gc failure, rebuilt by the next track). 57/57 tests pass, typecheck and oxlint clean.
  • Real machine: a snapshot store that had failed gc 700+ times with the same missing object was rebuilt on the next track(), git count-objects reports zero garbage, and the hourly cleanup no longer fails.

Screenshots / recordings

Not applicable – not a UI change.

Checklist

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

…pshot stores

Failed or interrupted git gc runs leave tmp_pack_* files in objects/pack
that are never removed: git only cleans them at the end of a successful
gc and cleanup() returns early on failure. Remove repack temp files older
than an hour after every gc run, success or failure.

gc also fails permanently when the project's own gc prunes objects the
snapshot store references through its alternates. Detect those failures
and drop the store so the next track() rebuilds it from scratch instead
of failing every hour and leaking disk forever.
@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 cleanup fails forever and leaks tmp_pack_* after project gc prunes shared objects

1 participant