Snapshot feature needs safeguards for large directories (home directory filled disk) #5991

Closed
opened 2026-02-16 17:59:12 -05:00 by yindo · 0 comments
Owner

Originally created by @sahilchouksey on GitHub (Jan 14, 2026).

Originally assigned to: @thdxr on GitHub.

The snapshot feature runs git add . on the entire worktree without any size or path checks. When .git exists in a large directory (like home), this causes severe disk exhaustion.

What happened

  • Accidentally had .git in home directory (~)
  • Ran opencode . from home
  • Snapshot started tracking entire home directory (112GB)
  • Disk went from 44GB free → nearly 0 within minutes
  • CPU pinned at 100% from continuous git add .
  • System became unresponsive - couldn't make any changes, had to delete cache just to recover
  • Had to manually pkill -9 git processes and delete ~/.local/share/opencode/snapshot/

Root cause

packages/opencode/src/snapshot/index.ts:31:

await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`

No checks exist for:

  • Home directory (~, /home/*, /)
  • Directory size or file count
  • Disk space availability

Suggested fixes

  1. Block dangerous paths: Skip snapshot if worktree is $HOME, /home/*, or /
  2. Size threshold: Warn/skip if directory >1GB or >10k files
  3. Disk space check: Abort if available disk < 5GB
  4. User confirmation: Prompt before snapshotting unusually large directories
Originally created by @sahilchouksey on GitHub (Jan 14, 2026). Originally assigned to: @thdxr on GitHub. The snapshot feature runs `git add .` on the entire worktree without any size or path checks. When `.git` exists in a large directory (like home), this causes severe disk exhaustion. ## What happened - Accidentally had `.git` in home directory (`~`) - Ran `opencode .` from home - Snapshot started tracking entire home directory (112GB) - Disk went from 44GB free → nearly 0 within minutes - CPU pinned at 100% from continuous `git add .` - **System became unresponsive - couldn't make any changes, had to delete cache just to recover** - Had to manually `pkill -9` git processes and delete `~/.local/share/opencode/snapshot/` ## Root cause `packages/opencode/src/snapshot/index.ts:31`: ```typescript await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .` ``` No checks exist for: - Home directory (`~`, `/home/*`, `/`) - Directory size or file count - Disk space availability ## Suggested fixes 1. **Block dangerous paths:** Skip snapshot if worktree is `$HOME`, `/home/*`, or `/` 2. **Size threshold:** Warn/skip if directory >1GB or >10k files 3. **Disk space check:** Abort if available disk < 5GB 4. **User confirmation:** Prompt before snapshotting unusually large directories
yindo added the perf label 2026-02-16 17:59:12 -05:00
yindo closed this issue 2026-02-16 17:59:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5991