## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip Cloud can manage the Google sign-in for a Google Workspace connection. The app keeps the refresh token. Cloud keeps no token. > - When a user removes the connection, the app asks Cloud to end the access at Google (#22065). > - Before this change, the app deleted the token after that call, whatever Cloud answered. If Google or Cloud could not be reached, the access stayed open at Google, and no retry was possible. > - The owner decided on 2026-11-23: the app keeps the token in a pending record and retries until Google answers. Cloud still never stores a provider token. > - This pull request adds that pending record and a background retry. It also covers company deletion and a Cloud-removed instance. > - The benefit is that a removed Google connection does not keep access at Google because of a short outage, and the user does not need to do anything. ## Linked Issues or Issue Description Refs #22065 **What happened?** A managed Google connection was removed while Paperclip Cloud or Google was unavailable. The removal result was `not_ended`, and the refresh token was deleted. Paperclip could not try again, so Google access stayed open. **What did you expect?** Paperclip keeps the token only for the retry, and retries automatically until Google confirms or gives a final answer. The user sees that Paperclip keeps trying, and does not need to act. **Steps to reproduce** 1. Connect Gmail through Paperclip Cloud. 2. Make the broker revoke fail (Cloud unavailable, or Google 5xx). 3. Remove the connection. The token is deleted and nothing retries. ## What Changed - New table `google_pending_revocations` (migration `0502`, additive, `CREATE TABLE` only). It has `company_id` with no foreign key, so a row outlives a deleted company. It stores the token as the same `local_encrypted` material as the connection secret version. It never stores plaintext. It is not a company secret: it is not listed, an agent cannot bind it, and no route reads it. - `google-access-removal.ts`: before the broker call, the app copies the sent token version into a pending row (lease 2 minutes, so a restart during the call resumes). A final outcome deletes the row. A retryable outcome (`provider_revocation_failed`, `revocation_in_progress`, `broker_unavailable`, `broker_error`, `unexpected_error`) keeps it, and the result is the new `retrying`. If the connection secret is still live after the conditional delete (for example, the user signed in again during the call), the row is deleted. - New worker on the `google-pending-revocation` delivery queue (`registerDeadlineWork`; it registers the real next deadline and has no deadline when the table is empty). Each attempt takes a lease on the row and calls the broker with a 15-second timeout. Backoff is 1, 2, 4 ... minutes, up to 6 hours. The hard stop is 30 days. The worker stops without a call if a live company secret holds the same token. - When a retry ends, the worker writes a `connection.google_access_retry` audit event and a `tool_connection.google_access_ended` or `tool_connection.google_access_not_ended` activity entry (labels added to the activity feed). For a deleted company, it writes only a log line. - Company deletion queues every managed Google token of the company inside the delete transaction, before the secrets are deleted (`reason = company_deleted`). - When the Cloud connection status check finds the instance `removed`, the app queues every managed Google token (`reason = instance_removed`), then deletes each connection secret. - `ManagedGoogleAccessRemoval.result` gets `retrying` (shared type and OpenAPI schema). The removal message for `retrying`: "Google didn't confirm that Paperclip's access has ended yet. Paperclip will keep trying automatically." It has no link and asks for no action. - Docs: `doc/connections/GOOGLE-WORKSPACE.md` ("Pending revocation"), `docs/api/tool-connections.md`, the help page `docs/guides/board-operator/deleting-connection-data.md`, and a dated decision row in `doc/memory/google-connector-memory.md`. - `tests/runner-e2e/source-sdk-public-inputs.json` refreshed for the changed shared type, as `pnpm verify` asks. ## Verification - `npx vitest run src/__tests__/google-managed-connection-removal.test.ts` (embedded Postgres): 46 pass. Without the fix, 15 fail (red), with the fix all pass (green). New cases: - an unconfirmed token is kept only in the pending row, encrypted, not in the secrets list; the worker retries and deletes the row when Google confirms; audit and activity are written; - the row exists during the broker call, so a fresh worker after a restart revokes it; - `binding_not_known`, `other_connections_remain` and `provider_revocation_disabled` stop the retry; - backoff 1 minute to 6 hours, and give-up at 30 days with a final audit and activity entry; - a live secret with the same token stops the retry without a call; - an older broker's `403 INSTANCE_SUSPENDED` is retried; - company deletion queues the token and the worker revokes it after the company is gone; - a removed instance queues every token, drops the secrets, does not queue again, and the worker revokes. - `npx vitest run src/__tests__/paperclip-cloud-connector-status.test.ts`: the removed-instance hook runs only for `removed`, and a failure does not change the status. - `ui`: `npx vitest run src/features/connections/googleAccessRemoval.test.ts` (7 pass, the new `retrying` case is red without the change). - Also passed: `tool-connection-content-deletion`, its canary, `delivery-work-coordinator`, `idle-local-work`, `packages/db` tests; `server` `tsc --noEmit`. - `pnpm verify` exits 2 (global doc input changed), so required CI supplies the broad coverage. - Not verified: any call to a real broker or to Google. No request was sent to staging, production or Google. ## Risks - Migration is additive (`CREATE TABLE` and indexes on the new table): `online_compatible`. - Paperclip now holds an encrypted token for at most 30 days after removal when Google did not confirm. The token is never usable for tool calls: no grant or connection refers to the row. - Instance removal deletes the managed Google connection secrets. Those connections then need a reconnect after a new enrollment. They could not refresh anyway, because Cloud refuses a removed instance. - Deploy order: either order is safe. With the current production broker, a removed instance's revoke gets `403` and the app retries until the hard stop. The Cloud broker change that accepts it is a separate PR in the private Cloud repository. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use (shell, file edits, embedded Postgres tests), standard reasoning. ## 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>
6.2 KiB
title, summary
| title | summary |
|---|---|
| Tool Connections | Remove a connection or one of its grants, 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.
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.
{
"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:
{
"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
}
roleNameis 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.savedRoleArnis the role ARN saved on a finished connection when it is this connection's own role (roleName), ornull. 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.trustPolicyis for setting up by hand.ACCOUNT_IDin it stands for the customer's AWS account ID.issuerPublishedistruewhen 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.