{"record":{"id":"1939df0a792183dc","repo":"jlcodes99/cockpit-tools","slug":"timedout","errorCode":"TimedOut","errorMessage":"PowerShell 进程探测超时（{}ms）","messagePattern":"PowerShell 进程探测超时（(.+?)ms）","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"warning","filePath":"crates/cockpit-core/src/modules/process_core_discovery.rs","lineNumber":460,"sourceCode":"            if let Some(mut out) = child.stdout.take() {\n                let _ = out.read_to_end(&mut stdout);\n            }\n            if let Some(mut err) = child.stderr.take() {\n                let _ = err.read_to_end(&mut stderr);\n            }\n            let result = Ok(std::process::Output {\n                status,\n                stdout,\n                stderr,\n            });\n            log_command_trace_result(&preview, &result, start.elapsed());\n            return result;\n        }\n\n        if start.elapsed() >= timeout {\n            let _ = child.kill();\n            let _ = child.wait();\n            let result = Err(Error::new(\n                ErrorKind::TimedOut,\n                format!(\"PowerShell 进程探测超时（{}ms）\", timeout.as_millis()),\n            ));\n            log_command_trace_result(&preview, &result, start.elapsed());\n            return result;\n        }\n\n        thread::sleep(Duration::from_millis(100));\n    }\n}\n\n#[cfg(target_os = \"windows\")]\nfn cmd_output(args: &[&str]) -> std::io::Result<std::process::Output> {\n    use std::os::windows::process::CommandExt;\n\n    let mut command = Command::new(\"cmd\");\n    command.creation_flags(CREATE_NO_WINDOW).args(args);\n    let preview = format_command_preview(&command);","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/crates/cockpit-core/src/modules/process_core_discovery.rs#L442-L478","documentation":"`powershell_output_with_timeout` spawns a PowerShell child process to enumerate application processes; if the child does not finish within the configured timeout, it is killed and an `std::io::Error` with `ErrorKind::TimedOut` and message \"PowerShell 进程探测超时（{N}ms）\" is returned. Callers (`collect_*_process_entries_from_powershell` for Codex, Antigravity, CodeBuddy, WorkBuddy) then fail their process discovery step.","triggerScenarios":"PowerShell startup or the process query takes longer than the timeout budget — cold PowerShell first-run (profile loading, .NET JIT), heavily loaded CPU, or a very large number of running processes making the WMI/CIM query slow.","commonSituations":"First invocation after boot on Windows when PowerShell is not warm; antivirus scanning powershell.exe on launch; slow machines with hundreds of processes; overly tight timeout constants.","solutions":["Retry the discovery call — a warm PowerShell usually completes well within the timeout on the second run.","Increase the timeout constant passed to `powershell_output_with_timeout` (e.g. 3s → 10s).","Launch PowerShell with `-NoProfile` to skip slow profile scripts.","Reduce the query cost (narrow the WMI/CIM filter) so enumeration finishes faster."],"exampleFix":"// before\nlet entries = collect_codex_process_entries_from_powershell()?;\n// after\nlet entries = match collect_codex_process_entries_from_powershell() {\n    Ok(e) => e,\n    Err(e) if e.kind() == std::io::ErrorKind::TimedOut => {\n        log::warn!(\"process discovery timed out, retrying once\");\n        collect_codex_process_entries_from_powershell().unwrap_or_default()\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// best-effort pre-check (Windows)\n// ensure powershell.exe resolves before the timed call\nwhich::which(\"powershell\").map_err(|_| std::io::Error::new(std::io::ErrorKind::NotFound, \"powershell not on PATH\"))?","typeGuard":"fn is_probe_timeout(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::TimedOut && e.to_string().contains(\"PowerShell 进程探测超时\")\n}","tryCatchPattern":"match powershell_output_with_timeout(&mut child, timeout) {\n    Ok(out) => out,\n    Err(e) if e.kind() == std::io::ErrorKind::TimedOut => {\n        log::warn!(\"probe timed out; retrying with warm powershell\");\n        retry_once_or_default()\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Spawn PowerShell with -NoProfile to avoid slow profile load.","Warm up PowerShell once at app start so later probes are fast.","Set a generous timeout (>= 5-10s) with a single retry.","Degrade gracefully: return an empty process list instead of failing the whole discovery."],"tags":["rust","windows","powershell","timeout","process-discovery"],"backgroundTag":"process-probe-timeout","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}