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
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function setAntigravityVersion(version: string): void {
* signature that the backend requires for Gemini 3.7/3.8 Flash. Kept current by
* `initAntigravityCliVersion()`; see docs/ANTIGRAVITY_API_SPEC.md.
*/
export const ANTIGRAVITY_CLI_VERSION_FALLBACK = "1.5.14";
export const ANTIGRAVITY_CLI_VERSION_FALLBACK = "1.5.17";

/**
* Build id (`cl`) reported by each CLI version in its client signature.
Expand All @@ -101,6 +101,9 @@ export const ANTIGRAVITY_CLI_VERSION_FALLBACK = "1.5.14";
* version than the one this plugin was written against.
*/
const ANTIGRAVITY_CLI_BUILDS: Record<string, string> = {
// Build id taken from the artifact agy itself downloads:
// antigravity-cli/1.5.17-4823843970351104/linux-x64/cli_linux_x64.tar.gz
"1.5.17": "4823843970351104",
"1.5.14": "1027820220",
"1.5.8": "962369648",
};
Expand Down
34 changes: 33 additions & 1 deletion src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ vi.mock("./plugin/stats", () => ({
},
}));

import { createAntigravityPlugin, verifyAccountAccess } from "./plugin";
import { createAntigravityPlugin, verifyAccountAccess, extractToSSuspensionReason } from "./plugin";

function createMockClient() {
return {
Expand Down Expand Up @@ -254,6 +254,38 @@ describe("v1 plugin empty response retry (2.3)", () => {
});
});

describe("extractToSSuspensionReason", () => {
it("recognizes the account-level Terms of Service suspension", () => {
const body = JSON.stringify({
error: {
code: 403,
message: "This service has been disabled in this account for violation of Terms of Service. Please submit an appeal to continue using this product.",
status: "PERMISSION_DENIED",
},
});

const reason = extractToSSuspensionReason(body);
expect(reason).toContain("violation of Terms of Service");
});

it("does not treat a validation_required 403 as a suspension", () => {
const body = JSON.stringify({
error: {
code: 403,
message: "Validation Required",
details: [{ reason: "VALIDATION_REQUIRED", metadata: { validation_url: "https://accounts.google.com/verify" } }],
},
});

expect(extractToSSuspensionReason(body)).toBeUndefined();
});

it("ignores rate-limit and quota bodies", () => {
const body = JSON.stringify({ error: { code: 429, message: "Individual quota reached" } });
expect(extractToSSuspensionReason(body)).toBeUndefined();
});
});

