From b68d91269fe39226c1708dfea9f4be5581f09b44 Mon Sep 17 00:00:00 2001 From: damocles Date: Wed, 22 Jul 2026 17:51:34 +0200 Subject: [PATCH] refactor(#2629): fix stale self-filter doc comments + flatten the sender-check let-chain --- hive-matrix-mcp/src/handlers.rs | 15 +++++++++------ hive-matrix-mcp/src/timeline.rs | 12 ++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/hive-matrix-mcp/src/handlers.rs b/hive-matrix-mcp/src/handlers.rs index 344d7fef..7001fcbb 100644 --- a/hive-matrix-mcp/src/handlers.rs +++ b/hive-matrix-mcp/src/handlers.rs @@ -903,12 +903,15 @@ pub async fn collect_unread_with_ids( } else { (None, None) }; - // Skip rooms where the newest unread event was sent by the agent itself. - // Self-authored messages should not trigger an unread notification. - if let (Some(ref sender), Some(own_id)) = (&last_sender, own_user_id) { - if sender == own_id.as_str() { - continue; - } + // Skip a single-unread room whose newest event is the agent's own + // message: after a rebuild the read receipt may not have advanced + // past it yet, so `notification_count` can still report 1 — without + // this the agent self-wakes on its own message. Only reachable on the + // count==1 path, where `last_sender` is populated. + if let (Some(sender), Some(own_id)) = (&last_sender, own_user_id) + && sender.as_str() == own_id.as_str() + { + continue; } result.push(( room.room_id().to_owned(), diff --git a/hive-matrix-mcp/src/timeline.rs b/hive-matrix-mcp/src/timeline.rs index 6e46e4fa..e4a9da67 100644 --- a/hive-matrix-mcp/src/timeline.rs +++ b/hive-matrix-mcp/src/timeline.rs @@ -9,8 +9,10 @@ //! //! Todo summaries stay short: `sweep_unread` pushes the per-room unread //! summary (`wake::format_unread_summary`); the message stays unread -//! server-side so the agent fetches detail via `read_room`. Self-sent -//! messages never raise an unread notification, so they never wake. +//! server-side so the agent fetches detail via `read_room`. A self-authored +//! newest message can still read as unread after a rebuild (the read receipt +//! lags), so `collect_unread_with_ids` filters those rooms out — the agent +//! never wakes on its own message. use std::collections::HashSet; @@ -33,8 +35,10 @@ use crate::{handlers, wake}; /// `Some(name)` only in multi-account mode, prepended so the agent knows /// which account to `read_room` on. /// -/// Self-sent messages don't raise an unread notification server-side, so -/// no explicit self-filter is needed here. +/// Rooms whose newest unread event is the agent's own message are filtered +/// out by `collect_unread_with_ids` (after a rebuild a stale read receipt can +/// otherwise leave a self-authored message counted as unread and self-wake +/// the agent). pub async fn sweep_unread( client: &Client, notified: &Mutex>,