fix: F6 P1-3 PulseController DDP warning assert + P2 detection logging
P1-3: Add missing assert on warning log in test_start_without_ddp_logs_warning - assert len(warning_calls) >= 1 - assert 'PulseController.start() called without DDP' in str(warning_calls[0]) P2-1: Make gateway_state_path configurable via PresenceEngine param and ROCKETCHAT_GATEWAY_STATE_PATH env var (was hardcoded ~/.hermes/gateway_state.json) P2-2: Add separate 'detection unavailable' log message when pgrep fails, instead of falling through to generic 'no background activity detected' P2-3: Document telemetry coupling in _increment_telemetry docstrings (both PulseController and DetectionTimer)
This commit is contained in:
@@ -85,6 +85,7 @@ class PresenceEngine:
|
||||
enabled: bool = True,
|
||||
coalesce_ms: int = 2000,
|
||||
pulse_interval: float = 1.5,
|
||||
gateway_state_path: str = "",
|
||||
_clamp_pulse: bool = True,
|
||||
):
|
||||
"""Initialize the PresenceEngine.
|
||||
@@ -94,6 +95,8 @@ class PresenceEngine:
|
||||
enabled: Whether presence updates are enabled.
|
||||
coalesce_ms: Coalesce delay in milliseconds (default 2000).
|
||||
pulse_interval: PulseController interval in seconds (0.5-30, default 1.5).
|
||||
gateway_state_path: Path to gateway_state.json. Defaults to
|
||||
ROCKETCHAT_GATEWAY_STATE_PATH env var or ~/.hermes/gateway_state.json.
|
||||
_clamp_pulse: If True, clamp pulse_interval to 0.5-30. Set False for testing.
|
||||
"""
|
||||
self._rest = rest
|
||||
@@ -136,6 +139,7 @@ class PresenceEngine:
|
||||
|
||||
# P0-1: DetectionTimer — erkennt Hintergrund-Agenten, steuert PulseController
|
||||
self._detection_timer = DetectionTimer(
|
||||
gateway_state_path=gateway_state_path,
|
||||
detection_interval=10.0,
|
||||
on_change=self._on_detection_change,
|
||||
)
|
||||
@@ -620,7 +624,12 @@ class PulseController:
|
||||
logger.debug("[pulse] REST setStatus failed: %s", e)
|
||||
|
||||
def _increment_telemetry(self) -> None:
|
||||
"""Increment the heartbeat_pulse telemetry counter."""
|
||||
"""Increment the heartbeat_pulse telemetry counter.
|
||||
|
||||
NOTE: Coupled to archivar.routing_telemetry.routing_telemetry.
|
||||
This is a cross-module dependency that should be refactored
|
||||
to use a shared telemetry interface or event bus.
|
||||
"""
|
||||
try:
|
||||
from archivar.routing_telemetry import routing_telemetry
|
||||
routing_telemetry.heartbeat_pulse += 1
|
||||
@@ -655,7 +664,10 @@ class DetectionTimer:
|
||||
on_change: Callback(is_active) when detection state changes.
|
||||
"""
|
||||
if not gateway_state_path:
|
||||
gateway_state_path = os.path.expanduser("~/.hermes/gateway_state.json")
|
||||
gateway_state_path = os.environ.get(
|
||||
"ROCKETCHAT_GATEWAY_STATE_PATH",
|
||||
os.path.expanduser("~/.hermes/gateway_state.json"),
|
||||
)
|
||||
self._gateway_state_path = gateway_state_path
|
||||
self._detection_interval = detection_interval
|
||||
self._on_change = on_change
|
||||
@@ -741,6 +753,10 @@ class DetectionTimer:
|
||||
logger.debug("[detection] pgrep fallback failed: %s", e)
|
||||
result = False
|
||||
source = "pgrep_error"
|
||||
logger.info(
|
||||
"[detection] check #%d: detection unavailable (pgrep failed)",
|
||||
self._check_count,
|
||||
)
|
||||
|
||||
# If no source produced a result, log inactive
|
||||
if source == "none":
|
||||
@@ -785,7 +801,12 @@ class DetectionTimer:
|
||||
time.sleep(0.1)
|
||||
|
||||
def _increment_telemetry(self) -> None:
|
||||
"""Increment the heartbeat_detection telemetry counter."""
|
||||
"""Increment the heartbeat_detection telemetry counter.
|
||||
|
||||
NOTE: Coupled to archivar.routing_telemetry.routing_telemetry.
|
||||
This is a cross-module dependency that should be refactored
|
||||
to use a shared telemetry interface or event bus.
|
||||
"""
|
||||
try:
|
||||
from archivar.routing_telemetry import routing_telemetry
|
||||
routing_telemetry.heartbeat_detection += 1
|
||||
|
||||
@@ -1383,6 +1383,8 @@ class TestPulseControllerStartWithoutDdp:
|
||||
c for c in mock_logger.warning.call_args_list
|
||||
if "DDP" in str(c) or "ddp" in str(c)
|
||||
]
|
||||
assert len(warning_calls) >= 1
|
||||
assert "PulseController.start() called without DDP" in str(warning_calls[0])
|
||||
# Mindestens: kein Crash, Thread läuft sauber durch
|
||||
assert not pc.is_running()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user