{"record":{"id":"63f90df9c1e2a24f","repo":"nikivdev/code","slug":"git-index-stayed-locked-after-retr-close","errorCode":null,"errorMessage":"{}. Git index stayed locked after {} retr{}; close competing git/jj processes or remove stale .git/index.lock, then retry.","messagePattern":"(.+?)\\. Git index stayed locked after (.+?) retr(.+?); close competing git/jj processes or remove stale \\.git/index\\.lock, then retry\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sync.rs","lineNumber":4643,"sourceCode":"                    \"jj git export hit Git index lock; retrying {retry_num}/{max_retries} in {}ms\",\n                    delay.as_millis()\n                ),\n            );\n            sync_progressln!(\n                \"jj git export hit a transient Git index lock; retrying ({}/{}) in {}ms...\",\n                retry_num,\n                max_retries,\n                delay.as_millis()\n            );\n            std::thread::sleep(delay);\n            continue;\n        }\n\n        jj_print_output(&output);\n        let failure = jj_failure_message(&args, &output);\n        if is_git_index_lock_error(&failure_text) {\n            let retries = JJ_GIT_EXPORT_LOCK_RETRY_DELAYS_MS.len();\n            bail!(\n                \"{}. Git index stayed locked after {} retr{}; close competing git/jj processes or remove stale .git/index.lock, then retry.\",\n                failure,\n                retries,\n                if retries == 1 { \"y\" } else { \"ies\" }\n            );\n        }\n        bail!(\"{}\", failure);\n    }\n\n    unreachable!(\"jj git export retry loop should always return\");\n}\n\nfn jj_run_in(repo_root: &Path, args: &[&str]) -> Result<()> {\n    let output = jj_run_output_in(repo_root, args)?;\n    jj_print_output(&output);\n    if !output.status.success() {\n        bail!(\"{}\", jj_failure_message(args, &output));\n    }","sourceCodeStart":4625,"sourceCodeEnd":4661,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/sync.rs#L4625-L4661","documentation":"Raised in src/sync.rs by the `jj git export` retry wrapper when the command keeps failing because the git index is locked (.git/index.lock held by another process). After exhausting all configured retry delays (JJ_GIT_EXPORT_LOCK_RETRY_DELAYS_MS), the library bails with the jj failure message plus guidance to close competing git/jj processes or remove a stale lock, then retry. It exists to surface a persistent lock contention problem rather than looping forever.","triggerScenarios":"`jj git export` was run, its output matched is_git_index_lock_error, and every retry attempt (JJ_GIT_EXPORT_LOCK_RETRY_DELAYS_MS.len() times) still hit the index lock.","commonSituations":"Another git/jj process (IDE auto-fetch, git status hook, background sync) holds .git/index.lock concurrently; a crashed git process left a stale lock file; parallel tooling operating on the same repo.","solutions":["Close competing git/jj processes (IDE background fetches, other terminals) and re-run the sync","If no process holds the lock, remove the stale lock: `rm .git/index.lock`","Retry the sync operation after clearing contention","Increase/inspect JJ_GIT_EXPORT_LOCK_RETRY_DELAYS_MS if contention is frequent"],"exampleFix":"// before: stale lock present\n$ rm .git/index.lock\n// after: retry succeeds\n$ <sync command>","handlingStrategy":"retry","validationCode":"use std::path::Path;\n// before running sync, ensure no stale git index lock\nlet lock = Path::new(\".git/index.lock\");\nif lock.exists() {\n    eprintln!(\".git/index.lock exists; close other git/jj processes or remove it before syncing\");\n}","typeGuard":null,"tryCatchPattern":"// retry the sync after clearing the lock\nfor attempt in 0..3 {\n    match run_sync() {\n        Err(e) if e.to_string().contains(\"Git index stayed locked\") => {\n            let _ = std::fs::remove_file(\".git/index.lock\");\n            std::thread::sleep(std::time::Duration::from_millis(500 * (attempt + 1)));\n        }\n        other => { other?; break; }\n    }\n}","preventionTips":["Don't run git/jj commands in the same repo concurrently (IDEs, hooks, background fetch)","Clean up .git/index.lock after crashed processes before syncing","Increase JJ_GIT_LOCK retry delays if lock contention is common","Close IDE auto-fetch while running long sync operations"],"tags":["git","jj","index-lock","retry-exhausted"],"backgroundTag":"git-index-lock","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}