Skip to content

fix: add timeout to snapshot git add to handle large worktrees#18069

Open
ihubanov wants to merge 1 commit intoanomalyco:devfrom
ihubanov:fix/snapshot-timeout-large-files
Open

fix: add timeout to snapshot git add to handle large worktrees#18069
ihubanov wants to merge 1 commit intoanomalyco:devfrom
ihubanov:fix/snapshot-timeout-large-files

Conversation

@ihubanov
Copy link

@ihubanov ihubanov commented Mar 18, 2026

Issue for this PR

Closes #18072
Fixes #8887
Fixes #3182

Type of change

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

What does this PR do?

The snapshot system runs git add . on the full worktree at every agentic step. When the worktree contains large non-code files (media, datasets, ML models, Go/npm dependencies), this operation runs indefinitely — observed running for 3+ hours at 90% CPU, with the hourly git gc cleanup consuming 3.7GB RAM. See also #3182 (98GB snapshots from Go deps) and #8887 (snapshot ignores watcher.ignore).

This fix wraps the git add . call in a 15-second Effect.timeout. If it times out:

  1. Kill the hung git add process (handled by Effect's scoped interruption)
  2. Generate an info/exclude file for the snapshot repo containing:
    • Known binary/large file extensions (.mp4, .zip, .onnx, .safetensors, etc.)
    • The project's .gitignore rules
    • Any top-level directories exceeding 100MB (detected via a shallow scan)
  3. Retry git add . with the exclusions in place

The exclude generation is guarded by a flag so it runs at most once per session. Normal-sized code projects see zero overhead since the timeout is never hit.

This is complementary to the watcher.ignore approach proposed in #8887 — this provides a runtime safety net for users who haven't configured ignore rules.

How did you verify your code works?

Tested on a workspace containing a ~500MB media directory that previously caused the snapshot system to hang. After the fix, the first git add . times out at 15s, excludes are generated, and the retry completes quickly. Subsequent track()/patch()/diff() calls work normally.

Checklist

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

When opencode is used in a workspace containing large non-code files
(media, datasets, ML models, etc.), the `git add .` in the snapshot
system can run indefinitely — consuming excessive CPU and memory.

This adds a 15-second timeout to `git add .`. If it times out, the
snapshot system generates an exclude file that:
- Skips known binary/large file extensions (.mp4, .zip, .onnx, etc.)
- Copies the project's .gitignore rules
- Scans top-level directories and excludes any over 100MB

The retry `git add .` then runs with these exclusions in place.
Normal-sized projects see zero overhead since the timeout is never hit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 18, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Mar 18, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

1 participant