-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Change headers and struct of rate limits #4060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
codex/codex-rs/tui/src/chatwidget/tests.rs
Lines 380 to 418 in 0b363ce
#[test] | |
fn rate_limit_warnings_emit_thresholds() { | |
let mut state = RateLimitWarningState::default(); | |
let mut warnings: Vec<String> = Vec::new(); | |
warnings.extend(state.take_warnings(10.0, 55.0)); | |
warnings.extend(state.take_warnings(55.0, 10.0)); | |
warnings.extend(state.take_warnings(10.0, 80.0)); | |
warnings.extend(state.take_warnings(80.0, 10.0)); | |
warnings.extend(state.take_warnings(10.0, 95.0)); | |
warnings.extend(state.take_warnings(95.0, 10.0)); | |
assert_eq!( | |
warnings.len(), | |
6, | |
"expected one warning per threshold per limit" | |
); | |
assert!( | |
warnings | |
.iter() | |
.any(|w| w.contains("Hourly usage exceeded 50%")), | |
"expected hourly 50% warning" | |
); | |
assert!( | |
warnings | |
.iter() | |
.any(|w| w.contains("Weekly usage exceeded 50%")), | |
"expected weekly 50% warning" | |
); | |
assert!( | |
warnings | |
.iter() | |
.any(|w| w.contains("Hourly usage exceeded 90%")), | |
"expected hourly 90% warning" | |
); | |
assert!( | |
warnings | |
.iter() | |
.any(|w| w.contains("Weekly usage exceeded 90%")), |
[P1] Adjust warning tests for new rate-limit messages
The warning text was rephrased to "Heads up, you've used over …" in RateLimitWarningState
, but the unit test still asserts that the warnings contain substrings such as "Hourly usage exceeded 50%" and "Weekly usage exceeded 50%". With the new wording none of these substrings appear, so rate_limit_warnings_emit_thresholds
will now fail even when the runtime behaviour is correct. The test expectations should be updated to match the new messages or to check the thresholds in a wording-agnostic way.
Reply with @codex fix comments
to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
codex-rs/core/src/client.rs
Outdated
fn parse_rate_limit_snapshot(headers: &HeaderMap) -> Option<RateLimitSnapshotEvent> { | ||
let primary_used_percent = parse_header_f64(headers, "x-codex-primary-used-percent")?; | ||
let weekly_used_percent = parse_header_f64(headers, "x-codex-protection-used-percent")?; | ||
let primary_to_weekly_ratio_percent = | ||
parse_header_f64(headers, "x-codex-primary-over-protection-limit-percent")?; | ||
let secondary_used_percent = parse_header_f64(headers, "x-codex-secondry-used-percent")?; | ||
let primary_to_secondary_ratio_percent = | ||
parse_header_f64(headers, "x-codex-primary-over-secondry-limit-percent")?; | ||
let primary_window_minutes = parse_header_u64(headers, "x-codex-primary-window-minutes")?; | ||
let weekly_window_minutes = parse_header_u64(headers, "x-codex-protection-window-minutes")?; | ||
let secondary_window_minutes = parse_header_u64(headers, "x-codex-secondry-window-minutes")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Use correct HTTP header names when parsing secondary limits
The new rate‑limit parsing still looks for headers named x-codex-secondry-*
in several places. Given that the struct and surrounding code consistently use the fully spelled term “secondary”, these typos will fail to match the actual x-codex-secondary-*
headers emitted by the server, and parse_rate_limit_snapshot
will always return None
. Downstream consumers (warning messages, TUI status) will silently lose rate‑limit information.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix on the api side first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
- Corrected rate limit snapshot parsing to look up the properly spelled
x-codex-secondary-*
headers and updated the mock SSE response to emit the same names so rate-limit snapshots are captured again. core/src/client.rsL487-L493 core/tests/suite/client.rsL761-L768 - Updated the TUI rate-limit warning test to assert the new “Heads up…” copy for every threshold, ensuring the warning logic is covered end-to-end. tui/src/chatwidget/tests.rsL381-L413
Testing
- ✅
just fmt
- ✅
just fix -p codex-core
- ✅
just fix -p codex-tui
- ✅
USER=root cargo test -p codex-core
- ✅
cargo test -p codex-tui
No description provided.