fix(antigravity): retry transient upstream failures
Retry short-lived 5xx/capacity errors (500/502/503/504 + message patterns) with bounded backoff capped at 15s; honor Retry-After/reset hints and skip when wait is too long. Keep 400 non-retryable. Enable the retry hook for 500 alongside existing 429/503. Deduplicate sanitized Antigravity tool names before emitting the single functionDeclarations group to avoid upstream "Tool names must be unique" rejections. Add Headroom size diagnostics and phantom-savings warning when reported token delta does not shrink the outbound payload. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
parent
2deacf69b1
commit
639f1204d0
@@ -32,8 +32,38 @@ describe("antigravity computeRetryDelay hook (D3)", () => {
|
||||
expect(await ag.computeRetryDelay(res(429), 3)).toBe(Math.min(1000 * 2 ** 3, MAX));
|
||||
});
|
||||
|
||||
it("503 without retry info → veto (no auto backoff)", async () => {
|
||||
expect(await ag.computeRetryDelay(res(503), 1)).toBe(false);
|
||||
it("503 without retry info → transient backoff", async () => {
|
||||
expect(await ag.computeRetryDelay(res(503), 1)).toBe(2000);
|
||||
});
|
||||
|
||||
it("retries Antigravity agent terminated body even when status is not 429", async () => {
|
||||
const r = res(500, {}, { error: { message: "Agent execution terminated due to error" } });
|
||||
expect(await ag.computeRetryDelay(r, 1)).toBe(2000);
|
||||
});
|
||||
|
||||
it("retries high traffic body", async () => {
|
||||
const r = res(500, {}, { error: { message: "Our servers are experiencing high traffic" } });
|
||||
expect(await ag.computeRetryDelay(r, 2)).toBe(4000);
|
||||
});
|
||||
|
||||
it("does not retry non-transient 400 errors", async () => {
|
||||
const r = res(400, {}, { error: { message: "Invalid request" } });
|
||||
expect(await ag.computeRetryDelay(r, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("deduplicates sanitized tool names", () => {
|
||||
const out = ag.transformRequest("claude-opus-4-6-thinking", {
|
||||
request: {
|
||||
contents: [{ role: "user", parts: [{ text: "hi" }] }],
|
||||
tools: [{ functionDeclarations: [
|
||||
{ name: "read/file", parameters: { type: "object", properties: {} } },
|
||||
{ name: "read file", parameters: { type: "object", properties: {} } },
|
||||
{ name: "read/file", parameters: { type: "object", properties: {} } },
|
||||
] }],
|
||||
},
|
||||
}, true, { projectId: "project-1", connectionId: "conn-1" });
|
||||
|
||||
expect(out.request.tools[0].functionDeclarations.map(fn => fn.name)).toEqual(["read_file"]);
|
||||
});
|
||||
|
||||
it("buildHeaders includes cached session id after transformRequest", () => {
|
||||
|
||||
@@ -85,6 +85,16 @@ describe("BaseExecutor.execute — network error retry/fallback", () => {
|
||||
});
|
||||
|
||||
describe("BaseExecutor.execute — computeRetryDelay hook veto", () => {
|
||||
it("only invokes computeRetryDelay when status has retry config", async () => {
|
||||
const ex = makeExec({ baseUrl: "https://x/api", retry: { 503: { attempts: 1, delayMs: 0 } } });
|
||||
ex.computeRetryDelay = vi.fn().mockResolvedValue(0);
|
||||
fetchMock.mockResolvedValueOnce(res(500));
|
||||
const out = await ex.execute({ model: "m", body: {}, stream: false, credentials: creds });
|
||||
expect(out.response.status).toBe(500);
|
||||
expect(ex.computeRetryDelay).not.toHaveBeenCalled();
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("hook returning false skips retry (uses fallback path)", async () => {
|
||||
const ex = makeExec({ baseUrl: "https://x/api", retry: { 429: { attempts: 5, delayMs: 0 } } });
|
||||
ex.computeRetryDelay = vi.fn().mockResolvedValue(false);
|
||||
|
||||
Reference in New Issue
Block a user