diff --git a/crates/agent-core/src/reconcile.rs b/crates/agent-core/src/reconcile.rs index 285583d..276aa73 100644 --- a/crates/agent-core/src/reconcile.rs +++ b/crates/agent-core/src/reconcile.rs @@ -399,7 +399,8 @@ impl ClientSync { ); for row in ¤t { ensure!( - terminal(&row.state) && row.update_handoff_bytes.is_empty(), + matches!(row.state.as_str(), "succeeded" | "failed" | "cancelled" | "expired") + && row.update_handoff_bytes.is_empty(), "CLOSED_CONTROL_DEFINITIVE_ONLY" ); let old = original diff --git a/crates/agent-windows/src/helper_system.rs b/crates/agent-windows/src/helper_system.rs index 440b536..0b830b7 100644 --- a/crates/agent-windows/src/helper_system.rs +++ b/crates/agent-windows/src/helper_system.rs @@ -1091,6 +1091,7 @@ impl SystemHelper { serde_json::from_slice(&response.decision_bytes)?; self.clock .require_generation(decision.connection_generation)?; + let started = Instant::now(); self.wait_apply_clock(decision.issued_at,decision.valid_until)?; self.sync()?; let value = if let Some(grant)=crate::update_control::active_grant(&self.db)? { @@ -1099,7 +1100,21 @@ impl SystemHelper { &self.clock,&self.pin,&budget,grant)?; self.sync.as_mut().unwrap().apply(&mut self.db,&guard,response,request_bytes,&self.clock,&self.boot)? } else { - self.sync.as_mut().unwrap().apply(&mut self.db,&self.guard,response,request_bytes,&self.clock,&self.boot)? + // Refresh only a clock read that the core proves failed before + // its first transaction. Keep the original capture and deadline. + loop { + let result = self.sync.as_mut().unwrap().apply( + &mut self.db, &self.guard, response, request_bytes, + &self.clock, &self.boot, + ); + match result { + Err(error) if rmm_agent_core::helper_reconcile::retryable_precommit_clock(&error) + && started.elapsed() < Duration::from_secs(3) => { + std::thread::sleep(Duration::from_millis(20)); + } + other => break other?, + } + } }; let no_start_anchor = if value.ready && (self.settings.enable_effects diff --git a/crates/agent-windows/src/release_service_switch.ps1 b/crates/agent-windows/src/release_service_switch.ps1 index 3d60d56..5089252 100644 --- a/crates/agent-windows/src/release_service_switch.ps1 +++ b/crates/agent-windows/src/release_service_switch.ps1 @@ -24,7 +24,7 @@ function Replace-Pin([string]$Path, [string]$Value) { $temp = "$Path.next-$([Guid]::NewGuid())" try { [IO.File]::WriteAllText($temp, $Value, [Text.UTF8Encoding]::new($false)) - [IO.File]::Replace($temp, $Path, $null) + [IO.File]::Replace($temp, $Path, [NullString]::Value) } finally { if (Test-Path -LiteralPath $temp) { Remove-Item -LiteralPath $temp } } diff --git a/crates/agent-windows/src/runtime.rs b/crates/agent-windows/src/runtime.rs index d7619d7..82f64d1 100644 --- a/crates/agent-windows/src/runtime.rs +++ b/crates/agent-windows/src/runtime.rs @@ -1784,20 +1784,40 @@ impl Agent { let prepared = sync.prepare( self.journal.connection_mut(), self.ledger.as_ref().context("LEDGER_REQUIRED")?, - context, + context.clone(), helper, &self.clock, ); #[cfg(feature = "system-helper")] - if helper.is_some() - && prepared - .as_ref() - .is_err_and(|error| error.to_string() == "SYSTEM_HELPER_APPLY_UNCONFIRMED") - { - // This authenticated readback already established why another - // capture cannot advance this channel. - self.helper_apply_unconfirmed = true; - } + let prepared = match (prepared, helper) { + (Err(error), Some(snapshot)) if error.to_string() == "SYSTEM_HELPER_APPLY_UNCONFIRMED" => { + self.helper_apply_unconfirmed = true; + // The helper supplied a fresh authenticated snapshot on its serialized + // lane. Only an idle actor may ask the core to prove an exact missed ACK. + if self.running.is_some() || self.prepared || self.deferred_sync.is_some() + || self.deferred_permit.is_some() || self.helper_control.is_some() + || self.helper_probe.is_some() || self.update_pending + || self.update_prefetch.is_some() || self.update_health.is_some() + { + return Err(error); + } + use rmm_agent_windows::helper_runtime::intent; + let idle = if Path::new(intent::DB).try_exists()? { + intent::Store::open(false)?.pending()?.is_empty() + } else { + snapshot.attempts.is_empty() + }; + if !idle { + return Err(error); + } + sync.prepare_with_closed_control_idle( + self.journal.connection_mut(), + self.ledger.as_ref().context("LEDGER_REQUIRED")?, + context, Some(snapshot), &self.clock, true, + ) + } + (ordinary, _) => ordinary, + }; let prepared = prepared?; #[cfg(feature = "system-helper")] {