feat(#2569): migrate matrix producer to the in-agent todo socket (unread + invites); drop dead mcp.sock/wake plumbing
This commit is contained in:
parent
a2d44c7eb6
commit
21f1569a04
5 changed files with 113 additions and 166 deletions
|
|
@ -73,7 +73,6 @@ async fn main() -> Result<()> {
|
|||
|
||||
let cfgs = accounts::configured().context("read matrix account config")?;
|
||||
let mcp_socket = paths::daemon_socket();
|
||||
let hyperhive_socket = paths::hyperhive_socket();
|
||||
let multi = cfgs.len() > 1;
|
||||
let primary = cfgs[0].name.clone();
|
||||
let mut registry = Registry::new(primary);
|
||||
|
|
@ -81,10 +80,10 @@ async fn main() -> Result<()> {
|
|||
|
||||
for (idx, cfg) in cfgs.into_iter().enumerate() {
|
||||
let is_primary = idx == 0;
|
||||
// Account-tag the wakes only in multi-account mode so single-
|
||||
// account wake bodies stay byte-identical to the legacy format.
|
||||
// Account-tag the todos only in multi-account mode so single-
|
||||
// account todo summaries stay byte-identical to the legacy format.
|
||||
let tag = multi.then(|| cfg.name.clone());
|
||||
match bring_up_account(&cfg, &hyperhive_socket, tag.clone(), is_primary).await {
|
||||
match bring_up_account(&cfg, tag.clone(), is_primary).await {
|
||||
Ok(Some((client, sync_loop))) => {
|
||||
registry.insert(cfg.name, client);
|
||||
sync_loops.push(sync_loop);
|
||||
|
|
@ -109,8 +108,7 @@ async fn main() -> Result<()> {
|
|||
// before being skipped for this daemon lifetime.
|
||||
Err(e) if is_primary => return Err(e.context("bring up primary matrix account")),
|
||||
Err(e) => {
|
||||
if let Some((client, sync_loop)) =
|
||||
bring_up_secondary_with_retry(&cfg, &hyperhive_socket, tag, e).await
|
||||
if let Some((client, sync_loop)) = bring_up_secondary_with_retry(&cfg, tag, e).await
|
||||
{
|
||||
registry.insert(cfg.name, client);
|
||||
sync_loops.push(sync_loop);
|
||||
|
|
@ -189,7 +187,6 @@ async fn main() -> Result<()> {
|
|||
/// failure, no token, or all retries exhausted).
|
||||
async fn bring_up_secondary_with_retry(
|
||||
cfg: &AccountCfg,
|
||||
hyperhive_socket: &std::path::Path,
|
||||
tag: Option<String>,
|
||||
first_error: anyhow::Error,
|
||||
) -> Option<(Client, SyncLoop)> {
|
||||
|
|
@ -219,7 +216,7 @@ async fn bring_up_secondary_with_retry(
|
|||
"retrying secondary account bring-up after backoff"
|
||||
);
|
||||
tokio::time::sleep(std::time::Duration::from_secs(delay)).await;
|
||||
match bring_up_account(cfg, hyperhive_socket, tag.clone(), false).await {
|
||||
match bring_up_account(cfg, tag.clone(), false).await {
|
||||
Ok(Some((client, sync_loop))) => {
|
||||
tracing::info!(account = %cfg.name, "secondary matrix account recovered");
|
||||
return Some((client, sync_loop));
|
||||
|
|
@ -260,7 +257,6 @@ async fn bring_up_secondary_with_retry(
|
|||
/// handling). The returned sync loop is driven by the caller.
|
||||
async fn bring_up_account(
|
||||
cfg: &AccountCfg,
|
||||
hyperhive_socket: &std::path::Path,
|
||||
tag: Option<String>,
|
||||
is_primary: bool,
|
||||
) -> Result<Option<(Client, SyncLoop)>> {
|
||||
|
|
@ -293,30 +289,26 @@ async fn bring_up_account(
|
|||
|
||||
let sync_client = client.clone();
|
||||
let cb_client = client.clone();
|
||||
let wake_socket = Arc::new(hyperhive_socket.to_path_buf());
|
||||
// Separate dedup sets: one tracks invites already woken about, the
|
||||
// Separate dedup sets: one tracks invites already pushed as todos, the
|
||||
// other unread-message rooms. Both are pruned to their current state
|
||||
// each sweep (see the sweep fns) so re-invites / new messages re-wake.
|
||||
// each sweep (see the sweep fns) so re-invites / new messages re-push.
|
||||
let invite_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
let unread_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
// Startup cancel-and-recreate (loose-ends v2): wipe this agent's
|
||||
// matrix todos so stale ones (rooms read while the daemon was down) don't
|
||||
// linger, then let the first sweep rebuild the set to match current
|
||||
// unread reality. Best-effort; the sweep converges regardless.
|
||||
let _ = crate::wake::send_todo_clear(hyperhive_socket, None, true).await;
|
||||
// matrix todos so stale ones (rooms read / invites resolved while the
|
||||
// daemon was down) don't linger, then let the first sweep rebuild the
|
||||
// set to match current reality. Best-effort; the sweep converges.
|
||||
let _ = crate::wake::send_todo_clear(None, true).await;
|
||||
let sync_loop: SyncLoop = Box::pin(async move {
|
||||
sync_client
|
||||
.sync_with_callback(SyncSettings::default(), move |_response| {
|
||||
let client = cb_client.clone();
|
||||
let socket = wake_socket.clone();
|
||||
let invite_notified = invite_notified.clone();
|
||||
let unread_notified = unread_notified.clone();
|
||||
let tag = tag.clone();
|
||||
async move {
|
||||
timeline::sweep_invites(&client, &socket, &invite_notified, tag.as_deref())
|
||||
.await;
|
||||
timeline::sweep_unread(&client, &socket, &unread_notified, tag.as_deref())
|
||||
.await;
|
||||
timeline::sweep_invites(&client, &invite_notified, tag.as_deref()).await;
|
||||
timeline::sweep_unread(&client, &unread_notified, tag.as_deref()).await;
|
||||
matrix_sdk::LoopCtrl::Continue
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue