@@ -36,8 +36,6 @@ const SUMMARY_WINDOW_MINS = new Map([ |
36 | 36 | const MANUAL_REDIRECT: RequestInit = { redirect: "manual" }; |
37 | 37 | const CLI_RENEWAL_TIMEOUT = "30 seconds"; |
38 | 38 | const CLI_RENEWAL_BACKOFF_MS = [60_000, 5 * 60_000, 15 * 60_000, 60 * 60_000] as const; |
39 | | -const CLI_EXPIRED_MESSAGE = |
40 | | - "Antigravity's saved sign-in has expired. Start an Antigravity turn to renew it, then refresh limits."; |
41 | 39 |
|
42 | 40 | export type AntigravityCliTokenRenewalResult = "renewed" | "busy" | "failed"; |
43 | 41 | const TokenFile = Schema.Struct({ |
@@ -407,6 +405,12 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( |
407 | 405 | } |
408 | 406 | let { token } = yield* decodeCliToken(stored); |
409 | 407 | if (!(Date.parse(token.expiry ?? "") > now + 60_000)) { |
| 408 | + const expired = makeUnavailableUsageLimits({ |
| 409 | + checkedAt, |
| 410 | + reason: "probeFailed", |
| 411 | + message: |
| 412 | + "Antigravity's saved sign-in has expired. Start an Antigravity turn to renew it, then refresh limits.", |
| 413 | + }); |
410 | 414 | const storedHash = yield* sha256(stored); |
411 | 415 | const blocked = |
412 | 416 | renewalBackoff?.storedHash === storedHash && now < renewalBackoff.retryAfter; |
@@ -416,40 +420,24 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( |
416 | 420 | Boolean(token.refresh_token?.trim()) && |
417 | 421 | !blocked; |
418 | 422 | if (!canRenew) { |
419 | | - return makeUnavailableUsageLimits({ |
420 | | - checkedAt, |
421 | | - reason: "probeFailed", |
422 | | - message: CLI_EXPIRED_MESSAGE, |
423 | | - }); |
| 423 | + return expired; |
424 | 424 | } |
425 | 425 | const outcome = yield* input.renewCliToken.pipe( |
426 | 426 | Effect.timeoutOption(CLI_RENEWAL_TIMEOUT), |
427 | 427 | Effect.map((result) => Option.getOrElse(result, () => "failed" as const)), |
428 | 428 | ); |
429 | 429 | if (generation !== startedGeneration) { |
430 | | - return makeUnavailableUsageLimits({ |
431 | | - checkedAt, |
432 | | - reason: "probeFailed", |
433 | | - message: CLI_EXPIRED_MESSAGE, |
434 | | - }); |
| 430 | + return expired; |
435 | 431 | } |
436 | 432 | if (outcome !== "renewed") { |
437 | 433 | if (outcome !== "busy") { |
438 | 434 | recordRenewalFailure(startedGeneration, storedHash, yield* Clock.currentTimeMillis); |
439 | 435 | } |
440 | | - return makeUnavailableUsageLimits({ |
441 | | - checkedAt, |
442 | | - reason: "probeFailed", |
443 | | - message: CLI_EXPIRED_MESSAGE, |
444 | | - }); |
| 436 | + return expired; |
445 | 437 | } |
446 | 438 | const refreshedStored = yield* readStoredCliToken; |
447 | 439 | if (generation !== startedGeneration) { |
448 | | - return makeUnavailableUsageLimits({ |
449 | | - checkedAt, |
450 | | - reason: "probeFailed", |
451 | | - message: CLI_EXPIRED_MESSAGE, |
452 | | - }); |
| 440 | + return expired; |
453 | 441 | } |
454 | 442 | if (refreshedStored === undefined) { |
455 | 443 | return makeUnavailableUsageLimits({ |
@@ -463,11 +451,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( |
463 | 451 | if (!(Date.parse(refreshed.token.expiry ?? "") > renewedAt + 60_000)) { |
464 | 452 | const refreshedHash = yield* sha256(refreshedStored); |
465 | 453 | recordRenewalFailure(startedGeneration, refreshedHash, renewedAt, storedHash); |
466 | | - return makeUnavailableUsageLimits({ |
467 | | - checkedAt, |
468 | | - reason: "probeFailed", |
469 | | - message: CLI_EXPIRED_MESSAGE, |
470 | | - }); |
| 454 | + return expired; |
471 | 455 | } |
472 | 456 | if (generation === startedGeneration) renewalBackoff = undefined; |
473 | 457 | token = refreshed.token; |
|