fix(core): narrow capacity retry ownership

This commit is contained in:
Peter Steinberger
2026-07-09 20:28:57 -07:00
parent 64569aedd4
commit b6b5ab6efd
14 changed files with 190 additions and 266 deletions
+1
View File
@@ -6,6 +6,7 @@ pub use crate::retry::RetryOn;
pub use crate::retry::RetryPolicy;
pub use crate::retry::backoff;
pub use crate::retry::run_with_retry;
pub use crate::retry::run_with_retry_if;
pub use crate::sse::sse_stream;
pub use crate::telemetry::RequestTelemetry;
pub use codex_http_client::HttpClient as CodexHttpClient;
+17 -3
View File
@@ -47,9 +47,22 @@ pub fn backoff(base: Duration, attempt: u64) -> Duration {
}
pub async fn run_with_retry<T, F, Fut>(
policy: RetryPolicy,
make_req: impl FnMut() -> Request,
op: F,
) -> Result<T, TransportError>
where
F: Fn(Request, u64) -> Fut,
Fut: Future<Output = Result<T, TransportError>>,
{
run_with_retry_if(policy, make_req, op, |_| true).await
}
pub async fn run_with_retry_if<T, F, Fut>(
policy: RetryPolicy,
mut make_req: impl FnMut() -> Request,
op: F,
retry_if: impl Fn(&TransportError) -> bool,
) -> Result<T, TransportError>
where
F: Fn(Request, u64) -> Fut,
@@ -60,9 +73,10 @@ where
match op(req, attempt).await {
Ok(resp) => return Ok(resp),
Err(err)
if policy
.retry_on
.should_retry(&err, attempt, policy.max_attempts) =>
if retry_if(&err)
&& policy
.retry_on
.should_retry(&err, attempt, policy.max_attempts) =>
{
sleep(backoff(policy.base_delay, attempt + 1)).await;
}