mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents use apps through connections. Most app connections use an OAuth sign-in. > - Paperclip saves a draft connection before it opens the provider sign-in page. > - When the user cancels or abandons that sign-in, the draft stays. The Apps list counts it as a connection that "needs attention". > - The user did not ask for that connection, and the user must not clean it up by hand. > - This pull request hides drafts that never finished their first sign-in and removes the draft when the user clicks Cancel. > - The benefit is that a cancelled sign-in leaves no visible connection, and a retry makes exactly one connection. ## Linked Issues or Issue Description Refs #22634 **What happened?** A workspace has one working "Google Workspace for the organization" connection. The user clicks "Add account", chooses services, and clicks Continue. The page shows "Opening Google Workspace…". The user clicks Cancel before finishing at Google. The Apps page then shows "2 connections · 1 needs attention". **What did you expect to happen?** A cancelled sign-in leaves no visible connection. The same applies when the user closes the page, reloads it, closes the Google tab, or refuses consent at Google. A retry after a cancel makes exactly one connection. A cancelled reconnect of a working connection does not change that connection. **Steps to reproduce** 1. Connect one Google Workspace account. 2. Open Apps, then Google Workspace, then "Add account". 3. Click "Continue to sign in", choose services, and click Continue. 4. On the "Opening Google Workspace" page, click Cancel. 5. Look at the Google Workspace card on the Apps page. ## What Changed - Root cause: `connectApp` saves an OAuth draft (`status: "draft"`) before sign-in (`server/src/services/tool-access.ts`, the connection insert in the connect path). Cancel only navigated away. The Apps list counted every draft as "needs attention" (`ui/src/pages/apps/Browse.tsx`, `connectionState` and the attention count). - New module `server/src/services/tool-access/connections/first-sign-in.ts`. It decides if an OAuth draft never held a credential. It checks for OAuth tokens on the connection and its grants, legacy inline tokens (the removal module's list), a provider consent time, an external credential, and the markers a real connection keeps when it needs a new sign-in. If any check is not clear, the connection counts as real. - The connection list endpoint sets `firstSignInPending: true` on those drafts. The shared `ToolConnection` type has the new field. - New route `POST /tool-connections/:connectionId/sign-in/cancel`. It checks company access and configure permission. It removes the draft with the normal removal teardown (grants, OAuth states, bindings) only if the draft never held a credential. For any other connection it changes nothing and returns `abandoned: false`. A removal writes the activity entry `tool_connection.sign_in_cancelled`. The route is in the OpenAPI registry. - The Apps list does not show connections with `firstSignInPending`, and it does not show an app whose only connections are such drafts. The check is one pass with `Set` lookups. - Cancel works in one transaction: it deletes the pending sign-in states, locks the connection, checks it again, and parks it as `disabled` with the marker `oauth_sign_in_cancelled`. If the connection must stay, the transaction rolls back. Then the normal removal archives the parked draft. Setup never reuses a parked draft, so a retry during the removal gets its own row. - One predicate, `connectionRemovedOrSignInCancelled`, guards authorization start, access finish and machine sign-in. The direct, Cloud and Vercel Connect callbacks and the access finish step lock the connection before they write a grant or activate it, and return 409 `oauth_sign_in_cancelled` for a parked draft. - `docs/api/tool-connections.md` documents the cancel route and the list flag. - The setup page calls the cancel route when the user clicks Cancel on the sign-in screen. It does this only for a draft that this page made. It does not do this for a resume, a reconnect, or a task-linked setup. - Design for abandoned drafts (tab closed, reload, consent refused): they are not listed, and the next attempt reuses them through the existing draft reuse in setup. No background cleanup job is added. ## Verification - `server/src/__tests__/tool-access-cancelled-first-sign-in.integration.test.ts` runs the real routes against embedded Postgres and a local OAuth provider. It covers: a draft is marked and hidden; a provider token exchange held open across Cancel ends in 409; Cancel and a retry at the same time leave exactly one active connection; a parked draft is hidden and refuses a new sign-in start; a legacy draft with an inline token is not cancelled; Cancel removes it, deletes its OAuth state, logs activity, and a late callback fails; a retry after Cancel gives exactly one live connection (organization and personal); Cancel does not change an active connection or a connection that needs a new sign-in; a draft refused at the provider stays hidden and Cancel removes it; another company cannot cancel the draft. - `ui/src/pages/apps/Browse.test.tsx`: a pending draft is not listed and does not add "needs attention". - `ui/src/pages/apps/AppsConnect.test.tsx`: Google Workspace setup, Continue, then Cancel calls the cancel route for the new draft. - Red/green: the new Browse and setup tests fail without the UI change. The server test fails on master because the route and flag do not exist. - Local runs: the new server file, `openapi-routes.test.ts`, `tool-access-oauth-protocol.integration.test.ts`, `Browse.test.tsx`, `AppsConnect.test.tsx`, `activity-format.test.ts`, and `src/features/connections` pass. Server typecheck passes. `pnpm verify` exits 2 because of the pinned inputs file, so CI supplies broad coverage. - Not done: a real browser test against Google. ## Risks - Low risk. The cancel route fails toward no change: it removes nothing that shows any sign of a credential. - Cancel and a late provider callback agree under the connection row lock. If the callback commits first, Cancel changes nothing. If Cancel commits first, the callback returns 409 and saves nothing. This covers the direct, Cloud and Vercel Connect callbacks and the access finish step. - If the removal after Cancel fails, the draft stays parked and hidden, and a second Cancel finishes it. - A connection that was removed before and is now added again keeps its old consent record. If that new sign-in is cancelled, it stays as a visible draft, as it does today. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used in Claude Code with tool use (shell, file edits, 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 - [ ] 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
7.2 KiB
Markdown
115 lines
7.2 KiB
Markdown
---
|
|
title: Tool Connections
|
|
summary: Remove a connection or one of its grants, cancel a first sign-in, read what happened at the provider, and read what to set up in AWS for an AWS role connection
|
|
---
|
|
|
|
Removing a connection or a grant always completes in Paperclip. The response says what happened at the provider when Paperclip can ask the provider to end access.
|
|
|
|
## Remove a Connection
|
|
|
|
```
|
|
DELETE /api/tool-connections/{connectionId}
|
|
DELETE /api/tool-connections/{connectionId}?deleteStoredContent=true
|
|
```
|
|
|
|
The caller needs `connections:configure` for the connection. Only a board user can set `deleteStoredContent=true`.
|
|
|
|
The `200` response is the archived connection with a `removal` object. `removal` holds counts of what was torn down, for example `secretsRevoked` and `grantsRevoked`. With `deleteStoredContent=true`, the response also has `contentDeletion`.
|
|
|
|
## Cancel a First Sign-In
|
|
|
|
```
|
|
POST /api/tool-connections/{connectionId}/sign-in/cancel
|
|
```
|
|
|
|
Use this when a user cancels the provider sign-in for a new connection. The caller needs `connections:configure` for the connection.
|
|
|
|
Paperclip removes the connection only if it is an OAuth draft that never held a credential. The removal is the same teardown as `DELETE`, and the activity log gets `tool_connection.sign_in_cancelled`. The `200` response is `{ "abandoned": true, "connection": ... }` with the archived connection.
|
|
|
|
For any other connection, Paperclip changes nothing. This includes an active connection and a connection that needs a new sign-in after it worked before. The `200` response is `{ "abandoned": false, "connection": ... }` with the unchanged connection.
|
|
|
|
`GET /api/companies/{companyId}/tools/connections` sets `firstSignInPending: true` on an OAuth draft that never held a credential. The Apps page does not show these drafts, and the next setup for the same app reuses them.
|
|
|
|
## Remove a Grant
|
|
|
|
```
|
|
DELETE /api/tool-connections/{connectionId}/grants/{grantId}
|
|
```
|
|
|
|
The caller needs `connections:configure` for the connection, or must be the grant's own user. The `200` response is the revoked grant.
|
|
|
|
## Google Access (`providerAccess`)
|
|
|
|
For a Google connection that Paperclip Cloud manages, the connection response has `removal.providerAccess` and the grant response has `providerAccess`. Other connections do not have this field.
|
|
|
|
```json
|
|
{
|
|
"provider": "google",
|
|
"result": "ended",
|
|
"outcomes": ["revoked"]
|
|
}
|
|
```
|
|
|
|
`result` is one of:
|
|
|
|
| `result` | Meaning |
|
|
| --- | --- |
|
|
| `ended` | Google ended Paperclip's access for every removed grant. |
|
|
| `ended_unconfirmed` | Google ended access for at least one removed grant, and the others reported other connections. Paperclip cannot tell whether they were the same Google account. |
|
|
| `other_connections_remain` | Other Paperclip connections still use this Google account, so Google keeps the access. |
|
|
| `retrying` | Google did not confirm yet for at least one removed grant (Paperclip Cloud or Google could not be reached, or Google failed). Paperclip keeps that token in a pending record and retries in the background; the user does not need to act. |
|
|
| `not_ended` | Paperclip Cloud gave a final answer that it cannot end the access at Google for at least one removed grant, or the token could not be kept for a retry. The user can remove it at https://myaccount.google.com/connections. |
|
|
|
|
`outcomes` has one code for each refresh token Paperclip sent, in order. The codes are for diagnosis, not for display.
|
|
|
|
A failure to end access at Google does not undo the local removal. On both routes the local removal completes first, then Paperclip asks Paperclip Cloud to end access at Google once in the request. When that is not confirmed and can be retried, the result is `retrying`: a background worker retries with backoff from 1 minute up to 6 hours, for at most 30 days. When the retry ends, the connection's audit history gets a `connection.google_access_retry` event, and the activity log gets `tool_connection.google_access_ended` or `tool_connection.google_access_not_ended`. Revoking an organization grant whose token the connection itself still uses does not end access at Google and has no `providerAccess`; removing the connection does. The activity entry for the removal records the same `providerAccess`, and the connection's audit history gets a `connection.google_access_removal` event with it.
|
|
|
|
## AWS Role Setup
|
|
|
|
```
|
|
GET /api/tool-connections/{connectionId}/aws-setup
|
|
GET /api/tool-connections/{connectionId}/aws-setup?accessLevel=full
|
|
```
|
|
|
|
Returns what to create in AWS for an AWS role connection (`connectionMethodKey` `aws-role`): an IAM OpenID Connect identity provider for the company's issuer and a role that trusts only this connection. The setup screen reads it after saving the connection as a draft, and again on reconnect. It never contains a secret.
|
|
|
|
The caller needs `connections:configure` for the connection.
|
|
|
|
`accessLevel` is optional (`read_only` or `full`). It sets up for an access level that is not saved yet, such as one changed while reconnecting. Without it, the saved access level is used. For `read_only` the template's `AccessPolicyArn` defaults to `ReadOnlyAccess`; for `full` it has no default.
|
|
|
|
When this instance can serve the role method, the `200` response is:
|
|
|
|
```json
|
|
{
|
|
"available": true,
|
|
"issuer": "https://paperclip.example.com/oidc/companies/<companyId>",
|
|
"audience": "sts.amazonaws.com",
|
|
"subject": "connection:<connectionId>",
|
|
"providerHost": "paperclip.example.com/oidc/companies/<companyId>",
|
|
"roleName": "paperclip-<connectionId>",
|
|
"savedRoleArn": null,
|
|
"accessLevel": "read_only",
|
|
"trustPolicy": { "Version": "2012-10-17", "Statement": ["..."] },
|
|
"cloudFormationTemplate": "{ ... }",
|
|
"cloudFormationConsoleUrl": "https://console.aws.amazon.com/cloudformation/home#/stacks/create",
|
|
"issuerPublished": true
|
|
}
|
|
```
|
|
|
|
- `roleName` is the role the template and the agent prompt create. It is named after the connection, and CloudFormation fills in the account, so the template needs no edits.
|
|
- `savedRoleArn` is the role ARN saved on a finished connection when it is this connection's own role (`roleName`), or `null`. Drafts never keep a role ARN, and a role with any other name is not offered, because the setup steps tell an AWS administrator to update this role.
|
|
- `trustPolicy` is for setting up by hand. `ACCOUNT_ID` in it stands for the customer's AWS account ID.
|
|
- `issuerPublished` is `true` when the company's signing key is published, so AWS can validate the issuer.
|
|
|
|
Otherwise the `200` response is `{ "available": false, "reason": "<reason>" }`:
|
|
|
|
| `reason` | Meaning |
|
|
| --- | --- |
|
|
| `no_public_url` | The instance has no public address, so AWS cannot reach its issuer. |
|
|
| `not_https` | The instance is not served over HTTPS, which AWS requires. |
|
|
| `has_port` | The instance address includes a port, which AWS does not allow. |
|
|
| `loopback` | The instance runs on this computer only. |
|
|
| `address_changed` | The instance address changed after this draft was saved. Saving the draft again uses the current address. A finished connection is set up for the current address instead, since reconnecting records it. |
|
|
|
|
Errors: `404` when the connection does not exist or is not accessible, and `422` with code `aws_role_setup_unavailable` when the connection does not use an AWS role.
|