fix(P-108c): Send-Pfad-Härtung — Antwort-Ziel MUSS Origin-Raum sein
Root Cause (Rainer-Review t_cfe5d9d6): send()/send_clarify() nutzten
_THEMATIC_TARGET_ROOM als Prio-2-Zielraum. Bei Stream-Retry-Subtasks /
Token-Mismatch fielen Prio 0 (_CURRENT_ORIGIN_ROOM) und Prio 1
(_room_context-TTL) durch -> Prio 2 griff -> Antwort im falschen Raum
(Andreas-Fund 29.08. 10:50: ProtonBridge-Frage 69f8beae -> Antwort
6a19b0ff).
Fix:
1. send() + send_clarify(): _THEMATIC_TARGET_ROOM (Prio 2) entfernt für
user-basierte Antworten. Fallback ist jetzt der letzte bekannte Raum
des Users (user_rooms-Map) — NIEMALS der Archivar-Sticky-Target.
2. B2-Branch (Z.4122-4139): _THEMATIC_TARGET_ROOM.set('') +
_CURRENT_ORIGIN_ROOM.set(room_id) explizit — Sticky-Reset bei
Origin-Gewinnung (Defense-in-Depth).
Tests: test_p108c_send_path.py (5 Tests, RED->GREEN validiert).
PoC-Test 1 reproduzierte den Bug exakt (Log 'send via Archivar target:
user:testuser -> room_b') BEVOR der Fix griff.
This commit is contained in:
+46
-40
@@ -4137,6 +4137,14 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# (Setter B) den Sticky NICHT ungeprüft erneuert.
|
||||
self._sticky_bypassed_this_turn = True
|
||||
_should_classify = False
|
||||
# P-108c: Defense-in-Depth — Sticky-Reset bei
|
||||
# Origin-Gewinnung. _THEMATIC_TARGET_ROOM darf keinen
|
||||
# stale Wert aus einem früheren Turn tragen, sonst
|
||||
# greift send() Prio 2 und leitet die Antwort in den
|
||||
# falschen Raum. _CURRENT_ORIGIN_ROOM explizit auf den
|
||||
# Origin-Raum setzen (konsistent mit Stay-Here-Logik).
|
||||
_THEMATIC_TARGET_ROOM.set("")
|
||||
_CURRENT_ORIGIN_ROOM.set(room_id)
|
||||
else:
|
||||
# Thema matcht → Sticky greift
|
||||
# V8.1.1 R1: Catch-All-Guard — nicht in Catch-All-Raum auto-routen
|
||||
@@ -8778,28 +8786,29 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
routing_counter.increment('contextvar_reset_fallback')
|
||||
logger.info("[rocketchat] send via _room_context fallback: %s → %s", chat_id, real_room_id)
|
||||
else:
|
||||
# Priority 1: Archivar-Kontext — nur für proaktive Nachrichten
|
||||
# ohne vorherige Frage (kein _CURRENT_ORIGIN_ROOM gesetzt).
|
||||
thematic_target = _THEMATIC_TARGET_ROOM.get()
|
||||
if thematic_target:
|
||||
real_room_id = thematic_target
|
||||
logger.debug("[rocketchat] send via Archivar target: %s → %s", chat_id, real_room_id)
|
||||
# P-108c: _THEMATIC_TARGET_ROOM (Archivar-Sticky-Target) darf
|
||||
# bei user-basierten Antworten NIEMALS als Zielraum greifen.
|
||||
# Der Wert kann aus einem früheren Turn (Feature-97) oder
|
||||
# einem fremden Task-Kontext stammen und würde die Antwort
|
||||
# in den falschen Raum leiten (Andreas-Fund 29.08. 10:50).
|
||||
# Prio 2 ist NUR für DIREKTE Raum-Chats / proaktive Nachrichten
|
||||
# gedacht — bei user:*-Antworten ist der letzte bekannte Raum
|
||||
# des Users (user_rooms-Map) die korrekte Fallback-Quelle.
|
||||
# Priority 2: proaktive Nachricht — use most recent room for this user
|
||||
rooms = self._user_rooms.get(chat_id, [])
|
||||
if rooms:
|
||||
real_room_id = rooms[-1] # last room user was active in
|
||||
logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id)
|
||||
else:
|
||||
# Priority 2: proaktive Nachricht — use most recent room for this user
|
||||
rooms = self._user_rooms.get(chat_id, [])
|
||||
if rooms:
|
||||
real_room_id = rooms[-1] # last room user was active in
|
||||
logger.debug("[rocketchat] send via user_map (proactive): %s → %s", chat_id, real_room_id)
|
||||
# Fallback: try to find any room with recent activity involving this user
|
||||
logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id)
|
||||
fallback_room = self._find_fallback_room_for_user(chat_id)
|
||||
if fallback_room:
|
||||
real_room_id = fallback_room
|
||||
logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id)
|
||||
else:
|
||||
# Fallback: try to find any room with recent activity involving this user
|
||||
logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id)
|
||||
fallback_room = self._find_fallback_room_for_user(chat_id)
|
||||
if fallback_room:
|
||||
real_room_id = fallback_room
|
||||
logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id)
|
||||
else:
|
||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
||||
|
||||
# ── Minimal-Fix: Parse [[BUTTONS:...]] markup from agent response text ──
|
||||
# This allows the agent to request buttons by embedding markup in its
|
||||
@@ -9193,28 +9202,25 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
routing_counter.increment('contextvar_reset_fallback')
|
||||
logger.info("[rocketchat] send_clarify via _room_context fallback: %s → %s", chat_id, real_room_id)
|
||||
else:
|
||||
# Priority 1: Archivar-Kontext — nur für proaktive Nachrichten
|
||||
# ohne vorherige Frage (kein _CURRENT_ORIGIN_ROOM gesetzt).
|
||||
thematic_target = _THEMATIC_TARGET_ROOM.get()
|
||||
if thematic_target:
|
||||
real_room_id = thematic_target
|
||||
logger.debug("[rocketchat] send_clarify via Archivar target: %s → %s", chat_id, real_room_id)
|
||||
# P-108c: _THEMATIC_TARGET_ROOM darf bei user-basierten
|
||||
# Clarify-Antworten NIEMALS als Zielraum greifen (gleiche
|
||||
# Bug-Klasse wie send()). Fallback ist der letzte bekannte
|
||||
# Raum des Users.
|
||||
# Priority 2: proactive message — use most recent room for this user
|
||||
rooms = self._user_rooms.get(chat_id, [])
|
||||
if rooms:
|
||||
real_room_id = rooms[-1] # last room user was active in
|
||||
logger.debug("[rocketchat] send_clarify via user_map (proactive): %s → %s", chat_id, real_room_id)
|
||||
else:
|
||||
# Priority 2: proactive message — use most recent room for this user
|
||||
rooms = self._user_rooms.get(chat_id, [])
|
||||
if rooms:
|
||||
real_room_id = rooms[-1] # last room user was active in
|
||||
logger.debug("[rocketchat] send_clarify via user_map (proactive): %s → %s", chat_id, real_room_id)
|
||||
# Fallback: try to find any room with recent activity involving this user
|
||||
logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id)
|
||||
fallback_room = self._find_fallback_room_for_user(chat_id)
|
||||
if fallback_room:
|
||||
real_room_id = fallback_room
|
||||
logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id)
|
||||
else:
|
||||
# Fallback: try to find any room with recent activity involving this user
|
||||
logger.warning("[rocketchat] No mapped room for %s, attempting fallback", chat_id)
|
||||
fallback_room = self._find_fallback_room_for_user(chat_id)
|
||||
if fallback_room:
|
||||
real_room_id = fallback_room
|
||||
logger.info("[rocketchat] Using fallback room %s for %s", fallback_room, chat_id)
|
||||
else:
|
||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
||||
logger.error("[rocketchat] No real room for %s, cannot send", chat_id)
|
||||
return SendResult(success=False, error=f"No real room for virtual chat_id {chat_id}")
|
||||
|
||||
# Render full option text in the message body so users
|
||||
# can read long choices that would be truncated in buttons.
|
||||
|
||||
Reference in New Issue
Block a user