P-045: CLARIFY — 2 Root-Cause-Fixes (No resolved room + pending_questions-Leak)
PROBLEM 1 — "No resolved room for user:andreas":
_set_room_context_origin() wurde für JEDE eingehende Nachricht aufgerufen,
inklusive CLARIFY-Button-Klicks. Das generierte ein NEUES Task-Token und
überschrieb _room_context. Der Agent-Task hatte das alte Token via
copy_context() eingefroren → Token-Mismatch in send() → ContextVar-Skip
→ "No resolved room" Fehler.
Fix: _set_room_context_origin() wird für CLARIFY/ARCHIVAR_CLARIFY responses
NICHT mehr aufgerufen. Der Agent-Task behält seinen korrekten Kontext.
PROBLEM 2 — pending_questions wird nicht geleert:
Zwei Teil-Ursachen:
a) Off-by-one: idx = int(choice) statt idx = int(choice) - 1.
Button-Payload verwendet i+1 (1-basiert), aber der Handler nutzte
den Wert direkt als 0-basierten Index. Für choice "5" bei 5 Optionen
war idx=5 out-of-bounds → resolved_text fiel auf Fallback zurück.
b) _set_room_context_origin() überschrieb den Kontext BEVOR der
Cleanup-Code lief — der room_id aus der Nachricht war korrekt,
aber der Kontext war bereits korrumpiert.
Fix a: idx = int(choice) - 1 (1-basiert → 0-basiert)
Fix b: Durch Problem-1-Fix bereits behoben (kein _room_context-Overwrite)
ZUSÄTZLICH:
- is_archivar_clarify wird jetzt früh in _process_incoming gesetzt
(statt doppelt definiert zu werden)
- Debug-Logging für _clarify_room + pending_questions Cleanup
- Debug-Logging in send_clarify() für _clarify_room Mapping
This commit is contained in:
+39
-2
@@ -2202,6 +2202,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
|
||||
# Check for CLARIFY button responses
|
||||
is_clarify_response = text.startswith("CLARIFY:") if text else False
|
||||
# P-045: ARCHIVAR_CLARIFY detection early — needed for _room_context guard
|
||||
is_archivar_clarify = text.startswith("ARCHIVAR_CLARIFY:") if text else False
|
||||
|
||||
msg_id = msg_obj.get("_id", "")
|
||||
room_id = msg_obj.get("rid", "")
|
||||
@@ -2299,7 +2301,12 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# ── P1: _room_context als persistenter Fallback (Stream-Retry ContextVar-Reset) ──
|
||||
# ContextVars sind asyncio-task-lokal — bei Stream-Retries in neuem Task
|
||||
# geht _CURRENT_ORIGIN_ROOM verloren. _room_context (global dict) überlebt.
|
||||
# P-045: CLARIFY/ARCHIVAR_CLARIFY button responses dürfen _room_context
|
||||
# NICHT überschreiben. Der Agent-Task hat den korrekten Kontext bereits
|
||||
# via copy_context() eingefroren. Ein neues Token würde den Token-Match
|
||||
# in send() brechen → "No resolved room" Fehler.
|
||||
virtual_chat_id = f"user:{username}"
|
||||
if not is_clarify_response and not is_archivar_clarify:
|
||||
_set_room_context_origin(virtual_chat_id, room_id)
|
||||
|
||||
# ── V9: PresenceEngine — Hooks übernehmen das Status-Management ──
|
||||
@@ -2412,7 +2419,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# P-013: Button-Detection VOR CLARIFY-Filter — is_clarify_response
|
||||
# (CLARIFY: prefix) wird weiterhin zuerst geprüft, dieser Block
|
||||
# fängt NUR plain-digit Texte ab.
|
||||
is_archivar_clarify = text.startswith("ARCHIVAR_CLARIFY:") if text else False
|
||||
# P-045: is_archivar_clarify jetzt früh in _process_incoming gesetzt (line ~2206)
|
||||
if not is_clarify_response and not is_archivar_clarify:
|
||||
stripped = text.strip()
|
||||
if stripped.isdigit() and room_id in self._room_clarify:
|
||||
@@ -2441,9 +2448,21 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if _clarify_room_id:
|
||||
_affected_rooms.append(_clarify_room_id)
|
||||
# Clean up pending_questions — Clarify is resolved
|
||||
# P-045: Debug-Logging für Root-Cause-Analyse
|
||||
logger.debug(
|
||||
"[rocketchat] P-045 CLARIFY plain-digit cleanup: clarify_id=%s, room_id=%s, "
|
||||
"_affected_rooms=%s, _clarify_room_id=%s, "
|
||||
"pending_before=%s",
|
||||
clarify_id, room_id, _affected_rooms, _clarify_room_id,
|
||||
sorted(self._rooms_with_pending_questions),
|
||||
)
|
||||
for _rid in _affected_rooms:
|
||||
self._rooms_with_pending_questions.discard(_rid)
|
||||
self._rooms_with_pending_questions.discard(room_id)
|
||||
logger.debug(
|
||||
"[rocketchat] P-045 CLARIFY plain-digit cleanup done: pending_after=%s",
|
||||
sorted(self._rooms_with_pending_questions),
|
||||
)
|
||||
try:
|
||||
from tools.clarify_gateway import resolve_gateway_clarify
|
||||
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
||||
@@ -2494,7 +2513,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
return
|
||||
elif choice.isdigit():
|
||||
# Numeric choice → resolve the clarify immediately
|
||||
idx = int(choice)
|
||||
# P-045: choice is 1-based (button payload uses i+1), convert to 0-based index
|
||||
idx = int(choice) - 1
|
||||
resolved_text: Optional[str] = None
|
||||
try:
|
||||
from tools.clarify_gateway import _entries as _clarify_entries
|
||||
@@ -2520,9 +2540,21 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if _clarify_room_id:
|
||||
_affected_rooms.append(_clarify_room_id)
|
||||
# Clean up pending_questions — Clarify is resolved
|
||||
# P-045: Debug-Logging für Root-Cause-Analyse
|
||||
logger.debug(
|
||||
"[rocketchat] P-045 CLARIFY cleanup: clarify_id=%s, room_id=%s, "
|
||||
"_affected_rooms=%s, _clarify_room_id=%s, "
|
||||
"pending_before=%s",
|
||||
clarify_id, room_id, _affected_rooms, _clarify_room_id,
|
||||
sorted(self._rooms_with_pending_questions),
|
||||
)
|
||||
for _rid in _affected_rooms:
|
||||
self._rooms_with_pending_questions.discard(_rid)
|
||||
self._rooms_with_pending_questions.discard(room_id)
|
||||
logger.debug(
|
||||
"[rocketchat] P-045 CLARIFY cleanup done: pending_after=%s",
|
||||
sorted(self._rooms_with_pending_questions),
|
||||
)
|
||||
try:
|
||||
from tools.clarify_gateway import resolve_gateway_clarify
|
||||
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
||||
@@ -7613,6 +7645,11 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# P-044: Reverse mapping for robust cleanup
|
||||
self._clarify_room = getattr(self, '_clarify_room', {})
|
||||
self._clarify_room[clarify_id] = real_room_id
|
||||
logger.debug(
|
||||
"[rocketchat] P-045 send_clarify: _clarify_room[%s] = %s, "
|
||||
"_room_clarify[%s] = %s",
|
||||
clarify_id, real_room_id, real_room_id, clarify_id,
|
||||
)
|
||||
|
||||
# For "Other" button, we need to enable text capture mode
|
||||
# This is done by calling mark_awaiting_text when the user clicks "Other"
|
||||
|
||||
Reference in New Issue
Block a user