-
Notifications
You must be signed in to change notification settings - Fork 6.4k
background rate limits fetch #6789
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
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
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 automated review suggestions for this pull request.
ℹ️ 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
- 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 address that feedback".
codex-rs/tui/src/chatwidget.rs
Outdated
| tokio::spawn(async move { | ||
| let mut interval = tokio::time::interval(Duration::from_secs(60)); | ||
|
|
||
| loop { | ||
| if let Some(snapshot) = fetch_rate_limits(base_url.clone(), auth.clone()).await { |
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.
Cancel stale rate-limit pollers when creating new chat widgets
When a chat widget is constructed we now spawn a tokio task that loops forever fetching /usage snapshots, but the task is never tied to the widget’s lifetime or cancelled. If the user starts another session in the same TUI run (e.g. via AppEvent::NewSession), each new ChatWidget will add another infinite interval while the previous one keeps running, so /usage is hit multiple times per minute and RateLimitSnapshotFetched keeps firing with potentially stale auth. This stacks redundant network traffic and repeated UI updates until the process exits.
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.
@codex can you check when this actually happens? then, implement a fix for this
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
- Tracked the chat widget’s rate-limit polling task, cancelling any existing poller before starting a new one and aborting it on drop so new sessions don’t accumulate stale
/usageloops. tui/src/chatwidget.rsL250-L299 tui/src/chatwidget.rsL1756-L1787 tui/src/chatwidget.rsL2825-L2831 - Initialized the new poller handle across chat widget constructors and manual test helpers to reflect the managed lifecycle state. tui/src/chatwidget.rsL1043-L1089 tui/src/chatwidget.rsL1115-L1162 tui/src/chatwidget/tests.rsL304-L357
Testing
- ✅
just fmt - ✅
just fix -p codex-tui - ✅
cargo test -p codex-tui
fetching rate limits every minute asynchronously