@cortexkit/opencode-antigravity-auth 3.0.24 → 3.0.26

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.
@@ -58,7 +58,7 @@
58
58
  "format": "esm"
59
59
  },
60
60
  "../core/dist/account-migration.js": {
61
- "bytes": 181364,
61
+ "bytes": 183913,
62
62
  "imports": [
63
63
  {
64
64
  "path": "node:crypto",
@@ -171,7 +171,7 @@
171
171
  "format": "esm"
172
172
  },
173
173
  "../core/dist/account-selector.js": {
174
- "bytes": 58735,
174
+ "bytes": 61373,
175
175
  "imports": [
176
176
  {
177
177
  "path": "../core/dist/fingerprint.js",
@@ -285,7 +285,7 @@
285
285
  "format": "esm"
286
286
  },
287
287
  "../core/dist/account-manager.js": {
288
- "bytes": 68295,
288
+ "bytes": 68562,
289
289
  "imports": [
290
290
  {
291
291
  "path": "node:crypto",
@@ -3173,7 +3173,7 @@
3173
3173
  "format": "esm"
3174
3174
  },
3175
3175
  "src/plugin/storage.ts": {
3176
- "bytes": 28304,
3176
+ "bytes": 28395,
3177
3177
  "imports": [
3178
3178
  {
3179
3179
  "path": "node:fs",
@@ -4355,7 +4355,7 @@
4355
4355
  "imports": [],
4356
4356
  "exports": [],
4357
4357
  "inputs": {},
4358
- "bytes": 3173161
4358
+ "bytes": 3180370
4359
4359
  },
4360
4360
  "dist/cli.js": {
4361
4361
  "imports": [
@@ -5146,7 +5146,7 @@
5146
5146
  "bytesInOutput": 10845
5147
5147
  },
5148
5148
  "../core/dist/account-migration.js": {
5149
- "bytesInOutput": 148478
5149
+ "bytesInOutput": 150328
5150
5150
  },
5151
5151
  "../core/dist/account-repository.js": {
5152
5152
  "bytesInOutput": 78687
@@ -5542,7 +5542,7 @@
5542
5542
  "bytesInOutput": 46416
5543
5543
  },
5544
5544
  "src/plugin/storage.ts": {
5545
- "bytesInOutput": 11075
5545
+ "bytesInOutput": 11142
5546
5546
  },
5547
5547
  "src/runtime-paths.ts": {
5548
5548
  "bytesInOutput": 6278
@@ -5677,7 +5677,7 @@
5677
5677
  "bytesInOutput": 292
5678
5678
  }
5679
5679
  },
5680
- "bytes": 1190036
5680
+ "bytes": 1191953
5681
5681
  }
5682
5682
  }
5683
5683
  }
package/dist/index.js CHANGED
@@ -1801,6 +1801,8 @@ function openMigrationStore(modules, paths, now, onStep) {
1801
1801
  }
1802
1802
  async function rowsOf(store) {
1803
1803
  const read = await store.read();
1804
+ if (read.status === "error" && read.kind === "snapshot-contended")
1805
+ throw new AccountStoreBusyError();
1804
1806
  if (read.status !== "ready")
1805
1807
  throw new AccountMigrationError("successor is not a ready public store");
1806
1808
  return read.rows;
@@ -2009,8 +2011,46 @@ function receipt(journal) {
2009
2011
  restartRequired: journal.sourceKind !== "absent" || journal.operation === "rollback"
2010
2012
  };
2011
2013
  }
2014
+ async function readAdmissionState(path5) {
2015
+ try {
2016
+ const bytes = await secureRead(path5);
2017
+ return { bytes, stamp: digest(bytes) };
2018
+ } catch (error) {
2019
+ if (errno(error) === "ENOENT")
2020
+ return { bytes: void 0, stamp: void 0 };
2021
+ throw error;
2022
+ }
2023
+ }
2012
2024
  async function currentSuccessor(store, paths, journal) {
2013
- const config = object(jsonBytes(await secureRead(paths.configPath)), "active config");
2025
+ for (let attempt = 0; attempt < ADMISSION_SNAPSHOT_ATTEMPTS; attempt++) {
2026
+ const configBytes = await secureRead(paths.configPath);
2027
+ let state;
2028
+ let snapshot2;
2029
+ let failure2;
2030
+ try {
2031
+ state = await readAdmissionState(paths.statePath);
2032
+ snapshot2 = {
2033
+ stateBytes: state.bytes,
2034
+ rows: await rowsOf(store),
2035
+ settings: await settingsOf(store)
2036
+ };
2037
+ } catch (error) {
2038
+ failure2 = { error };
2039
+ }
2040
+ const checkedConfigBytes = await secureRead(paths.configPath);
2041
+ const checkedState = await readAdmissionState(paths.statePath);
2042
+ if (digest(configBytes) !== digest(checkedConfigBytes) || state !== void 0 && state.stamp !== checkedState.stamp)
2043
+ continue;
2044
+ if (failure2)
2045
+ throw failure2.error;
2046
+ if (!snapshot2)
2047
+ throw new AccountMigrationError("active snapshot missing");
2048
+ return validateCurrentSuccessor(journal, configBytes, snapshot2.stateBytes, snapshot2.rows, snapshot2.settings);
2049
+ }
2050
+ throw new AccountStoreBusyError();
2051
+ }
2052
+ function validateCurrentSuccessor(journal, configBytes, stateBytes, rows, settings) {
2053
+ const config = object(jsonBytes(configBytes), "active config");
2014
2054
  if (config.version !== 1 || !Array.isArray(config.accounts))
2015
2055
  throw new AccountMigrationError("active config lacks its native roster");
2016
2056
  const pool = object(config.commonAuthPool, "active native pool");
@@ -2027,15 +2067,14 @@ async function currentSuccessor(store, paths, journal) {
2027
2067
  if (new Set(nativeIds).size !== nativeIds.length || Object.keys(entries).length !== nativeIds.length || Object.keys(entries).some((id) => !nativeIds.includes(id)))
2028
2068
  throw new AccountMigrationError("active native entry/roster presence differs");
2029
2069
  let stateAccounts = {};
2030
- if (await exists(paths.statePath)) {
2031
- const state = object(jsonBytes(await secureRead(paths.statePath)), "active state");
2070
+ if (stateBytes !== void 0) {
2071
+ const state = object(jsonBytes(stateBytes), "active state");
2032
2072
  if (state.version !== 1)
2033
2073
  throw new AccountMigrationError("active native state schema differs");
2034
2074
  stateAccounts = object(state.accounts, "active state accounts");
2035
2075
  }
2036
2076
  if (Object.keys(stateAccounts).length !== nativeIds.length || Object.keys(stateAccounts).some((id) => !nativeIds.includes(id)))
2037
2077
  throw new AccountMigrationError("active state contains orphan or missing credentials");
2038
- const rows = await rowsOf(store);
2039
2078
  if (!isDeepStrictEqual(rows.map((row) => row.id), nativeIds))
2040
2079
  throw new AccountMigrationError("public and native active roster order differs");
2041
2080
  rows.forEach((row) => {
@@ -2044,10 +2083,10 @@ async function currentSuccessor(store, paths, journal) {
2044
2083
  if (entry.credentialEpoch !== rowRef(row).credentialEpoch || Object.hasOwn(entry, "quota") !== (row.quota !== void 0) || row.quota !== void 0 && !isDeepStrictEqual(entry.quota, row.quota))
2045
2084
  throw new AccountMigrationError("active native epoch or quota presence differs from public row");
2046
2085
  });
2047
- const settings = await settingsOf(store);
2048
2086
  if (!isDeepStrictEqual(decodeAccountStoreGeneration(settings[ACCOUNT_STORE_GENERATION_SETTINGS_KEY]), generationJson(journal)))
2049
2087
  throw new AccountMigrationError("active generation setting differs from journal");
2050
2088
  decodeRoutingSettings(settings[ROUTING_SETTINGS_KEY]);
2089
+ return settings;
2051
2090
  }
2052
2091
  function openAdmissionStore(modules, paths, now) {
2053
2092
  return modules.store.openPoolStore({
@@ -2175,11 +2214,13 @@ async function readAccountStoreAdmission(legacyPath, modules, now, expectedGener
2175
2214
  if (!journal)
2176
2215
  throw new AccountMigrationError("active serving journal missing");
2177
2216
  const store = openAdmissionStore(modules, binding.paths, now);
2178
- await currentSuccessor(store, binding.paths, journal);
2179
- if ((await settingsOf(store))[MANAGEMENT_SETTINGS_KEY] !== void 0)
2217
+ const settings = await currentSuccessor(store, binding.paths, journal);
2218
+ if (settings[MANAGEMENT_SETTINGS_KEY] !== void 0)
2180
2219
  return { status: "pending" };
2181
2220
  return { status: "active", receipt: binding.receipt, paths: binding.paths };
2182
2221
  } catch (error) {
2222
+ if (error instanceof AccountStoreBusyError)
2223
+ return { status: "busy", retryable: true };
2183
2224
  return {
2184
2225
  status: "error",
2185
2226
  reason: error instanceof AccountMigrationError ? error.reason : "current credential serving validation failed"
@@ -3730,6 +3771,8 @@ async function initializePrivateEmptyGeneration(modules, paths, parentLease, man
3730
3771
  await expectedFreshArtifacts(paths, journal);
3731
3772
  await currentSuccessor(store, paths, journal);
3732
3773
  const admission = await readAccountStoreAdmission(paths.legacyPath, modules, options.now, journal.id);
3774
+ if (admission.status === "busy")
3775
+ throw new AccountStoreBusyError();
3733
3776
  if (admission.status !== "active" || !isDeepStrictEqual(admission.receipt, receipt(journal)))
3734
3777
  throw new AccountMigrationError("published empty generation is not admitted");
3735
3778
  await boundary?.("pointer:after-sync-before-stage-cleanup");
@@ -3865,7 +3908,7 @@ async function cleanupPointerStage(legacyPath, pointer, lease) {
3865
3908
  await unlink2(stage);
3866
3909
  return true;
3867
3910
  }
3868
- var AccountMigrationError, QUOTA_FIELDS, ACCOUNT_MIGRATION_PHASES, ACCOUNT_MIGRATION_MANAGEMENT_STEPS, ACCOUNT_STORE_GENERATION_SETTINGS_KEY, UUID, SHA256;
3911
+ var AccountMigrationError, QUOTA_FIELDS, ACCOUNT_MIGRATION_PHASES, ACCOUNT_MIGRATION_MANAGEMENT_STEPS, ACCOUNT_STORE_GENERATION_SETTINGS_KEY, UUID, SHA256, ADMISSION_SNAPSHOT_ATTEMPTS, AccountStoreBusyError;
3869
3912
  var init_account_migration = __esm({
3870
3913
  "../core/dist/account-migration.js"() {
3871
3914
  "use strict";
@@ -3897,6 +3940,14 @@ var init_account_migration = __esm({
3897
3940
  ACCOUNT_STORE_GENERATION_SETTINGS_KEY = "antigravityGeneration";
3898
3941
  UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
3899
3942
  SHA256 = /^[0-9a-f]{64}$/;
3943
+ ADMISSION_SNAPSHOT_ATTEMPTS = 3;
3944
+ AccountStoreBusyError = class extends Error {
3945
+ retryable = true;
3946
+ constructor() {
3947
+ super("The Antigravity account store is busy. Try again in a moment.");
3948
+ this.name = "AccountStoreBusyError";
3949
+ }
3950
+ };
3900
3951
  }
3901
3952
  });
3902
3953
 
@@ -7184,6 +7235,9 @@ var init_account_selector = __esm({
7184
7235
  const candidates = this.preferAccountOutsideParent(this.accounts.filter((acc) => {
7185
7236
  if (acc.enabled === false)
7186
7237
  return false;
7238
+ if (acc.accountIneligible === true || acc.verificationRequired === true) {
7239
+ return false;
7240
+ }
7187
7241
  if (acc.index === currentIndex)
7188
7242
  return false;
7189
7243
  clearExpiredRateLimits(acc, this.now);
@@ -7431,7 +7485,9 @@ var init_account_selector = __esm({
7431
7485
  *
7432
7486
  * Note: Returning `0` can mean either:
7433
7487
  * 1. No eligible candidates exist in the pool, OR
7434
- * 2. At least one eligible candidate is immediately usable without waiting.
7488
+ * 2. At least one eligible candidate is hard/cooldown-ready without waiting
7489
+ * (this does not imply the candidate is fully selectable, as soft quota
7490
+ * or session-level policies may still apply).
7435
7491
  * Callers must distinguish "no eligible candidates" from "zero wait time"
7436
7492
  * by inspecting candidate pool availability / eligibility directly.
7437
7493
  *
@@ -7439,7 +7495,7 @@ var init_account_selector = __esm({
7439
7495
  * @param model Optional model name for per-model rate limits
7440
7496
  * @param eligibleIndexes Optional set of account indexes permitted for this request
7441
7497
  * @param includeCooldown Whether to factor in `coolingDownUntil` alongside quota rate limits
7442
- * @returns Minimum wait duration in milliseconds, or 0 if immediately usable or no candidates
7498
+ * @returns Minimum wait duration in milliseconds, or 0 if hard/cooldown-ready or no candidates
7443
7499
  */
7444
7500
  getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown = false) {
7445
7501
  const now = this.now();
@@ -7637,8 +7693,51 @@ var init_account_selector = __esm({
7637
7693
  perAccount: perAccount.sort((a, b) => b.claude + b.gemini - (a.claude + a.gemini))
7638
7694
  };
7639
7695
  }
7640
- isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
7641
- return isOverSoftQuotaThreshold(account, family, this.getEffectiveSoftQuotaThreshold(thresholdPercent), cacheTtlMs, this.now, model);
7696
+ isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes) {
7697
+ return isOverSoftQuotaThreshold(account, family, this.getEffectiveSoftQuotaThreshold(thresholdPercent, excludeIndexes), cacheTtlMs, this.now, model);
7698
+ }
7699
+ /**
7700
+ * Calculates the minimum wait duration across eligible accounts until at least
7701
+ * one candidate becomes selectable.
7702
+ *
7703
+ * For each eligible account:
7704
+ * accountWait = max(hardCooldownWait, applicableSoftResetDelay)
7705
+ * where hardCooldownWait uses getMinWaitTimeForFamily(..., includeCooldown=true).
7706
+ * Soft quota is applicable if and only if eligible.length > 1 and thresholdPercent < 100.
7707
+ * Unknown soft reset renders that account an unknown candidate.
7708
+ * Returns minimum known accountWait, or null if no eligible candidates or all unknown.
7709
+ */
7710
+ getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7711
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7712
+ if (eligible.length === 0)
7713
+ return null;
7714
+ const now = this.now();
7715
+ const applySoftQuota = eligible.length > 1 && thresholdPercent < 100;
7716
+ const knownWaits = [];
7717
+ for (const acc of eligible) {
7718
+ const hardCooldownWait = this.getMinWaitTimeForFamily(family, model, /* @__PURE__ */ new Set([acc.index]), true);
7719
+ if (applySoftQuota && isOverSoftQuotaThreshold(acc, family, thresholdPercent, cacheTtlMs, this.now, model)) {
7720
+ if (!model && family !== "claude") {
7721
+ continue;
7722
+ }
7723
+ const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
7724
+ const groupData = acc.cachedQuota?.[quotaGroup];
7725
+ if (!groupData?.resetTime) {
7726
+ continue;
7727
+ }
7728
+ const resetTimestamp = Date.parse(groupData.resetTime);
7729
+ if (!Number.isFinite(resetTimestamp) || resetTimestamp <= now) {
7730
+ continue;
7731
+ }
7732
+ const softResetDelay = resetTimestamp - now;
7733
+ knownWaits.push(Math.max(hardCooldownWait, softResetDelay));
7734
+ } else {
7735
+ knownWaits.push(hardCooldownWait);
7736
+ }
7737
+ }
7738
+ if (knownWaits.length === 0)
7739
+ return null;
7740
+ return Math.min(...knownWaits);
7642
7741
  }
7643
7742
  getOldestQuotaCacheAge() {
7644
7743
  let oldest = null;
@@ -10020,8 +10119,8 @@ var init_account_manager = __esm({
10020
10119
  getSessionSummary() {
10021
10120
  return this.selection.getSessionSummary();
10022
10121
  }
10023
- isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
10024
- return this.selection.isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model);
10122
+ isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes) {
10123
+ return this.selection.isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes);
10025
10124
  }
10026
10125
  /**
10027
10126
  * The accounts a quota check should cover. For a repository-backed
@@ -10071,6 +10170,9 @@ var init_account_manager = __esm({
10071
10170
  getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10072
10171
  return this.selection.getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10073
10172
  }
10173
+ getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10174
+ return this.selection.getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10175
+ }
10074
10176
  };
10075
10177
  }
10076
10178
  });
@@ -32790,6 +32892,8 @@ async function assertLegacyPoolInUse(legacyPath) {
32790
32892
  }
32791
32893
  function refusalMessage2(admission) {
32792
32894
  switch (admission.status) {
32895
+ case "busy":
32896
+ return new AccountStoreBusyError().message;
32793
32897
  case "pending":
32794
32898
  return admission.operation === "rollback" ? `An account-store rollback is pending; rerun \`${ROLLBACK_COMMAND}\`.` : `An account-store migration is pending; stop every Antigravity process and rerun \`${MIGRATE_COMMAND}\`.`;
32795
32899
  case "inactive":
@@ -54366,8 +54470,8 @@ function createRequestExecutor(deps) {
54366
54470
  accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
54367
54471
  );
54368
54472
  if (modelUnavailableIndexes.size > 0) {
54369
- const candidates = accountManager.getEnabledAccounts().filter(
54370
- (entry) => eligibleIndexes === null || eligibleIndexes.has(entry.index)
54473
+ const candidates = accountManager.getAccounts().filter(
54474
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && (eligibleIndexes === null || eligibleIndexes.has(entry.index))
54371
54475
  );
54372
54476
  if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
54373
54477
  pushDebug(
@@ -54403,13 +54507,14 @@ function createRequestExecutor(deps) {
54403
54507
  if (account) {
54404
54508
  routingPlacementConsidered = true;
54405
54509
  if (firstPlacement && credentials.domain === "vault" && credentials.routingCandidate && model && isPrimaryVaultRequest(kind, init?.headers)) {
54406
- const candidates = accountManager.getEnabledAccounts().filter(
54407
- (row) => !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
54510
+ const candidates = accountManager.getAccounts().filter(
54511
+ (row) => row.enabled !== false && !row.accountIneligible && !row.verificationRequired && !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
54408
54512
  row,
54409
54513
  family,
54410
54514
  config.soft_quota_threshold_percent,
54411
54515
  softQuotaCacheTtlMs,
54412
- model
54516
+ model,
54517
+ excludedIndexes
54413
54518
  )
54414
54519
  ).map((row) => ({
54415
54520
  ...credentials.routingCandidate(row),
@@ -54455,10 +54560,11 @@ function createRequestExecutor(deps) {
54455
54560
  const blockedSince = allAccountsBlockedAt;
54456
54561
  const remainingWaitMs = () => maxWaitMs > 0 ? Math.max(0, maxWaitMs - (Date.now() - blockedSince)) : Number.POSITIVE_INFINITY;
54457
54562
  const quotaWins = remainingWaitMs() <= deadline.remainingMs();
54563
+ const eligibleCandidates = accountManager.getAccounts().filter(
54564
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
54565
+ );
54458
54566
  const eligibleCandidateIndexes = new Set(
54459
- accountManager.getAccounts().filter(
54460
- (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
54461
- ).map((entry) => entry.index)
54567
+ eligibleCandidates.map((entry) => entry.index)
54462
54568
  );
54463
54569
  if (eligibleCandidateIndexes.size === 0) {
54464
54570
  waitPolicy.refusal = () => createNativeGoogleErrorResponse({
@@ -54467,28 +54573,55 @@ function createRequestExecutor(deps) {
54467
54573
  });
54468
54574
  return waitPolicy.refusal();
54469
54575
  }
54470
- if (accountManager.areAllAccountsOverSoftQuota(
54576
+ const threshold = config.soft_quota_threshold_percent;
54577
+ const combinedDelayMs = accountManager.getMinSelectableWaitTimeForFamily(
54471
54578
  family,
54472
- config.soft_quota_threshold_percent,
54579
+ threshold,
54473
54580
  softQuotaCacheTtlMs,
54474
54581
  model,
54475
54582
  eligibleCandidateIndexes
54476
- )) {
54477
- const threshold = config.soft_quota_threshold_percent;
54478
- const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(
54583
+ );
54584
+ const waitMs = combinedDelayMs !== null && combinedDelayMs > 0 ? combinedDelayMs : 6e4;
54585
+ const allOverSoftQuota = accountManager.areAllAccountsOverSoftQuota(
54586
+ family,
54587
+ threshold,
54588
+ softQuotaCacheTtlMs,
54589
+ model,
54590
+ eligibleCandidateIndexes
54591
+ );
54592
+ const hasActiveCooldown = eligibleCandidates.some(
54593
+ (acc) => accountManager.isAccountCoolingDown(acc)
54594
+ );
54595
+ const applySoftQuota = eligibleCandidates.length > 1 && threshold < 100;
54596
+ const hasUnknownSoftReset = applySoftQuota && eligibleCandidates.some((acc) => {
54597
+ if (!accountManager.isAccountOverSoftQuota(
54598
+ acc,
54479
54599
  family,
54480
54600
  threshold,
54481
54601
  softQuotaCacheTtlMs,
54482
54602
  model,
54483
- eligibleCandidateIndexes
54484
- );
54603
+ excludedIndexes
54604
+ )) {
54605
+ return false;
54606
+ }
54607
+ if (!model && family !== "claude") return true;
54608
+ const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
54609
+ const groupData = acc.cachedQuota?.[quotaGroup];
54610
+ if (!groupData?.resetTime) return true;
54611
+ const ts = Date.parse(groupData.resetTime);
54612
+ return !Number.isFinite(ts) || ts <= Date.now();
54613
+ });
54614
+ const resetDeadline = !hasActiveCooldown && !hasUnknownSoftReset && combinedDelayMs !== null && combinedDelayMs > 0 ? Date.now() + combinedDelayMs : void 0;
54615
+ const remainingResetAfterMs = () => resetDeadline ? Math.max(0, resetDeadline - Date.now()) : void 0;
54616
+ if (allOverSoftQuota) {
54485
54617
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54486
54618
  status: 412,
54487
54619
  reason: "soft_quota",
54488
- resetAfterMs: softQuotaWaitMs
54620
+ resetAfterMs: remainingResetAfterMs()
54489
54621
  }) : void 0;
54490
- if (softQuotaWaitMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs) {
54491
- const waitTimeFormatted = softQuotaWaitMs ? formatWaitTime(softQuotaWaitMs) : "unknown";
54622
+ if (combinedDelayMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && waitMs > maxWaitMs) {
54623
+ const resetAfterMs = remainingResetAfterMs();
54624
+ const waitTimeFormatted = resetAfterMs !== void 0 && resetAfterMs > 0 ? formatWaitTime(resetAfterMs) : "unknown";
54492
54625
  await showToast(
54493
54626
  `All accounts over ${threshold}% quota threshold. Resets in ${waitTimeFormatted}.`,
54494
54627
  "error"
@@ -54496,33 +54629,26 @@ function createRequestExecutor(deps) {
54496
54629
  return createNativeGoogleErrorResponse({
54497
54630
  status: 412,
54498
54631
  reason: "soft_quota",
54499
- resetAfterMs: softQuotaWaitMs
54632
+ resetAfterMs: remainingResetAfterMs()
54500
54633
  });
54501
54634
  }
54502
54635
  pushDebug(
54503
- `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${softQuotaWaitMs}`
54636
+ `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${waitMs}`
54504
54637
  );
54505
54638
  if (!retryState.softQuotaToastShown()) {
54506
54639
  await showToast(
54507
- `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`,
54640
+ `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(waitMs)}...`,
54508
54641
  "warning"
54509
54642
  );
54510
54643
  retryState.markSoftQuotaToastShown();
54511
54644
  }
54512
- await sleep4(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
54645
+ await sleep4(Math.min(waitMs, remainingWaitMs()), abortSignal);
54513
54646
  continue;
54514
54647
  }
54515
- const minWaitMs = accountManager.getMinWaitTimeForFamily(
54516
- family,
54517
- model,
54518
- eligibleCandidateIndexes,
54519
- true
54520
- );
54521
- const waitMs = minWaitMs || 6e4;
54522
54648
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54523
54649
  status: 412,
54524
54650
  reason: "pool_unavailable",
54525
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
54651
+ resetAfterMs: remainingResetAfterMs()
54526
54652
  }) : void 0;
54527
54653
  pushDebug(
54528
54654
  `all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`
@@ -54547,9 +54673,8 @@ function createRequestExecutor(deps) {
54547
54673
  return createNativeGoogleErrorResponse({
54548
54674
  status: 412,
54549
54675
  reason: "pool_unavailable",
54550
- // Zero means the account manager has no future reset to report.
54551
- // The fallback sleep duration above is not a quota reset estimate.
54552
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
54676
+ // Fallback sleep duration gets NO reset metadata.
54677
+ resetAfterMs: remainingResetAfterMs()
54553
54678
  });
54554
54679
  }
54555
54680
  if (!retryState.rateLimitToastShown()) {