Files
PaperClipAI/server/src/services/native-runtime/antigravity-release.ts
T
DottaandPaperclip e04efb9734 feat(antigravity): allow plugin Runner-task and remote Google sign-in targets once released (#22940)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The native Runner executes Google Antigravity on local hosts, Core
managed sandboxes, and plugin Runner-task environments such as Paperclip
Computer.
> - Before this change, Paperclip refused Google sign-in on all remote
targets even after release, returned an unavailable error when testing
Antigravity on plugin Runner-task environments, and did not wire remote
refresh-token write-back on Core sandboxes or released Antigravity
profile resolution.
> - Paperclip Cloud needs Google Antigravity to run with both Gemini API
keys and Google sign-in on both plugin Runner-task environments and Core
managed sandboxes once the profile flips from pending to qualified.
> - This pull request lifts the released-state remote sign-in refusal,
wires plugin Runner-task probing and released profile resolution for
Antigravity, adds Core sandbox remote sign-in write-back and checkpoint
exclusion, and keeps pending-release candidate grants restricted to
API-key non-plugin targets.
> - The benefit is that flipping the Antigravity profile from pending to
qualified immediately enables picker selection, agent creation/save,
Test probing, and execution with either Gemini API keys or Google
sign-in on both plugin Runner-task environments and Core sandboxes.

## Linked Issues or Issue Description

- Refs #22923 (Item 6 of
`doc/plans/2026-11-25-antigravity-cloud-rollout.md`, gaps G6 and G7)
- Pairs with #22933 (Item 2: Antigravity sign-in task credential and
plugin write-back) and #22935 (Item 3: keep per-turn-only harnesses
per-turn on warm environments)
- Refs #22930 (Item 1: Gemini API key task credential for plugin
Runners)

## What Changed

- **Remote Google sign-in policy & credential preparation
(`antigravity-connection-policy.ts`,
`antigravity-runner-credentials.ts`)**:
- Allow both Gemini API key and Google sign-in on remote targets in
`antigravityConnectionRefusal` once `releasePending` is `false`, while
keeping `lifecycleMode: "warm"` refused and keeping pending-release
candidate grants API-key-only on non-plugin remote targets.
- Strip all `GOOGLE_*` and non-selected `GEMINI_*` variables (plus
`PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET`) in
`prepareAntigravityRunnerCredentials`, enforce
`antigravityConnectionRefusal` using `antigravityReleasePending()`, and
pass pure sanitized sign-in JSON on remote runs (without local `/swarm`
metadata).
- **Core sandbox remote sign-in write-back & checkpoint safety
(`native-credential-store.ts`, `native-session-executor.ts`,
`antigravity-runner-credentials.ts`)**:
- Extend `createNativeCredentialStore` to support `provider:
"antigravity"` (`acp_token.json` and `auth-refresh.json`) over local and
remote command runners.
- Add optional `runtimeStore` support to `antigravityCredentialTurn` and
wire it in `native-session-executor.ts` for Core remote sandboxes so
rotated Google refresh tokens copy back after process retirement and
remote credential files are scrubbed.
- Exclude
`antigravity-home/antigravity-acp/{acp_token.json,auth-refresh.json,auth-refresh.json.tmp,logs}`
from remote ACPX session checkpoints.
- Enforce `antigravityConnectionRefusal` in `preparePluginTaskOwner` and
reject pending `pluginTask` execution in
`assertAntigravityExecutionAdmissible` (defense in depth).
- **Plugin Runner-task probing, released profile resolution & agent
save/setup (`provider-profile.ts`, `plugin-runner-probe.ts`,
`antigravity-connection-probe.ts`, `agent-environment-test.ts`,
`agents.ts`, `NewAgentSetup.tsx`)**:
- Add `antigravity` to `DEFAULT_ACPX_RUNNER_MODELS` and the qualified
ACPX agent allowlist in `provider-profile.ts`, requiring an explicit
non-placeholder model ID and checking `antigravityReleasePending()`.
- Wire `testAntigravityConnection` to delegate plugin Runner-task
targets to `probePluginRunnerEnvironment` instead of returning `"Google
Antigravity is unavailable in this hosting environment."`, and update
`probePluginRunnerEnvironment` to run `admissionOnly: true` for
Antigravity with either Gemini API key or Google sign-in once released,
returning `antigravity_metadata_verified`.
- Allow Core sandbox/SSH `probeAntigravityExecutionTarget` for Google
sign-in once released, preserve `antigravity_remote_runtime_ready` warn
status in `agent-environment-test.ts` and `NewAgentSetup.tsx`.
- Allow released Antigravity creation without `enableNativeRunner`,
allow released remote sign-in account model discovery on the tenant
host, and refuse pending plugin targets even when a `linux-x64`
candidate grant exists.
- Note on existing >1,000-line files: edits to
`server/src/routes/agents.ts` and
`server/src/services/native-runtime/native-session-executor.ts` are
minimal wiring at existing Antigravity call sites (+12 and +26 net
lines).
- **Tests**:
- Updated `antigravity-runner-credentials.test.ts`,
`native-credential-store.test.ts`, `antigravity-save-refusal.test.ts`,
`antigravity-connection-probe.test.ts`, `antigravity-release.test.ts`,
`adapter-routes.test.ts`, `agent-runner-selection.test.ts`,
`agent-environment-test-status.test.ts`,
`native-session-executor.test.ts`, and
`ui/src/lib/cloud-harness-policy.test.ts`.
- Added
`server/src/services/native-runtime/plugin-runner-probe-antigravity.test.ts`.

