fix: V8.2.1 — 7 Befunde (A2 Caller, A3 Persistenz, A4 Strategie-Block, Tests, Feature-Flag, conftest, runbook)

Befund 1 (P0): A2 Dead-Code — _should_trigger_nachklaerung() in adapter.py
Button-Response-Handler angebunden. stay_once (Button 3) triggert jetzt
Nachklärung mit Strategie-Buttons. ARCHIVAR_CLARIFY-Responses werden
verarbeitet (Strategie-Thema → Ring-Zustand "jetzt", ANDERER GRUND →
normales Lernen).

Befund 2 (P0): A3 Persistenz-Bug — _stay_counts und _keyword_last_matched
in RoomMap.save() und _from_dict() serialisiert. Tracking-Felder
überleben Gateway-Restart.

Befund 3 (P1): A4 Strategie-Block — _is_strategie_topic() im DM-Pfad
des Routers. Strategie-Themen im DM → stay_in_room (kein Routing,
kein Lernen).

Befund 4 (P1): Tests — 8 neue echte Integrationstests (TestV821A2,
TestV821A3, TestV821A4). 27/27 grün.

Befund 5 (P2): ARCHIVAR_STRATEGY_AUTO_DETECT env var in config.py,
Default false (Rainer Auflage P1).

Befund 6 (P2): conftest.py mit temp_room_map_path und temp_state_path
Fixtures für saubere Pfad-Tests.

Befund 7 (P2): docs/deployment-runbook.md mit .45 Bare-VM Schritten
inkl. room-map.json Pfad-Korrektur.
This commit is contained in:
Bernd (Hermes)
2026-07-14 21:27:32 +02:00
parent 39a5041621
commit de930a1227
7 changed files with 590 additions and 4 deletions
+61 -3
View File
@@ -1218,8 +1218,9 @@ class RocketChatAdapter(BasePlatformAdapter):
msg_obj.get("actions") and
msg_obj.get("params", {}).get("triggerSender") and
msg_obj.get("params", {}).get("payload"))
or (text and "::" in text and not text.startswith("CLARIFY:") and text.split("::", 1)[0].strip() != "")
or (text and "::" in text and not text.startswith("CLARIFY:") and not text.startswith("ARCHIVAR_CLARIFY:") and text.split("::", 1)[0].strip() != "")
or (text and text.startswith("CLARIFY:"))
or (text and text.startswith("ARCHIVAR_CLARIFY:"))
)
# Check for CLARIFY button responses
@@ -1315,6 +1316,8 @@ class RocketChatAdapter(BasePlatformAdapter):
# ── CLARIFY Response Handling ───────────────────────────────────
# Handle CLARIFY button responses: CLARIFY:<clarify_id>:<choice> or CLARIFY:<clarify_id>:other
# V8.2.1 A2: Handle ARCHIVAR_CLARIFY (Nachklärung) responses
is_archivar_clarify = text.startswith("ARCHIVAR_CLARIFY:") if text else False
if is_clarify_response and text.startswith("CLARIFY:"):
routing_counter.increment('clarify_answer_bypass')
logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id)
@@ -1376,6 +1379,48 @@ class RocketChatAdapter(BasePlatformAdapter):
except Exception as e:
logger.debug("[rocketchat] Error processing CLARIFY response: %s", e)
# ── V8.2.1 A2: ARCHIVAR_CLARIFY (Nachklärung) Response Handling ──
if is_archivar_clarify:
routing_counter.increment('archivar_clarify_bypass')
logger.info("ROUTING BYPASS: reason=archivar_clarify_bypass, origin_room=%s", room_id)
try:
# Format: ARCHIVAR_CLARIFY:<choice>
parts = text.split(":", 2)
if len(parts) >= 2:
choice = parts[1].strip()
strategie_topics = {"absprache", "planung", "strategie", "entscheidung"}
if choice in strategie_topics:
# Strategie-Thema → Ring-Zustand 'jetzt' (30 Min), KEIN Lernen
if _MULTIROOM() and self.archivar is not None:
self.archivar._state.set_ring_state(room_id, "jetzt", ttl_minutes=30)
logger.info(
"[rocketchat] V8.2.1 A2: Strategie-Modus aktiviert — "
"topic=%s, room=%s, ring=jetzt (30 Min)",
choice, room_id[:8],
)
await self._post_message_with_retry(
room_id,
f"🎯 Verstanden — '{choice}' ist ein Strategie-Thema. "
"Ich bleibe hier und lerne nichts dazu."
)
elif choice == "anderer_grund":
# ANDERER GRUND → normales Lernen
if _MULTIROOM() and self.archivar is not None:
logger.info(
"[rocketchat] V8.2.1 A2: ANDERER GRUND — "
"normales Lernen in room %s",
room_id[:8],
)
await self._post_message_with_retry(
room_id,
"👍 Alles klar — ich lerne daraus fürs nächste Mal."
)
else:
logger.warning("[rocketchat] Unknown ARCHIVAR_CLARIFY choice: %s", choice)
return # Nachricht verarbeitet — keine weitere Verarbeitung
except Exception as e:
logger.debug("[rocketchat] Error processing ARCHIVAR_CLARIFY response: %s", e)
# Auto-Onboarding: Wenn onboarding_active, fange alle relevanten Antworten ab
if _MULTIROOM() and self.archivar is not None and self.archivar._stats.get("onboarding_active", False):
stripped = text.strip()
@@ -1487,10 +1532,23 @@ class RocketChatAdapter(BasePlatformAdapter):
await self._post_message_with_retry(room_id, "🔒 Verstanden — dieser Raum wird nicht mehr automatisch geroutet. (Gilt dauerhaft)")
feedback_type = "never"
else:
# 3️⃣ Hier bleiben → Antwort im Ursprungsraum (nur diesmal, kein Sticky)
# Bug 4 fix: Track stay count — nach 3× stay in 10 Min → auto-promote zu never_route
# 3️⃣ Nur diesmal → Antwort im Ursprungsraum (nur diesmal, kein Sticky)
# V8.2.1 A2: Nach stay_once → Nachklärung mit Strategie-Buttons
await self._post_message_with_retry(room_id, "👍 Bleiben hier — ich kümmere mich drum.")
feedback_type = "stay"
# V8.2.1 A2: Nachklärung bei stay_once — Strategie-Buttons senden
if _MULTIROOM() and self.archivar is not None:
if self.archivar._should_trigger_nachklaerung("stay_once"):
nachklaerung_buttons = self.archivar._get_nachklaerung_buttons()
await self._send_archivar_buttons(
room_id,
nachklaerung_buttons["text"],
{"actions": nachklaerung_buttons["actions"]},
)
logger.info(
"[rocketchat] V8.2.1 A2: Nachklärung gesendet — "
"Strategie-Buttons in room %s", room_id[:8],
)
# Stay-Counter: Wenn der User 3× in 10 Min "Hier bleiben" klickt,
# wird der Raum automatisch auf "never_route" gesetzt.
# P1-3: stay_tracker ist jetzt persistent in ArchivarState