fix(ops): skip cwd-hidden OS helpers and non-worktree processes on cleanup

This commit is contained in:
weichen
2026-09-23 12:54:45 +00:00
parent c0a0db3a70
commit 7cb7981deb
+18 -8
View File
@@ -134,16 +134,26 @@ def _linux_same_user_cwds():
except (FileNotFoundError, ProcessLookupError):
continue
except PermissionError:
# Linux may hide cwd for the per-user OS service manager despite a
# matching UID. This narrowly named OS process is not a task agent;
# all other unreadable same-user processes remain fail-closed.
# Linux may hide cwd for per-user OS/session helpers despite a matching
# UID. Skip only when the process is a known session helper, or when
# cmdline is readable and clearly not rooted under any task worktree.
# All other unreadable same-user processes remain fail-closed.
try:
if (proc / "comm").read_text().strip() == "systemd":
print(f"[notice] OS user service manager {proc.name} hides cwd; "
"managed task registry and lifecycle locks remain required", file=sys.stderr)
continue
comm = (proc / "comm").read_text().strip()
except (OSError, UnicodeError):
pass
comm = ""
if comm in {"systemd", "sd-pam", "sshd", "sshd-session"}:
print(f"[notice] OS session helper {proc.name} ({comm}) hides cwd; "
"managed task registry and lifecycle locks remain required", file=sys.stderr)
continue
try:
cmdline = (proc / "cmdline").read_bytes().replace(b"\0", b" ").decode("utf-8", "replace")
except (OSError, UnicodeError):
cmdline = ""
if cmdline and ".worktrees/" not in cmdline and "/.kilo/worktrees/" not in cmdline:
print(f"[notice] cwd-hidden process {proc.name} ({comm or 'unknown'}) has no worktree path in cmdline; "
"managed task registry and lifecycle locks remain required", file=sys.stderr)
continue
unreadable.append(proc.name)
if unreadable:
raise Refused(f"cannot verify cwd of same-user process {','.join(unreadable)}; cleanup_pending")