fix(tui): retry Codex responses requests#3344
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request refactors the Responses API request in DeepSeekClient to use a retry mechanism (send_with_retry) and adds an integration test to verify retries on rate-limited requests. The review feedback points out that calling crate::oauth::codex_account_id() inside the retry closure causes redundant synchronous disk I/O on every retry attempt, and suggests resolving the account ID once outside the closure.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let response = self | ||
| .send_with_retry(|| { | ||
| let mut builder = self | ||
| .http_client | ||
| .post(&url) | ||
| .header("Content-Type", "application/json") | ||
| .header("Accept", "text/event-stream") | ||
| .header("OpenAI-Beta", "responses=experimental") | ||
| .header("originator", "codex_cli_rs"); | ||
| if let Some(account_id) = crate::oauth::codex_account_id() { | ||
| builder = builder.header("chatgpt-account-id", account_id); | ||
| } | ||
| builder.json(&body) | ||
| }) |
There was a problem hiding this comment.
Calling crate::oauth::codex_account_id() inside the retry closure causes a synchronous disk read of the Codex credentials file (auth.json) on every retry attempt. To avoid redundant synchronous I/O in an asynchronous context, resolve the account ID once outside the closure and capture it by reference.
| let response = self | |
| .send_with_retry(|| { | |
| let mut builder = self | |
| .http_client | |
| .post(&url) | |
| .header("Content-Type", "application/json") | |
| .header("Accept", "text/event-stream") | |
| .header("OpenAI-Beta", "responses=experimental") | |
| .header("originator", "codex_cli_rs"); | |
| if let Some(account_id) = crate::oauth::codex_account_id() { | |
| builder = builder.header("chatgpt-account-id", account_id); | |
| } | |
| builder.json(&body) | |
| }) | |
| let account_id = crate::oauth::codex_account_id(); | |
| let response = self | |
| .send_with_retry(|| { | |
| let mut builder = self | |
| .http_client | |
| .post(&url) | |
| .header("Content-Type", "application/json") | |
| .header("Accept", "text/event-stream") | |
| .header("OpenAI-Beta", "responses=experimental") | |
| .header("originator", "codex_cli_rs"); | |
| if let Some(account_id) = &account_id { | |
| builder = builder.header("chatgpt-account-id", account_id); | |
| } | |
| builder.json(&body) | |
| }) |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Thanks @cyq1017 — your contribution landed in
Closing this PR now that the code is on If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the |
Route the Codex Responses stream request through the shared retry stack so retryable transport and HTTP failures get the same backoff, retry-status banner, and request health accounting as the chat path. Add a wiremock regression that returns a retryable 429 before a successful SSE stream, and resolve the optional Codex account id once before retry attempts. Harvested from PR Hmbown#3344 by @cyq1017. Refs Hmbown#3019, Hmbown#2487. Verified with: cargo test -p codewhale-tui client::responses --locked Verified with: cargo fmt --all -- --check Co-authored-by: cyq1017 <61975706+cyq1017@users.noreply.github.com>
Fixes #3019.
Problem:
/codex/responsesrequest once and returned immediately on retryable transport/status failures.Change:
send_with_retrywhile rebuilding the request body and headers per attempt.Verification:
cargo test -p codewhale-tui client::responsescargo fmt --all -- --checkgit diff --checkKnown gate:
Lintcan fail on the shared provider-registry drift fixed by fix(config): restore huggingface env precedence #3329 (HUGGINGFACE_API_KEYprecedence). This PR only changescrates/tui/src/client/responses.rsand does not touch that surface.