From 2423385c059f63aec9845c2d0c7c2dbaba554648 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:43:10 +0530 Subject: [PATCH] refactor(serve): one place maps "process gone" to orphaned in the watchdog The inner ProcessLookupError handler around the marker probe made the outer one reachable only through an injected pid_exists that raises (gateway.status._pid_exists never does). Keep the single mapping; the degrade-to-liveness fixture no longer models a stderr the probe now classifies as a missing process. --- hermes_cli/web_server_lifecycle.py | 7 ++----- tests/hermes_cli/test_serve_parent_watchdog.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hermes_cli/web_server_lifecycle.py b/hermes_cli/web_server_lifecycle.py index b9eb0d9c44..78dcafdf66 100644 --- a/hermes_cli/web_server_lifecycle.py +++ b/hermes_cli/web_server_lifecycle.py @@ -75,9 +75,8 @@ def _process_start_marker(pid: int) -> str: marker = result.stdout.strip() if result.returncode == 0 and marker: return f"ps:{marker}" - # rc==1 with empty output is the portable "no such pid"; "No such process" widens that for ps - # builds that say so explicitly. Any other failure stays an OSError so the watchdog degrades to - # pid liveness instead of exiting on a healthy backend. + # Only known "missing pid" signals become ProcessLookupError; anything else stays OSError so the + # watchdog degrades to pid liveness instead of exiting on a healthy backend. if (result.returncode == 1 and not marker) or "no such process" in result.stderr.lower(): raise ProcessLookupError(pid) raise OSError(f"ps could not inspect PID {pid}: {result.stderr.strip()}") @@ -300,8 +299,6 @@ def _is_serve_orphaned( pid_exists = _pid_exists return not bool(pid_exists(int(desktop_pid))) - except ProcessLookupError: - return True except Exception: return False diff --git a/tests/hermes_cli/test_serve_parent_watchdog.py b/tests/hermes_cli/test_serve_parent_watchdog.py index 4ad394a976..95cb895cfe 100644 --- a/tests/hermes_cli/test_serve_parent_watchdog.py +++ b/tests/hermes_cli/test_serve_parent_watchdog.py @@ -183,7 +183,7 @@ def test_parent_watchdog_degrades_to_pid_liveness_when_marker_probe_raises_oserr """#80204: a probe failure must fall through to ``pid_exists`` instead of pinning the watchdog to "not orphaned" forever on a dead Desktop parent.""" def broken_marker_probe(pid: int) -> str: - raise OSError(f"ps could not inspect PID {pid}: ps: {pid}: No such process") + raise OSError(f"ps could not inspect PID {pid}: process table temporarily unavailable") marker = "ps:Thu Aug 20 22:33:11 2026" assert _is_serve_orphaned(4242, marker, pid_exists=lambda _pid: False,