修复 master CI 的 Codex CLI 失败状态竞态 (#273)
Project CI / Frontend tests (push) Successful in 3m0s
Project CI / Backend tests (push) Successful in 6m29s
Project CI / Repository checks (push) Successful in 2m39s
Project CI / Native shell tests (push) Successful in 20m46s

修复 Codex CLI 子进程提前退出时 stdin BrokenPipe 导致未采集真实退出码的问题。\n\n- BrokenPipe 时继续等待并采集脱敏 stderr\n- 非零退出优先返回真实退出码\n- 保留其他 stdin 错误的快速失败行为\n\n已验证:Codex CLI 失败回归测试、cargo fmt、编码检查、git diff --check。

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/273
Co-authored-by: kdletters <kdletters@qq.com>
Co-committed-by: kdletters <kdletters@qq.com>
This commit was merged in pull request #273.
This commit is contained in:
2026-09-03 17:34:28 +08:00
committed by 段舒康
parent d5e05d79fe
commit 3e034d681d
@@ -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)
}