nikivdev/code · error

failed to restore sync auto-stash automatically: {} Run `git

Error message

failed to restore sync auto-stash automatically: {}
Run `git stash list` and restore manually if needed.

What it means

Auto-stash restore failed with a captured git `detail`, but no repair packet path exists, so only manual `git stash list` recovery is suggested. This is the fallback bail at the end of the restore helper.

Source

Thrown at src/sync.rs:5258

                    }
                    return Ok(());
                }
                SyncRepairRouteOutcome::ValidationPending => {
                    bail!(
                        "sync agent cleared the raw stash conflicts but left the repo mid-merge.\nRun `:sync repair --packet {}` or inspect the repo before dropping the stash.",
                        packet_path.display()
                    );
                }
                SyncRepairRouteOutcome::Unresolved => {}
            }
        }
        bail!(
            "failed to restore sync auto-stash automatically: {}\nRun `:sync repair --packet {}` or `git stash list` and restore manually if needed.",
            detail,
            packet_path.display()
        );
    }
    bail!(
        "failed to restore sync auto-stash automatically: {}\nRun `git stash list` and restore manually if needed.",
        detail
    );
}

fn restore_stash(repo_root: &Path, auto_stash_state: &AutoStashState, allow_autofix: bool) {
    if let Err(err) = restore_stash_result(repo_root, auto_stash_state, allow_autofix) {
        sync_stderrln!("warning: {}", err);
    }
}

fn stash_pop_untracked_conflict(output: &str) -> bool {
    output.contains("could not restore untracked files from stash")
        || (output.contains("already exists, no checkout") && output.contains("stash"))
}

fn drop_stash_if_untracked_restored(repo_root: &Path) -> Result<bool> {
    if git_capture_in(repo_root, &["rev-parse", "--verify", "stash@{0}"]).is_err() {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read `detail` for the exact git error
  2. `git stash list` then `git stash apply stash@{0}`, resolve conflicts, `git stash drop`
  3. Re-run sync with autofix/repair enabled to get a repair packet next time

Example fix

git stash apply stash@{0}
# resolve conflicts
git add -A && git stash drop stash@{0}
Defensive patterns

Strategy: fallback

Validate before calling

git status --porcelain  # refuse to sync with dirty tree
# abort if output non-empty

Try / catch

match sync() {
    Err(e) if e.contains("failed to restore sync auto-stash") => {
        run("git", &["stash", "list"]);
        run("git", &["stash", "apply", "stash@{0}"]);
        // resolve, then stash drop
    }
    other => other,
}

Prevention

When it happens

Trigger: Stash pop/apply failed (detail recorded) and `repair_packet_path` is None; all packet-less fallbacks exhausted.

Common situations: Simple conflict on pop in a one-off sync run; stash entry locked or corrupted; repo dirty in ways stash apply rejects.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/9df375607b996d8a. Report an issue: GitHub.