fix: correct jitter range to ±25% and fix abort.rs doc — review findings
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
//! Shared abort-flag checks.
|
//! Shared abort-flag checks.
|
||||||
//!
|
//!
|
||||||
//! The two variants (Option<Arc<AtomicBool>> and bare AtomicBool) are
|
//! Three variants (Option<Arc<AtomicBool>>, bare AtomicBool, and
|
||||||
//! used across the agent runtime, subagent, workflow engine, and provider.
|
//! Option<&AtomicBool>) cover the agent runtime, subagent, workflow
|
||||||
|
//! engine, and provider.
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
|||||||
pub fn backoff_seconds(attempt: u32, max_secs: u64) -> Duration {
|
pub fn backoff_seconds(attempt: u32, max_secs: u64) -> Duration {
|
||||||
let base_secs = (2u64).pow(attempt).min(max_secs);
|
let base_secs = (2u64).pow(attempt).min(max_secs);
|
||||||
let quarter = (base_secs * 250_000_000).max(100_000_000); // 25% of base, min 100ms
|
let quarter = (base_secs * 250_000_000).max(100_000_000); // 25% of base, min 100ms
|
||||||
let offset = jitter_ns(quarter);
|
let offset = jitter_ns(quarter * 2); // [0, 50% of base)
|
||||||
// ±25%: offset in [0, quarter), so result = base - quarter/2 + offset
|
// ±25%: offset in [0, 2×quarter), result = base + offset - quarter
|
||||||
// which lies in [base - 25%, base + 25%).
|
// which lies in [base - 25%, base + 25%).
|
||||||
let ns = base_secs * 1_000_000_000 + offset - quarter / 2;
|
let ns = base_secs * 1_000_000_000 + offset - quarter;
|
||||||
Duration::from_nanos(ns)
|
Duration::from_nanos(ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user