diff --git a/plugin/archivar/presence_engine.py b/plugin/archivar/presence_engine.py index 1de4dda..9bef2ae 100644 --- a/plugin/archivar/presence_engine.py +++ b/plugin/archivar/presence_engine.py @@ -1471,6 +1471,8 @@ class DetectionTimer: gateway_used = False # True if gateway_state was the deciding signal plugin_used = False # P1-2: True if plugin_state was the deciding signal plugin_bg_tasks = -1 # P1-2: -1 = not read, >=0 = count + subagent_used = False # Phase 5: True if subagent_status.json was the deciding signal + subagent_count = -1 # Phase 5: -1 = not read, >=0 = count detection_source = "none" # P1-2: which signal decided # ── P2 PRIMARY: PID-Sentinel — prüft ob Gateway-Prozess lebt ──────── @@ -1504,8 +1506,21 @@ class DetectionTimer: plugin_used = True detection_source = "plugin_state" - # ── P2 QUATERNARY: pgrep — erweitertes Pattern 'gateway run' ──────── + # ── Phase 5: QUATERNARY: subagent_status.json ──────────────────────── if not pid_used and not gateway_used and not plugin_used: + try: + from archivar.subagent_tracker import _read_subagent_state, _get_subagent_state_path + subagent_state = _read_subagent_state(_get_subagent_state_path()) + subagent_count = len(subagent_state.get("active", [])) + if subagent_count > 0: + result = True + subagent_used = True + detection_source = "subagent_status" + except Exception as e: + logger.debug("[detection] subagent_status.json read failed: %s", e) + + # ── P2 QUATERNARY: pgrep — erweitertes Pattern 'gateway run' ──────── + if not pid_used and not gateway_used and not plugin_used and not subagent_used: try: own_pid = os.getpid() # P2 Fix: Pattern um 'gateway run' erweitert @@ -1530,9 +1545,10 @@ class DetectionTimer: # ── Log: all signals, result, source ─────────────────────────────── pgrep_str = str(pgrep_pids) if pgrep_pids >= 0 else "error" plugin_str = str(plugin_bg_tasks) if plugin_bg_tasks >= 0 else "n/a" + subagent_str = str(subagent_count) if subagent_count >= 0 else "n/a" logger.info( "[detection] check #%d: pid_sentinel=%s, gateway_state=%d (primary=%s), " - "plugin_state=%s (bg_tasks=%s), pgrep=%s, " + "plugin_state=%s (bg_tasks=%s), subagent_status=%s (active=%s), pgrep=%s, " "result=%s, source=%s", self._check_count, "alive" if pid_used else "dead", @@ -1540,6 +1556,8 @@ class DetectionTimer: "yes" if gateway_used else "no", "yes" if plugin_used else "no", plugin_str, + "yes" if subagent_used else "no", + subagent_str, pgrep_str, "active" if result else "inactive", detection_source,