Hmbown/CodeWhale · error

provider stream error

Error message

provider stream error: {error}

What it means

drive_prompt_stream surfaces any error event emitted by the provider's token stream by wrapping it with anyhow!. When the underlying provider stream yields StreamEvent::Error, the prompt turn aborts and returns this error to the ACP caller instead of a completed PromptOutcome.

Solutions

  1. Inspect the wrapped {error} text for the provider's own message (auth, rate limit, invalid request) and fix that root cause first
  2. Verify provider credentials and model name in config, then retry the request
  3. Retry the prompt turn; transient stream errors are often temporary
  4. Add upstream retry/backoff handling in the client that calls the ACP server
  5. Check provider status/endpoint availability if the error persists

Example fix

// before: turn fails wholesale on stream error
StreamEvent::Error { error } => return Err(anyhow!("provider stream error: {error}")),
// after: caller retries with backoff
match server.run_agentic_prompt_turn(req).await {
    Ok(outcome) => handle(outcome),
    Err(e) if e.to_string().contains("provider stream error") => retry_with_backoff(req),
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling the prompt turn, verify provider is configured and reachable
let provider_cfg = config.provider()?;
if provider_cfg.api_key.is_none() { return Err(anyhow!("provider API key not configured")); }

Type guard

fn is_provider_stream_error(err: &anyhow::Error) -> bool {
    err.to_string().starts_with("provider stream error:")
}

Try / catch

match turn_result {
    Ok(outcome) => outcome,
    Err(e) if is_provider_stream_error(&e) => {
        tracing::warn!("provider stream failed: {e:#}");
        retry_with_backoff(|| run_turn(), 3)?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling run_agentic_prompt_turn (or drive_prompt_stream in tests) while the provider's streaming response produces an error event — e.g. provider API returned an HTTP error mid-stream, authentication failed, or the model backend aborted the SSE/chunked stream.

Common situations: Expired or invalid provider API key, provider rate limiting or outage mid-generation, malformed request rejected by the provider after streaming began, network interruption during a long completion.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/9897381473c0d483. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/acp_server.rs:506

                            }
                            StreamEvent::ContentBlockDelta {
                                index,
                                delta: Delta::InputJsonDelta { partial_json },
                            } => {
                                if let Some(acc) = pending_tool_uses.get_mut(&index) {
                                    acc.buffer.push_str(&partial_json);
                                }
                            }
                            StreamEvent::ContentBlockStop { index } => {
                                if let Some(acc) = pending_tool_uses.remove(&index) {
                                    tool_calls.push(acc.finalize());
                                }
                            }
                            StreamEvent::MessageStop => {
                                return Ok((PromptOutcome::Completed(accumulated), tool_calls));
                            }
                            StreamEvent::Error { error } => {
                                return Err(anyhow!("provider stream error: {error}"));
                            }
                            _ => {}
                        }
                    }
                    Some(Err(err)) => return Err(err),
                }
            }
            line = reader.next_line(), if reader_open => {
                let line = match line? {
                    Some(line) => line,
                    // Input closed mid-turn: stop watching it, keep draining.
                    None => {
                        reader_open = false;
                        continue;
                    }
                };
                if line.trim().is_empty() {
                    continue;

View on GitHub (pinned to 73e0f67d83)