fix: add timeout to git commands to prevent Zed extension hang on Win… #7586
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the OpenCode extension hanging indefinitely on "Loading..." when opening Git repositories in Zed editor on Windows.
Problem
When opening a Git repository in Zed on Windows, three git commands in
Project.fromDirectory()would hang indefinitely:git rev-list --max-parents=0 --all(project ID generation)git rev-parse --show-toplevel(repository root detection)git rev-parse --git-common-dir(worktree detection)This caused the Zed extension to freeze during initialization, preventing users from using the OpenCode assistant in any Git repository.
Root Cause
The issue was initially reported as a Zed bug in zed-industries/zed#43335, but investigation revealed it was an OpenCode bug. The git commands were executed without any timeout mechanism, causing indefinite hangs on Windows when called through the Zed Agent Communication Protocol.
Solution
Added a
gitWithTimeout()helper function that wraps git command promises with a 5-second timeout usingPromise.race(). When a timeout occurs:log.warn)The timeout is conservative enough (5 seconds) that it won't affect normal git operations on any platform, but prevents indefinite hangs.
Testing
Related Issues
Changes
gitWithTimeout()helper function inpackages/opencode/src/project/project.tsFixes #7587