Skip to content

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

fix(antigravity): start a fresh session when Google cannot decode a media part

AdityaUmalef44b41d31a55
diff --git a/server/drivers/acp/turn-health.test.ts b/server/drivers/acp/turn-health.test.ts
index c7a7d907dc..1778189e4d 100644
--- a/server/drivers/acp/turn-health.test.ts
+++ b/server/drivers/acp/turn-health.test.ts
@@ -8,7 +8,7 @@ import { afterEach, describe, expect, it } from "vitest";
import type { ProviderInstance } from "../../contracts.ts";
import { recordEvents } from "../../testing/events.ts";
import { removeTempDir } from "../../testing/cleanup.ts";
-import { antigravityHarnessLimit } from "../antigravity-turn-outcome.ts";
+import { antigravityHarnessFailure } from "../antigravity-turn-outcome.ts";
import { ANTIGRAVITY_SESSION_SETUP_TIMEOUT_MS } from "../antigravity.ts";
import { createAcpDriver, type AcpSupport } from "./core.ts";
import { ANTIGRAVITY_HARNESS_FAILURE_LOG } from "./harness-failure.ts";
@@ -93,7 +93,7 @@ describe("an agent whose own log says its local harness failed", () => {
+ "Error 429, Message: Quota exhausted., Status: RESOURCE_EXHAUSTED, Details: [map[metadata:map[quotaResetDelay:38m0s] reason:QUOTA_EXHAUSTED]]";
const driver = createAcpDriver({
...SUPPORT,
- stderrFailure: { line: ANTIGRAVITY_HARNESS_FAILURE_LOG, message: "The local agent connection failed.", failure: (line) => antigravityHarnessLimit("Turn Health Test", line) },
+ stderrFailure: { line: ANTIGRAVITY_HARNESS_FAILURE_LOG, message: "The local agent connection failed.", failure: (line) => antigravityHarnessFailure("Turn Health Test", line) },
});
instance = await driver.create({
instanceId: "turn-health-quota", displayName: "Turn Health", enabled: true, config: driver.defaultConfig(),
diff --git a/server/drivers/antigravity-turn-outcome.test.ts b/server/drivers/antigravity-turn-outcome.test.ts
index 964d7e20e9..16fe954ed6 100644
--- a/server/drivers/antigravity-turn-outcome.test.ts
+++ b/server/drivers/antigravity-turn-outcome.test.ts
@@ -14,7 +14,7 @@ import type { ProviderInstance } from "../contracts.ts";
import { removeTempDir } from "../testing/cleanup.ts";
import { recordEvents } from "../testing/events.ts";
import { antigravityTokenPath } from "./antigravity-acp.ts";
-import { antigravityHarnessLimit, antigravityLimitFacts, antigravityQuotaFamily, watchAntigravityPromptOutcome } from "./antigravity-turn-outcome.ts";
+import { antigravityHarnessFailure, antigravityLimitFacts, antigravityQuotaFamily, watchAntigravityPromptOutcome } from "./antigravity-turn-outcome.ts";
import { AntigravityDriver } from "./antigravity.ts";
const USER_INPUT = 14;
@@ -43,6 +43,9 @@ const TIMESTAMP_ERROR = errorText(
const MISSING_SIGNATURE_ERROR = errorText(
'Error 400, Message: {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}, Status: INVALID_ARGUMENT, Details: []',
);
+const CORRUPT_MEDIA_ERROR = errorText(
+ "Error 400, Message: Unable to process input: the file or media data is empty, corrupted, or malformed., Status: INVALID_ARGUMENT, Details: []",
+);
const INVALID_SIGNATURE_ERROR = errorText(
'Error 400, Message: {"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.0: Invalid `signature` in `thinking` block"}}, Status: INVALID_ARGUMENT, Details: []',
);
@@ -137,7 +140,7 @@ describe("watchAntigravityPromptOutcome", () => {
expect(refusal!.facts.limitResetsAt).toBeUndefined();
});
- it("reads a lost thinking signature as a broken session, a 404 by when it came, and restarts the runtime after any of them", async () => {
+ it("reads a lost thinking signature or an undecodable media part as a broken session, a 404 by when it came, and restarts the runtime after any of them", async () => {
const { directory, conversations } = profile();
const sessionId = "4c2b7d1e-5472-4277-b6ee-27b2e05570a7";
const turn = async (steps: ReadonlyArray<readonly [number, string]>) => {
@@ -146,7 +149,7 @@ describe("watchAntigravityPromptOutcome", () => {
return check({ stopReason: "end_turn" });
};
expect(await turn([[USER_INPUT, "hello"], [PLANNER_RESPONSE, "fine"]])).toBeUndefined();
- for (const error of [MISSING_SIGNATURE_ERROR, INVALID_SIGNATURE_ERROR]) {
+ for (const error of [MISSING_SIGNATURE_ERROR, INVALID_SIGNATURE_ERROR, CORRUPT_MEDIA_ERROR]) {
expect(await turn([[USER_INPUT, "again"], [ERROR_MESSAGE, error]])).toMatchObject({
acpSessionBroken: true, acpSessionFailure: true, acpUsageLimit: false,
message: `${NAME}'s saved conversation can no longer be sent to the model. The next message starts a fresh ${NAME} session with this conversation's context.`,
@@ -212,14 +215,16 @@ describe("watchAntigravityPromptOutcome", () => {
expect(antigravityLimitFacts(undefined, known)).toEqual({ limit: "model" });
});
- it("reads a harness failure line on stderr that reports an exhausted quota as a usage limit, and no other one", () => {
+ it("reads a harness failure line on stderr that reports an exhausted quota as a usage limit, an undecodable media part as a broken session, and no other one", () => {
const harness = (error: string) => `E1124 14:52:01.000001 4242 local_connection.py:551] harness stderr: Agent run failed: ${error}`;
- expect(antigravityHarnessLimit(NAME, harness(QUOTA_ERROR.split("\n")[1]!), 0))
+ expect(antigravityHarnessFailure(NAME, harness(QUOTA_ERROR.split("\n")[1]!), 0))
.toMatchObject({ acpUsageLimit: true, message: expect.stringContaining("has reached its usage limit"), facts: { limitResetsAt: 3_600_000 } });
- expect(antigravityHarnessLimit(NAME, harness("RESOURCE_EXHAUSTED (code 429): Quota exceeded. reason:QUOTA_EXHAUSTED quotaResetDelay:38m0s]"), 0))
+ expect(antigravityHarnessFailure(NAME, harness("RESOURCE_EXHAUSTED (code 429): Quota exceeded. reason:QUOTA_EXHAUSTED quotaResetDelay:38m0s]"), 0))
.toMatchObject({ acpUsageLimit: true, facts: { limitResetsAt: 38 * 60_000 } });
- expect(antigravityHarnessLimit(NAME, harness("failed to handle call hook response: no pending hook for ID hook_request_2"), 0)).toBeUndefined();
- expect(antigravityHarnessLimit(NAME, harness(UNAVAILABLE_ERROR.split("\n")[1]!), 0)).toBeUndefined();
+ expect(antigravityHarnessFailure(NAME, harness("failed to handle call hook response: no pending hook for ID hook_request_2"), 0)).toBeUndefined();
+ expect(antigravityHarnessFailure(NAME, harness(UNAVAILABLE_ERROR.split("\n")[1]!), 0)).toBeUndefined();
+ expect(antigravityHarnessFailure(NAME, harness(CORRUPT_MEDIA_ERROR.split("\n")[1]!), 0))
+ .toMatchObject({ acpSessionBroken: true, acpSessionFailure: true, acpUsageLimit: false, message: expect.stringContaining("starts a fresh") });
});
it("gives no failure for a session id that is no file name, a missing profile, or a log replaced during the prompt", async () => {
diff --git a/server/drivers/antigravity-turn-outcome.ts b/server/drivers/antigravity-turn-outcome.ts
index 87ef83e9e0..ef12e28db0 100644
--- a/server/drivers/antigravity-turn-outcome.ts
+++ b/server/drivers/antigravity-turn-outcome.ts
@@ -11,6 +11,8 @@
// - from pingdotgg/t3code@f9a3c38c505: a lost thinking signature marks the
// session broken, and the next turn starts a fresh one from this
// conversation's context instead of resuming it;
+// - an undecodable media part in the history (a file the model read that
+// Google cannot decode) marks the session broken the same way;
// - from pingdotgg/t3code@f68d36d8aa9: the 1.5 "STATUS (code NNN): message"
// form, and a 404 after the model already answered in this turn counted
// as a temporary server error, not a refusal (the one resend T3 sends then
@@ -41,6 +43,9 @@ const QUOTA_EXHAUSTED = /\breason: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)/;
+// Google cannot decode a file the model read into its history as a media part (a cut-off PDF, say). The part stays in
+// the native history, so every later prompt to that session fails the same way.
+const UNDECODABLE_MEDIA = /\bfile or media data is empty, corrupted, or malformed\b/i;
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.
@@ -165,6 +170,11 @@ function restarting(failure: AcpReportedFailure, broken = false): AcpReportedFai
return Object.assign(failure, { acpSessionFailure: true }, broken ? { acpSessionBroken: true } : {});
}
+/** The saved native history can no longer be sent: the next turn starts a fresh session instead of resuming it. */
+function brokenSession(provider: string): AcpReportedFailure {
+ return restarting(new AcpReportedFailure({ message: `${provider}'s saved conversation can no longer be sent to the model. The next message starts a fresh ${provider} session with this conversation's context.` }, false), true);
+}
+
/** The failure a prompt's result and the last step it added stand for; undefined for a normal reply. */
export function antigravityTurnFailure(
provider: string,
@@ -179,9 +189,7 @@ export function antigravityTurnFailure(
const text = errorText ?? "";
const apiError = API_ERROR.exec(text) ?? statusError(text);
if (stopReason === "refusal" || QUOTA_EXHAUSTED.test(text)) return restarting(usageLimit(provider, text, now, timeZone));
- if (INVALID_THINKING_SIGNATURE.test(text)) {
- return restarting(new AcpReportedFailure({ message: `${provider}'s saved conversation can no longer be sent to the model. The next message starts a fresh ${provider} session with this conversation's context.` }, false), true);
- }
+ if (INVALID_THINKING_SIGNATURE.test(text) || UNDECODABLE_MEDIA.test(text)) return brokenSession(provider);
if (apiError === null) return restarting(new AcpReportedFailure(engineFailure(provider, "", { kind: "refused", status: null })!, false));
const [, httpStatus, message, status] = apiError;
if (httpStatus === "429" || status === "RESOURCE_EXHAUSTED") return restarting(usageLimit(provider, text, now, timeZone));
@@ -191,11 +199,13 @@ export function antigravityTurnFailure(
return restarting(new AcpReportedFailure(engineFailure(provider, message!.trim(), { kind: transient ? "server" : "refused", status: http })!, false));
}
-/** The usage limit a harness failure line on stderr reports, when it reports one; undefined for any other failure. */
-export function antigravityHarnessLimit(provider: string, line: string, now: number = Date.now()): AcpReportedFailure | undefined {
+/** The usage limit or broken session a harness failure line on stderr reports, when it reports one; undefined for any
+ * other failure. */
+export function antigravityHarnessFailure(provider: string, line: string, now: number = Date.now()): AcpReportedFailure | undefined {
const apiError = API_ERROR.exec(line) ?? statusError(line);
const exhausted = QUOTA_EXHAUSTED.test(line) || apiError?.[1] === "429" || apiError?.[3] === "RESOURCE_EXHAUSTED";
- return exhausted ? usageLimit(provider, line, now) : undefined;
+ if (exhausted) return usageLimit(provider, line, now);
+ return UNDECODABLE_MEDIA.test(line) ? brokenSession(provider) : undefined;
}
/**
diff --git a/server/drivers/antigravity.ts b/server/drivers/antigravity.ts
index a09e620273..ce87389660 100644
--- a/server/drivers/antigravity.ts
+++ b/server/drivers/antigravity.ts
@@ -40,7 +40,7 @@ import {
validateAntigravityRuntime,
verifyAntigravityBrowserHelper,
} from "./antigravity-acp.ts";
-import { antigravityHarnessLimit, antigravityLimitFacts, watchAntigravityPromptOutcome } from "./antigravity-turn-outcome.ts";
+import { antigravityHarnessFailure, antigravityLimitFacts, watchAntigravityPromptOutcome } from "./antigravity-turn-outcome.ts";
import { splitAntigravityThinking } from "./antigravity-models.ts";
import { AntigravityAuthController } from "./antigravity-auth.ts";
import { AntigravityCliLogin, type LoginProcesses } from "./antigravity-native-login.ts";
@@ -207,8 +207,9 @@ const support: AcpSupport = {
stderrFailure: {
line: ANTIGRAVITY_HARNESS_FAILURE_LOG,
message: "Antigravity's local agent connection failed. Send the message again to continue in a fresh Antigravity process.",
- // A run that failed on an exhausted quota is a usage limit, so the bot's fallback model can carry on.
- failure: (line) => antigravityHarnessLimit(support.displayName, line),
+ // A run that failed on an exhausted quota is a usage limit, so the bot's fallback model can carry on; one that
+ // failed on an undecodable media part is not resumed.
+ failure: (line) => antigravityHarnessFailure(support.displayName, line),
},
clientFileSystem: true,
// Only the native CLI takes them; agy_acp_server keeps its stdio proxies.