From 1982756c6d7ac987a45c379ace290b1ad3be825b Mon Sep 17 00:00:00 2001 From: kdletters Date: Thu, 3 Sep 2026 16:47:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Codex=20CLI=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=8A=B6=E6=80=81=E9=87=87=E9=9B=86=E7=AB=9E=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BrokenPipe 时继续采集子进程退出状态 保留 stderr 脱敏摘要并避免泄露原始错误 --- .../src-tauri/src/agent/codex_cli.rs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs index 15d7d45c0..c010e69bc 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs @@ -666,12 +666,27 @@ async fn request_game_creator_agent_codex_cli_with_executable( let mut stdin = child.stdin.take().ok_or_else(|| { platform_llm::LlmError::Transport("Codex CLI Agent stdin 未建立".to_string()) })?; - stdin.write_all(prompt.as_bytes()).await.map_err(|error| { - platform_llm::LlmError::Transport(format!("写入 Codex CLI Agent prompt 失败:{error}")) - })?; - stdin.shutdown().await.map_err(|error| { - platform_llm::LlmError::Transport(format!("关闭 Codex CLI Agent stdin 失败:{error}")) - })?; + // 短生命周期 CLI 可能在 prompt 写完前退出;继续采集退出状态和脱敏 + // stderr,确保调用方拿到可行动的进程错误,而不是平台相关的 BrokenPipe。 + let mut stdin_error = None; + if let Err(error) = stdin.write_all(prompt.as_bytes()).await { + if error.kind() == std::io::ErrorKind::BrokenPipe { + stdin_error = Some(format!("写入 Codex CLI Agent prompt 失败:{error}")); + } else { + return Err(platform_llm::LlmError::Transport(format!( + "写入 Codex CLI Agent prompt 失败:{error}" + ))); + } + } + if let Err(error) = stdin.shutdown().await { + if error.kind() == std::io::ErrorKind::BrokenPipe { + stdin_error.get_or_insert_with(|| format!("关闭 Codex CLI Agent stdin 失败:{error}")); + } else { + return Err(platform_llm::LlmError::Transport(format!( + "关闭 Codex CLI Agent stdin 失败:{error}" + ))); + } + } drop(stdin); let stdout = child.stdout.take().ok_or_else(|| { @@ -744,6 +759,9 @@ async fn request_game_creator_agent_codex_cli_with_executable( stderr.sha256 ))); } + if let Some(error) = stdin_error { + return Err(platform_llm::LlmError::Transport(error)); + } parse_game_creator_codex_cli_response(&stdout, &request) } -- 2.52.0