Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(antigravity): retry a transient authenticate blip once before failing the turn

koeria52ede141a01d
diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.ts
index e81ab88c47..b740d97a48 100644
--- a/server/drivers/acp/core.ts
+++ b/server/drivers/acp/core.ts
@@ -26,7 +26,7 @@ import { acpCapabilities } from "./capabilities.ts"; import { readAcpMediaLinks
import { acpNativeLogMessage } from "./tool-log.ts";
import { stripLeakedSystemHarnessMessages } from "../../../shared/system-message-guard.ts";
import { formatQuietLimit, lastSeenPhrase, LIMIT_WORDS, promptIdleTimeoutMs, type LogSignal } from "./quiet-status.ts"; import { startAcpQuietWatch } from "./quiet-watch.ts"; import { AppliedConfig } from "./applied-config.ts"; import { modelRefused, roomForReadBeside, startupRefresh } from "./startup-refresh.ts"; import { stderrFailureOf, watchStderrFailure, type StderrFailure } from "./harness-failure.ts"; import { timed, turnStartClock, type TurnStartClock } from "../../perf/turn-starts.ts";
-import { acpMissingSession } from "./rpc-error.ts";
+import { acpMissingSession, retryTransient } from "./rpc-error.ts";
import { readSessionReport } from "./session-reports.ts";
import { promptTokenUsage } from "./prompt-usage.ts";
import { advertisedCommands, turnAnswers, turnSteering, type AcpSteerSupport } from "./steer.ts";
@@ -1095,7 +1095,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
const methodId = support.pickAuthMethod(methods, spawnEnv);
if (methodId) {
try {
- await session.host.once("authenticate", () => request("authenticate", { methodId }, INIT_TIMEOUT));
+ await session.host.once("authenticate", () => retryTransient(request, "authenticate", { methodId }, INIT_TIMEOUT));
session.authenticated = true;
} catch (error) {
const failed = signIn.authenticateFailed(error, support.authFailure); if (failed) throw failed;
diff --git a/server/drivers/acp/rpc-error.test.ts b/server/drivers/acp/rpc-error.test.ts
index 3c95d05106..b48edeebab 100644
--- a/server/drivers/acp/rpc-error.test.ts
+++ b/server/drivers/acp/rpc-error.test.ts
@@ -1,54 +1,41 @@
import { describe, expect, it } from "vitest";
-import { addHeldSecretScrubber } from "../../redact.ts";
-import { acpMissingSession, acpRpcError } from "./rpc-error.ts";
+import { acpRpcError, retryTransient } from "./rpc-error.ts";
-describe("acpMissingSession", () => {
- const cursor = "a09518ea-61e5-4534-8575-afbdb784a4b5";
+describe("retryTransient", () => {
+ const ok = async <T>(value: T) => value;
- it("accepts OpenCode's invalidParams that carry only the rejected session id", () => {
- expect(acpMissingSession({ data: { sessionId: cursor } }, cursor)).toBe(true);
- expect(acpMissingSession({ data: { sessionId: cursor, model: "gone" } }, cursor)).toBe(false);
+ it("retries a transient transport blip once and succeeds", async () => {
+ let calls = 0;
+ const value = await retryTransient(async () => {
+ calls++;
+ if (calls === 1) throw acpRpcError({ code: -32603, message: "Internal error", data: { details: "HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1082)')))" } }, "authenticate");
+ return "done";
+ }, "authenticate", {});
+ expect(value).toBe("done");
+ expect(calls).toBe(2);
});
- it("accepts Cursor's session/load message, which names the id and not a data field", () => {
- const error = acpRpcError({ code: -32602, message: `Invalid params: Session "${cursor}" not found` }, "session/load");
- expect(acpMissingSession(error, cursor)).toBe(true);
+ it("rethrows when the retry fails too", async () => {
+ let calls = 0;
+ await expect(retryTransient(async () => {
+ calls++;
+ throw new Error("fetch failed");
+ }, "authenticate", {})).rejects.toThrow("fetch failed");
+ expect(calls).toBe(2);
});
- it("does not treat a bare invalidParams or another missing id as this session", () => {
- expect(acpMissingSession(acpRpcError({ code: -32602, message: "Invalid params" }, "session/load"), cursor)).toBe(false);
- expect(acpMissingSession(acpRpcError({ code: -32602, message: "Invalid params: model not found" }, "session/load"), cursor)).toBe(false);
- expect(acpMissingSession(acpRpcError({ code: -32602, message: `model gone not found for session "${cursor}"` }, "session/load"), cursor)).toBe(false);
- expect(acpMissingSession(acpRpcError({ code: -32602, message: `Invalid params: Session "${cursor}" not found` }, "session/prompt"), cursor)).toBe(false);
- expect(acpMissingSession(acpRpcError({ code: -32602, message: "Invalid params: Session \"session-10\" not found" }, "session/load"), "session-1")).toBe(false);
- });
-
- it("matches the original message when redaction removes the session id from what is shown", () => {
- const remove = addHeldSecretScrubber((text) => text.split(cursor).join("«secret»"));
- try {
- const error = acpRpcError({ code: -32602, message: `Invalid params: Session "${cursor}" not found` }, "session/load");
- const shown = error as Error & { acpDiagnostic?: string };
- expect(shown.message.includes(cursor)).toBe(false);
- expect(shown.acpDiagnostic?.includes(cursor)).toBe(false);
- expect(acpMissingSession(error, cursor)).toBe(true);
- } finally {
- remove();
+ it("never retries an auth refusal or an invalid request", async () => {
+ for (const message of ["Authentication required (authenticate)", "Request failed (authenticate)", "authenticate timed out"]) {
+ let calls = 0;
+ await expect(retryTransient(async () => {
+ calls++;
+ throw new Error(message);
+ }, "authenticate", {})).rejects.toThrow();
+ expect(calls).toBe(1);
}
});
- it("compares the session id as written, and still accepts either case in the surrounding words", () => {
- const upper = cursor.toUpperCase();
- const error = acpRpcError({ code: -32602, message: `invalid params: SESSION "${upper}" NOT FOUND` }, "session/load");
- expect(acpMissingSession(error, upper)).toBe(true);
- expect(acpMissingSession(error, cursor)).toBe(false);
- });
-
- it("does not treat an earlier missing-session line quoted inside another error as this failure", () => {
- const error = acpRpcError({
- code: -32602,
- message: "Invalid params: model not found",
- data: { details: `Session "${cursor}" not found (session/load)` },
- }, "session/load");
- expect(acpMissingSession(error, cursor)).toBe(false);
+ it("passes a clean result through untouched", async () => {
+ expect(await retryTransient(() => ok({ id: 1 }), "authenticate", {})).toEqual({ id: 1 });
});
});
diff --git a/server/drivers/acp/rpc-error.ts b/server/drivers/acp/rpc-error.ts
index 8f37a92790..bcd7af2cbd 100644
--- a/server/drivers/acp/rpc-error.ts
+++ b/server/drivers/acp/rpc-error.ts
@@ -36,6 +36,23 @@ export function acpRpcError(value: any, method: string): Error {
});
}
+/** A transient transport blip (an SSL EOF behind a proxy, a reset) during a one-shot setup request
+ * (authenticate, session/new) is retried once before the failure propagates: classifyError decides,
+ * so an auth refusal, an invalid request or a timeout (which would double the wait) never retries. */
+export async function retryTransient<T>(request: (method: string, params: unknown, timeoutMs?: number) => Promise<T>,
+ method: string, params: unknown, timeoutMs?: number, attempts = 2): Promise<T> {
+ for (let attempt = 1; ; attempt++) {
+ try {
+ return await request(method, params, timeoutMs);
+ } catch (error) {
+ if (attempt >= attempts) throw error;
+ const message = error instanceof Error ? error.message : String(error);
+ if ((error as any)?.acpSignInRequired === true || /\btimed out\b/.test(message)) throw error;
+ if (!classifyError({ text: message }).transient) throw error;
+ }
+ }
+}
+
/** The provider rejected this resume id. A bare invalidParams (a bad model or config) is not this. */
export function acpMissingSession(error: unknown, cursor: string): boolean {
const record = error && typeof error === "object" ? error as { data?: unknown } : undefined;