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

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The agent sign-in panel reads the user's active sign-in session
before it starts a new one
> - When that active session belongs to another computer or AI
connection, the panel throws an error and shows "Another sign-in attempt
is active"
> - This is an expected state that the user must resolve. But the error
has no status, so the query client classifies it as an unknown failure
> - Because of that, the query retries it two times and then sends it to
Sentry as an unexpected error
> - This pull request marks this state as a conflict (409). The query
does not retry it and does not report it. The panel shows the same
message
> - The benefit is that Sentry shows real failures only, and the user
sees the conflict at once, not after about 3 seconds of retries

## Linked Issues or Issue Description

No public issue exists. The issue is below. It follows the bug template.

**What happened?**
A user opened the agent sign-in panel while a different sign-in for the
same owner was active on another computer or AI connection. The panel
showed "Another sign-in attempt is active…". The browser also sent a
handled `Error` to Sentry from the active-session query
(`query_kind=adapter-login-active-session`). This happens in the
displayed-code panel (Codex and similar adapters) and in the Claude
setup-token panel. Both throw the same kind of error.

**Expected behavior**
The panel shows the conflict and the "Cancel previous sign-in and retry"
action. The app does not retry the read. The app does not report the
conflict to Sentry, because it is a known user state and not a failure.

**Steps to reproduce**
1. Start a sign-in for an agent on computer A. Do not complete it.
2. Open the sign-in panel for an agent on computer B, as the same user.
3. The active-session read finds the session for computer A. The query
retries two times, then the panel shows the conflict, and Sentry gets an
event.

**Paperclip version or commit**
`master` at 66a8aa7f7e. Sentry saw it on hosted releases 91e9365d59 and
earlier.

**Relevant logs or output**
`Error: Another sign-in attempt is active. Finish or cancel that attempt
before starting a new sign-in.` (mechanism generic, handled, culprit
`queryFn`). A similar group has the message "Finish or cancel it in its
original account setup before starting this one." from the Claude
setup-token panel.

## What Changed

- `ui/src/lib/query-client.ts`: Add `QueryStateConflictError`. It
carries `status = 409`, so `classifyError` returns `conflict`. Because
of that, `shouldRetryRequest` does not retry it,
`shouldReportQueryError` does not send it to Sentry, and `describeError`
still shows its message.
- `ui/src/components/AgentConfigForm.tsx`: `AdapterLoginConflictError`
(displayed-code panel) now extends `QueryStateConflictError`. The Claude
setup-token panel now throws `QueryStateConflictError` and not a plain
`Error`.
- Tests: A render test for each panel (`codex_local` and `claude_local`)
uses the real `createAppQueryClient`. It checks that the panel shows the
conflict, reads the active session one time, does not start a new
sign-in, and does not report an error. The unit tests in
`query-client.test.ts` check the retry and report rules for the new
error.

## Verification

- Red: With the original `AgentConfigForm.tsx`, both new render tests
fail: `expected "vi.fn()" to be called 1 times, but got 3 times` (two
retries).
- Green: `cd ui && npx vitest run
src/components/AgentConfigForm.render.test.tsx
src/lib/query-client.test.ts src/api/errors
src/components/AgentConfigForm.test src/components/new-agent` passes: 6
files, 118 tests.
- `pnpm verify` selected a broad set because `query-client.ts` is
imported widely. I stopped the local run and used full CI on head
4267d070e7 for broad coverage. CI ran the full suite, and both changed
test files passed there (`AgentConfigForm.render.test.tsx` 8 tests,
`query-client.test.ts` 27 tests).
- `tsc --noEmit -p ui/tsconfig.json` shows no errors in the changed
files.

## Risks

- Low risk. The change touches only the two client-side conflict errors.
API errors and other query errors keep their current classification.
- The panel no longer retries the conflict read. A retry reads the same
server state, so this does not remove a recovery path. The "Cancel
previous sign-in and retry" action refetches the read.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edit, test runs).

## 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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-01 06:36:53 +00:00
1 parent c737187ec7
commit fd6e940b35
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);
+3 -2
View File
@@ -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;
+6
View File
@@ -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);
+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. */
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";