From f0a7e83546c60b128f8a4423d768ecf9e05fc862 Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Mon, 10 Aug 2026 15:20:04 +0200 Subject: [PATCH] =?UTF-8?q?hotfix:=20CLARIFY-Button=20::-Format=20?= =?UTF-8?q?=E2=80=94=20resolve=5Fgateway=5Fclarify()=20wurde=20nie=20aufge?= =?UTF-8?q?rufen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ROOT CAUSE: Der ::-Format-Branch (CLARIFY:::) 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) --- plugin/adapter.py | 101 +++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/plugin/adapter.py b/plugin/adapter.py index 3a37bcd..476d23a 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -2429,6 +2429,8 @@ class RocketChatAdapter(BasePlatformAdapter): # Resolve via gateway and clean up self._clarify_state.pop(clarify_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: from tools.clarify_gateway import resolve_gateway_clarify resolved = resolve_gateway_clarify(clarify_id, resolved_text) @@ -2454,64 +2456,69 @@ class RocketChatAdapter(BasePlatformAdapter): routing_counter.increment('clarify_answer_bypass') logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id) try: + # ── Format-Extraktion (gemeinsam für alt und neu) ── if "::" in text: # Neues Format: CLARIFY::: (via _build_custom_buttons) prefix_part, choice = text.split("::", 1) clarify_id = prefix_part.split(":", 1)[1] else: - # Altes Format: CLARIFY::other (Other-Button) + # Altes Format: CLARIFY:: parts = text.split(":", 2) if len(parts) != 3: logger.debug("[rocketchat] Unrecognized CLARIFY format: %s", text) logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY unrecognized format — skipping") return _, clarify_id, choice = parts - if choice == "other": - # For "Other" button, enable text capture mode - from tools.clarify_gateway import mark_awaiting_text - mark_awaiting_text(clarify_id) - logger.debug("[rocketchat] Clarify %s: awaiting text response from %s", clarify_id, username) - logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY other — awaiting text") - # Don't process further - wait for the next text message - return - elif choice.isdigit(): - # Numeric choice → resolve the clarify immediately - idx = int(choice) - resolved_text: Optional[str] = None - try: - from tools.clarify_gateway import _entries as _clarify_entries - entry = _clarify_entries.get(clarify_id) - if entry and entry.choices and 0 <= idx < len(entry.choices): - resolved_text = entry.choices[idx] - except Exception: - resolved_text = None - if resolved_text is None: - # Race: entry vanished. Echo the index. - resolved_text = f"choice {idx + 1}" - # Resolve via gateway and clean up - self._clarify_state.pop(clarify_id, None) - # Clean up room→clarify mapping (button click resolved it) - for rid, cid in list(self._room_clarify.items()): - if cid == clarify_id: - self._room_clarify.pop(rid, None) - try: - from tools.clarify_gateway import resolve_gateway_clarify - resolved = resolve_gateway_clarify(clarify_id, resolved_text) - if resolved: - logger.info( - "[rocketchat] Clarify %s resolved: %s (session=%s)", - clarify_id, resolved_text[:60], self._clarify_state.get(clarify_id, "?"), - ) - else: - logger.warning("[rocketchat] Clarify %s resolve returned False", clarify_id) - except Exception as exc: - logger.error("[rocketchat] resolve_gateway_clarify failed: %s", exc) - # Don't route to agent — this was a button click - 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) + + # ── Gemeinsame Verarbeitung (beide Formate) ── + if choice == "other": + # For "Other" button, enable text capture mode + from tools.clarify_gateway import mark_awaiting_text + mark_awaiting_text(clarify_id) + logger.debug("[rocketchat] Clarify %s: awaiting text response from %s", clarify_id, username) + logger.debug("[rocketchat] ARCHIVAR-DEBUG: CLARIFY other — awaiting text") + # Don't process further - wait for the next text message + return + elif choice.isdigit(): + # Numeric choice → resolve the clarify immediately + idx = int(choice) + resolved_text: Optional[str] = None + try: + from tools.clarify_gateway import _entries as _clarify_entries + entry = _clarify_entries.get(clarify_id) + if entry and entry.choices and 0 <= idx < len(entry.choices): + resolved_text = entry.choices[idx] + except Exception: + resolved_text = None + if resolved_text is None: + # Race: entry vanished. Echo the index. + resolved_text = f"choice {idx + 1}" + # Resolve via gateway and clean up + self._clarify_state.pop(clarify_id, None) + # Clean up room→clarify mapping (button click resolved it) + for rid, cid in list(self._room_clarify.items()): + if cid == clarify_id: + self._room_clarify.pop(rid, None) + # Clean up pending_questions — Clarify is resolved + self._rooms_with_pending_questions.discard(room_id) + try: + from tools.clarify_gateway import resolve_gateway_clarify + resolved = resolve_gateway_clarify(clarify_id, resolved_text) + if resolved: + logger.info( + "[rocketchat] Clarify %s resolved: %s (session=%s)", + clarify_id, resolved_text[:60], self._clarify_state.get(clarify_id, "?"), + ) + else: + logger.warning("[rocketchat] Clarify %s resolve returned False", clarify_id) + except Exception as exc: + logger.error("[rocketchat] resolve_gateway_clarify failed: %s", exc) + # Don't route to agent — this was a button click + 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: logger.debug("[rocketchat] Error processing CLARIFY response: %s", e)