fix(HOTFIX): Widerspruch-Clarify nur nach tatsächlicher Auto-Route
Der Widerspruch-Clarify feuerte ohne vorherige Auto-Route, weil classify_and_route() detect_routing_contradiction() unbedingt aufrief — nur der Text wurde geprüft, nicht ob _recent_auto_routes[origin_room_id] existiert. MyTestBot1 zeigte den Clarify bei normalen Nachrichten und ersetzte damit den Butler-Modus. Fix: Widerspruch-Check nur wenn BEIDE Bedingungen erfüllt sind: 1. aktiver _recent_auto_routes[origin_room_id]-Eintrag (Auto-Route fand statt) 2. Text enthält Widerspruch-Muster - adapter_integration.py: set_recent_auto_routes() + Gate im Pre-Check - adapter.py: bindet _recent_auto_routes-Dict an den Handler - 2 neue Tests (kein Auto-Route → kein Clarify; mit Auto-Route → Clarify)
This commit is contained in:
@@ -1172,6 +1172,9 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
button_send_callback=self._send_archivar_buttons,
|
button_send_callback=self._send_archivar_buttons,
|
||||||
conversation_history=self._conversation_history,
|
conversation_history=self._conversation_history,
|
||||||
)
|
)
|
||||||
|
# HOTFIX: _recent_auto_routes-Dict an den Handler binden, damit die
|
||||||
|
# Widerspruch-Erkennung nur nach tatsächlicher Auto-Route feuert.
|
||||||
|
self.archivar.set_recent_auto_routes(self._recent_auto_routes)
|
||||||
else:
|
else:
|
||||||
self.archivar = None
|
self.archivar = None
|
||||||
self._conversation_history = None
|
self._conversation_history = None
|
||||||
|
|||||||
@@ -216,6 +216,13 @@ class ArchivarMessageHandler:
|
|||||||
# ── RoutingWiderspruchDetector ──────────────────────────────────
|
# ── RoutingWiderspruchDetector ──────────────────────────────────
|
||||||
self._feedback_detector = RoutingWiderspruchDetector()
|
self._feedback_detector = RoutingWiderspruchDetector()
|
||||||
|
|
||||||
|
# ── HOTFIX: Referenz auf die _recent_auto_routes-Dict des Adapters ──
|
||||||
|
# Wird via set_recent_auto_routes() gebunden. Die Widerspruch-Erkennung
|
||||||
|
# darf NUR feuern, wenn für den Ursprungsraum ein aktiver Auto-Route-
|
||||||
|
# Eintrag existiert (eine Auto-Route hat tatsächlich stattgefunden).
|
||||||
|
# Ohne Eintrag wird der Widerspruch-Check komplett übersprungen.
|
||||||
|
self._recent_auto_routes: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
# ── RoomMap Loading ─────────────────────────────────────────────────
|
# ── RoomMap Loading ─────────────────────────────────────────────────
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -403,7 +410,18 @@ class ArchivarMessageHandler:
|
|||||||
# damit der Adapter einen Clarify (2 Buttons) auslöst statt zu routen.
|
# damit der Adapter einen Clarify (2 Buttons) auslöst statt zu routen.
|
||||||
# Der Router selbst kennt den Widerspruch nicht — er hat bereits
|
# Der Router selbst kennt den Widerspruch nicht — er hat bereits
|
||||||
# eine normale RoutingDecision produziert. Wir überschreiben sie.
|
# eine normale RoutingDecision produziert. Wir überschreiben sie.
|
||||||
contradiction = self.detect_routing_contradiction(text, origin_room_id)
|
# ── HOTFIX: Widerspruch-Check NUR nach tatsächlicher Auto-Route ──
|
||||||
|
# Der Widerspruch-Clarify ist eine Reaktion auf eine Auto-Route, KEIN
|
||||||
|
# Ersatz für den Butler-Modus. Er darf NUR feuern, wenn BEIDE Bedingungen
|
||||||
|
# erfüllt sind:
|
||||||
|
# 1. Es gibt einen aktiven _recent_auto_routes[origin_room_id]-Eintrag
|
||||||
|
# (eine Auto-Route hat tatsächlich stattgefunden).
|
||||||
|
# 2. Der Text enthält ein Widerspruch-Muster.
|
||||||
|
# Ist Bedingung 1 NICHT erfüllt (keine vorherige Auto-Route), wird der
|
||||||
|
# Widerspruch-Check komplett übersprungen → normale Verarbeitung.
|
||||||
|
contradiction = None
|
||||||
|
if origin_room_id and origin_room_id in self._recent_auto_routes:
|
||||||
|
contradiction = self.detect_routing_contradiction(text, origin_room_id)
|
||||||
if contradiction is not None:
|
if contradiction is not None:
|
||||||
logger.info(
|
logger.info(
|
||||||
"V8.5: Routing-Widerspruch in classify_and_route — "
|
"V8.5: Routing-Widerspruch in classify_and_route — "
|
||||||
@@ -1264,6 +1282,21 @@ class ArchivarMessageHandler:
|
|||||||
"""
|
"""
|
||||||
self._presence_engine = engine
|
self._presence_engine = engine
|
||||||
|
|
||||||
|
def set_recent_auto_routes(self, recent_auto_routes: Dict[str, Dict[str, Any]]) -> None:
|
||||||
|
"""HOTFIX: Binde die _recent_auto_routes-Dict des Adapters an den Handler.
|
||||||
|
|
||||||
|
Die Widerspruch-Erkennung (detect_routing_contradiction) darf NUR feuern,
|
||||||
|
wenn für den Ursprungsraum ein aktiver Auto-Route-Eintrag existiert —
|
||||||
|
d.h. eine Auto-Route hat tatsächlich stattgefunden. Ohne diesen Eintrag
|
||||||
|
wird der Widerspruch-Check komplett übersprungen und die Nachricht normal
|
||||||
|
verarbeitet (Butler-Modus, Keyword-Matching, etc.).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
recent_auto_routes: Die Dict des Adapters
|
||||||
|
``{origin_room_id: {target_room, topic, timestamp, ...}}``.
|
||||||
|
"""
|
||||||
|
self._recent_auto_routes = recent_auto_routes
|
||||||
|
|
||||||
def bind_outbound_gate(self, gate) -> None:
|
def bind_outbound_gate(self, gate) -> None:
|
||||||
"""P5 V9.x: Bindet das OutboundGate für Parallel-Stream-Schutz.
|
"""P5 V9.x: Bindet das OutboundGate für Parallel-Stream-Schutz.
|
||||||
|
|
||||||
|
|||||||
@@ -333,3 +333,102 @@ class TestAutoRouteContradictionScenarios:
|
|||||||
# 2. Nächste Nachricht OHNE Keyword → kein Widerspruch
|
# 2. Nächste Nachricht OHNE Keyword → kein Widerspruch
|
||||||
r2 = archivar._feedback_detector.detect("Wie ist das Wetter heute?")
|
r2 = archivar._feedback_detector.detect("Wie ist das Wetter heute?")
|
||||||
assert r2 is None
|
assert r2 is None
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# Test 5: HOTFIX — Widerspruch-Clarify NUR nach tatsächlicher Auto-Route
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
|
||||||
|
class TestContradictionRequiresPriorAutoRoute:
|
||||||
|
"""Der Widerspruch-Clarify darf NUR nach einer tatsächlichen Auto-Route feuern.
|
||||||
|
|
||||||
|
HOTFIX: classify_and_route() überspringt den Widerspruch-Check komplett,
|
||||||
|
wenn für den Ursprungsraum KEIN aktiver _recent_auto_routes-Eintrag existiert.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _make_handler(self, tmp_path):
|
||||||
|
"""Handler mit echtem Detector + Mock-Router, der normal routet."""
|
||||||
|
from plugin.archivar.adapter_integration import ArchivarMessageHandler
|
||||||
|
from plugin.archivar.router import RoutingDecision
|
||||||
|
|
||||||
|
handler = ArchivarMessageHandler.__new__(ArchivarMessageHandler)
|
||||||
|
handler._initialized = True
|
||||||
|
handler._feedback_detector = _make_detector()
|
||||||
|
handler._recent_auto_routes = {}
|
||||||
|
handler._stats = {
|
||||||
|
"total": 0, "classified": 0, "contradiction": 0, "errors": 0,
|
||||||
|
}
|
||||||
|
handler._state = _make_state(tmp_path)
|
||||||
|
handler._room_map = MagicMock()
|
||||||
|
handler._room_map.rooms = {}
|
||||||
|
handler._doc_store = None
|
||||||
|
# Callbacks für den normalen Move-Request-Pfad (Butler-Modus).
|
||||||
|
handler._send_callback = AsyncMock(return_value=True)
|
||||||
|
handler._button_send_callback = AsyncMock(return_value=True)
|
||||||
|
|
||||||
|
# Mock-Router: liefert eine normale (nicht-Widerspruch) Decision.
|
||||||
|
normal_decision = RoutingDecision(
|
||||||
|
category="work_order",
|
||||||
|
target_room="room_target",
|
||||||
|
confidence=0.9,
|
||||||
|
stay_in_room=False,
|
||||||
|
move_request_sent=True,
|
||||||
|
)
|
||||||
|
handler._router = MagicMock()
|
||||||
|
handler._router.route = AsyncMock(return_value=normal_decision)
|
||||||
|
return handler
|
||||||
|
|
||||||
|
def test_no_prior_auto_route_no_clarify(self, tmp_path):
|
||||||
|
"""Nachricht OHNE vorherige Auto-Route + 'passt hier her' → KEIN Clarify.
|
||||||
|
|
||||||
|
Der Text enthält ein Widerspruch-Muster ('passt hier her'), aber es gibt
|
||||||
|
keinen _recent_auto_routes-Eintrag → der Widerspruch-Check wird übersprungen
|
||||||
|
und die Nachricht normal verarbeitet (kein is_contradiction).
|
||||||
|
"""
|
||||||
|
handler = self._make_handler(tmp_path)
|
||||||
|
origin_room = "room_origin"
|
||||||
|
|
||||||
|
# Kein Auto-Route-Eintrag vorhanden
|
||||||
|
assert origin_room not in handler._recent_auto_routes
|
||||||
|
|
||||||
|
decision = asyncio.run(
|
||||||
|
handler.classify_and_route(
|
||||||
|
"Nein, es passt hier her", origin_room_id=origin_room
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# KEIN Widerspruch → normale Verarbeitung
|
||||||
|
assert decision.is_contradiction is False
|
||||||
|
assert decision.contradiction_result is None
|
||||||
|
assert decision.category == "work_order"
|
||||||
|
assert handler._stats.get("contradiction", 0) == 0
|
||||||
|
|
||||||
|
def test_with_prior_auto_route_clarify_fires(self, tmp_path):
|
||||||
|
"""Nachricht MIT vorheriger Auto-Route + 'passt hier her' → Clarify.
|
||||||
|
|
||||||
|
Gegenprobe: existiert ein _recent_auto_routes-Eintrag, feuert der
|
||||||
|
Widerspruch-Check und setzt is_contradiction=True.
|
||||||
|
"""
|
||||||
|
handler = self._make_handler(tmp_path)
|
||||||
|
origin_room = "room_origin"
|
||||||
|
|
||||||
|
# Auto-Route hat tatsächlich stattgefunden
|
||||||
|
handler._recent_auto_routes[origin_room] = {
|
||||||
|
"origin_room": origin_room,
|
||||||
|
"target_room": "room_target",
|
||||||
|
"topic": "dokumentation",
|
||||||
|
"timestamp": 1234567890.0,
|
||||||
|
"source": "auto",
|
||||||
|
}
|
||||||
|
|
||||||
|
decision = asyncio.run(
|
||||||
|
handler.classify_and_route(
|
||||||
|
"Nein, es passt hier her", origin_room_id=origin_room
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert decision.is_contradiction is True
|
||||||
|
assert decision.contradiction_result is not None
|
||||||
|
assert decision.category == "contradiction"
|
||||||
|
assert handler._stats.get("contradiction", 0) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user