fix: recover from M_UNKNOWN_TOKEN in hive-matrix-daemon

when the homeserver rejects the token (stale session after state wipe or
expiry), the daemon now deletes the token file + matrix-sdk state dir
and exits cleanly instead of crash-looping.

hive-c0re's matrix::ensure_all sweep now runs periodically every 30
minutes (in addition to startup) so deleted token files get
re-provisioned without requiring a hive-c0re restart. the systemd.paths
watcher on the token file path then restarts the daemon with a fresh
token.
This commit is contained in:
damocles 2026-06-04 09:47:36 +02:00 committed by mara
commit 1c5936febb
2 changed files with 53 additions and 3 deletions

View file

@ -267,8 +267,26 @@ async fn cmd_serve(
// access_token persisted to `<state>/matrix-token`. No-op when
// the hive-matrix container isn't running. Backgrounded because
// UIAA is a two-roundtrip dance per agent.
//
// Runs once at startup AND periodically every 30 minutes so that
// token files deleted by `hive-matrix-daemon` (stale-token
// recovery — `M_UNKNOWN_TOKEN`) get re-provisioned without
// requiring a hive-c0re restart.
let mut matrix_shutdown = coord.shutdown_rx();
tokio::spawn(async move {
let interval = std::time::Duration::from_mins(30);
matrix::ensure_all().await;
loop {
tokio::select! {
() = tokio::time::sleep(interval) => {
matrix::ensure_all().await;
}
_ = matrix_shutdown.changed() => {
tracing::info!("matrix ensure_all: shutdown signal received");
break;
}
}
}
});
// Periodic broker vacuum: drop fully-acked messages older
// than 30 days. Delivered-but-unacked rows (recoverable via