Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): confirm transient Windows process exits during recovery

Chrisac34415a798d
diff --git a/docs/research/pi-subagent-delegation.md b/docs/research/pi-subagent-delegation.md
index aebbe4037e..61a35de6f0 100644
--- a/docs/research/pi-subagent-delegation.md
+++ b/docs/research/pi-subagent-delegation.md
@@ -23,7 +23,8 @@ parentSessionId、runDir 和全部 child/session/agent 身份,并确认所有
进程清单确认 run UUID 对应的 runner 与所有 native session ID 对应的 Pi 子进程均已消失,
包括 runner 已退出但子进程仍存活的情况。清单查询失败、超时、截断,或无法确认本账号
进程可见性时保留未知;Windows 使用系统的当前用户过滤取得 PID 集合,再逐项核验 CIM
-命令行,任一缺失或不可读都不放行,不把其他账号的受保护系统进程混入当前账号证明。
+命令行;若进程在两次查询之间消失或命令行不可读,必须再由 OS 独立确认该 PID 已退出。
+仍存活但不可读或存活查询失败都不放行,不把其他账号的受保护系统进程混入当前账号证明。
仅排除本次启动的 `tasklist` 查询进程自身 PID,避免它正常退出后使清单永久不完整。
查询是只读核验,不向清单里的 PID 发信号。同一次扫描复用清单,下次扫描重新读取。
续跑使用新 run UUID;复用 native session ID 的活跃子进程仍保守视为未结束。
diff --git a/packages/maker-core/src/agents/pi/pi-subagent-runs.ts b/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
index dd0dc7ff72..41002b9c43 100644
--- a/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
+++ b/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
@@ -3123,8 +3123,9 @@ async function terminalResultProcessIdentities(
* Empty/failed/truncated probes are unknown, not proof of absence. Windows can
* omit command lines for protected processes in other accounts. Use the OS
* user filter first (tasklist /FI USERNAME, like POSIX ps -u), then require a
- * readable command line for every selected PID. A missing/inaccessible own
- * process keeps recovery closed; PID discovery never authorizes a kill.
+ * readable command line or independent exit confirmation for every selected
+ * PID. An inaccessible live process keeps recovery closed; PID discovery never
+ * authorizes a kill.
*/
async function readRecoveryProcessInventory(deadline: number): Promise<string[] | null> {
try {
@@ -3164,11 +3165,25 @@ async function readRecoveryProcessInventory(deadline: number): Promise<string[]
'foreach ($item in $items) {',
' $number = [int]$item.ProcessId',
' if (-not $processIds.ContainsKey($number)) { continue }',
- ' if ([string]::IsNullOrWhiteSpace($item.CommandLine)) { $complete = $false; break }',
+ ' if ([string]::IsNullOrWhiteSpace($item.CommandLine)) { continue }',
' $commands.Add($item.CommandLine)',
' $processIds.Remove($number)',
'}',
- '@{ complete = ($complete -and $processIds.Count -eq 0); commands = @($commands.ToArray()); count = $count } | ConvertTo-Json -Compress',
+ // Other short-lived processes can exit between tasklist and CIM too.
+ // Missing command lines alone are not exit evidence; independently
+ // check each remaining PID. Only an exited process can leave the count.
+ 'foreach ($number in @($processIds.Keys)) {',
+ ' $unreadable = $null',
+ ' try {',
+ ' $unreadable = [System.Diagnostics.Process]::GetProcessById($number)',
+ ' if ($unreadable.HasExited) { $count-- } else { $complete = $false }',
+ ' } catch [System.ArgumentException] {',
+ ' $count--',
+ ' } finally {',
+ ' if ($null -ne $unreadable) { $unreadable.Dispose() }',
+ ' }',
+ '}',
+ '@{ complete = $complete; commands = @($commands.ToArray()); count = $count } | ConvertTo-Json -Compress',
].join('\n');
const { stdout } = await execFileAsync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
encoding: 'utf8', timeout: Math.min(DEFAULT_KILL_BUDGET_MS, remaining), maxBuffer: 4 * 1024 * 1024, windowsHide: true,