mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 04:29:01 +01:00
fix(cloud-trial): do not attach Connect OpenRouter repair card on starter-trial auth failures (#23633)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - When a normal agent fails with a provider authentication error, `connectionIntentService.requestForRunAuthFailure` infers the AI provider from the agent's model and attaches a pending `"Connect <Provider>"` interaction card on the issue thread. > - Cloud starter-inference agents (`runtimeConfig.cloudTrialInference: true`, no saved `aiConnection`) run OpenCode with `openrouter/openai/gpt-6-luna` through Paperclip Cloud's server-side proxy instead of a user-saved OpenRouter connection. > - If a starter-inference run ever encounters an OpenRouter 401 failure, `requestForRunAuthFailure` attached a pending `"Connect OpenRouter"` card, causing the agent to keep nagging the user to respond to that card on subsequent turns even after succeeding. > - This pull request skips `requestForRunAuthFailure` for agents using Cloud starter inference without a saved `aiConnection`, leaving `CloudTrialGate` as the single owner of prompting users to connect a model provider. > - The benefit is that starter-inference chats never accumulate stale `"Connect OpenRouter"` cards. ## Linked Issues or Issue Description Refs #23401, #23616 **Summary** Skip creating a `"Connect OpenRouter"` `connection_intent` card in `requestForRunAuthFailure` when the agent runs on Cloud starter inference (`runtimeConfig.cloudTrialInference: true` without a saved `aiConnection`). **Steps to Reproduce** 1. Run an OpenCode agent configured with `runtimeConfig.cloudTrialInference: true` and `adapterConfig.model: "openrouter/openai/gpt-6-luna"` (no `runtimeConfig.aiConnection`). 2. Trigger an OpenRouter HTTP 401 authentication failure on a run. 3. Observe `requestForRunAuthFailure` creating a pending `"Connect OpenRouter"` `issue_thread_interactions` row on the chat issue. **Expected Behavior** `requestForRunAuthFailure` returns `null` and creates no pending `"Connect OpenRouter"` interaction for Cloud starter-inference agents. ## What Changed - `server/src/services/connection-intents.ts`: Returned `null` in `requestForRunAuthFailure` when `!saved && !router && isAgentUsingCloudTrialInference(agent.runtimeConfig)`. - `server/src/__tests__/connection-intents-service.test.ts`: Added a regression test proving that an OpenRouter 401 failure on a Cloud starter-trial agent returns `null` and creates zero `issue_thread_interactions` rows. ## Verification - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/connection-intents-service.test.ts -t "does not create a Connect OpenRouter card|adopts a Copilot account"` — passed (2/2 tests). - `pnpm --filter @paperclipai/server typecheck` — passed (0 errors). ## Risks - Low risk. Narrow 1-line guard scoped strictly to agents with `runtimeConfig.cloudTrialInference === true` and no saved `aiConnection`. Normal agents with or without saved AI connections keep their exact existing auth-repair behavior. ## Model Used - Google Gemini (Antigravity agentic runtime, thinking mode with tool use and local 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 - [ ] 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
This commit is contained in:
1 parent
63d3354be7
commit
bba20403ba
2 files changed
+72
-1
No files matched your search
@@ -1117,6 +1117,70 @@ describeEmbeddedPostgres("connectionIntentService", () => {
|
||||
expect((await db.select().from(agents).where(eq(agents.id, f.agent.id)))[0]!.runtimeConfig.aiConnection).toMatchObject({ provider: "github", mode: "responsible_user" });
|
||||
});
|
||||
|
||||
it("does not create a Connect OpenRouter card on auth failures for Cloud starter-trial agents", async () => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const runId = randomUUID();
|
||||
const userId = `trial-user-${randomUUID().slice(0, 8)}`;
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Starter Trial Auth Repair Co",
|
||||
issuePrefix: `ST${randomUUID().slice(0, 4).toUpperCase()}`,
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "user",
|
||||
principalId: userId,
|
||||
membershipRole: "owner",
|
||||
status: "active",
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "Starter Chief of Staff",
|
||||
role: "ceo",
|
||||
adapterType: "paperclip_runner",
|
||||
adapterConfig: { provider: "opencode", model: "openrouter/openai/gpt-6-luna" },
|
||||
runtimeConfig: { cloudTrialInference: true },
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
title: "Chat with Starter Chief of Staff",
|
||||
status: "in_progress",
|
||||
assigneeAgentId: agentId,
|
||||
});
|
||||
await db.insert(heartbeatRuns).values({
|
||||
id: runId,
|
||||
companyId,
|
||||
agentId,
|
||||
status: "failed",
|
||||
responsibleUserId: userId,
|
||||
errorCode: "provider_auth_failed",
|
||||
contextSnapshot: { issueId },
|
||||
resultJson: {
|
||||
providerFailure: {
|
||||
schema: "paperclip.provider-failure.v1",
|
||||
provider: "openrouter",
|
||||
phase: "turn",
|
||||
category: "authentication",
|
||||
retryability: "non_retryable",
|
||||
httpStatus: 401,
|
||||
message: "No cookie auth credentials found",
|
||||
},
|
||||
},
|
||||
});
|
||||
const intents = connectionIntentService(db);
|
||||
await expect(intents.requestForRunAuthFailure(runId)).resolves.toBeNull();
|
||||
expect(
|
||||
await db
|
||||
.select()
|
||||
.from(issueThreadInteractions)
|
||||
.where(eq(issueThreadInteractions.issueId, issueId)),
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
async function accessFixture(source = "composio") {
|
||||
const [company] = await db.insert(companies).values({ name: "Grant fixture", issuePrefix: `G${randomUUID().slice(0, 7)}` }).returning();
|
||||
const [agent] = await db.insert(agents).values({ companyId: company.id, name: "Default agent", role: "general", adapterType: "process" }).returning();
|
||||
|
||||
@@ -12,7 +12,13 @@ import { createHash } from "node:crypto";
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import { logActivity } from "./activity-log.js";
|
||||
import { aiConnectionService } from "./ai-connections.js";
|
||||
import { aiConnectionBindingSchema, aiConnectionCatalogSlug, aiConnectionRouterBindingSchema, aiConnectionSourceSlug } from "@paperclipai/shared";
|
||||
import {
|
||||
aiConnectionBindingSchema,
|
||||
aiConnectionCatalogSlug,
|
||||
aiConnectionRouterBindingSchema,
|
||||
aiConnectionSourceSlug,
|
||||
isAgentUsingCloudTrialInference,
|
||||
} from "@paperclipai/shared";
|
||||
import { aiBindingForAuthRecovery, isAiAuthenticationRepairable } from "./ai-auth-failure.js";
|
||||
import {
|
||||
detectUnconfiguredGitHubAuthFailureInEvents,
|
||||
@@ -1541,6 +1547,7 @@ export function connectionIntentService(db: Db) {
|
||||
if (!agent) return null;
|
||||
const saved = aiConnectionBindingSchema.safeParse(agent.runtimeConfig.aiConnection).data;
|
||||
const router = aiConnectionRouterBindingSchema.safeParse(agent.runtimeConfig.aiConnection).data;
|
||||
if (!saved && !router && isAgentUsingCloudTrialInference(agent.runtimeConfig)) return null;
|
||||
const selected = router ? record(run.contextSnapshot?.aiRouterSelection) : null;
|
||||
const managed = router && selected ? await managedAgent(run.companyId, run.agentId, String(record(selected.binding)?.provider), { sourceRunId: run.id }) : null;
|
||||
const binding = router ? managed?.binding : saved ?? aiBindingForAuthRecovery(agent.adapterType, agent.adapterConfig, run);
|
||||
|
||||
Reference in new issue
Block a user