mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
fix(antigravity): resolve hosted login and model discovery from configured provider pack (#22983)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip supports Google Antigravity through Paperclip Runner, including server-hosted Google sign-in and account-bound model discovery. > - In Docker and hosted deployments, the server ships Antigravity's verified Linux runtime closure inside the build-owned provider pack at `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`, not under `server/dist/vendor/paperclip-runner/`. > - Because `startAntigravityBrowserLogin` and `discoverAntigravityModels` only checked `import.meta.url` and `PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT`, hosted Google sign-in and subscription model discovery failed immediately on container deployments. > - This pull request adds an explicit `providerPackageRoot` option to the Runner asset-root and Antigravity helpers and forwards the normalized `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH` from the server without mutating `process.env`. > - The benefit is that hosted Google Antigravity sign-in and model discovery resolve the verified build-owned closure cleanly on Docker and Cloud deployments while keeping all manifest, symlink, and closure-integrity checks intact. ## Linked Issues or Issue Description Refs #22932 **What happened?** On a Docker/hosted server where `hostedGoogleAiLoginSupported` is `true` and `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH=/opt/paperclip-runner/provider-pack`, starting Google Subscription sign-in returned `HTTP 201` on `POST /ai-connections/local/attempts` and then immediately failed on `/ai-connections/local/check` with `Google sign-in did not complete. Start sign-in again.` and no OAuth URL. `discoverAntigravityModels` hit the same missing asset lookup in container deployments. **Expected behavior** Hosted Google Antigravity sign-in and account-bound model discovery resolve the verified `provider-assets/antigravity/linux-x64` closure from the server's configured `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH` provider pack, return the PKCE loopback authorization URL for hosted redirect relay, and load the account's model catalog. **Steps to reproduce** 1. Run the Paperclip Docker image (`node server/dist-runtime/index.mjs`) with `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH=/opt/paperclip-runner/provider-pack`. 2. Open the Google Antigravity and Gemini connector and start a `Google Subscription` sign-in attempt. 3. Observe `/ai-connections/local/check` immediately returning `Google sign-in did not complete. Start sign-in again.` without an authorization URL. **Paperclip version or commit** `1fca3a6d8c5a2be455f1240e96ff8d12387ad688` (on `master`) **Deployment mode** Docker ## What Changed - Added an optional `RunnerProviderAssetsRootOptions` (`{ providerPackageRoot?, providerPackageManifest? }`) parameter to `resolveRunnerProviderAssetsRoot` in `packages/paperclip-runner/src/drivers/acpx/provider-assets-root.ts` so callers can pass an explicit package root without mutating `process.env`, reusing the same manifest, symlink, containment, and TOCTOU verification checks and failing closed on invalid roots. - Threaded optional `{ providerPackageRoot }` through `antigravityNativeDistributionSpec`, `startAntigravityBrowserLogin`, and `discoverAntigravityModels`. - Updated `server/src/services/local-ai-browser-login.ts` and `server/src/services/antigravity-connection-models.ts` to normalize `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH` (stripping trailing slashes and rejecting non-normalized or relative paths) and pass `{ providerPackageRoot }` when configured. - Added unit tests covering explicit `providerPackageRoot` resolution for bundled server paths, fail-closed validation on invalid roots, and server forwarding in `provider-assets-root.test.ts`, `antigravity-connection-models.test.ts`, and `local-ai-browser-login-google.test.ts`. ## Verification - `pnpm --filter @paperclipai/paperclip-runner build:typescript` — passed. - `pnpm --filter @paperclipai/server typecheck` — passed. - `pnpm --filter @paperclipai/paperclip-runner exec vitest run src/drivers/acpx/provider-assets-root.test.ts src/drivers/acpx/antigravity-auth.test.ts src/drivers/acpx/antigravity-models.test.ts` — passed (52/52 tests across 3 files). - `pnpm exec vitest run server/src/__tests__/antigravity-connection-models.test.ts server/src/services/local-ai-browser-login-google.test.ts server/src/__tests__/antigravity-local-ai-login.test.ts` — passed (31/31 tests across 3 files). - `node --test packages/paperclip-runner/scripts/contracts/contract-fingerprints.test.mjs` — passed (11/11 tests). ## Risks - Low risk. When `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH` is unset (ordinary local development), all call sites keep their existing single-argument behavior. When set, the path must be normalized and absolute and still passes `resolveRunnerProviderAssetsRoot`'s full `package.json` and symlink-containment checks plus `verifyNativeAcpxInstallation`'s pinned SHA-256 closure verification. No contract fingerprints or database schemas change. ## 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>
This commit is contained in:
1 parent
331e1a9fd3
commit
362bdc1117
9 files changed
+145
-11
No files matched your search
@@ -170,7 +170,10 @@ export async function verifyAntigravityCredential(home: string, options: { signa
|
||||
* initialize/authenticate; pending provider qualification remains enforced for
|
||||
* every session and prompt by the ordinary runtime installation path.
|
||||
*/
|
||||
export function startAntigravityBrowserLogin(home: string): AntigravityBrowserLoginState {
|
||||
export function startAntigravityBrowserLogin(
|
||||
home: string,
|
||||
options?: { providerPackageRoot?: string },
|
||||
): AntigravityBrowserLoginState {
|
||||
const controller = new AbortController();
|
||||
activeBrowserHomes.add(home);
|
||||
let resolveStopped: () => void;
|
||||
@@ -182,7 +185,10 @@ export function startAntigravityBrowserLogin(home: string): AntigravityBrowserLo
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined, failPending: ((error: Error) => void) | undefined;
|
||||
try {
|
||||
await checkAntigravityPrivateHome(home);
|
||||
const installation = await verifyNativeAcpxInstallation(antigravityNativeDistributionSpec());
|
||||
const spec = options?.providerPackageRoot !== undefined
|
||||
? antigravityNativeDistributionSpec(process.platform, process.arch, { providerPackageRoot: options.providerPackageRoot })
|
||||
: antigravityNativeDistributionSpec();
|
||||
const installation = await verifyNativeAcpxInstallation(spec);
|
||||
lease = await installation.openCommand({ signal: controller.signal });
|
||||
const environment = await antigravityPrivateEnvironment(home);
|
||||
if (controller.signal.aborted) throw new Error(LOGIN_ERROR);
|
||||
|
||||
@@ -16,11 +16,22 @@ export function antigravityRuntimeCachePath(closure: string, platform: string, a
|
||||
return realRuntimeCachePath(home, "antigravity", `${platform}-${architecture}`, closure, "Antigravity runtime cache must contain real directories");
|
||||
}
|
||||
|
||||
export function antigravityNativeDistributionSpec(platform: NodeJS.Platform = process.platform, architecture: string = process.arch): NativeAcpxDistributionInput {
|
||||
export function antigravityNativeDistributionSpec(
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
architecture: string = process.arch,
|
||||
options?: { providerPackageRoot?: string },
|
||||
): NativeAcpxDistributionInput {
|
||||
const key = `${platform}-${architecture}`;
|
||||
if (!Object.hasOwn(ANTIGRAVITY_DISTRIBUTION_PINS, key)) throw new Error(`Antigravity has no admitted complete runtime closure for ${key}`);
|
||||
const pin = ANTIGRAVITY_DISTRIBUTION_PINS[key as keyof typeof ANTIGRAVITY_DISTRIBUTION_PINS];
|
||||
const packaged = join(resolveRunnerProviderAssetsRoot(import.meta.url, "antigravity"), key);
|
||||
const packaged = join(
|
||||
resolveRunnerProviderAssetsRoot(
|
||||
import.meta.url,
|
||||
"antigravity",
|
||||
options?.providerPackageRoot !== undefined ? { providerPackageRoot: options.providerPackageRoot } : undefined,
|
||||
),
|
||||
key,
|
||||
);
|
||||
let distributionRoot = packaged;
|
||||
try {
|
||||
const stat = lstatSync(packaged);
|
||||
|
||||
@@ -69,7 +69,10 @@ function catalog(value: unknown, nonce: string): AntigravityModelCatalog {
|
||||
* writeback. Execution retires before ordinary results/errors. A cleanup error
|
||||
* transfers the home-retention obligation through its retired completion.
|
||||
*/
|
||||
export async function discoverAntigravityModels(home: string, options: { signal?: AbortSignal } = {}): Promise<AntigravityModelCatalog> {
|
||||
export async function discoverAntigravityModels(
|
||||
home: string,
|
||||
options: { signal?: AbortSignal; providerPackageRoot?: string } = {},
|
||||
): Promise<AntigravityModelCatalog> {
|
||||
const deadline = new AbortController(), timer = setTimeout(() => deadline.abort(), 30_000);
|
||||
const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
|
||||
let lease: VerifiedAcpxCommandLease | undefined, child: ChildProcessWithoutNullStreams | undefined, closed: Promise<void> | undefined;
|
||||
@@ -79,7 +82,10 @@ export async function discoverAntigravityModels(home: string, options: { signal?
|
||||
signal.throwIfAborted();
|
||||
await checkAntigravityPrivateHome(home);
|
||||
signal.throwIfAborted();
|
||||
const installation = await verifyNativeAcpxInstallation(antigravityNativeDistributionSpec());
|
||||
const spec = options.providerPackageRoot !== undefined
|
||||
? antigravityNativeDistributionSpec(process.platform, process.arch, { providerPackageRoot: options.providerPackageRoot })
|
||||
: antigravityNativeDistributionSpec();
|
||||
const installation = await verifyNativeAcpxInstallation(spec);
|
||||
signal.throwIfAborted();
|
||||
lease = await installation.openCommand({ signal });
|
||||
const environment = await antigravityPrivateEnvironment(home);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { antigravityNativeDistributionSpec } from "./antigravity-installation.js";
|
||||
import { resolveRunnerProviderAssetsRoot } from "./provider-assets-root.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
@@ -131,3 +132,19 @@ it("rejects an unrelated server manifest, escaped vendor sidecar and linked mani
|
||||
await symlink(join(outside, "package.json"), join(path, "package.json"));
|
||||
expect(() => resolveRunnerProviderAssetsRoot(pathToFileURL(join(path, "dist/vendor/paperclip-runner/drivers/acpx/pi-installation.js")).href, "pi")).toThrow();
|
||||
});
|
||||
|
||||
it("resolves explicit providerPackageRoot for bundled server runtimes and Antigravity closures without env mutation", async () => {
|
||||
vi.stubEnv("PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT", undefined);
|
||||
vi.stubEnv("PAPERCLIP_ACPX_PROVIDER_PACKAGE_MANIFEST", undefined);
|
||||
const pack = await root();
|
||||
await writeFile(join(pack, "package.json"), JSON.stringify({ name: "@paperclipai/paperclip-runner" }));
|
||||
await mkdir(join(pack, "provider-assets/antigravity/linux-x64"), { recursive: true });
|
||||
expect(resolveRunnerProviderAssetsRoot("file:///app/server/dist-runtime/index.mjs", "antigravity", { providerPackageRoot: pack }))
|
||||
.toBe(join(pack, "provider-assets/antigravity"));
|
||||
expect(antigravityNativeDistributionSpec("linux", "x64", { providerPackageRoot: pack }).distributionRoot)
|
||||
.toBe(join(pack, "provider-assets/antigravity/linux-x64"));
|
||||
// Explicit invalid roots fail closed instead of falling back to process.env.
|
||||
vi.stubEnv("PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT", pack);
|
||||
expect(() => resolveRunnerProviderAssetsRoot("file:///app/server/dist-runtime/index.mjs", "antigravity", { providerPackageRoot: "relative" }))
|
||||
.toThrow("normalized absolute");
|
||||
});
|
||||
@@ -17,11 +17,23 @@ function assertServerVendorLayout(root: string): void {
|
||||
if (!info.isFile() || info.isSymbolicLink() || realpathSync(sidecar) !== sidecar) throw new Error("Runner server vendor sidecar is invalid");
|
||||
}
|
||||
|
||||
export type RunnerProviderAssetsRootOptions = {
|
||||
providerPackageRoot?: string;
|
||||
providerPackageManifest?: string;
|
||||
};
|
||||
|
||||
/** Resolve only runner-owned package assets, including descriptor-loaded sidecars. */
|
||||
export function resolveRunnerProviderAssetsRoot(moduleUrl: string, provider: NativeProvider): string {
|
||||
export function resolveRunnerProviderAssetsRoot(
|
||||
moduleUrl: string,
|
||||
provider: NativeProvider,
|
||||
options?: RunnerProviderAssetsRootOptions,
|
||||
): string {
|
||||
if (!(NATIVE_ASSET_PROVIDERS as readonly string[]).includes(provider)) throw new Error("Unknown native ACP provider assets");
|
||||
const boundRoot = process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT;
|
||||
const boundManifest = process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_MANIFEST;
|
||||
const explicitRoot = options?.providerPackageRoot;
|
||||
const boundRoot = explicitRoot !== undefined ? explicitRoot : process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT;
|
||||
const boundManifest = explicitRoot !== undefined
|
||||
? options?.providerPackageManifest
|
||||
: process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_MANIFEST;
|
||||
let packageRoot: string;
|
||||
if (boundRoot !== undefined) {
|
||||
const root = normalizedAbsolute(boundRoot);
|
||||
|
||||
@@ -147,3 +147,19 @@ it("allows another provider launch while the original cleanup still cannot journ
|
||||
expect(mocks.discover).toHaveBeenCalledTimes(2);
|
||||
expect(mocks.cleanup).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it("forwards PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH to model discovery and rejects non-normalized paths", async () => {
|
||||
try {
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "/opt/paperclip-runner/provider-pack/");
|
||||
mocks.discover.mockResolvedValueOnce({ models: [{ id: "gemini-3.8-flash-high", label: "Gemini 3.8 Flash (High)" }], defaultModelId: "gemini-3.8-flash-high" });
|
||||
await antigravityConnectionModels({} as never, input);
|
||||
expect(mocks.discover).toHaveBeenLastCalledWith("/private/selected-google-home", { providerPackageRoot: "/opt/paperclip-runner/provider-pack" });
|
||||
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "/opt/paperclip-runner/../etc");
|
||||
mocks.discover.mockResolvedValueOnce({ models: [{ id: "gemini-3.8-flash-high", label: "Gemini 3.8 Flash (High)" }], defaultModelId: "gemini-3.8-flash-high" });
|
||||
await antigravityConnectionModels({} as never, input);
|
||||
expect(mocks.discover).toHaveBeenLastCalledWith("/private/selected-google-home");
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import path from "node:path";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import { antigravityApiKeyModels, type AiConnectionBinding } from "@paperclipai/shared";
|
||||
import { AntigravityModelDiscoveryCleanupError, discoverAntigravityModels } from "../vendor/paperclip-runner/index.js";
|
||||
@@ -7,6 +8,13 @@ import { prepareManagedAiRuntime } from "./ai-connection-runtime.js";
|
||||
import { RetiredCredentialRecoveryError } from "./quota-credential-recovery.js";
|
||||
import { retainGoogleCredentialCleanup } from "./retained-google-credential-cleanup.js";
|
||||
|
||||
function configuredRemoteProviderPackRoot(): string | undefined {
|
||||
const raw = process.env.PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH?.trim();
|
||||
if (!raw || raw.includes("\0") || !path.isAbsolute(raw)) return undefined;
|
||||
const trimmed = raw.replace(/\/+$/, "") || "/";
|
||||
return path.resolve(trimmed) === trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
/** A Google API key's catalog does not depend on the key or the environment:
|
||||
* the pinned runtime builds it locally. Suggestions only; an explicit model id
|
||||
* stays accepted and native admission decides. */
|
||||
@@ -41,7 +49,12 @@ export async function antigravityConnectionModels(db: Db, input: {
|
||||
if (runtime.attribution.method !== "subscription") return antigravityApiKeyModelCatalog();
|
||||
const home = runtime.config.env.GEMINI_HOME;
|
||||
if (typeof home !== "string" || !home) throw unprocessable("The selected Google runtime account is unavailable.");
|
||||
try { return (await discoverAntigravityModels(home)).models; }
|
||||
const providerPackageRoot = configuredRemoteProviderPackRoot();
|
||||
try {
|
||||
return (await (providerPackageRoot
|
||||
? discoverAntigravityModels(home, { providerPackageRoot })
|
||||
: discoverAntigravityModels(home))).models;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof AntigravityModelDiscoveryCleanupError) {
|
||||
// The native owner retains the live child and immutable command lease.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
startAntigravityBrowserLogin: vi.fn(() => ({ abort: async () => undefined })),
|
||||
}));
|
||||
|
||||
vi.mock("../vendor/paperclip-runner/index.js", () => ({
|
||||
resolveCodexCommand: vi.fn(),
|
||||
startAntigravityBrowserLogin: mocks.startAntigravityBrowserLogin,
|
||||
}));
|
||||
|
||||
import { startLocalBrowserLogin } from "./local-ai-browser-login.js";
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("startLocalBrowserLogin (google)", () => {
|
||||
it("forwards normalized PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH to startAntigravityBrowserLogin", () => {
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "/opt/paperclip-runner/provider-pack/");
|
||||
startLocalBrowserLogin("google", "/tmp/google-login-home");
|
||||
expect(mocks.startAntigravityBrowserLogin).toHaveBeenCalledExactlyOnceWith("/tmp/google-login-home", {
|
||||
providerPackageRoot: "/opt/paperclip-runner/provider-pack",
|
||||
});
|
||||
});
|
||||
|
||||
it("omits providerPackageRoot when PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH is unset or non-normalized", () => {
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "");
|
||||
startLocalBrowserLogin("google", "/tmp/google-login-home");
|
||||
expect(mocks.startAntigravityBrowserLogin).toHaveBeenLastCalledWith("/tmp/google-login-home");
|
||||
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "/opt/paperclip-runner/../etc");
|
||||
startLocalBrowserLogin("google", "/tmp/google-login-home");
|
||||
expect(mocks.startAntigravityBrowserLogin).toHaveBeenLastCalledWith("/tmp/google-login-home");
|
||||
|
||||
vi.stubEnv("PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH", "relative/pack");
|
||||
startLocalBrowserLogin("google", "/tmp/google-login-home");
|
||||
expect(mocks.startAntigravityBrowserLogin).toHaveBeenLastCalledWith("/tmp/google-login-home");
|
||||
});
|
||||
});
|
||||
@@ -47,9 +47,21 @@ _, status = os.waitpid(pid, 0)
|
||||
sys.exit(os.waitstatus_to_exitcode(status))
|
||||
`;
|
||||
|
||||
function configuredRemoteProviderPackRoot(): string | undefined {
|
||||
const raw = process.env.PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH?.trim();
|
||||
if (!raw || raw.includes("\0") || !path.isAbsolute(raw)) return undefined;
|
||||
const trimmed = raw.replace(/\/+$/, "") || "/";
|
||||
return path.resolve(trimmed) === trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
/** Run the same browser-code login used by sandbox connections on the local host. */
|
||||
export function startLocalBrowserLogin(provider: "anthropic" | "openai" | "google", home: string): LocalBrowserLoginState {
|
||||
if (provider === "google") return startAntigravityBrowserLogin(home);
|
||||
if (provider === "google") {
|
||||
const providerPackageRoot = configuredRemoteProviderPackRoot();
|
||||
return providerPackageRoot
|
||||
? startAntigravityBrowserLogin(home, { providerPackageRoot })
|
||||
: startAntigravityBrowserLogin(home);
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const state: LocalBrowserLoginState = { abort: () => controller.abort() };
|
||||
const args = provider === "anthropic" ? ["setup-token"] : ["login", "--device-auth"];
|
||||
|
||||
Reference in new issue
Block a user