feat(slash-worker): self-terminate on parent death via create_time watchdog

Daemon thread polls _is_orphaned (original ppid check + psutil create_time PID-reuse
guard, no PR_SET_PDEATHSIG). On orphan, drains an in-flight command up to a grace
window then os._exit(0). Started before the HermesCLI build to cover the spawn window.

Task: swl-qrf.8
This commit is contained in:
firefly
2026-06-08 07:03:12 -07:00
committed by Teknium
parent b31c6c33b2
commit 8b6a8f667d
2 changed files with 68 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import psutil
from tui_gateway import slash_worker
def test_is_orphaned_true_when_ppid_changes():
# Our parent went away and we were reparented to a subreaper/init.
assert slash_worker._is_orphaned(1234, 1.0, getppid=lambda: 999999) is True
def test_is_orphaned_true_when_parent_create_time_mismatch():
# Same ppid but a different create_time means the PID was reused.
me = psutil.Process()
assert slash_worker._is_orphaned(me.pid, 0.0, getppid=lambda: me.pid) is True
def test_is_orphaned_false_when_parent_alive_and_matches():
me = psutil.Process()
assert (
slash_worker._is_orphaned(me.pid, me.create_time(), getppid=lambda: me.pid) is False
)