fix(#1666): wake on pending matrix invites via post-sync sweep

This commit is contained in:
damocles 2026-06-14 22:07:04 +02:00 committed by mara
commit ca84cf427b
2 changed files with 68 additions and 52 deletions

View file

@ -65,7 +65,6 @@ async fn main() -> Result<()> {
.context("build matrix client")?;
timeline::install_message_handler(&matrix_client, hyperhive_socket.clone());
timeline::install_invite_handler(&matrix_client, hyperhive_socket);
// Spawn the unix socket server before sync starts so the MCP
// bridge can connect as soon as the first claude turn fires. The
@ -79,10 +78,26 @@ async fn main() -> Result<()> {
}
});
// Sync forever; matrix-sdk handles reconnection internally.
// Sync forever; matrix-sdk handles reconnection internally. After
// every sync, sweep pending invites and wake the agent for any new
// one: the StrippedRoomMemberEvent handler dispatched unreliably
// (cold-start invites + handler races produced no wake), so
// invite-waking lives on this post-sync sweep with a dedup set.
let invite_socket = std::sync::Arc::new(hyperhive_socket);
let invite_notified =
std::sync::Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
let sweep_client = matrix_client.clone();
let sync_settings = SyncSettings::default();
matrix_client
.sync(sync_settings)
.sync_with_callback(sync_settings, move |_response| {
let client = sweep_client.clone();
let socket = invite_socket.clone();
let notified = invite_notified.clone();
async move {
timeline::sweep_invites(&client, &socket, &notified).await;
matrix_sdk::LoopCtrl::Continue
}
})
.await
.context("matrix-sdk sync loop exited")?;