hotfix: CLARIFY-Button ::-Format — resolve_gateway_clarify() wurde nie aufgerufen
ROOT CAUSE: Der ::-Format-Branch (CLARIFY:<id>::<choice>) extrahierte clarify_id und choice, machte dann aber NICHTS. Die gesamte Verarbeitungslogik (resolve_gateway_clarify, Cleanup, return) lag im else:-Block und wurde für ::-Format-Nachrichten nie erreicht. FIX: - Format-Extraktion (:: vs :) von der Verarbeitung getrennt - Beide Formate münden in gemeinsame if/elif/else-Verarbeitung - resolve_gateway_clarify() wird jetzt für BEIDE Formate aufgerufen - _rooms_with_pending_questions wird nach Clarify-Auflösung geleert (sowohl im Button-Handler als auch im Plain-Digit-Intercept) SYMPTOM: CLARIFY:d4bddd91dc::2 kam um 12:07:52 an, wurde als clarify_answer_bypass erkannt, aber resolve_gateway_clarify() wurde nie aufgerufen. Der Raum blieb 3+ Stunden in pending_questions. Jede weitere Nachricht wurde mit pending_questions_bypass übersprungen. PITFALLS: - P-013: CLARIFY-Antworten triggern False-Positive BUTTON_CLICK (nicht betroffen) - Plain-Digit-Intercept (2407-2448) blockiert CLARIFY-Button-Handler NICHT (is_clarify_response=True → wird korrekt übersprungen)
This commit is contained in:
+54
-47
@@ -2429,6 +2429,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# Resolve via gateway and clean up
|
# Resolve via gateway and clean up
|
||||||
self._clarify_state.pop(clarify_id, None)
|
self._clarify_state.pop(clarify_id, None)
|
||||||
self._room_clarify.pop(room_id, None)
|
self._room_clarify.pop(room_id, None)
|
||||||
|
# Clean up pending_questions — Clarify is resolved
|
||||||
|
self._rooms_with_pending_questions.discard(room_id)
|
||||||
try:
|
try:
|
||||||
from tools.clarify_gateway import resolve_gateway_clarify
|
from tools.clarify_gateway import resolve_gateway_clarify
|
||||||
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
||||||
@@ -2454,64 +2456,69 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
routing_counter.increment('clarify_answer_bypass')
|
routing_counter.increment('clarify_answer_bypass')
|
||||||
logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id)
|
logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id)
|
||||||
try:
|
try:
|
||||||
|
# ── Format-Extraktion (gemeinsam für alt und neu) ──
|
||||||
if "::" in text:
|
if "::" in text:
|
||||||
# Neues Format: CLARIFY:<id>::<choice> (via _build_custom_buttons)
|
# Neues Format: CLARIFY:<id>::<choice> (via _build_custom_buttons)
|
||||||
prefix_part, choice = text.split("::", 1)
|
prefix_part, choice = text.split("::", 1)
|
||||||
clarify_id = prefix_part.split(":", 1)[1]
|
clarify_id = prefix_part.split(":", 1)[1]
|
||||||
else:
|
else:
|
||||||
# Altes Format: CLARIFY:<id>:other (Other-Button)
|
# Altes Format: CLARIFY:<id>:<token>
|
||||||
parts = text.split(":", 2)
|
parts = text.split(":", 2)
|
||||||
if len(parts) != 3:
|
if len(parts) != 3:
|
||||||
logger.debug("[rocketchat] Unrecognized CLARIFY format: %s", text)
|
logger.debug("[rocketchat] Unrecognized CLARIFY format: %s", text)
|
||||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY unrecognized format — skipping")
|
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY unrecognized format — skipping")
|
||||||
return
|
return
|
||||||
_, clarify_id, choice = parts
|
_, clarify_id, choice = parts
|
||||||
if choice == "other":
|
|
||||||
# For "Other" button, enable text capture mode
|
# ── Gemeinsame Verarbeitung (beide Formate) ──
|
||||||
from tools.clarify_gateway import mark_awaiting_text
|
if choice == "other":
|
||||||
mark_awaiting_text(clarify_id)
|
# For "Other" button, enable text capture mode
|
||||||
logger.debug("[rocketchat] Clarify %s: awaiting text response from %s", clarify_id, username)
|
from tools.clarify_gateway import mark_awaiting_text
|
||||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY other — awaiting text")
|
mark_awaiting_text(clarify_id)
|
||||||
# Don't process further - wait for the next text message
|
logger.debug("[rocketchat] Clarify %s: awaiting text response from %s", clarify_id, username)
|
||||||
return
|
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY other — awaiting text")
|
||||||
elif choice.isdigit():
|
# Don't process further - wait for the next text message
|
||||||
# Numeric choice → resolve the clarify immediately
|
return
|
||||||
idx = int(choice)
|
elif choice.isdigit():
|
||||||
resolved_text: Optional[str] = None
|
# Numeric choice → resolve the clarify immediately
|
||||||
try:
|
idx = int(choice)
|
||||||
from tools.clarify_gateway import _entries as _clarify_entries
|
resolved_text: Optional[str] = None
|
||||||
entry = _clarify_entries.get(clarify_id)
|
try:
|
||||||
if entry and entry.choices and 0 <= idx < len(entry.choices):
|
from tools.clarify_gateway import _entries as _clarify_entries
|
||||||
resolved_text = entry.choices[idx]
|
entry = _clarify_entries.get(clarify_id)
|
||||||
except Exception:
|
if entry and entry.choices and 0 <= idx < len(entry.choices):
|
||||||
resolved_text = None
|
resolved_text = entry.choices[idx]
|
||||||
if resolved_text is None:
|
except Exception:
|
||||||
# Race: entry vanished. Echo the index.
|
resolved_text = None
|
||||||
resolved_text = f"choice {idx + 1}"
|
if resolved_text is None:
|
||||||
# Resolve via gateway and clean up
|
# Race: entry vanished. Echo the index.
|
||||||
self._clarify_state.pop(clarify_id, None)
|
resolved_text = f"choice {idx + 1}"
|
||||||
# Clean up room→clarify mapping (button click resolved it)
|
# Resolve via gateway and clean up
|
||||||
for rid, cid in list(self._room_clarify.items()):
|
self._clarify_state.pop(clarify_id, None)
|
||||||
if cid == clarify_id:
|
# Clean up room→clarify mapping (button click resolved it)
|
||||||
self._room_clarify.pop(rid, None)
|
for rid, cid in list(self._room_clarify.items()):
|
||||||
try:
|
if cid == clarify_id:
|
||||||
from tools.clarify_gateway import resolve_gateway_clarify
|
self._room_clarify.pop(rid, None)
|
||||||
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
# Clean up pending_questions — Clarify is resolved
|
||||||
if resolved:
|
self._rooms_with_pending_questions.discard(room_id)
|
||||||
logger.info(
|
try:
|
||||||
"[rocketchat] Clarify %s resolved: %s (session=%s)",
|
from tools.clarify_gateway import resolve_gateway_clarify
|
||||||
clarify_id, resolved_text[:60], self._clarify_state.get(clarify_id, "?"),
|
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
||||||
)
|
if resolved:
|
||||||
else:
|
logger.info(
|
||||||
logger.warning("[rocketchat] Clarify %s resolve returned False", clarify_id)
|
"[rocketchat] Clarify %s resolved: %s (session=%s)",
|
||||||
except Exception as exc:
|
clarify_id, resolved_text[:60], self._clarify_state.get(clarify_id, "?"),
|
||||||
logger.error("[rocketchat] resolve_gateway_clarify failed: %s", exc)
|
)
|
||||||
# Don't route to agent — this was a button click
|
else:
|
||||||
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY resolved — skipping")
|
logger.warning("[rocketchat] Clarify %s resolve returned False", clarify_id)
|
||||||
return
|
except Exception as exc:
|
||||||
else:
|
logger.error("[rocketchat] resolve_gateway_clarify failed: %s", exc)
|
||||||
# Unknown token — let it fall through as regular text
|
# Don't route to agent — this was a button click
|
||||||
logger.warning("[rocketchat] Unknown clarify token: %s", choice)
|
logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY resolved — skipping")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# Unknown token — let it fall through as regular text
|
||||||
|
logger.warning("[rocketchat] Unknown clarify token: %s", choice)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug("[rocketchat] Error processing CLARIFY response: %s", e)
|
logger.debug("[rocketchat] Error processing CLARIFY response: %s", e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user