Skip to content
Merged
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
20 changes: 18 additions & 2 deletions apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ const errorPayload = (error: string) =>
`Agent execution terminated due to error.\u0012agent executor error: ${error}: ${error}\n(1) attached stack trace\n -- stack trace:`,
),
]);
// An unparsable reset timestamp must not hide the reset delay.
// An unparsable reset timestamp must not hide the reset delay, nor a retry delay outrank it.
const QUOTA_ERROR = errorPayload(
"Error 429, Message: Quota exhausted for test model., Status: RESOURCE_EXHAUSTED, Details: [map[@type:type.googleapis.com/google.rpc.ErrorInfo domain:googleapis.com metadata:map[quotaResetDelay:3600s quotaResetTimeStamp:soon] reason:QUOTA_EXHAUSTED]]",
"Error 429, Message: Quota exhausted for test model., Status: RESOURCE_EXHAUSTED, Details: [map[@type:type.googleapis.com/google.rpc.RetryInfo retryDelay:42s] map[@type:type.googleapis.com/google.rpc.ErrorInfo domain:googleapis.com metadata:map[quotaResetDelay:3600s quotaResetTimeStamp:soon] reason:QUOTA_EXHAUSTED]]",
);
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]]",
);
const INVALID_ARGUMENT_ERROR = errorPayload(
"Error 400, Message: Request contains an invalid argument., Status: INVALID_ARGUMENT, Details: []",
Expand Down Expand Up @@ -101,6 +104,19 @@ describe("watchAntigravityPromptOutcome", () => {
},
),
);
assert.deepEqual(
yield* turn([
[USER_INPUT, input],
[ERROR_MESSAGE, RATE_LIMIT_ERROR],
]),
{
class: "usage_limit",
message: "Resource has been exhausted (e.g. check quota).",
code: "RESOURCE_EXHAUSTED",
retryable: true,
resetAt: "1970-01-01T00:00:42.000Z",
},
);
assert.deepEqual(
yield* turn([
[USER_INPUT, input],
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/provider/acp/AntigravityTurnOutcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const API_ERROR = /Error (\d{3}), Message: (.+?), Status: ([A-Z_]+)/s;
const QUOTA_EXHAUSTED = /\breason:QUOTA_EXHAUSTED\b/;
const RESET_TIMESTAMP = /\bquotaResetTimeStamp:([^\s\]]+)/;
const RESET_DELAY = /\bquotaResetDelay:((?:\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 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 @@ -76,7 +78,7 @@ function resetAtFrom(text: string, now: DateTime.Utc): string | undefined {
// makeProviderFailure drops a timestamp that does not parse, so fall back to the delay.
const timestamp = RESET_TIMESTAMP.exec(text)?.[1];
if (timestamp !== undefined && Option.isSome(DateTime.make(timestamp))) return timestamp;
const delay = RESET_DELAY.exec(text)?.[1];
const delay = RESET_DELAY.exec(text)?.[1] ?? RETRY_DELAY.exec(text)?.[1];
if (delay === undefined) return undefined;
let delayMs = 0;
for (const [, amount, unit] of delay.matchAll(GO_DURATION_PART)) {
Expand Down Expand Up @@ -120,6 +122,7 @@ function turnFailure(
message: message!.trim(),
code: status ?? null,
retryable: rateLimited || Number(httpStatus) >= 500,
resetAt: resetAtFrom(text, now) ?? null,
});
}

Expand Down
Loading