{"record":{"id":"0e3e412d6a390aea","repo":"Hmbown/CodeWhale","slug":"turn-failed","errorCode":null,"errorMessage":"turn failed","messagePattern":"turn failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/app-server/src/lib.rs","lineNumber":1884,"sourceCode":"        let (last_seq, status, error) = stream_result?;\n        self.last_seq_by_thread\n            .insert(thread_id.to_string(), last_seq);\n\n        match status {\n            TurnTerminalStatus::Completed => Ok(json!({\n                \"thread_id\": thread_id,\n                \"status\": \"accepted\",\n                \"thread\": Value::Null,\n                \"threads\": [],\n                \"model\": Value::Null,\n                \"model_provider\": Value::Null,\n                \"cwd\": Value::Null,\n                \"approval_policy\": Value::Null,\n                \"sandbox\": Value::Null,\n                \"events\": [],\n                \"data\": { \"turn_id\": turn_id },\n            })),\n            TurnTerminalStatus::Failed => Err(anyhow!(\n                \"{}\",\n                error.unwrap_or_else(|| \"turn failed\".to_string())\n            )),\n            TurnTerminalStatus::Interrupted => Err(anyhow!(\n                \"{}\",\n                error.unwrap_or_else(|| \"turn interrupted\".to_string())\n            )),\n            TurnTerminalStatus::Canceled => Err(anyhow!(\n                \"{}\",\n                error.unwrap_or_else(|| \"turn canceled\".to_string())\n            )),\n        }\n    }\n\n    async fn stream_turn_events<W: AsyncWrite + Unpin>(\n        &self,\n        thread_id: &str,\n        turn_id: &str,","sourceCodeStart":1866,"sourceCodeEnd":1902,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/app-server/src/lib.rs#L1866-L1902","documentation":"Raised when a runtime API turn terminates with `TurnTerminalStatus::Failed`. The handler maps the terminal event to a Rust error, using the error message carried in the turn event when present, and falling back to the literal string \"turn failed\" when the upstream event supplies no error text. It is the propagation point for runtime-side turn failures into the caller's anyhow error.","triggerScenarios":"A turn processed through the runtime API reaches the Failed terminal status in its event stream, and the event payload contains no `error` message.","commonSituations":"Model/provider errors inside the runtime, invalid turn input rejected mid-run, runtime crashes during turn execution, or network failures on the runtime side where no structured error is attached.","solutions":["Inspect the runtime API session logs around the failed turn for the underlying cause, since the error text here is a generic fallback.","Check that the thread's model/provider configuration is valid and the provider is reachable.","Retry the turn; transient provider or runtime failures often resolve on retry.","If reproducible, capture the turn event stream (the `data: {turn_id}` event) and report the runtime-side failure details."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_turn(...).await {\n    Err(e) if e.to_string().contains(\"turn failed\") => {\n        // inspect runtime logs; retry with backoff if transient\n    }\n    other => other?,\n}","preventionTips":["Keep provider credentials and model config validated before starting turns","Monitor runtime logs for the real underlying failure","Implement bounded retry for transient provider errors"],"tags":["turn","runtime-api","provider"],"backgroundTag":"upstream-api-error","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"}