{"record":{"id":"a6a5b6b379b43c90","repo":"lima-vm/lima","slug":"cannot-safely-prune-while-instance-q-is-being-us","errorCode":null,"errorMessage":"cannot safely prune while instance %#q is being used: %w","messagePattern":"cannot safely prune while instance %#q is being used: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/prune.go","lineNumber":86,"sourceCode":"\t}\n\n\t// Sweep leftover partial downloads (data.part / data.tmp.*) from the kept entries.\n\treturn downloader.RemoveStaleTempFiles(opt)\n}\n\nfunc knownLocations(ctx context.Context) (map[string]limatype.File, error) {\n\tlocations := make(map[string]limatype.File)\n\n\t// Collect locations from instances\n\tinstances, err := store.Instances()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, instanceName := range instances {\n\t\tinstance, err := store.Inspect(ctx, instanceName)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\treturn nil, fmt.Errorf(\"cannot safely prune while instance %#q is being used: %w\", instanceName, err)\n\t\t\t}\n\t\t\treturn nil, err\n\t\t}\n\t\tif instance.Errors != nil {\n\t\t\tlogrus.Warnf(\"skipping instance %#q because it has errors: %v\", instanceName, instance.Errors)\n\t\t\tcontinue\n\t\t}\n\t\tmaps.Copy(locations, locationsFromLimaYAML(instance.Config))\n\t}\n\n\t// Collect locations from templates\n\ttemplates, err := templatestore.Templates()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, t := range templates {\n\t\ttmpl, err := limatmpl.Read(ctx, \"\", t.Location)\n\t\tif err != nil {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/prune.go#L68-L104","documentation":"knownLocations enumerates instances to decide what prune may safely delete. If store.Inspect on a listed instance returns an error that is os.ErrNotExist, the listing is stale relative to the disk, so prune aborts with \"cannot safely prune while instance <name> is being used\" rather than deleting data based on inconsistent state. Other inspect errors are returned unwrapped.","triggerScenarios":"An instance directory listed by store.Instances() disappeared (concurrent `limactl delete`, external rm) between listing and inspection while running `limactl prune`.","commonSituations":"Running prune in parallel with instance deletion; manually removing ~/.lima/instance dirs while Lima commands run; race with another limactl process in CI.","solutions":["Re-run `limactl prune` once no other limactl commands are executing","Run `limactl list` to refresh/verify consistent instance state, then prune","Remove the stale/ghost instance reference (e.g. finish the interrupted delete) and retry"],"exampleFix":"// before\nlimactl prune &  limactl delete myvm --force   # racy\n// after\nlimactl delete myvm --force\nlimactl prune","handlingStrategy":"retry","validationCode":"# ensure no other limactl operation is in flight\npgrep -f 'limactl (delete|prune)' && { echo 'lima operation in progress' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := pruneCmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"cannot safely prune while instance\") {\n        time.Sleep(2 * time.Second)\n        // retry prune once concurrent operations have finished\n    }\n}","preventionTips":["Do not run prune concurrently with instance create/delete","Refresh state with `limactl list` after external modifications to ~/.lima","Clean up interrupted deletes before pruning"],"tags":["prune","instance","race-condition"],"backgroundTag":"stale-instance-state","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}