Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Problem

When using Mux, git operations (worktree create/delete/rename) can get interrupted (user cancel, crash, terminal closed), leaving orphaned .git/index.lock files in the main repository. This causes subsequent git operations to fail with:

fatal: Unable to create '/Users/.../mux/.git/index.lock': File exists.

Another git process seems to be running in this repository...

Solution

Added cleanStaleLock() helper that removes lock files older than 5 seconds before git operations that touch the main repository's index:

  • createWorktree
  • removeWorktree
  • pruneWorktrees
  • WorktreeRuntime.createWorkspace
  • WorktreeRuntime.renameWorkspace
  • WorktreeRuntime.deleteWorkspace

The 5-second threshold ensures we only remove orphaned locks, not locks from legitimately running processes.

Testing

Added unit tests for the cleanStaleLock function:

  • Removes lock files older than threshold
  • Does not remove recent lock files
  • Handles missing lock files gracefully

Generated with mux

Git creates index.lock during operations that modify the index. If a
process is killed mid-operation (user cancel, crash, terminal closed),
the lock file gets orphaned. This is common in Mux when git operations
are interrupted.

Added cleanStaleLock() helper that removes lock files older than 5
seconds before git operations that touch the main repository's index:
- createWorktree
- removeWorktree
- pruneWorktrees
- WorktreeRuntime.createWorkspace
- WorktreeRuntime.renameWorkspace
- WorktreeRuntime.deleteWorkspace

The 5-second threshold ensures we only remove orphaned locks, not
locks from legitimately running processes.

_Generated with mux_
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@ammario ammario merged commit 13f1e66 into main Dec 9, 2025
19 checks passed
@ammario ammario deleted the fix-git-index-lock-issue branch December 9, 2025 03:33
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