fix(cli): codex exec exit-1 no longer discards a valid recon/agent result

`codex exec` in --dangerously-bypass-approvals-and-sandbox mode exits non-zero
when a tool/command it ran internally (curl/nmap/etc.) returned non-zero — even
though it produced a valid final answer. chat_cli treated any non-zero exit as a
hard failure and dropped the output ("recon round 1 failed ... exit 1"). Now, on
non-zero exit WITH usable stdout and no auth/rate/quota keyword, we use the
output; only genuine auth/rate/quota errors (or empty output) fail hard.
This commit is contained in:
CyberSecurityUP
2026-07-10 16:37:00 -03:00
parent 54bf424c1d
commit d9c191ec39
@@ -245,6 +245,19 @@ impl ChatClient {
} else {
"no output".to_string()
};
// Agentic CLIs (esp. `codex exec` in bypass-sandbox mode) exit
// non-zero when a tool/command they ran internally returned non-zero
// (e.g. a curl/nmap that failed) — even though they produced a valid
// final answer. Treat that as success and use the output; only fail
// hard on a genuine auth/rate/quota error or when there's no output.
let low = format!("{stdout}\n{stderr}").to_lowercase();
let hard = ["not logged in", "please log in", "please login", "run /login",
"unauthorized", "not authenticated", "invalid api key", "no api key",
"rate limit", "429", "quota", "credit balance", "usage limit"]
.iter().any(|k| low.contains(k));
if !stdout.is_empty() && !hard {
return Ok(stdout);
}
return Err(anyhow!(
"{} subscription CLI exit {}: {}",
bin,