mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
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:
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 { 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<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 () => {
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
|
||||
@@ -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 <Panel key={agentId} {...props} agentId={agentId} />;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user