@cortexkit/opencode-antigravity-auth 3.1.10 → 3.1.12

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.
Files changed (172) hide show
  1. package/dist/cli.js +357 -58
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +42 -32
  4. package/dist/index.js +1115 -493
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +98 -65
  7. package/dist/server.js +1266 -616
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/cli.d.ts +3 -1
  11. package/dist/src/cli.d.ts.map +1 -1
  12. package/dist/src/cli.js +19 -6
  13. package/dist/src/cli.js.map +1 -1
  14. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  15. package/dist/src/common-auth-embedded/claustrum/consumer.js +32 -0
  16. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
  17. package/dist/src/common-auth-embedded/claustrum/custody.js +145 -8
  18. package/dist/src/common-auth-embedded/claustrum/host.js +8 -0
  19. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  20. package/dist/src/common-auth-embedded/claustrum/hub.js +10 -0
  21. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  22. package/dist/src/common-auth-embedded/routing-accessor/index.js +5 -3
  23. package/dist/src/common-auth-embedded/source-output.json +35 -35
  24. package/dist/src/ga/rpc/protocol.d.ts +11 -5
  25. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  26. package/dist/src/ga/rpc/protocol.js +11 -3
  27. package/dist/src/ga/rpc/protocol.js.map +1 -1
  28. package/dist/src/ga/server/index.d.ts.map +1 -1
  29. package/dist/src/ga/server/index.js +30 -14
  30. package/dist/src/ga/server/index.js.map +1 -1
  31. package/dist/src/ga/tui/host-ga.d.ts +2 -1
  32. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  33. package/dist/src/ga/tui/host-ga.js +9 -4
  34. package/dist/src/ga/tui/host-ga.js.map +1 -1
  35. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  36. package/dist/src/plugin/account-access.d.ts +1 -0
  37. package/dist/src/plugin/account-access.d.ts.map +1 -1
  38. package/dist/src/plugin/account-access.js +28 -0
  39. package/dist/src/plugin/account-access.js.map +1 -1
  40. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  41. package/dist/src/plugin/auth-loader.js +21 -12
  42. package/dist/src/plugin/auth-loader.js.map +1 -1
  43. package/dist/src/plugin/background-quota-refresh.d.ts +11 -24
  44. package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
  45. package/dist/src/plugin/background-quota-refresh.js +54 -60
  46. package/dist/src/plugin/background-quota-refresh.js.map +1 -1
  47. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  48. package/dist/src/plugin/background-vault-quota-refresh.js +6 -3
  49. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  50. package/dist/src/plugin/cache/signature-cache.d.ts +3 -0
  51. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
  52. package/dist/src/plugin/cache/signature-cache.js +73 -46
  53. package/dist/src/plugin/cache/signature-cache.js.map +1 -1
  54. package/dist/src/plugin/cache.d.ts.map +1 -1
  55. package/dist/src/plugin/cache.js +17 -7
  56. package/dist/src/plugin/cache.js.map +1 -1
  57. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  58. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  59. package/dist/src/plugin/core/streaming/displayed-thinking.js +58 -0
  60. package/dist/src/plugin/core/streaming/displayed-thinking.js.map +1 -0
  61. package/dist/src/plugin/fetch/warmup.d.ts +9 -2
  62. package/dist/src/plugin/fetch/warmup.d.ts.map +1 -1
  63. package/dist/src/plugin/fetch/warmup.js +22 -14
  64. package/dist/src/plugin/fetch/warmup.js.map +1 -1
  65. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  66. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  67. package/dist/src/plugin/ga-location-services.js +2 -0
  68. package/dist/src/plugin/ga-location-services.js.map +1 -1
  69. package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
  70. package/dist/src/plugin/ga-shared-vault-custody.js +7 -1
  71. package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -1
  72. package/dist/src/plugin/index.d.ts.map +1 -1
  73. package/dist/src/plugin/index.js +6 -1
  74. package/dist/src/plugin/index.js.map +1 -1
  75. package/dist/src/plugin/quota.d.ts +10 -2
  76. package/dist/src/plugin/quota.d.ts.map +1 -1
  77. package/dist/src/plugin/quota.js +38 -10
  78. package/dist/src/plugin/quota.js.map +1 -1
  79. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  80. package/dist/src/plugin/request-helpers.js +51 -19
  81. package/dist/src/plugin/request-helpers.js.map +1 -1
  82. package/dist/src/plugin/request.d.ts +12 -1
  83. package/dist/src/plugin/request.d.ts.map +1 -1
  84. package/dist/src/plugin/request.js +27 -42
  85. package/dist/src/plugin/request.js.map +1 -1
  86. package/dist/src/plugin/shared/request-services.d.ts +4 -1
  87. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  88. package/dist/src/plugin/shared/request-services.js +142 -24
  89. package/dist/src/plugin/shared/request-services.js.map +1 -1
  90. package/dist/src/plugin/shared/runtime.d.ts +3 -4
  91. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  92. package/dist/src/plugin/shared/runtime.js +2 -2
  93. package/dist/src/plugin/shared/runtime.js.map +1 -1
  94. package/dist/src/plugin/shared/vault-request-credentials.d.ts +25 -15
  95. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  96. package/dist/src/plugin/shared/vault-request-credentials.js +141 -68
  97. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  98. package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  99. package/dist/src/setup.d.ts +3 -0
  100. package/dist/src/setup.d.ts.map +1 -1
  101. package/dist/src/setup.js +18 -6
  102. package/dist/src/setup.js.map +1 -1
  103. package/dist/src/sidebar-state.d.ts +20 -7
  104. package/dist/src/sidebar-state.d.ts.map +1 -1
  105. package/dist/src/sidebar-state.js +57 -8
  106. package/dist/src/sidebar-state.js.map +1 -1
  107. package/dist/src/tui.d.ts.map +1 -1
  108. package/dist/src/tui.js +43 -23
  109. package/dist/src/tui.js.map +1 -1
  110. package/dist/tui-build-map.json +9 -9
  111. package/dist/tui-ga-build-map.json +5 -5
  112. package/dist/types/src/cli.d.ts +3 -1
  113. package/dist/types/src/cli.d.ts.map +1 -1
  114. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  115. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
  116. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  117. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  118. package/dist/types/src/ga/rpc/protocol.d.ts +11 -5
  119. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  120. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  121. package/dist/types/src/plugin/account-access.d.ts +1 -0
  122. package/dist/types/src/plugin/account-access.d.ts.map +1 -1
  123. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  124. package/dist/types/src/plugin/background-quota-refresh.d.ts +11 -24
  125. package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -1
  126. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  127. package/dist/types/src/plugin/cache/signature-cache.d.ts +3 -0
  128. package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
  129. package/dist/types/src/plugin/cache.d.ts.map +1 -1
  130. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  131. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  132. package/dist/types/src/plugin/fetch/warmup.d.ts +9 -2
  133. package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -1
  134. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  135. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  136. package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
  137. package/dist/types/src/plugin/index.d.ts.map +1 -1
  138. package/dist/types/src/plugin/quota.d.ts +10 -2
  139. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  140. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  141. package/dist/types/src/plugin/request.d.ts +12 -1
  142. package/dist/types/src/plugin/request.d.ts.map +1 -1
  143. package/dist/types/src/plugin/shared/request-services.d.ts +4 -1
  144. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  145. package/dist/types/src/plugin/shared/runtime.d.ts +3 -4
  146. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  147. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +25 -15
  148. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  149. package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  150. package/dist/types/src/setup.d.ts +3 -0
  151. package/dist/types/src/setup.d.ts.map +1 -1
  152. package/dist/types/src/sidebar-state.d.ts +20 -7
  153. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  154. package/package.json +3 -3
  155. package/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  156. package/src/common-auth-embedded/claustrum/consumer.js +32 -0
  157. package/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
  158. package/src/common-auth-embedded/claustrum/custody.js +145 -8
  159. package/src/common-auth-embedded/claustrum/host.js +8 -0
  160. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  161. package/src/common-auth-embedded/claustrum/hub.js +10 -0
  162. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  163. package/src/common-auth-embedded/routing-accessor/index.js +5 -3
  164. package/src/common-auth-embedded/source-output.json +35 -35
  165. package/src/sidebar-state.ts +77 -8
  166. package/src/tui-compiled/sidebar-state.js +40 -1
  167. package/src/tui-compiled/tui.js +49 -24
  168. package/src/tui-ga-compiled/host-ga.js +11 -5
  169. package/src/tui-ga-raw/host-ga.tsx +17 -6
  170. package/src/tui-raw/sidebar-state.js +40 -1
  171. package/src/tui-raw/tui.tsx +40 -24
  172. package/src/tui.tsx +40 -24
