Skip to content

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

Closed
ihubanov wants to merge 1 commit into
anomalyco:devfrom
ihubanov:fix/snapshot-timeout-large-files
Closed

ihubanov wants to merge 1 commit into
anomalyco:devfrom
ihubanov:fix/snapshot-timeout-large-files

Conversation

@ihubanov

@ihubanov ihubanov commented Mar 18, 2026 •

Copy link
Copy Markdown

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) <[email protected]>
@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
Copy Markdown
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
Copy Markdown
Contributor

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

@rekram1-node

Copy link
Copy Markdown
Collaborator

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Labels

None yet

Projects

None yet

2 participants