diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts index eb0695948b30c..a08de9e8760ed 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts @@ -30,6 +30,34 @@ const QUOTA_ERROR = errorPayload( const RATE_LIMIT_ERROR = errorPayload( "Error 429, Message: Resource has been exhausted (e.g. check quota)., Status: RESOURCE_EXHAUSTED, Details: [map[@type:type.googleapis.com/google.rpc.ErrorInfo domain:cloudcode-pa.googleapis.com reason:RATE_LIMIT_EXCEEDED] map[@type:type.googleapis.com/google.rpc.RetryInfo retryDelay:42s]]", ); +// Antigravity 1.5 writes "STATUS (code NNN): message", protobuf bytes, then Google's JSON body. +const JSON_QUOTA_ERROR = Buffer.concat([ + Buffer.from([0x12, 0x86, 0x01]), + Buffer.from( + "RESOURCE_EXHAUSTED (code 429): Individual quota reached. Resets in 2h24m51s.\u001a«\tHTTP 429 Too Many Requests\n\n" + + JSON.stringify( + { + error: { + code: 429, + details: [ + { + "@type": "type.googleapis.com/google.rpc.ErrorInfo", + metadata: { + quotaResetDelay: "2h24m51.361888584s", + quotaResetTimeStamp: "2026-11-19T18:33:55Z", + }, + reason: "QUOTA_EXHAUSTED", + }, + { "@type": "type.googleapis.com/google.rpc.RetryInfo", retryDelay: "8691.36s" }, + ], + status: "RESOURCE_EXHAUSTED", + }, + }, + null, + 2, + ), + ), +]); const INVALID_ARGUMENT_ERROR = errorPayload( "Error 400, Message: Request contains an invalid argument., Status: INVALID_ARGUMENT, Details: []", ); @@ -127,6 +155,19 @@ describe("watchAntigravityPromptOutcome", () => { resetAt: "1970-01-01T00:00:42.000Z", }), ); + assert.deepEqual( + yield* turn([ + [USER_INPUT, input], + [ERROR_MESSAGE, JSON_QUOTA_ERROR], + ]), + reusable({ + class: "usage_limit", + message: "You have reached your Antigravity quota for this period.", + code: "RESOURCE_EXHAUSTED", + retryable: true, + resetAt: "2026-11-19T18:33:55.000Z", + }), + ); assert.deepEqual( yield* turn([ [USER_INPUT, input], diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts index 2cbe4d62b3a4b..9320613395b6e 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts @@ -19,15 +19,19 @@ const ERROR_STEP_TYPE = 17; const MAX_ERROR_PAYLOAD_BYTES = 16_384; // The Go harness's rendering of a Google API error, as the agent's api_errors.py reads it. const API_ERROR = /Error (\d{3}), Message: (.+?), Status: ([A-Z_]+)/s; -const QUOTA_EXHAUSTED = /\breason:QUOTA_EXHAUSTED\b/; +// 1.5 writes "STATUS (code NNN): message" and the JSON body; groups keep API_ERROR's order. +const STATUS_ERROR = /\b(?=[A-Z_]+ \(code (\d{3})\): (\P{Cc}+))([A-Z_]+)/u; +// The Go map renders `key:value`; the JSON body renders `"key": "value"`. +const QUOTA_EXHAUSTED = /\breason"?:\s*"?QUOTA_EXHAUSTED\b/; // Claude rejects a saved thinking block without a valid signature. It sits in the native // history, so every later prompt to that session fails the same way. const INVALID_THINKING_SIGNATURE = /\bmessages\.\d+\.content\.\d+(?:\.thinking\.signature: Field required|: Invalid `signature` in `thinking` block)/; -const RESET_TIMESTAMP = /\bquotaResetTimeStamp:([^\s\]]+)/; -const RESET_DELAY = /\bquotaResetDelay:((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]])/; +const RESET_TIMESTAMP = /\bquotaResetTimeStamp"?:\s*"?([^\s\]",]+)/; +const RESET_DELAY = + /\bquotaResetDelay"?:\s*"?((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]"])/; // google.rpc.RetryInfo, which plain rate limits carry instead of a quota reset. -const RETRY_DELAY = /\bretryDelay:((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]])/; +const RETRY_DELAY = /\bretryDelay"?:\s*"?((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]"])/; const GO_DURATION_PART = /(\d+(?:\.\d+)?)(ns|us|µs|μs|ms|h|m|s)/g; const GO_DURATION_UNIT_MS: Record = { ns: 1e-6, @@ -123,7 +127,7 @@ function turnFailure( // The agent maps only the SDK's QUOTA_EXHAUSTED stop reason to `refusal`. if (errorText === undefined && stopReason !== "refusal") return undefined; const text = errorText ?? ""; - const apiError = API_ERROR.exec(text); + const apiError = API_ERROR.exec(text) ?? STATUS_ERROR.exec(text); const reusable = (failure: OrchestrationV2ProviderFailure) => ({ failure, threadDisposition: "reusable" }) as const; if (stopReason === "refusal" || QUOTA_EXHAUSTED.test(text)) {