AIStudio2API
AIStudio2API copied to clipboard
[Bug] generateWithRetry exits without retrying when fileBound switches to copyFiles = true and retry.maxAttempts is not incremented
发生了什么 / What happened
Summary
When a GenerateContent request references a Drive file (resourceID != "") whose owner account is disabled or cooling down, generateWithRetry sets copyFiles = true to copy the file to another eligible account, but forgets to increment retry.maxAttempts.
Reproduction Scenario (from code inspection)
- Have 2 accounts:
account_a(owns uploaded filefile_1) andaccount_b(enabled and ready). - Disable
account_a(or disable it after upload), leaving 1 enabled account (len(EnabledAccounts()) == 1). - Send a
GenerateContentrequest referencingfile_1(withoutX-AIStudio-Account).
Expected vs Observed
- Expected: When
acquireWarmLeasereturnsErrNoEligibleAccount/AllCoolingErrorfor the file owner andgenerateWithRetryswitches tocopyFiles = true, the loop runs a retry attempt usingaccount_band copies the file toaccount_b. - Observed:
retry.maxAttemptsis initialized tomax(len(service.pool.EnabledAccounts()), 1)(1).- On
attempt = 0,acquireWarmLeasefails on the pinned file owner. generateWithRetrysetscopyFiles = trueandcontinues without incrementingretry.maxAttempts.- The loop increments
attemptto1, failsattempt < retry.maxAttempts(1 < 1), and exits withwinner == nil, returning the owner-unavailable error instead of copying toaccount_b. - Even when both accounts are enabled (
maxAttempts == 2),attempt = 0consumes one of the two attempts just togglingcopyFiles = true, leaving no switch budget if the target account hits a transient error.
Root Cause Pointer
In internal/app/runtime.go (generateWithRetry):
awaitCatalogSyncright above properly runsretry.maxAttempts++beforecontinue.- Immediately below it:
if fileBound && !copyFiles && (errors.Is(acquireErr, aistudio.ErrNoEligibleAccount) || errors.As(acquireErr, &ownerCooling)) && requestCtx.Err() == nil { copyFiles = true continue }
retry.maxAttempts++ is missing here.
Suggested Fix
Add retry.maxAttempts++ alongside copyFiles = true before continue (matching awaitCatalogSync).
版本 / Version
No response