From a4bcebf4406c8dc6c0c4e0dcaceedb37683710e2 Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Wed, 18 Nov 2026 21:19:14 +0100 Subject: [PATCH] Slow successful Windows helper time refreshes --- crates/agent-windows/src/runtime.rs | 2 +- crates/agent-windows/src/signed_clock.rs | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/agent-windows/src/runtime.rs b/crates/agent-windows/src/runtime.rs index e58939c..db9ddb0 100644 --- a/crates/agent-windows/src/runtime.rs +++ b/crates/agent-windows/src/runtime.rs @@ -935,7 +935,7 @@ impl Agent { let _ = time_helper.time_close(generation).await; } helper_report.record(&helper_state, "system_helper", &result); - tokio::time::sleep(mode.interval(result.is_ok())).await; + tokio::time::sleep(mode.helper_interval(result.is_ok())).await; } let _ = time_helper.time_close(generation).await; })); diff --git a/crates/agent-windows/src/signed_clock.rs b/crates/agent-windows/src/signed_clock.rs index ac50cd6..0d86f62 100644 --- a/crates/agent-windows/src/signed_clock.rs +++ b/crates/agent-windows/src/signed_clock.rs @@ -31,6 +31,15 @@ impl SamplingMode { (Self::Jobs, false) => Duration::from_millis(500), } } + + pub fn helper_interval(self, verified: bool) -> std::time::Duration { + match (self, verified) { + // Each refresh verifies both service images over the pipe. A held + // signed time sample remains usable for up to five minutes. + (Self::Jobs, true) => std::time::Duration::from_secs(5), + _ => self.interval(verified), + } + } } fn independent_time_key(time_key_hex: &str, job_key_hex: &str) -> Result<[u8; 32]> { @@ -1637,6 +1646,26 @@ mod tests { } std::fs::remove_dir_all(dir).unwrap(); } + + #[test] + fn helper_sampling_spaces_successes_and_retries_failures_quickly() { + use std::time::Duration; + assert_eq!( + SamplingMode::Jobs.helper_interval(true), + Duration::from_secs(5) + ); + assert_eq!( + SamplingMode::Jobs.helper_interval(false), + Duration::from_millis(500) + ); + for verified in [false, true] { + assert_eq!( + SamplingMode::Passive.helper_interval(verified), + Duration::from_secs(30) + ); + } + } + fn sample(ns: u64) -> Sample { Sample { wall_utc_ns: 1_800_000_000_000_000_000 + ns as i64,