{"record":{"id":"9897381473c0d483","repo":"Hmbown/CodeWhale","slug":"provider-stream-error-error","errorCode":null,"errorMessage":"provider stream error: {error}","messagePattern":"provider stream error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/acp_server.rs","lineNumber":506,"sourceCode":"                            }\n                            StreamEvent::ContentBlockDelta {\n                                index,\n                                delta: Delta::InputJsonDelta { partial_json },\n                            } => {\n                                if let Some(acc) = pending_tool_uses.get_mut(&index) {\n                                    acc.buffer.push_str(&partial_json);\n                                }\n                            }\n                            StreamEvent::ContentBlockStop { index } => {\n                                if let Some(acc) = pending_tool_uses.remove(&index) {\n                                    tool_calls.push(acc.finalize());\n                                }\n                            }\n                            StreamEvent::MessageStop => {\n                                return Ok((PromptOutcome::Completed(accumulated), tool_calls));\n                            }\n                            StreamEvent::Error { error } => {\n                                return Err(anyhow!(\"provider stream error: {error}\"));\n                            }\n                            _ => {}\n                        }\n                    }\n                    Some(Err(err)) => return Err(err),\n                }\n            }\n            line = reader.next_line(), if reader_open => {\n                let line = match line? {\n                    Some(line) => line,\n                    // Input closed mid-turn: stop watching it, keep draining.\n                    None => {\n                        reader_open = false;\n                        continue;\n                    }\n                };\n                if line.trim().is_empty() {\n                    continue;","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/acp_server.rs#L488-L524","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped {error} text for the provider's own message (auth, rate limit, invalid request) and fix that root cause first","Verify provider credentials and model name in config, then retry the request","Retry the prompt turn; transient stream errors are often temporary","Add upstream retry/backoff handling in the client that calls the ACP server","Check provider status/endpoint availability if the error persists"],"exampleFix":"// before: turn fails wholesale on stream error\nStreamEvent::Error { error } => return Err(anyhow!(\"provider stream error: {error}\")),\n// after: caller retries with backoff\nmatch server.run_agentic_prompt_turn(req).await {\n    Ok(outcome) => handle(outcome),\n    Err(e) if e.to_string().contains(\"provider stream error\") => retry_with_backoff(req),\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"// before calling the prompt turn, verify provider is configured and reachable\nlet provider_cfg = config.provider()?;\nif provider_cfg.api_key.is_none() { return Err(anyhow!(\"provider API key not configured\")); }","typeGuard":"fn is_provider_stream_error(err: &anyhow::Error) -> bool {\n    err.to_string().starts_with(\"provider stream error:\")\n}","tryCatchPattern":"match turn_result {\n    Ok(outcome) => outcome,\n    Err(e) if is_provider_stream_error(&e) => {\n        tracing::warn!(\"provider stream failed: {e:#}\");\n        retry_with_backoff(|| run_turn(), 3)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep provider API keys valid and rotated","Add upstream retry with exponential backoff for transient stream failures","Monitor provider status and rate limits","Fail fast on invalid model names before starting a stream"],"tags":["provider","streaming","acp","network"],"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"}