Skip to content

Commit 7c22e24

Browse files
saphidclaude
andauthored
fix(antigravity): rate-limited turns keep their reset time (pingdotgg#29594)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b183048 commit 7c22e24

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ const errorPayload = (error: string) =>
2222
`Agent execution terminated due to error.\u0012agent executor error: ${error}: ${error}\n(1) attached stack trace\n -- stack trace:`,
2323
),
2424
]);
25-
// An unparsable reset timestamp must not hide the reset delay.
25+
// An unparsable reset timestamp must not hide the reset delay, nor a retry delay outrank it.
2626
const QUOTA_ERROR = errorPayload(
27-
"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]]",
27+
"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]]",
28+
);
29+
const RATE_LIMIT_ERROR = errorPayload(
30+
"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]]",
2831
);
2932
const INVALID_ARGUMENT_ERROR = errorPayload(
3033
"Error 400, Message: Request contains an invalid argument., Status: INVALID_ARGUMENT, Details: []",
@@ -101,6 +104,19 @@ describe("watchAntigravityPromptOutcome", () => {
101104
},
102105
),
103106
);
107+
assert.deepEqual(
108+
yield* turn([
109+
[USER_INPUT, input],
110+
[ERROR_MESSAGE, RATE_LIMIT_ERROR],
111+
]),
112+
{
113+
class: "usage_limit",
114+
message: "Resource has been exhausted (e.g. check quota).",
115+
code: "RESOURCE_EXHAUSTED",
116+
retryable: true,
117+
resetAt: "1970-01-01T00:00:42.000Z",
118+
},
119+
);
104120
assert.deepEqual(
105121
yield* turn([
106122
[USER_INPUT, input],

‎apps/server/src/provider/acp/AntigravityTurnOutcome.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const API_ERROR = /Error (\d{3}), Message: (.+?), Status: ([A-Z_]+)/s;
2121
const QUOTA_EXHAUSTED = /\breason:QUOTA_EXHAUSTED\b/;
2222
const RESET_TIMESTAMP = /\bquotaResetTimeStamp:([^\s\]]+)/;
2323
const RESET_DELAY = /\bquotaResetDelay:((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]])/;
24+
// google.rpc.RetryInfo, which plain rate limits carry instead of a quota reset.
25+
const RETRY_DELAY = /\bretryDelay:((?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|h|m|s))+)(?=[\s\]])/;
2426
const GO_DURATION_PART = /(\d+(?:\.\d+)?)(ns|us|µs|μs|ms|h|m|s)/g;
2527
const GO_DURATION_UNIT_MS: Record<string, number> = {
2628
ns: 1e-6,
@@ -76,7 +78,7 @@ function resetAtFrom(text: string, now: DateTime.Utc): string | undefined {
7678
// makeProviderFailure drops a timestamp that does not parse, so fall back to the delay.
7779
const timestamp = RESET_TIMESTAMP.exec(text)?.[1];
7880
if (timestamp !== undefined && Option.isSome(DateTime.make(timestamp))) return timestamp;
79-
const delay = RESET_DELAY.exec(text)?.[1];
81+
const delay = RESET_DELAY.exec(text)?.[1] ?? RETRY_DELAY.exec(text)?.[1];
8082
if (delay === undefined) return undefined;
8183
let delayMs = 0;
8284
for (const [, amount, unit] of delay.matchAll(GO_DURATION_PART)) {
@@ -120,6 +122,7 @@ function turnFailure(
120122
message: message!.trim(),
121123
code: status ?? null,
122124
retryable: rateLimited || Number(httpStatus) >= 500,
125+
resetAt: resetAtFrom(text, now) ?? null,
123126
});
124127
}
125128

0 commit comments

Comments
 (0)