Commit 4d1947a
authored
🤖 fix: reduce git lock conflicts in background polling (#915)
## Problem
Background git polling runs `git fetch` every 3-60 seconds. Even when
there's nothing new to fetch, `git fetch` acquires `maintenance.lock`,
which can conflict with:
- Manual git commands in terminal
- Agent git operations during streaming
## Solution
Check if fetch is needed before acquiring any locks:
1. `git ls-remote` → get remote SHA (network only, **no lock**)
2. `git cat-file -e` → is SHA already local? (**no lock**)
3. If local → skip fetch (**no lock needed**)
4. If not local → fetch to get new commits (lock, but only when
genuinely needed)
## Why this works
```
# Before: always locks
git fetch → maintenance.lock (even if nothing to fetch)
# After: only locks when needed
ls-remote + cat-file → no lock (common case: SHA already local)
git fetch → lock (rare: new remote commits)
```
In practice, IDEs fetch periodically and agent `git pull` operations
keep refs current, so the "already local" path triggers most of the
time.
---
_Generated with `mux`_1 parent 4d61f89 commit 4d1947a
1 file changed
+33
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | | - | |
88 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
97 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
98 | 127 | | |
99 | 128 | | |
100 | 129 | | |
| |||
0 commit comments