fix: P1 Quick-Reply Dedup — 3x-Bug + UX-Text-Anpassung
- outbound_gate.py: separates _quick_reply_sent Dict fuer Trigger-Raeume (nicht an _in_flight gebunden), mark_quick_reply_sent/quick_reply_already_sent - adapter.py: zentraler _maybe_send_quick_reply Helper mit Dedup + kontext- abhaengigem Text (same-room vs cross-room) - send() und send_clarify() rufen beide den Helper statt duplizierter Logik - Tests: 3 Gate-Tests (6.1-6.3) + 3 Integration-Tests (Dedup, Same-Room-Text, Cross-Room-Text) - Diff: 268 Zeilen (<300 F4-Limit)
This commit is contained in:
+46
-17
@@ -6537,26 +6537,43 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
self.ddp = None
|
||||
logger.info("[rocketchat] Disconnected")
|
||||
|
||||
# ── P1: Quick-Reply Dedup Helper ──────────────────────────────────
|
||||
# Zentraler Helper für Quick-Reply — verhindert 3x-Senden durch
|
||||
# Dedup-Flag im _TurnHandle und kontextabhängigen Text (same-room
|
||||
# vs cross-room).
|
||||
|
||||
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).
|
||||
) -> Optional[SendResult]:
|
||||
"""Sendet Quick-Reply wenn noch keiner für diesen Raum gesendet wurde.
|
||||
|
||||
P1 Fix: Verhindert dass Quick-Reply mehrfach gesendet wird wenn
|
||||
parallele Tasks aus _dispatch_agent gleichzeitig feuern.
|
||||
Dedup: quick_reply_already_sent prüft das Flag im _TurnHandle.
|
||||
Kontextabhängiger Text:
|
||||
- Same-Raum (active_room_id == gate_room_id): kein Raum-Name
|
||||
- Cross-Raum mit Name: „Ich antworte gerade in #RaumX — …"
|
||||
- Cross-Raum ohne Name: generischer Fallback
|
||||
|
||||
Returns:
|
||||
SendResult wenn Quick-Reply gesendet wurde, None wenn bereits
|
||||
gesendet (Dedup).
|
||||
"""
|
||||
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
|
||||
return None
|
||||
|
||||
# Kontextabhängiger Text
|
||||
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.'
|
||||
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.'
|
||||
text = (
|
||||
f"Ich antworte gerade in #{active_room_name} — "
|
||||
f"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.'
|
||||
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)
|
||||
@@ -6565,6 +6582,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
"[rocketchat] P5 V9.x: Quick-Reply sent to room=%s (blocked by %s)",
|
||||
gate_room_id[:8], active_room_name or "unknown",
|
||||
)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
|
||||
async def send(self, chat_id: str, content: str, reply_to: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None) -> SendResult:
|
||||
@@ -6656,13 +6674,18 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
decision = GateDecision(allow=False, reason="timeout")
|
||||
|
||||
if not decision.allow:
|
||||
# Quick-Reply: anderer Raum blockiert immer noch
|
||||
# Quick-Reply via zentralem Helper (Dedup + kontextabhängiger Text)
|
||||
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", "")
|
||||
await self._maybe_send_quick_reply(_gate_room_id, active_room, active_name)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
qr_result = await self._maybe_send_quick_reply(
|
||||
_gate_room_id, active_room, active_name
|
||||
)
|
||||
if qr_result is not None:
|
||||
return qr_result
|
||||
# Dedup: Quick-Reply bereits gesendet → trotzdem return
|
||||
return SendResult(success=True, message_id="quick_reply_dedup")
|
||||
# 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)
|
||||
_gate_acquired = (decision.reason == "gate_clear")
|
||||
@@ -7100,12 +7123,18 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
except asyncio.TimeoutError:
|
||||
decision = GateDecision(allow=False, reason="timeout")
|
||||
if not decision.allow:
|
||||
# Quick-Reply via zentralem Helper (Dedup + kontextabhängiger Text)
|
||||
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", "")
|
||||
await self._maybe_send_quick_reply(_gate_room_id, active_room, active_name)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
qr_result = await self._maybe_send_quick_reply(
|
||||
_gate_room_id, active_room, active_name
|
||||
)
|
||||
if qr_result is not None:
|
||||
return qr_result
|
||||
# Dedup: Quick-Reply bereits gesendet → trotzdem return
|
||||
return SendResult(success=True, message_id="quick_reply_dedup")
|
||||
# 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)
|
||||
_gate_acquired = (decision.reason == "gate_clear")
|
||||
|
||||
Reference in New Issue
Block a user