ソースを参照

Add debug logging around roster dispatch and thread anchoring

Diagnosing missing or empty rosters in production meant reading code;
member counts, filtered-out empties and already-announced thread roots
now log at debug so the next incident explains itself from the logs.
Paul Klumpp 1 週間 前
コミット
9d2668b5c5
1 ファイル変更34 行追加0 行削除
  1. 34 0
      adapter.py

+ 34 - 0
adapter.py

@@ -1083,12 +1083,24 @@ class ChattoAdapter(BasePlatformAdapter):
                 "Chatto: could not list members of room %s", room_id, exc_info=True
             )
             return ""
+        logger.debug(
+            "Chatto: roster for room %s: %d members fetched, total_count=%d",
+            room_id,
+            len(members),
+            page.total_count,
+        )
         entries = [
             entry
             for entry in (self._roster_entry(member) for member in members)
             if entry
         ]
         if not entries:
+            logger.debug(
+                "Chatto: roster for room %s empty after filtering "
+                "(%d fetched, all deleted/self/without user)",
+                room_id,
+                len(members),
+            )
             return ""
 
         unfetched = max(0, page.total_count - len(members))
@@ -1131,6 +1143,10 @@ class ChattoAdapter(BasePlatformAdapter):
         through this gate can still bring the roster.
         """
         if thread_root_event_id in self._roster_announced:
+            logger.debug(
+                "Chatto: roster for thread root %s already announced",
+                thread_root_event_id,
+            )
             return ""
         roster = await self._room_roster_context(client, room_id)
         if not roster:
@@ -1421,6 +1437,14 @@ class ChattoAdapter(BasePlatformAdapter):
         )  # we could also take the room id but then, we're in a thread already.
         if not thread_id and room_kind != RoomKind.DM:
             thread_id = message.id
+        logger.debug(
+            "Chatto: thread anchoring for msg %s: incoming thread_root_event_id=%r, "
+            "room_kind=%s, anchored thread_id=%r",
+            message.id,
+            message.thread_root_event_id,
+            room_kind.name,
+            thread_id,
+        )
 
         # A dispatch that opens the thread is where the agent learns who is in
         # the channel — later turns ride in that thread and need no repeat. The
@@ -1428,9 +1452,19 @@ class ChattoAdapter(BasePlatformAdapter):
         # never mingles with what the user actually wrote.
         roster = ""
         if room_kind != RoomKind.DM and thread_root_event_id is None:
+            logger.debug(
+                "Chatto: fetching roster for new thread in room %s (root %s)",
+                room_id,
+                message.id,
+            )
             roster = await self._roster_for_new_thread(
                 client, room_id=room_id, thread_root_event_id=message.id
             )
+            if not roster:
+                logger.debug(
+                    "Chatto: dispatching channel message without roster "
+                    "(lookup failed, empty, or already announced)"
+                )
 
         source = self.build_source(
             chat_id=room_id,