codex: generalize deferred goal retry names (#31176)

This commit is contained in:
Eric Traut
2026-07-05 10:34:07 -07:00
parent 347ba2f0dc
commit 918e8d0307
2 changed files with 9 additions and 13 deletions

View File

@@ -310,7 +310,7 @@ where
.accounting_state()
.turn_is_current_active_goal(input.turn_id) =>
{
runtime.defer_capacity_retry();
runtime.defer_retry();
return;
}
CodexErrorInfo::UsageLimitExceeded => ActiveGoalStopReason::UsageLimit,

View File

@@ -23,7 +23,7 @@ use tokio::sync::SemaphorePermit;
// Capacity failures do not consume user tokens, but retrying immediately can
// create a tight loop of failed turns. Keep the retry cadence deliberately low.
const SERVER_OVERLOADED_GOAL_RETRY_DELAY: Duration = Duration::from_secs(5 * 60);
const DEFERRED_GOAL_RETRY_DELAY: Duration = Duration::from_secs(5 * 60);
#[derive(Clone)]
pub struct GoalRuntimeHandle {
@@ -50,7 +50,7 @@ struct GoalRuntimeInner {
thread_manager: Weak<ThreadManager>,
accounting_state: Arc<GoalAccountingState>,
enabled: AtomicBool,
capacity_retry_pending: AtomicBool,
retry_pending: AtomicBool,
tools_available_for_thread: bool,
goal_state_lock: Semaphore,
}
@@ -103,7 +103,7 @@ impl GoalRuntimeHandle {
thread_manager,
accounting_state,
enabled: AtomicBool::new(config.enabled),
capacity_retry_pending: AtomicBool::new(false),
retry_pending: AtomicBool::new(false),
tools_available_for_thread: config.tools_available_for_thread,
goal_state_lock: Semaphore::new(/*permits*/ 1),
}),
@@ -122,12 +122,8 @@ impl GoalRuntimeHandle {
self.is_enabled() && self.inner.tools_available_for_thread
}
pub(crate) fn defer_capacity_retry(&self) {
if self
.inner
.capacity_retry_pending
.swap(true, Ordering::Relaxed)
{
pub(crate) fn defer_retry(&self) {
if self.inner.retry_pending.swap(true, Ordering::Relaxed) {
return;
}
@@ -135,11 +131,11 @@ impl GoalRuntimeHandle {
// A newly resumed runtime intentionally starts without this backoff.
let runtime = Arc::downgrade(&self.inner);
drop(tokio::spawn(async move {
tokio::time::sleep(SERVER_OVERLOADED_GOAL_RETRY_DELAY).await;
tokio::time::sleep(DEFERRED_GOAL_RETRY_DELAY).await;
let Some(inner) = runtime.upgrade() else {
return;
};
inner.capacity_retry_pending.store(false, Ordering::Relaxed);
inner.retry_pending.store(false, Ordering::Relaxed);
let runtime = GoalRuntimeHandle { inner };
if let Err(err) = runtime.continue_if_idle().await {
tracing::warn!(
@@ -392,7 +388,7 @@ impl GoalRuntimeHandle {
}
pub(crate) async fn continue_if_idle(&self) -> Result<(), String> {
if self.inner.capacity_retry_pending.load(Ordering::Relaxed) {
if self.inner.retry_pending.load(Ordering::Relaxed) {
return Ok(());
}
if !self.tools_visible() {