From fe276d95ffeb4269f3f8c9366a3da0656d52a7f6 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 29 Jun 2026 20:05:58 +0300 Subject: [PATCH] Keep Windows training agent alive --- tools/install_windows_training_agent.ps1 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/install_windows_training_agent.ps1 b/tools/install_windows_training_agent.ps1 index fc82c8b..b67a5b6 100644 --- a/tools/install_windows_training_agent.ps1 +++ b/tools/install_windows_training_agent.ps1 @@ -3,7 +3,8 @@ param( [string]$TaskName = "TradeBot Windows Training Agent", [string]$ApiBaseUrl = "https://tb.kusoft.xyz", [string]$ApiAuth = "", - [int]$PollSeconds = 60, + [int]$PollSeconds = 10, + [int]$WatchdogMinutes = 5, [string]$RepoRoot = "", [switch]$StartNow, [switch]$KeepLegacyRetrainer @@ -59,6 +60,7 @@ if (-not $KeepLegacyRetrainer) { } $python = Resolve-Python +$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $arguments = @( "-u", "`"$Agent`"", @@ -68,9 +70,17 @@ $arguments = @( ) -join " " $action = New-ScheduledTaskAction -Execute $python -Argument $arguments -WorkingDirectory $RepoRoot -$trigger = New-ScheduledTaskTrigger -AtLogOn -User ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) +$trigger = @( + New-ScheduledTaskTrigger -AtLogOn -User $currentUser + New-ScheduledTaskTrigger -AtStartup + New-ScheduledTaskTrigger ` + -Once ` + -At (Get-Date).AddMinutes(1) ` + -RepetitionInterval (New-TimeSpan -Minutes $WatchdogMinutes) ` + -RepetitionDuration (New-TimeSpan -Days 3650) +) $principal = New-ScheduledTaskPrincipal ` - -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) ` + -UserId $currentUser ` -LogonType Interactive ` -RunLevel Limited $settings = New-ScheduledTaskSettingsSet ` @@ -78,6 +88,8 @@ $settings = New-ScheduledTaskSettingsSet ` -MultipleInstances IgnoreNew ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries ` + -RestartCount 999 ` + -RestartInterval (New-TimeSpan -Minutes 1) ` -ExecutionTimeLimit (New-TimeSpan -Days 30) Register-ScheduledTask ` @@ -93,6 +105,6 @@ if ($StartNow) { Start-ScheduledTask -TaskName $TaskName } -Write-Host "Registered scheduled task '$TaskName' for Windows logon." +Write-Host "Registered scheduled task '$TaskName' for Windows startup, logon, and watchdog restarts." Write-Host "Agent API: $ApiBaseUrl" Write-Host "Agent script: $Agent"