From d32e4f25cfd9313dd93296e5bd7e7ca4ff1d8a16 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 25 Aug 2025 22:51:01 -0700 Subject: [PATCH] Added caps on retry config settings (#2701) The CLI supports config settings `stream_max_retries` and `request_max_retries` that allow users to override the default retry counts (4 and 5, respectively). However, there's currently no cap placed on these values. In theory, a user could configure an effectively infinite retry count which could hammer the server. This PR adds a reasonable cap (currently 100) to both of these values. --- codex-rs/core/src/model_provider_info.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codex-rs/core/src/model_provider_info.rs b/codex-rs/core/src/model_provider_info.rs index 0102591d..1a3e5a27 100644 --- a/codex-rs/core/src/model_provider_info.rs +++ b/codex-rs/core/src/model_provider_info.rs @@ -17,6 +17,10 @@ use crate::error::EnvVarError; const DEFAULT_STREAM_IDLE_TIMEOUT_MS: u64 = 300_000; const DEFAULT_STREAM_MAX_RETRIES: u64 = 5; const DEFAULT_REQUEST_MAX_RETRIES: u64 = 4; +/// Hard cap for user-configured `stream_max_retries`. +const MAX_STREAM_MAX_RETRIES: u64 = 100; +/// Hard cap for user-configured `request_max_retries`. +const MAX_REQUEST_MAX_RETRIES: u64 = 100; /// Wire protocol that the provider speaks. Most third-party services only /// implement the classic OpenAI Chat Completions JSON schema, whereas OpenAI @@ -207,12 +211,14 @@ impl ModelProviderInfo { pub fn request_max_retries(&self) -> u64 { self.request_max_retries .unwrap_or(DEFAULT_REQUEST_MAX_RETRIES) + .min(MAX_REQUEST_MAX_RETRIES) } /// Effective maximum number of stream reconnection attempts for this provider. pub fn stream_max_retries(&self) -> u64 { self.stream_max_retries .unwrap_or(DEFAULT_STREAM_MAX_RETRIES) + .min(MAX_STREAM_MAX_RETRIES) } /// Effective idle timeout for streaming responses.