mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 20:09:10 +01:00
fix(antigravity): resolve the hosted runtime in one place and report sign-in failures plainly (#22990)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Google Antigravity agents can sign in with a Google subscription. On hosted public deployments the server starts the pinned Antigravity runtime and relays the pasted loopback redirect (#22932). > - The server looked for that runtime only in the server package's vendored assets and the OS-account cache. The Docker image keeps the verified closure in the build-owned provider pack (`PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`). > - So every hosted attempt failed before the runtime started, and the page showed "Google sign-in did not complete. Start sign-in again." with no sign-in link. Every failure reason became that one message, and nothing was logged. > - #22983 added the pack lookup as an option that each caller had to pass. That leaves several search paths that can drift: installation verification still used none. > - This pull request moves the pack lookup into the one canonical resolver, gives sign-in failures a typed reason with one plain-language message each, and logs a secret-free reason code. > - The benefit is that sign-in, model discovery and installation verification always find the same verified runtime, and a server without the runtime says why. ## Linked Issues or Issue Description Refs #22932, Refs #22983 **Describe the bug** On a hosted authenticated public deployment, the user chooses Google Antigravity and then "Google Subscription". The page immediately shows "Google sign-in did not complete. Start sign-in again." `POST .../ai-connections/local/attempts` returns 201, and every `POST .../ai-connections/local/check` returns `sign_in_required` with the same message and no `authorizationUrl`. **Steps to reproduce** 1. Run the standard image as an authenticated public deployment. Do not create an Antigravity runtime cache in the server account. 2. Create an agent with Google Antigravity and choose Google Subscription. 3. See the error before any sign-in step runs. **Expected behavior** The server starts the pinned runtime from the image's provider pack and shows the Google sign-in link. If the server has no runtime, the message says so in plain language and does not tell the user to start again. **Root cause** `antigravityNativeDistributionSpec()` resolved `<server>/dist/vendor/paperclip-runner/provider-assets/antigravity/<target>` and then `$HOME/.paperclip/runtimes/antigravity/<target>/<closure>`. The image ships the closure at `$PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH/provider-assets/antigravity/linux-x64`. `startAntigravityBrowserLogin` caught every failure with a bare `catch` and showed the generic message. The #22932 tests mocked both the runtime resolution and the installation check. ## What Changed - Runner: `antigravityNativeDistributionSpec` is the one resolver for every caller. The search order is: the runner package's own assets (runnerd binds Runner children to the selected pack with `PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT`), then the deployment provider pack from `PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`, then the OS-account cache. The pack root must be a normalized absolute path. The pack goes through the manifest and link checks of `resolveRunnerProviderAssetsRoot` from #22983. The pinned closure digest check is unchanged. - Runner: the `providerPackageRoot` option on `startAntigravityBrowserLogin`, `discoverAntigravityModels` and `antigravityNativeDistributionSpec` is removed. The server no longer reads the pack path. - Runner: sign-in failures have a typed reason (`runtime_unavailable`, `start_failed`, `login_incomplete`, `aborted`). One table maps each reason to its message. A missing runtime reports "This server does not have the current Google Antigravity runtime, so Google sign-in cannot start. Use a Google API key instead, or update Paperclip on this server." - Runner: model discovery throws `AntigravityRuntimeUnavailableError` when the runtime is missing. The server shows a plain-language message for it instead of "Could not load models for this Google account". - Server: sign-in failures, except cancelled attempts, are logged with a secret-free code such as `ANTIGRAVITY_SIGN_IN_RUNTIME_UNAVAILABLE`. A missing runtime during model discovery is logged as `ANTIGRAVITY_RUNTIME_UNAVAILABLE`. ## Verification - Red on master, green on this branch: - `antigravity-installation.test.ts`: pack resolution, precedence, cache fallback, link and path refusal, and one test that binds sign-in, model discovery and `verifyAntigravityInstallation` to the same pack with no vendored assets. - `antigravity-auth.test.ts`: one test for each failure reason and its message. - `antigravity-models.test.ts`: a missing runtime gives `AntigravityRuntimeUnavailableError` without a launch. - `pnpm --filter @paperclipai/paperclip-runner exec vitest run` on the antigravity auth, stream-order, installation, models and provider-assets-root suites: 76 of 76 pass. - `server/src/__tests__/local-ai-browser-login-google.test.ts`, `antigravity-connection-models.test.ts` and `antigravity-local-ai-login.test.ts`: 33 of 33 pass. - The runner `tsc --noEmit` and the server `tsc --noEmit` pass. - `node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check` reports no registry change. - `pnpm verify` returned exit 2 (runner test files are outside the resolved test graphs). Required CI supplies the broad coverage. - Not run: a live Google sign-in against the real closure in a hosted image. That needs a deploy and a real Google account. ## Risks - Low risk. The pack is used only when the packaged assets are absent and the pack contains the target. A modified pack still fails the pinned closure check. - A pack root that is relative or contains `..` now fails as "runtime unavailable" instead of being ignored silently. - Error text changes only for failures before the runtime initializes. > 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 - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, test runs). ## 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 - [x] 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>
This commit is contained in:
1 parent
cb39f99a39
commit
304854ee99
15 files changed
+297
-126
No files matched your search
@@ -5,6 +5,9 @@ const mocks = vi.hoisted(() => ({ managed: vi.fn(), discover: vi.fn(), cleanup:
|
||||
CleanupError: class extends Error {
|
||||
constructor(readonly retired: Promise<void>) { super("cleanup pending"); }
|
||||
},
|
||||
UnavailableError: class extends Error {
|
||||
readonly code = "ANTIGRAVITY_RUNTIME_UNAVAILABLE";
|
||||
},
|
||||
}));
|
||||
const spawned = vi.hoisted(() => vi.fn());
|
||||
vi.mock("node:child_process", async original => {
|
||||
@@ -16,6 +19,7 @@ vi.mock("../services/ai-connection-runtime.js", () => ({ prepareManagedAiRuntime
|
||||
vi.mock("../middleware/logger.js", () => ({ logger: { warn: mocks.warn } }));
|
||||
vi.mock("../vendor/paperclip-runner/index.js", () => ({
|
||||
discoverAntigravityModels: mocks.discover, AntigravityModelDiscoveryCleanupError: mocks.CleanupError,
|
||||
AntigravityRuntimeUnavailableError: mocks.UnavailableError,
|
||||
}));
|
||||
import { antigravityConnectionModels } from "../services/antigravity-connection-models.js";
|
||||
import { RetiredCredentialRecoveryError } from "../services/quota-credential-recovery.js";
|
||||
@@ -45,6 +49,14 @@ it("uses the selected account lifecycle and returns only its model catalog", asy
|
||||
expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith();
|
||||
});
|
||||
|
||||
it("reports a missing server runtime plainly and logs its reason code", async () => {
|
||||
mocks.discover.mockRejectedValueOnce(new mocks.UnavailableError("runtime missing"));
|
||||
await expect(antigravityConnectionModels({} as never, input)).rejects.toThrow(
|
||||
"This server does not have the current Google Antigravity runtime, so Google account models cannot load. Use a Google API key instead, or update Paperclip on this server.");
|
||||
expect(mocks.warn).toHaveBeenCalledWith({ companyId: "company", code: "ANTIGRAVITY_RUNTIME_UNAVAILABLE" }, "Antigravity model discovery runtime is unavailable");
|
||||
expect(mocks.cleanup).toHaveBeenCalledExactlyOnceWith();
|
||||
});
|
||||
|
||||
it("returns the pinned API-key catalog for a Gemini API key without preparing a credential or starting a process", async () => {
|
||||
const models = await antigravityConnectionModels({} as never, { ...input, binding: { provider: "google", method: "api_key", mode: "responsible_user" } });
|
||||
expect(models.map(model => model.id)).toEqual(antigravityApiKeyModels().map(model => model.id));
|
||||
@@ -147,19 +159,3 @@ 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();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const runner = vi.hoisted(() => ({ warn: vi.fn(), start: vi.fn((_home: string, _options?: { onFailure?: (reason: string) => void }) => ({ abort: async () => undefined })) }));
|
||||
vi.mock("../middleware/logger.js", () => ({ logger: { warn: runner.warn } }));
|
||||
vi.mock("../vendor/paperclip-runner/index.js", () => ({ resolveCodexCommand: vi.fn(), startAntigravityBrowserLogin: runner.start }));
|
||||
vi.mock("@paperclipai/adapter-claude-local/server", () => ({ runSetupTokenLogin: vi.fn() }));
|
||||
vi.mock("@paperclipai/adapter-codex-local/server", () => ({ runDeviceLogin: vi.fn() }));
|
||||
import { startLocalBrowserLogin } from "../services/local-ai-browser-login.js";
|
||||
|
||||
afterEach(() => { vi.clearAllMocks(); });
|
||||
|
||||
describe("server-host Google sign-in failure logging", () => {
|
||||
it.each([
|
||||
["runtime_unavailable", "ANTIGRAVITY_SIGN_IN_RUNTIME_UNAVAILABLE"],
|
||||
["start_failed", "ANTIGRAVITY_SIGN_IN_START_FAILED"],
|
||||
["login_incomplete", "ANTIGRAVITY_SIGN_IN_LOGIN_INCOMPLETE"],
|
||||
])("logs %s by its secret-free reason code", (reason, code) => {
|
||||
startLocalBrowserLogin("google", "/tmp/attempt");
|
||||
runner.start.mock.calls[0]![1]!.onFailure!(reason);
|
||||
expect(runner.warn).toHaveBeenCalledExactlyOnceWith({ code }, "Google Antigravity sign-in failed");
|
||||
});
|
||||
|
||||
it("does not log a cancelled attempt", () => {
|
||||
startLocalBrowserLogin("google", "/tmp/attempt");
|
||||
runner.start.mock.calls[0]![1]!.onFailure!("aborted");
|
||||
expect(runner.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,20 +1,12 @@
|
||||
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";
|
||||
import { AntigravityModelDiscoveryCleanupError, AntigravityRuntimeUnavailableError, discoverAntigravityModels } from "../vendor/paperclip-runner/index.js";
|
||||
import { unprocessable } from "../errors.js";
|
||||
import { logger } from "../middleware/logger.js";
|
||||
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. */
|
||||
@@ -49,13 +41,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.");
|
||||
const providerPackageRoot = configuredRemoteProviderPackRoot();
|
||||
try {
|
||||
return (await (providerPackageRoot
|
||||
? discoverAntigravityModels(home, { providerPackageRoot })
|
||||
: discoverAntigravityModels(home))).models;
|
||||
}
|
||||
try { return (await discoverAntigravityModels(home)).models; }
|
||||
catch (error) {
|
||||
if (error instanceof AntigravityRuntimeUnavailableError) {
|
||||
logger.warn({ companyId: input.companyId, code: error.code }, "Antigravity model discovery runtime is unavailable");
|
||||
throw unprocessable("This server does not have the current Google Antigravity runtime, so Google account models cannot load. Use a Google API key instead, or update Paperclip on this server.", { code: error.code });
|
||||
}
|
||||
if (error instanceof AntigravityModelDiscoveryCleanupError) {
|
||||
// The native owner retains the live child and immutable command lease.
|
||||
// Keep this selected credential home until that owner proves retirement.
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import { runSetupTokenLogin } from "@paperclipai/adapter-claude-local/server";
|
||||
import { runDeviceLogin } from "@paperclipai/adapter-codex-local/server";
|
||||
import { ensureCommandResolvable, resolveCommandForLogs } from "@paperclipai/adapter-utils/server-utils";
|
||||
import { resolveCodexCommand, startAntigravityBrowserLogin } from "../vendor/paperclip-runner/index.js";
|
||||
import { logger } from "../middleware/logger.js";
|
||||
|
||||
export type LocalBrowserLoginState = {
|
||||
authorizationUrl?: string;
|
||||
@@ -47,20 +48,14 @@ _, 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") {
|
||||
const providerPackageRoot = configuredRemoteProviderPackRoot();
|
||||
return providerPackageRoot
|
||||
? startAntigravityBrowserLogin(home, { providerPackageRoot })
|
||||
: startAntigravityBrowserLogin(home);
|
||||
return startAntigravityBrowserLogin(home, {
|
||||
onFailure: (reason) => {
|
||||
if (reason !== "aborted") logger.warn({ code: `ANTIGRAVITY_SIGN_IN_${reason.toUpperCase()}` }, "Google Antigravity sign-in failed");
|
||||
},
|
||||
});
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const state: LocalBrowserLoginState = { abort: () => controller.abort() };
|
||||
|
||||
+2
@@ -10,6 +10,7 @@
|
||||
type RunnerModule = typeof import("@paperclipai/paperclip-runner");
|
||||
|
||||
export type {
|
||||
AntigravityBrowserLoginFailureReason,
|
||||
AntigravityBrowserLoginState,
|
||||
GeneratedAntigravitySwarmChannel,
|
||||
GeneratedAntigravitySwarmCredentialFacts,
|
||||
@@ -244,6 +245,7 @@ export const GENERATED_ANTIGRAVITY_SWARM_DEFAULT_CHANNEL = runner.GENERATED_ANTI
|
||||
export const readGeneratedAntigravitySwarmCredentialFacts = runner.readGeneratedAntigravitySwarmCredentialFacts;
|
||||
export const discoverAntigravityModels = runner.discoverAntigravityModels;
|
||||
export const AntigravityModelDiscoveryCleanupError = runner.AntigravityModelDiscoveryCleanupError;
|
||||
export const AntigravityRuntimeUnavailableError = runner.AntigravityRuntimeUnavailableError;
|
||||
export const PROVIDER_PACK_COMPATIBILITY = runner.PROVIDER_PACK_COMPATIBILITY;
|
||||
export const bundledRemoteProviderPackManifestPath = runner.bundledRemoteProviderPackManifestPath;
|
||||
export const bundledRemoteRunnerBinary = runner.bundledRemoteRunnerBinary;
|
||||
|
||||
Reference in new issue
Block a user