mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
fix(ai-connections): say why a local sign-in attempt ended (#22668)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Onboarding and the agent setup screen connect a subscription account
with local sign-in (`useLocalAiLogin`) when the login environment is
local and the server supports it
> - A local sign-in attempt lasts 30 minutes. The client polls `POST
/companies/:id/ai-connections/local/check`
> - The check answers `{ status: "expired" }` whenever the attempt is no
longer waiting for the user, not only after the deadline
> - So a cancelled attempt, an attempt that "Start sign-in again"
replaced, and an attempt that already connected the account all show
"This sign-in attempt expired"
> - This pull request keeps the status and adds the real reason as the
error text that the sign-in panel already shows
> - The benefit is that people see why sign-in stopped, and support can
tell an expiry from a replacement
## Linked Issues or Issue Description
**What happened?**
A person saw "This sign-in attempt expired. Start sign-in again." during
subscription sign-in, well inside the 30-minute attempt window. In
`localAiLoginService().check`, any attempt whose status is not
`waiting_for_user` answers `{ status: "expired" }`. That includes
`cancelled` (a cancel, or a replacement by "Start sign-in again" in
another tab or step), an attempt whose cancel is still in progress, and
`authenticated` (already connected).
**Expected behavior**
"Expired" appears only when the 30-minute deadline has passed. A
cancelled, replaced or completed attempt says what happened.
**Steps to reproduce**
1. Start local sign-in for an account.
2. Choose "Start sign-in again" (or cancel the attempt).
3. Check the first attempt. It answers `{ status: "expired" }`, and the
panel shows "This sign-in attempt expired".
**Paperclip version or commit**
`master` at `5f5ac154368`.
**Deployment mode**
Any deployment where local sign-in is available, including onboarding.
## What Changed
- `local-ai-login.ts` `check()`: an attempt that is `authenticated` or
has a connection answers `{ status: "expired", error: "This sign-in
already connected the account." }`. An attempt that is `cancelled`, or
whose cancel is still in progress, answers `{ status: "expired", error:
"This sign-in attempt was cancelled or replaced by a newer one. Start
sign-in again." }`. An attempt past its deadline or `timed_out` still
answers `{ status: "expired" }`.
- The `LocalAiLoginStatus` type and the client do not change.
`useLocalAiLogin` already shows a server `error` before its default
expiry text.
- Test: `ai-legacy-compatibility.test.ts` covers a replaced attempt, a
cancelled attempt, and a completed attempt.
## Verification
- `pnpm exec vitest run
server/src/__tests__/antigravity-local-ai-login.test.ts
server/src/__tests__/ai-connections.test.ts
server/src/__tests__/ai-legacy-compatibility.test.ts`: 3 files, 186
tests passed.
- The new test fails on `master`.
- `pnpm --filter @paperclipai/server typecheck` passes.
## Risks
- Low risk. The status values stay the same, so client logic does not
change. Only the error text changes for cancelled, replaced and
completed attempts.
- A completed attempt still answers `expired`, so the panel offers
"Start sign-in again". Answering `ready` would let the client reconnect
the same attempt, but it would also start the client's connect flow
again, so this change keeps the existing status.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with shell, file
edit, and code execution tools.
## 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
- [x] I will address all Greptile and reviewer comments before
requesting merge
This commit is contained in:
1 parent
7f343549db
commit
ff68490d03
2 files changed
+23
No files matched your search
@@ -198,6 +198,25 @@ it("enforces local attempt ownership, company, target, cancellation, and expiry"
|
||||
expect(row.status).toBe("timed_out");
|
||||
});
|
||||
|
||||
it("tells the owner why an ended attempt stopped instead of calling every one expired", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async () => new Response("{}")));
|
||||
const ownCompany = randomUUID();
|
||||
await db.insert(companies).values({ id: ownCompany, name: "Ended attempts", issuePrefix: "END" });
|
||||
await db.insert(companyMemberships).values({ companyId: ownCompany, principalId: owner, principalType: "user", status: "active", membershipRole: "owner" });
|
||||
const login = localAiLoginService(db);
|
||||
const replacedMessage = "This sign-in attempt was cancelled or replaced by a newer one. Start sign-in again.";
|
||||
const first = await login.start(ownCompany, owner, loginIntent());
|
||||
const retry = await login.start(ownCompany, owner, loginIntent(), true);
|
||||
expect(await login.check(ownCompany, owner, loginIntent(), first.sessionId)).toEqual({ status: "expired", error: replacedMessage });
|
||||
await login.cancel(ownCompany, owner, retry.sessionId);
|
||||
expect(await login.check(ownCompany, owner, loginIntent(), retry.sessionId)).toEqual({ status: "expired", error: replacedMessage });
|
||||
const completed = await login.start(ownCompany, owner, loginIntent());
|
||||
await writeFile(path.join(directoryFor(completed.sessionId), "auth.json"), auth("completed-login"));
|
||||
await login.complete(ownCompany, owner, completed.sessionId, loginIntent());
|
||||
expect(await login.check(ownCompany, owner, loginIntent(), completed.sessionId))
|
||||
.toEqual({ status: "expired", error: "This sign-in already connected the account." });
|
||||
});
|
||||
|
||||
it("explicit retry replaces another owned local attempt while ordinary navigation preserves it", async () => {
|
||||
const login = localAiLoginService(db);
|
||||
const first = await login.start(companyId, owner, loginIntent());
|
||||
|
||||
@@ -288,6 +288,10 @@ export function localAiLoginService(db: Db) {
|
||||
));
|
||||
if (!session?.aiConnection || !sameTarget(session.aiConnection, intent))
|
||||
throw notFound("Local sign-in attempt not found for this connection.");
|
||||
if (session.status === "authenticated" || session.connectionId)
|
||||
return { status: "expired", error: "This sign-in already connected the account." };
|
||||
if (session.status === "cancelled" || session.failureReason === RETIREMENT_PENDING)
|
||||
return { status: "expired", error: "This sign-in attempt was cancelled or replaced by a newer one. Start sign-in again." };
|
||||
if (session.status !== "waiting_for_user" || !session.expiresAt || session.expiresAt.getTime() <= Date.now())
|
||||
return { status: "expired" };
|
||||
directory = loginHome(id);
|
||||
|
||||
Reference in new issue
Block a user