Hmbown/CodeWhale · error
turn failed
Error message
turn failed
What it means
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.
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.
Defensive patterns
Strategy: retry
Try / catch
match run_turn(...).await {
Err(e) if e.to_string().contains("turn failed") => {
// inspect runtime logs; retry with backoff if transient
}
other => other?,
} Prevention
- 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
When it happens
Trigger: A turn processed through the runtime API reaches the Failed terminal status in its event stream, and the event payload contains no `error` message.
Common situations: 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.
Related errors
- turn canceled
- turn interrupted
- A provider and page loader are required.
- Antigravity is a retired, non-runnable legacy provider…
- Antigravity is a retired, non-runnable legacy provider…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/0e3e412d6a390aea.
Report an issue: GitHub.
Appendix: source
Thrown at crates/app-server/src/lib.rs:1884
let (last_seq, status, error) = stream_result?;
self.last_seq_by_thread
.insert(thread_id.to_string(), last_seq);
match status {
TurnTerminalStatus::Completed => Ok(json!({
"thread_id": thread_id,
"status": "accepted",
"thread": Value::Null,
"threads": [],
"model": Value::Null,
"model_provider": Value::Null,
"cwd": Value::Null,
"approval_policy": Value::Null,
"sandbox": Value::Null,
"events": [],
"data": { "turn_id": turn_id },
})),
TurnTerminalStatus::Failed => Err(anyhow!(
"{}",
error.unwrap_or_else(|| "turn failed".to_string())
)),
TurnTerminalStatus::Interrupted => Err(anyhow!(
"{}",
error.unwrap_or_else(|| "turn interrupted".to_string())
)),
TurnTerminalStatus::Canceled => Err(anyhow!(
"{}",
error.unwrap_or_else(|| "turn canceled".to_string())
)),
}
}
async fn stream_turn_events<W: AsyncWrite + Unpin>(
&self,
thread_id: &str,
turn_id: &str,View on GitHub (pinned to 73e0f67d83)