fix(ui): stop retrying and reporting an active sign-in conflict

The sign-in panels read the caller's active sign-in session. When that
session belongs to another computer or AI connection, the read throws and
the panel shows "Another sign-in attempt is active". The error had no
status, so the query client classified it as unknown: it retried the read
twice and then reported it to Sentry as an unexpected failure.

Add QueryStateConflictError, which carries status 409 so it classifies as
a conflict: no retry, no Sentry report, and describeError keeps its
message. Use it for the displayed-code panel's AdapterLoginConflictError
and for the Claude setup-token panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
devinfoleyandClaude Opus 5.5 committed 2026-12-01 06:17:19 +00:00
1 parent 66a8aa7f7e
commit 4267d070e7
4 files changed
+59 -4

No files matched your search

@@ -13,6 +13,8 @@ import { isBlockedFromReplay } from "@/lib/analytics/replay-recording.test-utils
import { ApiError } from "../api/client"; import { ApiError } from "../api/client";
import { CodexLocalConfigFields } from "../adapters/codex-local/config-fields"; import { CodexLocalConfigFields } from "../adapters/codex-local/config-fields";
import type { AdapterConfigFieldsProps } from "../adapters/types"; import type { AdapterConfigFieldsProps } from "../adapters/types";
import { createAppQueryClient } from "../lib/query-client";
import type { ConnectivityStore } from "../lib/connectivity";
const mockAgentsApi = vi.hoisted(() => ({ const mockAgentsApi = vi.hoisted(() => ({
get: vi.fn(), get: vi.fn(),
@@ -90,13 +92,16 @@ vi.mock("../adapters", () => ({
}), }),
})); }));
vi.mock("../adapters/use-adapter-capabilities", () => ({ vi.mock("../adapters/use-adapter-capabilities", () => ({
useAdapterCapabilities: () => () => ({ useAdapterCapabilities: () => (type: string) => ({
supportsInstructionsBundle: true, supportsInstructionsBundle: true,
supportsSkills: true, supportsSkills: true,
supportsLocalAgentJwt: true, supportsLocalAgentJwt: true,
requiresMaterializedRuntimeSkills: false, requiresMaterializedRuntimeSkills: false,
supportsAcp: true, 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: () => [] })); vi.mock("../adapters/use-disabled-adapters", () => ({ useDisabledAdaptersSync: () => [] }));
@@ -266,6 +271,39 @@ describe("AgentConfigForm session replay masking", () => {
expect(container.textContent).toContain("Retry sign in"); 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<ConnectivityStore["getSnapshot"]> },
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(
<QueryClientProvider client={client}>
<AdapterLoginPanel companyId="company-1" environmentId="sandbox-1" adapterType={adapterType}
requiresAgent agentId="agent-1" autoStart />
</QueryClientProvider>,
));
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 () => { it("blocks the displayed login code from session replay", async () => {
const container = document.createElement("div"); const container = document.createElement("div");
document.body.appendChild(container); document.body.appendChild(container);
+3 -2
View File
@@ -1,5 +1,6 @@
import { environmentLoginRequiresAgent, environmentSupportsLoginPty } from "@paperclipai/shared"; import { environmentLoginRequiresAgent, environmentSupportsLoginPty } from "@paperclipai/shared";
import { matchesAdapterLoginTarget, useAdapterLoginCancellation } from "./useAdapterLoginCancellation"; 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 { ACCOUNT_BOUND_MODEL_DISCOVERY_QUERY_OPTIONS, antigravityModelGroup, isAccountBoundAcpxAgent } from "@/lib/native-model-catalog";
import { useConnectionModels } from "./ai-connections/useConnectionModels"; import { useConnectionModels } from "./ai-connections/useConnectionModels";
import { agentHarnessName, agentHarnessType, agentRunner, paperclipRunnerProfileForHarness, normalizeClaudeRunnerOptions, type AgentRunnerChoice } from "@paperclipai/shared"; import { agentHarnessName, agentHarnessType, agentRunner, paperclipRunnerProfileForHarness, normalizeClaudeRunnerOptions, type AgentRunnerChoice } from "@paperclipai/shared";
@@ -2901,7 +2902,7 @@ export function AdapterLoginPanel(props: AdapterLoginPanelProps) {
return <Panel key={agentId} {...props} agentId={agentId} />; return <Panel key={agentId} {...props} agentId={agentId} />;
} }
class AdapterLoginConflictError extends Error { class AdapterLoginConflictError extends QueryStateConflictError {
constructor(readonly sessionId: string) { constructor(readonly sessionId: string) {
super("Another sign-in attempt is active. Finish or cancel that attempt before starting a new sign-in."); 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 const wrongConnection = aiConnection
? !matchesAdapterLoginTarget(active, { environmentId, aiConnection }) ? !matchesAdapterLoginTarget(active, { environmentId, aiConnection })
: Boolean(active.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; return active;
} catch (error) { } catch (error) {
if (error instanceof ApiError && error.status === 404) return null; if (error instanceof ApiError && error.status === 404) return null;
+6
View File
@@ -10,6 +10,7 @@ import {
retryDelayFor, retryDelayFor,
shouldReportQueryError, shouldReportQueryError,
QueryNotReadyError, QueryNotReadyError,
QueryStateConflictError,
shouldRetryRequest, shouldRetryRequest,
TRANSIENT_RETRY_DELAYS_MS, TRANSIENT_RETRY_DELAYS_MS,
type MutationErrorToast, type MutationErrorToast,
@@ -32,6 +33,10 @@ describe("retry policy", () => {
expect(shouldRetryRequest(0, new ApiError("No", status, null))).toBe(false); 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", () => { 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); 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 ApiError("boom", 500, null))).toBe(true);
expect(shouldReportQueryError(new Error("parse failure"))).toBe(true); expect(shouldReportQueryError(new Error("parse failure"))).toBe(true);
expect(shouldReportQueryError(new QueryNotReadyError("Not ready"))).toBe(false); 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(gatewayDown())).toBe(false);
expect(shouldReportQueryError(new TypeError("Failed to fetch"))).toBe(false); expect(shouldReportQueryError(new TypeError("Failed to fetch"))).toBe(false);
expect(shouldReportQueryError(new ApiError("Not found", 404, null))).toBe(false); expect(shouldReportQueryError(new ApiError("Not found", 404, null))).toBe(false);
+10
View File
@@ -104,6 +104,16 @@ export function reconnectDelayFor(failureCount: number, error: unknown): number
/** A successful response whose expected state has not arrived yet. */ /** A successful response whose expected state has not arrived yet. */
export class QueryNotReadyError extends Error {} 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. */ /** Query errors worth a Sentry event: not outages, not denials or missing items. */
export function shouldReportQueryError(error: unknown): boolean { export function shouldReportQueryError(error: unknown): boolean {
return !(error instanceof QueryNotReadyError) && classifyError(error) === "unknown"; return !(error instanceof QueryNotReadyError) && classifyError(error) === "unknown";