From 49100f99af530c49e6b5e0492c5a863cac47886f Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 26 Jun 2026 07:22:36 +0000 Subject: [PATCH] fix: end D601 gateway tasks before apply --- scripts/src/hwlab-node-hwpod-preinstall.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/src/hwlab-node-hwpod-preinstall.ts b/scripts/src/hwlab-node-hwpod-preinstall.ts index bf710021..c230df99 100644 --- a/scripts/src/hwlab-node-hwpod-preinstall.ts +++ b/scripts/src/hwlab-node-hwpod-preinstall.ts @@ -110,6 +110,7 @@ interface HwpodGatewayApplyResult { readonly taskName: string; readonly periodicTaskName: string; readonly runTaskExitCode: number | null; + readonly failureDetail?: string; readonly valuesRedacted?: boolean; } @@ -801,6 +802,7 @@ function applyGatewayRuntime( taskName: profile.taskName, periodicTaskName: profile.periodicTaskName, runTaskExitCode: null, + failureDetail: compactResultTail(result), valuesRedacted: true, }; } @@ -814,6 +816,7 @@ function applyGatewayRuntime( taskName: profile.taskName, periodicTaskName: profile.periodicTaskName, runTaskExitCode: null, + failureDetail: short(result.stdout, 500), valuesRedacted: true, }; } @@ -825,6 +828,7 @@ function applyGatewayRuntime( taskName: profile.taskName, periodicTaskName: profile.periodicTaskName, runTaskExitCode: typeof parsed.runTaskExitCode === "number" ? parsed.runTaskExitCode : null, + failureDetail: typeof parsed.failureDetail === "string" && parsed.failureDetail.length > 0 ? short(parsed.failureDetail, 500) : undefined, valuesRedacted: true, }; } @@ -864,6 +868,7 @@ function renderHwpodGatewayPlan(value: HwpodGatewayPlan): string { ["writtenFiles", value.remoteApply.writtenFiles.length], ["stoppedLegacyPids", value.remoteApply.stoppedLegacyPids.join(",") || "-"], ["runTaskExitCode", value.remoteApply.runTaskExitCode ?? "-"], + ["failureDetail", value.remoteApply.failureDetail ?? "-"], ]; return [ `hwlab nodes hwpod-preinstall ${commandAction(value.command)} (${value.status})`, @@ -1142,6 +1147,14 @@ $EnsureVbs = Join-Path $Root 'ensure-node-ws.vbs' $RunTask = 'wscript.exe //B //Nologo "' + $RunVbs + '"' $EnsureTask = 'wscript.exe //B //Nologo "' + $EnsureVbs + '"' New-Item -ItemType Directory -Force -Path $Root, (Join-Path $Root 'logs'), (Join-Path $Root '.state'), (Join-Path $Root 'tools'), (Join-Path $Root 'tools\\src') | Out-Null +function EndTaskIfPresent([string]$Name) { + $task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue + if ($null -eq $task) { return } + if ([string]$task.State -eq 'Running') { + $null = schtasks /End /TN $Name 2>&1 + Start-Sleep -Seconds 2 + } +} function WritePayloadFile($item) { $target = Join-Path $Root ([string]$item.path) $parent = Split-Path -Parent $target @@ -1153,6 +1166,8 @@ function WritePayloadFile($item) { return [string]$item.path } $stopped = @() +EndTaskIfPresent $PeriodicTaskName +EndTaskIfPresent $TaskName $processes = @(Get-CimInstance Win32_Process -Filter "Name='bun.exe'" | Where-Object { ($_.CommandLine -match 'hwpod-node\\.ts\\s+connect') -and ($_.CommandLine -match [regex]::Escape($NodeId)) }) foreach ($proc in $processes) { $stopped += [int]$proc.ProcessId