From 9d40159cad3b55c753ed02e7a4dee8cc7b6d15eb Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Oct 2026 18:37:27 +0000 Subject: Add request timeout and retry support to aichat HTTP clients - Add timeout, retries, retry_delay_ms, and retry_max_delay_ms options to client extra config to bound long-running requests and retry failed attempts with exponential backoff. - Apply a total request timeout via reqwest .timeout(). - Implement retry with exponential backoff for non-streaming and streaming chat completions. - Disable reqwest-eventsource internal auto-reconnect so it does not loop forever; outer retry logic is now the single owner of retry behavior. - Document the new options in config.example.yaml. --- src/client/stream.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/client/stream.rs') diff --git a/src/client/stream.rs b/src/client/stream.rs index fd82c94..94802a8 100644 --- a/src/client/stream.rs +++ b/src/client/stream.rs @@ -4,6 +4,7 @@ use crate::utils::AbortSignal; use anyhow::{anyhow, bail, Context, Result}; use futures_util::{Stream, StreamExt}; use reqwest::RequestBuilder; +use reqwest_eventsource::retry::Never; use reqwest_eventsource::{Error as EventSourceError, Event, RequestBuilderExt}; use serde_json::Value; use tokio::sync::mpsc::UnboundedSender; @@ -95,6 +96,11 @@ where F: FnMut(SseMmessage) -> Result, { let mut es = builder.eventsource()?; + // Disable the eventsource client's automatic reconnect so the outer retry + // logic (driven by ExtraConfig.retries) is the single owner of retry + // behavior. Without this, a dropped connection is re-opened internally in a + // loop that never surfaces the failure to the caller. + es.set_retry_policy(Box::new(Never)); while let Some(event) = es.next().await { match event { Ok(Event::Open) => {} -- cgit v1.2.3