Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []",
);
Expand Down Expand Up @@ -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],
Expand Down
14 changes: 9 additions & 5 deletions apps/server/src/provider/acp/AntigravityTurnOutcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> = {
ns: 1e-6,
Expand Down Expand Up @@ -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)) {
Expand Down
Loading