nikivdev/code · error

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

Error message

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

What it means

Auto-stash restore failed and the underlying git error detail is included (`detail`), with a repair packet path available. The library appends the packet-based repair command and manual stash recovery instructions.

Source

Thrown at src/sync.rs:5252

                    if drop_latest_stash_if_present(repo_root)? {
                        sync_progressln!(
                            "  ✓ Sync agent resolved stash conflicts and dropped auto-stash"
                        );
                    } else {
                        sync_progressln!("  ✓ Sync agent resolved stash conflicts");
                    }
                    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 {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the embedded `detail` to see the exact git failure
  2. Run `:sync repair --packet <path>` as printed in the message
  3. Or `git stash apply stash@{0}` manually, resolve conflicts, then drop

Example fix

# message shows: failed to restore ...: CONFLICT (content): Merge conflict in foo.rs
:sync repair --packet /tmp/sync-repair-abc123
Defensive patterns

Strategy: try-catch

Validate before calling

git status --porcelain && git stash list  # know the pre-sync state

Try / catch

if let Err(e) = sync() {
    let msg = e.to_string();
    if msg.contains("failed to restore sync auto-stash automatically:") {
        eprintln!("git detail: {}", msg); // the embedded detail
        // run `:sync repair --packet <path>` shown in the message
    }
}

Prevention

When it happens

Trigger: Stash pop/apply returned an error captured in `detail` (e.g. conflict output or exit status), `repair_packet_path` was Some, and no repair route (autofix/agent) succeeded.

Common situations: Conflicting changes both stashed and re-modified; stash apply refusing due to untracked file overwrite; agent auto-fix unavailable or declined (`allow_autofix` false).

Related errors


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