Skip to content

"Snapshot mechanism stalls on large workspaces: ~1min per git snapshot, permanent index.lock deadlock after a crash" #42597

Closed as not planned

Description

@fifaliao

Description

On a large git workspace (~5,300 tracked files) running opencode 1.18.18 on Windows, the project snapshot mechanism becomes pathological:

  1. Every agentic iteration triggers a full git add -A + git commit inside a custom snapshot repository. On a large workspace each of these takes ~1 minute (git add -A ≈ 57s, git commit ≈ 19s measured locally), so every single model interaction is blocked for ~1 minute before anything is sent.
  2. When a snapshot git process crashes (or is killed), it leaves a stale index.lock in the snapshot repository. From then on, every snapshot operation fails with fatal: Unable to create '...index.lock': File exists and opencode retries indefinitely — memory balloons to 6–8 GB, disk reads exceed 10 GB, and no response is ever produced. The only fix is to manually delete the index.lock file.

Plugins

No response

OpenCode version

1.18.18

Steps to reproduce

  1. Open a large repo (several thousand tracked files) in opencode on Windows.
  2. Verify the snapshot git repo under ~/.local/share/opencode/snapshot/<projectID>/...:
    • Run git add -A in that repo → observe tens of seconds.
    • Run git commit → same.
  3. Trigger a snapshot operation and then kill the opencode process mid-operation → a stale index.lock is left behind.
  4. Restart opencode in the same directory → every interaction now logs:
    WARN level=WARN message="failed to add snapshot files" exitCode=128
    stderr="fatal: Unable to create '.../snapshot/.../index.lock': File exists.
    Another git process seems to be running in this repository..."
    
    The session becomes unresponsive: ~6–8 GB RSS, continually increasing disk reads, and no answer is returned, because snapshot never succeeds and opencode retries forever.

Screenshot and/or share link

No response

Operating System

windows

Terminal

No response

Activity

  1. fifaliao commented on Aug 14, 2026

    @fifaliao
    Author

    Set in the project opencode.json:

    { "snapshot": false }

    and delete any stale index.lock in the snapshot repo:

    C:\Users\<you>\.local\share\opencode\snapshot\<projectID>\<hash>\index.lock
    

    This restores normal interactivity but disables undo/redo for file changes.

  2. github-actions commented on Aug 14, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. CENFARG commented on Sep 30, 2026

    @CENFARG

    Adding data points from Windows 11 / opencode 1.18.33 (CLI + Desktop) — same snapshot pathology, with three extra findings that made it catastrophic and might help debugging.

    Environment: worktree is a Dropbox-synced docs tree with ~1.68M files across many nested git repositories.

    1. Two artifacts made every git add fail fatally, so the snapshot index was NEVER persisted — which turns the "~1 min per snapshot" into "full re-scan on every single agent step":

    • a nested git repository with zero commits (a stray git init that was never committed) → fatal: '<dir>/' does not have a commit checked out
    • a literal nul file (0 bytes, created by a > nul redirect from Git Bash) at the worktree root → fatal: invalid path 'nul'

    Both are invisible in opencode's log — the only symptom was generic slowness. Each failed add meant the next step re-scanned the whole tree again. One of these was created ~2 weeks before we diagnosed the slowness, which matches when symptoms started.

    2. The hang variant here is a CPU livelock, not a stdin block. Repeatedly observed a git parent/child pair where the parent sits at 0 CPU while the child spins at ~100% of one core for 5–15 minutes with exactly 0 bytes of I/O (Process IOReadBytes/IOWriteBytes = 0), holding index.lock. A second concurrent snapshot op then blocks at 0 CPU on the same lock. The command line matches the parent/child git add --all --sparse --pathspec-from-file=- --pathspec-file-nul shape from #41648, but with the opposite CPU signature (spin vs. sleep-on-stdin), so the stdin theory may only cover part of the failure space.

    3. Agent-facing symptom: "zombie" assistant messages with zero tokens. While the snapshot blocks the loop, the assistant message is created but no process/stream log lines ever appear, and the message is finalized (sometimes only when the instance closes) with tokens.output = 0 and no finish reason — no error logged at all. Measured instances: one turn hung for 1442s (24 min) and another for 391s producing nothing. From the user's perspective this looks exactly like a provider outage.

    Fix that worked here (after removing the two fatal artifacts): added the heavy subtrees to the worktree .gitignore (1.68M → 125k files), ran one clean git add directly in the snapshot repo to persist the index (3.7 MB), after which snapshot adds became incremental and fast (2.2s, 0 errors).

    Suggestions: (a) surface snapshot git add fatals in the log/UI instead of silently retrying full rescans forever, (b) skip embedded repos without commits the same way gitignored files are handled, (c) don't let the snapshot git add block the agent loop (async or bounded timeout).

    Related: #41648 (stdin-block variant, macOS), #29413 (orphaned index.lock on Windows).

  4. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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