From 6953c75cb35934f455fb8f71e1b154bab30826c4 Mon Sep 17 00:00:00 2001 From: emersonbusson <93008583+emersonbusson@users.noreply.github.com> Date: Fri, 18 Sep 2026 09:50:21 +0000 Subject: [PATCH] feat(guardian): handle graceful Ctrl+C with resource cleanup Registers a Console.CancelKeyPress handler in Invoke-GuardianWatch to flush the host telemetry ring and log a guardian_stopped event, ensuring safe exit. --- scripts/windows/Watch-RamSharedWsl.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/windows/Watch-RamSharedWsl.ps1 b/scripts/windows/Watch-RamSharedWsl.ps1 index b1bdbadcc..a65103a36 100644 --- a/scripts/windows/Watch-RamSharedWsl.ps1 +++ b/scripts/windows/Watch-RamSharedWsl.ps1 @@ -833,6 +833,13 @@ function Invoke-GuardianWatch { $eventPath = Join-Path $runDirectory "guardian-events.jsonl" $telemetryPath = Join-Path $ArtifactRoot "windows-telemetry.jsonl" Write-GuardianEvent -Path $eventPath -Event "guardian_started" -Data @{ heartbeat = $HeartbeatPath; stale_after_seconds = $StaleAfterSec } + [Console]::add_CancelKeyPress({ + param($sender, $e) + $e.Cancel = $true + Write-HostTelemetryRing -Path $telemetryPath + Write-GuardianEvent -Path $eventPath -Event "guardian_stopped" -Data @{ reason = "cancel_key_press" } + [Environment]::Exit(0) + }) while ($true) { # A current heartbeat must be observed before any HEALTHY proof can be # published. Never let a boot probe race ahead of stale-heartbeat