@@ -41,11 +41,12 @@ import { isTitleVaultRequest } from './vault-routing-purpose';
41
41
  const FIRST_RETRY_DELAY_MS = 1000;
42
42
  // Re-probe within an hour even when no quota refresh has revealed a new allowance.
43
43
  const MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1000;
44
- // Routing is asked once, when a session is first placed, and its answer holds
45
- // for the whole session, so a slow answer that misses the deadline is costly
44
+ // Routing is normally asked when a session is first placed, and its answer
45
+ // holds for the whole session. A slow answer that misses the deadline is costly
46
46
  // while the wait itself is rare. Use the routing accessor's 2 s ceiling, well
47
47
  // above routing's normal admission time.
48
48
  const ROUTING_ASK_DEADLINE_MS = 2000;
49
+ const FIRST_PLACEMENT_REFUSAL_MAX_RETRY_SECS = 5;
49
50
  const REFUSAL_BODY_TIMEOUT_MS = 2_000;
50
51
  const REFUSAL_BODY_MAX_BYTES = 64 * 1024;
51
52
  // Replay only a complete body so response processing and debug logging never
@@ -336,15 +337,17 @@ export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
336
337
  });
337
338
  if (signal?.aborted)
338
339
  return;
339
- if (result.status === 'ok' && result.quota?.groups) {
340
+ if (result.status === 'ok' &&
341
+ result.quota?.groups &&
342
+ result.checkedAt !== undefined) {
340
343
  // Re-resolve the selected row itself. If it was removed meanwhile,
341
344
  // drop the reading rather than writing onto whichever row shifted
342
345
  // into its slot.
343
346
  const currentIndex = accountManager.getAccounts().indexOf(account);
344
347
  if (currentIndex === -1)
345
348
  return;
346
- accountManager.updateQuotaCache(currentIndex, result.quota.groups, expectedRefreshToken);
347
- accountManager.requestSaveToDisk();
349
+ if (accountManager.updateQuotaCache(currentIndex, result.quota.groups, expectedRefreshToken, result.checkedAt))
350
+ accountManager.requestSaveToDisk();
348
351
  }
349
352
  }
