@cortexkit/opencode-antigravity-auth 3.0.6 → 3.0.7
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 +620 -120
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +128 -44
- package/dist/index.js +1469 -675
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +154 -73
- package/dist/server.js +1075 -280
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +38 -1
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- 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 +14 -3
- package/dist/src/common-auth-embedded/quota/format.js +135 -18
- package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/quota/index.js +1 -1
- 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 +92 -76
- 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.map +1 -1
- package/dist/src/ga/server/index.js +4 -2
- 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/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/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +4 -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/request-services.d.ts +8 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +140 -58
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +12 -3
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +3 -0
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +14 -1
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +57 -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 +26 -128
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +42 -13
- package/dist/tui-ga-build-map.json +46 -17
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- 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 +14 -3
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
- 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.map +1 -1
- package/dist/types/src/plugin/config/schema.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/request-services.d.ts +8 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +12 -3
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +14 -1
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/src/common-auth-embedded/claustrum/consumer.js +38 -1
- package/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- 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 +14 -3
- package/src/common-auth-embedded/quota/format.js +135 -18
- package/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/src/common-auth-embedded/quota/index.js +1 -1
- 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 +92 -76
- 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/quota/format.js +135 -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 +145 -427
- 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 +135 -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 +135 -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/quota/format.js +135 -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 +50 -309
- package/src/tui.tsx +50 -309
|
@@ -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';
|
|
@@ -270,12 +270,11 @@ export function createRequestExecutor(deps) {
|
|
|
270
270
|
log.debug('routing-report-failed', { sessionId, error: String(error) });
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
|
-
async function execute(input, init, options
|
|
273
|
+
async function execute(input, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
274
274
|
const assertAdmission = async () => {
|
|
275
|
-
|
|
276
|
-
await deps.assertAdmission?.();
|
|
277
|
-
init?.signal?.throwIfAborted();
|
|
275
|
+
await deadline.wait(() => deps.assertAdmission?.());
|
|
278
276
|
};
|
|
277
|
+
const logResponseBody = (...args) => deadline.wait(() => debug.logResponseBody(...args));
|
|
279
278
|
await assertAdmission();
|
|
280
279
|
// Normalize Request/URL inputs to (urlString, init) so the string-based
|
|
281
280
|
// transform pipeline sees the real method/headers/body. Without this,
|
|
@@ -291,7 +290,7 @@ export function createRequestExecutor(deps) {
|
|
|
291
290
|
});
|
|
292
291
|
}
|
|
293
292
|
const bodyBuffer = req.body
|
|
294
|
-
? await req.clone().arrayBuffer()
|
|
293
|
+
? await deadline.wait(() => req.clone().arrayBuffer())
|
|
295
294
|
: undefined;
|
|
296
295
|
init = {
|
|
297
296
|
method: init?.method ?? req.method,
|
|
@@ -355,7 +354,8 @@ export function createRequestExecutor(deps) {
|
|
|
355
354
|
// A host that sends each request through its own raw sender (the GA
|
|
356
355
|
// loopback bridge) supplies it per request; every send of this request,
|
|
357
356
|
// warmups included, then goes through it with the same AbortSignal.
|
|
358
|
-
const
|
|
357
|
+
const sender = options.transport ?? defaultTransport;
|
|
358
|
+
const transport = (url, sendInit, sendOptions) => deadline.open(() => sender(url, sendInit, { ...sendOptions, signal: deadline.signal }));
|
|
359
359
|
const requestSessionIdentity = options.session ?? extractOpenCodeSessionIdentity(init?.headers);
|
|
360
360
|
// AGY conversation/trajectory/step metadata is kept per session and
|
|
361
361
|
// request kind: a title or compaction request never advances the
|
|
@@ -376,7 +376,7 @@ export function createRequestExecutor(deps) {
|
|
|
376
376
|
const urlString = typeof input === 'string' ? input : toUrlString(input);
|
|
377
377
|
const modelFromUrl = extractModelFromUrl(urlString) ?? 'unknown';
|
|
378
378
|
return createNoAccountResponse(credentials.domain === 'vault'
|
|
379
|
-
? VAULT_ACCOUNT_REMEDY
|
|
379
|
+
? (credentials.emptyRosterRefusal?.() ?? VAULT_ACCOUNT_REMEDY)
|
|
380
380
|
: 'No Antigravity accounts configured. Run `opencode auth login`.', modelFromUrl);
|
|
381
381
|
}
|
|
382
382
|
const urlString = toUrlString(input);
|
|
@@ -386,7 +386,7 @@ export function createRequestExecutor(deps) {
|
|
|
386
386
|
const pushDebug = (line) => {
|
|
387
387
|
if (!debug.isDebugEnabled())
|
|
388
388
|
return;
|
|
389
|
-
debugLines.push(redactCredentialText(line, [...selectedCredentials]));
|
|
389
|
+
debugLines.push(redactCredentialText(line, [...selectedCredentials], [...selectedProjectIds]));
|
|
390
390
|
};
|
|
391
391
|
pushDebug(`request=${urlString}`);
|
|
392
392
|
if (requestSessionIdentity.sessionId) {
|
|
@@ -403,6 +403,7 @@ export function createRequestExecutor(deps) {
|
|
|
403
403
|
let lastError = null;
|
|
404
404
|
const abortSignal = init?.signal ?? undefined;
|
|
405
405
|
const checkAborted = () => {
|
|
406
|
+
deadline.check();
|
|
406
407
|
if (abortSignal?.aborted) {
|
|
407
408
|
throw abortSignal.reason instanceof Error
|
|
408
409
|
? abortSignal.reason
|
|
@@ -436,9 +437,10 @@ export function createRequestExecutor(deps) {
|
|
|
436
437
|
}
|
|
437
438
|
}
|
|
438
439
|
try {
|
|
439
|
-
await notify?.(message, variant);
|
|
440
|
+
await deadline.wait(() => notify?.(message, variant));
|
|
440
441
|
}
|
|
441
442
|
catch {
|
|
443
|
+
checkAborted();
|
|
442
444
|
// TUI may not be available
|
|
443
445
|
}
|
|
444
446
|
};
|
|
@@ -447,6 +449,8 @@ export function createRequestExecutor(deps) {
|
|
|
447
449
|
let previousAccountIndex = -1;
|
|
448
450
|
let needsCacheWarmup = false;
|
|
449
451
|
let localRecaptureUsed = false;
|
|
452
|
+
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
|
|
453
|
+
let allAccountsBlockedAt;
|
|
450
454
|
while (true) {
|
|
451
455
|
await assertAdmission();
|
|
452
456
|
checkAborted();
|
|
@@ -527,11 +531,28 @@ export function createRequestExecutor(deps) {
|
|
|
527
531
|
account = null;
|
|
528
532
|
}
|
|
529
533
|
if (!account) {
|
|
534
|
+
// Rate-limit and soft-quota waits belong to the same blocked period.
|
|
535
|
+
// Selection of an eligible account below starts a fresh budget.
|
|
536
|
+
allAccountsBlockedAt ??= Date.now();
|
|
537
|
+
const blockedSince = allAccountsBlockedAt;
|
|
538
|
+
const remainingWaitMs = () => maxWaitMs > 0
|
|
539
|
+
? Math.max(0, maxWaitMs - (Date.now() - blockedSince))
|
|
540
|
+
: Number.POSITIVE_INFINITY;
|
|
541
|
+
// At an equal deadline, retain the classified blocked-pool refusal.
|
|
542
|
+
// This priority never changes either clock or replenishes the request.
|
|
543
|
+
const quotaWins = remainingWaitMs() <= deadline.remainingMs();
|
|
530
544
|
if (accountManager.areAllAccountsOverSoftQuota(family, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, model)) {
|
|
531
545
|
const threshold = config.soft_quota_threshold_percent;
|
|
532
546
|
const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(family, threshold, softQuotaCacheTtlMs, model);
|
|
533
|
-
|
|
547
|
+
waitPolicy.refusal = quotaWins
|
|
548
|
+
? () => createNativeGoogleErrorResponse({
|
|
549
|
+
status: 412,
|
|
550
|
+
reason: 'soft_quota',
|
|
551
|
+
resetAfterMs: softQuotaWaitMs,
|
|
552
|
+
})
|
|
553
|
+
: undefined;
|
|
534
554
|
if (softQuotaWaitMs === null ||
|
|
555
|
+
remainingWaitMs() <= 0 ||
|
|
535
556
|
(maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs)) {
|
|
536
557
|
const waitTimeFormatted = softQuotaWaitMs
|
|
537
558
|
? formatWaitTime(softQuotaWaitMs)
|
|
@@ -548,11 +569,18 @@ export function createRequestExecutor(deps) {
|
|
|
548
569
|
await showToast(`All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`, 'warning');
|
|
549
570
|
retryState.markSoftQuotaToastShown();
|
|
550
571
|
}
|
|
551
|
-
await sleep(softQuotaWaitMs, abortSignal);
|
|
572
|
+
await sleep(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
|
|
552
573
|
continue;
|
|
553
574
|
}
|
|
554
575
|
const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
|
|
555
576
|
const waitMs = minWaitMs || 60_000;
|
|
577
|
+
waitPolicy.refusal = quotaWins
|
|
578
|
+
? () => createNativeGoogleErrorResponse({
|
|
579
|
+
status: 412,
|
|
580
|
+
reason: 'pool_unavailable',
|
|
581
|
+
resetAfterMs: minWaitMs > 0 ? minWaitMs : undefined,
|
|
582
|
+
})
|
|
583
|
+
: undefined;
|
|
556
584
|
pushDebug(`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`);
|
|
557
585
|
if (debug.isDebugEnabled()) {
|
|
558
586
|
debug.logAccountContext('All accounts rate-limited', {
|
|
@@ -562,8 +590,7 @@ export function createRequestExecutor(deps) {
|
|
|
562
590
|
});
|
|
563
591
|
debug.logRateLimitSnapshot(family, accountManager.getAccountsSnapshot());
|
|
564
592
|
}
|
|
565
|
-
|
|
566
|
-
if (maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
593
|
+
if (remainingWaitMs() <= 0 || (maxWaitMs > 0 && waitMs > maxWaitMs)) {
|
|
567
594
|
const waitTimeFormatted = formatWaitTime(waitMs);
|
|
568
595
|
await showToast(`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`, 'error');
|
|
569
596
|
return createNativeGoogleErrorResponse({
|
|
@@ -579,10 +606,12 @@ export function createRequestExecutor(deps) {
|
|
|
579
606
|
await showToast(`All ${accountCount} account(s) rate-limited for ${family}. Waiting ${waitSecValue}s...`, 'warning');
|
|
580
607
|
retryState.markRateLimitToastShown();
|
|
581
608
|
}
|
|
582
|
-
await sleep(waitMs, abortSignal);
|
|
609
|
+
await sleep(Math.min(waitMs, remainingWaitMs()), abortSignal);
|
|
583
610
|
continue;
|
|
584
611
|
}
|
|
585
|
-
//
|
|
612
|
+
// An eligible account ends the contiguous all-accounts-blocked period.
|
|
613
|
+
allAccountsBlockedAt = undefined;
|
|
614
|
+
waitPolicy.refusal = undefined;
|
|
586
615
|
retryState.resetAllAccountsBlockedToasts();
|
|
587
616
|
pushDebug(`selected idx=${account.index} email=${account.email ?? ''} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`);
|
|
588
617
|
if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
|
|
@@ -623,11 +652,21 @@ export function createRequestExecutor(deps) {
|
|
|
623
652
|
// Project resolution can use this bearer before the main model send.
|
|
624
653
|
if (auth.access)
|
|
625
654
|
selectedCredentials.add(auth.access);
|
|
626
|
-
const
|
|
627
|
-
|
|
655
|
+
const packedProject = parseRefreshParts(auth.refresh);
|
|
656
|
+
for (const projectId of [
|
|
657
|
+
packedProject.projectId,
|
|
658
|
+
packedProject.managedProjectId,
|
|
659
|
+
]) {
|
|
660
|
+
if (projectId)
|
|
661
|
+
selectedProjectIds.add(projectId);
|
|
662
|
+
}
|
|
663
|
+
const context = await deadline
|
|
664
|
+
.wait(() => credentials.ensureProject(auth))
|
|
628
665
|
.catch((error) => {
|
|
629
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
666
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
630
667
|
});
|
|
668
|
+
if (context.effectiveProjectId)
|
|
669
|
+
selectedProjectIds.add(context.effectiveProjectId);
|
|
631
670
|
await assertAdmission();
|
|
632
671
|
// A project cache may carry an older bearer. Only the token fixed
|
|
633
672
|
// before this await belongs to the newly prepared request.
|
|
@@ -639,9 +678,10 @@ export function createRequestExecutor(deps) {
|
|
|
639
678
|
if (persistProject && projectAuth.refresh !== auth.refresh) {
|
|
640
679
|
credentials.updateFromAuth(account, projectAuth);
|
|
641
680
|
try {
|
|
642
|
-
await credentials.saveToDisk();
|
|
681
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
643
682
|
}
|
|
644
683
|
catch (error) {
|
|
684
|
+
checkAborted();
|
|
645
685
|
log.error('Failed to persist project context', {
|
|
646
686
|
error: String(error),
|
|
647
687
|
});
|
|
@@ -669,7 +709,7 @@ export function createRequestExecutor(deps) {
|
|
|
669
709
|
if (accessTokenExpired(authRecord)) {
|
|
670
710
|
try {
|
|
671
711
|
await assertAdmission();
|
|
672
|
-
const refreshed = await credentials.refresh(account);
|
|
712
|
+
const refreshed = await deadline.wait(() => credentials.refresh(account));
|
|
673
713
|
if (!refreshed) {
|
|
674
714
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
675
715
|
trackers.health.recordFailure(account.index);
|
|
@@ -696,23 +736,26 @@ export function createRequestExecutor(deps) {
|
|
|
696
736
|
authRecord = refreshed;
|
|
697
737
|
grantCheck = captureFor(authRecord);
|
|
698
738
|
try {
|
|
699
|
-
await credentials.saveToDisk();
|
|
739
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
700
740
|
}
|
|
701
741
|
catch (error) {
|
|
742
|
+
checkAborted();
|
|
702
743
|
log.error('Failed to persist refreshed auth', {
|
|
703
744
|
error: String(error),
|
|
704
745
|
});
|
|
705
746
|
}
|
|
706
747
|
}
|
|
707
748
|
catch (error) {
|
|
749
|
+
checkAborted();
|
|
708
750
|
if (credentials.isInvalidGrant(error)) {
|
|
709
751
|
const removed = credentials.removeAccount(account);
|
|
710
752
|
if (removed) {
|
|
711
753
|
log.warn('Removed revoked account from pool - reauthenticate via `opencode auth login`');
|
|
712
754
|
try {
|
|
713
|
-
await credentials.saveToDiskReplace();
|
|
755
|
+
await deadline.wait(() => credentials.saveToDiskReplace());
|
|
714
756
|
}
|
|
715
757
|
catch (persistError) {
|
|
758
|
+
checkAborted();
|
|
716
759
|
log.error('Failed to persist revoked account removal', {
|
|
717
760
|
error: String(persistError),
|
|
718
761
|
});
|
|
@@ -720,9 +763,10 @@ export function createRequestExecutor(deps) {
|
|
|
720
763
|
}
|
|
721
764
|
if (accountManager.getAccountCount() === 0) {
|
|
722
765
|
try {
|
|
723
|
-
await credentials.clearStoredAuth();
|
|
766
|
+
await deadline.wait(() => credentials.clearStoredAuth());
|
|
724
767
|
}
|
|
725
768
|
catch (storeError) {
|
|
769
|
+
checkAborted();
|
|
726
770
|
log.error('Failed to clear stored Antigravity OAuth credentials', {
|
|
727
771
|
error: String(storeError),
|
|
728
772
|
});
|
|
@@ -763,6 +807,7 @@ export function createRequestExecutor(deps) {
|
|
|
763
807
|
retryState.resetAccountFailureState(account.index);
|
|
764
808
|
}
|
|
765
809
|
catch (error) {
|
|
810
|
+
checkAborted();
|
|
766
811
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
767
812
|
trackers.health.recordFailure(account.index);
|
|
768
813
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -784,10 +829,10 @@ export function createRequestExecutor(deps) {
|
|
|
784
829
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
785
830
|
await assertAdmission();
|
|
786
831
|
if (credentials.domain === 'vault') {
|
|
787
|
-
const admission = await credentials.admit({
|
|
832
|
+
const admission = await deadline.wait(() => credentials.admit({
|
|
788
833
|
account: selected,
|
|
789
834
|
signal: abortSignal,
|
|
790
|
-
});
|
|
835
|
+
}));
|
|
791
836
|
selectedCredentials.add(admission.accessToken);
|
|
792
837
|
if (admission.projectId !== preparedProjectId) {
|
|
793
838
|
throw new Error('The vault served another project for this send; skipping it');
|
|
@@ -799,7 +844,7 @@ export function createRequestExecutor(deps) {
|
|
|
799
844
|
if (!localGrant) {
|
|
800
845
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
801
846
|
}
|
|
802
|
-
await localGrant.captured.check();
|
|
847
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
803
848
|
await assertAdmission();
|
|
804
849
|
return { init: sendInit };
|
|
805
850
|
};
|
|
@@ -841,13 +886,16 @@ export function createRequestExecutor(deps) {
|
|
|
841
886
|
onDebug: pushDebug,
|
|
842
887
|
});
|
|
843
888
|
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();
|
|
889
|
+
const transformed = await deadline.wait(() => wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId));
|
|
890
|
+
await deadline.wait(() => transformed.text());
|
|
846
891
|
warmupState.markSuccess(prepared.sessionId);
|
|
847
892
|
pushDebug('thinking-warmup: done');
|
|
848
893
|
}
|
|
849
894
|
catch (error) {
|
|
850
895
|
warmupState.clearWarmupAttempt(prepared.sessionId);
|
|
896
|
+
if (error instanceof PreResponseTimeoutError)
|
|
897
|
+
throw error;
|
|
898
|
+
checkAborted();
|
|
851
899
|
if (isLocalGrantError(error))
|
|
852
900
|
throw error;
|
|
853
901
|
pushDebug(`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -872,14 +920,14 @@ export function createRequestExecutor(deps) {
|
|
|
872
920
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
873
921
|
if (probeResponse.body) {
|
|
874
922
|
const reader = probeResponse.body.getReader();
|
|
875
|
-
await reader.read();
|
|
876
|
-
await reader.cancel();
|
|
923
|
+
await deadline.wait(() => reader.read());
|
|
924
|
+
await deadline.wait(() => reader.cancel());
|
|
877
925
|
}
|
|
878
926
|
const status = probeResponse.status;
|
|
879
927
|
if (status >= 400) {
|
|
880
928
|
let errorSnippet = '';
|
|
881
929
|
try {
|
|
882
|
-
const errText = await probeResponse.text().catch(() => '');
|
|
930
|
+
const errText = await deadline.wait(() => probeResponse.text().catch(() => ''));
|
|
883
931
|
errorSnippet = errText.slice(0, 200);
|
|
884
932
|
}
|
|
885
933
|
catch {
|
|
@@ -892,6 +940,9 @@ export function createRequestExecutor(deps) {
|
|
|
892
940
|
}
|
|
893
941
|
}
|
|
894
942
|
catch (error) {
|
|
943
|
+
if (error instanceof PreResponseTimeoutError)
|
|
944
|
+
throw error;
|
|
945
|
+
checkAborted();
|
|
895
946
|
if (isLocalGrantError(error)) {
|
|
896
947
|
needsCacheWarmup = true;
|
|
897
948
|
throw error;
|
|
@@ -937,10 +988,10 @@ export function createRequestExecutor(deps) {
|
|
|
937
988
|
// retry it was taken for, then is gone.
|
|
938
989
|
sendAdmission =
|
|
939
990
|
rotatedAdmission ??
|
|
940
|
-
(await credentials.admit({
|
|
991
|
+
(await deadline.wait(() => credentials.admit({
|
|
941
992
|
account,
|
|
942
993
|
signal: abortSignal,
|
|
943
|
-
}));
|
|
994
|
+
})));
|
|
944
995
|
rotatedAdmission = undefined;
|
|
945
996
|
sendAccessToken = sendAdmission.accessToken;
|
|
946
997
|
sendProjectId = sendAdmission.projectId;
|
|
@@ -952,6 +1003,8 @@ export function createRequestExecutor(deps) {
|
|
|
952
1003
|
else {
|
|
953
1004
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
954
1005
|
}
|
|
1006
|
+
if (sendProjectId)
|
|
1007
|
+
selectedProjectIds.add(sendProjectId);
|
|
955
1008
|
selectedCredentials.add(sendAccessToken);
|
|
956
1009
|
const prepared = prepareAgyWireRequest(wire, {
|
|
957
1010
|
input,
|
|
@@ -1005,7 +1058,6 @@ export function createRequestExecutor(deps) {
|
|
|
1005
1058
|
sessionId: prepared.sessionId,
|
|
1006
1059
|
toolDebugMissing: prepared.toolDebugMissing,
|
|
1007
1060
|
toolDebugSummary: prepared.toolDebugSummary,
|
|
1008
|
-
toolDebugPayload: prepared.toolDebugPayload,
|
|
1009
1061
|
dumpContext,
|
|
1010
1062
|
});
|
|
1011
1063
|
await runThinkingWarmup(prepared, sendProjectId);
|
|
@@ -1024,12 +1076,14 @@ export function createRequestExecutor(deps) {
|
|
|
1024
1076
|
if (!localGrant) {
|
|
1025
1077
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
1026
1078
|
}
|
|
1027
|
-
await localGrant.captured.check();
|
|
1079
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
1028
1080
|
await assertAdmission();
|
|
1029
1081
|
}
|
|
1030
1082
|
pushDebug(`dispatching request via ${prepared.headerStyle} transport`);
|
|
1031
1083
|
physicalAttemptStarted = true;
|
|
1032
1084
|
const response = await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug });
|
|
1085
|
+
if (response.ok)
|
|
1086
|
+
deadline.acceptHeaders();
|
|
1033
1087
|
apiRequestCount++;
|
|
1034
1088
|
accountManager.recordRequest(account.index, family);
|
|
1035
1089
|
const requestCounts = accountManager.getDailyRequestCounts(account.index);
|
|
@@ -1046,18 +1100,19 @@ export function createRequestExecutor(deps) {
|
|
|
1046
1100
|
// version of the same credential and account may retry this
|
|
1047
1101
|
// endpoint, once; otherwise the 401 stands.
|
|
1048
1102
|
try {
|
|
1049
|
-
await sendAdmission.report401(response.status);
|
|
1103
|
+
await deadline.wait(() => sendAdmission.report401(response.status));
|
|
1050
1104
|
}
|
|
1051
1105
|
catch (error) {
|
|
1106
|
+
checkAborted();
|
|
1052
1107
|
log.debug('send-admission-401-report-failed', {
|
|
1053
1108
|
error: String(error),
|
|
1054
1109
|
});
|
|
1055
1110
|
}
|
|
1056
1111
|
if (!vault401Retried) {
|
|
1057
|
-
const next = await credentials.admit({
|
|
1112
|
+
const next = await deadline.wait(() => credentials.admit({
|
|
1058
1113
|
account,
|
|
1059
1114
|
signal: abortSignal,
|
|
1060
|
-
});
|
|
1115
|
+
}));
|
|
1061
1116
|
if (next.credentialId === sendAdmission.credentialId &&
|
|
1062
1117
|
next.accountIdentity === sendAdmission.accountIdentity &&
|
|
1063
1118
|
next.recordVersion > sendAdmission.recordVersion) {
|
|
@@ -1096,7 +1151,7 @@ export function createRequestExecutor(deps) {
|
|
|
1096
1151
|
const headerRetryMs = retryAfterMsFromResponse(response, defaultRetryMs);
|
|
1097
1152
|
const bodyInfo = await (async () => {
|
|
1098
1153
|
try {
|
|
1099
|
-
const text = await response.clone().text();
|
|
1154
|
+
const text = await deadline.wait(() => response.clone().text());
|
|
1100
1155
|
try {
|
|
1101
1156
|
return JSON.parse(text);
|
|
1102
1157
|
}
|
|
@@ -1105,6 +1160,7 @@ export function createRequestExecutor(deps) {
|
|
|
1105
1160
|
}
|
|
1106
1161
|
}
|
|
1107
1162
|
catch {
|
|
1163
|
+
checkAborted();
|
|
1108
1164
|
return null;
|
|
1109
1165
|
}
|
|
1110
1166
|
})();
|
|
@@ -1157,7 +1213,7 @@ export function createRequestExecutor(deps) {
|
|
|
1157
1213
|
if (reasonInfo.reason)
|
|
1158
1214
|
pushDebug(`429 reason=${reasonInfo.reason}`);
|
|
1159
1215
|
debug.logRateLimitEvent(account.index, account.email, family, response.status, effectiveDelayMs, reasonInfo);
|
|
1160
|
-
await
|
|
1216
|
+
await logResponseBody(debugContext, response, 429);
|
|
1161
1217
|
trackers.health.recordRateLimit(account.index);
|
|
1162
1218
|
const _accountLabel = account.email || `Account ${account.index + 1}`;
|
|
1163
1219
|
if (backoff.attempt === 1 &&
|
|
@@ -1210,10 +1266,10 @@ export function createRequestExecutor(deps) {
|
|
|
1210
1266
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
1211
1267
|
retryState.resetAccountFailureState(account.index);
|
|
1212
1268
|
if (response.status === 403) {
|
|
1213
|
-
const errorBodyText = await response
|
|
1269
|
+
const errorBodyText = await deadline.wait(() => response
|
|
1214
1270
|
.clone()
|
|
1215
1271
|
.text()
|
|
1216
|
-
.catch(() => '');
|
|
1272
|
+
.catch(() => ''));
|
|
1217
1273
|
const extracted = classifyAccessError(errorBodyText);
|
|
1218
1274
|
if (extracted.accountIneligible) {
|
|
1219
1275
|
const ineligibleReason = extracted.message ??
|
|
@@ -1254,7 +1310,7 @@ export function createRequestExecutor(deps) {
|
|
|
1254
1310
|
response.status >= 500;
|
|
1255
1311
|
if (shouldRetryEndpoint &&
|
|
1256
1312
|
i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
1257
|
-
await
|
|
1313
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1258
1314
|
lastFailure = createFailureContext(response);
|
|
1259
1315
|
continue;
|
|
1260
1316
|
}
|
|
@@ -1297,13 +1353,13 @@ export function createRequestExecutor(deps) {
|
|
|
1297
1353
|
note: response.ok ? 'Success' : `Error ${response.status}`,
|
|
1298
1354
|
});
|
|
1299
1355
|
if (response.ok && !prepared.streaming) {
|
|
1300
|
-
await
|
|
1356
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1301
1357
|
}
|
|
1302
1358
|
if (!response.ok) {
|
|
1303
|
-
await
|
|
1359
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1304
1360
|
if (response.status === 400) {
|
|
1305
1361
|
const cloned = response.clone();
|
|
1306
|
-
const bodyText = await cloned.text();
|
|
1362
|
+
const bodyText = await deadline.wait(() => cloned.text());
|
|
1307
1363
|
if (bodyText.includes('Prompt is too long') ||
|
|
1308
1364
|
bodyText.includes('prompt_too_long')) {
|
|
1309
1365
|
await showToast('Context too long - use /compact to reduce size', 'warning');
|
|
@@ -1318,12 +1374,13 @@ export function createRequestExecutor(deps) {
|
|
|
1318
1374
|
const maxAttempts = config.empty_response_max_attempts ?? 4;
|
|
1319
1375
|
const retryDelayMs = config.empty_response_retry_delay_ms ?? 2000;
|
|
1320
1376
|
const clonedForCheck = response.clone();
|
|
1321
|
-
const bodyText = await clonedForCheck.text();
|
|
1377
|
+
const bodyText = await deadline.wait(() => clonedForCheck.text());
|
|
1322
1378
|
if (isEmptyResponseBody(bodyText)) {
|
|
1323
1379
|
const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1324
1380
|
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
1325
1381
|
pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
|
|
1326
1382
|
if (currentAttempts < maxAttempts) {
|
|
1383
|
+
deadline.resume();
|
|
1327
1384
|
await showToast(`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`, 'warning');
|
|
1328
1385
|
await sleep(retryDelayMs, abortSignal);
|
|
1329
1386
|
continue;
|
|
@@ -1337,7 +1394,7 @@ export function createRequestExecutor(deps) {
|
|
|
1337
1394
|
const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1338
1395
|
retryState.clearEmptyResponseAttempts();
|
|
1339
1396
|
}
|
|
1340
|
-
const transformedResponse = await wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary,
|
|
1397
|
+
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
1398
|
const contextError = transformedResponse.headers.get('x-antigravity-context-error');
|
|
1342
1399
|
if (contextError) {
|
|
1343
1400
|
if (contextError === 'prompt_too_long') {
|
|
@@ -1378,6 +1435,9 @@ export function createRequestExecutor(deps) {
|
|
|
1378
1435
|
return transformedResponse;
|
|
1379
1436
|
}
|
|
1380
1437
|
catch (error) {
|
|
1438
|
+
if (error instanceof PreResponseTimeoutError)
|
|
1439
|
+
throw error;
|
|
1440
|
+
checkAborted();
|
|
1381
1441
|
if (tokenConsumed &&
|
|
1382
1442
|
(!isLocalGrantError(error) || !physicalAttemptStarted)) {
|
|
1383
1443
|
trackers.token.refund(account.index);
|
|
@@ -1393,7 +1453,8 @@ export function createRequestExecutor(deps) {
|
|
|
1393
1453
|
!localRecaptureUsed) {
|
|
1394
1454
|
localRecaptureUsed = true;
|
|
1395
1455
|
try {
|
|
1396
|
-
|
|
1456
|
+
const originalGrant = localGrant.captured;
|
|
1457
|
+
await deadline.wait(() => originalGrant.resolveCurrent());
|
|
1397
1458
|
const auth = credentials.toAuthDetails(account);
|
|
1398
1459
|
if (!auth.access || accessTokenExpired(auth))
|
|
1399
1460
|
return createNativeGoogleErrorResponse({
|
|
@@ -1420,6 +1481,7 @@ export function createRequestExecutor(deps) {
|
|
|
1420
1481
|
if (error instanceof Error &&
|
|
1421
1482
|
error.message === 'THINKING_RECOVERY_NEEDED') {
|
|
1422
1483
|
if (!forceThinkingRecovery) {
|
|
1484
|
+
deadline.resume();
|
|
1423
1485
|
pushDebug('thinking-recovery: API error detected, retrying with forced recovery');
|
|
1424
1486
|
forceThinkingRecovery = true;
|
|
1425
1487
|
i = -1;
|
|
@@ -1464,20 +1526,20 @@ export function createRequestExecutor(deps) {
|
|
|
1464
1526
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
1465
1527
|
pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
|
|
1466
1528
|
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,
|
|
1529
|
+
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
1530
|
}
|
|
1469
1531
|
throw terminalFetchError(lastError, `Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
|
|
1470
1532
|
}
|
|
1471
1533
|
if (accountCount <= 1) {
|
|
1472
1534
|
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,
|
|
1535
|
+
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
1536
|
}
|
|
1475
1537
|
throw terminalFetchError(lastError, 'All Antigravity endpoints failed');
|
|
1476
1538
|
}
|
|
1477
1539
|
continue;
|
|
1478
1540
|
}
|
|
1479
1541
|
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,
|
|
1542
|
+
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
1543
|
}
|
|
1482
1544
|
throw terminalFetchError(lastError, 'All Antigravity accounts failed');
|
|
1483
1545
|
}
|
|
@@ -1519,26 +1581,46 @@ export function createRequestExecutor(deps) {
|
|
|
1519
1581
|
const cancellation = createRequestCancellation(requestedSignal
|
|
1520
1582
|
? [requestedSignal, shutdown.signal]
|
|
1521
1583
|
: [shutdown.signal]);
|
|
1584
|
+
const deadline = new PreResponseDeadline(cancellation.signal, deps.preResponseClock);
|
|
1585
|
+
log.debug('pre-response-start', { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
1586
|
+
const waitPolicy = {};
|
|
1522
1587
|
const selectedCredentials = new Set();
|
|
1523
|
-
const
|
|
1588
|
+
const selectedProjectIds = new Set();
|
|
1589
|
+
const pending = deadline
|
|
1590
|
+
.wait(() => execute(input, { ...init, signal: deadline.signal }, requestOptions ?? {}, selectedCredentials, selectedProjectIds, deadline, waitPolicy))
|
|
1591
|
+
.catch((error) => {
|
|
1592
|
+
cancellation.signal.throwIfAborted();
|
|
1593
|
+
if (error instanceof PreResponseTimeoutError) {
|
|
1594
|
+
log.debug('pre-response-timeout', { reason: error.reason });
|
|
1595
|
+
return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
|
|
1596
|
+
}
|
|
1597
|
+
throw error;
|
|
1598
|
+
})
|
|
1524
1599
|
.then(async (response) => {
|
|
1600
|
+
// Retain caller cancellation over the accepted response body;
|
|
1601
|
+
// only the pre-response timer ends at accepted headers.
|
|
1602
|
+
deadline.acceptTerminalResponse();
|
|
1525
1603
|
// Overflow classification read a clone to EOF. Reuse that text
|
|
1526
1604
|
// for redaction; safe diagnostics retain the original unread response.
|
|
1527
1605
|
if (bufferedOverflow.has(response)) {
|
|
1606
|
+
deadline.dispose();
|
|
1528
1607
|
cancellation.release();
|
|
1529
|
-
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response));
|
|
1608
|
+
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response), [...selectedProjectIds]);
|
|
1530
1609
|
}
|
|
1531
1610
|
const retained = await retainResponseLifetime(response, cancellation);
|
|
1532
1611
|
inFlight.add(retained.settled);
|
|
1533
1612
|
void retained.settled.then(() => inFlight.delete(retained.settled));
|
|
1534
|
-
|
|
1613
|
+
void retained.settled.then(() => deadline.dispose());
|
|
1614
|
+
return redactCredentialResponse(preserveResponseMetadata(retained.response, response), [...selectedCredentials], undefined, [...selectedProjectIds]);
|
|
1535
1615
|
}, (error) => {
|
|
1616
|
+
deadline.dispose();
|
|
1536
1617
|
cancellation.release();
|
|
1537
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1618
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1538
1619
|
})
|
|
1539
1620
|
.catch((error) => {
|
|
1621
|
+
deadline.dispose();
|
|
1540
1622
|
cancellation.release();
|
|
1541
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1623
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1542
1624
|
});
|
|
1543
1625
|
inFlight.add(pending);
|
|
1544
1626
|
void pending.then(() => inFlight.delete(pending), () => inFlight.delete(pending));
|