diff --git a/ui/src/components/AgentConfigForm.render.test.tsx b/ui/src/components/AgentConfigForm.render.test.tsx index 3c026d08f0f..d5a2931be4e 100644 --- a/ui/src/components/AgentConfigForm.render.test.tsx +++ b/ui/src/components/AgentConfigForm.render.test.tsx @@ -13,6 +13,8 @@ import { isBlockedFromReplay } from "@/lib/analytics/replay-recording.test-utils import { ApiError } from "../api/client"; import { CodexLocalConfigFields } from "../adapters/codex-local/config-fields"; import type { AdapterConfigFieldsProps } from "../adapters/types"; +import { createAppQueryClient } from "../lib/query-client"; +import type { ConnectivityStore } from "../lib/connectivity"; const mockAgentsApi = vi.hoisted(() => ({ get: vi.fn(), @@ -90,13 +92,16 @@ vi.mock("../adapters", () => ({ }), })); vi.mock("../adapters/use-adapter-capabilities", () => ({ - useAdapterCapabilities: () => () => ({ + useAdapterCapabilities: () => (type: string) => ({ supportsInstructionsBundle: true, supportsSkills: true, supportsLocalAgentJwt: true, requiresMaterializedRuntimeSkills: false, supportsAcp: true, - login: { panelMode: "displayed_code", timeoutPolicy: "caller_bounded" }, + login: { + panelMode: type === "claude_local" ? "submitted_browser_code" : "displayed_code", + timeoutPolicy: "caller_bounded", + }, }), })); vi.mock("../adapters/use-disabled-adapters", () => ({ useDisabledAdaptersSync: () => [] })); @@ -266,6 +271,39 @@ describe("AgentConfigForm session replay masking", () => { expect(container.textContent).toContain("Retry sign in"); }); + it.each([ + ["codex_local", mockAgentsApi.getActiveAdapterAuthLoginSession, mockAgentsApi.startAdapterAuthLogin], + ["claude_local", mockAgentsApi.getActiveClaudeSetupTokenLoginSession, mockAgentsApi.startClaudeSetupTokenLogin], + ])("shows another computer's active %s sign-in without retrying it or reporting it to Sentry", async (adapterType, getActive, start) => { + const container = document.createElement("div"); + const root = createRoot(container); + roots.push(root); + const reportError = vi.fn(); + const client = createAppQueryClient({ + connectivity: { reportError: () => {}, getSnapshot: () => ({ status: "online" }) as ReturnType }, + reportError, + }); + getActive.mockResolvedValue({ + sessionId: "session-other", agentId: "agent-2", environmentId: "sandbox-1", aiConnection: null, + }); + // No stored Claude token: the status route answers 404. + mockAgentsApi.getClaudeOAuthTokenStatus.mockRejectedValue(new ApiError("Not found", 404, null)); + await act(() => root.render( + + + , + )); + await vi.waitFor( + () => expect(container.textContent).toContain("Another sign-in attempt is active."), + { timeout: 10_000 }, + ); + expect(getActive).toHaveBeenCalledTimes(1); + expect(start).not.toHaveBeenCalled(); + expect(reportError).not.toHaveBeenCalled(); + client.clear(); + }, 15_000); + it("blocks the displayed login code from session replay", async () => { const container = document.createElement("div"); document.body.appendChild(container); diff --git a/ui/src/components/AgentConfigForm.tsx b/ui/src/components/AgentConfigForm.tsx index 5e08534828e..b1a59498c3e 100644 --- a/ui/src/components/AgentConfigForm.tsx +++ b/ui/src/components/AgentConfigForm.tsx @@ -1,5 +1,6 @@ import { environmentLoginRequiresAgent, environmentSupportsLoginPty } from "@paperclipai/shared"; import { matchesAdapterLoginTarget, useAdapterLoginCancellation } from "./useAdapterLoginCancellation"; +import { QueryStateConflictError } from "@/lib/query-client"; import { ACCOUNT_BOUND_MODEL_DISCOVERY_QUERY_OPTIONS, antigravityModelGroup, isAccountBoundAcpxAgent } from "@/lib/native-model-catalog"; import { useConnectionModels } from "./ai-connections/useConnectionModels"; import { agentHarnessName, agentHarnessType, agentRunner, paperclipRunnerProfileForHarness, normalizeClaudeRunnerOptions, type AgentRunnerChoice } from "@paperclipai/shared"; @@ -2901,7 +2902,7 @@ export function AdapterLoginPanel(props: AdapterLoginPanelProps) { return ; } -class AdapterLoginConflictError extends Error { +class AdapterLoginConflictError extends QueryStateConflictError { constructor(readonly sessionId: string) { super("Another sign-in attempt is active. Finish or cancel that attempt before starting a new sign-in."); } @@ -3676,7 +3677,7 @@ function SubmittedBrowserCodeLoginPanel({ const wrongConnection = aiConnection ? !matchesAdapterLoginTarget(active, { environmentId, aiConnection }) : Boolean(active.aiConnection); - if (wrongComputer || wrongConnection) throw new Error("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one."); + if (wrongComputer || wrongConnection) throw new QueryStateConflictError("Another sign-in attempt is active. Finish or cancel it in its original account setup before starting this one."); return active; } catch (error) { if (error instanceof ApiError && error.status === 404) return null; diff --git a/ui/src/lib/query-client.test.ts b/ui/src/lib/query-client.test.ts index 4932a826efe..6d023334e8c 100644 --- a/ui/src/lib/query-client.test.ts +++ b/ui/src/lib/query-client.test.ts @@ -10,6 +10,7 @@ import { retryDelayFor, shouldReportQueryError, QueryNotReadyError, + QueryStateConflictError, shouldRetryRequest, TRANSIENT_RETRY_DELAYS_MS, type MutationErrorToast, @@ -32,6 +33,10 @@ describe("retry policy", () => { expect(shouldRetryRequest(0, new ApiError("No", status, null))).toBe(false); }); + it("never retries a state the user must resolve", () => { + expect(shouldRetryRequest(0, new QueryStateConflictError("Another sign-in is active"))).toBe(false); + }); + it("retries the gateway code even when it arrives with a 4xx", () => { expect(shouldRetryRequest(0, new ApiError("x", 404, { error: "tenant_app_unavailable" }))).toBe(true); }); @@ -61,6 +66,7 @@ describe("retry policy", () => { expect(shouldReportQueryError(new ApiError("boom", 500, null))).toBe(true); expect(shouldReportQueryError(new Error("parse failure"))).toBe(true); expect(shouldReportQueryError(new QueryNotReadyError("Not ready"))).toBe(false); + expect(shouldReportQueryError(new QueryStateConflictError("Another sign-in is active"))).toBe(false); expect(shouldReportQueryError(gatewayDown())).toBe(false); expect(shouldReportQueryError(new TypeError("Failed to fetch"))).toBe(false); expect(shouldReportQueryError(new ApiError("Not found", 404, null))).toBe(false); diff --git a/ui/src/lib/query-client.ts b/ui/src/lib/query-client.ts index 04e2988ed0f..306ebeafb77 100644 --- a/ui/src/lib/query-client.ts +++ b/ui/src/lib/query-client.ts @@ -104,6 +104,16 @@ export function reconnectDelayFor(failureCount: number, error: unknown): number /** A successful response whose expected state has not arrived yet. */ export class QueryNotReadyError extends Error {} +/** + * A successful read that found a state the user must resolve, such as another + * active sign-in. It carries status 409, so it classifies as a conflict: the + * page shows its message, a retry would read the same state, and it is not a + * Sentry event. + */ +export class QueryStateConflictError extends Error { + readonly status = 409; +} + /** Query errors worth a Sentry event: not outages, not denials or missing items. */ export function shouldReportQueryError(error: unknown): boolean { return !(error instanceof QueryNotReadyError) && classifyError(error) === "unknown";