describe("verifyAccountAccess (3.3)", () => {
afterEach(() => {
vi.restoreAllMocks();
Expand Down
102 changes: 99 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,31 @@ function extractVerificationErrorDetails(bodyText: string): {
};
}

/**
* 403 signature for an account-level Terms of Service suspension.
*
* Distinct from `validation_required`: there is no verification URL, and no
* amount of retrying clears it. The backend answers this for every model on the
* account, so the account has to leave rotation instead of being retried.
*/
export function extractToSSuspensionReason(bodyText: string): string | undefined {
if (!bodyText) {
return undefined;
}
const decoded = decodeEscapedText(bodyText);
const match = decoded
.split("\n")
.map((line) => line.trim())
.find((line) =>
/violation of terms of service/i.test(line) ||
/service has been disabled in this account/i.test(line),
);
if (!match) {
return undefined;
}
return match.slice(0, 300);
}

export async function verifyAccountAccess(
account: {
refreshToken: string;
Expand Down Expand Up @@ -605,8 +630,40 @@ type VerificationStoredAccount = {
verificationRequiredAt?: number;
verificationRequiredReason?: string;
verificationUrl?: string;
suspended?: boolean;
suspendedAt?: number;
suspendedReason?: string;
};

/**
* Persists a ToS suspension in the raw storage record. Mirrors
* `markStoredAccountVerificationRequired` so a crash right after the 403 does
* not put the suspended account back in rotation on the next start.
*/
function markStoredAccountSuspended(account: VerificationStoredAccount, reason: string): boolean {
let changed = false;
const normalizedReason = reason.trim();

if (account.suspended !== true) {
account.suspended = true;
changed = true;
}
if (account.suspendedAt === undefined) {
account.suspendedAt = Date.now();
changed = true;
}
if (normalizedReason && account.suspendedReason !== normalizedReason) {
account.suspendedReason = normalizedReason;
changed = true;
}
if (account.enabled !== false) {
account.enabled = false;
changed = true;
}

return changed;
}

function markStoredAccountVerificationRequired(
account: VerificationStoredAccount,
reason: string,
Expand Down Expand Up @@ -2308,6 +2365,37 @@ export const createAntigravityPlugin = (providerId: string) => async (

if (response.status === 403) {
const errorBodyText = await response.clone().text().catch(() => "");
const suspensionReason = extractToSSuspensionReason(errorBodyText);

if (suspensionReason) {
accountManager.markAccountSuspended(account.index, suspensionReason);
try {
const stored = await loadAccounts();
const target = stored?.accounts[account.index];
if (stored && target && markStoredAccountSuspended(target, suspensionReason)) {
await saveAccounts(stored);
}
} catch (persistError) {
pushDebug(`suspension persist failed: ${String(persistError)}`);
}

const label = account.email || `Account ${account.index + 1}`;
if (accountManager.shouldShowAccountToast(account.index, 60000)) {
await showToast(
`[WARN] ${label} is suspended (Terms of Service). Removed from rotation; appeal at support.google.com.`,
"warning",
);
accountManager.markToastShown(account.index);
}

pushDebug(`tos-suspension: disabled account ${account.index} (${suspensionReason})`);
getHealthTracker().recordFailure(account.index);

lastFailure = createFailureContext(response);
shouldSwitchAccount = true;
break;
}

const extracted = extractVerificationErrorDetails(errorBodyText);

if (extracted.validationRequired) {
Expand Down Expand Up @@ -2706,9 +2794,11 @@ export const createAntigravityPlugin = (providerId: string) => async (
while (true) {
const now = Date.now();
const existingAccounts = existingStorage.accounts.map((acc, idx) => {
let status: 'active' | 'rate-limited' | 'expired' | 'verification-required' | 'unknown' = 'unknown';
let status: 'active' | 'rate-limited' | 'expired' | 'verification-required' | 'suspended' | 'unknown' = 'unknown';

if (acc.verificationRequired) {
if (acc.suspended) {
status = 'suspended';
} else if (acc.verificationRequired) {
status = 'verification-required';
} else {
const rateLimits = acc.rateLimitResetTimes;
Expand Down Expand Up @@ -2738,6 +2828,8 @@ export const createAntigravityPlugin = (providerId: string) => async (
status,
isCurrentAccount: idx === (existingStorage.activeIndex ?? 0),
enabled: acc.enabled !== false,
suspended: acc.suspended === true,
suspendedReason: acc.suspendedReason,
};
});

Expand All @@ -2750,7 +2842,11 @@ export const createAntigravityPlugin = (providerId: string) => async (

for (const res of results) {
const label = res.email || `Account ${res.index + 1}`;
const disabledStr = res.disabled ? " (disabled)" : "";
const disabledStr = res.suspended
? " (suspended: Terms of Service)"
: res.disabled
? " (disabled)"
: "";
console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
console.log(` ${label}${disabledStr}`);
console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
Expand Down
59 changes: 59 additions & 0 deletions src/plugin/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,65 @@ describe("AccountManager", () => {
vi.useRealTimers();
});

it("reports a Terms of Service suspension instead of a plain disable", () => {
const stored: AccountStorageV4 = {
version: 4,
accounts: [
{ email: "banned@example.com", refreshToken: "rb", addedAt: 1, lastUsed: 0, enabled: false, suspended: true, suspendedReason: "violation of Terms of Service" },
],
activeIndex: 0,
};

const manager = new AccountManager(undefined, stored);
const reasons = manager.getAllBlockedReasons("gemini");

expect(reasons[0]?.reason).toContain("suspended");
expect(reasons[0]?.reason).toContain("violation of Terms of Service");
expect(reasons[0]?.waitMs).toBeNull();
});

it("keeps a suspended account out of rotation even if the file says enabled", () => {
const stored: AccountStorageV4 = {
version: 4,
accounts: [
{ email: "banned@example.com", refreshToken: "rb", addedAt: 1, lastUsed: 0, enabled: true, suspended: true },
{ email: "healthy@example.com", refreshToken: "rh", addedAt: 1, lastUsed: 0 },
],
activeIndex: 0,
};

const manager = new AccountManager(undefined, stored);
expect(manager.getAccounts()[0]?.enabled).toBe(false);
expect(manager.getNextForFamily("gemini")?.index).toBe(1);
});

it("takes a suspended account out of rotation and restores it on explicit enable", () => {
const stored: AccountStorageV4 = {
version: 4,
accounts: [
{ email: "banned@example.com", refreshToken: "rb", addedAt: 1, lastUsed: 0 },
{ email: "healthy@example.com", refreshToken: "rh", addedAt: 1, lastUsed: 0 },
],
activeIndex: 0,
};

const manager = new AccountManager(undefined, stored);
expect(manager.markAccountSuspended(0, "violation of Terms of Service")).toBe(true);

const suspended = manager.getAccounts()[0];
expect(suspended?.enabled).toBe(false);
expect(suspended?.suspended).toBe(true);
expect(suspended?.suspendedReason).toBe("violation of Terms of Service");

const next = manager.getNextForFamily("gemini");
expect(next?.index).toBe(1);

expect(manager.setAccountEnabled(0, true)).toBe(true);
const restored = manager.getAccounts()[0];
expect(restored?.enabled).toBe(true);
expect(restored?.suspended).toBe(false);
});

it("names the cause when only the model-less family key was marked", () => {
vi.useFakeTimers();
vi.setSystemTime(10_000);
Expand Down
Loading