feat(hermes): switch to call_on_each_event with proper narrow filter
CI / validate (pull_request) Failing after 5s

This commit is contained in:
Jerome
2026-06-20 22:34:59 +00:00
parent 141814a12a
commit b8ae43f652
@@ -125,12 +125,20 @@ class ZulipAdapter:
def _event_loop(self) -> None:
"""Background thread to listen for Zulip events.
Creates a dedicated asyncio event loop for this thead (Python 3.13+).
Uses call_on_each_event (not call_on_each_message) for proper @mention detection.
"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
self._client.call_on_each_message(
# Build narrow to filter for our stream only
stream = self.config['zulip']['stream']
narrow = [[u"stream", stream]]
logger.info(f"Zulip: call_on_each_event narrow=[{narrow}]")
self._client.call_on_each_event(
lambda event: self._process_event(event),
event_types=["message"],
narrow=narrow,
)
except Exception as e:
logger.error(f"Event loop crashed: {e}")
@@ -142,7 +150,15 @@ class ZulipAdapter:
def _process_event(self, event: Dict[str, Any]) -> None:
"""Bridge the synchronous event to the async on_event handler."""
event_type = str(event.get("type", "unknown"))
logger.info(f"[ZULIP_EVENT] Processing: {event_type}")
flags = event.get("flags", [])
sender_email = event.get("sender_email", "unknown")
sender_id = event.get("sender_id", 0)
logger.info(f"[ZULIP_EVENT] type={event_type} flags={flags} sender_id={sender_id} sender_email={sender_email}")
# Check if this message is mentioned to us
is_mentioned = "mentioned" in flags
logger.info(f"[DEBUG] is_mentioned (via flags)={is_mentioned}")
try:
loop = asyncio.get_event_loop()
if loop.is_running():