Skip to content

Snapshot directory can grow to 40GB+ in 7 days due to hardcoded prune=7.days #17397

Description

@qimenluoshu-eng

Description

Bug: Snapshot directory fills disk during git gc --prune=7.days (disk drops 40GB in 2 hours)

Description

The snapshot cleanup feature (git gc --prune=7.days) can cause massive disk space spikes that temporarily require 2x the final pack size, potentially filling the entire disk.

In my case: Available disk space dropped from 75GB to 35GB in about 2 hours, and I had to kill the git process to prevent complete disk exhaustion.

Steps to Reproduce

  1. Use OpenCode for 7+ days with frequent file edits (each triggers git add .)
  2. Allow the hourly git gc --prune=7.days task to run
  3. Observe disk space rapidly depleting as Git creates a huge pack file

Root Cause Analysis

Based on logs in ~/.local/share/opencode/log/:

  1. Every file edit triggers git add . - OpenCode tracks all changes in ~/.local/share/opencode/snapshot/global/
  2. 7 days of changes accumulate - After 7 days, thousands of loose Git objects exist
  3. When git gc runs:
    • Reads all loose objects
    • Writes a huge pack file (requires 2x temporary space because loose objects + new pack coexist)
    • Only deletes loose objects after pack is complete

The critical issue: If free space is less than the estimated pack size, the system can run out of disk mid-process.

Evidence

  • Before gc: 75GB available
  • During gc: Dropped to 35GB (40GB pack file being created)
  • Had to kill git process to prevent complete disk fill
  • Logs show two 2.1GB pack files and one 54MB pack were created

Related Issues

User Impact (Current Limitations)

Users currently have no control over:

  • The prune interval (hardcoded 7 days)
  • Disk space checking before gc
  • Maximum pack file size
  • Manual cleanup of old snapshots

Proposed Fixes

  1. Add disk space check - Abort if free space < (estimated pack size + 10GB buffer)
  2. Use --max-pack-size - Split large packs into e.g., 1GB chunks to reduce temporary space needs
  3. Make prune interval configurable - Allow users to set 1-30 days via env var (e.g., OPENCODE_SNAPSHOT_DAYS)
  4. Add monitoring/warning - Log warnings before space runs out; optionally notify user
  5. Implement cleanup for old snapshots - Currently they're never deleted even after prune

Environment

  • OS: macOS 12.6
  • OpenCode version: 1.2.4
  • Git version: 2.39.5
  • Total disk: 234GB APFS

Plugins

No response

OpenCode version

OpenCode Desktop v1.2.25

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions