From d995fb8503b22948fd3916376101b707bce99e3a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 14:15:27 +0100 Subject: [PATCH] Use observation time for Move freshness --- crates/muninn-daemon/src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 2b7b590..972e08a 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -1217,7 +1217,7 @@ fn verify_move_sources_fresh( let latest = states .iter() .filter(|state| state.host_id == options.host_id && state.move_id == source.move_id) - .max_by_key(|state| state.sequence) + .max_by_key(|state| unix_timestamp_sort_key(&state.observed_at)) .ok_or_else(|| { anyhow!( "Muninn Move source {} has no controller-state records", @@ -1252,6 +1252,10 @@ fn parse_unix_timestamp(value: &str) -> Result { .context("timestamp seconds must be an integer") } +fn unix_timestamp_sort_key(value: &str) -> u64 { + parse_unix_timestamp(value).unwrap_or(0) +} + fn request_move_light(options: Options) -> Result<()> { ensure_state_dirs(&options)?; let mut node = open_node(&options, "muninn-move-light-request")?; @@ -1300,6 +1304,9 @@ fn move_state_status(options: Options) -> Result<()> { states.sort_by(|a, b| { a.stream_id .cmp(&b.stream_id) + .then(unix_timestamp_sort_key(&a.observed_at).cmp(&unix_timestamp_sort_key( + &b.observed_at, + ))) .then(a.sequence.cmp(&b.sequence)) }); if states.is_empty() {