## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents call connected apps, such as Google Workspace, and Paperclip keeps parts of the results in tool-call records, approvals, run transcripts and files > - #22010 added "Delete data" on a connection. It removes that content for one connection. > - Deleting a task or a company did not run the same cleanup. Task deletion set the task link to null on tool calls, approvals and runs, so their previews and transcripts stayed. Company deletion removed the rows but left run logs and files in storage. > - Google's restricted-scope review requires that users can delete the Google data we hold, and that the policy matches the product > - This pull request runs the "Delete data" steps when a task is deleted, and removes a deleted company's run logs and files from storage in the background > - The benefit is that deleting a task or a company removes every copy of connection content, and a canary test makes sure that a new store cannot skip these paths ## Linked Issues or Issue Description Refs #22010 **Problem** Deleting a task leaves connection content in tool-call previews, audit history, approval requests, results passed to later runs, run transcripts (events, excerpts, result text and the run log in every copy) and saved tool results over 500,000 bytes. Deleting a company leaves run logs (object journal, archive, local file, S3 mirror) and all stored files, including attachments and saved tool results. "Delete data" on a connection also left saved tool results over 500,000 bytes in storage. **Expected behavior** Deleting a task removes the connection content of the task's runs and calls. Deleting a company removes its run logs and files from storage, not only its rows. "Delete data" removes saved tool results of the runs whose transcripts it deletes. **Steps to reproduce** 1. Let an agent call a connection on a task, so that the run has a log, events and a saved tool result. 2. Delete the task, or delete the company. 3. Look in `tool_invocations`, `heartbeat_runs`, `heartbeat_run_events` and object storage. The content is still there. ## What Changed - New table `issue_connection_content_deletions`. Task deletion records, in the same transaction and before the task row goes, the task's runs that used a connection or are still working, the task's calls without a run, and the task's call events that belong to neither. Audit entries are matched by run, call or task. The background worker then runs the existing "Delete data" steps for that scope. Runs of the task that are still working are recorded too, even if they have not used a connection yet, so a connection call they make after the deletion is also cleared. The job rechecks every 1 to 5 minutes while runs or approvals are open and finishes as soon as they settle, for up to a day. It writes an `issue.connection_content_deleted` activity entry with counts only, and only when it deleted something. - New table `stored_object_deletions`. Company deletion records every run log and every file of the company before the rows go. The table has no foreign key to the company, so the removal continues after the company is gone. Each object is retried with backoff until storage confirms the deletion. Task deletion also records the task's attached files here, so a failed best-effort delete in the route is retried. - `content-deletion.ts` stays the one owner of "remove connection content". Each job table has its own typed store (load, save, finish, activity, failure), so no per-table column can compile against the other table. The storage ledger is in `stored-object-deletion.ts`, and the task request is in `issue-content-deletion.ts`. The steps now take a scope (one connection, or the runs and calls of one deleted task). The connection path behaves as before. - "Delete data" and task deletion now also delete saved tool results over 500,000 bytes (`runner-api` assets) of each run whose transcript they delete: the object in storage and the asset row. Files attached to a task, a case or a company logo are not touched. - The canary test scans every text and JSON column and every storage copy (object journal, legacy mirror, local files and file storage) after a connection deletion, a task deletion and a company deletion. It also checks that another task and another company keep their content. - Docs: the store inventory in `doc/memory/google-connector-memory.md` has columns for task and company deletion. The production checklist, the code-fixes plan, the connector playbook and the user help page `docs/guides/board-operator/deleting-connection-data.md` are updated. ## Verification - `cd server && npx vitest run src/__tests__/tool-connection-content-deletion-canary.test.ts` (12 tests). Before the fix, the new task and company tests failed: the scan found the marker in run logs, the legacy mirror, local files, saved results and attachments. The connection test also failed on the saved tool result file. - `cd server && npx vitest run src/__tests__/tool-connection-content-deletion.test.ts src/__tests__/google-managed-connection-removal.test.ts src/__tests__/git-restore-point-ledger.test.ts src/__tests__/agent-observability.test.ts` (85 tests pass). - Nine more suites that delete tasks or companies pass (456 tests), for example `decision-target-work`, `approval-retention-work`, `cleanup-removal-service` and `tool-gateway-service`. - `pnpm --filter @paperclipai/db typecheck` passes, including the migration compatibility guard (`0501` is `online_compatible`: two new tables and their indexes). - `cd server && pnpm typecheck` passes. - `pnpm verify` exits 2 because a global CI input changed. Required CI supplies the broad coverage. ## Risks - Migration: two new tables only. The previous release does not read them, so it keeps working during the overlap deploy. - Task deletion runs three more indexed queries in its transaction. It creates a job only when the task used a connection. - Company deletion inserts one ledger row per run log and per file in its existing transaction. The storage work is batched in the background, 50 objects at a time. - Company deletion now removes all of the company's files and run logs from storage. Before, they stayed in storage with no row that pointed to them. - `stored_object_deletions` keeps `company_id` without a foreign key, like `execution_workspace_restore_points`, so that removal can finish after the company is gone. It holds object keys only, no content. - A task deletion creates a job when the task used a connection or still has a run that is working. While runs or approvals are open, the job rechecks every 1 to 5 minutes. It stops waiting one day after the deletion. It then writes `issue.connection_content_deletion_incomplete` with the counts of what was still open, and that content stays. A job that deleted nothing and left nothing open writes no activity entry. - A run of the deleted task that was still working is in the scope. If it calls a connection after the task is deleted, the job waits for it and clears that content too. - Not changed: deleting a company does not ask Google to revoke the grant. Raw provider traces still expire on their own. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use (shell, file edit, test runs). Extended reasoning on. ## 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>
19 KiB
Google Workspace connector: code fixes before submission
Started November 17, 2026. Temporary working plan; delete it once the items land. It covers section 2 of the production checklist.
Based on a read of master at 56654adecd. Items marked confirmed were seen
in the code. Items marked to check are suspected gaps that need a look
before any change. Fixes 1 to 4 and 6 landed on November 17. Fix 9 has every
tool built but no service switched on. Fix 10 is done in the app. Fixes 5, 7
and 8 are not started.
Each fix is its own pull request with a failing test first. For the scope change in fix 2, the deploy order is app first, then broker (see fix 10).
Order
| # | Fix | Size | Blocks submission | Status |
|---|---|---|---|---|
| 1 | Data-use disclosure in the picker | Small | Yes | Done, #21998 |
| 2 | Lock the managed scope set to 14 | Small to medium | Yes | Done in the app, #22001 |
| 3 | Take gmail.modify off the Paperclip-managed client |
Small | Yes | Done, #22001 |
| 4 | Confirm injection screening on Google results | Check, then small | Yes | Done, #21999 |
| 5 | Revoke at Google on last disconnect | Medium | Likely | Not started |
| 6 | Retention and deletion of Google content | Audit, then unknown | Yes | Done with limits, #22010 |
| 7 | Security scan findings | Unknown | Yes (assessment) | Not started |
| 8 | Remove the experimental gate | Small | No, release step | Not started |
| 9 | REST-backed tool set | Large | Yes | All 36 tools and the switch merged; none switched on |
| 10 | Scope cleanup across code, Cloud and Console | Medium | Yes | App done; broker and Console open |
1. Data-use disclosure in the picker
Done (Nov 17, #21998). Every Google Workspace sign-in start now goes through the picker, including four sign-in paths on the app page. The Gmail read & write line says Google's screen also mentions sending and that Paperclip does not send. The plan below is kept for reference.
Confirmed gap. ServicePicker in
ui/src/features/connections/GoogleWorkspaceServices.tsx shows three service
rows and Cancel / Continue. Its only description is screen-reader text. Google
requires a disclosure inside the app, immediately before consent, that says
what data is accessed and how it is used and shared; a privacy-policy link
alone does not count.
- Add a short visible block above the footer, built from the current selection: what Paperclip will be able to read and change for the chosen services, that agents send this content to the model provider configured for the workspace to do the tasks they are given, that it is not used to train general models, and where results are stored.
- Link the privacy policy and the Limited Use statement.
- The copy changes with the selection (read only versus read & write; Gmail write says "create drafts", never "send").
- Show it for new setup and for reconnect, in both the Apps flow and the
task-hosted flow (both use
GoogleWorkspaceServicesDialog). - Tests in
GoogleWorkspaceServices.test.tsx: disclosure present for each selection, absent wording for unselected services, links present. - Update the Storybook story under
ui/storybook/stories/connection-setup/google-workspace-services.stories.tsx. - Follow
DESIGN.md(tokens only, form footer rules).
Link to https://paperclip.ing/privacy (section 4.1 holds the Limited Use statement). The disclosure wording must agree with that policy, so the policy edits listed in the working memory land first or together. Dotta signs off the wording.
2. Lock the managed scope set to 14
Done in the app (Nov 17, #22001).
GOOGLE_WORKSPACE_SUBMITTED_SCOPES is the hand-written list of 14 and
workspace.all uses it. Requests outside the 14 are rejected; scopes Google
reports on a saved grant are capped to the 14 instead of failing it. The
broker change is in fix 10. The plan below is kept for reference.
Confirmed. The selector derives scopes from
GOOGLE_WORKSPACE_SERVICE_GROUPS in
packages/shared/src/google-workspace-connectors.ts, which yields 14 scopes
across all modes. But the workspace.all profile is still the 21-scope legacy
union (Chat, Contacts, Directory, profile and calendar.readonly included),
and isGoogleWorkspaceScopeGrant accepts any subset of those 21.
- Add a test that the union of every selectable combination equals an explicit list of the 14 scopes, so a new scope cannot slip in unnoticed. Today's tests pin 9 (default) and 21 (legacy) only.
- Add a server test that an authorization request for the unified connection carrying any scope outside the 14 is rejected, for both the managed and the customer-owned path.
- Narrow
isGoogleWorkspaceScopeGrantfor the unified connection to the 14. To check first: whether saved grants or the broker's sealed envelopes depend on the 21-scope definition (the code comment says the union is kept stable for the broker contract). If so, add a separate 14-scope constant and leave the legacy definition for old grants. - Companion change in the Cloud broker registry so the production client cannot be asked for the other 7. App first, then broker (fix 10).
3. Take gmail.modify off the Paperclip-managed client
Done (Nov 17, #22001).
Gmail archive, Chat, People and Workspace Search managed methods are no longer
offered for new setup or reconnect; saved connections keep refreshing and
running. The broker has no gmail.archive profile. The plan below is kept for
reference.
Confirmed. packages/shared/src/app-definitions/gmail.json has a
paperclip-archive method ("Connect with Paperclip", profile gmail.archive)
that requests gmail.modify, a restricted scope that is not in the
submission. If the production broker ever enables that profile, the verified
client requests an undeclared restricted scope.
- Remove the
paperclip-archivemethod, or gate it so it can never use the Paperclip-managed client. Keepcustomer-archive-oauth(the customer's own Google client is outside our verification). - Keep
server/src/services/gmail-archive-tool-policy.tsworking for saved connections. - To check: whether any saved connection uses
paperclip-archive, and whether the production or staging broker hasgmail.archiveenabled. - Do the same inventory for every other "Connect with Paperclip" Google method
in
packages/shared/src/app-definitions/google-*.jsonandgmail.json(Chat, People, Workspace Search and the per-service cards): each one that can reach the managed client either stays within the 14 scopes or loses its managed method. - Test: no app definition with the managed strategy lists a scope outside the 14.
4. Confirm injection screening on Google results
Done (Nov 17, #21999).
Every path was traced and tested. The one unscreened path, resource reads
through a named gateway, is now screened for every connector. What screening
does and does not cover is in doc/prompt-injection-prevention.md. The plan
below is kept for reference.
To check. Tool-result screening exists
(doc/prompt-injection-prevention.md): built-in detection is always on, and a
model check is optional per company. Not yet confirmed that every Google
Workspace tool result passes through it, in particular email bodies and file
content fetched through the unified connection.
- Trace a
gmail__get_messageand adrive__read_file_contentcall from the gateway to the runner and confirm the guard runs on the result. - Add a test with an injected instruction inside an email body and inside a
document, expecting
prompt_injection_blocked. - Fix any path that skips the guard.
- Write two paragraphs for the submission describing what the screening does and does not protect against.
5. Revoke at Google on last disconnect
Confirmed behavior, likely gap. Removing a managed Google connection is
local only, because Google's revoke ends every grant for that user on the
client and would break their other Google connections
(doc/connections/GOOGLE-WORKSPACE.md). With one unified connection that
reasoning mostly goes away, and reviewers expect disconnect to end access.
- When a user removes their last grant on the Paperclip-managed Google client, call Google's revoke endpoint through the broker.
- If other grants for the same Google account remain, stay local and say so in the confirmation text.
- Tests: last grant revokes; one of two does not; a revoke failure still removes the local credential and reports the failure.
- Needs a broker endpoint; broker first.
6. Retention and deletion of Google content
Done, with limits (Nov 17, #22010).
Any connection's page has "Delete data", and removing a connection offers the
same. It clears previews, approval cards, results passed to later runs, app
views and the whole transcript of each settled run that used the connection.
It keeps call records without content. Deleting a task or a company runs
the same cleanup, including run logs and saved files in storage. Limits:
content agents wrote into tasks stays until the task is deleted; "Delete data"
skips runs in progress. The help page is
docs/guides/board-operator/deleting-connection-data.md. The inventory is in
the working memory under "Where Google content is kept". Revoking at Google is
fix 5. The plan below is kept for reference.
To check. Email and file content returned by tools is stored in task comments, run history, tool results and attachments. Disconnecting does not delete any of it. Google requires that users can delete their data and that we document how.
Audit findings (Nov 17, as reported) are in the working memory under "Where Google content is kept". The planned fix is a "delete data read through this connection" action.
- Inventory where Google tool results are stored and for how long.
- Confirm that deleting a task or a workspace removes them.
- Decide with the privacy owner whether an explicit "delete data from this connection" action is needed. If the answer is yes, that becomes its own plan.
- Write the user help page either way.
7. Security scan findings
- Run the static and dynamic scans used for the CASA self-assessment against the server, the broker and the reviewer instance.
- Triage findings into fix now, accepted with reason, and not applicable.
- One pull request per finding class.
8. Remove the experimental gate (release step, last)
Confirmed. enableGoogleWorkspaceConnector defaults to off
(packages/shared/src/validators/instance.ts, set on the app definition in
google-workspace.json, enforced in tool-gateway.ts,
connection-intents.ts and setup-policy.ts).
- After Google approves: default it on, or remove the key and its checks.
- Update
doc/connections/GOOGLE-WORKSPACE.mdand the release notes. - Decide what happens to the aggregator Google apps that appear while the gate is off.
9. REST-backed tool set (chosen November 17)
Decision: launch on our own tools over Google's REST APIs, designed so we can
switch to Google's hosted MCP servers later, kept in one folder so it can be
deleted cleanly. Part 1 is
#22000 (merged Nov 17): the
folder and Gmail get_message, search_threads and create_draft. Its README
records the dispatch trace and the recommended in-process seam.
Status (Nov 17, night):
| Service | Implemented | Switched on | PRs |
|---|---|---|---|
| Gmail | 9 of 9 | No | #22000, #22014 |
| Calendar | 9 of 9 | No | #22017 |
| Drive | 8 of 8 | No | #22028 |
| Docs | 2 of 2 | No | #22029 |
| Sheets | 6 of 6 | No | #22027 |
| Slides | 2 of 2 | No | #22029 |
The per-service switch and in-process dispatch landed in #22016. Every service is still on Google's MCP. The gateway calls the REST tools in process, as the trace in #22000 recommended. The gateway also sets the size limit for REST results (999,885 bytes, matching what it accepts from Google's MCP servers); see "Result size" in the folder README.
Remaining work:
- Refuse inserting an image by public web address in Docs and Slides before they are switched on (Google fetches an address the agent chose).
- Create the staging tester and run live acceptance there.
- Switch services to REST one at a time, each after its live test.
- Record a
tools/listand sample answers from Google's servers for the contract test, and compareread_docandread_presentationcontent. - Check
copy_fileunderdrive.fileon a file the app never opened. - Removal test (step 4 below).
The seam
Today the unified connection sends each tool call, with the user's Google
access token, to a Google MCP endpoint chosen by a closed registry in
packages/shared/src/google-workspace-connectors.ts (serverUrl per service).
Everything above that point (picker, scopes, grant checks, allowlist, approval,
audit, injection screening) only knows tool names and required scopes.
So the replacement is an MCP server of our own that exposes the same tools as Google's: same names, same input fields, same result shape, backed by REST. The rest of the system keeps speaking MCP to it and cannot tell the difference. Switching to Google's MCP later is changing which endpoint the registry returns.
Layout
One folder inside the existing server, not a new package. No new dependency, workspace or release change.
server/src/google-workspace-rest-tools/
index.ts the only entry point: create the server / handle a call
server.ts MCP wiring (list tools, call tool); thin
google-http.ts the one place that calls googleapis.com: auth header,
allowed hosts, errors mapped to MCP errors, retry rules
tools.ts, tool.ts the tool list and the shared tool shape
errors.ts
README.md boundary rules, dispatch trace, differences from Google
gmail/ one file per tool, plus schemas and helpers
drive/ (later) args in, REST request out,
docs/ REST response in, MCP result out
sheets/
slides/
calendar/
Boundary rules
- One switch. The registry gains a transport choice per service
(
google_mcporpaperclip_rest). That choice, plus registering the folder, is the only Google-REST knowledge outside the folder. - No REST types leave the folder. Its public surface is MCP tool
definitions and MCP results. A boundary test limits its imports to its own
files, Node built-ins, the MCP SDK and
zod. - Nothing in the folder knows about Paperclip. No company, connection, grant, policy or audit code. It receives a tool name, arguments and an access token, and returns a result. Authorization, scope checks, approval, audit and injection screening stay with their current owners in the gateway.
- It stores nothing. No tokens, no content, no cache.
- The allowlist stays where it is.
toolScopesingoogle-workspace-connectors.tsremains the single list of allowed tools; the folder implements exactly that list, and a test fails if the two differ. - Removal test. Deleting the folder and setting the switch to
google_mcpleaves a build that passes. Add this as a checklist item for the removal PR.
Parity
- Tool names and schemas come from Google's published MCP tool reference, not from our guess. A contract test compares our definitions with a recorded listing from Google's servers (we can record it on our enrolled internal account).
- Where REST cannot match an MCP tool's behavior exactly, write the difference in the folder's README rather than hiding it.
Order of work
- Trace the dispatch path and confirm the seam. Traced in #22000's README: an in-process call, because the egress guard refuses a loopback address on public deployments.
- Folder skeleton,
google-http.ts, and Gmailget_message,search_threadsandcreate_draft(#22000, merged). Then the switch, end to end on the staging tester. The demo depends on Gmail. - Rest of Gmail, then Calendar, Drive, Docs, Sheets, Slides (done Nov 17).
- Contract and removal tests.
Tools to build (36): Gmail 9, Drive 8, Docs 2, Sheets 6, Slides 2, Calendar 9.
To check
- Whether a Google client marked for AI agents may call the REST APIs.
- Each Cloud project needs the six REST APIs enabled.
- Speed: this sits in the tool-call path. Measured: the adapter adds about 15 µs per call; the result size check adds about 5 µs for a 4 KB result.
Lessons
- Address parsing: patching a split-on-commas parser case by case kept breaking (comments, groups, IPv6 literals); write one RFC 5322 tokenizer with table-driven tests from the start.
- No new package: the server is published, so a new package it depends on would also need publishing; a folder inside the server avoids that.
10. Scope cleanup across code, Cloud and Console
Decision (November 17): what we ask for, what the code accepts, what the
Cloud broker allows and what the Console declares must be the same 14 scopes.
Fixes 2 and 3 cover this repository and are done. Still needed in the Cloud
broker (paperclip-cloud, registry at src/connections/providers.ts, as
reported by the Nov 17 audit):
- Limit
workspace.allto the 14. - On refresh and claim, cap reported scopes to the 14 instead of failing, and keep accepting the old 21-scope refresh binding until older app versions are gone.
- Stop offering Chat, People and Search for new sessions on the verified client.
- Do not merge the branch that adds a Gmail archive profile.
- Deploy order: app first, then broker.
Also needed:
- Compare the Console declaration for both Google apps with the 14 (needs the project owner's sign-in).
- Keep the working memory's "Scopes" and "Cloud broker" sections current.
Read & write Calendar now also requests calendar.events.freebusy (Nov 17).
It is one of the 14 and the broker accepts any nonempty subset of
workspace.all, so neither the broker nor the Console needs a change for it.
Not code, but needed by these fixes
- Published privacy policy and Limited Use statement URLs (fix 1).
- Sign-off on disclosure wording (fix 1).
- Broker changes in the Cloud repository (fixes 5 and 10).
- Current broker profile settings for staging and production (fixes 2, 3).