{"record":{"id":"c14df78e75544c42","repo":"gastownhall/beads","slug":"kill-verified-orphan-backend-pid-d-from-s-w","errorCode":null,"errorMessage":"kill verified orphan backend pid %d from %s: %w","messagePattern":"kill verified orphan backend pid (.+?) from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dbproxy/proxy/endpoint.go","lineNumber":837,"sourceCode":"\thandle, dead, err := openRecordedProcess(pf)\n\tif err != nil {\n\t\treturn unverifiableProcessError(\n\t\t\t\"backend cleanup\",\n\t\t\trecordPath,\n\t\t\tpf.Pid,\n\t\t\terr,\n\t\t\tunverifiableProcessChecks{},\n\t\t)\n\t}\n\tif dead {\n\t\tif _, err := quarantineRecord(rootDir, server.PIDFileName, time.Now()); err != nil {\n\t\t\treturn fmt.Errorf(\"quarantine dead backend record: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\tif err := handle.Kill(); err != nil {\n\t\t_ = handle.Close()\n\t\treturn fmt.Errorf(\"kill verified orphan backend pid %d from %s: %w\", pf.Pid, recordPath, err)\n\t}\n\t// Close before waiting: an open handle on Windows keeps the dead PID\n\t// allocated, so procid.Verify would keep matching it and the exit wait\n\t// below would always time out.\n\tif err := handle.Close(); err != nil {\n\t\treturn fmt.Errorf(\"close verified backend process handle for pid %d: %w\", pf.Pid, err)\n\t}\n\tif err := waitForRecordedProcessExit(pf, backendExitTimeout); err != nil {\n\t\treturn fmt.Errorf(\"wait for verified orphan backend pid %d: %w\", pf.Pid, err)\n\t}\n\tif _, err := quarantineRecord(rootDir, server.PIDFileName, time.Now()); err != nil {\n\t\treturn fmt.Errorf(\"quarantine orphan backend record: %w\", err)\n\t}\n\treturn nil\n}\n\ntype unverifiableProcessChecks struct {\n\tLiveEstablished bool","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dbproxy/proxy/endpoint.go#L819-L855","documentation":"Cleanup verified the recorded PID as this workspace's orphaned backend and attempted to kill it. This error wraps a failure of handle.Kill() on that process handle — the orphan backend could not be terminated, so the stale record is left un-quarantined and cleanup aborts.","triggerScenarios":"openRecordedProcess returned a live handle matching pf, handle.Kill() returns an error at internal/storage/dbproxy/proxy/endpoint.go:835-837 (e.g. insufficient privileges, access denied, process already terminating with a handle error).","commonSituations":"The orphan backend runs as a different user (e.g. started via sudo) so the current user may not signal it; on Windows, access-denied from OpenProcess-protected processes; hardened containers/seccomp blocking signals.","solutions":["Kill the process manually with elevated privileges: kill -9 <pid> (or Stop-Process -Force -Id <pid> on Windows).","Run the cleanup under the same user (or via sudo) that started the backend.","Confirm with ps/tasklist whether the process already exited; if it is gone, quarantine the record manually and retry.","Check container/sandbox policies if signals are being blocked."],"exampleFix":"// before\nError: kill verified orphan backend pid 4242 from /ws/.beads/dbproxy/dolt-backend.pid: operation not permitted\n// after\n$ sudo kill -9 4242\n$ mv /ws/.beads/dbproxy/dolt-backend.pid /ws/.beads/dbproxy/dolt-backend.pid.stale-$(date +%s)","handlingStrategy":"try-catch","validationCode":"// Pre-check you may signal the recorded pid before invoking cleanup:\nif proc, err := os.FindProcess(pid); err == nil {\n    _ = proc.Signal(syscall.Signal(0)) // EPERM here predicts kill failure\n}","typeGuard":"func canSignal(pid int) bool {\n    p, err := os.FindProcess(pid)\n    if err != nil { return false }\n    return p.Signal(syscall.Signal(0)) == nil\n}","tryCatchPattern":"if err := cleanupOrphanBackend(rootDir); err != nil && strings.Contains(err.Error(), \"kill verified orphan backend pid\") {\n    // escalate: run cleanup under the backend's owning user or with sudo,\n    // or kill -9 <pid> manually, then quarantine the record\n}","preventionTips":["Start backends and run bd under the same user account.","Avoid launching backends via sudo.","In containers, run cleanup inside the same container/PID namespace.","Grant signal rights (Windows: same user/elevated shell) for service-owned processes."],"tags":["go","process-kill","permissions","orphan-backend"],"backgroundTag":"process-kill-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}