Skip to content

Snapshot can recursively ingest its own data when worktree is the home directory #20442

Closed as not planned

Description

@liujuanjuan1984

Description

On OpenCode 1.2.24, I hit a disk exhaustion / high-CPU loop caused by the snapshot mechanism when the worktree was the home directory.

In my case, starting opencode serve from /home/<user> resulted in a snapshot repo under ~/.local/share/opencode/snapshot/global, and I observed repeated commands of the form:

git --git-dir /home/<user>/.local/share/opencode/snapshot/global --work-tree /home/<user> add

The problem is that the snapshot storage directory itself lives inside that same worktree. On this setup, ~/.local/share/opencode/ was visible to the snapshot repo as content under the captured tree instead of being reliably excluded. After process restarts / interrupted snapshot writes, objects/pack accumulated many very large tmp_pack_* files until the disk filled up, while git add kept respawning at high CPU.

This looks like a logic hole around broad worktrees such as /home/<user>: the snapshot repo can end up recursively ingesting its own data.

Expected behavior: snapshot storage should never be snapshotted. OpenCode should either store snapshot data outside the worktree, hard-exclude its own data directory, or reject worktrees that contain the OpenCode data directory.

Plugins

None

OpenCode version

1.2.24

Steps to reproduce

  1. Start opencode serve with a worktree that contains the OpenCode data directory, for example /home/<user>.
  2. Let OpenCode initialize snapshot storage under ~/.local/share/opencode/snapshot/....
  3. Restart or interrupt the process while snapshot activity is happening.
  4. Check ~/.local/share/opencode/snapshot/.../objects/pack.
  5. Observe large tmp_pack_* files accumulating, rising disk usage, and repeated git add activity.

Screenshot and/or share link

No share link. I can provide additional logs if needed.

Operating System

Debian GNU/Linux 13

Terminal

Headless server environment

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Apr 1, 2026
  2. assigned and unassigned on Apr 26, 2026
  3. removed
    perfIndicates a performance issue or need for optimization
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  5. piknockyou commented on Sep 30, 2026

    @piknockyou

    Same condition here - the worktree was my home directory, with opencode's own data inside it. My visible symptom was different (no replies, service restarting in a loop), but for anyone landing on this thread the practical fix is worth writing down:

    From the folder where you start opencode: git rev-parse --show-toplevel

    • If it prints your home folder (or another broad parent folder) instead of a real project: that repo is almost certainly accidental - delete that .git (rename if unsure) and start opencode inside an actual project folder. That removes the self-referential snapshot walk entirely.
    • If it prints a real project of yours: give the giant directories a .gitignore entry, or turn snapshots off with "snapshot": false, so the scan stops walking hundreds of thousands of files.

    Deleting the stray ~/.git fixed it completely for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions