From 7333fd4dfd0b4f3f2218d1b180a147c697dff8ad Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Wed, 7 Jan 2026 11:01:57 -0300 Subject: [PATCH] ep cli: Clean leftover git locks (#46255) Sometimes git locks are left over from crashed runs. We now assume there's only one process of the CLI running and clean them up. If we want to run multiple processes at the same time, we should consider our own file-based lock, but it seems fine for an internal tool. Release Notes: - N/A --- crates/edit_prediction_cli/src/load_project.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/edit_prediction_cli/src/load_project.rs b/crates/edit_prediction_cli/src/load_project.rs index a3dc44a128..8fa53618f1 100644 --- a/crates/edit_prediction_cli/src/load_project.rs +++ b/crates/edit_prediction_cli/src/load_project.rs @@ -204,6 +204,17 @@ async fn setup_worktree(example: &Example, step_progress: &StepProgress) -> Resu let worktree_path = repo_name.worktree_path(); let repo_lock = git::lock_repo(&repo_dir).await; + // Clean up any stale git lock files from previous crashed runs. + // Safe-ish since we have our own lock. + // WARNING: Can corrupt worktrees if multiple processes of the CLI are running. + let worktree_git_dir = repo_dir + .join(".git/worktrees") + .join(repo_name.name.as_ref()); + let index_lock = worktree_git_dir.join("index.lock"); + if index_lock.exists() { + fs::remove_file(&index_lock).ok(); + } + if !repo_dir.is_dir() { step_progress.set_substatus(format!("cloning {}", repo_name.name)); fs::create_dir_all(&repo_dir)?;