Skip to content

An agent-managed museum exhibit, built in Rust with Gajae-Code / LazyCodex — developed and maintained with no human intervention.

Rust

feat: API timeout config, Retry-After header, configurable retry, and 400 transient retry

TheArchitectit04bc5f57880c
diff --git a/rust/crates/api/src/error.rs b/rust/crates/api/src/error.rs
index aa8e5fc1..60ae1f5f 100644
--- a/rust/crates/api/src/error.rs
+++ b/rust/crates/api/src/error.rs
@@ -582,6 +582,7 @@ mod tests {
body: String::new(),
retryable: false,
suggested_action: None,
+ retry_after: None,
};
assert!(error.is_context_window_failure());
diff --git a/rust/crates/api/src/lib.rs b/rust/crates/api/src/lib.rs
index a5b7d726..e96e92f8 100644
--- a/rust/crates/api/src/lib.rs
+++ b/rust/crates/api/src/lib.rs
@@ -12,9 +12,8 @@ pub use client::{
};
pub use error::ApiError;
pub use http_client::{
- TimeoutConfig,
build_http_client, build_http_client_or_default, build_http_client_with,
- build_http_client_with_opts, ProxyConfig,
+ build_http_client_with_opts, ProxyConfig, TimeoutConfig,
};
pub use prompt_cache::{
CacheBreakEvent, PromptCache, PromptCacheConfig, PromptCachePaths, PromptCacheRecord,
diff --git a/rust/crates/api/src/providers/anthropic.rs b/rust/crates/api/src/providers/anthropic.rs
index 72001780..dd458195 100644
--- a/rust/crates/api/src/providers/anthropic.rs
+++ b/rust/crates/api/src/providers/anthropic.rs
@@ -467,7 +467,8 @@ impl AnthropicClient {
break;
}
- let delay = if let Some(retry_after) = last_error.as_ref().and_then(|e| e.retry_after()) {
+ let delay = if let Some(retry_after) = last_error.as_ref().and_then(|e| e.retry_after())
+ {
retry_after
} else {
self.jittered_backoff_for_attempt(attempts)?
@@ -909,7 +910,10 @@ async fn expect_success(response: reqwest::Response) -> Result<reqwest::Response
})
}
-fn parse_retry_after(headers: &reqwest::header::HeaderMap, status: reqwest::StatusCode) -> Option<std::time::Duration> {
+fn parse_retry_after(
+ headers: &reqwest::header::HeaderMap,
+ status: reqwest::StatusCode,
+) -> Option<std::time::Duration> {
if status != reqwest::StatusCode::TOO_MANY_REQUESTS {
return None;
}
diff --git a/rust/crates/api/src/providers/openai_compat.rs b/rust/crates/api/src/providers/openai_compat.rs
index 00326f52..cfeb4c3c 100644
--- a/rust/crates/api/src/providers/openai_compat.rs
+++ b/rust/crates/api/src/providers/openai_compat.rs
@@ -1667,7 +1667,10 @@ async fn expect_success(response: reqwest::Response) -> Result<reqwest::Response
})
}
-fn parse_retry_after(headers: &reqwest::header::HeaderMap, status: reqwest::StatusCode) -> Option<std::time::Duration> {
+fn parse_retry_after(
+ headers: &reqwest::header::HeaderMap,
+ status: reqwest::StatusCode,
+) -> Option<std::time::Duration> {
if status != reqwest::StatusCode::TOO_MANY_REQUESTS {
return None;
}
diff --git a/rust/crates/runtime/src/config.rs b/rust/crates/runtime/src/config.rs
index 46639b75..b31c0168 100644
--- a/rust/crates/runtime/src/config.rs
+++ b/rust/crates/runtime/src/config.rs
@@ -1184,10 +1184,8 @@ fn parse_optional_api_timeout_config(root: &JsonValue) -> Result<ApiTimeoutConfi
return Ok(ApiTimeoutConfig::default());
};
let context = "merged settings.apiTimeout";
- let connect_timeout_secs = optional_u64(obj, "connectTimeout", context)?
- .unwrap_or(30);
- let request_timeout_secs = optional_u64(obj, "requestTimeout", context)?
- .unwrap_or(300);
+ let connect_timeout_secs = optional_u64(obj, "connectTimeout", context)?.unwrap_or(30);
+ let request_timeout_secs = optional_u64(obj, "requestTimeout", context)?.unwrap_or(300);
let max_retries = optional_u64(obj, "maxRetries", context)?
.map(|v| v as u32)
.unwrap_or(8);
diff --git a/rust/crates/runtime/src/lib.rs b/rust/crates/runtime/src/lib.rs
index 4cdba8fc..f3997273 100644
--- a/rust/crates/runtime/src/lib.rs
+++ b/rust/crates/runtime/src/lib.rs
@@ -65,13 +65,12 @@ pub use compact::{
get_compact_continuation_message, should_compact, CompactionConfig, CompactionResult,
};
pub use config::{
- ApiTimeoutConfig, ConfigEntry, ConfigError, ConfigLoader, ConfigSource,
- McpConfigCollection, McpManagedProxyServerConfig, McpOAuthConfig, McpRemoteServerConfig,
- McpSdkServerConfig, McpServerConfig, McpStdioServerConfig, McpTransport,
+ suppress_config_warnings_for_json_mode, ApiTimeoutConfig, ConfigEntry, ConfigError,
+ ConfigLoader, ConfigSource, McpConfigCollection, McpManagedProxyServerConfig, McpOAuthConfig,
+ McpRemoteServerConfig, McpSdkServerConfig, McpServerConfig, McpStdioServerConfig, McpTransport,
McpWebSocketServerConfig, OAuthConfig, ProviderFallbackConfig, ResolvedPermissionMode,
RuntimeConfig, RuntimeFeatureConfig, RuntimeHookConfig, RuntimePermissionRuleConfig,
- RuntimePluginConfig, ScopedMcpServerConfig, suppress_config_warnings_for_json_mode,
- CLAW_SETTINGS_SCHEMA_NAME,
+ RuntimePluginConfig, ScopedMcpServerConfig, CLAW_SETTINGS_SCHEMA_NAME,
};
pub use config_validate::{
check_unsupported_format, format_diagnostics, validate_config_file, ConfigDiagnostic,