feat(antigravity): swarms use the CLI's own default channel, and say which Google account they run on

Google's app and CLI use Google's default channel, where Gemini 4 Neon is
offered; Paperclip forced the stable endpoint, which offers no Neon and bills
a separately exhausted pool. The swarm route now passes no endpoint override by
default. The deployment can pin Google's stable channel with the server env
PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL (provider_default | stable); a Neon refusal
on stable names that fix. The start step names the channel, and the Runner
compares the CLI's own sign-in (from its log) with the agent's connection as
digests only, showing a plain notice when they differ.

Also: a resent accepted /swarm returns its original receipt before any
availability check, and the request text is used verbatim (the composer
removes the one /swarm the user typed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 committed 2026-11-24 16:44:02 -06:00
1 parent 22913aed7a
commit 48caed2d3a
19 files changed
+284 -45

No files matched your search

@@ -3,7 +3,8 @@ import { constants } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { antigravityCredentialTurn, bindAntigravityCredentialTurn, bindAntigravityTransportRetirement, prepareAntigravityRunnerCredentials } from "./antigravity-runner-credentials.js";
import { antigravityAccountDigest, antigravityCredentialTurn, antigravitySwarmChannel, bindAntigravityCredentialTurn, bindAntigravityTransportRetirement, prepareAntigravityRunnerCredentials } from "./antigravity-runner-credentials.js";
import { sanitizeAntigravityCredential } from "../../vendor/paperclip-runner/index.js";
import { completeManagedNativeCredentialTurn } from "./managed-native-credentials.js";
import type { NativeSession, createRunnerdCodexTransport } from "../../vendor/paperclip-runner/index.js";
import { bindRetainedGoogleCredentialHome } from "../retained-google-credential-cleanup.js";
@@ -99,12 +100,34 @@ describe("Antigravity managed Runner credentials", () => {
GOOGLE_CLOUD_ACCESS_TOKEN: "ambient", PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "spoofed",
} })).toEqual({ home: null, environment: { GEMINI_API_KEY: "fixture-selected" } });
});
it("binds the deployment's swarm channel and only a digest of the connection account to the credential", async () => {
const managedHome = await home();
await writeFile(join(managedHome, "antigravity-acp", "acp_token.json"), credential("fixture-selected"), { mode: 0o600 });
const previous = process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL;
process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL = "stable";
try {
const { environment } = await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: {}, accountEmail: "Owner@Example.test" });
const secret = environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!;
expect(JSON.parse(secret).paperclip).toEqual({ swarmChannel: "stable", accountSha256: antigravityAccountDigest("owner@example.test") });
expect(secret).not.toMatch(/example\.test/i);
// Pinned: the Runner's antigravityAccountDigest pins the same value for the CLI's sign-in.
expect(antigravityAccountDigest("OWNER@example.test")).toBe("0fde1d32467703827f511884b66298187e2944f4bfe260303f893a0af908f81e");
} finally {
if (previous === undefined) delete process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL; else process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL = previous;
}
expect(antigravitySwarmChannel({})).toBe("provider_default");
expect(antigravitySwarmChannel({ PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL: "daily" })).toBe("provider_default");
});
it("projects only the selected private token and rejects remote subscription delivery", async () => {
const managedHome = await home();
await writeFile(join(managedHome, "antigravity-acp", "acp_token.json"), credential("fixture-selected"), { mode: 0o600 });
expect(await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: { GEMINI_HOME: "/untrusted" } })).toEqual({
home: managedHome, credential: credential("fixture-selected"), environment: { PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: credential("fixture-selected") },
});
const projected = await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: { GEMINI_HOME: "/untrusted" } });
expect(projected).toMatchObject({ home: managedHome, credential: credential("fixture-selected") });
expect(Object.keys(projected.environment)).toEqual(["PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET"]);
// The selected token, plus the swarm route's run facts, which the Runner's sanitizer drops before any write.
expect(JSON.parse(projected.environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!)).toEqual({
...JSON.parse(credential("fixture-selected")), paperclip: { swarmChannel: "provider_default" } });
expect(sanitizeAntigravityCredential(projected.environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!)).toBe(credential("fixture-selected"));
for (const [input, code] of [[{ remote: true, environment: {} }, "antigravity_remote_sign_in_unsupported"],
[{ remote: false, lifecycleMode: "warm" as const, environment: {} }, "antigravity_warm_unsupported"],
[{ remote: false, lifecycleMode: "warm" as const, environment: { GEMINI_API_KEY: "fixture-selected" } }, "antigravity_warm_unsupported"]] as const) {
@@ -1,5 +1,5 @@
import { constants } from "node:fs";
import { randomUUID } from "node:crypto";
import { createHash, randomUUID } from "node:crypto";
import { mkdir, mkdtemp, realpath, rename, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -35,12 +35,30 @@ export function bindAntigravityTransportRetirement(bundle: RunnerdTransport): Ru
return bundle.transport;
}
/**
* The Google channel a trusted /swarm's Antigravity CLI talks to, owned by the
* deployment: `provider_default` (the default; Google's daily channel, which
* Google's own app and CLI use and which can change with less notice) or
* `stable` (Google's stable endpoint, which may offer fewer models).
*/
export const ANTIGRAVITY_SWARM_CHANNEL_ENV = "PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL";
export function antigravitySwarmChannel(env: NodeJS.ProcessEnv = process.env): "provider_default" | "stable" {
return env[ANTIGRAVITY_SWARM_CHANNEL_ENV]?.trim().toLowerCase() === "stable" ? "stable" : "provider_default";
}
/** Same digest as the Runner's antigravityAccountDigest: a one-way, non-identifying account comparison. */
export function antigravityAccountDigest(email: string): string {
return createHash("sha256").update(`paperclip.antigravity-account.v1:${email.trim().toLowerCase()}`, "utf8").digest("hex");
}
/** Only explicit run credentials may enter Antigravity's isolated runtime. */
export async function prepareAntigravityRunnerCredentials(input: {
environment: NodeJS.ProcessEnv;
remote: boolean;
managedHome?: string;
lifecycleMode?: "per_turn" | "warm";
/** The connection's Google account; only its digest reaches the Runner. */
accountEmail?: string;
}): Promise<{ environment: NodeJS.ProcessEnv; home: string | null; credential?: string }> {
const environment = { ...input.environment };
for (const key of [AUTH_SECRET, "GEMINI_HOME", "GOOGLE_API_KEY", "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_CLOUD_ACCESS_TOKEN"]) delete environment[key];
@@ -59,7 +77,13 @@ export async function prepareAntigravityRunnerCredentials(input: {
} catch {
throw new Error("The selected Google Antigravity account is unavailable. Reconnect the Google account, then retry.");
}
environment[AUTH_SECRET] = credential;
// Run facts bound to this credential for the swarm route (channel, account
// digest). The Runner's credential sanitizer drops them before any write, so
// the staged token and its writeback comparison are unchanged.
environment[AUTH_SECRET] = JSON.stringify({ ...JSON.parse(credential) as Record<string, unknown>, paperclip: {
swarmChannel: antigravitySwarmChannel(),
...(input.accountEmail ? { accountSha256: antigravityAccountDigest(input.accountEmail) } : {}),
} });
return { environment, home, credential };
}
@@ -10662,6 +10662,8 @@ export async function executePaperclipNativeSession(input: {
managedAiCredentialHome?: string;
managedAiCredentialIdentity?: string;
managedAiAccountIdentity?: string;
/** The Google account of an Antigravity subscription grant (Runner compares only its digest). */
managedAiAccountEmail?: string;
managedAiCredentialWriteback?: ManagedAiCredentialWritebackBinding;
billingIdentity?: Pick<AdapterExecutionResult, "provider" | "biller" | "billingType">;
onTaskDispatched?: () => Promise<void> | void;
@@ -16487,6 +16489,8 @@ export async function createRunnerdBackend(input: {
managedAiCredentialHome?: string;
managedAiCredentialIdentity?: string;
managedAiAccountIdentity?: string;
/** The Google account of an Antigravity subscription grant (Runner compares only its digest). */
managedAiAccountEmail?: string;
managedAiCredentialWriteback?: ManagedAiCredentialWritebackBinding;
onTaskDispatched?: () => Promise<void> | void;
runnerExecutionTarget?: AdapterExecutionTarget | null;
@@ -18615,7 +18619,7 @@ async function createRunnerdBackendWithinSessionClaim(
if (grokCredential) effectiveRunnerEnvironmentBase = grokCredential.environment;
const antigravityCredential = isAntigravity ? await prepareAntigravityRunnerCredentials({
environment: effectiveRunnerEnvironmentBase, remote: Boolean(remoteTarget), managedHome: input.managedAiCredentialHome,
lifecycleMode: input.execution.session.lifecyclePolicy.mode,
lifecycleMode: input.execution.session.lifecyclePolicy.mode, accountEmail: input.managedAiAccountEmail,
}) : null;
if (antigravityCredential) effectiveRunnerEnvironmentBase = antigravityCredential.environment;
// The server-held tool authority owns this credential. Do not deliver a