Recover a Windows maintenance setup interrupted before policy activation

This commit is contained in:
2026-11-17 17:32:17 +01:00
parent fe55995154
commit 8c39e79a79
9 changed files with 303 additions and 63 deletions
@@ -70,10 +70,10 @@ $journal=Uuid $Witness.journal_id;$helper=Uuid $Witness.helper_id;$decision=Uuid
$checkpoint=[long]$Witness.helper_checkpoint
Check ($checkpoint -gt 0) 'Missing closed helper checkpoint'
$rows=@($Witness.attempts|Where-Object {$null -ne $_})
$gate=$null;$db=$null;$transaction=$false;$stopped=$false
$gate=$null;$db=$null;$transaction=$false
try {
$gate=[IO.File]::Open((Join-Path $data 'release-job.lock'),'Open','ReadWrite','None')
if((Get-Service $agent).Status -ne 'Stopped'){Stop-Service $agent;$stopped=$true}
if((Get-Service $agent).Status -ne 'Stopped'){Stop-Service $agent}
$apply=$Action -eq 'Apply'
$db=[EnrollmentWindowDb]::new($dbPath,$apply)
if($apply){
@@ -84,9 +84,9 @@ try {
if($apply){Check ($db.Scalar('PRAGMA local.journal_mode') -ceq 'delete') 'Local consumption journal mode differs';$db.Exec('PRAGMA local.synchronous=FULL')}
$db.Exec($(if($apply){'BEGIN IMMEDIATE'}else{'BEGIN'}));$transaction=$true
$done=$db.Scalar("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='retired_windows_update_windows'") -eq '1'
if($done -and $db.Scalar("SELECT count(*) FROM retired_windows_update_windows WHERE case_id='$case' AND helper_id='$helper' AND journal_id='$journal'") -eq '1'){
if($done -and $db.Scalar("SELECT count(*) FROM retired_windows_update_windows WHERE case_id='$case' AND helper_id='$helper' AND journal_id='$journal' AND decision_id='$decision' AND helper_checkpoint=$checkpoint") -eq '1'){
$db.Exec('ROLLBACK');$transaction=$false
[ordered]@{already_retired=$true;case_id=$case;attempts=$rows.Count}|ConvertTo-Json -Compress;return
[ordered]@{already_retired=$true;verified=$true;applied=$true;case_id=$case;helper_id=$helper;decision_id=$decision;attempts=$rows.Count}|ConvertTo-Json -Compress;return
}
Check ($db.Scalar("SELECT count(*) FROM reconcile_meta WHERE id=1 AND journal_id='$journal' AND helper_id='$helper' AND helper_checkpoint=$checkpoint AND last_decision='$decision' AND pending_request IS NULL AND (fault IS NULL OR fault='HELPER_JOURNAL_DISAPPEARED')") -eq '1') 'Agent and signed central final checkpoint differ'
Check ($db.Scalar("SELECT count(*) FROM proof.helper_sync_meta WHERE journal_id='$helper' AND agent_journal_id='$journal' AND checkpoint>=$checkpoint AND last_decision='$decision' AND fault IS NULL") -eq '1') 'Archived helper has not applied the same signed final decision'