[PR #7586] fix: add timeout to git commands to prevent Zed extension hang on Win… #12449

Open
opened 2026-02-16 18:17:21 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7586

State: open
Merged: No


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 using Promise.race(). When a timeout occurs:

  • Logs a warning message for debugging (log.warn)
  • Returns the fallback value (undefined)
  • Triggers existing fallback logic (already in place for when git commands fail)
  • Gracefully degrades to non-git behavior instead of hanging
    The timeout is conservative enough (5 seconds) that it won't affect normal git operations on any platform, but prevents indefinite hangs.

Testing

  • Tested on Windows 11 with Zed 0.218.6
  • Confirmed extension now loads successfully in Git repositories
  • Binary built and tested locally with the patched code
  • No impact on non-Windows platforms (timeout is generous for normal operations)
  • Fallback behavior works correctly when timeout is triggered

Related Issues

  • Closes the OpenCode hang issue reported in zed-industries/zed#43335 (was initially thought to be a Zed bug, but root cause was in OpenCode)

Changes

  • Added gitWithTimeout() helper function in packages/opencode/src/project/project.ts
  • Wrapped three git commands with timeout protection
  • Added warning log when timeout occurs for debugging purposes

Fixes #7587

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7586 **State:** open **Merged:** No --- 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 using `Promise.race()`. When a timeout occurs: - Logs a warning message for debugging (`log.warn`) - Returns the fallback value (undefined) - Triggers existing fallback logic (already in place for when git commands fail) - Gracefully degrades to non-git behavior instead of hanging The timeout is conservative enough (5 seconds) that it won't affect normal git operations on any platform, but prevents indefinite hangs. Testing - Tested on Windows 11 with Zed 0.218.6 - Confirmed extension now loads successfully in Git repositories - Binary built and tested locally with the patched code - No impact on non-Windows platforms (timeout is generous for normal operations) - Fallback behavior works correctly when timeout is triggered Related Issues - Closes the OpenCode hang issue reported in zed-industries/zed#43335 (was initially thought to be a Zed bug, but root cause was in OpenCode) Changes - Added `gitWithTimeout()` helper function in `packages/opencode/src/project/project.ts` - Wrapped three git commands with timeout protection - Added warning log when timeout occurs for debugging purposes Fixes #7587
yindo added the pull-request label 2026-02-16 18:17:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12449