From 1df7b680eee0b7d60971a1101191e7ee3ddb3e97 Mon Sep 17 00:00:00 2001 From: jjbrunton Date: Fri, 22 May 2026 23:06:33 +0100 Subject: [PATCH] Stop re-attempting /joined_members on rooms we can't read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reddit's homeserver returns 404 from /_matrix/client/v3/rooms/{id}/joined_members for rooms we've left, been kicked from, or never fully joined — which is roughly every chat that wasn't accepted by the recipient. The previous enrichUsernames pass retried these on every delta sync, flooding the dashboard log with debug-level 404s. Track failures in an in-memory unresolvable set so each room is tried at most once per process. Co-Authored-By: Claude Opus 4.7 --- src/services/chat/service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/services/chat/service.ts b/src/services/chat/service.ts index 0cc92fc..adb5084 100644 --- a/src/services/chat/service.ts +++ b/src/services/chat/service.ts @@ -104,6 +104,8 @@ export class ChatService { private cache: ChatCache; private queue: Promise = Promise.resolve(); private readonly t2ToUsername = new Map(); + /** Rooms whose /joined_members lookup has already failed — don't retry. */ + private readonly unresolvableRooms = new Set(); private syncingKind: 'full' | 'delta' | null = null; private progress: SyncProgress | null = null; private progressListener: SyncProgressListener | null = null; @@ -1006,6 +1008,7 @@ export class ChatService { const roomT2: Map = new Map(); // roomId -> bare t2 id for (const chat of this.cache.get()) { if (!chat.roomId) continue; + if (this.unresolvableRooms.has(chat.roomId)) continue; const needsLookup = !chat.username || chat.username === 'unknown' || @@ -1023,8 +1026,16 @@ export class ChatService { if (!chat.roomName || chat.roomName === 'unknown' || chat.roomName.startsWith('@')) { chat.roomName = chat.username; } + } else { + // No t2-shaped member in the room (probably empty or only us + // after the other party left). Don't keep retrying every sync. + this.unresolvableRooms.add(chat.roomId); } } catch (err) { + // 404/403 means we can't read membership for this room (left, kicked, + // or never fully joined). Cache the failure so the next delta doesn't + // spam the homeserver — and the log — with the same lookup. + this.unresolvableRooms.add(chat.roomId); this.logger.debug(`[chat] joined_members lookup failed for ${chat.roomId}:`, err); } }