Wait for the SYSTEM helper's own clock before sync apply
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-16 13:39:57 +01:00
parent 10dce856bf
commit f54872af8e
6 changed files with 332 additions and 1 deletions
+31
View File
@@ -843,6 +843,7 @@ pub struct SystemHelper {
boot: WindowsBoot,
sync: Option<HelperSync<DalekVerifier>>,
last_diagnostic: Option<Instant>,
last_apply_diagnostic: Option<Instant>,
unsettled_msi: Option<UnsettledMsi>,
}
impl SystemHelper {
@@ -867,6 +868,7 @@ impl SystemHelper {
boot,
sync,
last_diagnostic: None,
last_apply_diagnostic: None,
unsettled_msi: None,
})
}
@@ -920,6 +922,30 @@ impl SystemHelper {
);
Ok(())
}
fn wait_apply_clock(&self,issued:chrono::DateTime<chrono::Utc>,until:chrono::DateTime<chrono::Utc>)->Result<()> {
crate::job_readiness::wait_for_helper_apply_clock(&self.clock,issued,until)
}
/// Passive, bounded static denial metadata only. Never feeds a gate.
fn record_apply_error(&mut self,error:&anyhow::Error)->Result<()> {
if self.last_apply_diagnostic.is_some_and(|at|at.elapsed()<Duration::from_secs(5)){return Ok(());}
self.last_apply_diagnostic=Some(Instant::now());self.recheck()?;
const CODES:&[&str]=&["SYSTEM_APPLY_CLOCK_WAIT_EXPIRED","SYSTEM_APPLY_ORIGINAL_DEADLINE_EXPIRED","SYNC_PROFILE_OR_CLOCK","FRESH_PROCESS_SNAPSHOT_REQUIRED","OLD_PROCESS_DECISION_OR_BOOT","ROOT_SNAPSHOT_REQUEST_MISMATCH","TIME_RUNTIME_NO_EVIDENCE","TIME_NATIVE_NO_EVIDENCE","TIME_STALE_RESPONSE","TIME_NATIVE_EVIDENCE_INVALIDATED","TIME_SOURCE_AGE_AT_CHECK","TIME_LOCAL_WALL_OUTSIDE_BOUND","TIME_NATIVE_CONFIG_CHANGED","TIME_RUNTIME_CONNECTION_CHANGED","TIME_RUNTIME_GENERATION"];
let code=error.chain().find_map(|e|CODES.iter().copied().find(|c|*c==e.to_string())).unwrap_or("SYSTEM_APPLY_VALIDATION_OR_STORAGE_FAILURE");
let path=Path::new(STATE_ROOT).join("apply-last-error.json");
let pending=Path::new(STATE_ROOT).join(".apply-last-error.pending");
let writers=[self.settings.helper.service_sid.clone()];
if path.try_exists()?{let _old=PinnedFile::open(&path,false,&[],&writers,false)?;}
let bytes=serde_json::to_vec(&serde_json::json!({"schema_version":1,"observed_at_utc":chrono::Utc::now(),"helper_pid":std::process::id(),"code":code,"ready":false,"diagnostic_only":true}))?;
ensure!(bytes.len()<=1024,"SYSTEM_APPLY_DIAGNOSTIC_LIMIT");
use std::io::Write;
let mut file=OpenOptions::new().write(true).create_new(true).open(&pending)?;
let identity=ipc::file_identity(&file)?;
{let _check=PinnedFile::open_read_shared(&pending,false,&[],&writers)?;}
file.write_all(&bytes)?;file.sync_all()?;drop(file);
std::fs::rename(&pending,&path)?;
let checked=PinnedFile::open(&path,false,&[],&writers,false)?;
ensure!(checked.identity==identity,"SYSTEM_APPLY_DIAGNOSTIC_REPLACED");Ok(())
}
fn recheck(&mut self) -> Result<()> {
ipc::require_self(&self.settings.helper)?;
for file in &mut self.files {
@@ -996,6 +1022,10 @@ impl SystemHelper {
serde_json::from_slice(&response.decision_bytes)?;
self.clock
.require_generation(decision.connection_generation)?;
// Same authenticated original call, BEFORE any application.
// The independent time pipe continues on its own thread.
// No signature/deadline/lease is relaxed and no Execute retry.
self.wait_apply_clock(decision.issued_at,decision.valid_until)?;
self.sync()?;
let value = self.sync.as_mut().unwrap().apply(
&mut self.db,
@@ -1084,6 +1114,7 @@ impl SystemHelper {
let body = match result {
Ok(body) => body,
Err(e) => {
if matches!(call.operation,Operation::Apply{..}) {let _diagnostic=self.record_apply_error(&e);}
if let Some(sync) = &mut self.sync {
sync.close();
}