350
353
  catch (err) {
@@ -492,6 +495,25 @@ export function createRequestExecutor(deps) {
492
495
  let retired = false;
493
496
  let drainPromise;
494
497
  let disposePromise;
498
+ let warnedConditionReceipt = false;
499
+ const runVaultCondition = (operation) => {
500
+ void Promise.resolve()
501
+ .then(operation)
502
+ .catch((error) => {
503
+ if (warnedConditionReceipt ||
504
+ !(error instanceof Error) ||
505
+ !('kind' in error) ||
506
+ error.kind !== 'no-receipt')
507
+ return;
508
+ warnedConditionReceipt = true;
509
+ try {
510
+ log.warn('vault-condition-no-receipt');
511
+ }
512
+ catch {
513
+ // Diagnostics cannot fail a published reply.
514
+ }
515
+ });
516
+ };
495
517
  /** Reports a 401 served to an auxiliary send against its admission. */
496
518
  const reportVault401 = (admission, status) => {
497
519
  if (!admission || status !== 401)
@@ -633,6 +655,9 @@ export function createRequestExecutor(deps) {
633
655
  : undefined;
634
656
  const isChildRequest = requestSessionIdentity.parentSessionId !== null;
635
657
  let physicalSendCount = 0;
658
+ // Empty-response retries are budgeted per logical request: a success or
659
+ // an exhausted budget in another request must not refill this one.
660
+ let emptyResponseAttempts = 0;
636
661
  if (accountManager.getAccountCount() === 0) {
637
662
  // Surface a real 401 with the Google error envelope instead of a
638
663
  // 200 SSE body — OpenCode's HTTP layer treats 200 as success and
@@ -726,6 +751,11 @@ export function createRequestExecutor(deps) {
726
751
  }
727
752
  };
728
753
  let accountSwitchCount = 0;
754
+ // Google's capacity and server-busy errors describe the model, not the
755
+ // account, so another account rarely helps and each switch repeats the
756
+ // full endpoint retries. One switch is allowed per request; a second
757
+ // exhaustion ends the request.
758
+ let capacityExhaustedSelections = 0;
729
759
  let unconfirmedRetries = 0;
730
760
  const maxAccountSwitches = config.max_account_switches ?? 2;
731
761
  let previousAccountIndex = -1;
@@ -739,6 +769,7 @@ export function createRequestExecutor(deps) {
739
769
  let routingPlacementConsidered = false;
740
770
  let routedCandidate;
741
771
  let continueRouting;
772
+ let continueOnlyLogin = false;
742
773
  const refusedRoutes = new Map();
743
774
  let routingTitle = false;
744
775
  let routingWaitMs = 0;
@@ -794,11 +825,13 @@ export function createRequestExecutor(deps) {
794
825
  const choice = routedCandidate;
795
826
  routedCandidate = undefined;
796
827
  const exhausted = continueRouting;
828
+ const onlyLoginContinuation = continueOnlyLogin;
797
829
  continueRouting = undefined;
830
+ continueOnlyLogin = false;
798
831
  if (exhausted)
799
832
  refusedRoutes.set(routingIdentityKey(exhausted), exhausted);
800
833
  const accountCount = accountManager.getAccountCount();
801
- if (accountCount === 0) {
834
+ if (accountCount === 0 && !onlyLoginContinuation) {
802
835
  if (choice)
803
836
  return failedRoutedPick();
804
837
  // Mirror the no-account short-circuit inside the retry loop so callers
@@ -1018,7 +1051,7 @@ export function createRequestExecutor(deps) {
1018
1051
  routingPlacementConsidered = true;
1019
1052
  const canHold = !!holdCandidate &&
1020
1053
  candidates.some((candidate) => routingIdentityKey(candidate) === holdCandidate);
1021
- const answer = await deadline.wait(() => {
1054
+ const ask = () => deadline.wait(() => {
1022
1055
  const input = {
1023
1056
  sessionId: accountSessionIdentity.id,
1024
1057
  provider: 'antigravity',
@@ -1039,9 +1072,25 @@ export function createRequestExecutor(deps) {
1039
1072
  }
1040
1073
  : input);
1041
1074
  });
1075
+ let answer = await ask();
1076
+ const firstRefusal = !exhausted && answer && 'refused' in answer
1077
+ ? answer.refused
1078
+ : undefined;
1079
+ if (firstRefusal?.code === 'account_selection_refused' &&
1080
+ firstRefusal.retryAfterSecs !== undefined &&
1081
+ firstRefusal.retryAfterSecs <=
1082
+ FIRST_PLACEMENT_REFUSAL_MAX_RETRY_SECS) {
1083
+ // Wait without sending, then give routing one more chance to place
1084
+ // the session. A second refusal is final.
1085
+ await routingSleep(firstRefusal.retryAfterSecs * 1000, 'account_free');
1086
+ checkAborted();
1087
+ answer = await ask();
1088
+ }
1042
1089
  checkAborted();
1043
1090
  if (answer && 'refused' in answer)
1044
1091
  return routingRefusalResponse(answer.refused);
1092
+ if (!answer && onlyLoginContinuation && candidates.length === 0)
1093
+ return failedRoutedPick();
1045
1094
  if (exhausted && answer?.hold) {
1046
1095
  if (!canHold ||
1047
1096
  routingIdentityKey(answer.candidate) !== holdCandidate)
@@ -1507,9 +1556,12 @@ export function createRequestExecutor(deps) {
1507
1556
  streaming: true,
1508
1557
  projectId,
1509
1558
  });
1559
+ // Only a warmup that never reached the sender gets its attempt back.
1560
+ let warmupDispatched = false;
1510
1561
  try {
1511
1562
  pushDebug('thinking-warmup: start');
1512
1563
  const warmupSend = await credentialForAuxiliarySend(warmupInit, projectId);
1564
+ warmupDispatched = true;
1513
1565
  const warmupResponse = await sendPhysical(warmupUrl, warmupSend.init, warmupSend.admission, prepared.effectiveModel ?? model ?? 'unknown', 'prime');
1514
1566
  reportVault401(warmupSend.admission, warmupResponse.status);
1515
1567
  const transformed = await deadline.wait(() => wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId));
@@ -1518,7 +1570,8 @@ export function createRequestExecutor(deps) {
1518
1570
  pushDebug('thinking-warmup: done');
1519
1571
  }
1520
1572
  catch (error) {
1521
- warmupState.clearWarmupAttempt(prepared.sessionId);
1573
+ if (!warmupDispatched)
1574
+ warmupState.refundAttempt(prepared.sessionId);
1522
1575
  if (error instanceof PreResponseTimeoutError)
1523
1576
  throw error;
1524
1577
  checkAborted();
@@ -1861,9 +1914,14 @@ export function createRequestExecutor(deps) {
1861
1914
  const routed429 = response.status === 429 ? routedIdentity : undefined;
1862
1915
  if (response.status === 429 && rateLimitReason === 'UNKNOWN') {
1863
1916
  await logResponseBody(debugContext, response, 429);
1864
- // Inspect the actual wire instruction, not conversation or tool text.
1865
- const outgoing = JSON.parse(String(prepared.init.body));
1866
- const recognised = systemInstructionHasHarnessIdentity(outgoing.request?.systemInstruction);
1917
+ // Inspect the actual wire instruction, not conversation or tool
1918
+ // text. Preparation keeps the instruction it serialized; parse
1919
+ // the body only when something replaced it afterwards.
1920
+ const carried = prepared.wireSystemInstruction;
1921
+ const recognised = systemInstructionHasHarnessIdentity(carried && carried.body === prepared.init.body
1922
+ ? carried.instruction
1923
+ : JSON.parse(String(prepared.init.body)).request
1924
+ ?.systemInstruction);
1867
1925
  if (recognised) {
1868
1926
  void response.body?.cancel().catch(() => { });
1869
1927
  return unconfirmedRefusal();
@@ -1985,8 +2043,13 @@ export function createRequestExecutor(deps) {
1985
2043
  i -= 1;
1986
2044
  continue;
1987
2045
  }
1988
- pushDebug(`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted, switching account`);
1989
2046
  retainHttpFailure(response);
2047
+ capacityExhaustedSelections++;
2048
+ if (capacityExhaustedSelections > 1) {
2049
+ pushDebug(`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted again after one account switch, giving up`);
2050
+ return terminalMainAttemptFailure('Antigravity has no capacity for this model right now');
2051
+ }
2052
+ pushDebug(`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted, switching account`);
1990
2053
  shouldSwitchAccount = true;
1991
2054
  break;
1992
2055
  }
@@ -2068,6 +2131,10 @@ export function createRequestExecutor(deps) {
2068
2131
  i -= 1;
2069
2132
  continue;
2070
2133
  }
2134
+ if (routed429 && exhaustion) {
2135
+ const { accountId, credentialId } = routed429;
2136
+ continueRouting = { accountId, credentialId, ...exhaustion };
2137
+ }
2071
2138
  const switchAccountDelayMs = config.switch_account_delay_ms ?? 500;
2072
2139
  if (accountCount > 1) {
2073
2140
  const quotaMsg = reasonInfo.quotaResetTime
@@ -2076,7 +2143,7 @@ export function createRequestExecutor(deps) {
2076
2143
  await showToast(`Rate limited again. Switching account in ${formatWaitTime(switchAccountDelayMs)}...${quotaMsg}`, 'warning');
2077
2144
  await sleep(switchAccountDelayMs, abortSignal);
2078
2145
  }
2079
- else {
2146
+ else if (!continueRouting || isHardEligible(account)) {
2080
2147
  const expBackoffMs = Math.min(FIRST_RETRY_DELAY_MS * 2 ** (backoff.attempt - 1), 60000);
2081
2148
  const expBackoffFormatted = expBackoffMs >= 1000
2082
2149
  ? `${Math.round(expBackoffMs / 1000)}s`
@@ -2085,10 +2152,6 @@ export function createRequestExecutor(deps) {
2085
2152
  await routingSleep(expBackoffMs, 'rate_limited', backoff.attempt);
2086
2153
  }
2087
2154
  retainHttpFailure(response);
2088
- if (routed429 && exhaustion) {
2089
- const { accountId, credentialId } = routed429;
2090
- continueRouting = { accountId, credentialId, ...exhaustion };
2091
- }
2092
2155
  shouldSwitchAccount = true;
2093
2156
  break;
2094
2157
  }
@@ -2153,6 +2216,17 @@ export function createRequestExecutor(deps) {
2153
2216
  const extracted = errorBodyText === undefined
2154
2217
  ? undefined
2155
2218
  : classifyAccessError(errorBodyText);
2219
+ const served = sendAdmission;
2220
+ const reportCondition = (reason) => {
2221
+ if (credentials.domain !== 'vault' || !served?.reportCondition)
2222
+ return;
2223
+ const actionUrl = extracted?.structuredVerifyUrl;
2224
+ waitPolicy.vaultConditions.push(() => served.reportCondition?.({
2225
+ reason,
2226
+ providerStatus: 403,
2227
+ ...(actionUrl && { actionUrl }),
2228
+ }));
2229
+ };
2156
2230
  if (routedIdentity &&
2157
2231
  (extracted?.accountIneligible || extracted?.validationRequired)) {
2158
2232
  // A signed-out observation lets routing move the session without
@@ -2179,6 +2253,7 @@ export function createRequestExecutor(deps) {
2179
2253
  trackers.health.recordFailure(account.index);
2180
2254
  retainHttpFailure(response);
2181
2255
  shouldSwitchAccount = true;
2256
+ reportCondition('provider_ineligible');
2182
2257
  break;
2183
2258
  }
2184
2259
  if (extracted?.validationRequired) {
@@ -2196,6 +2271,7 @@ export function createRequestExecutor(deps) {
2196
2271
  trackers.health.recordFailure(account.index);
2197
2272
  retainHttpFailure(response);
2198
2273
  shouldSwitchAccount = true;
2274
+ reportCondition('provider_verification_required');
2199
2275
  break;
2200
2276
  }
2201
2277
  }
@@ -2260,8 +2336,7 @@ export function createRequestExecutor(deps) {
2260
2336
  throw markUpstreamFailure(error);
2261
2337
  }));
2262
2338
  if (isEmptyResponseBody(bodyText)) {
2263
- const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
2264
- const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
2339
+ const currentAttempts = ++emptyResponseAttempts;
2265
2340
  pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
2266
2341
  if (currentAttempts < maxAttempts) {
2267
2342
  deadline.resume();
@@ -2269,14 +2344,11 @@ export function createRequestExecutor(deps) {
2269
2344
  await sleep(retryDelayMs, abortSignal);
2270
2345
  continue;
2271
2346
  }
2272
- retryState.clearEmptyResponseAttempts();
2273
2347
  return createNativeGoogleErrorResponse({
2274
2348
  status: 502,
2275
2349
  reason: 'empty_response',
2276
2350
  });
2277
2351
  }
2278
- const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
2279
- retryState.clearEmptyResponseAttempts();
2280
2352
  }
2281
2353
  const routingObservation = credentials.domain === 'vault' &&
2282
2354
  sendAdmission &&
@@ -2296,7 +2368,10 @@ export function createRequestExecutor(deps) {
2296
2368
  }
2297
2369
  }
2298
2370
  if (apiRequestCount > 1) {
2299
- pushDebug(`[Quota] Total API requests for this user message: ${apiRequestCount} (${apiRequestCount - 1} retries)`);
2371
+ // Counts only main-request responses received on the current
2372
+ // account selection; warmups, probes, failed sends and earlier
2373
+ // selections are not included.
2374
+ pushDebug(`[Quota] Main-request responses on this account selection: ${apiRequestCount}`);
2300
2375
  }
2301
2376
  const dailyCounts = accountManager.getDailyRequestCounts(account.index);
2302
2377
  if (dailyCounts) {
@@ -2331,6 +2406,12 @@ export function createRequestExecutor(deps) {
2331
2406
  const refresh = credentials.refreshQuotaAfterSuccess;
2332
2407
  waitPolicy.quota = (signal) => refresh(account, config.quota_refresh_interval_minutes, signal);
2333
2408
  }
2409
+ const served = sendAdmission;
2410
+ if (credentials.domain === 'vault' &&
2411
+ response.ok &&
2412
+ transformedResponse.ok &&
2413
+ served?.clearCondition)
2414
+ waitPolicy.vaultConditions.push(() => served.clearCondition?.());
2334
2415
  return routingObservation &&
2335
2416
  credentials.domain === 'vault' &&
2336
2417
  sendAdmission &&
@@ -2353,6 +2434,11 @@ export function createRequestExecutor(deps) {
2353
2434
  trackers.token.refund(account.index);
2354
2435
  tokenConsumed = false;
2355
2436
  }
2437
+ // Successful headers pause the deadline while the response is
2438
+ // read. Every branch below can send again, so a failure while
2439
+ // reading must restore the original expiry first; once it has
2440
+ // passed, this throws the deadline error instead of resending.
2441
+ deadline.resume();
2356
2442
  if (credentials.domain === 'local' &&
2357
2443
  localGrant?.captured.source === 'store' &&
2358
2444
  isLocalGrantError(error)) {
@@ -2443,6 +2529,15 @@ export function createRequestExecutor(deps) {
2443
2529
  // Unconfirmed refusals have their own request-wide retry budget.
2444
2530
  if (switchedForUnconfirmed)
2445
2531
  continue;
2532
+ if (accountCount === 1 &&
2533
+ continueRouting &&
2534
+ (continueRouting.limitWindow === 'signed_out' ||
2535
+ !isHardEligible(account))) {
2536
+ // Tell routing the last login signed out or exhausted its quota even
2537
+ // when the pool counts no usable logins. Asking routing sends nothing to Google.
2538
+ continueOnlyLogin = true;
2539
+ continue;
2540
+ }
2446
2541
  accountSwitchCount++;
2447
2542
  if (accountSwitchCount > maxAccountSwitches) {
2448
2543
  pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
@@ -2502,7 +2597,11 @@ export function createRequestExecutor(deps) {
2502
2597
  const handoff = createAfterHandoff(advisoryWork, requestedSignal
2503
2598
  ? [requestedSignal, shutdown.signal]
2504
2599
  : [shutdown.signal], () => log.debug('post-response-advisory-work-failed'));
2505
- const waitPolicy = {};
2600
+ const waitPolicy = { vaultConditions: [] };
2601
+ const publishVaultConditions = () => {
2602
+ for (const operation of waitPolicy.vaultConditions.splice(0))
2603
+ runVaultCondition(operation);
2604
+ };
2506
2605
  const selectedCredentials = new Set();
2507
2606
  const selectedProjectIds = new Set();
2508
2607
  const redactFailure = (error) => {
@@ -2552,8 +2651,27 @@ export function createRequestExecutor(deps) {
2552
2651
  deadline.dispose();
2553
2652
  cancellation.release();
2554
2653
  throw redactFailure(error);
2654
+ })
2655
+ .then((response) => {
2656
+ if (waitPolicy.vaultConditions.length > 0) {
2657
+ // Use the host's publication point, not the end of any failed
2658
+ // attempt that may have led to a successful reply on another account.
2659
+ if (requestOptions?.onResponseHandoff) {
2660
+ try {
2661
+ requestOptions.onResponseHandoff(publishVaultConditions);
2662
+ return response;
2663
+ }
2664
+ catch {
2665
+ // Even a failed handoff registration cannot change the reply.
2666
+ }
2667
+ }
2668
+ setImmediate(publishVaultConditions);
2669
+ }
2670
+ return response;
2555
2671
  })
2556
2672
  .catch((error) => {
2673
+ if (waitPolicy.vaultConditions.length > 0)
2674
+ setImmediate(publishVaultConditions);
2557
2675
  handoff.cancel();
2558
2676
  deadline.dispose();
2559
2677
  cancellation.release();