{"record":{"id":"f83d3f8d61af3e25","repo":"lima-vm/lima","slug":"failed-to-sync-back-the-changes-from-guest-instanc","errorCode":null,"errorMessage":"failed to sync back the changes from guest instance to host: %w","messagePattern":"failed to sync back the changes from guest instance to host: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/shell.go","lineNumber":551,"sourceCode":"\t\treturn shell\n\t}\n\treturn `\"` + shell + `\"`\n}\n\nfunc askUserForRsyncBack(ctx context.Context, cmd *cobra.Command, inst *limatype.Instance, sshCmd *exec.Cmd, hostCurrentDir, destRsyncDir string, rsync copytool.CopyTool, tty bool) error {\n\tremoteSource := fmt.Sprintf(\"%s:%s\", inst.Name, destRsyncDir)\n\tclean := filepath.Clean(hostCurrentDir)\n\tdirForCleanup := shellescape.Quote(filepath.Join(*inst.Config.User.Home, clean))\n\tcleanupGuestWorkdir := false\n\n\trsyncBack := func() error {\n\t\tpaths := []string{\n\t\t\tremoteSource,\n\t\t\thostCurrentDir,\n\t\t}\n\n\t\tif err := rsyncDirectory(ctx, cmd, rsync, paths); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to sync back the changes from guest instance to host: %w\", err)\n\t\t}\n\t\tlogrus.Info(\"Successfully synced back the changes to host.\")\n\t\tcleanupGuestWorkdir = true\n\t\treturn nil\n\t}\n\n\tdefer func() {\n\t\tif !cleanupGuestWorkdir {\n\t\t\treturn\n\t\t}\n\t\t// Clean up the guest synced workdir\n\t\tif err := executeSSHForRsync(ctx, *sshCmd, inst.SSHLocalPort, inst.SSHAddress, fmt.Sprintf(\"rm -rf %s\", dirForCleanup)); err != nil {\n\t\t\tlogrus.WithError(err).Warn(\"Failed to clean up guest synced workdir\")\n\t\t}\n\t}()\n\n\tif !tty {\n\t\treturn rsyncBack()","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/shell.go#L533-L569","documentation":"After the interactive shell exits, limactl syncs changes made inside the guest's synced workdir back to the original host directory via rsyncDirectory. This error wraps a failure of that guest->host rsync. When it occurs, the guest synced workdir is intentionally NOT cleaned up, so changes remain recoverable at destRsyncDir in the guest.","triggerScenarios":"User confirmed \"Yes\" to accepting changes (or the session is non-TTY, where rsyncBack runs unconditionally) and rsyncDirectory from `instance:destRsyncDir` back to hostCurrentDir fails: SSH failure, host directory permissions, files deleted/replaced concurrently on the host, or rsync protocol mismatch.","commonSituations":"Host directory was deleted or renamed while the shell session was open, so the rsync destination vanished; host files became read-only or owned by another user; network/ssh multiplexing dropped for long sessions; rsync version mismatch between host and guest after a lima/OS upgrade.","solutions":["Recover changes from the guest workdir: `limactl shell <instance> ls <destRsyncDir>` then manually rsync/scp them out, since cleanup was skipped.","Ensure the original host directory still exists and is writable, then re-run `limactl shell <instance>` and accept the changes again.","Fix host-side permissions on hostCurrentDir (chown/chmod) and retry.","Check rsync versions on both sides match and are >= 3.2.4; upgrade the older side.","Review the wrapped rsync stderr (printed by rsyncDirectory) for the exact cause (e.g. 'connection unexpectedly closed')."],"exampleFix":"// before\nif err := rsyncDirectory(ctx, cmd, rsync, paths); err != nil {\n    return fmt.Errorf(\"failed to sync back the changes from guest instance to host: %w\", err)\n}\n// after: guard that the destination exists before syncing back\nif _, err := os.Stat(hostCurrentDir); err != nil {\n    if mkErr := os.MkdirAll(hostCurrentDir, 0o755); mkErr != nil {\n        return fmt.Errorf(\"host dir %s unavailable: %w (guest copy preserved at %s)\", hostCurrentDir, mkErr, destRsyncDir)\n    }\n}\nif err := rsyncDirectory(ctx, cmd, rsync, paths); err != nil {\n    return fmt.Errorf(\"failed to sync back the changes from guest instance to host: %w\", err)\n}","handlingStrategy":"validation","validationCode":"test -d \"$PWD\" && test -w \"$PWD\" && echo 'host dir writable, safe to sync back' || echo 'host dir missing or read-only: changes kept in guest at synced workdir'","typeGuard":null,"tryCatchPattern":"// if the error occurs, changes are NOT lost — recover from the guest\nlimactl shell default || true\nlimactl shell default -- ls /home/<user>.lima/<basename-of-hostdir>  # inspect preserved workdir","preventionTips":["Don't delete or rename the host directory while a lima shell session is open in it.","Keep the host directory writable by your user for the whole session.","For long sessions, be aware SSH control connections can drop; re-check connectivity before relying on rsync-back.","Keep rsync versions consistent between host and guest."],"tags":["rsync","ssh","data-loss","file-sync"],"backgroundTag":"rsync-transfer-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}