AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] usageLimitResetPattern only parses hours/minutes, failing on day/second reset messages

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Summary

In internal/aistudio/quota.go, usageLimitResetPattern matches reset durations formatted as resets in X hours, Y minutes:

var usageLimitResetPattern = regexp.MustCompile(`resets in (?:(\d+) hours?)?(?:, )?(?:(\d+) minutes?)?`)

When Google reports a 429 reset window that includes days (e.g., resets in 1 day, 2 hours or resets in 2 days), seconds (resets in 45 seconds), or uses retry in X hours, Y minutes, usageLimitReset fails to extract the duration.

Consequences When usageLimitReset returns ok = false on a plan limit:

QuotaCooldownForError cannot determine the explicit reset time. The account falls back to now.Add(time.Minute) (短期限额), waking up after 60 seconds instead of the upstream reset window and repeatedly failing with 429. Suggested Fix Update usageLimitResetPattern to support optional days, hours, minutes, and seconds, and accept either resets in or retry in:

var usageLimitResetPattern = regexp.MustCompile(`(?:resets|retry)\s+in\s+(?:(\d+)\s+days?)?(?:,\s*)?(?:(\d+)\s+hours?)?(?:,\s*)?(?:(\d+)\s+minutes?)?(?:,\s*)?(?:(\d+)\s+seconds?)?`)
And calculate total duration: days*24h + hours*1h + minutes*1m + seconds*1s.

版本 / Version

v0.3.13

photobrand avatar Nov 21 '26 19:11 photobrand