{"record":{"id":"fa5d65398067df81","repo":"lima-vm/lima","slug":"failed-to-remove-the-autostart-entry-for-instance","errorCode":null,"errorMessage":"failed to remove the autostart entry for instance %#q: %w","messagePattern":"failed to remove the autostart entry for instance %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/autostart/managers.go","lineNumber":110,"sourceCode":"\tif t.enabler != nil {\n\t\treturn t.enabler(ctx, true, inst.Name)\n\t}\n\treturn nil\n}\n\nfunc (t *TemplateFileBasedManager) UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error {\n\tif registered, err := t.IsRegistered(ctx, inst); err != nil {\n\t\treturn fmt.Errorf(\"failed to check if the autostart entry for instance %#q is registered: %w\", inst.Name, err)\n\t} else if !registered {\n\t\treturn nil\n\t}\n\tif t.enabler != nil {\n\t\tif err := t.enabler(ctx, false, inst.Name); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to disable the autostart entry for instance %#q: %w\", inst.Name, err)\n\t\t}\n\t}\n\tif err := os.Remove(t.filePath(inst.Name)); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove the autostart entry for instance %#q: %w\", inst.Name, err)\n\t}\n\treturn nil\n}\n\nfunc (t *TemplateFileBasedManager) renderTemplate(instName, workDir string, getExecutable func() (string, error)) ([]byte, error) {\n\tif t.template == \"\" {\n\t\treturn nil, errors.New(\"no template available\")\n\t}\n\tselfExeAbs, err := getExecutable()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdata := map[string]string{\n\t\t\"Binary\":   selfExeAbs,\n\t\t\"Instance\": instName,\n\t\t\"WorkDir\":  workDir,\n\t}\n\tmaps.Copy(data, t.extraTemplateVars)","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/autostart/managers.go#L92-L128","documentation":"os.Remove of the autostart entry file failed after the disable step succeeded. The wrapper tells you which instance's entry could not be removed; the wrapped error carries the OS reason (most commonly ENOENT from a race, or EACCES/EPERM).","triggerScenarios":"UnregisterFromStartAtLogin: IsRegistered returned true, disable succeeded, then os.Remove(t.filePath(inst.Name)) failed — e.g. the file was deleted concurrently, the directory is read-only, or an immutable/ACL flag blocks deletion.","commonSituations":"Another limactl process or the user removed the entry file between the stat and the remove; ~/.config/systemd/user or ~/Library/LaunchAgents permissions changed; entry file owned by another user after running limactl with sudo previously.","solutions":["Check the wrapped error: if ENOENT, the entry is already gone — treat unregister as done","Fix ownership/permissions on the entry file and its directory (chown back to your user; avoid running limactl with sudo)","Remove manually: delete ~/.config/systemd/user/lima-<instance>.service (Linux) or ~/Library/LaunchAgents/lima-*.plist (macOS) and reload"],"exampleFix":"// before: entry owned by root after sudo use\nsudo chown -R $USER ~/.config/systemd/user\n// after: retry\nlimactl autostart remove default","handlingStrategy":"try-catch","validationCode":"path := entryPath(inst.Name)\nif _, err := os.Stat(path); err == nil {\n    if fi, err2 := os.Stat(filepath.Dir(path)); err2 != nil || !isWritable(fi) {\n        // fix dir permissions before unregister\n    }\n}\n","typeGuard":null,"tryCatchPattern":"if err := mgr.UnregisterFromStartAtLogin(ctx, inst); err != nil {\n    var pathErr *os.PathError\n    if errors.As(err, &pathErr) && errors.Is(pathErr.Err, syscall.ENOENT) {\n        return nil // already removed concurrently\n    }\n    return err\n}\n","preventionTips":["Avoid concurrent limactl processes operating on the same instance's autostart entry","Keep ~/.config/systemd/user (Linux) / ~/Library/LaunchAgents (macOS) owned by your user","Don't set immutable flags or restrictive ACLs on autostart entry files","Clean up root-owned leftovers after any sudo limactl use"],"tags":["autostart","filesystem","permissions"],"backgroundTag":"file-remove-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}