{"record":{"id":"d3728fb96cd8e9bd","repo":"Hmbown/CodeWhale","slug":"cloud-agent-harness-exited-with-code-exit-code","errorCode":null,"errorMessage":"Cloud agent harness exited with code {exit_code}: {}","messagePattern":"Cloud agent harness exited with code (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/cloud_dispatch.rs","lineNumber":1678,"sourceCode":"            body,\n        )?;\n        let status = response.status();\n        let text = response.text().unwrap_or_default();\n        if !status.is_success() {\n            bail!(\"Cloud agent harness execution failed (HTTP {status}).\");\n        }\n        let parsed: serde_json::Value = serde_json::from_str(&text)\n            .context(\"the sandbox returned an unreadable harness result\")?;\n        let exit_code = parsed\n            .get(\"exitCode\")\n            .and_then(serde_json::Value::as_i64)\n            .unwrap_or(0);\n        let result = parsed\n            .get(\"result\")\n            .and_then(serde_json::Value::as_str)\n            .unwrap_or(\"\");\n        if exit_code != 0 {\n            bail!(\n                \"Cloud agent harness exited with code {exit_code}: {}\",\n                sanitize_error(result)\n            );\n        }\n        Ok(result.chars().take(MAX_HARNESS_OUTPUT_CHARS).collect())\n    }\n\n    fn collect_patch(&self, receipt: &SandboxReceipt) -> Result<PatchReceipt> {\n        let base_branch = self\n            .run_harness(\n                receipt,\n                &HarnessCommand {\n                    argv: vec![\n                        \"git\".to_string(),\n                        \"rev-parse\".to_string(),\n                        \"--abbrev-ref\".to_string(),\n                        \"origin/HEAD\".to_string(),\n                    ],","sourceCodeStart":1660,"sourceCodeEnd":1696,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/cloud_dispatch.rs#L1660-L1696","documentation":"Thrown by `run_harness` when the harness command executed successfully at the HTTP level but its process exited with a non-zero exit code. The sandbox's `result` text is sanitized and appended to the message, so the message contains the harness's own failure output. This means the agent's command genuinely failed inside the sandbox, not that the transport broke.","triggerScenarios":"Any harness command (setup script, build, patch-extraction git commands) whose shell process exits non-zero: missing tool in the sandbox image, failing tests, git conflicts, script bugs, or out-of-memory kills (exit 137).","commonSituations":"Base image lacking a dependency the script assumes; repository state differing from local (rebuilt from remote head); command timeout producing a killed-process exit code; agent-authored shell commands with typos.","solutions":["Read the sanitized `result` text appended to the message — it names the actual command failure; fix the command or script it reports.","Reproduce the command locally or in a fresh sandbox to see if it depends on uncommitted local state.","If the exit code is 124/137 (timeout/kill), reduce the work per command or raise timeout_secs in the HarnessCommand.","If a required binary is missing, update the sandbox base image or install it in the setup harness step."],"exampleFix":"// before\nHarnessCommand { argv: vec![\"make\", \"release\"], cwd: SANDBOX_WORKSPACE.into(), timeout_secs: 60 }\n// after (tool missing / too slow in sandbox)\nHarnessCommand { argv: vec![\"bash\", \"-lc\", \"cargo build --release\"], cwd: SANDBOX_WORKSPACE.into(), timeout_secs: 600 }","handlingStrategy":"try-catch","validationCode":"// surface the sanitized result text to the user before deciding to retry\nlet msg = err.to_string();\nlet detail = msg.splitn(2, \": \").nth(1).unwrap_or(\"\");","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"exited with code\") => {\n        log_harness_failure(&e.to_string()); // includes sanitized sandbox output\n        // do not blind-retry: the command itself failed\n    }\n    other => other,\n}","preventionTips":["Install all toolchain dependencies in the sandbox base image before running harness commands.","Set realistic timeout_secs per command; 124/137 exit codes mean timeout/killed.","Reproduce commands locally to catch sandbox/local environment drift.","Always read the sanitized output appended to the message — it names the real failure."],"tags":["cloud","sandbox","process","exit-code"],"backgroundTag":"command-not-found","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"}