param([switch]$QwenOnly) $ErrorActionPreference = 'Stop' $taskRoot = 'D:\web\zyt' $phpBinary = 'D:\phpstudy_pro\Extensions\php\php8.2.9nts\php.exe' $expected = @{ qwen = 22252; openai = 22300 } if ($QwenOnly) { $expected.qwen = 37984 } $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $receipt = @() $lanes = if ($QwenOnly) { @('qwen') } else { @('qwen', 'openai') } foreach ($lane in $lanes) { $checkArgs = @("$taskRoot\artifacts\prescription-ai-runtime\retry_qwen.php") if ($lane -eq 'openai') { $checkArgs += '--openai' } $checkText = & $phpBinary @checkArgs if ($LASTEXITCODE -ne 0) { throw "Queue eligibility changed for $lane" } $check = $checkText | ConvertFrom-Json if (-not $check.eligible -or $check.running_model_tasks -ne 0) { throw "Worker is not idle: $lane" } $workers = @(Get-CimInstance Win32_Process -Filter "Name='php.exe'" | Where-Object { $_.CommandLine -match "prescription-ai:work --lane=$lane(?:\s|$)" }) if ($workers.Count -ne 1 -or $workers[0].ProcessId -ne $expected[$lane] -or $workers[0].ExecutablePath -ne $phpBinary) { throw "Worker identity changed: $lane" } Stop-Process -Id $workers[0].ProcessId -ErrorAction Stop Wait-Process -Id $workers[0].ProcessId -Timeout 10 -ErrorAction SilentlyContinue $outPath = "$taskRoot\artifacts\prescription-ai-runtime\$lane-$stamp.stdout.log" $errPath = "$taskRoot\artifacts\prescription-ai-runtime\$lane-$stamp.stderr.log" $started = Start-Process -FilePath $phpBinary -ArgumentList @('think', 'prescription-ai:work', "--lane=$lane") -WorkingDirectory "$taskRoot\server" -WindowStyle Hidden -RedirectStandardOutput $outPath -RedirectStandardError $errPath -PassThru $receipt += [pscustomobject]@{ lane = $lane; old_pid = $workers[0].ProcessId; new_pid = $started.Id; started_at = (Get-Date).ToString('o'); stdout = $outPath; stderr = $errPath } } $receipt | ConvertTo-Json -Depth 3 | Set-Content -LiteralPath "$taskRoot\artifacts\prescription-ai-runtime\model-worker-restart-$stamp.json" -Encoding utf8 $receipt | ConvertTo-Json -Depth 3