fix(A3): on_agent_busy/on_message_received toten Code entfernt

This commit is contained in:
Bernd (Hermes)
2026-07-24 17:09:17 +02:00
parent 9db62bf94a
commit 0a05816b68
2 changed files with 15 additions and 30 deletions
+2 -20
View File
@@ -217,8 +217,8 @@ class PresenceEngine:
self._active_tasks -= 1 self._active_tasks -= 1
count = self._active_tasks count = self._active_tasks
# FIX: Resume pulse when all active tasks complete. # FIX: Resume pulse when all active tasks complete.
# on_agent_busy() pauses the pulse, but resume() was never called # mark_busy_started() pauses the pulse via adapter, but resume()
# in production — the pulse stayed paused forever. # was never called in production — the pulse stayed paused forever.
if count == 0: if count == 0:
self._pulse_controller.resume() self._pulse_controller.resume()
logger.info("[presence] active_tasks=0 → pulse resumed") logger.info("[presence] active_tasks=0 → pulse resumed")
@@ -597,24 +597,6 @@ class PresenceEngine:
""" """
self._pulse_controller.cancel_pending() self._pulse_controller.cancel_pending()
def on_agent_busy(self, room_name: str = "") -> None:
"""Hook: Agent is processing a message — pause pulse, set busy.
Priority 1 (highest): busy (rot) — Nachricht wird verarbeitet.
"""
self.set_current_room(room_name)
self.increment_active_tasks()
self.update_presence()
# Pause pulse if running
self._pulse_controller.pause()
def on_message_received(self, room_name: str = "") -> None:
"""Hook: Message received — same as on_agent_busy.
Alias for on_agent_busy for semantic clarity.
"""
self.on_agent_busy(room_name=room_name)
# ═══════════════════════════════════════════════════════════════════════════ # ═══════════════════════════════════════════════════════════════════════════
# PulseController — DDP-basierte Heartbeat-Pulsierung (1.5s Intervall) # PulseController — DDP-basierte Heartbeat-Pulsierung (1.5s Intervall)
+13 -10
View File
@@ -1136,10 +1136,10 @@ class TestEdgeCaseReconnectRace:
class TestEdgeCaseOnAgentBusy: class TestEdgeCaseOnAgentBusy:
"""Test 31: on_agent_busy() — pausiert Pulse, setzt busy (rot).""" """Test 31: mark_busy_started() + pause() — pausiert Pulse, setzt busy (rot)."""
def test_on_agent_busy_pauses_pulse(self): def test_on_agent_busy_pauses_pulse(self):
"""on_agent_busy() pausiert den PulseController und setzt busy.""" """mark_busy_started() + pause() pausiert den PulseController und setzt busy."""
from plugin.archivar.presence_engine import PresenceEngine from plugin.archivar.presence_engine import PresenceEngine
mock_rest = MagicMock() mock_rest = MagicMock()
@@ -1164,8 +1164,9 @@ class TestEdgeCaseOnAgentBusy:
time.sleep(0.1) time.sleep(0.1)
assert engine._pulse_controller.is_running() assert engine._pulse_controller.is_running()
# on_agent_busy: pausiert Pulse # A3: mark_busy_started + pause ersetzt on_agent_busy (toter Code entfernt)
engine.on_agent_busy(room_name="#Test") engine.mark_busy_started(room_name="#Test")
engine._pulse_controller.pause()
time.sleep(0.1) time.sleep(0.1)
# Pulse sollte pausiert sein # Pulse sollte pausiert sein
@@ -1198,8 +1199,9 @@ class TestEdgeCaseOnAgentBusy:
engine._pulse_controller.start() engine._pulse_controller.start()
engine._background_tasks = 3 engine._background_tasks = 3
# on_agent_busy # A3: mark_busy_started + pause ersetzt on_agent_busy
engine.on_agent_busy(room_name="#Test") engine.mark_busy_started(room_name="#Test")
engine._pulse_controller.pause()
time.sleep(0.1) time.sleep(0.1)
# Task beendet → decrement + update # Task beendet → decrement + update
@@ -1214,10 +1216,10 @@ class TestEdgeCaseOnAgentBusy:
class TestEdgeCaseOnMessageReceived: class TestEdgeCaseOnMessageReceived:
"""Test 32: on_message_received() — wie on_agent_busy, pausiert Pulse.""" """Test 32: mark_busy_started() + pause() — wie on_agent_busy, pausiert Pulse."""
def test_on_message_received_pauses_pulse(self): def test_on_message_received_pauses_pulse(self):
"""on_message_received() verhält sich wie on_agent_busy().""" """mark_busy_started() + pause() verhält sich wie on_agent_busy()."""
from plugin.archivar.presence_engine import PresenceEngine from plugin.archivar.presence_engine import PresenceEngine
mock_rest = MagicMock() mock_rest = MagicMock()
@@ -1238,8 +1240,9 @@ class TestEdgeCaseOnMessageReceived:
time.sleep(0.1) time.sleep(0.1)
assert engine._pulse_controller.is_running() assert engine._pulse_controller.is_running()
# on_message_received → wie on_agent_busy # A3: mark_busy_started + pause ersetzt on_message_received
engine.on_message_received(room_name="#Test") engine.mark_busy_started(room_name="#Test")
engine._pulse_controller.pause()
time.sleep(0.1) time.sleep(0.1)
assert not engine._pulse_controller.is_running() or engine._pulse_controller._paused.is_set() assert not engine._pulse_controller.is_running() or engine._pulse_controller._paused.is_set()