Files
PaperClipAI/docs/guides/board-operator/deleting-connection-data.md
T
DottaandClaude Opus 5.5 0aaf946227 fix(connections): keep retrying when Google does not confirm a revoked grant (#22669)
## 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>
2026-11-23 15:28:07 -06:00

5.1 KiB

title, summary
title summary
Deleting Data Read Through a Connection Permanently remove what Paperclip saved from a connected app's tool calls

When an agent uses a connected app, such as Google Workspace, Paperclip saves part of what the app returned so you can review the work later. You can delete that saved data at any time, for any connected app.

What Paperclip saves

For each tool call an agent makes through a connection, Paperclip keeps:

  • A short preview of the request and the result (up to about 4,000 characters, with secrets removed)
  • For actions that needed approval, the preview and arguments shown on the approval card, and the result passed back to the agent
  • Interactive app views that a tool showed in a task
  • The transcript of the run that made the call, which can contain the full result, and of the run that received an approved action's result

This data stays until you delete it. Removing the connection alone does not delete it.

How to delete it

You need permission to manage the connection.

From the connection's page:

  1. Open Connectors and select the connection.
  2. At the bottom of the Permissions tab, select Delete data.
  3. Check the counts in the confirmation and select Delete data.

When you remove a connection:

  1. Open Connectors, open the connection's menu, and select Remove connection.
  2. Select Also delete data read through this connection.
  3. Select Remove connection.

For a Google connection that Paperclip set up for you, removing the connection also asks Google to end Paperclip's access to that Google account. The message after removal tells you whether access was ended. If other Paperclip connections still use the same Google account, Google keeps Paperclip's access until you remove those too. If Google could not be reached or did not confirm, the message says so and Paperclip keeps trying in the background, for up to 30 days, even if Paperclip restarts. You do not need to do anything. The connection's activity shows when access was ended, or that Paperclip stopped trying. If Google gave a final answer that Paperclip cannot end the access, the message says so, and you can remove Paperclip from your Google account's third-party connections.

When you delete a company, Paperclip also ends its access at Google for every Google connection Paperclip set up for that company. This continues in the background after the company is gone. Connections that use your own Google OAuth app are removed only in Paperclip.

Deletion starts right away and continues in the background. It finishes even if Paperclip restarts while it runs. If a step fails, for example because file storage is unavailable, Paperclip keeps the request open and tries again until every step succeeds. It reports the deletion as finished only then. The connection's page shows when the data was last deleted.

What is deleted

  • Request and result previews for every call made through the connection before you asked to delete, including the copies in the connection's audit history
  • Approval previews, arguments and results for those calls, on the approval card and in what was passed back to the agent
  • Interactive app views from those calls
  • The whole transcript of every run that called the connection or received an approved action's result, including that run's other steps and its final summary
  • Tool results too large to pass to the agent directly, which Paperclip saved as files for those runs

What is kept

  • The record that each call happened: when, which tool, which agent, the outcome, the size of the data, and a fingerprint of it. Paperclip needs these for its activity history and usage counts. They do not contain the data.
  • Anything your agents wrote into tasks: comments, documents and files. This action does not remove them, even when an agent copied data from the app into them. Delete or edit those items yourself, or delete the task.
  • The connection's audit activity, which records counts only.
  • Transcripts of later runs that only read the context an interactive app view shared. Paperclip does not record which runs read it. Delete those tasks if you need that text gone.
  • Raw provider traces. An administrator must turn them on, and they expire on their own within 24 hours.

Deleting a task or a company

Deleting a task also deletes this data for the task's runs, from every connected app. Comments, documents and files in the task are deleted with it, including the files in storage. If a run of the task is still working, or an approval for it is still open, Paperclip waits for up to a day and then deletes the data on its own. After a day, it stops waiting and leaves what is still open.

Deleting a company deletes all of its data, including run transcripts and files in storage. Storage clean-up continues in the background after the company is gone, and Paperclip retries it until it succeeds.

Runs that are still working

Paperclip does not change a run while it is still working. The confirmation tells you how many runs are skipped for this reason. Select Delete data again after they finish.

It cannot be undone

Deleted data cannot be recovered.