Conversation
…cy-limit fix(auth): limit auto-refresh concurrency to prevent refresh storms
…y-after fix(codex): honor usage_limit_reached resets_at for retry_after
feat(registry): add gemini-3.1-flash-image support
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant enhancements to API interaction and system stability. It refines how the system handles rate limits from external APIs by parsing detailed retry information and implements a concurrency control mechanism for authentication refreshes. Additionally, it expands the system's capabilities by integrating a new AI model, ensuring broader compatibility and functionality. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements across the codebase. It adds support for parsing Retry-After information from Codex API error responses to handle rate limiting more effectively. Concurrency for authentication token refreshes is now limited to improve stability. Additionally, the next_retry_after field is exposed in the auth files management API, and a new model configuration has been added. The changes are well-implemented and include relevant tests. My review includes one suggestion to refactor a new test file to use a table-driven approach for better maintainability.
| func TestParseCodexRetryAfter(t *testing.T) { | ||
| now := time.Unix(1_700_000_000, 0) | ||
|
|
||
| t.Run("resets_in_seconds", func(t *testing.T) { | ||
| body := []byte(`{"error":{"type":"usage_limit_reached","resets_in_seconds":123}}`) | ||
| retryAfter := parseCodexRetryAfter(http.StatusTooManyRequests, body, now) | ||
| if retryAfter == nil { | ||
| t.Fatalf("expected retryAfter, got nil") | ||
| } | ||
| if *retryAfter != 123*time.Second { | ||
| t.Fatalf("retryAfter = %v, want %v", *retryAfter, 123*time.Second) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("prefers resets_at", func(t *testing.T) { | ||
| resetAt := now.Add(5 * time.Minute).Unix() | ||
| body := []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(resetAt) + `,"resets_in_seconds":1}}`) | ||
| retryAfter := parseCodexRetryAfter(http.StatusTooManyRequests, body, now) | ||
| if retryAfter == nil { | ||
| t.Fatalf("expected retryAfter, got nil") | ||
| } | ||
| if *retryAfter != 5*time.Minute { | ||
| t.Fatalf("retryAfter = %v, want %v", *retryAfter, 5*time.Minute) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("fallback when resets_at is past", func(t *testing.T) { | ||
| resetAt := now.Add(-1 * time.Minute).Unix() | ||
| body := []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(resetAt) + `,"resets_in_seconds":77}}`) | ||
| retryAfter := parseCodexRetryAfter(http.StatusTooManyRequests, body, now) | ||
| if retryAfter == nil { | ||
| t.Fatalf("expected retryAfter, got nil") | ||
| } | ||
| if *retryAfter != 77*time.Second { | ||
| t.Fatalf("retryAfter = %v, want %v", *retryAfter, 77*time.Second) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("non-429 status code", func(t *testing.T) { | ||
| body := []byte(`{"error":{"type":"usage_limit_reached","resets_in_seconds":30}}`) | ||
| if got := parseCodexRetryAfter(http.StatusBadRequest, body, now); got != nil { | ||
| t.Fatalf("expected nil for non-429, got %v", *got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("non usage_limit_reached error type", func(t *testing.T) { | ||
| body := []byte(`{"error":{"type":"server_error","resets_in_seconds":30}}`) | ||
| if got := parseCodexRetryAfter(http.StatusTooManyRequests, body, now); got != nil { | ||
| t.Fatalf("expected nil for non-usage_limit_reached, got %v", *got) | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
This test function can be refactored into a table-driven test to improve maintainability and make it easier to add new test cases. This approach reduces code duplication and clearly separates test cases' data from the test logic.
func TestParseCodexRetryAfter(t *testing.T) {
now := time.Unix(1_700_000_000, 0)
resetAtFuture := now.Add(5 * time.Minute).Unix()
resetAtPast := now.Add(-1 * time.Minute).Unix()
durationPtr := func(d time.Duration) *time.Duration {
return &d
}
testCases := []struct {
name string
statusCode int
body []byte
want *time.Duration
}{
{
name: "resets_in_seconds",
statusCode: http.StatusTooManyRequests,
body: []byte(`{"error":{"type":"usage_limit_reached","resets_in_seconds":123}}`),
want: durationPtr(123 * time.Second),
},
{
name: "prefers resets_at",
statusCode: http.StatusTooManyRequests,
body: []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(resetAtFuture) + `,"resets_in_seconds":1}}`),
want: durationPtr(5 * time.Minute),
},
{
name: "fallback when resets_at is past",
statusCode: http.StatusTooManyRequests,
body: []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(resetAtPast) + `,"resets_in_seconds":77}}`),
want: durationPtr(77 * time.Second),
},
{
name: "non-429 status code",
statusCode: http.StatusBadRequest,
body: []byte(`{"error":{"type":"usage_limit_reached","resets_in_seconds":30}}`),
want: nil,
},
{
name: "non usage_limit_reached error type",
statusCode: http.StatusTooManyRequests,
body: []byte(`{"error":{"type":"server_error","resets_in_seconds":30}}`),
want: nil,
},
{
name: "empty body",
statusCode: http.StatusTooManyRequests,
body: []byte{},
want: nil,
},
{
name: "no retry fields",
statusCode: http.StatusTooManyRequests,
body: []byte(`{"error":{"type":"usage_limit_reached"}}`),
want: nil,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := parseCodexRetryAfter(tc.statusCode, tc.body, now)
if tc.want == nil {
if got != nil {
t.Fatalf("expected nil, got %v", *got)
}
return
}
if got == nil {
t.Fatalf("expected %v, got nil", *tc.want)
}
if *got != *tc.want {
t.Fatalf("got %v, want %v", *got, *tc.want)
}
})
}
}
No description provided.