sweep: dedupe matrix ensure_all banner closure

This commit is contained in:
iris 2026-07-16 20:14:00 +02:00 committed by mara
commit 84ea7b8e7d

View file

@ -401,6 +401,21 @@ async fn cmd_serve(
}
}
});
/// Banner message for a failing matrix `ensure_all` sweep, shared by
/// both the initial and periodic `record_err` call sites below so the
/// wording can't drift between them.
fn matrix_sweep_banner(ctx: sweep_health::SweepFailure) -> String {
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 user sweep: same shape — ensure every container has
// an account on the local matrix-tuwunel homeserver with an
// access_token persisted to `<state>/matrix-token`. No-op when
@ -422,18 +437,7 @@ async fn cmd_serve(
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
)
});
health.record_err(matrix_sweep_banner);
}
loop {
tokio::select! {
@ -441,18 +445,7 @@ async fn cmd_serve(
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
)
});
health.record_err(matrix_sweep_banner);
}
}
_ = matrix_shutdown.changed() => {