sweep: wire matrix::ensure_all() into the warning-banner registry

Fast-follow for #2289 — matrix::ensure_all() (admin user, per-agent
sync, hive Space + chat-room provisioning/invites) ran periodically
every 30 minutes but only ever warn!'d to the journal on failure, so a
persistent problem (missing invites, broken admin token, etc.) was
invisible to the operator.

ensure_all() now returns bool (aggregate ok/fail across every
sub-step) instead of (), and both call sites in main.rs feed that into
a debounced SweepHealth("matrix_ensure_all", warn, threshold=2) —
matches the existing knowledge_pull pattern. A lone bad sweep
self-heals silently; two consecutive failures raise a banner that
clears on the next clean sweep.

forge::ensure_all()'s remaining independent steps are still open —
that sweep only runs once at startup (no periodic loop), so the
debounced pattern doesn't map as directly; left for a follow-up.
This commit is contained in:
iris 2026-07-16 20:04:35 +02:00 committed by mara
commit b889f403d5
2 changed files with 62 additions and 12 deletions

View file

@ -414,11 +414,46 @@ async fn cmd_serve(
let mut matrix_shutdown = coord.shutdown_rx();
tokio::spawn(async move {
let interval = std::time::Duration::from_mins(30);
matrix::ensure_all().await;
// Debounced banner: a lone bad sweep (homeserver mid-restart, a
// transient HTTP blip) shouldn't flap the dashboard, but a sweep
// that's been failing for hours (missing agent invites, a broken
// admin token) should surface. Cleared the moment a sweep is clean.
let mut health = sweep_health::SweepHealth::new("matrix_ensure_all", "warn", 2);
if matrix::ensure_all().await {
health.record_ok();
} else {
health.record_err(|ctx| {
let age = ctx.since_last_ok.map_or_else(
|| "no success this session".to_owned(),
|d| format!("last ok {} ago", sweep_health::fmt_age(d)),
);
format!(
"matrix user/space sweep failing ({} consecutive, {age}) \
some agents may be missing matrix accounts, space membership, \
or chat-room invites",
ctx.consecutive
)
});
}
loop {
tokio::select! {
() = tokio::time::sleep(interval) => {
matrix::ensure_all().await;
if matrix::ensure_all().await {
health.record_ok();
} else {
health.record_err(|ctx| {
let age = ctx.since_last_ok.map_or_else(
|| "no success this session".to_owned(),
|d| format!("last ok {} ago", sweep_health::fmt_age(d)),
);
format!(
"matrix user/space sweep failing ({} consecutive, {age}) \
some agents may be missing matrix accounts, space membership, \
or chat-room invites",
ctx.consecutive
)
});
}
}
_ = matrix_shutdown.changed() => {
tracing::info!("matrix ensure_all: shutdown signal received");