Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 4, 2025

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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammar-agent ammar-agent force-pushed the git-polling-lock-fix branch 2 times, most recently from 567fe83 to 534500d Compare December 4, 2025 22:19
The background git fetch polling was creating locks that conflicted with
terminal commands and agent git operations.

Now uses a smarter approach:
1. git ls-remote to get remote SHA (no lock, network only)
2. git cat-file -e to check if SHA exists locally (no lock)
3. If local: skip fetch entirely (no lock needed)
4. If not local: fetch to get new commits (lock, but rare)

This eliminates locks in the common case where the remote SHA is already
local (e.g., IDE or user already fetched). Locks only occur when there
are genuinely new remote commits that haven't been fetched by anyone.

_Generated with `mux`_
@ammar-agent ammar-agent changed the title 🤖 fix: git polling skips fetch when lock files present 🤖 fix: reduce git lock conflicts in background polling Dec 5, 2025
@ammario ammario merged commit 4d1947a into main Dec 5, 2025
17 checks passed
@ammario ammario deleted the git-polling-lock-fix branch December 5, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants