@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",
@@ -5952,7 +5952,7 @@
5952
5952
  "format": "esm"
5953
5953
  },
5954
5954
  "src/plugin/shared/request-services.ts": {
5955
- "bytes": 122841,
5955
+ "bytes": 124754,
5956
5956
  "imports": [
5957
5957
  {
5958
5958
  "path": "../core/dist/index.js",
@@ -6487,7 +6487,7 @@
6487
6487
  "imports": [],
6488
6488
  "exports": [],
6489
6489
  "inputs": {},
6490
- "bytes": 4728397
6490
+ "bytes": 4739474
6491
6491
  },
6492
6492
  "dist/index.js": {
6493
6493
  "imports": [
@@ -7679,7 +7679,7 @@
7679
7679
  "bytesInOutput": 10845
7680
7680
  },
7681
7681
  "../core/dist/account-migration.js": {
7682
- "bytesInOutput": 148482
7682
+ "bytesInOutput": 150336
7683
7683
  },
7684
7684
  "../core/dist/account-repository.js": {
7685
7685
  "bytesInOutput": 78810
@@ -7694,7 +7694,7 @@
7694
7694
  "bytesInOutput": 11075
7695
7695
  },
7696
7696
  "../core/dist/account-selector.js": {
7697
- "bytesInOutput": 50935
7697
+ "bytesInOutput": 53453
7698
7698
  },
7699
7699
  "../core/dist/atomic-write.js": {
7700
7700
  "bytesInOutput": 905
@@ -7715,7 +7715,7 @@
7715
7715
  "bytesInOutput": 1325
7716
7716
  },
7717
7717
  "../core/dist/account-manager.js": {
7718
- "bytesInOutput": 61547
7718
+ "bytesInOutput": 61818
7719
7719
  },
7720
7720
  "../core/dist/account-types.js": {
7721
7721
  "bytesInOutput": 97
@@ -8075,7 +8075,7 @@
8075
8075
  "bytesInOutput": 46529
8076
8076
  },
8077
8077
  "src/plugin/storage.ts": {
8078
- "bytesInOutput": 12150
8078
+ "bytesInOutput": 12217
8079
8079
  },
8080
8080
  "src/runtime-paths.ts": {
8081
8081
  "bytesInOutput": 6383
@@ -8426,7 +8426,7 @@
8426
8426
  "bytesInOutput": 7610
8427
8427
  },
8428
8428
  "src/plugin/shared/request-services.ts": {
8429
- "bytesInOutput": 83260
8429
+ "bytesInOutput": 84545
8430
8430
  },
8431
8431
  "src/common-auth-embedded/routing-accessor/index.js": {
8432
8432
  "bytesInOutput": 3335
@@ -8480,7 +8480,7 @@
8480
8480
  "bytesInOutput": 0
8481
8481
  }
8482
8482
  },
8483
- "bytes": 2139634
8483
+ "bytes": 2145629
8484
8484
  }
8485
8485
  }
8486
8486
  }
package/dist/server.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
  });
@@ -32694,6 +32796,8 @@ async function assertLegacyPoolInUse(legacyPath) {
32694
32796
  }
32695
32797
  function refusalMessage2(admission) {
32696
32798
  switch (admission.status) {
32799
+ case "busy":
32800
+ return new AccountStoreBusyError().message;
32697
32801
  case "pending":
32698
32802
  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}\`.`;
32699
32803
  case "inactive":
@@ -45265,8 +45369,8 @@ function createRequestExecutor(deps) {
45265
45369
  accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
45266
45370
  );
45267
45371
  if (modelUnavailableIndexes.size > 0) {
45268
- const candidates = accountManager.getEnabledAccounts().filter(
45269
- (entry) => eligibleIndexes === null || eligibleIndexes.has(entry.index)
45372
+ const candidates = accountManager.getAccounts().filter(
45373
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && (eligibleIndexes === null || eligibleIndexes.has(entry.index))
45270
45374
  );
45271
45375
  if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
45272
45376
  pushDebug(
@@ -45302,13 +45406,14 @@ function createRequestExecutor(deps) {
45302
45406
  if (account) {
45303
45407
  routingPlacementConsidered = true;
45304
45408
  if (firstPlacement && credentials.domain === "vault" && credentials.routingCandidate && model && isPrimaryVaultRequest(kind, init?.headers)) {
45305
- const candidates = accountManager.getEnabledAccounts().filter(
45306
- (row) => !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
45409
+ const candidates = accountManager.getAccounts().filter(
45410
+ (row) => row.enabled !== false && !row.accountIneligible && !row.verificationRequired && !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
45307
45411
  row,
45308
45412
  family,
45309
45413
  config.soft_quota_threshold_percent,
45310
45414
  softQuotaCacheTtlMs,
45311
- model
45415
+ model,
45416
+ excludedIndexes
45312
45417
  )
45313
45418
  ).map((row) => ({
45314
45419
  ...credentials.routingCandidate(row),
@@ -45354,10 +45459,11 @@ function createRequestExecutor(deps) {
45354
45459
  const blockedSince = allAccountsBlockedAt;
45355
45460
  const remainingWaitMs = () => maxWaitMs > 0 ? Math.max(0, maxWaitMs - (Date.now() - blockedSince)) : Number.POSITIVE_INFINITY;
45356
45461
  const quotaWins = remainingWaitMs() <= deadline.remainingMs();
45462
+ const eligibleCandidates = accountManager.getAccounts().filter(
45463
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
45464
+ );
45357
45465
  const eligibleCandidateIndexes = new Set(
45358
- accountManager.getAccounts().filter(
45359
- (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
45360
- ).map((entry) => entry.index)
45466
+ eligibleCandidates.map((entry) => entry.index)
45361
45467
  );
45362
45468
  if (eligibleCandidateIndexes.size === 0) {
45363
45469
  waitPolicy.refusal = () => createNativeGoogleErrorResponse({
@@ -45366,28 +45472,55 @@ function createRequestExecutor(deps) {
45366
45472
  });
45367
45473
  return waitPolicy.refusal();
45368
45474
  }
45369
- if (accountManager.areAllAccountsOverSoftQuota(
45475
+ const threshold = config.soft_quota_threshold_percent;
45476
+ const combinedDelayMs = accountManager.getMinSelectableWaitTimeForFamily(
45370
45477
  family,
45371
- config.soft_quota_threshold_percent,
45478
+ threshold,
45372
45479
  softQuotaCacheTtlMs,
45373
45480
  model,
45374
45481
  eligibleCandidateIndexes
45375
- )) {
45376
- const threshold = config.soft_quota_threshold_percent;
45377
- const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(
45482
+ );
45483
+ const waitMs = combinedDelayMs !== null && combinedDelayMs > 0 ? combinedDelayMs : 6e4;
45484
+ const allOverSoftQuota = accountManager.areAllAccountsOverSoftQuota(
45485
+ family,
45486
+ threshold,
45487
+ softQuotaCacheTtlMs,
45488
+ model,
45489
+ eligibleCandidateIndexes
45490
+ );
45491
+ const hasActiveCooldown = eligibleCandidates.some(
45492
+ (acc) => accountManager.isAccountCoolingDown(acc)
45493
+ );
45494
+ const applySoftQuota = eligibleCandidates.length > 1 && threshold < 100;
45495
+ const hasUnknownSoftReset = applySoftQuota && eligibleCandidates.some((acc) => {
45496
+ if (!accountManager.isAccountOverSoftQuota(
45497
+ acc,
45378
45498
  family,
45379
45499
  threshold,
45380
45500
  softQuotaCacheTtlMs,
45381
45501
  model,
45382
- eligibleCandidateIndexes
45383
- );
45502
+ excludedIndexes
45503
+ )) {
45504
+ return false;
45505
+ }
45506
+ if (!model && family !== "claude") return true;
45507
+ const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
45508
+ const groupData = acc.cachedQuota?.[quotaGroup];
45509
+ if (!groupData?.resetTime) return true;
45510
+ const ts = Date.parse(groupData.resetTime);
45511
+ return !Number.isFinite(ts) || ts <= Date.now();
45512
+ });
45513
+ const resetDeadline = !hasActiveCooldown && !hasUnknownSoftReset && combinedDelayMs !== null && combinedDelayMs > 0 ? Date.now() + combinedDelayMs : void 0;
45514
+ const remainingResetAfterMs = () => resetDeadline ? Math.max(0, resetDeadline - Date.now()) : void 0;
45515
+ if (allOverSoftQuota) {
45384
45516
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
45385
45517
  status: 412,
45386
45518
  reason: "soft_quota",
45387
- resetAfterMs: softQuotaWaitMs
45519
+ resetAfterMs: remainingResetAfterMs()
45388
45520
  }) : void 0;
45389
- if (softQuotaWaitMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs) {
45390
- const waitTimeFormatted = softQuotaWaitMs ? formatWaitTime(softQuotaWaitMs) : "unknown";
45521
+ if (combinedDelayMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && waitMs > maxWaitMs) {
45522
+ const resetAfterMs = remainingResetAfterMs();
45523
+ const waitTimeFormatted = resetAfterMs !== void 0 && resetAfterMs > 0 ? formatWaitTime(resetAfterMs) : "unknown";
45391
45524
  await showToast(
45392
45525
  `All accounts over ${threshold}% quota threshold. Resets in ${waitTimeFormatted}.`,
45393
45526
  "error"
@@ -45395,33 +45528,26 @@ function createRequestExecutor(deps) {
45395
45528
  return createNativeGoogleErrorResponse({
45396
45529
  status: 412,
45397
45530
  reason: "soft_quota",
45398
- resetAfterMs: softQuotaWaitMs
45531
+ resetAfterMs: remainingResetAfterMs()
45399
45532
  });
45400
45533
  }
45401
45534
  pushDebug(
45402
- `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${softQuotaWaitMs}`
45535
+ `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${waitMs}`
45403
45536
  );
45404
45537
  if (!retryState.softQuotaToastShown()) {
45405
45538
  await showToast(
45406
- `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`,
45539
+ `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(waitMs)}...`,
45407
45540
  "warning"
45408
45541
  );
45409
45542
  retryState.markSoftQuotaToastShown();
45410
45543
  }
45411
- await sleep4(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
45544
+ await sleep4(Math.min(waitMs, remainingWaitMs()), abortSignal);
45412
45545
  continue;
45413
45546
  }
45414
- const minWaitMs = accountManager.getMinWaitTimeForFamily(
45415
- family,
45416
- model,
45417
- eligibleCandidateIndexes,
45418
- true
45419
- );
45420
- const waitMs = minWaitMs || 6e4;
45421
45547
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
45422
45548
  status: 412,
45423
45549
  reason: "pool_unavailable",
45424
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
45550
+ resetAfterMs: remainingResetAfterMs()
45425
45551
  }) : void 0;
45426
45552
  pushDebug(
45427
45553
  `all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`
@@ -45446,9 +45572,8 @@ function createRequestExecutor(deps) {
45446
45572
  return createNativeGoogleErrorResponse({
45447
45573
  status: 412,
45448
45574
  reason: "pool_unavailable",
45449
- // Zero means the account manager has no future reset to report.
45450
- // The fallback sleep duration above is not a quota reset estimate.
45451
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
45575
+ // Fallback sleep duration gets NO reset metadata.
45576
+ resetAfterMs: remainingResetAfterMs()
45452
45577
  });
45453
45578
  }
45454
45579
  if (!retryState.rateLimitToastShown()) {
@@ -48259,6 +48384,7 @@ function tokenExchange(overrides) {
48259
48384
  };
48260
48385
  }
48261
48386
  function storeRefusal(status) {
48387
+ if (status.status === "busy") return new AccountStoreBusyError();
48262
48388
  return new Error(
48263
48389
  status.status === "initialization-required" ? "The Antigravity account store is not initialized; initialize it with the antigravity-auth CLI." : status.status === "error" ? `The Antigravity account store cannot be opened: ${status.reason}` : `The Antigravity account store is ${status.status}; finish its migration or rollback with \`antigravity-auth migrate --offline\` or \`antigravity-auth rollback --offline\`.`
48264
48390
  );
@@ -50956,20 +51082,32 @@ function createGaPoolLogin(input2) {
50956
51082
  method,
50957
51083
  connectExisting: () => track(
50958
51084
  (async () => {
51085
+ let stage = "initial-admission";
50959
51086
  try {
50960
51087
  await admit2();
50961
51088
  if (!input2.local?.assertExistingPool) throw new Error(LOGIN_FAILED);
51089
+ stage = "existing-pool-admission";
50962
51090
  await abortable(
50963
51091
  track(input2.local.assertExistingPool(admit2)),
50964
51092
  shutdown.signal
50965
51093
  );
51094
+ stage = "final-admission";
50966
51095
  await admit2();
51096
+ stage = "placeholder";
50967
51097
  return placeholderCredential({
50968
51098
  integrationID: ANTIGRAVITY_PROVIDER_ID,
50969
51099
  methodID: GA_POOL_RECONNECT_METHOD_ID,
50970
51100
  now: Date.now()
50971
51101
  });
50972
- } catch {
51102
+ } catch (error) {
51103
+ const busy = error instanceof AccountStoreBusyError;
51104
+ try {
51105
+ console.warn(
51106
+ `[antigravity.pool-login] stage=${stage} reason=${busy ? "store-busy" : "store-refusal"}`
51107
+ );
51108
+ } catch {
51109
+ }
51110
+ if (busy) throw new AccountStoreBusyError();
50973
51111
  throw new Error(LOGIN_FAILED);
50974
51112
  }
50975
51113
  })()
@@ -50980,7 +51118,9 @@ function createGaPoolLogin(input2) {
50980
51118
  await admit2();
50981
51119
  await input2.local.persist(result, admit2);
50982
51120
  await admit2();
50983
- } catch {
51121
+ } catch (error) {
51122
+ if (error instanceof AccountStoreBusyError)
51123
+ throw new AccountStoreBusyError();
50984
51124
  throw new Error(LOGIN_FAILED);
50985
51125
  }
50986
51126
  })()