## Verification

- Local Vitest (all passed against a released-profile fixture as well as
the real pending profile):
- `pnpm --filter @paperclipai/server exec vitest run
src/services/native-runtime/antigravity-runner-credentials.test.ts
src/services/native-runtime/native-credential-store.test.ts
src/services/native-runtime/antigravity-release.test.ts
src/services/native-runtime/plugin-runner-probe-antigravity.test.ts
src/services/native-runtime/plugin-runner-probe-runner-mismatch.test.ts
src/services/native-runtime/plugin-runner-credentials.test.ts
src/__tests__/antigravity-connection-probe.test.ts
src/__tests__/antigravity-save-refusal.test.ts
src/__tests__/antigravity-managed-subscription.test.ts
src/__tests__/antigravity-plugin-task-credential-writeback.test.ts
src/services/agent-runner-selection.test.ts
src/services/agent-environment-test-status.test.ts` (12 files, 425 tests
passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/adapter-routes.test.ts --hookTimeout=60000` (36 passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-test-environment-routes.test.ts --hookTimeout=60000
-t "passes the selected Antigravity"` (1 passed)
- `pnpm --filter @paperclipai/server exec vitest run
src/services/native-runtime/native-session-executor.test.ts -t "projects
the selected Antigravity subscription"` (2 passed)
- `pnpm --filter @paperclipai/ui exec vitest run
src/lib/cloud-harness-policy.test.ts` (36 passed)
- Typechecks:
  - `pnpm --filter @paperclipai/server exec tsc --noEmit` (passed)
  - `pnpm --filter @paperclipai/ui typecheck` (passed)
- Not run live: the real Antigravity profile remains `pending` until
Item 8; live staging verification on Paperclip Computer and Core managed
sandboxes is covered by Item 12.

## Risks

- Low risk while the Antigravity profile remains `pending`: all new
remote sign-in and plugin Runner-task paths stay gated behind
`!antigravityReleasePending()`, and pending-release candidate behavior
remains unchanged (and tighter on plugin environments).
- Once Item 8 flips the profile to qualified, released Antigravity
agents on Core sandboxes and plugin Runner-task environments will use
the paths tested here; live acceptance on staging is gated by Items
9–12.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Google Gemini (Antigravity agent with tool use and code execution)

## 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-11-25 08:36:37 -06:00

129 lines
6.7 KiB
TypeScript

import {
NativeProviderStateIncompatibleError,
QUALIFIED_ACPX_PROFILES,
type NativeExecutionInput,
} from "../../vendor/paperclip-runner/index.js";
import { supportsLinuxLibc } from "@paperclipai/shared";
import type { RunnerTarget } from "../agent-runner-selection.js";
import { ANTIGRAVITY_REMOTE_TARGET, resolveAntigravityCandidateAdmission } from "./acpx-qualification.js";
/** The platform a pending candidate grant must name for this execution. */
export function antigravityCandidateTarget(remote: boolean): { platform: string; architecture: string } {
return remote ? ANTIGRAVITY_REMOTE_TARGET : { platform: process.platform, architecture: process.arch };
}
/**
* The candidate grant the agent picker may offer for one environment, bound to
* the target the run would use. This host needs a grant that names this host.
* A Core sandbox or SSH environment needs a grant for the cloud pack's
* linux-x64 closure and a linux-x64 glibc Computer the Runner supports (or the
* managed cloud image). A plugin Runner-task environment offers no candidate
* grant while pending because the plugin launch contract carries no candidate
* grant; once released, no candidate grant is needed and plugin Runner-task
* environments offer Antigravity through the ordinary qualified Runner path.
* May throw for a grant that is invalid or names another target.
*/
export function antigravityCandidateForRunnerTarget(companyId: string, target: RunnerTarget) {
if (!antigravityReleasePending()) return undefined;
if (target.driver === "local") return resolveAntigravityCandidateAdmission({ companyId, target: antigravityCandidateTarget(false) });
if ((target.driver !== "sandbox" && target.driver !== "ssh") || target.runnerTasks) return undefined;
const managedImage = target.driver === "sandbox" && target.managedCloudImage && !target.platform && !target.architecture;
const linuxX64 = target.platform === ANTIGRAVITY_REMOTE_TARGET.platform && target.architecture === ANTIGRAVITY_REMOTE_TARGET.architecture
&& target.libc === "glibc" && supportsLinuxLibc(target.libc, target.glibcVersion);
if (!managedImage && !linuxX64) return undefined;
return resolveAntigravityCandidateAdmission({ companyId, target: ANTIGRAVITY_REMOTE_TARGET });
}
/**
* Google Antigravity's server gates while its Runner profile is pending, and
* the general qualified ACPX path after the release flip. Every gate reads the
* release declaration at call time, the way Kimi's do, never the agent name
* alone, so the flip needs no change here.
*/
export function antigravityReleasePending(): boolean {
return QUALIFIED_ACPX_PROFILES.antigravity.qualificationStatus === "pending";
}
export function isAntigravityProvider(
provider: NativeExecutionInput["provider"] | undefined,
): provider is Extract<NativeExecutionInput["provider"], { kind: "acpx" }> {
return provider?.kind === "acpx" && provider.agent === "antigravity";
}
/** Only the pending candidate owns a fresh daemon and state root per run. A
* qualified release keeps the ordinary per-session scope (company, agent,
* workspace and task session), so subtasks still never share a root. */
export function antigravityUsesRunScopedState(execution: NativeExecutionInput): boolean {
return isAntigravityProvider(execution.provider) && antigravityReleasePending();
}
/** The candidate keeps its saved conversation to the same session. A qualified
* release uses the ordinary recovery policy, including the automatic
* replacement conversation after a failed resume. */
export function antigravityForcesSameSessionRecovery(provider: NativeExecutionInput["provider"] | undefined): boolean {
return isAntigravityProvider(provider) && antigravityReleasePending();
}
export const ANTIGRAVITY_EARLIER_RELEASE_STATE_REASON =
"Google Antigravity session state was saved by an earlier release";
// The persisted profile snapshot carries no qualification status. The flip
// bumps agentProfileVersion, so candidate-era state differs here by version.
const RELEASE_IDENTITY_FIELDS = [
"agentProfileVersion", "commandDigest", "acpxVersion", "agentServerPackage", "agentServerVersion",
"agentRuntimePackage", "agentRuntimeVersion",
] as const;
/**
* Saved Antigravity state binds the release profile it was created under. State
* from another release (the pending candidate's per-run root and grant under
* its profile version, or any older profile) is refused permanently and by
* name. The run keeps its saved session and workspace, and the next run starts
* a replacement conversation in the same workspace instead of repeating it.
*/
export function assertAntigravitySavedStateCurrent(execution: NativeExecutionInput): void {
if (!isAntigravityProvider(execution.provider)) return;
const saved = (execution.provider.profile ?? {}) as unknown as Record<string, unknown>;
const current = QUALIFIED_ACPX_PROFILES.antigravity as unknown as Record<string, unknown>;
if (RELEASE_IDENTITY_FIELDS.some(field => saved[field] !== current[field])) {
throw new NativeProviderStateIncompatibleError(ANTIGRAVITY_EARLIER_RELEASE_STATE_REASON);
}
}
/**
* Executor admission. While pending, only an exact per-turn candidate grant
* bound to the execution target's platform may run: this host locally, or the
* cloud pack's linux-x64 closure remotely. After the flip no grant is needed and Antigravity takes the
* same path as Kimi and Copilot; only state saved by another release is refused.
*/
export function assertAntigravityExecutionAdmissible(input: {
execution: NativeExecutionInput;
useRunnerd?: boolean;
backend?: unknown;
restartRecovery?: unknown;
remoteTarget: boolean;
pluginTask?: boolean;
hostEnvironment?: NodeJS.ProcessEnv;
}): void {
const { execution } = input;
if (!isAntigravityProvider(execution.provider)) return;
if (!antigravityReleasePending()) {
assertAntigravitySavedStateCurrent(execution);
return;
}
if (input.pluginTask) {
throw new Error("paperclip_runner_antigravity_candidate_ineligible: exact target-bound per-turn candidate admission is required");
}
let candidate: ReturnType<typeof resolveAntigravityCandidateAdmission>;
try {
candidate = resolveAntigravityCandidateAdmission({
companyId: execution.binding.companyId, model: execution.provider.model, target: antigravityCandidateTarget(input.remoteTarget),
}, input.hostEnvironment ?? process.env);
} catch { candidate = undefined; }
if (!candidate || !input.useRunnerd || input.backend || input.restartRecovery
|| execution.session.lifecyclePolicy.mode !== "per_turn"
|| ("homeMode" in execution && execution.homeMode === "preconfigured")) {
throw new Error("paperclip_runner_antigravity_candidate_ineligible: exact target-bound per-turn candidate admission is required");
}
}