mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
Verify onboarding models and explain provider failures (#23563)
Verify deployment-configured model preferences with the selected account. Preserve structured provider failures and show descriptive messages for known causes through the existing onboarding error display. Keep the existing failure buttons, account binding, and retry/sign-in behavior. Validation: UI typecheck, 38 focused tests, four browser journeys, all applicable CI checks, and Greptile 5/5 with no unresolved review comments. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
b066a3ddd3
commit
6e340a3f96
17 files changed
+394
-20
No files matched your search
@@ -63,6 +63,14 @@ function createApp(
|
||||
}
|
||||
|
||||
describe("GET /health", () => {
|
||||
it("exposes only valid deployment model preferences to the onboarding client", async () => {
|
||||
const app = createApp(undefined, testServerInfo, undefined, {
|
||||
PAPERCLIP_ONBOARDING_MODELS: '{"example_local":["preferred","compatible"]}',
|
||||
});
|
||||
const res = await request(app).get("/health");
|
||||
expect(res.body.onboardingModels).toEqual({ example_local: ["preferred", "compatible"] });
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockReadPersistedDevServerStatus.mockReturnValue(undefined);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { supportsHostedGoogleAiLogin, supportsLocalAiLogin } from "../services/local-ai-login-policy.js";
|
||||
import { randomUUID, timingSafeEqual } from "node:crypto";
|
||||
import { Router } from "express";
|
||||
import { onboardingModels } from "../services/onboarding-models.js";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import { and, count, eq, gt, inArray, isNull, sql } from "drizzle-orm";
|
||||
import { heartbeatRuns, instanceUserRoles, invites } from "@paperclipai/db";
|
||||
@@ -244,6 +245,7 @@ export function healthRoutes(
|
||||
const healthStatus =
|
||||
startupRecovery.phase === "ready" ? "ok" : "starting";
|
||||
const cloud = getCloudHealthStatus(runtimeEnv);
|
||||
const preferredOnboardingModels = onboardingModels(runtimeEnv);
|
||||
// Operator-hidden settings ride every response (like `cloud`): the list
|
||||
// holds UI surface names only, and the settings nav needs it before any
|
||||
// fuller-detail fetch. Omitted entirely when nothing is hidden, so
|
||||
@@ -283,6 +285,7 @@ export function healthRoutes(
|
||||
serverVersion: serverVersion,
|
||||
commit,
|
||||
serverInfo,
|
||||
...(Object.keys(preferredOnboardingModels).length ? { onboardingModels: preferredOnboardingModels } : {}),
|
||||
...(cloud ? { cloud } : {}),
|
||||
...(hiddenSettings.length ? { hiddenSettings } : {}),
|
||||
}
|
||||
@@ -434,6 +437,7 @@ export function healthRoutes(
|
||||
res.json({
|
||||
status: healthStatus,
|
||||
version: serverVersion,
|
||||
...(Object.keys(preferredOnboardingModels).length ? { onboardingModels: preferredOnboardingModels } : {}),
|
||||
serverVersion,
|
||||
commit,
|
||||
deploymentMode: opts.deploymentMode,
|
||||
|
||||
@@ -14,6 +14,7 @@ import { resolveAcpxQualification } from "./acpx-qualification.js";
|
||||
import { antigravityConnectionRefusal } from "./antigravity-connection-policy.js";
|
||||
import { antigravityReleasePending } from "./antigravity-release.js";
|
||||
import { isRunnerRevisionMismatch, runnerRevisionMismatchTestResult } from "../runner-revision-mismatch.js";
|
||||
import { setupProbeFailure } from "./setup-probe-failure.js";
|
||||
|
||||
/** Core verifies a real Runner; providers only implement their task API. */
|
||||
export async function probePluginRunnerEnvironment(context: AdapterEnvironmentTestContext,
|
||||
@@ -101,7 +102,7 @@ export async function probePluginRunnerEnvironment(context: AdapterEnvironmentTe
|
||||
if (isRunnerRevisionMismatch(error)) return runnerRevisionMismatchTestResult("paperclip_runner", testedAt);
|
||||
// Provider failures may contain credentials or private addressing.
|
||||
return { adapterType: "paperclip_runner", status: "fail", testedAt,
|
||||
checks: [{ code: "runner_hello_probe_failed", level: "error", message: "The selected plugin environment did not complete the Runner hello probe and confirmed cleanup. Check its runtime, account, and model access." }] };
|
||||
checks: [setupProbeFailure(error)] };
|
||||
} finally {
|
||||
if (!probeStarted || cleanupConfirmed) rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { setupProbeFailure } from "./setup-probe-failure.js";
|
||||
|
||||
it.each(["model_unavailable", "authentication", "permission", "quota_exhausted", "rate_limit", "overloaded", "timeout"])(
|
||||
"preserves the actionable %s category without exposing provider diagnostics", category => {
|
||||
const failure = { schema: "paperclip.provider-failure.v1", provider: "anthropic", phase: "turn", category,
|
||||
retryability: "requires_action", message: "private account at https://internal.example credential=fixture-secret" };
|
||||
const error = Object.assign(new Error(failure.message), { providerFailure: failure });
|
||||
const check = setupProbeFailure(new Error("wrapped", { cause: error }));
|
||||
expect(check).toMatchObject({ code: `runner_hello_probe_${category === "authentication" ? "auth_required" : category}`, level: "error" });
|
||||
expect(JSON.stringify(check)).not.toMatch(/internal\.example|fixture-secret|private account/);
|
||||
expect(check.message).not.toMatch(/another subscription|change provider|reconnect|saved credentials/i);
|
||||
},
|
||||
);
|
||||
it("does not infer plan restrictions from arbitrary errors", () => {
|
||||
expect(setupProbeFailure(new Error("model_not_found https://private.example")))
|
||||
.toMatchObject({ code: "runner_hello_probe_failed" });
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { providerFailureFromError } from "../../vendor/paperclip-runner/index.js";
|
||||
import type { AdapterEnvironmentCheck } from "@paperclipai/adapter-utils";
|
||||
|
||||
export function setupProbeFailure(error: unknown): AdapterEnvironmentCheck {
|
||||
const failure = providerFailureFromError(error);
|
||||
const messages = {
|
||||
model_unavailable: "Your account does not have access to the selected model.",
|
||||
authentication: "Your sign-in could not be verified. Please sign in again.",
|
||||
permission: "Your account does not have permission to make this request.",
|
||||
quota_exhausted: "Your account has no usage remaining. Check your plan's limits or available credits.",
|
||||
rate_limit: "Your account is temporarily rate limited. Please wait before trying again.",
|
||||
overloaded: "The provider is temporarily unavailable. Please try again shortly.",
|
||||
timeout: "The provider did not respond in time. Please try again.",
|
||||
};
|
||||
if (failure && failure.category in messages) {
|
||||
const category = failure.category as keyof typeof messages;
|
||||
return { code: `runner_hello_probe_${category === "authentication" ? "auth_required" : category}`,
|
||||
level: "error", message: messages[category] };
|
||||
}
|
||||
return { code: "runner_hello_probe_failed", level: "error",
|
||||
message: "Paperclip could not verify your account. Please try again." };
|
||||
}
|
||||
@@ -457,6 +457,25 @@ describe("Codex selected native account verification", () => {
|
||||
expect(nativeProbe).toHaveBeenCalledOnce();
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
});
|
||||
it.each(["local", "ssh"].flatMap(transport =>
|
||||
["model_unavailable", "authentication", "permission", "quota_exhausted"].map(category => [transport, category]),
|
||||
))("preserves structured %s probe failures for subscription recovery (%s)", async (transport, category) => {
|
||||
const providerFailure = { schema: "paperclip.provider-failure.v1", provider: "codex", phase: "turn", category,
|
||||
retryability: "requires_action", message: "private provider diagnostic bound-account" };
|
||||
nativeProbe.mockImplementation(async input => {
|
||||
await input.onCleanupConfirmed();
|
||||
throw new Error("native probe failed", { cause: Object.assign(new Error(providerFailure.message), { providerFailure }) });
|
||||
});
|
||||
const selectedContext = transport === "ssh" ? sshContext : { companyId: "company", adapterType: "paperclip_runner", config: {} };
|
||||
const result = await testNativeRunnerAuthentication({ ...selectedContext, config: { env: { OPENAI_API_KEY: "bound-account" } } }, "codex", "gpt-6.1-sol");
|
||||
expect(result.status).toBe("fail");
|
||||
expect(result.checks[0]).toMatchObject({ code: `runner_hello_probe_${category === "authentication" ? "auth_required" : category}`, level: "error" });
|
||||
expect(result.checks.some(check => check.code === ADAPTER_AUTH_MISSING_CHECK_CODE)).toBe(category === "authentication");
|
||||
expect(JSON.stringify(result)).not.toMatch(/private provider diagnostic|bound-account/);
|
||||
expect(nativeProbe).toHaveBeenCalledOnce();
|
||||
expect(transport === "ssh" ? selectedRemoteRunner : selectedRunner).toHaveBeenCalledOnce();
|
||||
await expect(stat(nativeProbeRuntimeDirectories[0]!)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
it("names the ChatGPT retirement when the backend rejects a retired model", async () => {
|
||||
nativeProbe.mockRejectedValue(new Error(JSON.stringify({ type: "error", status: 400,
|
||||
error: { type: "invalid_request_error", message: "The 'gpt-5.5' model is not supported when using Codex with a ChatGPT account." } })));
|
||||
|
||||
@@ -13,6 +13,7 @@ import { readRemoteUserHome } from "./remote-user-home.js";
|
||||
import { createNativeSshCommandRunner } from "./native-ssh-command-runner.js";
|
||||
import { resolvePaperclipRunnerTransport } from "@paperclipai/adapter-utils/runner-connectivity";
|
||||
import { createNativeRunnerExecutionDriver } from "./native-runner-execution-driver.js";
|
||||
import { setupProbeFailure } from "./setup-probe-failure.js";
|
||||
|
||||
|
||||
const PROBE_TRANSPORT_ENV_KEYS = ["PATH", "LANG", "LANGUAGE", "TZ", "TMPDIR", "TEMP", "TMP", "SSL_CERT_FILE", "SSL_CERT_DIR", "NODE_EXTRA_CA_CERTS", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "ALL_PROXY", "http_proxy", "https_proxy", "no_proxy", "all_proxy"];
|
||||
@@ -264,11 +265,14 @@ export async function testNativeRunnerAuthentication(context: AdapterEnvironment
|
||||
message: `The native ${provider} runtime verified the selected account and model in ${remote ? "the selected environment" : "the Paperclip host"}.` }] };
|
||||
} catch (error) {
|
||||
if (error instanceof NativeEnvironmentProbeCleanupError) throw error;
|
||||
const message = redactNativeProbeMessage(error instanceof Error ? error.message : "The selected native runtime could not verify this account.", { ...environment, ...(sourceAuthJson ? { [authKey]: sourceAuthJson } : {}) });
|
||||
const authentication = /(?:invalid (?:api[- ]?key|auth(?:entication)? token)|authentication (?:failed|required)|unauthenticated|unauthorized|not authenticated|please (?:log|sign) in|not logged in|\b(?:401|403)\b)/i.test(message);
|
||||
const failure = setupProbeFailure(error);
|
||||
const classified = failure.code !== "runner_hello_probe_failed";
|
||||
const message = classified ? failure.message : redactNativeProbeMessage(error instanceof Error ? error.message : "The selected native runtime could not verify this account.", { ...environment, ...(sourceAuthJson ? { [authKey]: sourceAuthJson } : {}) });
|
||||
const authentication = classified ? failure.code === "runner_hello_probe_auth_required"
|
||||
: /(?:invalid (?:api[- ]?key|auth(?:entication)? token)|authentication (?:failed|required)|unauthenticated|unauthorized|not authenticated|please (?:log|sign) in|not logged in|\b(?:401|403)\b)/i.test(message);
|
||||
const rejectedModel = provider === "codex" ? CODEX_CHATGPT_MODEL_REJECTION_RE.exec(message)?.[1] : undefined;
|
||||
const retirementHint = rejectedModel ? codexChatGptRetirementHint(rejectedModel) : null;
|
||||
return { adapterType: "paperclip_runner", status: "fail", testedAt: new Date().toISOString(), checks: [{ code: `${provider}_hello_probe_${authentication ? "auth_required" : /timed out/i.test(message) ? "timeout" : "failed"}`, level: "error", message,
|
||||
return { adapterType: "paperclip_runner", status: "fail", testedAt: new Date().toISOString(), checks: [classified ? failure : { code: `${provider}_hello_probe_${authentication ? "auth_required" : /timed out/i.test(message) ? "timeout" : "failed"}`, level: "error", message,
|
||||
hint: retirementHint ?? "Check the selected account, model access, and native runtime prerequisites, then retry." },
|
||||
...(authentication && provider === "codex" ? [{ code: ADAPTER_AUTH_MISSING_CHECK_CODE, level: "error" as const,
|
||||
message: "The selected Codex account needs authentication.",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { onboardingModels } from "./onboarding-models.js";
|
||||
|
||||
it("leaves deployments without preferences on their normal adapter defaults", () => {
|
||||
expect(onboardingModels({})).toEqual({});
|
||||
});
|
||||
it("reads fresh deployment preferences without provider or plan policy in Core", () => {
|
||||
const env = { PAPERCLIP_ONBOARDING_MODELS: '{"example_local":["preferred","backup","preferred"]}' };
|
||||
expect(onboardingModels(env)).toEqual({ example_local: ["preferred", "backup"] });
|
||||
env.PAPERCLIP_ONBOARDING_MODELS = '{"example_local":["replacement"]}';
|
||||
expect(onboardingModels(env)).toEqual({ example_local: ["replacement"] });
|
||||
});
|
||||
it.each(["null", "[]", "invalid", '{"adapter":[]}', '{"adapter":[1]}', '{"adapter":["https://private.example"]}',
|
||||
'{"adapter":["one","two","three","four"]}', " ".repeat(8193)])("rejects malformed or unbounded preferences %#", raw => {
|
||||
expect(onboardingModels({ PAPERCLIP_ONBOARDING_MODELS: raw })).toEqual({});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
export function onboardingModels(env: Record<string, string | undefined>): Record<string, string[]> {
|
||||
const raw = env.PAPERCLIP_ONBOARDING_MODELS;
|
||||
if (!raw || raw.length > 8_192) return {};
|
||||
try {
|
||||
const value: unknown = JSON.parse(raw);
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
||||
const entries = Object.entries(value);
|
||||
if (entries.length > 16 || entries.some(([harness, models]) =>
|
||||
!/^[a-z][a-z0-9_]{0,63}$/.test(harness) || !Array.isArray(models) || !models.length || models.length > 3
|
||||
|| models.some(model => typeof model !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._/\[\]-]{0,159}$/.test(model)),
|
||||
)) return {};
|
||||
return Object.fromEntries(entries.map(([harness, models]) => [harness, [...new Set(models as string[])]]));
|
||||
} catch { return {}; }
|
||||
}
|
||||
Reference in new issue
Block a user