nikivdev/code · error
failed to restore sync auto-stash automatically. Run `:sync
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
This error is thrown by the sync command's auto-stash restore logic when an automatic git stash created before syncing could not be popped/applied back onto the repository. The library includes a repair-packet path so the user can re-run a repair flow; this variant fires when a repair packet path is known and gets embedded in the message.
Source
Thrown at src/sync.rs:5218
}
}
let repair_packet_path = if conflicted_files.is_empty() {
None
} else {
write_sync_repair_packet(
repo_root,
SyncRepairKind::StashRestoreConflict,
&conflicted_files,
detail,
None,
Some(auto_stash_state),
packet_dir_override,
)
.ok()
};
if detail.is_empty() {
if let Some(packet_path) = repair_packet_path {
bail!(
"failed to restore sync auto-stash automatically. Run `:sync repair --packet {}` or `git stash list` and restore manually if needed.",
packet_path.display()
);
}
bail!(
"failed to restore sync auto-stash automatically. Run `git stash list` and restore manually if needed."
);
}
if let Some(packet_path) = repair_packet_path {
if allow_autofix {
match try_route_sync_conflicts_to_sync_agent(repo_root, &packet_path)? {
SyncRepairRouteOutcome::Completed => {
restore_intent_to_add_paths(repo_root, &auto_stash_state.intent_to_add_paths)
.context("restored stash but could not restore intent-to-add markers")?;
if drop_latest_stash_if_present(repo_root)? {
sync_progressln!(
" ✓ Sync agent resolved stash conflicts and dropped auto-stash"View on GitHub (pinned to a747e741ae)
Solutions
- Run the suggested `:sync repair --packet <path>` command shown in the message
- Run `git stash list` and manually apply/drop the stash entry
- Resolve conflicts manually, then `git stash drop` the restored entry
Example fix
// terminal
:sync repair --packet /tmp/sync-repair-abc123
# or
git stash list && git stash apply stash@{0} Defensive patterns
Strategy: fallback
Validate before calling
git stash list && git status --porcelain # ensure no stale auto-stash / clean tree before :sync
Try / catch
match sync_result {
Err(e) if e.to_string().contains("failed to restore sync auto-stash") => {
run("git", &["stash", "list"]);
// apply or drop stash@{0} manually, then rerun repair
}
r => r?,
} Prevention
- Commit or stash intentionally before running :sync
- Avoid editing files while a sync is in flight
- Re-run `:sync repair --packet <path>` promptly rather than making more edits
- Keep autofix enabled so repair packets can be consumed automatically
When it happens
Trigger: During sync, a stash restore (e.g. `git stash pop`/`apply`) failed with conflicts or a non-clean state, and `repair_packet_path` was Some, but no repair/agent route could restore the stash automatically.
Common situations: Concurrent edits to stashed files during sync; merge conflicts reintroduced on pop; dirty worktree from a failed push/pull; interrupted previous sync leaving a stale stash entry.
Related errors
- failed to restore sync auto-stash automatically. Run `git st
- failed to restore sync auto-stash automatically: {} Run `:sy
- failed to restore sync auto-stash automatically: {} Run `git
- Failed to stash local changes: {}. Resolve the issue and re-
- failed to stash working tree: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/da13ffefa619f733.
Report an issue: GitHub.