From 3dab2d2efbf21363f0a998a647d9f67663fed064 Mon Sep 17 00:00:00 2001 From: shuv Date: Tue, 17 Nov 2026 20:11:44 -0800 Subject: [PATCH 1/2] fix(antigravity): fail a bare RESOURCE_EXHAUSTED once when quota is nearly full --- packages/antigravity-plugin/src/wire.ts | 16 +++++++-- .../antigravity-plugin/test/error.test.ts | 35 +++++++++++++++++++ .../test/session-antigravity-error.test.ts | 21 +++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/packages/antigravity-plugin/src/wire.ts b/packages/antigravity-plugin/src/wire.ts index 09b5b71c662d..0528e7d2659e 100644 --- a/packages/antigravity-plugin/src/wire.ts +++ b/packages/antigravity-plugin/src/wire.ts @@ -322,20 +322,32 @@ export function explainCloudCodeError(input: { input.error.reason?.toLowerCase() === "quota_exhausted" || (input.error.status === "RESOURCE_EXHAUSTED" && fiveHour !== undefined && fiveHour.remainingFraction <= 0) || (input.error.status === "RESOURCE_EXHAUSTED" && messageIsLongQuota(input.error.message)) - const headline = + // Cloud Code answers some request content with an instant bare RESOURCE_EXHAUSTED while quota is untouched. + // Retrying sends the same content again, so fail once instead of treating it as a throttle. + const rejected = + !quota && + !input.error.reason && + input.error.status === "RESOURCE_EXHAUSTED" && + fiveHour !== undefined && + fiveHour.remainingFraction >= 0.95 + const status = input.error.status && input.error.message ? `${input.error.status}: ${input.error.message}` : (input.error.status ?? input.error.message ?? "") + const headline = rejected + ? `${status} Quota is nearly full, so this is likely Google rejecting the request content, not quota; not retrying.` + : status const readout = windows.map( (window) => `${window.id} remainingFraction=${JSON.stringify(window.remainingFraction)}${window.resetTime ? ` resetTime=${window.resetTime}` : ""}`, ) const fallbackReset = windows.length === 0 && input.error.resetTime ? [`resetTime=${input.error.resetTime}`] : [] const message = [headline, ...readout, ...fallbackReset].filter((part) => part.length > 0).join(" ") - const reason = quota ? "QUOTA_EXHAUSTED" : input.error.reason + const reason = quota ? "QUOTA_EXHAUSTED" : rejected ? "CONTENT_BLOCKED" : input.error.reason return { message, quota, + rejected, body: JSON.stringify({ error: { code: input.httpStatus, diff --git a/packages/antigravity-plugin/test/error.test.ts b/packages/antigravity-plugin/test/error.test.ts index 33029fb09762..48e5664049c9 100644 --- a/packages/antigravity-plugin/test/error.test.ts +++ b/packages/antigravity-plugin/test/error.test.ts @@ -188,6 +188,41 @@ describe("Cloud Code 429 bodies", () => { ).toBe(true) }) + const fullQuota = (remainingFraction: number) => ({ + groups: [{ displayName: "Gemini models", buckets: [{ window: "5h", remainingFraction, resetTime: reset }] }], + }) + + test("fails a bare RESOURCE_EXHAUSTED once when the model's 5h quota is nearly full", () => { + const explained = GoogleAntigravityWire.explainCloudCodeError({ + error: { status: "RESOURCE_EXHAUSTED", message: "Resource has been exhausted (e.g. check quota)." }, + summary: fullQuota(0.9998), + httpStatus: 429, + modelID: "gemini-3.8-flash-low", + }) + expect(explained?.quota).toBe(false) + expect(explained?.rejected).toBe(true) + expect(explained?.message).toContain("likely Google rejecting the request content, not quota") + expect(explained?.message).toContain("gemini:5h remainingFraction=0.9998") + expect(JSON.parse(explained?.body ?? "{}").error.details).toEqual([ + { "@type": "type.googleapis.com/google.rpc.ErrorInfo", reason: "CONTENT_BLOCKED" }, + ]) + }) + + test.each([ + { name: "an explicit reason", error: { reason: "RATE_LIMIT_EXCEEDED" }, summary: fullQuota(1) }, + { name: "partly used quota", error: {}, summary: fullQuota(0.5) }, + { name: "no quota summary", error: {}, summary: undefined }, + ])("keeps a bare throttle retryable with $name", ({ error, summary }) => { + expect( + GoogleAntigravityWire.explainCloudCodeError({ + error: { status: "RESOURCE_EXHAUSTED", message: "Resource has been exhausted (e.g. check quota).", ...error }, + summary, + httpStatus: 429, + modelID: "gemini-3.8-flash-low", + })?.rejected, + ).toBe(false) + }) + test("ignores success-shaped bodies", () => { expect(GoogleAntigravityWire.parseCloudCodeError('data: {"response":{"candidates":[]}}\n\n')).toBeUndefined() }) diff --git a/packages/core/test/session-antigravity-error.test.ts b/packages/core/test/session-antigravity-error.test.ts index 2ca6058ff9fd..0d52cba683bd 100644 --- a/packages/core/test/session-antigravity-error.test.ts +++ b/packages/core/test/session-antigravity-error.test.ts @@ -127,3 +127,24 @@ for (const modelID of ["gemini-4-argon-high", "gemini-3.8-flash-high"] as const) ) } } + +it.effect("a bare RESOURCE_EXHAUSTED with nearly full quota classifies as a non-retryable content rejection", () => + Effect.sync(() => { + const explained = GoogleAntigravityWire.explainCloudCodeError({ + error: { status: "RESOURCE_EXHAUSTED", message: "Resource has been exhausted (e.g. check quota)." }, + summary: { groups: [{ displayName: "Gemini models", buckets: [{ window: "5h", remainingFraction: 0.9998 }] }] }, + httpStatus: 429, + modelID: "gemini-4-carbon-high", + }) + const error = RequestExecutor.httpFailure({ + message: explained!.body, + url: GoogleAntigravityWire.generateURL, + status: 429, + responseHeaders: { "content-type": "application/json" }, + responseBody: explained!.body, + }) + expect(error.reason._tag).toBe("ContentPolicy") + expect(isRetryable(error)).toBe(false) + expect(error.message).toContain("not quota") + }), +) From cc595daa5a8e5616dd386ffeb989ee19cfaaa54e Mon Sep 17 00:00:00 2001 From: shuv Date: Tue, 17 Nov 2026 20:14:28 -0800 Subject: [PATCH 2/2] fix(antigravity): clarify near-unused quota rejection and keep weekly caps and retry delays out of it --- packages/antigravity-plugin/src/wire.ts | 12 +++++-- .../antigravity-plugin/test/error.test.ts | 34 ++++++++++++++++++- .../test/session-antigravity-error.test.ts | 2 +- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packages/antigravity-plugin/src/wire.ts b/packages/antigravity-plugin/src/wire.ts index 0528e7d2659e..9fce15b88982 100644 --- a/packages/antigravity-plugin/src/wire.ts +++ b/packages/antigravity-plugin/src/wire.ts @@ -267,6 +267,7 @@ export type CloudCodeError = { message?: string reason?: string resetTime?: string + retryDelay?: string } type QuotaWindow = { @@ -324,18 +325,21 @@ export function explainCloudCodeError(input: { (input.error.status === "RESOURCE_EXHAUSTED" && messageIsLongQuota(input.error.message)) // Cloud Code answers some request content with an instant bare RESOURCE_EXHAUSTED while quota is untouched. // Retrying sends the same content again, so fail once instead of treating it as a throttle. + const group = fiveHour ? `${fiveHour.id.split(":")[0]}:` : undefined const rejected = !quota && !input.error.reason && + !input.error.retryDelay && input.error.status === "RESOURCE_EXHAUSTED" && fiveHour !== undefined && - fiveHour.remainingFraction >= 0.95 + fiveHour.remainingFraction >= 0.95 && + windows.every((window) => !window.id.startsWith(group ?? "") || window.remainingFraction > 0) const status = input.error.status && input.error.message ? `${input.error.status}: ${input.error.message}` : (input.error.status ?? input.error.message ?? "") const headline = rejected - ? `${status} Quota is nearly full, so this is likely Google rejecting the request content, not quota; not retrying.` + ? `${status} This is likely not quota: at least 95% of this model's quota is unused, so Google probably rejected this request's content. Not retrying; changing the prompt or switching models may help.` : status const readout = windows.map( (window) => @@ -382,6 +386,7 @@ function cloudCodeError(text: string): CloudCodeError | undefined { ...(message ? { message } : {}), ...(details.reason ? { reason: details.reason } : {}), ...(details.resetTime ? { resetTime: details.resetTime } : {}), + ...(details.retryDelay ? { retryDelay: details.retryDelay } : {}), } } @@ -397,7 +402,7 @@ function nestedGoogleError(message: string) { function errorDetails(error: Record | undefined) { const details = error && Array.isArray(error.details) ? error.details : [] - return details.reduce<{ reason?: string; resetTime?: string }>((acc, detail) => { + return details.reduce<{ reason?: string; resetTime?: string; retryDelay?: string }>((acc, detail) => { if (!isRecord(detail)) return acc const metadata = isRecord(detail.metadata) ? detail.metadata : undefined return { @@ -407,6 +412,7 @@ function errorDetails(error: Record | undefined) { textField(metadata?.quotaResetTimeStamp) ?? textField(metadata?.quotaResetTimestamp) ?? textField(metadata?.resetTime), + retryDelay: acc.retryDelay ?? textField(detail.retryDelay), } }, {}) } diff --git a/packages/antigravity-plugin/test/error.test.ts b/packages/antigravity-plugin/test/error.test.ts index 48e5664049c9..2f4d268a5d08 100644 --- a/packages/antigravity-plugin/test/error.test.ts +++ b/packages/antigravity-plugin/test/error.test.ts @@ -201,17 +201,49 @@ describe("Cloud Code 429 bodies", () => { }) expect(explained?.quota).toBe(false) expect(explained?.rejected).toBe(true) - expect(explained?.message).toContain("likely Google rejecting the request content, not quota") + expect(explained?.message).toContain("likely not quota: at least 95% of this model's quota is unused") expect(explained?.message).toContain("gemini:5h remainingFraction=0.9998") expect(JSON.parse(explained?.body ?? "{}").error.details).toEqual([ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", reason: "CONTENT_BLOCKED" }, ]) }) + test.each([ + { modelID: "gemini-3.8-flash-low", group: "Gemini models", fraction: 0.95, rejected: true }, + { modelID: "claude-sonnet-4-6", group: "Claude + GPT", fraction: 1, rejected: true }, + { modelID: "claude-sonnet-4-6", group: "Gemini models", fraction: 1, rejected: false }, + ])("reads the failed model's own group for $modelID", ({ modelID, group, fraction, rejected }) => { + expect( + GoogleAntigravityWire.explainCloudCodeError({ + error: { status: "RESOURCE_EXHAUSTED", message: "Resource has been exhausted (e.g. check quota)." }, + summary: { groups: [{ displayName: group, buckets: [{ window: "5h", remainingFraction: fraction }] }] }, + httpStatus: 429, + modelID, + })?.rejected, + ).toBe(rejected) + }) + test.each([ { name: "an explicit reason", error: { reason: "RATE_LIMIT_EXCEEDED" }, summary: fullQuota(1) }, { name: "partly used quota", error: {}, summary: fullQuota(0.5) }, { name: "no quota summary", error: {}, summary: undefined }, + { name: "a retry delay", error: { retryDelay: "30s" }, summary: fullQuota(1) }, + { name: "5h just under the threshold", error: {}, summary: fullQuota(0.9499) }, + { + name: "an exhausted weekly window", + error: {}, + summary: { + groups: [ + { + displayName: "Gemini models", + buckets: [ + { window: "5h", remainingFraction: 1 }, + { window: "weekly", remainingFraction: 0 }, + ], + }, + ], + }, + }, ])("keeps a bare throttle retryable with $name", ({ error, summary }) => { expect( GoogleAntigravityWire.explainCloudCodeError({ diff --git a/packages/core/test/session-antigravity-error.test.ts b/packages/core/test/session-antigravity-error.test.ts index 0d52cba683bd..43623844ccb1 100644 --- a/packages/core/test/session-antigravity-error.test.ts +++ b/packages/core/test/session-antigravity-error.test.ts @@ -145,6 +145,6 @@ it.effect("a bare RESOURCE_EXHAUSTED with nearly full quota classifies as a non- }) expect(error.reason._tag).toBe("ContentPolicy") expect(isRetryable(error)).toBe(false) - expect(error.message).toContain("not quota") + expect(error.message).toContain("likely not quota") }), )