{"record":{"id":"d9b0470726d17a06","repo":"Hmbown/CodeWhale","slug":"exec-turn-failed-error-agent","errorCode":null,"errorMessage":"exec turn failed: {error}","messagePattern":"exec turn failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/exec_agent.rs","lineNumber":1444,"sourceCode":"    if json_output {\n        println!(\"{}\", serde_json::to_string_pretty(&summary)?);\n    }\n\n    if let Some(error) = summary.error.as_ref()\n        && !error.trim().is_empty()\n    {\n        // Distinguish retryable infrastructure failures (provider/transport,\n        // after all in-session retries are exhausted) from genuine task\n        // failures so supervisors and bench harnesses can tell them apart at\n        // the process level without parsing the stream. Genuine failures\n        // keep the historical `bail!` → exit 1 path.\n        let exit_code = exec_failure_exit_code(summary.error_category.as_deref());\n        if exit_code != 1 {\n            eprintln!(\"Error: exec turn failed: {error}\");\n            let _ = io::stdout().flush();\n            std::process::exit(exit_code);\n        }\n        bail!(\"exec turn failed: {error}\");\n    }\n\n    if matches!(\n        summary.status.as_deref(),\n        Some(\"failed\" | \"canceled\" | \"interrupted\")\n    ) {\n        let status = summary.status.as_deref().unwrap_or(\"unknown\");\n        bail!(\"exec turn ended with status {status}\");\n    }\n\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::{ExecAgentEvents, exec_automation_services, exec_disallowed_tools};\n    use crate::core::engine::mock_engine_handle;\n    use crate::core::engine::tool_catalog::REQUEST_USER_INPUT_NAME;","sourceCodeStart":1426,"sourceCodeEnd":1462,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/exec_agent.rs#L1426-L1462","documentation":"When a CLI exec turn fails with an error category that maps to a non-1 exit code, run_exec_agent prints the failure to stderr and exits the process directly with that code; for the category that maps to exit code 1 it instead returns this anyhow error from the function. Either way the message surfaces the underlying turn error to the caller of the exec entrypoint.","triggerScenarios":"A `codewhale exec` turn fails (provider error, tool failure, aborted turn) and `exec_failure_exit_code(summary.error_category)` yields 1 — the error is propagated as `bail!(\"exec turn failed: {error}\")`.","commonSituations":"Transient upstream/API errors during scripted exec runs; a misconfigured provider route in headless/CI usage; the prompt triggered a tool that failed and the turn aborted with a generic error category.","solutions":["Read the `{error}` text in the message/preceding stderr output to identify the underlying turn failure and fix that cause.","For provider/API errors, verify the configured route (provider, model, API key) is valid and reachable.","Retry the exec command if the failure was transient; non-1 exit codes are returned as process exit codes for that purpose.","Inspect summary.error_category to map the failure to its documented exit code and handling in your script."],"exampleFix":"// before (scripting blindly)\ncodewhale exec \"prompt\"\n// after\ncodewhale exec \"prompt\" || { echo \"exec failed: $?\"; retry_or_alert; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match codewhale_exec_status {\n    0 => {}, // success\n    code @ 2.. => { eprintln!(\"exec failed with categorized exit {code}; see stderr\"); }\n    _ => { eprintln!(\"exec turn failed (exit 1): inspect the error text\"); }\n}","preventionTips":["Validate provider routes and API keys before headless runs.","Retry transient failures with backoff keyed on the categorized exit code.","Capture stderr, since non-1 categories print the error there before exiting."],"tags":["exec","cli","turn-loop","exit-code"],"backgroundTag":"api-request-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}