fix(P-064+P-065): Hook-Registrierung in connect() + Onboarding ACTIVE-Guard aufspalten
P-064: _register_presence_hooks() war definiert aber wurde NIE aufgerufen.
- _active_adapter wurde NIE auf self gesetzt (Hook-Callbacks fanden None).
- connect() ruft jetzt _register_presence_hooks() + setzt _active_adapter.
- Nutzt sys.modules.get(__name__.rsplit('.', 1)[0]) für Flat-Modul-Ladung.
P-065: _is_onboarding_phase_active() behandelte ACTIVE als 'aktiv'.
- OnboardingState.ACTIVE = abgeschlossen, aber Guard blockte alle Nachrichten.
- Neue Methoden: _is_onboarding_running() (Guard) + _is_onboarding_completed() (Prefix).
- 6 Aufrufer umgestellt: 4 auf _is_onboarding_running(), 1 auf Kombination.
- _is_onboarding_phase_active() bleibt als Legacy-Wrapper (ACTIVE entfernt).
This commit is contained in:
+115
-15
@@ -1342,8 +1342,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
if not _MULTIROOM() or self.archivar is None:
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Prüfe ob Onboarding bereits aktiv ist
|
# Prüfe ob Onboarding bereits läuft (P-065: _is_onboarding_running)
|
||||||
if self._is_onboarding_phase_active()[0]:
|
if self._is_onboarding_running()[0]:
|
||||||
logger.debug("[rocketchat] A1b: Onboarding bereits aktiv — DDP-Event ignoriert: room=%s", room_id[:12])
|
logger.debug("[rocketchat] A1b: Onboarding bereits aktiv — DDP-Event ignoriert: room=%s", room_id[:12])
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1877,8 +1877,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# 2. Gateway findet Räume die nicht in room-map.json stehen
|
# 2. Gateway findet Räume die nicht in room-map.json stehen
|
||||||
# 3. DM wird jetzt auch thematisch onboardet (Thema, Keywords, Catch-All)
|
# 3. DM wird jetzt auch thematisch onboardet (Thema, Keywords, Catch-All)
|
||||||
# B9 fix (a): Idempotenz-Guard — wenn Onboarding bereits läuft, nicht erneut starten
|
# B9 fix (a): Idempotenz-Guard — wenn Onboarding bereits läuft, nicht erneut starten
|
||||||
# P-054: Verwende _is_onboarding_phase_active() für SM-State-Awareness
|
# P-065: Verwende _is_onboarding_running() für Guard-Check
|
||||||
if self._is_onboarding_phase_active()[0]:
|
if self._is_onboarding_running()[0]:
|
||||||
logger.info("[rocketchat] B9: Onboarding bereits aktiv — überspringe Reconnect-Trigger")
|
logger.info("[rocketchat] B9: Onboarding bereits aktiv — überspringe Reconnect-Trigger")
|
||||||
# B9 fix (b): is_reconnect — prüfe ob neue Räume hinzugekommen sind
|
# B9 fix (b): is_reconnect — prüfe ob neue Räume hinzugekommen sind
|
||||||
elif is_reconnect and self.archivar._room_map and len(self.archivar._room_map.rooms) > 0:
|
elif is_reconnect and self.archivar._room_map and len(self.archivar._room_map.rooms) > 0:
|
||||||
@@ -1929,6 +1929,22 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
logger.info("[rocketchat] Onboarding bereits ACTIVE — überspringe DM-Theme-Check (Map hat Räume)")
|
logger.info("[rocketchat] Onboarding bereits ACTIVE — überspringe DM-Theme-Check (Map hat Räume)")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("[rocketchat] Archivar-Initialisierung fehlgeschlagen: %s — Fallback ohne Klassifikation", e)
|
logger.warning("[rocketchat] Archivar-Initialisierung fehlgeschlagen: %s — Fallback ohne Klassifikation", e)
|
||||||
|
# ── P-064: Hook-Registrierung + _active_adapter setzen ──────────
|
||||||
|
# _register_presence_hooks() war definiert aber wurde NIE aufgerufen.
|
||||||
|
# _active_adapter war deklariert aber wurde NIE auf self gesetzt.
|
||||||
|
# Folge: PresenceEngine lief mit sync_hooks=true aber ohne Hooks.
|
||||||
|
import sys
|
||||||
|
try:
|
||||||
|
plugin_mod = sys.modules.get(__name__.rsplit(".", 1)[0])
|
||||||
|
if plugin_mod is not None:
|
||||||
|
plugin_mod._active_adapter = self
|
||||||
|
plugin_mod._register_presence_hooks()
|
||||||
|
logger.info("[rocketchat] P-064: Presence-Hooks registriert + _active_adapter gesetzt")
|
||||||
|
else:
|
||||||
|
logger.warning("[rocketchat] P-064: plugin-Modul nicht in sys.modules — Hook-Registrierung übersprungen")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning("[rocketchat] P-064: Hook-Registrierung fehlgeschlagen: %s", e)
|
||||||
|
|
||||||
self._mark_connected()
|
self._mark_connected()
|
||||||
self._running = True
|
self._running = True
|
||||||
self._listen_task = asyncio.create_task(self._listen_loop())
|
self._listen_task = asyncio.create_task(self._listen_loop())
|
||||||
@@ -1949,8 +1965,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
(is_active: bool, operator_room_id: str, reason: str)
|
(is_active: bool, operator_room_id: str, reason: str)
|
||||||
is_active = True wenn Onboarding läuft (IN_PROGRESS/PAUSED)
|
is_active = True wenn Onboarding läuft (IN_PROGRESS/PAUSED)
|
||||||
oder abgeschlossen ist (ACTIVE).
|
oder abgeschlossen ist (ACTIVE).
|
||||||
operator_room_id aus OnboardingStateMachine._data (YAML),
|
|
||||||
NICHT aus In-Memory.
|
P-065: Diese Methode ist jetzt ein Legacy-Wrapper.
|
||||||
|
Verwende _is_onboarding_running() für Guard-Checks
|
||||||
|
und _is_onboarding_completed() für ONBOARD:-Prefix-Erkennung.
|
||||||
"""
|
"""
|
||||||
if not _MULTIROOM() or self.archivar is None:
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
return (False, "", "no_multiroom_or_archivar")
|
return (False, "", "no_multiroom_or_archivar")
|
||||||
@@ -1965,13 +1983,12 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
if sm is not None:
|
if sm is not None:
|
||||||
try:
|
try:
|
||||||
sm_state = sm.state
|
sm_state = sm.state
|
||||||
# ACTIVE = abgeschlossen, aber Phase ist noch "aktiv" für
|
# P-065: ACTIVE ist NICHT mehr in sm_active enthalten.
|
||||||
# ONBOARD:-Prefix-Erkennung nach Gateway-Restart
|
# _is_onboarding_running() ist der korrekte Guard.
|
||||||
sm_active = sm_state in (
|
sm_active = sm_state in (
|
||||||
OnboardingState.AWAITING_ROOM,
|
OnboardingState.AWAITING_ROOM,
|
||||||
OnboardingState.AWAITING_INTENT,
|
OnboardingState.AWAITING_INTENT,
|
||||||
OnboardingState.AWAITING_TEST,
|
OnboardingState.AWAITING_TEST,
|
||||||
OnboardingState.ACTIVE,
|
|
||||||
OnboardingState.PAUSED,
|
OnboardingState.PAUSED,
|
||||||
)
|
)
|
||||||
sm_operator_room = getattr(sm._data, 'operator_room_id', '') or ''
|
sm_operator_room = getattr(sm._data, 'operator_room_id', '') or ''
|
||||||
@@ -1990,6 +2007,85 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
reason = "sm_active" if sm_active else ("stats_active" if stats_active else "inactive")
|
reason = "sm_active" if sm_active else ("stats_active" if stats_active else "inactive")
|
||||||
return (is_active, operator_room_id, reason)
|
return (is_active, operator_room_id, reason)
|
||||||
|
|
||||||
|
def _is_onboarding_running(self) -> tuple:
|
||||||
|
"""P-065: Guard-Check — läuft gerade ein Onboarding-Interview?
|
||||||
|
|
||||||
|
Returns True NUR bei aktiven Interview-Phasen:
|
||||||
|
IN_PROGRESS, AWAITING_ROOM, AWAITING_INTENT, AWAITING_TEST, PAUSED
|
||||||
|
|
||||||
|
Returns False bei: ACTIVE (abgeschlossen), COMPLETED, ERROR, NONE
|
||||||
|
|
||||||
|
Verwendung: Nachrichten-Guards, DDP-Event-Blocker,
|
||||||
|
Lazy-Onboarding-Trigger — überall wo Nachrichten blockiert
|
||||||
|
werden sollen, solange ein Interview läuft.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(is_running: bool, operator_room_id: str, reason: str)
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return (False, "", "no_multiroom_or_archivar")
|
||||||
|
|
||||||
|
from archivar.onboarding_state import OnboardingState
|
||||||
|
|
||||||
|
sm = getattr(self, '_onboarding_sm', None)
|
||||||
|
sm_running = False
|
||||||
|
sm_operator_room = ""
|
||||||
|
if sm is not None:
|
||||||
|
try:
|
||||||
|
sm_state = sm.state
|
||||||
|
sm_running = sm_state in (
|
||||||
|
OnboardingState.AWAITING_ROOM,
|
||||||
|
OnboardingState.AWAITING_INTENT,
|
||||||
|
OnboardingState.AWAITING_TEST,
|
||||||
|
OnboardingState.PAUSED,
|
||||||
|
)
|
||||||
|
sm_operator_room = getattr(sm._data, 'operator_room_id', '') or ''
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
stats_active = self.archivar._stats.get("onboarding_active", False)
|
||||||
|
is_running = sm_running or stats_active
|
||||||
|
operator_room_id = sm_operator_room or self._onboarding_state.get("operator_room_id", "")
|
||||||
|
reason = "sm_running" if sm_running else ("stats_active" if stats_active else "not_running")
|
||||||
|
return (is_running, operator_room_id, reason)
|
||||||
|
|
||||||
|
def _is_onboarding_completed(self) -> tuple:
|
||||||
|
"""P-065: ONBOARD:-Prefix-Erkennung — ist Onboarding abgeschlossen?
|
||||||
|
|
||||||
|
Returns True NUR bei: ACTIVE, COMPLETED
|
||||||
|
(Onboarding wurde durchlaufen, ONBOARD:-Prefix soll erkannt werden)
|
||||||
|
|
||||||
|
Returns False bei: IN_PROGRESS, AWAITING_ROOM, AWAITING_INTENT,
|
||||||
|
AWAITING_TEST, PAUSED, ERROR, NONE
|
||||||
|
|
||||||
|
Verwendung: ONBOARD:-Prefix-Erkennung nach Gateway-Restart,
|
||||||
|
wenn onboarding.yaml auf ACTIVE steht aber kein Interview läuft.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(is_completed: bool, operator_room_id: str, reason: str)
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return (False, "", "no_multiroom_or_archivar")
|
||||||
|
|
||||||
|
from archivar.onboarding_state import OnboardingState
|
||||||
|
|
||||||
|
sm = getattr(self, '_onboarding_sm', None)
|
||||||
|
sm_completed = False
|
||||||
|
sm_operator_room = ""
|
||||||
|
if sm is not None:
|
||||||
|
try:
|
||||||
|
sm_state = sm.state
|
||||||
|
sm_completed = sm_state in (
|
||||||
|
OnboardingState.ACTIVE,
|
||||||
|
)
|
||||||
|
sm_operator_room = getattr(sm._data, 'operator_room_id', '') or ''
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
operator_room_id = sm_operator_room or self._onboarding_state.get("operator_room_id", "")
|
||||||
|
reason = "sm_completed" if sm_completed else "not_completed"
|
||||||
|
return (sm_completed, operator_room_id, reason)
|
||||||
|
|
||||||
async def _reconnect_ddp(self) -> bool:
|
async def _reconnect_ddp(self) -> bool:
|
||||||
"""Bug 7: DDP-Reconnect mit M13 GC.
|
"""Bug 7: DDP-Reconnect mit M13 GC.
|
||||||
|
|
||||||
@@ -2290,7 +2386,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
if (
|
if (
|
||||||
_MULTIROOM()
|
_MULTIROOM()
|
||||||
and self.archivar is not None
|
and self.archivar is not None
|
||||||
and not self._is_onboarding_phase_active()[0]
|
and not self._is_onboarding_running()[0]
|
||||||
and room_type != "d" # P0-4: Nur DM ausschließen, "unknown" durchlassen
|
and room_type != "d" # P0-4: Nur DM ausschließen, "unknown" durchlassen
|
||||||
):
|
):
|
||||||
lazy_result = self.archivar.lazy_onboarding_check(
|
lazy_result = self.archivar.lazy_onboarding_check(
|
||||||
@@ -2320,7 +2416,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
if (
|
if (
|
||||||
_MULTIROOM()
|
_MULTIROOM()
|
||||||
and self.archivar is not None
|
and self.archivar is not None
|
||||||
and self._is_onboarding_phase_active()[0]
|
and self._is_onboarding_running()[0]
|
||||||
and room_type != "d"
|
and room_type != "d"
|
||||||
):
|
):
|
||||||
# P-054: operator_room_id mit Fallback-Kette
|
# P-054: operator_room_id mit Fallback-Kette
|
||||||
@@ -2491,10 +2587,14 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
logger.debug("[rocketchat] Error processing ARCHIVAR_CLARIFY response: %s", e)
|
logger.debug("[rocketchat] Error processing ARCHIVAR_CLARIFY response: %s", e)
|
||||||
|
|
||||||
# Auto-Onboarding: Wenn onboarding_active, fange alle relevanten Antworten ab
|
# Auto-Onboarding: Wenn onboarding_active, fange alle relevanten Antworten ab
|
||||||
# P-054: Verwende _is_onboarding_phase_active() statt nur
|
# P-065: Kombiniere _is_onboarding_running() (Interview läuft) +
|
||||||
# archivar._stats['onboarding_active'] — kombiniert SM-State
|
# _is_onboarding_completed() (ONBOARD:-Prefix nach Gateway-Restart).
|
||||||
# (onboarding.yaml) + In-Memory + Disk-State.
|
# Beide liefern operator_room_id — wir nehmen die erste nicht-leere.
|
||||||
is_onboarding_phase, _onb_op_room, _onb_reason = self._is_onboarding_phase_active()
|
is_running, running_op_room, running_reason = self._is_onboarding_running()
|
||||||
|
is_completed, completed_op_room, completed_reason = self._is_onboarding_completed()
|
||||||
|
is_onboarding_phase = is_running or is_completed
|
||||||
|
_onb_op_room = running_op_room or completed_op_room
|
||||||
|
_onb_reason = running_reason if is_running else (completed_reason if is_completed else "inactive")
|
||||||
if _MULTIROOM() and self.archivar is not None and is_onboarding_phase:
|
if _MULTIROOM() and self.archivar is not None and is_onboarding_phase:
|
||||||
stripped = text.strip()
|
stripped = text.strip()
|
||||||
# P-054: is_operator_room mit Fallback-Kette aus drei Quellen:
|
# P-054: is_operator_room mit Fallback-Kette aus drei Quellen:
|
||||||
|
|||||||
Reference in New Issue
Block a user