fix: P1 — MessageType.BUTTON_CLICK → COMMAND (Move-Request Confirm crash)

Root cause: adapter.py referenced MessageType.BUTTON_CLICK which does
not exist in Hermes-Core (only TEXT, COMMAND, PHOTO, etc.). The heuristic
at line 1502 matched MOVE_REQ:room_id::✅Ja text payloads as button
responses, triggering the crash path in _dispatch_agent.

Changes:
1. Heuristic fix: exclude MOVE_REQ: prefix from button detection (line 1502)
2. MessageType.BUTTON_CLICK → MessageType.COMMAND in both dispatch sites
3. DRY refactor: extracted _message_type_for() helper method
4. Updated fallback exception handlers and log messages (BUTTON_CLICK → COMMAND)
5. Regression test: test_p1_button_click_fix.py (6 tests)

Verification:
- python3 -c "from gateway.platforms.base import MessageType; assert hasattr(MessageType,COMMAND)" → OK
- pytest test_v8_3_2.py -k confirm_move → PASSED
- grep BUTTON_CLICK plugin/adapter.py → 1 (docstring only)
- pytest plugin/ -k dispatch → 5 passed
- Full suite: 984 passed, 2 skipped, 0 failures
This commit is contained in:
Bernd (Hermes)
2026-07-19 21:00:31 +02:00
parent 4604f2e123
commit 439cca48be
2 changed files with 131 additions and 11 deletions
+25 -11
View File
@@ -1499,7 +1499,11 @@ class RocketChatAdapter(BasePlatformAdapter):
msg_obj.get("actions") and
msg_obj.get("params", {}).get("triggerSender") and
msg_obj.get("params", {}).get("payload"))
or (text and "::" in text and not text.startswith("CLARIFY:") and not text.startswith("ARCHIVAR_CLARIFY:") and text.split("::", 1)[0].strip() != "")
or (text and "::" in text
and not text.startswith("CLARIFY:")
and not text.startswith("ARCHIVAR_CLARIFY:")
and not text.startswith("MOVE_REQ:")
and text.split("::", 1)[0].strip() != "")
or (text and text.startswith("CLARIFY:"))
or (text and text.startswith("ARCHIVAR_CLARIFY:"))
)
@@ -2606,7 +2610,7 @@ class RocketChatAdapter(BasePlatformAdapter):
try:
from datetime import datetime
message_type = MessageType.BUTTON_CLICK if is_button_response else MessageType.TEXT
message_type = self._message_type_for(is_button_response)
# ── Archivar-Kontext-Weitergabe: Frage-Nr + Zielraum im Prompt ──
target_room_id = _THEMATIC_TARGET_ROOM.get()
if target_room_id:
@@ -2663,11 +2667,11 @@ class RocketChatAdapter(BasePlatformAdapter):
await self.handle_message(event)
except Exception as e:
logger.error("[rocketchat] handle_message error: %s", e)
# Fallback: Wenn BUTTON_CLICK fehlschlägt (z.B. nach Gateway-Neustart
# Fallback: Wenn COMMAND fehlschlägt (z.B. nach Gateway-Neustart
# verliert der neue Prozess den In-Memory-Callback), als normale
# Text-Nachricht mit Hinweis wiederholen.
if is_button_response and str(e) == "BUTTON_CLICK":
logger.info("[rocketchat] BUTTON_CLICK lost context — retrying as TEXT")
if is_button_response and str(e) == "COMMAND":
logger.info("[rocketchat] COMMAND lost context — retrying as TEXT")
try:
from datetime import datetime as dt2
fallback_source = SessionSource(
@@ -2689,7 +2693,7 @@ class RocketChatAdapter(BasePlatformAdapter):
fallback_event.source = fallback_source
await self.handle_message(fallback_event)
except Exception as e2:
logger.error("[rocketchat] BUTTON_CLICK text fallback also failed: %s", e2)
logger.error("[rocketchat] COMMAND text fallback also failed: %s", e2)
# ── R5: Inline-Command-Handler ────────────────────────────────────────
@@ -3403,6 +3407,16 @@ class RocketChatAdapter(BasePlatformAdapter):
"Verfügbar: `status`, `run`"
)
@staticmethod
def _message_type_for(is_button_response: bool) -> "MessageType":
"""Return the appropriate MessageType for a button response.
P1 fix: Hermes-Core has no BUTTON_CLICK enum member.
Button responses are dispatched as COMMAND so the agent
can handle them as structured input.
"""
return MessageType.COMMAND if is_button_response else MessageType.TEXT
async def _dispatch_agent(
self,
text: str,
@@ -3434,7 +3448,7 @@ class RocketChatAdapter(BasePlatformAdapter):
try:
from datetime import datetime
message_type = MessageType.BUTTON_CLICK if is_button_response else MessageType.TEXT
message_type = self._message_type_for(is_button_response)
# ── Archivar-Kontext-Weitergabe: Frage-Nr + Zielraum im Prompt ──
target_room_id = _THEMATIC_TARGET_ROOM.get()
if target_room_id:
@@ -3474,9 +3488,9 @@ class RocketChatAdapter(BasePlatformAdapter):
await self.handle_message(event)
except Exception as e:
logger.error("[rocketchat] handle_message error: %s", e)
# Fallback: Wenn BUTTON_CLICK fehlschlägt
if is_button_response and str(e) == "BUTTON_CLICK":
logger.info("[rocketchat] BUTTON_CLICK lost context — retrying as TEXT")
# Fallback: Wenn COMMAND fehlschlägt
if is_button_response and str(e) == "COMMAND":
logger.info("[rocketchat] COMMAND lost context — retrying as TEXT")
try:
from datetime import datetime as dt2
fallback_source = SessionSource(
@@ -3498,7 +3512,7 @@ class RocketChatAdapter(BasePlatformAdapter):
fallback_event.source = fallback_source
await self.handle_message(fallback_event)
except Exception as e2:
logger.error("[rocketchat] BUTTON_CLICK text fallback also failed: %s", e2)
logger.error("[rocketchat] COMMAND text fallback also failed: %s", e2)
async def _send_via_archivar(self, room_id: str, text: str) -> bool:
"""Callback for Archivar forwarding — sends a message copy to a target room."""