@cortexkit/opencode-antigravity-auth 3.0.6 → 3.0.8
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/dist/cli.js +1621 -183
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +228 -62
- package/dist/index.js +2728 -883
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +291 -104
- package/dist/server.js +2255 -390
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +41 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +152 -6
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
- package/dist/src/common-auth-embedded/claustrum/custody.js +311 -16
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/src/common-auth-embedded/claustrum/index.js +4 -1
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/dist/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +10 -2
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
- package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/dist/src/common-auth-embedded/quota/format.d.ts +17 -3
- package/dist/src/common-auth-embedded/quota/format.js +203 -18
- package/dist/src/common-auth-embedded/quota/index.d.ts +2 -2
- package/dist/src/common-auth-embedded/quota/index.js +1 -1
- package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
- package/dist/src/common-auth-embedded/setup/command-runner.js +118 -24
- package/dist/src/common-auth-embedded/setup/command.js +75 -19
- package/dist/src/common-auth-embedded/setup/enroll.js +17 -5
- package/dist/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/dist/src/common-auth-embedded/setup/index.js +1 -0
- package/dist/src/common-auth-embedded/setup/register.js +8 -2
- package/dist/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/dist/src/common-auth-embedded/source-output.json +142 -94
- package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/pool.js +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/dist/src/ga/server/index.d.ts +2 -0
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +18 -3
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +37 -3
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +2 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +5 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +2 -1
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +8 -6
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +7 -3
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/src/plugin/gemini-dump.js +2 -5
- package/dist/src/plugin/gemini-dump.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +3 -3
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/src/plugin/logging-utils.js +2 -5
- package/dist/src/plugin/logging-utils.js.map +1 -1
- package/dist/src/plugin/request.d.ts +1 -2
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +8 -12
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/src/plugin/shared/after-handoff.js +89 -0
- package/dist/src/plugin/shared/after-handoff.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +16 -3
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +193 -90
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +13 -4
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +17 -1
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +16 -1
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +60 -10
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/sidebar-projection.d.ts +4 -0
- package/dist/src/sidebar-projection.d.ts.map +1 -1
- package/dist/src/sidebar-projection.js +6 -2
- package/dist/src/sidebar-projection.js.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +94 -0
- package/dist/src/tui/quota-layout.d.ts.map +1 -0
- package/dist/src/tui/quota-layout.js +139 -0
- package/dist/src/tui/quota-layout.js.map +1 -0
- package/dist/src/tui/route-layout.d.ts +8 -0
- package/dist/src/tui/route-layout.d.ts.map +1 -0
- package/dist/src/tui/route-layout.js +36 -0
- package/dist/src/tui/route-layout.js.map +1 -0
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +105 -191
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +60 -31
- package/dist/tui-ga-build-map.json +46 -17
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +41 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +17 -3
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +2 -2
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/types/src/ga/server/index.d.ts +2 -0
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +2 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts +1 -2
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +16 -3
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +13 -4
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +16 -1
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/src/common-auth-embedded/claustrum/consumer.d.ts +41 -1
- package/src/common-auth-embedded/claustrum/consumer.js +152 -6
- package/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
- package/src/common-auth-embedded/claustrum/custody.js +311 -16
- package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/src/common-auth-embedded/claustrum/index.js +4 -1
- package/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/src/common-auth-embedded/fs/private-files.js +10 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
- package/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/src/common-auth-embedded/quota/format.d.ts +17 -3
- package/src/common-auth-embedded/quota/format.js +203 -18
- package/src/common-auth-embedded/quota/index.d.ts +2 -2
- package/src/common-auth-embedded/quota/index.js +1 -1
- package/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/src/common-auth-embedded/setup/command-error.js +79 -0
- package/src/common-auth-embedded/setup/command-runner.js +118 -24
- package/src/common-auth-embedded/setup/command.js +75 -19
- package/src/common-auth-embedded/setup/enroll.js +17 -5
- package/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/src/common-auth-embedded/setup/index.js +1 -0
- package/src/common-auth-embedded/setup/register.js +8 -2
- package/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/src/common-auth-embedded/source-output.json +142 -94
- package/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/src/common-auth-embedded/store/pool.js +0 -1
- package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-compiled/common-auth-embedded/quota/format.js +203 -18
- package/src/tui-compiled/common-auth-embedded/quota/index.js +1 -1
- package/src/tui-compiled/tui/quota-layout.js +378 -0
- package/src/tui-compiled/tui/route-layout.js +30 -0
- package/src/tui-compiled/tui.js +245 -501
- package/src/tui-ga-compiled/host-ga.js +82 -52
- package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +203 -18
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +1 -1
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
- package/src/tui-ga-raw/host-ga.tsx +71 -30
- package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +203 -18
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +1 -1
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-raw/common-auth-embedded/quota/format.js +203 -18
- package/src/tui-raw/common-auth-embedded/quota/index.js +1 -1
- package/src/tui-raw/tui/quota-layout.tsx +391 -0
- package/src/tui-raw/tui/route-layout.js +30 -0
- package/src/tui-raw/tui.tsx +171 -411
- package/src/tui.tsx +171 -411
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* `RequestWire`, which `createRequestWire` binds to one location's signature
|
|
17
17
|
* cache, debug log and logger; the raw sender is called unchanged.
|
|
18
18
|
*/
|
|
19
|
-
import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getQuotaKey, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, parseRateLimitReason, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
|
|
19
|
+
import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getQuotaKey, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, PRE_RESPONSE_DEADLINE_MS, PreResponseDeadline, PreResponseTimeoutError, parseRateLimitReason, parseRefreshParts, preResponseTimeoutResponse, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
|
|
20
20
|
import { ANTIGRAVITY_ENDPOINT_FALLBACKS } from '../../constants';
|
|
21
21
|
import { AntigravityKillswitchError } from '../errors';
|
|
22
22
|
import { createRetryState, } from '../fetch/retry-state';
|
|
@@ -26,6 +26,7 @@ import { noteGeminiDumpResponse } from '../gemini-dump';
|
|
|
26
26
|
import { evaluateKillswitchForAccount, throwIfAllKilled } from '../killswitch';
|
|
27
27
|
import { createNativeGoogleErrorResponse, createSyntheticTextResponse, isEmptyResponseBody, } from '../request-helpers';
|
|
28
28
|
import { extractOpenCodeSessionIdentity, } from '../session-context';
|
|
29
|
+
import { createAfterHandoff, } from "./after-handoff.js";
|
|
29
30
|
import { isLocalGrantError, LocalGrantSupersededError, } from './local-grant';
|
|
30
31
|
import { createRequestCancellation, retainResponseLifetime, } from './request-cancellation';
|
|
31
32
|
/**
|
|
@@ -270,12 +271,11 @@ export function createRequestExecutor(deps) {
|
|
|
270
271
|
log.debug('routing-report-failed', { sessionId, error: String(error) });
|
|
271
272
|
}
|
|
272
273
|
};
|
|
273
|
-
async function execute(input, init, options
|
|
274
|
+
async function execute(input, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
274
275
|
const assertAdmission = async () => {
|
|
275
|
-
|
|
276
|
-
await deps.assertAdmission?.();
|
|
277
|
-
init?.signal?.throwIfAborted();
|
|
276
|
+
await deadline.wait(() => deps.assertAdmission?.());
|
|
278
277
|
};
|
|
278
|
+
const logResponseBody = (...args) => deadline.wait(() => debug.logResponseBody(...args));
|
|
279
279
|
await assertAdmission();
|
|
280
280
|
// Normalize Request/URL inputs to (urlString, init) so the string-based
|
|
281
281
|
// transform pipeline sees the real method/headers/body. Without this,
|
|
@@ -291,7 +291,7 @@ export function createRequestExecutor(deps) {
|
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
const bodyBuffer = req.body
|
|
294
|
-
? await req.clone().arrayBuffer()
|
|
294
|
+
? await deadline.wait(() => req.clone().arrayBuffer())
|
|
295
295
|
: undefined;
|
|
296
296
|
init = {
|
|
297
297
|
method: init?.method ?? req.method,
|
|
@@ -355,7 +355,8 @@ export function createRequestExecutor(deps) {
|
|
|
355
355
|
// A host that sends each request through its own raw sender (the GA
|
|
356
356
|
// loopback bridge) supplies it per request; every send of this request,
|
|
357
357
|
// warmups included, then goes through it with the same AbortSignal.
|
|
358
|
-
const
|
|
358
|
+
const sender = options.transport ?? defaultTransport;
|
|
359
|
+
const transport = (url, sendInit, sendOptions) => deadline.open(() => sender(url, sendInit, { ...sendOptions, signal: deadline.signal }));
|
|
359
360
|
const requestSessionIdentity = options.session ?? extractOpenCodeSessionIdentity(init?.headers);
|
|
360
361
|
// AGY conversation/trajectory/step metadata is kept per session and
|
|
361
362
|
// request kind: a title or compaction request never advances the
|
|
@@ -376,7 +377,7 @@ export function createRequestExecutor(deps) {
|
|
|
376
377
|
const urlString = typeof input === 'string' ? input : toUrlString(input);
|
|
377
378
|
const modelFromUrl = extractModelFromUrl(urlString) ?? 'unknown';
|
|
378
379
|
return createNoAccountResponse(credentials.domain === 'vault'
|
|
379
|
-
? VAULT_ACCOUNT_REMEDY
|
|
380
|
+
? (credentials.emptyRosterRefusal?.() ?? VAULT_ACCOUNT_REMEDY)
|
|
380
381
|
: 'No Antigravity accounts configured. Run `opencode auth login`.', modelFromUrl);
|
|
381
382
|
}
|
|
382
383
|
const urlString = toUrlString(input);
|
|
@@ -386,7 +387,7 @@ export function createRequestExecutor(deps) {
|
|
|
386
387
|
const pushDebug = (line) => {
|
|
387
388
|
if (!debug.isDebugEnabled())
|
|
388
389
|
return;
|
|
389
|
-
debugLines.push(redactCredentialText(line, [...selectedCredentials]));
|
|
390
|
+
debugLines.push(redactCredentialText(line, [...selectedCredentials], [...selectedProjectIds]));
|
|
390
391
|
};
|
|
391
392
|
pushDebug(`request=${urlString}`);
|
|
392
393
|
if (requestSessionIdentity.sessionId) {
|
|
@@ -403,6 +404,7 @@ export function createRequestExecutor(deps) {
|
|
|
403
404
|
let lastError = null;
|
|
404
405
|
const abortSignal = init?.signal ?? undefined;
|
|
405
406
|
const checkAborted = () => {
|
|
407
|
+
deadline.check();
|
|
406
408
|
if (abortSignal?.aborted) {
|
|
407
409
|
throw abortSignal.reason instanceof Error
|
|
408
410
|
? abortSignal.reason
|
|
@@ -436,9 +438,10 @@ export function createRequestExecutor(deps) {
|
|
|
436
438
|
}
|
|
437
439
|
}
|
|
438
440
|
try {
|
|
439
|
-
await notify?.(message, variant);
|
|
441
|
+
await deadline.wait(() => notify?.(message, variant));
|
|
440
442
|
}
|
|
441
443
|
catch {
|
|
444
|
+
checkAborted();
|
|
442
445
|
// TUI may not be available
|
|
443
446
|
}
|
|
444
447
|
};
|
|
@@ -447,6 +450,8 @@ export function createRequestExecutor(deps) {
|
|
|
447
450
|
let previousAccountIndex = -1;
|
|
448
451
|
let needsCacheWarmup = false;
|
|
449
452
|
let localRecaptureUsed = false;
|
|
453
|
+
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
|
|
454
|
+
let allAccountsBlockedAt;
|
|
450
455
|
while (true) {
|
|
451
456
|
await assertAdmission();
|
|
452
457
|
checkAborted();
|
|
@@ -527,11 +532,28 @@ export function createRequestExecutor(deps) {
|
|
|
527
532
|
account = null;
|
|
528
533
|
}
|
|
529
534
|
if (!account) {
|
|
535
|
+
// Rate-limit and soft-quota waits belong to the same blocked period.
|
|
536
|
+
// Selection of an eligible account below starts a fresh budget.
|
|
537
|
+
allAccountsBlockedAt ??= Date.now();
|
|
538
|
+
const blockedSince = allAccountsBlockedAt;
|
|
539
|
+
const remainingWaitMs = () => maxWaitMs > 0
|
|
540
|
+
? Math.max(0, maxWaitMs - (Date.now() - blockedSince))
|
|
541
|
+
: Number.POSITIVE_INFINITY;
|
|
542
|
+
// At an equal deadline, retain the classified blocked-pool refusal.
|
|
543
|
+
// This priority never changes either clock or replenishes the request.
|
|
544
|
+
const quotaWins = remainingWaitMs() <= deadline.remainingMs();
|
|
530
545
|
if (accountManager.areAllAccountsOverSoftQuota(family, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, model)) {
|
|
531
546
|
const threshold = config.soft_quota_threshold_percent;
|
|
532
547
|
const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(family, threshold, softQuotaCacheTtlMs, model);
|
|
533
|
-
|
|
548
|
+
waitPolicy.refusal = quotaWins
|
|
549
|
+
? () => createNativeGoogleErrorResponse({
|
|
550
|
+
status: 412,
|
|
551
|
+
reason: 'soft_quota',
|
|
552
|
+
resetAfterMs: softQuotaWaitMs,
|
|
553
|
+
})
|
|
554
|
+
: undefined;
|
|
534
555
|
if (softQuotaWaitMs === null ||
|
|
556
|
+
remainingWaitMs() <= 0 ||
|
|
535
557
|
(maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs)) {
|
|
536
558
|
const waitTimeFormatted = softQuotaWaitMs
|
|
537
559
|
? formatWaitTime(softQuotaWaitMs)
|
|
@@ -548,11 +570,18 @@ export function createRequestExecutor(deps) {
|
|
|
548
570
|
await showToast(`All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`, 'warning');
|
|
549
571
|
retryState.markSoftQuotaToastShown();
|
|
550
572
|
}
|
|
551
|
-
await sleep(softQuotaWaitMs, abortSignal);
|
|
573
|
+
await sleep(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
|
|
552
574
|
continue;
|
|
553
575
|
}
|
|
554
576
|
const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
|
|
555
577
|
const waitMs = minWaitMs || 60_000;
|
|
578
|
+
waitPolicy.refusal = quotaWins
|
|
579
|
+
? () => createNativeGoogleErrorResponse({
|
|
580
|
+
status: 412,
|
|
581
|
+
reason: 'pool_unavailable',
|
|
582
|
+
resetAfterMs: minWaitMs > 0 ? minWaitMs : undefined,
|
|
583
|
+
})
|
|
584
|
+
: undefined;
|
|
556
585
|
pushDebug(`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`);
|
|
557
586
|
if (debug.isDebugEnabled()) {
|
|
558
587
|
debug.logAccountContext('All accounts rate-limited', {
|
|
@@ -562,8 +591,7 @@ export function createRequestExecutor(deps) {
|
|
|
562
591
|
});
|
|
563
592
|
debug.logRateLimitSnapshot(family, accountManager.getAccountsSnapshot());
|
|
564
593
|
}
|
|
565
|
-
|
|
566
|
-
if (maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
594
|
+
if (remainingWaitMs() <= 0 || (maxWaitMs > 0 && waitMs > maxWaitMs)) {
|
|
567
595
|
const waitTimeFormatted = formatWaitTime(waitMs);
|
|
568
596
|
await showToast(`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`, 'error');
|
|
569
597
|
return createNativeGoogleErrorResponse({
|
|
@@ -579,10 +607,12 @@ export function createRequestExecutor(deps) {
|
|
|
579
607
|
await showToast(`All ${accountCount} account(s) rate-limited for ${family}. Waiting ${waitSecValue}s...`, 'warning');
|
|
580
608
|
retryState.markRateLimitToastShown();
|
|
581
609
|
}
|
|
582
|
-
await sleep(waitMs, abortSignal);
|
|
610
|
+
await sleep(Math.min(waitMs, remainingWaitMs()), abortSignal);
|
|
583
611
|
continue;
|
|
584
612
|
}
|
|
585
|
-
//
|
|
613
|
+
// An eligible account ends the contiguous all-accounts-blocked period.
|
|
614
|
+
allAccountsBlockedAt = undefined;
|
|
615
|
+
waitPolicy.refusal = undefined;
|
|
586
616
|
retryState.resetAllAccountsBlockedToasts();
|
|
587
617
|
pushDebug(`selected idx=${account.index} email=${account.email ?? ''} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`);
|
|
588
618
|
if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
|
|
@@ -623,11 +653,21 @@ export function createRequestExecutor(deps) {
|
|
|
623
653
|
// Project resolution can use this bearer before the main model send.
|
|
624
654
|
if (auth.access)
|
|
625
655
|
selectedCredentials.add(auth.access);
|
|
626
|
-
const
|
|
627
|
-
|
|
656
|
+
const packedProject = parseRefreshParts(auth.refresh);
|
|
657
|
+
for (const projectId of [
|
|
658
|
+
packedProject.projectId,
|
|
659
|
+
packedProject.managedProjectId,
|
|
660
|
+
]) {
|
|
661
|
+
if (projectId)
|
|
662
|
+
selectedProjectIds.add(projectId);
|
|
663
|
+
}
|
|
664
|
+
const context = await deadline
|
|
665
|
+
.wait(() => credentials.ensureProject(auth))
|
|
628
666
|
.catch((error) => {
|
|
629
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
667
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
630
668
|
});
|
|
669
|
+
if (context.effectiveProjectId)
|
|
670
|
+
selectedProjectIds.add(context.effectiveProjectId);
|
|
631
671
|
await assertAdmission();
|
|
632
672
|
// A project cache may carry an older bearer. Only the token fixed
|
|
633
673
|
// before this await belongs to the newly prepared request.
|
|
@@ -639,9 +679,10 @@ export function createRequestExecutor(deps) {
|
|
|
639
679
|
if (persistProject && projectAuth.refresh !== auth.refresh) {
|
|
640
680
|
credentials.updateFromAuth(account, projectAuth);
|
|
641
681
|
try {
|
|
642
|
-
await credentials.saveToDisk();
|
|
682
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
643
683
|
}
|
|
644
684
|
catch (error) {
|
|
685
|
+
checkAborted();
|
|
645
686
|
log.error('Failed to persist project context', {
|
|
646
687
|
error: String(error),
|
|
647
688
|
});
|
|
@@ -669,7 +710,7 @@ export function createRequestExecutor(deps) {
|
|
|
669
710
|
if (accessTokenExpired(authRecord)) {
|
|
670
711
|
try {
|
|
671
712
|
await assertAdmission();
|
|
672
|
-
const refreshed = await credentials.refresh(account);
|
|
713
|
+
const refreshed = await deadline.wait(() => credentials.refresh(account));
|
|
673
714
|
if (!refreshed) {
|
|
674
715
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
675
716
|
trackers.health.recordFailure(account.index);
|
|
@@ -696,23 +737,26 @@ export function createRequestExecutor(deps) {
|
|
|
696
737
|
authRecord = refreshed;
|
|
697
738
|
grantCheck = captureFor(authRecord);
|
|
698
739
|
try {
|
|
699
|
-
await credentials.saveToDisk();
|
|
740
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
700
741
|
}
|
|
701
742
|
catch (error) {
|
|
743
|
+
checkAborted();
|
|
702
744
|
log.error('Failed to persist refreshed auth', {
|
|
703
745
|
error: String(error),
|
|
704
746
|
});
|
|
705
747
|
}
|
|
706
748
|
}
|
|
707
749
|
catch (error) {
|
|
750
|
+
checkAborted();
|
|
708
751
|
if (credentials.isInvalidGrant(error)) {
|
|
709
752
|
const removed = credentials.removeAccount(account);
|
|
710
753
|
if (removed) {
|
|
711
754
|
log.warn('Removed revoked account from pool - reauthenticate via `opencode auth login`');
|
|
712
755
|
try {
|
|
713
|
-
await credentials.saveToDiskReplace();
|
|
756
|
+
await deadline.wait(() => credentials.saveToDiskReplace());
|
|
714
757
|
}
|
|
715
758
|
catch (persistError) {
|
|
759
|
+
checkAborted();
|
|
716
760
|
log.error('Failed to persist revoked account removal', {
|
|
717
761
|
error: String(persistError),
|
|
718
762
|
});
|
|
@@ -720,9 +764,10 @@ export function createRequestExecutor(deps) {
|
|
|
720
764
|
}
|
|
721
765
|
if (accountManager.getAccountCount() === 0) {
|
|
722
766
|
try {
|
|
723
|
-
await credentials.clearStoredAuth();
|
|
767
|
+
await deadline.wait(() => credentials.clearStoredAuth());
|
|
724
768
|
}
|
|
725
769
|
catch (storeError) {
|
|
770
|
+
checkAborted();
|
|
726
771
|
log.error('Failed to clear stored Antigravity OAuth credentials', {
|
|
727
772
|
error: String(storeError),
|
|
728
773
|
});
|
|
@@ -763,6 +808,7 @@ export function createRequestExecutor(deps) {
|
|
|
763
808
|
retryState.resetAccountFailureState(account.index);
|
|
764
809
|
}
|
|
765
810
|
catch (error) {
|
|
811
|
+
checkAborted();
|
|
766
812
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
767
813
|
trackers.health.recordFailure(account.index);
|
|
768
814
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -784,10 +830,10 @@ export function createRequestExecutor(deps) {
|
|
|
784
830
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
785
831
|
await assertAdmission();
|
|
786
832
|
if (credentials.domain === 'vault') {
|
|
787
|
-
const admission = await credentials.admit({
|
|
833
|
+
const admission = await deadline.wait(() => credentials.admit({
|
|
788
834
|
account: selected,
|
|
789
835
|
signal: abortSignal,
|
|
790
|
-
});
|
|
836
|
+
}));
|
|
791
837
|
selectedCredentials.add(admission.accessToken);
|
|
792
838
|
if (admission.projectId !== preparedProjectId) {
|
|
793
839
|
throw new Error('The vault served another project for this send; skipping it');
|
|
@@ -799,7 +845,7 @@ export function createRequestExecutor(deps) {
|
|
|
799
845
|
if (!localGrant) {
|
|
800
846
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
801
847
|
}
|
|
802
|
-
await localGrant.captured.check();
|
|
848
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
803
849
|
await assertAdmission();
|
|
804
850
|
return { init: sendInit };
|
|
805
851
|
};
|
|
@@ -841,13 +887,16 @@ export function createRequestExecutor(deps) {
|
|
|
841
887
|
onDebug: pushDebug,
|
|
842
888
|
});
|
|
843
889
|
reportVault401(warmupSend.admission, warmupResponse.status);
|
|
844
|
-
const transformed = await wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId);
|
|
845
|
-
await transformed.text();
|
|
890
|
+
const transformed = await deadline.wait(() => wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId));
|
|
891
|
+
await deadline.wait(() => transformed.text());
|
|
846
892
|
warmupState.markSuccess(prepared.sessionId);
|
|
847
893
|
pushDebug('thinking-warmup: done');
|
|
848
894
|
}
|
|
849
895
|
catch (error) {
|
|
850
896
|
warmupState.clearWarmupAttempt(prepared.sessionId);
|
|
897
|
+
if (error instanceof PreResponseTimeoutError)
|
|
898
|
+
throw error;
|
|
899
|
+
checkAborted();
|
|
851
900
|
if (isLocalGrantError(error))
|
|
852
901
|
throw error;
|
|
853
902
|
pushDebug(`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -872,14 +921,14 @@ export function createRequestExecutor(deps) {
|
|
|
872
921
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
873
922
|
if (probeResponse.body) {
|
|
874
923
|
const reader = probeResponse.body.getReader();
|
|
875
|
-
await reader.read();
|
|
876
|
-
await reader.cancel();
|
|
924
|
+
await deadline.wait(() => reader.read());
|
|
925
|
+
await deadline.wait(() => reader.cancel());
|
|
877
926
|
}
|
|
878
927
|
const status = probeResponse.status;
|
|
879
928
|
if (status >= 400) {
|
|
880
929
|
let errorSnippet = '';
|
|
881
930
|
try {
|
|
882
|
-
const errText = await probeResponse.text().catch(() => '');
|
|
931
|
+
const errText = await deadline.wait(() => probeResponse.text().catch(() => ''));
|
|
883
932
|
errorSnippet = errText.slice(0, 200);
|
|
884
933
|
}
|
|
885
934
|
catch {
|
|
@@ -892,6 +941,9 @@ export function createRequestExecutor(deps) {
|
|
|
892
941
|
}
|
|
893
942
|
}
|
|
894
943
|
catch (error) {
|
|
944
|
+
if (error instanceof PreResponseTimeoutError)
|
|
945
|
+
throw error;
|
|
946
|
+
checkAborted();
|
|
895
947
|
if (isLocalGrantError(error)) {
|
|
896
948
|
needsCacheWarmup = true;
|
|
897
949
|
throw error;
|
|
@@ -937,10 +989,10 @@ export function createRequestExecutor(deps) {
|
|
|
937
989
|
// retry it was taken for, then is gone.
|
|
938
990
|
sendAdmission =
|
|
939
991
|
rotatedAdmission ??
|
|
940
|
-
(await credentials.admit({
|
|
992
|
+
(await deadline.wait(() => credentials.admit({
|
|
941
993
|
account,
|
|
942
994
|
signal: abortSignal,
|
|
943
|
-
}));
|
|
995
|
+
})));
|
|
944
996
|
rotatedAdmission = undefined;
|
|
945
997
|
sendAccessToken = sendAdmission.accessToken;
|
|
946
998
|
sendProjectId = sendAdmission.projectId;
|
|
@@ -952,6 +1004,8 @@ export function createRequestExecutor(deps) {
|
|
|
952
1004
|
else {
|
|
953
1005
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
954
1006
|
}
|
|
1007
|
+
if (sendProjectId)
|
|
1008
|
+
selectedProjectIds.add(sendProjectId);
|
|
955
1009
|
selectedCredentials.add(sendAccessToken);
|
|
956
1010
|
const prepared = prepareAgyWireRequest(wire, {
|
|
957
1011
|
input,
|
|
@@ -1005,7 +1059,6 @@ export function createRequestExecutor(deps) {
|
|
|
1005
1059
|
sessionId: prepared.sessionId,
|
|
1006
1060
|
toolDebugMissing: prepared.toolDebugMissing,
|
|
1007
1061
|
toolDebugSummary: prepared.toolDebugSummary,
|
|
1008
|
-
toolDebugPayload: prepared.toolDebugPayload,
|
|
1009
1062
|
dumpContext,
|
|
1010
1063
|
});
|
|
1011
1064
|
await runThinkingWarmup(prepared, sendProjectId);
|
|
@@ -1024,12 +1077,14 @@ export function createRequestExecutor(deps) {
|
|
|
1024
1077
|
if (!localGrant) {
|
|
1025
1078
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
1026
1079
|
}
|
|
1027
|
-
await localGrant.captured.check();
|
|
1080
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
1028
1081
|
await assertAdmission();
|
|
1029
1082
|
}
|
|
1030
1083
|
pushDebug(`dispatching request via ${prepared.headerStyle} transport`);
|
|
1031
1084
|
physicalAttemptStarted = true;
|
|
1032
1085
|
const response = await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug });
|
|
1086
|
+
if (response.ok)
|
|
1087
|
+
deadline.acceptHeaders();
|
|
1033
1088
|
apiRequestCount++;
|
|
1034
1089
|
accountManager.recordRequest(account.index, family);
|
|
1035
1090
|
const requestCounts = accountManager.getDailyRequestCounts(account.index);
|
|
@@ -1041,26 +1096,29 @@ export function createRequestExecutor(deps) {
|
|
|
1041
1096
|
if (credentials.domain === 'vault' &&
|
|
1042
1097
|
sendAdmission &&
|
|
1043
1098
|
response.status === 401) {
|
|
1044
|
-
//
|
|
1045
|
-
//
|
|
1046
|
-
//
|
|
1047
|
-
//
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1099
|
+
// Match ClaustrumConsumer.send: a rejected kept receipt is discarded
|
|
1100
|
+
// without re-admitting. For fresh receipts, re-admit before reporting
|
|
1101
|
+
// the final 401 so the report also discards any kept copy of the
|
|
1102
|
+
// rejected record version.
|
|
1103
|
+
if (!sendAdmission.fromKeptReceipt &&
|
|
1104
|
+
!vault401Retried &&
|
|
1105
|
+
!abortSignal?.aborted) {
|
|
1106
|
+
let next;
|
|
1107
|
+
try {
|
|
1108
|
+
next = await deadline.wait(() => credentials.admit({ account, signal: abortSignal }));
|
|
1109
|
+
}
|
|
1110
|
+
catch {
|
|
1111
|
+
checkAborted();
|
|
1112
|
+
// A failed re-admission leaves the original upstream 401 intact.
|
|
1113
|
+
}
|
|
1114
|
+
const retry = credentials.retryAfter401
|
|
1115
|
+
? credentials.retryAfter401(sendAdmission, next, 'model')
|
|
1116
|
+
: next &&
|
|
1117
|
+
!next.fromKeptReceipt &&
|
|
1118
|
+
next.credentialId === sendAdmission.credentialId &&
|
|
1119
|
+
next.accountIdentity === sendAdmission.accountIdentity &&
|
|
1120
|
+
next.recordVersion > sendAdmission.recordVersion;
|
|
1121
|
+
if (next && retry) {
|
|
1064
1122
|
vault401Retried = true;
|
|
1065
1123
|
rotatedAdmission = next;
|
|
1066
1124
|
void response.body?.cancel().catch(() => { });
|
|
@@ -1069,6 +1127,15 @@ export function createRequestExecutor(deps) {
|
|
|
1069
1127
|
continue;
|
|
1070
1128
|
}
|
|
1071
1129
|
}
|
|
1130
|
+
try {
|
|
1131
|
+
await deadline.wait(() => sendAdmission.report401(response.status));
|
|
1132
|
+
}
|
|
1133
|
+
catch (error) {
|
|
1134
|
+
checkAborted();
|
|
1135
|
+
log.debug('send-admission-401-report-failed', {
|
|
1136
|
+
error: String(error),
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1072
1139
|
}
|
|
1073
1140
|
// Record the final route selection so the sidebar renders the
|
|
1074
1141
|
// actual account/header-style used by this request. Fire-and-
|
|
@@ -1096,7 +1163,7 @@ export function createRequestExecutor(deps) {
|
|
|
1096
1163
|
const headerRetryMs = retryAfterMsFromResponse(response, defaultRetryMs);
|
|
1097
1164
|
const bodyInfo = await (async () => {
|
|
1098
1165
|
try {
|
|
1099
|
-
const text = await response.clone().text();
|
|
1166
|
+
const text = await deadline.wait(() => response.clone().text());
|
|
1100
1167
|
try {
|
|
1101
1168
|
return JSON.parse(text);
|
|
1102
1169
|
}
|
|
@@ -1105,6 +1172,7 @@ export function createRequestExecutor(deps) {
|
|
|
1105
1172
|
}
|
|
1106
1173
|
}
|
|
1107
1174
|
catch {
|
|
1175
|
+
checkAborted();
|
|
1108
1176
|
return null;
|
|
1109
1177
|
}
|
|
1110
1178
|
})();
|
|
@@ -1157,7 +1225,7 @@ export function createRequestExecutor(deps) {
|
|
|
1157
1225
|
if (reasonInfo.reason)
|
|
1158
1226
|
pushDebug(`429 reason=${reasonInfo.reason}`);
|
|
1159
1227
|
debug.logRateLimitEvent(account.index, account.email, family, response.status, effectiveDelayMs, reasonInfo);
|
|
1160
|
-
await
|
|
1228
|
+
await logResponseBody(debugContext, response, 429);
|
|
1161
1229
|
trackers.health.recordRateLimit(account.index);
|
|
1162
1230
|
const _accountLabel = account.email || `Account ${account.index + 1}`;
|
|
1163
1231
|
if (backoff.attempt === 1 &&
|
|
@@ -1210,10 +1278,10 @@ export function createRequestExecutor(deps) {
|
|
|
1210
1278
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
1211
1279
|
retryState.resetAccountFailureState(account.index);
|
|
1212
1280
|
if (response.status === 403) {
|
|
1213
|
-
const errorBodyText = await response
|
|
1281
|
+
const errorBodyText = await deadline.wait(() => response
|
|
1214
1282
|
.clone()
|
|
1215
1283
|
.text()
|
|
1216
|
-
.catch(() => '');
|
|
1284
|
+
.catch(() => ''));
|
|
1217
1285
|
const extracted = classifyAccessError(errorBodyText);
|
|
1218
1286
|
if (extracted.accountIneligible) {
|
|
1219
1287
|
const ineligibleReason = extracted.message ??
|
|
@@ -1254,7 +1322,7 @@ export function createRequestExecutor(deps) {
|
|
|
1254
1322
|
response.status >= 500;
|
|
1255
1323
|
if (shouldRetryEndpoint &&
|
|
1256
1324
|
i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
1257
|
-
await
|
|
1325
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1258
1326
|
lastFailure = createFailureContext(response);
|
|
1259
1327
|
continue;
|
|
1260
1328
|
}
|
|
@@ -1263,21 +1331,6 @@ export function createRequestExecutor(deps) {
|
|
|
1263
1331
|
trackers.health.recordSuccess(account.index);
|
|
1264
1332
|
if (!advisoryClosing)
|
|
1265
1333
|
accountManager.markAccountUsed(account.index);
|
|
1266
|
-
if (credentials.domain === 'local' &&
|
|
1267
|
-
!advisoryClosing &&
|
|
1268
|
-
credentials.refreshQuotaAfterSuccess) {
|
|
1269
|
-
const quotaCancellation = createRequestCancellation(init?.signal
|
|
1270
|
-
? [init.signal, shutdown.signal]
|
|
1271
|
-
: [shutdown.signal]);
|
|
1272
|
-
const work = credentials
|
|
1273
|
-
.refreshQuotaAfterSuccess(account, config.quota_refresh_interval_minutes, quotaCancellation.signal)
|
|
1274
|
-
.catch(() => {
|
|
1275
|
-
log.debug('post-response-advisory-work-failed');
|
|
1276
|
-
})
|
|
1277
|
-
.finally(() => quotaCancellation.release());
|
|
1278
|
-
advisoryWork.add(work);
|
|
1279
|
-
void work.then(() => advisoryWork.delete(work), () => advisoryWork.delete(work));
|
|
1280
|
-
}
|
|
1281
1334
|
const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
|
|
1282
1335
|
if (!advisoryClosing &&
|
|
1283
1336
|
proactiveThreshold > 0 &&
|
|
@@ -1297,13 +1350,13 @@ export function createRequestExecutor(deps) {
|
|
|
1297
1350
|
note: response.ok ? 'Success' : `Error ${response.status}`,
|
|
1298
1351
|
});
|
|
1299
1352
|
if (response.ok && !prepared.streaming) {
|
|
1300
|
-
await
|
|
1353
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1301
1354
|
}
|
|
1302
1355
|
if (!response.ok) {
|
|
1303
|
-
await
|
|
1356
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1304
1357
|
if (response.status === 400) {
|
|
1305
1358
|
const cloned = response.clone();
|
|
1306
|
-
const bodyText = await cloned.text();
|
|
1359
|
+
const bodyText = await deadline.wait(() => cloned.text());
|
|
1307
1360
|
if (bodyText.includes('Prompt is too long') ||
|
|
1308
1361
|
bodyText.includes('prompt_too_long')) {
|
|
1309
1362
|
await showToast('Context too long - use /compact to reduce size', 'warning');
|
|
@@ -1318,12 +1371,13 @@ export function createRequestExecutor(deps) {
|
|
|
1318
1371
|
const maxAttempts = config.empty_response_max_attempts ?? 4;
|
|
1319
1372
|
const retryDelayMs = config.empty_response_retry_delay_ms ?? 2000;
|
|
1320
1373
|
const clonedForCheck = response.clone();
|
|
1321
|
-
const bodyText = await clonedForCheck.text();
|
|
1374
|
+
const bodyText = await deadline.wait(() => clonedForCheck.text());
|
|
1322
1375
|
if (isEmptyResponseBody(bodyText)) {
|
|
1323
1376
|
const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1324
1377
|
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
1325
1378
|
pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
|
|
1326
1379
|
if (currentAttempts < maxAttempts) {
|
|
1380
|
+
deadline.resume();
|
|
1327
1381
|
await showToast(`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`, 'warning');
|
|
1328
1382
|
await sleep(retryDelayMs, abortSignal);
|
|
1329
1383
|
continue;
|
|
@@ -1337,7 +1391,7 @@ export function createRequestExecutor(deps) {
|
|
|
1337
1391
|
const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1338
1392
|
retryState.clearEmptyResponseAttempts();
|
|
1339
1393
|
}
|
|
1340
|
-
const transformedResponse = await wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary,
|
|
1394
|
+
const transformedResponse = await deadline.wait(() => wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary, debugLines, dumpContext));
|
|
1341
1395
|
const contextError = transformedResponse.headers.get('x-antigravity-context-error');
|
|
1342
1396
|
if (contextError) {
|
|
1343
1397
|
if (contextError === 'prompt_too_long') {
|
|
@@ -1375,9 +1429,20 @@ export function createRequestExecutor(deps) {
|
|
|
1375
1429
|
pushDebug(`[Quota] Session: ${sessionSummary.durationMinutes}min, ${familyTotal} ${family} reqs, ~${ratePerHour} reqs/hr, ${sessionSummary.accountsUsed} accounts used`);
|
|
1376
1430
|
}
|
|
1377
1431
|
}
|
|
1432
|
+
if (response.ok &&
|
|
1433
|
+
transformedResponse.ok &&
|
|
1434
|
+
credentials.domain === 'local' &&
|
|
1435
|
+
!advisoryClosing &&
|
|
1436
|
+
credentials.refreshQuotaAfterSuccess) {
|
|
1437
|
+
const refresh = credentials.refreshQuotaAfterSuccess;
|
|
1438
|
+
waitPolicy.quota = (signal) => refresh(account, config.quota_refresh_interval_minutes, signal);
|
|
1439
|
+
}
|
|
1378
1440
|
return transformedResponse;
|
|
1379
1441
|
}
|
|
1380
1442
|
catch (error) {
|
|
1443
|
+
if (error instanceof PreResponseTimeoutError)
|
|
1444
|
+
throw error;
|
|
1445
|
+
checkAborted();
|
|
1381
1446
|
if (tokenConsumed &&
|
|
1382
1447
|
(!isLocalGrantError(error) || !physicalAttemptStarted)) {
|
|
1383
1448
|
trackers.token.refund(account.index);
|
|
@@ -1393,7 +1458,8 @@ export function createRequestExecutor(deps) {
|
|
|
1393
1458
|
!localRecaptureUsed) {
|
|
1394
1459
|
localRecaptureUsed = true;
|
|
1395
1460
|
try {
|
|
1396
|
-
|
|
1461
|
+
const originalGrant = localGrant.captured;
|
|
1462
|
+
await deadline.wait(() => originalGrant.resolveCurrent());
|
|
1397
1463
|
const auth = credentials.toAuthDetails(account);
|
|
1398
1464
|
if (!auth.access || accessTokenExpired(auth))
|
|
1399
1465
|
return createNativeGoogleErrorResponse({
|
|
@@ -1420,6 +1486,7 @@ export function createRequestExecutor(deps) {
|
|
|
1420
1486
|
if (error instanceof Error &&
|
|
1421
1487
|
error.message === 'THINKING_RECOVERY_NEEDED') {
|
|
1422
1488
|
if (!forceThinkingRecovery) {
|
|
1489
|
+
deadline.resume();
|
|
1423
1490
|
pushDebug('thinking-recovery: API error detected, retrying with forced recovery');
|
|
1424
1491
|
forceThinkingRecovery = true;
|
|
1425
1492
|
i = -1;
|
|
@@ -1464,20 +1531,20 @@ export function createRequestExecutor(deps) {
|
|
|
1464
1531
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
1465
1532
|
pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
|
|
1466
1533
|
if (lastFailure) {
|
|
1467
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1534
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1468
1535
|
}
|
|
1469
1536
|
throw terminalFetchError(lastError, `Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
|
|
1470
1537
|
}
|
|
1471
1538
|
if (accountCount <= 1) {
|
|
1472
1539
|
if (lastFailure) {
|
|
1473
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1540
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1474
1541
|
}
|
|
1475
1542
|
throw terminalFetchError(lastError, 'All Antigravity endpoints failed');
|
|
1476
1543
|
}
|
|
1477
1544
|
continue;
|
|
1478
1545
|
}
|
|
1479
1546
|
if (lastFailure) {
|
|
1480
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1547
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1481
1548
|
}
|
|
1482
1549
|
throw terminalFetchError(lastError, 'All Antigravity accounts failed');
|
|
1483
1550
|
}
|
|
@@ -1519,26 +1586,62 @@ export function createRequestExecutor(deps) {
|
|
|
1519
1586
|
const cancellation = createRequestCancellation(requestedSignal
|
|
1520
1587
|
? [requestedSignal, shutdown.signal]
|
|
1521
1588
|
: [shutdown.signal]);
|
|
1589
|
+
const deadline = new PreResponseDeadline(cancellation.signal, deps.preResponseClock);
|
|
1590
|
+
log.debug('pre-response-start', { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
1591
|
+
const handoff = createAfterHandoff(advisoryWork, requestedSignal
|
|
1592
|
+
? [requestedSignal, shutdown.signal]
|
|
1593
|
+
: [shutdown.signal], () => log.debug('post-response-advisory-work-failed'));
|
|
1594
|
+
const waitPolicy = {};
|
|
1522
1595
|
const selectedCredentials = new Set();
|
|
1523
|
-
const
|
|
1596
|
+
const selectedProjectIds = new Set();
|
|
1597
|
+
const pending = deadline
|
|
1598
|
+
.wait(() => execute(input, { ...init, signal: deadline.signal }, requestOptions ?? {}, selectedCredentials, selectedProjectIds, deadline, waitPolicy))
|
|
1599
|
+
.catch((error) => {
|
|
1600
|
+
cancellation.signal.throwIfAborted();
|
|
1601
|
+
if (error instanceof PreResponseTimeoutError) {
|
|
1602
|
+
log.debug('pre-response-timeout', { reason: error.reason });
|
|
1603
|
+
return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
|
|
1604
|
+
}
|
|
1605
|
+
throw error;
|
|
1606
|
+
})
|
|
1524
1607
|
.then(async (response) => {
|
|
1608
|
+
// Retain caller cancellation over the accepted response body;
|
|
1609
|
+
// only the pre-response timer ends at accepted headers.
|
|
1610
|
+
deadline.acceptTerminalResponse();
|
|
1525
1611
|
// Overflow classification read a clone to EOF. Reuse that text
|
|
1526
1612
|
// for redaction; safe diagnostics retain the original unread response.
|
|
1527
1613
|
if (bufferedOverflow.has(response)) {
|
|
1614
|
+
handoff.cancel();
|
|
1615
|
+
deadline.dispose();
|
|
1528
1616
|
cancellation.release();
|
|
1529
|
-
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response));
|
|
1617
|
+
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response), [...selectedProjectIds]);
|
|
1530
1618
|
}
|
|
1531
1619
|
const retained = await retainResponseLifetime(response, cancellation);
|
|
1532
1620
|
inFlight.add(retained.settled);
|
|
1533
1621
|
void retained.settled.then(() => inFlight.delete(retained.settled));
|
|
1534
|
-
|
|
1622
|
+
void retained.settled.then(() => deadline.dispose());
|
|
1623
|
+
const published = await redactCredentialResponse(preserveResponseMetadata(retained.response, response), [...selectedCredentials], undefined, [...selectedProjectIds]);
|
|
1624
|
+
if (published.ok &&
|
|
1625
|
+
waitPolicy.quota &&
|
|
1626
|
+
requestOptions?.onResponseHandoff) {
|
|
1627
|
+
handoff.register(waitPolicy.quota);
|
|
1628
|
+
requestOptions.onResponseHandoff(handoff.acknowledge);
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
handoff.cancel();
|
|
1632
|
+
}
|
|
1633
|
+
return published;
|
|
1535
1634
|
}, (error) => {
|
|
1635
|
+
handoff.cancel();
|
|
1636
|
+
deadline.dispose();
|
|
1536
1637
|
cancellation.release();
|
|
1537
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1638
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1538
1639
|
})
|
|
1539
1640
|
.catch((error) => {
|
|
1641
|
+
handoff.cancel();
|
|
1642
|
+
deadline.dispose();
|
|
1540
1643
|
cancellation.release();
|
|
1541
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1644
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1542
1645
|
});
|
|
1543
1646
|
inFlight.add(pending);
|
|
1544
1647
|
void pending.then(() => inFlight.delete(pending), () => inFlight.delete(pending));
|