Files
PaperClipAI/server/src/services/native-runtime/antigravity-release.test.ts
T
DottaandPaperclip 3df59a1853 Unify Antigravity runtime and remote /swarm onto agy acp 1.5.19 (#23168)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The Paperclip Runner executes Google Antigravity agents on local
hosts and remote sandboxes
> - Previously, Paperclip shipped two separate Google runtimes: an 853
MiB IDE-extension ACP bundle (`agy_acp_server.par` 1.5.2 +
`localharness_external` + Python admission monkey-patch) for ordinary
turns and a separate `agy` 1.5.15 CLI binary for local-only `/swarm`
turns
> - Because the legacy server lacked `/swarm` and the CLI path refused
remote targets and required macOS Keychain or Linux user namespaces
(`auto` mode), remote sandboxes could not run `/swarm` and carried 853
MiB of legacy binaries
> - This pull request unifies all Antigravity surfaces (ordinary turns,
`/swarm`, interactive sign-in, and model discovery) onto one pinned
`agy` 1.5.19 CLI binary (`1.5.19-4821414830800896`) with file-backed
OAuth isolation (`AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1`) and
`--dangerously-skip-permissions` support for remote sandboxes
> - The benefit is one 268 MiB Linux binary instead of 853 MiB (saving
~585 MiB in remote images), no Python runtime monkey-patching, full
`/swarm` support on both local and remote hosts, and a unified 25-model
catalog including Gemini 4 Neon, Carbon, Hydrogen, and Argon

## Linked Issues or Issue Description

**What existing behavior does this improve?**
The Google Antigravity Runner driver, provider pack materialization,
Google sign-in flow, model discovery, and `/swarm` execution in
`packages/paperclip-runner`, `packages/shared`, `server`, and `ui`.

**Subsystem affected**
Cross-cutting (multiple of the above)

**Current behavior**
Ordinary Antigravity turns use the legacy 1.5.2 IDE-extension ACP server
(`agy_acp_server.par` + `localharness_external` + Python monkey-patch)
at ~853 MiB on `linux-x64`. Native `/swarm` turns require a separate
`agy` 1.5.15 CLI binary, refuse remote execution targets
(`input.remote`), and fail on Linux sandboxes without user namespaces
(`auto` mode).

**Proposed behavior**
All Antigravity flows use one pinned `agy` 1.5.19 binary
(`1.5.19-4821414830800896`, ~268 MiB on `linux-x64`) across all four
platforms (`darwin-arm64`, `darwin-x64`, `linux-x64`, `linux-arm64`).
Ordinary turns speak ACP directly through `openAntigravityAcpRuntime`.
Both ordinary and `/swarm` turns stage file-backed OAuth tokens under
`<agentHomeDirectory>/antigravity-cli/antigravity-oauth-token` with
`AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1`, isolate from host keychains, and
allow `/swarm` on remote targets using `--dangerously-skip-permissions`.
Interactive Google sign-in runs `agy acp --login` with
`https://antigravity.google/oauth-callback`, pre-creates
`<home>/antigravity-cli` with mode `0700`, and prompts for the
authorization code in the UI.

**Reason and benefit**
Unifying onto `agy` 1.5.19 cuts the `linux-x64` provider-pack footprint
by ~585 MiB, removes Python bytecode patching from materialization,
enables `/swarm` in headless Linux sandboxes without user namespaces or
D-Bus, and aligns ordinary turns, model discovery, and `/swarm` on the
same 25-model catalog.

**Breaking changes**
- `acpx-profiles.json` bumps `antigravity` to `agentProfileVersion: 3`
(`native:antigravity-cli`, version `1.5.19`). Existing saved legacy
1.5.2 sessions fail closed as incompatible saved state and start fresh
cleanly.
- Existing Google OAuth connections carrying `client_secret` remain
fully backward-compatible; new `agy acp --login` connections store
canonical credentials with `auth_method: "consumer"` and no
`client_secret`.

## What Changed

- Pin `agy` `1.5.19-4821414830800896` across all four platforms
(`darwin-arm64`, `darwin-x64`, `linux-x64`, `linux-arm64`) in
`antigravity-distributions.json`, `antigravity-cli-distributions.json`,
`antigravity-cli-pins.ts`, and `acpx-profiles.json`
(`agentProfileVersion: 3`), and regenerate TypeScript and Rust profile
artifacts.
- Replace ZIP + Python patch materialization with strict single-member
`tar.gz` verification (`materialize-antigravity-distribution.mjs`,
`provision-antigravity.mjs`, `probe-antigravity-metadata.mjs`,
`candidate-provider-pack.mjs`, `release-provider-pack.mjs`).
- Regenerate `packages/shared/src/antigravity-models.generated.ts` from
`agy` 1.5.19 (25 models across 8 families, including Gemini 4 Neon,
Carbon, Hydrogen, and Argon) and update
`packages/shared/src/antigravity-models.ts` and
`tests/runner-e2e/antigravity-qualification-cases.ts` for `xhigh`
thinking levels.
- Add direct ACP runtime
`packages/paperclip-runner/src/drivers/acpx/antigravity-acp-runtime.ts`
(`openAntigravityAcpRuntime`) for ordinary Antigravity turns with OAuth
and `GEMINI_API_KEY` support, `session/new` + `session/resume`,
`readOnly`/plan mode enforcement, HTTP and stdio MCP forwarding, live
`setModel`, slash-command neutralization, refusal classification,
cancellation, and lineage retirement; route ordinary Antigravity turns
unconditionally in `acpx-runtime-adapter.ts` without an ACPX fallback
seam.
- Update `antigravity-auth.ts`, `antigravity-credentials.ts`,
`antigravity-models.ts`, `antigravity-process.ts`, `runtime-host.ts`,
and `runtime-sandbox.ts` to run `agy acp --login`, pre-create
`<home>/antigravity-cli` with mode `0700` (preventing Go `os.MkdirAll`
`0755` readback failures), force file-backed token storage
(`AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1`), align `--gemini-dir` with
`agentHomeDirectory`, bound model-discovery token sync cleanup, and
scrub live CLI token files on cleanup.
- Enable remote `/swarm` by removing the `input.remote` refusal in
`server/src/services/antigravity-swarm.ts` and allowing
`--dangerously-skip-permissions` + `default` mode in
`antigravity-swarm-route.ts`, `antigravity-swarm-guard.ts`, and
`antigravity-swarm-runtime.ts` when `permissionMode === "approve-all"`.
- Update `ui/src/components/AdapterLoginChrome.tsx` copy to prompt for
an authorization code (`Submit code`) for
`https://antigravity.google/oauth-callback` while preserving callback
URL handling for loopback redirects.
- Add unit tests for `openAntigravityAcpRuntime`, direct Antigravity
routing, `0700` token directory pre-creation, and hosted
authorization-code login UX, and update Runner, script, shared, server,
Rust, UI, and runner-e2e test suites for `agy` 1.5.19.

## Verification

- Runner driver tests: `vitest run` across Antigravity driver test files
(`antigravity-auth.test.ts`, `antigravity-models.test.ts`,
`antigravity-acp-runtime.test.ts`, `antigravity-swarm-route.test.ts`,
`codex-credentials.test.ts`, `acpx-runtime-adapter.test.ts`,
`candidate-admission.test.ts`, `native-distribution-integrity.test.ts`)
— all passing.
- Runner script tests: `node --test` across all 7 Antigravity &
provider-pack script suites — 98/98 passed.
- Shared, UI, Server, and runner-e2e tests:
`antigravity-models.test.ts`, `AdapterLoginChrome.test.tsx` (23/23),
`antigravity-thread.test.tsx`, 23 server Antigravity/provider-pack
suites, and 7 `runner-e2e` Antigravity suites — all passing.
- Rust tests: `cargo test --manifest-path
packages/paperclip-runner/runner/Cargo.toml --locked -p
paperclip-runner-core -- acpx antigravity` — 145/145 passed.
- Typechecks & generators: `@paperclipai/shared`,
`@paperclipai/paperclip-runner` (TS + Rust), `@paperclipai/server` (all
layers), `@paperclipai/ui`, `generate-acpx-profiles.mjs --check`,
`generate-antigravity-models.mjs --check` — all passing.
- Live E2E against real pinned `agy` 1.5.19 binaries (macOS
`darwin-arm64`, headless Linux `linux-arm64` Docker with `--security-opt
no-new-privileges`, and a live remote test deployment):
- Verified `materialize-antigravity-distribution.mjs` on all 4 platform
archives and `probe-antigravity-metadata.mjs` on macOS and headless
Linux Docker.
- Verified live Google OAuth sign-in end-to-end via `agy acp --login` +
`https://antigravity.google/oauth-callback` authorization code exchange
on a live remote deployment, creating a working Antigravity connection.
- Verified `stageManagedAntigravityCredential` +
`AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1` file-backed isolation and cleanup
scrub on macOS and headless Linux Docker.
- Verified live `openAntigravityAcpRuntime` ordinary turn + HTTP MCP
tool call + `_meta.antigravity.systemPrompt.append` +
`setModel(gemini-4-argon-low)` + `session/resume` on real `agy` 1.5.19.
- Verified live `openAntigravitySwarmRuntime` `/swarm` turn with
`--dangerously-skip-permissions` spawning a real helper, writing
workspace file, calling `paperclip_finish`, and retiring cleanly.

## Risks

- **Coordinated Cloud deployment**: Remote sandboxes use the companion
transition-safe Cloud update to expect
`provider-assets/antigravity/linux-x64/agy`, accept `auth_method:
"consumer"` credentials without `client_secret`, and scrub
`antigravity-cli/antigravity-oauth-token`.
- **Saved session continuity**: Existing saved 1.5.2 sessions fail
closed as `ANTIGRAVITY_SAVED_STATE_INCOMPATIBLE` and start fresh cleanly
on 1.5.19.

## Model Used

- Google Gemini (Antigravity agentic coding assistant,
reasoning/tool-use/code-execution enabled)

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-12-01 22:01:25 +00:00

204 lines
12 KiB
TypeScript

import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
// Both release states are exercised against the same build: the qualified
// declaration that ships today (revision 2, no qualificationStatus), and the
// historical pending candidate declaration (revision 1, qualificationStatus: "pending").
const release = vi.hoisted(() => ({ pending: false }));
vi.mock("../../vendor/paperclip-runner/index.js", async importOriginal => {
const original = await importOriginal<typeof import("../../vendor/paperclip-runner/index.js")>();
const pending = {
...original.QUALIFIED_ACPX_PROFILES.antigravity,
agentProfileVersion: original.QUALIFIED_ACPX_PROFILES.antigravity.agentProfileVersion - 1,
qualificationStatus: "pending" as const,
};
const profiles = { ...original.QUALIFIED_ACPX_PROFILES };
Object.defineProperty(profiles, "antigravity", { enumerable: true,
get: () => release.pending ? pending : original.QUALIFIED_ACPX_PROFILES.antigravity });
return { ...original, QUALIFIED_ACPX_PROFILES: profiles };
});
import { NativeProviderStateIncompatibleError, QUALIFIED_ACPX_PROFILES, type NativeExecutionInput } from "../../vendor/paperclip-runner/index.js";
import { ANTIGRAVITY_CANDIDATE_ADMISSION_ENV } from "./acpx-qualification.js";
import {
antigravityCandidateForRunnerTarget,
antigravityForcesSameSessionRecovery,
antigravityReleasePending,
antigravityUsesRunScopedState,
assertAntigravityExecutionAdmissible,
} from "./antigravity-release.js";
import { nativeSessionFailureDisposition, nativeSessionFailureSourceCode, retireNeverOpenedCandidateRunRoot, scopedRunnerdStateRoot } from "./native-session-executor.js";
import { NATIVE_PROVIDER_STATE_INCOMPATIBLE } from "./native-session-resume.js";
import { ANTIGRAVITY_FIXTURE_COMPANY_ID as companyId, ANTIGRAVITY_FIXTURE_MODEL as model, antigravityExecution } from "./antigravity.test-fixture.js";
const distributions = JSON.parse(readFileSync(new URL("../../../../packages/paperclip-runner/antigravity-distributions.json", import.meta.url), "utf8"));
const candidateGrant = (target = "darwin-arm64", changes: Record<string, unknown> = {}) => {
const [platform, architecture] = target.split("-");
return JSON.stringify({ schema: "paperclip.acpx-candidate-admission.v1", companyId,
agent: "antigravity", model, profileDigest: QUALIFIED_ACPX_PROFILES.antigravity.commandDigest,
nativeClosureDigest: `sha256:${distributions.platforms[target].closureSha256}`,
platform, architecture, expiresAt: Date.now() + 60_000, ...changes });
};
afterEach(() => { release.pending = false; vi.unstubAllEnvs(); });
describe("Antigravity executor admission", () => {
const admissible = (execution: NativeExecutionInput, changes: Partial<Parameters<typeof assertAntigravityExecutionAdmissible>[0]> = {}) =>
() => assertAntigravityExecutionAdmissible({ execution, useRunnerd: true, remoteTarget: false, ...changes });
it("takes the general qualified path without a candidate grant, including pluginTask and remote targets", () => {
expect(antigravityReleasePending()).toBe(false);
expect(QUALIFIED_ACPX_PROFILES.antigravity.agentProfileVersion).toBe(3);
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
const execution = antigravityExecution();
expect(admissible(execution)).not.toThrow();
expect(admissible(execution, { remoteTarget: true, pluginTask: true })).not.toThrow();
expect(admissible(execution, { remoteTarget: true, restartRecovery: { kind: "reattach_remote_runner" } })).not.toThrow();
const preconfigured = { ...execution, homeMode: "preconfigured" } as NativeExecutionInput;
expect(admissible(preconfigured)).not.toThrow();
});
it("refuses ungranted and pluginTask execution when releasePending is forced true", () => {
release.pending = true;
expect(antigravityReleasePending()).toBe(true);
const execution = antigravityExecution();
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
expect(admissible(execution)).toThrow(/paperclip_runner_antigravity_candidate_ineligible/);
expect(admissible(execution, { remoteTarget: true })).toThrow(/candidate_ineligible/);
expect(admissible(execution, { remoteTarget: true, pluginTask: true })).toThrow(/candidate_ineligible/);
const warm = { ...execution, session: { ...execution.session, lifecyclePolicy: { mode: "warm", idleTimeoutMs: 1 } } } as NativeExecutionInput;
expect(admissible(warm)).toThrow(/candidate_ineligible/);
});
});
describe("Antigravity agent picker candidate", () => {
const cloud = { driver: "sandbox", platform: "linux", architecture: "x64", libc: "glibc" as const, glibcVersion: "2.39" };
it("offers no candidate once the profile is released, even if a stale grant env var is set", () => {
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, candidateGrant("linux-x64"));
expect(antigravityCandidateForRunnerTarget(companyId, cloud)).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "local" })).toBeUndefined();
expect(antigravityCandidateForRunnerTarget(companyId, { driver: "plugin", runnerTasks: true })).toBeUndefined();
});
});
describe("Antigravity recovery policy and state root", () => {
it("uses ordinary session-scoped state when released and per-run candidate scope only while pending", () => {
const execution = antigravityExecution();
const nextRun = antigravityExecution({ runId: "50000000-0000-4000-8000-000000000005" });
expect(antigravityForcesSameSessionRecovery(execution.provider)).toBe(false);
expect(antigravityUsesRunScopedState(execution)).toBe(false);
// Qualified: one root per session scope, kept across the session's runs.
expect(scopedRunnerdStateRoot(execution)).toBe(scopedRunnerdStateRoot(nextRun));
release.pending = true;
expect(antigravityForcesSameSessionRecovery(execution.provider)).toBe(true);
expect(antigravityUsesRunScopedState(execution)).toBe(true);
expect(scopedRunnerdStateRoot(execution)).not.toBe(scopedRunnerdStateRoot(nextRun));
});
it.each([false, true])("never shares a state root across subtasks or workspaces (pending=%s)", pending => {
release.pending = pending;
const parent = antigravityExecution();
const subtask = antigravityExecution({ issueId: "21000000-0000-4000-8000-000000000002",
workspaceId: "91000000-0000-4000-8000-000000000009", sessionId: "61000000-0000-4000-8000-000000000006" });
const otherWorkspace = antigravityExecution({ workspaceId: "92000000-0000-4000-8000-000000000009" });
const roots = new Set([parent, subtask, otherWorkspace].map(scopedRunnerdStateRoot));
expect(roots.size).toBe(3);
});
});
describe("Antigravity candidate same-run startup retry", () => {
let stateBase: string;
beforeEach(() => {
stateBase = mkdtempSync(join(tmpdir(), "antigravity-candidate-root-"));
vi.stubEnv("PAPERCLIP_RUNNER_STATE_DIR", stateBase);
});
afterEach(() => rmSync(stateBase, { recursive: true, force: true }));
/** What a candidate runner leaves after its session.open failed and it suspended. */
function writeFailedOpenRoot(execution: NativeExecutionInput, provider: Record<string, unknown> = {}) {
const root = scopedRunnerdStateRoot(execution);
mkdirSync(join(root, "control-plane"), { recursive: true, mode: 0o700 });
mkdirSync(join(root, "runner"), { recursive: true, mode: 0o700 });
writeFileSync(join(root, "control-plane", "control-plane-state.json"), JSON.stringify({
schema: "paperclip.runner.durable.control-plane-state.v2",
identity: { runnerInstanceId: "80000000-0000-4000-8000-000000000008", environmentLeaseId: execution.binding.executionWorkspaceId,
runId: execution.binding.runId, normalizedSessionId: execution.session.normalizedSessionId },
}));
writeFileSync(join(root, "runner", "acpx-provider-state.json"), JSON.stringify({
schema: "paperclip.runner.acpx-provider-state.v3", lifecycle: "closed", identity: null, activeTurnId: null,
providerExitUnconfirmed: false, semanticResult: null, pendingEvents: [], pendingRuntimeRequests: {}, openSemanticCalls: [],
...provider,
}));
return root;
}
const quarantined = (root: string) => existsSync(join(stateBase, "quarantine"))
&& readdirSync(join(stateBase, "quarantine")).some(name => name.startsWith(`${basename(root)}.identity_indeterminate.`));
it("retires a root whose session.open never opened a provider session only while pending", async () => {
release.pending = true;
const execution = antigravityExecution();
const root = writeFailedOpenRoot(execution);
expect(await retireNeverOpenedCandidateRunRoot(execution, root)).toBe(true);
expect(existsSync(root)).toBe(false);
expect(quarantined(root)).toBe(true);
});
it("keeps a root that opened a provider session or started a turn, and every root once released", async () => {
release.pending = true;
for (const provider of [
{ lifecycle: "suspended", identity: { kind: "acpx", acpxRecordId: "record" } },
{ lifecycle: "closed", identity: { kind: "acpx", acpxRecordId: "record" } },
{ lifecycle: "turn_active", activeTurnId: "turn" },
{ providerExitUnconfirmed: true },
]) {
const execution = antigravityExecution();
const root = writeFailedOpenRoot(execution, provider);
expect(await retireNeverOpenedCandidateRunRoot(execution, root)).toBe(false);
expect(existsSync(root)).toBe(true);
rmSync(root, { recursive: true, force: true });
}
// Another run's root is never this run's to retire.
const other = antigravityExecution({ runId: "50000000-0000-4000-8000-000000000005" });
const otherRoot = writeFailedOpenRoot(other);
expect(await retireNeverOpenedCandidateRunRoot(antigravityExecution(), otherRoot)).toBe(false);
expect(existsSync(otherRoot)).toBe(true);
release.pending = false;
const released = antigravityExecution();
const releasedRoot = writeFailedOpenRoot(released);
expect(await retireNeverOpenedCandidateRunRoot(released, releasedRoot)).toBe(false);
expect(existsSync(releasedRoot)).toBe(true);
});
});
describe("Antigravity state saved by the pending candidate, resumed by the qualified release", () => {
it("refuses the candidate's in-flight v1 state permanently and by name, never as a retryable interruption", () => {
// Saved before the deploy under the candidate's v1 profile version.
release.pending = true;
const saved = antigravityExecution();
release.pending = false;
vi.stubEnv(ANTIGRAVITY_CANDIDATE_ADMISSION_ENV, undefined);
let refusal: unknown;
try {
assertAntigravityExecutionAdmissible({ execution: saved, useRunnerd: true, remoteTarget: false,
restartRecovery: { kind: "same_run_resume" } });
} catch (error) { refusal = error; }
expect(refusal).toBeInstanceOf(NativeProviderStateIncompatibleError);
const code = nativeSessionFailureSourceCode(refusal);
expect(code).toBe(NATIVE_PROVIDER_STATE_INCOMPATIBLE);
expect(nativeSessionFailureDisposition(1, new Date(), code)).toMatchObject({
phase: "terminal_failure", failureCode: NATIVE_PROVIDER_STATE_INCOMPATIBLE, nextAttemptAt: null });
});
it("refuses an older qualified profile version by the same name", () => {
const saved = antigravityExecution();
(saved.provider as { profile: { agentProfileVersion: number } }).profile.agentProfileVersion -= 1;
expect(() => assertAntigravityExecutionAdmissible({ execution: saved, useRunnerd: true, remoteTarget: false }))
.toThrow(NativeProviderStateIncompatibleError);
});
});