From 6ca9b4327b38bbe5725deb1a464b358c893c4f0f Mon Sep 17 00:00:00 2001 From: xl-openai Date: Thu, 12 Feb 2026 00:17:48 -0800 Subject: [PATCH] fix: stop inheriting rate-limit limit_name (#11557) When we carry over values from partial rate-limit, we should only do so for the same limit_id. --- codex-rs/core/src/state/session.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/codex-rs/core/src/state/session.rs b/codex-rs/core/src/state/session.rs index 2ceb684d0..a2df7c239 100644 --- a/codex-rs/core/src/state/session.rs +++ b/codex-rs/core/src/state/session.rs @@ -177,20 +177,15 @@ impl SessionState { } } -// Merge partial rate-limit updates: new fields overwrite existing values; -// missing fields retain prior values. If `limit_id` is absent everywhere, -// default it to `"codex"`. +// Sometimes new snapshots don't include credits or plan information. +// Preserve those from the previous snapshot when missing. For `limit_id`, treat +// missing values as the default `"codex"` bucket. fn merge_rate_limit_fields( previous: Option<&RateLimitSnapshot>, mut snapshot: RateLimitSnapshot, ) -> RateLimitSnapshot { if snapshot.limit_id.is_none() { - snapshot.limit_id = previous - .and_then(|prior| prior.limit_id.clone()) - .or_else(|| Some("codex".to_string())); - } - if snapshot.limit_name.is_none() { - snapshot.limit_name = previous.and_then(|prior| prior.limit_name.clone()); + snapshot.limit_id = Some("codex".to_string()); } if snapshot.credits.is_none() { snapshot.credits = previous.and_then(|prior| prior.credits.clone()); @@ -305,7 +300,7 @@ mod tests { } #[tokio::test] - async fn set_rate_limits_preserves_previous_limit_id_when_missing() { + async fn set_rate_limits_defaults_to_codex_when_limit_id_missing_after_other_bucket() { let session_configuration = make_session_configuration_for_tests().await; let mut state = SessionState::new(session_configuration); @@ -339,12 +334,12 @@ mod tests { .latest_rate_limits .as_ref() .and_then(|v| v.limit_id.clone()), - Some("codex_other".to_string()) + Some("codex".to_string()) ); } #[tokio::test] - async fn set_rate_limits_accepts_new_limit_id_bucket() { + async fn set_rate_limits_carries_credits_and_plan_type_from_codex_to_codex_other() { let session_configuration = make_session_configuration_for_tests().await; let mut state = SessionState::new(session_configuration); @@ -367,7 +362,7 @@ mod tests { state.set_rate_limits(RateLimitSnapshot { limit_id: Some("codex_other".to_string()), - limit_name: Some("codex_other".to_string()), + limit_name: None, primary: Some(RateLimitWindow { used_percent: 30.0, window_minutes: Some(120), @@ -382,7 +377,7 @@ mod tests { state.latest_rate_limits, Some(RateLimitSnapshot { limit_id: Some("codex_other".to_string()), - limit_name: Some("codex_other".to_string()), + limit_name: None, primary: Some(RateLimitWindow { used_percent: 30.0, window_minutes: Some(120),