-
-
Notifications
You must be signed in to change notification settings - Fork 647
fix: improve account rotation with request timeouts and interruption safety #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
52d9b51
3757ec3
f12df55
b1306a4
203d4db
a4745c1
506698b
2b9b575
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,7 +44,7 @@ import { AccountManager, type ModelFamily, parseRateLimitReason, calculateBackof | |||||||||||||||
| import { createAutoUpdateCheckerHook } from "./hooks/auto-update-checker"; | ||||||||||||||||
| import { loadConfig, initRuntimeConfig, type AntigravityConfig } from "./plugin/config"; | ||||||||||||||||
| import { createSessionRecoveryHook, getRecoverySuccessToast } from "./plugin/recovery"; | ||||||||||||||||
| import { checkAccountsQuota } from "./plugin/quota"; | ||||||||||||||||
| import { checkAccountsQuota, triggerAsyncQuotaRefreshForAll } from "./plugin/quota"; | ||||||||||||||||
| import { initDiskSignatureCache } from "./plugin/cache"; | ||||||||||||||||
| import { createProactiveRefreshQueue, type ProactiveRefreshQueue } from "./plugin/refresh-queue"; | ||||||||||||||||
| import { initLogger, createLogger } from "./plugin/logger"; | ||||||||||||||||
|
|
@@ -90,7 +90,7 @@ let softQuotaToastShown = false; | |||||||||||||||
| let rateLimitToastShown = false; | ||||||||||||||||
|
|
||||||||||||||||
| // Module-level reference to AccountManager for access from auth.login | ||||||||||||||||
| let activeAccountManager: import("./plugin/accounts").AccountManager | null = null; | ||||||||||||||||
| let activeAccountManager: AccountManager | null = null; | ||||||||||||||||
|
|
||||||||||||||||
| function cleanupToastCooldowns(): void { | ||||||||||||||||
| if (rateLimitToastCooldowns.size > MAX_TOAST_COOLDOWN_ENTRIES) { | ||||||||||||||||
|
|
@@ -2022,7 +2022,23 @@ export const createAntigravityPlugin = (providerId: string) => async ( | |||||||||||||||
| tokenConsumed = getTokenTracker().consume(account.index); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const response = await fetch(prepared.request, prepared.init); | ||||||||||||||||
| // Check if we should proactively refresh all quotas | ||||||||||||||||
| if (accountManager.shouldRefreshAllQuotas()) { | ||||||||||||||||
| pushDebug("proactive-quota-refresh: pool is mostly blocked, refreshing all"); | ||||||||||||||||
| void triggerAsyncQuotaRefreshForAll(accountManager, client, providerId); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Create a combined signal for timeout and user abort | ||||||||||||||||
| const timeoutMs = (config.request_timeout_seconds ?? 180) * 1000; | ||||||||||||||||
| const timeoutSignal = AbortSignal.timeout(timeoutMs); | ||||||||||||||||
| const combinedSignal = abortSignal | ||||||||||||||||
| ? (AbortSignal as any).any([abortSignal, timeoutSignal]) | ||||||||||||||||
|
||||||||||||||||
| ? (AbortSignal as any).any([abortSignal, timeoutSignal]) | |
| // Create a combined signal for timeout and user abort | |
| const timeoutMs = (config.request_timeout_seconds ?? 180) * 1000; | |
| const timeoutSignal = AbortSignal.timeout(timeoutMs); | |
| const combinedSignal = abortSignal | |
| ? (abortSignal.any ? abortSignal.any([abortSignal, timeoutSignal]) : mergeAbortSignals(abortSignal, timeoutSignal)) | |
| : timeoutSignal; |
Alternatively, you could add a polyfill at the top of the file:
// Polyfill for older Node.js versions
if (typeof AbortSignal.any === 'undefined') {
AbortSignal.any = function(signals: AbortSignal[]): AbortSignal {
const controller = new AbortController();
for (const signal of signals) {
if (signal.aborted) {
controller.abort(signal.reason);
break;
}
signal.addEventListener('abort', () => {
controller.abort(signal.reason);
}, { once: true });
}
return controller.signal;
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRITICAL:
AbortSignal.timeout()compatibility issue - will cause runtime errorsAbortSignal.timeout()was added in Node.js 20.11.0, but this project supports Node.js >=20.0.0. Users on Node.js 20.0.0 - 20.10.x will encounter aTypeError: AbortSignal.timeout is not a functionruntime error.You'll need to add a
createTimeoutSignalpolyfill function alongside the existingAbortSignal.any()polyfill.