AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] generateWithRetry exits without retrying when fileBound switches to copyFiles = true and retry.maxAttempts is not incremented

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / 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)

  1. Have 2 accounts: account_a (owns uploaded file file_1) and account_b (enabled and ready).
  2. Disable account_a (or disable it after upload), leaving 1 enabled account (len(EnabledAccounts()) == 1).
  3. Send a GenerateContent request referencing file_1 (without X-AIStudio-Account).

Expected vs Observed

  • Expected: When acquireWarmLease returns ErrNoEligibleAccount / AllCoolingError for the file owner and generateWithRetry switches to copyFiles = true, the loop runs a retry attempt using account_b and copies the file to account_b.
  • Observed:
    • retry.maxAttempts is initialized to max(len(service.pool.EnabledAccounts()), 1) (1).
    • On attempt = 0, acquireWarmLease fails on the pinned file owner.
    • generateWithRetry sets copyFiles = true and continues without incrementing retry.maxAttempts.
    • The loop increments attempt to 1, fails attempt < retry.maxAttempts (1 < 1), and exits with winner == nil, returning the owner-unavailable error instead of copying to account_b.
    • Even when both accounts are enabled (maxAttempts == 2), attempt = 0 consumes one of the two attempts just toggling copyFiles = true, leaving no switch budget if the target account hits a transient error.

Root Cause Pointer

In internal/app/runtime.go (generateWithRetry):

  • awaitCatalogSync right above properly runs retry.maxAttempts++ before continue.
  • 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

photobrand avatar Nov 21 '26 10:11 photobrand