{"record":{"id":"f6eca156ed50f09c","repo":"lima-vm/lima","slug":"host-agent-is-running-but-driver-is-not","errorCode":null,"errorMessage":"host agent is running but driver is not","messagePattern":"host agent is running but driver is not","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/instance.go","lineNumber":191,"sourceCode":"\tinst.Status = status\n}\n\nfunc inspectStatusWithPIDFiles(instDir string, inst *limatype.Instance, y *limatype.LimaYAML) {\n\tvar err error\n\tinst.DriverPID, err = ReadPIDFile(filepath.Join(instDir, filenames.PIDFile(*y.VMType)))\n\tif err != nil {\n\t\tinst.Status = limatype.StatusBroken\n\t\tinst.Errors = append(inst.Errors, err)\n\t}\n\n\tif inst.Status == limatype.StatusUnknown {\n\t\tswitch {\n\t\tcase inst.HostAgentPID > 0 && inst.DriverPID > 0:\n\t\t\tinst.Status = limatype.StatusRunning\n\t\tcase inst.HostAgentPID == 0 && inst.DriverPID == 0:\n\t\t\tinst.Status = limatype.StatusStopped\n\t\tcase inst.HostAgentPID > 0 && inst.DriverPID == 0:\n\t\t\tinst.Errors = append(inst.Errors, errors.New(\"host agent is running but driver is not\"))\n\t\t\tinst.Status = limatype.StatusBroken\n\t\tdefault:\n\t\t\tinst.Errors = append(inst.Errors, fmt.Errorf(\"%s driver is running but host agent is not\", inst.VMType))\n\t\t\tinst.Status = limatype.StatusBroken\n\t\t}\n\t}\n}\n\n// ReadPIDFile returns 0 if the PID file does not exist, was written during a previous boot\n// of the host, or the process has already terminated (in which case the PID file will be\n// removed).\nfunc ReadPIDFile(path string) (int, error) {\n\t// The boot is checked before the PID is read, so that a PID file of a previous boot is\n\t// never trusted, not even when another process refreshes the marker in between.\n\tif previousBoot, err := pidFileFromPreviousBoot(path); err != nil {\n\t\treturn 0, err\n\t} else if previousBoot {\n\t\t// The PID was recorded before the last reboot, so it is meaningless now: it may","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/store/instance.go#L173-L209","documentation":"inspectStatusWithPIDFiles infers status from PID files when the driver reports no status string. If the host agent PID file is alive (PID > 0) but the driver PID is 0, the pair is inconsistent: the VM driver has exited while its supervisor lives on. The instance is marked StatusBroken.","triggerScenarios":"HostAgentPID > 0 && DriverPID == 0 during Inspect: the VM process (qemu/vz) crashed or was killed while the hostagent kept running; driver PID file missing while ha.pid remains.","commonSituations":"VM OOM-killed or crashed mid-session; user killed qemu manually; host sleep/resume killed the driver process; stale PID file misread (PID reused by another process).","solutions":["Run `limactl stop <inst>` to shut down the leftover host agent cleanly","If stop fails, kill the hostagent PID in ~/.lima/<inst>/ha.pid and remove stale PID files, then `limactl start <inst>`","Check driver logs (e.g. ~/.lima/<inst>/ha_stdout.log) for why the VM process exited","Verify the PID in the file is actually the hostagent (PID reuse can produce false positives)"],"exampleFix":"// before: ha.pid alive, qemu dead -> Broken\n// after: clean restart\nlimactl stop myvm || (kill $(cat ~/.lima/myvm/ha.pid); rm ~/.lima/myvm/*.pid); limactl start myvm","handlingStrategy":"validation","validationCode":"// Check PID-file consistency before Inspect\nhaPid := store.ReadPIDFile(filepath.Join(instDir, \"ha.pid\"))\ndrvPid := store.ReadPIDFile(filepath.Join(instDir, \"vm.pid\")) // driver-specific name varies\nif haPid > 0 && drvPid == 0 {\n    // inconsistent: hostagent alive, driver gone — stop+start before using the instance\n}","typeGuard":null,"tryCatchPattern":"inst, err := store.Inspect(ctx, instDir)\nif inst.Status == limatype.StatusBroken {\n    for _, e := range inst.Errors {\n        if strings.Contains(e.Error(), \"host agent is running but driver is not\") {\n            _ = instance.Stop(ctx, instName) // clean up, then start again\n        }\n    }\n}","preventionTips":["Never kill the VM (qemu/vz) process directly; use `limactl stop`","Prevent host sleep/hibernation from killing VMs, or restart instances after resume","Monitor for OOM killer events that terminate the driver process"],"tags":["lima","hostagent","driver","pid-files","broken-instance"],"backgroundTag":"orphaned-hostagent-process","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}