fix: P1 Quick-Reply Dedup — verhindert 3x-Sendung + kontextabhängiger UX-Text
BUG 1: Quick-Reply wurde 3x gesendet (send(), send_clarify(), parallele acquires) - _quick_reply_sent Set in OutboundGate für raumübergreifenden Dedup - _maybe_send_quick_reply Helper in adapter.py (eine zentrale Stelle) - Beide Call-Sites (send + send_clarify) durch Helper ersetzt BUG 2: Zirkulärer Quick-Reply-Text bei Same-Raum-Trigger - Same-Raum: 'Ich bin gerade beschäftigt — einen Moment bitte...' (ohne Raum) - Cross-Raum: 'Ich antworte gerade in #Raum — einen Moment bitte...' (mit Raum) Tests: 10 Gate-Tests + 3 Integration-Tests (13/13 grün)
This commit is contained in:
+33
-24
@@ -6537,6 +6537,35 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
self.ddp = None
|
||||
logger.info("[rocketchat] Disconnected")
|
||||
|
||||
async def _maybe_send_quick_reply(
|
||||
self, gate_room_id: str, active_room_id: Optional[str], active_room_name: str
|
||||
) -> None:
|
||||
"""Sendet Quick-Reply wenn noch nicht für diesen Raum gesendet (Dedup).
|
||||
|
||||
P1 Fix: Verhindert dass Quick-Reply mehrfach gesendet wird wenn
|
||||
parallele Tasks aus _dispatch_agent gleichzeitig feuern.
|
||||
"""
|
||||
if not hasattr(self, '_outbound_gate') or self._outbound_gate is None:
|
||||
return
|
||||
if self._outbound_gate.quick_reply_already_sent(gate_room_id):
|
||||
return
|
||||
|
||||
same_room = (active_room_id is not None and active_room_id == gate_room_id)
|
||||
if same_room:
|
||||
text = 'Ich bin gerade beschäftigt — einen Moment bitte, ich bin gleich bei dir.'
|
||||
elif active_room_name:
|
||||
text = f'Ich antworte gerade in #{active_room_name} — einen Moment bitte, ich bin gleich bei dir.'
|
||||
else:
|
||||
text = 'Ich antworte gerade in einem anderen Raum — einen Moment bitte, ich bin gleich bei dir.'
|
||||
|
||||
await self._post_message_unlocked(gate_room_id, text)
|
||||
self._outbound_gate.mark_quick_reply_sent(gate_room_id)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
logger.info(
|
||||
"[rocketchat] P5 V9.x: Quick-Reply sent to room=%s (blocked by %s)",
|
||||
gate_room_id[:8], active_room_name or "unknown",
|
||||
)
|
||||
|
||||
async def send(self, chat_id: str, content: str, reply_to: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None) -> SendResult:
|
||||
if not self.rest.auth_token:
|
||||
@@ -6631,20 +6660,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
active_room = self._outbound_gate.active_room_id
|
||||
active_name = ""
|
||||
if active_room and active_room in self._room_info:
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
quick_reply_text = (
|
||||
f"Ich antworte gerade in #{active_name} — "
|
||||
f"einen Moment bitte, ich bin gleich bei dir."
|
||||
) if active_name else (
|
||||
"Ich antworte gerade in einem anderen Raum — "
|
||||
"einen Moment bitte, ich bin gleich bei dir."
|
||||
)
|
||||
await self._post_message_unlocked(_gate_room_id, quick_reply_text)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
logger.info(
|
||||
"[rocketchat] P5 V9.x: Quick-Reply sent to room=%s (blocked by %s)",
|
||||
_gate_room_id[:8], active_name,
|
||||
)
|
||||
active_name = self._room_info[active_room].get("name", "")
|
||||
await self._maybe_send_quick_reply(_gate_room_id, active_room, active_name)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
# Fell through: decision.allow is True — track if WE created the entry
|
||||
# (gate_clear = we own it; same_room_same_token = someone else owns it)
|
||||
@@ -7086,16 +7103,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
active_room = self._outbound_gate.active_room_id
|
||||
active_name = ""
|
||||
if active_room and active_room in self._room_info:
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
quick_reply_text = (
|
||||
f"Ich antworte gerade in #{active_name} — "
|
||||
f"einen Moment bitte, ich bin gleich bei dir."
|
||||
) if active_name else (
|
||||
"Ich antworte gerade in einem anderen Raum — "
|
||||
"einen Moment bitte, ich bin gleich bei dir."
|
||||
)
|
||||
await self._post_message_unlocked(_gate_room_id, quick_reply_text)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
active_name = self._room_info[active_room].get("name", "")
|
||||
await self._maybe_send_quick_reply(_gate_room_id, active_room, active_name)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
# Fell through: decision.allow is True — track if WE created the entry
|
||||
# (gate_clear = we own it; same_room_same_token = someone else owns it)
|
||||
|
||||
Reference in New Issue
Block a user