Files
PaperClipAI/server/src/services/native-runtime/antigravity-release.ts
T
DottaandClaude Opus 5.5 70d4b6524c fix(antigravity): offer the cloud candidate in the agent picker for linux-x64 environments (#22655)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Google Antigravity is a native Runner harness (#22591). Its profile
is still pending, so only a company with an operator grant can see or
run it
> - A grant can name the cloud target (linux-x64), and save, Test and
execution already accept it for a cloud environment
> - The agent picker computed the candidate only for the local target,
so a company with a valid cloud grant never saw the harness for a cloud
environment
> - This pull request binds the picker to the selected environment's
target, in the Antigravity-owned module
> - The benefit is that a granted company can pick Antigravity for the
linux-x64 cloud environments that can run it, and still sees nothing
anywhere else

## Linked Issues or Issue Description

Refs #22591

**What happened?**
`GET /api/adapters?companyId=…&environmentId=…` returned
`candidateHarnesses` only when the environment target was `local`. A
company with a valid linux-x64 Antigravity grant got no candidate for a
Core sandbox or SSH environment.

**What did you expect?**
The picker offers the candidate for a linux-x64 cloud environment when
the company holds a grant for that target, the same way save, Test and
the executor admit it.

**Steps to reproduce**
1. Set a candidate grant that names linux-x64 for a company and exact
model.
2. Request the adapter list for that company with a linux-x64 sandbox
environment.
3. `paperclip_runner` has no `candidateHarnesses`.

## What Changed

- `antigravityCandidateForRunnerTarget` (in `antigravity-release.ts`)
decides the picker candidate per environment target:
  - local: unchanged.
- Core sandbox or SSH that is linux-x64, or the managed cloud image:
only a grant that names linux-x64 and its patched closure.
- plugin Runner-task environment, unknown or other platform, unavailable
Computer: none.
  - released profile: none.
- `GET /api/adapters` uses it for every resolved target. Expired or
mismatched grants stay quiet; malformed grants still log one warning.
- The qualification plan notes the picker rule and records, as an open
decision, why plugin Runner-task environments cannot run Antigravity
yet.

### Not in this PR: plugin Runner-task environments

Paperclip Cloud's warm Agent Computer runs agents only as plugin Runner
tasks. Antigravity cannot run there yet, and the fix is outside Core
alone:
- The plugin task credential contract
(`environmentTaskCredentialSchema`) has no Gemini API key type.
- The plugin prepares the provider launch from `launch-requirements.v1`,
which carries no candidate grant. The ACPX sidecar refuses a pending
profile without one.
- The Cloud plugin's harness table lists only Codex, Claude and
OpenCode. Kimi, Copilot and Pi do not run there either.
- Antigravity Test refuses the Runner-task path.

The picker therefore offers nothing for those environments until that
work lands.

## Verification

- Red, then green: `server/src/__tests__/adapter-routes.test.ts` "offers
a cloud environment the candidate only for the company's linux-x64
grant" failed before the fix and passes after it.
- New unit tests in `antigravity-release.test.ts` run the real grant
resolver: cloud grant offered, other company / arm64 / Runner-task /
expired / host grant refused, released profile offers none.
- `npx vitest run src/__tests__/adapter-routes.test.ts
src/services/native-runtime/antigravity-release.test.ts
src/services/native-runtime/acpx-qualification.test.ts
src/services/native-runtime/antigravity-candidate-admission.test.ts`: 98
passed.
- Server `tsc --noEmit`: clean. `pnpm verify`: see the CI checks for the
final revision.
- Not run live: no Antigravity prompt has completed in any environment
yet, and the only available Gemini key is free tier. No paid runner E2E
workflow was dispatched.

## Risks

- Low risk. The change is read-only catalog output. Save, Test and
execution keep their strict admission checks.
- A company that holds a linux-x64 grant now sees Antigravity for
linux-x64 sandbox and SSH environments. Those paths already accept that
grant.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use (shell,
file edits) in Claude Code.

## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:09:22 -06:00

123 lines
6.3 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 none: it cannot
* launch Antigravity yet. A released profile offers no candidate. 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;
hostEnvironment?: NodeJS.ProcessEnv;
}): void {
const { execution } = input;
if (!isAntigravityProvider(execution.provider)) return;
if (!antigravityReleasePending()) {
assertAntigravitySavedStateCurrent(execution);
return;
}
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");
}
}