"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(desktop): preserve Windows process exit evidence
Haozhe Wu8a0e90b840ca
diff --git a/.github/workflows/desktop-windows.yml b/.github/workflows/desktop-windows.ymlindex ad2664690..98801ccc2 100644--- a/.github/workflows/desktop-windows.yml+++ b/.github/workflows/desktop-windows.yml@@ -66,6 +66,11 @@ jobs:working-directory: desktop/electronrun: npm run smoke:credentials+ - name: Verify bounded native process adapter+ working-directory: desktop/electron+ shell: powershell+ run: .\scripts\test-process-utils.ps1+- name: Assemble minimal Python runtimeworking-directory: desktop/electronshell: powershelldiff --git a/desktop/electron/WINDOWS_PACKAGING.md b/desktop/electron/WINDOWS_PACKAGING.mdindex 77f79048c..96b01af7f 100644--- a/desktop/electron/WINDOWS_PACKAGING.md+++ b/desktop/electron/WINDOWS_PACKAGING.md@@ -38,6 +38,7 @@ cd ..\desktop\electronnpm cinpm run prepare:electronnpm run smoke:credentials+powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/test-process-utils.ps1npm run runtime:win -- -Cleannpm run smoke:lifecyclenpm run installer:win:reviewdiff --git a/desktop/electron/scripts/build-backend.ps1 b/desktop/electron/scripts/build-backend.ps1index 0000a16c4..98bff72e5 100644--- a/desktop/electron/scripts/build-backend.ps1+++ b/desktop/electron/scripts/build-backend.ps1@@ -25,6 +25,8 @@ $gtkInstallerUrl = "https://github.com/tschoonj/GTK-for-Windows-Runtime-Environm$gtkInstallerSha256 = 'd05e1488ca0e6ffaabb579bbeb82113c099152ca4260ebc63084b0dd174d4558'$gtkExtractRoot = Join-Path $gtkCacheRoot 'archive-runtime-v1'+. (Join-Path $PSScriptRoot 'process-utils.ps1')+function Get-VerifiedDownload {param([Parameter(Mandatory)][string]$Uri,@@ -92,38 +94,6 @@ function Resolve-SevenZip {throw '7z.exe is required to extract the checksum-pinned GTK archive without executing its legacy installer.'}-function Invoke-BoundedProcess {- param(- [Parameter(Mandatory)][string]$FilePath,- [Parameter(Mandatory)][string]$Arguments,- [Parameter(Mandatory)][int]$TimeoutSeconds,- [Parameter(Mandatory)][string]$Label- )-- $process = $null- try {- $process = Start-Process `- -FilePath $FilePath `- -ArgumentList $Arguments `- -NoNewWindow `- -PassThru- if (-not $process.WaitForExit($TimeoutSeconds * 1000)) {- $taskkill = Join-Path $env:SystemRoot 'System32\taskkill.exe'- & $taskkill /PID $process.Id /T /F | Out-Null- $process.WaitForExit(10000) | Out-Null- throw "$Label timed out after $TimeoutSeconds seconds."- }- if ($process.ExitCode -ne 0) {- throw "$Label failed (exit code $($process.ExitCode))."- }- }- finally {- if ($process) {- $process.Dispose()- }- }-}-if (-not $BuildPython) {$repoVenvPython = Join-Path $repoRoot '.venv\Scripts\python.exe'if (Test-Path -LiteralPath $repoVenvPython) {diff --git a/desktop/electron/scripts/process-utils.ps1 b/desktop/electron/scripts/process-utils.ps1new file mode 100644index 000000000..2cede0d74--- /dev/null+++ b/desktop/electron/scripts/process-utils.ps1@@ -0,0 +1,44 @@+function Invoke-BoundedProcess {+ [CmdletBinding()]+ param(+ [Parameter(Mandatory)][string]$FilePath,+ [Parameter(Mandatory)][string]$Arguments,+ [Parameter(Mandatory)][ValidateRange(1, 2147483)][int]$TimeoutSeconds,+ [Parameter(Mandatory)][string]$Label+ )++ # Windows PowerShell 5.1 can return a Process object with a null ExitCode+ # for Start-Process -PassThru -NoNewWindow (PowerShell/PowerShell#20400).+ # Use the .NET process API directly so timeout and exit-code evidence both+ # come from the same live process handle on every supported Windows image.+ $startInfo = [Diagnostics.ProcessStartInfo]::new()+ $startInfo.FileName = $FilePath+ $startInfo.Arguments = $Arguments+ $startInfo.UseShellExecute = $false+ $startInfo.CreateNoWindow = $true++ $process = [Diagnostics.Process]::new()+ $process.StartInfo = $startInfo+ try {+ if (-not $process.Start()) {+ throw "$Label failed to start."+ }+ if (-not $process.WaitForExit($TimeoutSeconds * 1000)) {+ $taskkill = Join-Path $env:SystemRoot 'System32\taskkill.exe'+ & $taskkill /PID $process.Id /T /F | Out-Null+ $process.WaitForExit(10000) | Out-Null+ throw "$Label timed out after $TimeoutSeconds seconds."+ }++ # The parameterless wait flushes final process state before ExitCode is+ # read. It returns immediately because the bounded wait already ended.+ $process.WaitForExit()+ $exitCode = [int]$process.ExitCode+ if ($exitCode -ne 0) {+ throw "$Label failed (exit code $exitCode)."+ }+ }+ finally {+ $process.Dispose()+ }+}diff --git a/desktop/electron/scripts/test-process-utils.ps1 b/desktop/electron/scripts/test-process-utils.ps1new file mode 100644index 000000000..68d91783c--- /dev/null+++ b/desktop/electron/scripts/test-process-utils.ps1@@ -0,0 +1,56 @@+$ErrorActionPreference = 'Stop'++. (Join-Path $PSScriptRoot 'process-utils.ps1')++$commandPrompt = Join-Path $env:SystemRoot 'System32\cmd.exe'++Invoke-BoundedProcess `+ -FilePath $commandPrompt `+ -Arguments '/d /s /c "exit 0"' `+ -TimeoutSeconds 5 `+ -Label 'zero-exit probe'++$nonZeroObserved = $false+try {+ Invoke-BoundedProcess `+ -FilePath $commandPrompt `+ -Arguments '/d /s /c "exit 7"' `+ -TimeoutSeconds 5 `+ -Label 'non-zero probe'+}+catch {+ if ($_.Exception.Message -ne 'non-zero probe failed (exit code 7).') {+ throw+ }+ $nonZeroObserved = $true+}+if (-not $nonZeroObserved) {+ throw 'The bounded process adapter accepted a non-zero exit code.'+}++$timeoutObserved = $false+$stopwatch = [Diagnostics.Stopwatch]::StartNew()+try {+ Invoke-BoundedProcess `+ -FilePath $commandPrompt `+ -Arguments '/d /s /c "ping.exe -n 6 127.0.0.1 >NUL"' `+ -TimeoutSeconds 1 `+ -Label 'timeout probe'+}+catch {+ if ($_.Exception.Message -ne 'timeout probe timed out after 1 seconds.') {+ throw+ }+ $timeoutObserved = $true+}+finally {+ $stopwatch.Stop()+}+if (-not $timeoutObserved) {+ throw 'The bounded process adapter accepted a process that exceeded its timeout.'+}+if ($stopwatch.Elapsed.TotalSeconds -ge 12) {+ throw "The timeout probe took too long to terminate: $($stopwatch.Elapsed.TotalSeconds) seconds."+}++Write-Host 'Bounded native process exit-code and timeout handling: OK'