feat: Phase 3 Wire-Up — DetectionTimer liest subagent_status.json

presence_engine.py DetectionTimer.check():
- Neue Quelle 'subagent_status' zwischen plugin_state und pgrep
- subagent_used/subagent_count Variablen für Tracking
- Log-Zeile erweitert um subagent_status Info
- Priorität: pid_sentinel > gateway_state > plugin_state > subagent_status > pgrep

Production-Impact: low (DetectionTimer pollt jetzt 5 Quellen statt 4)
This commit is contained in:
Bernd (Hermes)
2026-08-02 11:17:14 +02:00
parent 309b0ddc85
commit a8d920736d
+20 -2
View File
@@ -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,