@@ -197,6 +197,13 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
197197
198198 url := p.baseURL + "/chat/completions"
199199
200+ log.Debug().
201+ Str("provider", "ollama").
202+ Str("model", p.model).
203+ Int("messages", len(req.Messages)).
204+ Int("body_bytes", len(body)).
205+ Msg("Sending request to Ollama")
206+
200207 maxRetries := len(ollamaRetryDelays)
201208 var lastErr error
202209 for attempt := 0; attempt <= maxRetries; attempt++ {
@@ -229,6 +236,11 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
229236
230237 resp, err := p.httpClient.Do(httpReq)
231238 if err != nil {
239+ // Do not retry on context cancellation or timeout
240+ if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
241+ return nil, err
242+ }
243+
232244 lastErr = err
233245 continue
234246 }
@@ -251,6 +263,13 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
251263 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
252264 payload, _ := io.ReadAll(resp.Body)
253265 resp.Body.Close()
266+
267+ log.Error().
268+ Str("provider", "ollama").
269+ Int("status", resp.StatusCode).
270+ Str("body", string(payload)).
271+ Msg("Ollama non-retryable error")
272+
254273 return nil, fmt.Errorf("chat completion status %d: %s", resp.StatusCode, strings.TrimSpace(string(payload)))
255274 }
256275