tuxevil-rotator 4.4.7 → 4.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +2 -0
- package/package.json +1 -1
- package/plugins/opencode-discovery/index.mjs +50 -21
- package/src/providers/adapter.ts +5 -0
- package/src/providers/google-antigravity/index.ts +57 -0
- package/src/rotator.ts +289 -175
- package/src/types.ts +16 -0
- package/tools/telemetry-receiver/receiver.js +3262 -1076
package/src/rotator.ts
CHANGED
|
@@ -183,6 +183,21 @@ export function areAccountIdentitiesCompatible(
|
|
|
183
183
|
const rotatorLogger = logger.child("rotator");
|
|
184
184
|
const IN_CONTAINER = isRunningInContainer();
|
|
185
185
|
|
|
186
|
+
const PAID_ACCOUNT_TIERS: ReadonlySet<AccountTier> = new Set([
|
|
187
|
+
"ultra",
|
|
188
|
+
"pro",
|
|
189
|
+
"plus",
|
|
190
|
+
"max",
|
|
191
|
+
"team",
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
function isPaidAccountConfig(config: AccountConfig): boolean {
|
|
195
|
+
if (config.tier && config.tier !== "unknown") {
|
|
196
|
+
return PAID_ACCOUNT_TIERS.has(config.tier);
|
|
197
|
+
}
|
|
198
|
+
return config.type === "pro";
|
|
199
|
+
}
|
|
200
|
+
|
|
186
201
|
function currentUtcDay(now = Date.now()): string {
|
|
187
202
|
return new Date(now).toISOString().slice(0, 10);
|
|
188
203
|
}
|
|
@@ -221,6 +236,9 @@ interface AccountRequestWaiter {
|
|
|
221
236
|
// Reverse map: upstream model → the quota pool key it primarily represents (for deduplication).
|
|
222
237
|
const QUOTA_POOL_FOR_KICKSTART_MODEL: Record<string, string> = {
|
|
223
238
|
"gpt-oss-120b-medium": "claude",
|
|
239
|
+
"claude-sonnet-5-5-low": "claude",
|
|
240
|
+
"claude-sonnet-5-5-medium": "claude",
|
|
241
|
+
"claude-sonnet-4-6": "claude",
|
|
224
242
|
"gemini-3-flash": "gemini",
|
|
225
243
|
"gpt-5.6-luna": CODEX_QUOTA_MODEL_KEY,
|
|
226
244
|
// Legacy manual kickstart compatibility. New Ollama quota polling/routes
|
|
@@ -521,7 +539,10 @@ export class AccountRotator {
|
|
|
521
539
|
private routingWarningLastLoggedAt = new Map<string, number>();
|
|
522
540
|
private static readonly ROUTING_WARNING_DEDUP_MS = 60_000;
|
|
523
541
|
private autoWarmupEnabled = false;
|
|
524
|
-
private readonly kickstartDeniedUntil = new Map<
|
|
542
|
+
private readonly kickstartDeniedUntil = new Map<
|
|
543
|
+
string,
|
|
544
|
+
{ until: number; status: number; reason: string }
|
|
545
|
+
>();
|
|
525
546
|
// Debounced state writer: batches multiple saveState() calls within a 1s window
|
|
526
547
|
// to a single disk write. Hot paths (markError, recordRequest, etc.) call
|
|
527
548
|
// scheduleStateSave() instead of saveState() to avoid blocking the event loop.
|
|
@@ -1091,16 +1112,23 @@ export class AccountRotator {
|
|
|
1091
1112
|
setProviderCooldown: (acc, providerId, durationMs) =>
|
|
1092
1113
|
this.setProviderCooldown(acc, providerId, durationMs),
|
|
1093
1114
|
};
|
|
1094
|
-
// Parent-account model: poll quota for every provider credential
|
|
1115
|
+
// Parent-account model: poll quota for every active, valid provider credential
|
|
1095
1116
|
// the account holds (Google OAuth pools + Ollama usage pools).
|
|
1096
1117
|
const providerIds = new Set<string>(
|
|
1097
1118
|
(account.config.credentials ?? []).map((c) => c.provider),
|
|
1098
1119
|
);
|
|
1099
1120
|
if (providerIds.size === 0) providerIds.add(primaryProviderId(account.config));
|
|
1100
1121
|
for (const pid of providerIds) {
|
|
1122
|
+
if (account.invalidProviders?.[pid]) continue;
|
|
1123
|
+
if (this.isProviderOffForAccount(account, pid)) continue;
|
|
1124
|
+
const providerQuotaCtx: QuotaFetchContext = {
|
|
1125
|
+
...quotaCtx,
|
|
1126
|
+
reportQuotaPollFlag: (acc, statusCode, errorText) =>
|
|
1127
|
+
this.reportQuotaPollFlag(acc, statusCode, errorText, "quota-poll", pid),
|
|
1128
|
+
};
|
|
1101
1129
|
try {
|
|
1102
1130
|
await this.ensureValidTokenForProvider(account, pid);
|
|
1103
|
-
await getProviderAdapter(pid).fetchQuota(account,
|
|
1131
|
+
await getProviderAdapter(pid).fetchQuota(account, providerQuotaCtx);
|
|
1104
1132
|
if (pid === DEFAULT_PROVIDER) {
|
|
1105
1133
|
this.migratePersistedQuotaStateKeys();
|
|
1106
1134
|
}
|
|
@@ -1233,7 +1261,11 @@ export class AccountRotator {
|
|
|
1233
1261
|
statusCode: number,
|
|
1234
1262
|
errorText: string,
|
|
1235
1263
|
model = "quota-poll",
|
|
1264
|
+
providerId?: string,
|
|
1236
1265
|
): void {
|
|
1266
|
+
// Only emit flag telemetry on the transition into an invalid state; never
|
|
1267
|
+
// re-emit on repeated polls/kickstarts for an already-invalidated provider.
|
|
1268
|
+
if (providerId && account.invalidProviders?.[providerId]) return;
|
|
1237
1269
|
const modelKey = model === "quota-poll" ? account.quota[0]?.modelKey ?? model : model;
|
|
1238
1270
|
const ctx = this.getFlagContext(account, modelKey);
|
|
1239
1271
|
const lower = errorText.toLowerCase();
|
|
@@ -1325,6 +1357,7 @@ export class AccountRotator {
|
|
|
1325
1357
|
providerId: string;
|
|
1326
1358
|
adapter: ReturnType<typeof getProviderAdapter>;
|
|
1327
1359
|
upstreamModel: string;
|
|
1360
|
+
upstreamModels: string[];
|
|
1328
1361
|
} | null {
|
|
1329
1362
|
const poolKey = this.resolveAccountPoolKey(account, quotaModelKey);
|
|
1330
1363
|
const quota = account.quota.find((candidate) => candidate.modelKey === poolKey);
|
|
@@ -1334,9 +1367,20 @@ export class AccountRotator {
|
|
|
1334
1367
|
if (!hasCredential(account.config, providerId)) return null;
|
|
1335
1368
|
|
|
1336
1369
|
const adapter = getProviderAdapter(providerId);
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1339
|
-
|
|
1370
|
+
const candidates = adapter.getKickstartModelsForPool
|
|
1371
|
+
? adapter.getKickstartModelsForPool(poolKey, account)
|
|
1372
|
+
: (() => {
|
|
1373
|
+
const single = adapter.getKickstartModelForPool(poolKey);
|
|
1374
|
+
return single ? [single] : [];
|
|
1375
|
+
})();
|
|
1376
|
+
if (candidates.length === 0) return null;
|
|
1377
|
+
return {
|
|
1378
|
+
poolKey,
|
|
1379
|
+
providerId,
|
|
1380
|
+
adapter,
|
|
1381
|
+
upstreamModel: candidates[0],
|
|
1382
|
+
upstreamModels: candidates,
|
|
1383
|
+
};
|
|
1340
1384
|
}
|
|
1341
1385
|
|
|
1342
1386
|
// Timer priority for a specific model:
|
|
@@ -4408,7 +4452,7 @@ export class AccountRotator {
|
|
|
4408
4452
|
quota: a.quota,
|
|
4409
4453
|
inFlightRequests: a.inFlightRequests,
|
|
4410
4454
|
inFlightByModel: a.inFlightByModel,
|
|
4411
|
-
proDetected: a.config
|
|
4455
|
+
proDetected: isPaidAccountConfig(a.config),
|
|
4412
4456
|
tier: a.config.tier || "unknown",
|
|
4413
4457
|
healthScore: a.healthScore,
|
|
4414
4458
|
tokenBucket,
|
|
@@ -4664,7 +4708,7 @@ export class AccountRotator {
|
|
|
4664
4708
|
).length;
|
|
4665
4709
|
|
|
4666
4710
|
return {
|
|
4667
|
-
wasProAccount: account.config
|
|
4711
|
+
wasProAccount: isPaidAccountConfig(account.config),
|
|
4668
4712
|
accountQuotaPercent: quota,
|
|
4669
4713
|
timerType,
|
|
4670
4714
|
poolSize: this.accounts.length,
|
|
@@ -4696,15 +4740,20 @@ export class AccountRotator {
|
|
|
4696
4740
|
existing.consecutiveErrors = 0;
|
|
4697
4741
|
existing.accessToken = null;
|
|
4698
4742
|
existing.tokenExpires = 0;
|
|
4699
|
-
|
|
4743
|
+
const updatedProviders = new Set<string>(
|
|
4744
|
+
(accountConfig.credentials ?? []).map((credential) => credential.provider),
|
|
4745
|
+
);
|
|
4746
|
+
if (accountConfig.refreshToken) updatedProviders.add(DEFAULT_PROVIDER);
|
|
4747
|
+
if (receivesCodexCredential) updatedProviders.add("openai-codex");
|
|
4748
|
+
for (const pid of updatedProviders) {
|
|
4700
4749
|
if (existing.invalidProviders) {
|
|
4701
|
-
delete existing.invalidProviders[
|
|
4750
|
+
delete existing.invalidProviders[pid];
|
|
4702
4751
|
if (Object.keys(existing.invalidProviders).length === 0) {
|
|
4703
4752
|
delete existing.invalidProviders;
|
|
4704
4753
|
}
|
|
4705
4754
|
}
|
|
4706
4755
|
if (existing.providerTokens) {
|
|
4707
|
-
delete existing.providerTokens[
|
|
4756
|
+
delete existing.providerTokens[pid];
|
|
4708
4757
|
if (Object.keys(existing.providerTokens).length === 0) {
|
|
4709
4758
|
delete existing.providerTokens;
|
|
4710
4759
|
}
|
|
@@ -5089,7 +5138,18 @@ export class AccountRotator {
|
|
|
5089
5138
|
error: "provider turned off on the Models page",
|
|
5090
5139
|
};
|
|
5091
5140
|
}
|
|
5092
|
-
if (
|
|
5141
|
+
if (account.invalidProviders?.[target.providerId]) {
|
|
5142
|
+
return {
|
|
5143
|
+
ok: false,
|
|
5144
|
+
status: 409,
|
|
5145
|
+
upstreamModel: target.upstreamModel,
|
|
5146
|
+
error: `${target.providerId} credential requires re-authentication`,
|
|
5147
|
+
};
|
|
5148
|
+
}
|
|
5149
|
+
const enabledCandidates = target.upstreamModels.filter(
|
|
5150
|
+
(model) => !isProviderModelOff(this, target.providerId, model),
|
|
5151
|
+
);
|
|
5152
|
+
if (enabledCandidates.length === 0) {
|
|
5093
5153
|
return {
|
|
5094
5154
|
ok: false,
|
|
5095
5155
|
status: 409,
|
|
@@ -5098,13 +5158,23 @@ export class AccountRotator {
|
|
|
5098
5158
|
};
|
|
5099
5159
|
}
|
|
5100
5160
|
|
|
5101
|
-
const
|
|
5102
|
-
|
|
5161
|
+
const now = Date.now();
|
|
5162
|
+
const runnableCandidates: string[] = [];
|
|
5163
|
+
let activeDenial: { until: number; status: number; reason: string } | undefined;
|
|
5164
|
+
for (const model of enabledCandidates) {
|
|
5165
|
+
const denial = this.kickstartDeniedUntil.get(`${email}\0${model}`);
|
|
5166
|
+
if (!denial || denial.until <= now) {
|
|
5167
|
+
runnableCandidates.push(model);
|
|
5168
|
+
} else {
|
|
5169
|
+
activeDenial ??= denial;
|
|
5170
|
+
}
|
|
5171
|
+
}
|
|
5172
|
+
if (runnableCandidates.length === 0) {
|
|
5103
5173
|
return {
|
|
5104
5174
|
ok: false,
|
|
5105
|
-
status: 403,
|
|
5106
|
-
upstreamModel:
|
|
5107
|
-
error: "kickstart temporarily skipped after model-specific
|
|
5175
|
+
status: activeDenial?.status ?? 403,
|
|
5176
|
+
upstreamModel: enabledCandidates[0],
|
|
5177
|
+
error: activeDenial?.reason ?? "kickstart temporarily skipped after model-specific failure",
|
|
5108
5178
|
};
|
|
5109
5179
|
}
|
|
5110
5180
|
|
|
@@ -5126,7 +5196,6 @@ export class AccountRotator {
|
|
|
5126
5196
|
return { ok: false, status: 401, upstreamModel: "", error: "no access token" };
|
|
5127
5197
|
}
|
|
5128
5198
|
|
|
5129
|
-
const upstreamModel = target.upstreamModel;
|
|
5130
5199
|
const poolKey = target.poolKey;
|
|
5131
5200
|
|
|
5132
5201
|
const activeCooldown = Math.max(
|
|
@@ -5137,180 +5206,217 @@ export class AccountRotator {
|
|
|
5137
5206
|
return {
|
|
5138
5207
|
ok: false,
|
|
5139
5208
|
status: 429,
|
|
5140
|
-
upstreamModel,
|
|
5209
|
+
upstreamModel: runnableCandidates[0],
|
|
5141
5210
|
error: `quota cooldown active for ${Math.ceil((activeCooldown - Date.now()) / 1000)}s`,
|
|
5142
5211
|
};
|
|
5143
5212
|
}
|
|
5144
5213
|
|
|
5145
|
-
const
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5214
|
+
const label = account.config.label || account.config.email;
|
|
5215
|
+
let failedFrom: string | null = null;
|
|
5216
|
+
for (let index = 0; index < runnableCandidates.length; index++) {
|
|
5217
|
+
const upstreamModel = runnableCandidates[index];
|
|
5218
|
+
const denialKey = `${email}\0${upstreamModel}`;
|
|
5219
|
+
const nextCandidate = runnableCandidates[index + 1];
|
|
5220
|
+
const controller = new AbortController();
|
|
5221
|
+
const timeout = setTimeout(() => controller.abort(), 15_000);
|
|
5222
|
+
|
|
5223
|
+
let response: Response;
|
|
5224
|
+
if (kickstartAdapter.forwardKickstartRequest) {
|
|
5225
|
+
try {
|
|
5226
|
+
const forwarded = await kickstartAdapter.forwardKickstartRequest(
|
|
5227
|
+
account,
|
|
5228
|
+
upstreamModel,
|
|
5229
|
+
controller.signal,
|
|
5230
|
+
);
|
|
5231
|
+
response = forwarded.response;
|
|
5232
|
+
} catch (err) {
|
|
5233
|
+
clearTimeout(timeout);
|
|
5234
|
+
const msg = `kickstart network error: ${err instanceof Error ? err.message : String(err)}`;
|
|
5235
|
+
this.markError(account, msg);
|
|
5236
|
+
return { ok: false, status: 0, upstreamModel, error: msg };
|
|
5237
|
+
}
|
|
5158
5238
|
clearTimeout(timeout);
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5239
|
+
} else if (isOllamaAccount) {
|
|
5240
|
+
const ollamaBody: RequestBody = {
|
|
5241
|
+
project: "",
|
|
5242
|
+
model: upstreamModel,
|
|
5243
|
+
request: {
|
|
5244
|
+
messages: [{ role: "user", content: "." }],
|
|
5245
|
+
options: { num_predict: 1 },
|
|
5246
|
+
stream: false,
|
|
5247
|
+
},
|
|
5248
|
+
};
|
|
5249
|
+
try {
|
|
5250
|
+
const forwarded = await kickstartAdapter.forwardRequest(
|
|
5251
|
+
account,
|
|
5252
|
+
ollamaBody,
|
|
5253
|
+
{},
|
|
5254
|
+
controller.signal,
|
|
5255
|
+
);
|
|
5256
|
+
response = forwarded.response;
|
|
5257
|
+
} catch (err) {
|
|
5258
|
+
clearTimeout(timeout);
|
|
5259
|
+
const msg = `kickstart network error: ${err instanceof Error ? err.message : String(err)}`;
|
|
5260
|
+
this.markError(account, msg);
|
|
5261
|
+
return { ok: false, status: 0, upstreamModel, error: msg };
|
|
5262
|
+
}
|
|
5183
5263
|
clearTimeout(timeout);
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
project: this.getProjectIdForModel(account, poolKey),
|
|
5192
|
-
model: upstreamModel,
|
|
5193
|
-
request: {
|
|
5194
|
-
contents: [{ role: "user", parts: [{ text: "." }] }],
|
|
5195
|
-
generationConfig: { maxOutputTokens: 1 },
|
|
5196
|
-
},
|
|
5197
|
-
});
|
|
5198
|
-
|
|
5199
|
-
const endpoint = ANTIGRAVITY_ENDPOINTS[ANTIGRAVITY_ENDPOINTS.length - 1];
|
|
5200
|
-
const url = `${endpoint}/v1internal:streamGenerateContent?alt=sse`;
|
|
5201
|
-
|
|
5202
|
-
try {
|
|
5203
|
-
response = await fetch(url, {
|
|
5204
|
-
method: "POST",
|
|
5205
|
-
headers: {
|
|
5206
|
-
"Content-Type": "application/json",
|
|
5207
|
-
Authorization: `Bearer ${account.accessToken}`,
|
|
5208
|
-
"User-Agent": QUOTA_USER_AGENT,
|
|
5209
|
-
"X-Goog-Api-Client": REQUEST_GOOG_API_CLIENT,
|
|
5210
|
-
"Client-Metadata": REQUEST_CLIENT_METADATA,
|
|
5264
|
+
} else {
|
|
5265
|
+
const body = JSON.stringify({
|
|
5266
|
+
project: this.getProjectIdForModel(account, poolKey),
|
|
5267
|
+
model: upstreamModel,
|
|
5268
|
+
request: {
|
|
5269
|
+
contents: [{ role: "user", parts: [{ text: "." }] }],
|
|
5270
|
+
generationConfig: { maxOutputTokens: 1 },
|
|
5211
5271
|
},
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5272
|
+
});
|
|
5273
|
+
|
|
5274
|
+
const endpoint = ANTIGRAVITY_ENDPOINTS[ANTIGRAVITY_ENDPOINTS.length - 1];
|
|
5275
|
+
const url = `${endpoint}/v1internal:streamGenerateContent?alt=sse`;
|
|
5276
|
+
try {
|
|
5277
|
+
response = await fetch(url, {
|
|
5278
|
+
method: "POST",
|
|
5279
|
+
headers: {
|
|
5280
|
+
"Content-Type": "application/json",
|
|
5281
|
+
Authorization: `Bearer ${account.accessToken}`,
|
|
5282
|
+
"User-Agent": QUOTA_USER_AGENT,
|
|
5283
|
+
"X-Goog-Api-Client": REQUEST_GOOG_API_CLIENT,
|
|
5284
|
+
"Client-Metadata": REQUEST_CLIENT_METADATA,
|
|
5285
|
+
},
|
|
5286
|
+
body,
|
|
5287
|
+
signal: controller.signal,
|
|
5288
|
+
dispatcher: getAccountProxyDispatcher(account, "google-antigravity"),
|
|
5289
|
+
} as RequestInitWithDispatcher);
|
|
5290
|
+
} catch (err) {
|
|
5291
|
+
clearTimeout(timeout);
|
|
5292
|
+
const msg = `kickstart network error: ${err instanceof Error ? err.message : String(err)}`;
|
|
5293
|
+
this.markError(account, msg);
|
|
5294
|
+
return { ok: false, status: 0, upstreamModel, error: msg };
|
|
5295
|
+
}
|
|
5217
5296
|
clearTimeout(timeout);
|
|
5218
|
-
const msg = `kickstart network error: ${err instanceof Error ? err.message : String(err)}`;
|
|
5219
|
-
this.markError(account, msg);
|
|
5220
|
-
return { ok: false, status: 0, upstreamModel, error: msg };
|
|
5221
5297
|
}
|
|
5222
|
-
clearTimeout(timeout);
|
|
5223
|
-
}
|
|
5224
5298
|
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5299
|
+
let errorText = "";
|
|
5300
|
+
if (response.status === 429 || response.status === 401 || response.status === 403) {
|
|
5301
|
+
errorText = await response.text().catch(() => "");
|
|
5302
|
+
} else {
|
|
5303
|
+
try {
|
|
5304
|
+
await response.body?.cancel();
|
|
5305
|
+
} catch {
|
|
5306
|
+
// ignore
|
|
5307
|
+
}
|
|
5234
5308
|
}
|
|
5235
|
-
}
|
|
5236
|
-
|
|
5237
|
-
const label = account.config.label || account.config.email;
|
|
5238
5309
|
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
?
|
|
5245
|
-
|
|
5246
|
-
|
|
5310
|
+
if (response.status === 429) {
|
|
5311
|
+
this.kickstartDeniedUntil.delete(denialKey);
|
|
5312
|
+
const providerResourceExhausted =
|
|
5313
|
+
classifyRateLimitReason(errorText, response.status) === "quota-exhausted";
|
|
5314
|
+
const cooldownMs = providerResourceExhausted
|
|
5315
|
+
? target.providerId === DEFAULT_PROVIDER || target.providerId === "openai-codex"
|
|
5316
|
+
? parseRetryAfterMs(
|
|
5317
|
+
errorText,
|
|
5318
|
+
response.headers,
|
|
5319
|
+
RESOURCE_EXHAUSTED_FALLBACK_MS,
|
|
5320
|
+
)
|
|
5321
|
+
: RESOURCE_EXHAUSTED_FALLBACK_MS
|
|
5322
|
+
: Math.min(
|
|
5323
|
+
parseRetryAfterMs(errorText, response.headers),
|
|
5247
5324
|
RESOURCE_EXHAUSTED_FALLBACK_MS,
|
|
5248
|
-
)
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5325
|
+
);
|
|
5326
|
+
this.markExhausted(account, poolKey, cooldownMs, errorText || "kickstart 429");
|
|
5327
|
+
this.recordProvider429(account, poolKey, cooldownMs, providerResourceExhausted);
|
|
5328
|
+
this.log(
|
|
5329
|
+
`${label} [${poolKey}]: kickstart 429 — cooldown ${cooldownMs / 1000}s`,
|
|
5330
|
+
"warn",
|
|
5331
|
+
);
|
|
5332
|
+
return { ok: false, status: 429, upstreamModel };
|
|
5333
|
+
}
|
|
5334
|
+
|
|
5335
|
+
if (response.status === 401 || response.status === 403) {
|
|
5336
|
+
const failure = describeKickstartAuthFailure(response.status, upstreamModel, errorText);
|
|
5337
|
+
if (target.providerId === "openai-codex") {
|
|
5338
|
+
this.markProviderInvalid(account, target.providerId, failure.description);
|
|
5339
|
+
return { ok: false, status: response.status, upstreamModel, error: failure.description };
|
|
5340
|
+
}
|
|
5341
|
+
if (failure.accountEnforcement) {
|
|
5342
|
+
this.kickstartDeniedUntil.delete(denialKey);
|
|
5343
|
+
// Enforcement errors invalidate the provider credential, not sibling providers.
|
|
5344
|
+
this.reportQuotaPollFlag(account, response.status, errorText, upstreamModel, target.providerId);
|
|
5345
|
+
this.markProviderInvalid(account, target.providerId, failure.description);
|
|
5346
|
+
return { ok: false, status: response.status, upstreamModel, error: failure.description };
|
|
5347
|
+
}
|
|
5348
|
+
const reason = `kickstart temporarily skipped after model-specific ${response.status}`;
|
|
5349
|
+
this.kickstartDeniedUntil.set(denialKey, {
|
|
5350
|
+
until: Date.now() + 30 * 60 * 1000,
|
|
5351
|
+
status: response.status,
|
|
5352
|
+
reason,
|
|
5353
|
+
});
|
|
5354
|
+
if (nextCandidate) {
|
|
5355
|
+
failedFrom ??= `${response.status} on ${upstreamModel}`;
|
|
5356
|
+
this.log(
|
|
5357
|
+
`${label} [${poolKey}]: ${failure.description}; trying fallback ${nextCandidate}`,
|
|
5358
|
+
"warn",
|
|
5253
5359
|
);
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
poolKey,
|
|
5257
|
-
cooldownMs,
|
|
5258
|
-
errorText || "kickstart 429",
|
|
5259
|
-
);
|
|
5260
|
-
this.recordProvider429(
|
|
5261
|
-
account,
|
|
5262
|
-
poolKey,
|
|
5263
|
-
cooldownMs,
|
|
5264
|
-
providerResourceExhausted,
|
|
5265
|
-
);
|
|
5266
|
-
this.log(
|
|
5267
|
-
`${label} [${poolKey}]: kickstart 429 — cooldown ${cooldownMs / 1000}s`,
|
|
5268
|
-
"warn",
|
|
5269
|
-
);
|
|
5270
|
-
return { ok: false, status: 429, upstreamModel };
|
|
5271
|
-
}
|
|
5272
|
-
|
|
5273
|
-
if (response.status === 401 || response.status === 403) {
|
|
5274
|
-
const failure = describeKickstartAuthFailure(response.status, upstreamModel, errorText);
|
|
5275
|
-
if (target.providerId === "openai-codex") {
|
|
5276
|
-
this.markProviderInvalid(account, target.providerId, failure.description);
|
|
5277
|
-
} else if (failure.accountEnforcement) {
|
|
5278
|
-
// Provider-scoped invalidation: even with account-enforcement language
|
|
5279
|
-
// in the response, only the specific provider credential is invalidated.
|
|
5280
|
-
// Sibling providers on the same account remain routable.
|
|
5281
|
-
this.reportQuotaPollFlag(account, response.status, errorText, upstreamModel);
|
|
5282
|
-
this.markProviderInvalid(account, target.providerId, failure.description);
|
|
5283
|
-
} else {
|
|
5360
|
+
continue;
|
|
5361
|
+
}
|
|
5284
5362
|
account.lastError = failure.description;
|
|
5285
|
-
this.
|
|
5363
|
+
this.scheduleStateSave();
|
|
5286
5364
|
this.log(`${label}: ${failure.description}; retrying kickstart after 30 minutes`, "warn");
|
|
5365
|
+
return { ok: false, status: response.status, upstreamModel, error: failure.description };
|
|
5287
5366
|
}
|
|
5288
|
-
return { ok: false, status: response.status, upstreamModel, error: failure.description };
|
|
5289
|
-
}
|
|
5290
5367
|
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5368
|
+
this.kickstartDeniedUntil.delete(denialKey);
|
|
5369
|
+
|
|
5370
|
+
if (response.status === 400 || response.status === 404 || response.status >= 500) {
|
|
5371
|
+
const backoffMs = response.status >= 500 ? 15 * 60 * 1000 : 30 * 60 * 1000;
|
|
5372
|
+
const message = `kickstart ${response.status} on ${upstreamModel}`;
|
|
5373
|
+
this.kickstartDeniedUntil.set(denialKey, {
|
|
5374
|
+
until: Date.now() + backoffMs,
|
|
5375
|
+
status: response.status,
|
|
5376
|
+
reason: `kickstart temporarily skipped after ${response.status} on ${upstreamModel}`,
|
|
5377
|
+
});
|
|
5378
|
+
if (nextCandidate) {
|
|
5379
|
+
failedFrom ??= `${response.status} on ${upstreamModel}`;
|
|
5380
|
+
this.log(
|
|
5381
|
+
`${label} [${poolKey}]: ${message}; trying fallback ${nextCandidate}`,
|
|
5382
|
+
"warn",
|
|
5383
|
+
);
|
|
5384
|
+
continue;
|
|
5385
|
+
}
|
|
5386
|
+
// Model-specific upstream failures must not count toward disabling a healthy account.
|
|
5387
|
+
account.lastError = message;
|
|
5388
|
+
this.scheduleStateSave();
|
|
5389
|
+
this.log(
|
|
5390
|
+
`${label} [${poolKey}]: ${message}; retrying kickstart after ${backoffMs / 60_000} minutes`,
|
|
5391
|
+
"warn",
|
|
5392
|
+
);
|
|
5393
|
+
return { ok: false, status: response.status, upstreamModel, error: message };
|
|
5394
|
+
}
|
|
5295
5395
|
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5396
|
+
if (response.ok) {
|
|
5397
|
+
this.recordRequest(account, poolKey);
|
|
5398
|
+
target.adapter.clearQuotaCache?.(account);
|
|
5399
|
+
const fallbackNote = failedFrom ? ` (fallback after ${failedFrom})` : "";
|
|
5400
|
+
this.log(
|
|
5401
|
+
`${label} [${poolKey}]: kickstart sent via ${upstreamModel}${fallbackNote} — ${refreshQuota ? "refreshing quota" : "bulk quota refresh pending"}`,
|
|
5402
|
+
);
|
|
5403
|
+
if (refreshQuota) {
|
|
5404
|
+
try {
|
|
5405
|
+
await this.pollAccountQuota(account);
|
|
5406
|
+
} catch {
|
|
5407
|
+
// non-fatal
|
|
5408
|
+
}
|
|
5309
5409
|
}
|
|
5310
5410
|
}
|
|
5411
|
+
return { ok: response.ok, status: response.status, upstreamModel };
|
|
5311
5412
|
}
|
|
5312
5413
|
|
|
5313
|
-
return {
|
|
5414
|
+
return {
|
|
5415
|
+
ok: false,
|
|
5416
|
+
status: 503,
|
|
5417
|
+
upstreamModel: target.upstreamModel,
|
|
5418
|
+
error: `kickstart failed on all candidates for ${poolKey}`,
|
|
5419
|
+
};
|
|
5314
5420
|
}
|
|
5315
5421
|
|
|
5316
5422
|
/**
|
|
@@ -5333,11 +5439,14 @@ export class AccountRotator {
|
|
|
5333
5439
|
return { ok: false, error: "account not found", results: [] };
|
|
5334
5440
|
}
|
|
5335
5441
|
|
|
5336
|
-
const idlePools = account.quota.filter(
|
|
5337
|
-
(q)
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5442
|
+
const idlePools = account.quota.filter((q) => {
|
|
5443
|
+
if (!this.isQuotaIdleForKickstart(q)) return false;
|
|
5444
|
+
const target = this.getKickstartTarget(account, q.modelKey);
|
|
5445
|
+
if (!target) return false;
|
|
5446
|
+
if (account.invalidProviders?.[target.providerId]) return false;
|
|
5447
|
+
if (this.isProviderOffForAccount(account, target.providerId)) return false;
|
|
5448
|
+
return true;
|
|
5449
|
+
});
|
|
5341
5450
|
if (idlePools.length === 0) {
|
|
5342
5451
|
return { ok: true, results: [] };
|
|
5343
5452
|
}
|
|
@@ -5369,7 +5478,12 @@ export class AccountRotator {
|
|
|
5369
5478
|
primaryQuotaKey,
|
|
5370
5479
|
false,
|
|
5371
5480
|
);
|
|
5372
|
-
results.push({
|
|
5481
|
+
results.push({
|
|
5482
|
+
quotaPools,
|
|
5483
|
+
upstreamModel: result.upstreamModel || upstreamModel,
|
|
5484
|
+
ok: result.ok,
|
|
5485
|
+
status: result.status,
|
|
5486
|
+
});
|
|
5373
5487
|
}
|
|
5374
5488
|
|
|
5375
5489
|
if (results.some((result) => result.ok)) {
|
package/src/types.ts
CHANGED
|
@@ -1306,6 +1306,22 @@ export const KICKSTART_MODEL_FOR_QUOTA_POOL: Record<string, string> = {
|
|
|
1306
1306
|
"gemini": "gemini-3-flash",
|
|
1307
1307
|
};
|
|
1308
1308
|
|
|
1309
|
+
// Ordered fallback candidates per Antigravity quota pool (cheapest first; never Opus).
|
|
1310
|
+
export const KICKSTART_FALLBACK_MODELS_FOR_QUOTA_POOL: Record<string, readonly string[]> = {
|
|
1311
|
+
claude: ["gpt-oss-120b-medium", "claude-sonnet-4-6"],
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
// Paid (Pro/Ultra) Antigravity accounts advertise Claude 5.5 models and can hit
|
|
1315
|
+
// 503 on gpt-oss-120b-medium; prefer the cheapest low-effort Sonnet 5.5 model first.
|
|
1316
|
+
export const KICKSTART_PRO_MODELS_FOR_QUOTA_POOL: Record<string, readonly string[]> = {
|
|
1317
|
+
claude: [
|
|
1318
|
+
"claude-sonnet-5-5-low",
|
|
1319
|
+
"claude-sonnet-5-5-medium",
|
|
1320
|
+
"claude-sonnet-4-6",
|
|
1321
|
+
"gpt-oss-120b-medium",
|
|
1322
|
+
],
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1309
1325
|
export const QUOTA_API_URL =
|
|
1310
1326
|
"https://daily-cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels";
|
|
1311
1327
|
|