mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents run with an AI account that a person connects, for example a
personal Claude subscription
> - Paperclip keeps the saved sign-in of a personal account as a value
of a user secret, and that secret shows on the Secrets page
> - A person can delete or disable that secret, or its value in My
secrets, and Paperclip does not stop them
> - Then the connection still shows as healthy, but every agent run that
uses it fails with "Reconnect this AI account"
> - The reconnect also refuses the changed sign-in slot, so the person
cannot repair the account in place
> - This pull request refuses to delete or disable a user secret or its
value while a connected account uses it, and tells the person to
disconnect the account instead
> - The benefit is that a cleanup on the Secrets page cannot silently
stop all agent runs
## Linked Issues or Issue Description
**What happened?**
A user deleted the user secret that holds the saved sign-in of their
personal Claude subscription. The Secrets page did not warn them. After
that, every agent run failed with "Reconnect this AI account"
(`configuration_incomplete`). The connection still showed as healthy and
stayed the default for the provider. When the user tried to reconnect,
Paperclip refused the personal reconnect because the sign-in slot was
changed. The user then added a new company-shared account. Agents that
use "my default" ignore company-shared accounts, so the runs continued
to fail.
**Expected behavior**
Paperclip does not let a person delete or disable a secret that a
connected account uses. The message names the account and tells the
person to disconnect the account instead.
**Steps to reproduce**
1. Connect a personal Claude subscription and make it your default.
2. Open the Secrets page. Find the user secret with the key
`ai_<grantId>`.
3. Disable it or delete it.
4. Assign a task to an agent that uses your default AI account.
5. The run fails with "Reconnect this AI account". The AI account still
shows as healthy.
**Paperclip version or commit**
`master` at c72c468708
**Deployment mode**
Authenticated (hosted)
Related: #19406 (reuses the private sign-in slot when a person
reconnects a removed connection).
## What Changed
- `server/src/services/secrets.ts`: Add `assertNoConnectionSignsInWith`.
It takes a user secret definition or one value. It looks for a
connection that is not archived, or a grant that is not revoked, that
refers to one of the values. If it finds one, it throws a 409 with the
code `secret_used_by_connection` and the connection name.
- Add `withoutConnectionSignIn`. It holds
`withAccountHomeSecretMutationLock` for the company across the check and
the change. A reconnect (`aiConnectionService.save`) holds the same lock
while it rotates the value and reactivates the grant, so a reconnect
cannot land between the check and the change. The lock is re-entrant, so
the nested secret removals share it.
- The check applies to:
- `removeUserSecretDefinition`, and `updateUserSecretDefinition` with
`status: "deleted"`;
- `updateUserSecretDefinition` when the status changes away from
`active` (for example `disabled`);
- `removeCurrentUserSecretValue` (My secrets delete), and
`updateCurrentUserSecretValue` with `status: "deleted"`;
- `updateCurrentUserSecretValue` when the status changes away from
`active`.
- Other changes are not affected, for example a new name or a
reactivation to `active`. The internal disconnect cleanup uses
`secrets.remove` after it revokes the grant, so it does not change.
- The Secrets page already shows the error text in its toast, so the UI
does not change.
## Verification
- New test
`server/src/__tests__/secrets-service-connection-sign-in.test.ts`
(embedded Postgres). It saves a real personal Claude subscription
connection and checks that:
- a delete is refused with 409, names the account, and leaves the secret
and its definition active;
- a disable is refused, and a rename still works;
- a delete or disable of the value from My secrets is refused, and a
reactivation to `active` still works;
- a delete that waits behind a reconnect is refused when the reconnect
reactivates the grant first;
- after a disconnect (grant revoked), the delete succeeds.
- Without the change in `secrets.ts`, the refusal tests fail. With only
the first version of the check (outside the lock, definitions only), the
My secrets test and the reconnect-order test fail.
- `pnpm exec vitest run
server/src/__tests__/secrets-service-connection-sign-in.test.ts
server/src/__tests__/secrets-service.test.ts
server/src/__tests__/secrets-service-dangling-user-secret.test.ts
server/src/__tests__/secrets-routes.test.ts
server/src/__tests__/secrets-service-user-secret-owner-scoped.test.ts
server/src/__tests__/antigravity-disconnect-sign-in.test.ts
server/src/__tests__/agent-hire-ai-connections.test.ts
server/src/__tests__/github-catalog-timing.test.ts
server/src/__tests__/tool-gateway.test.ts`: 9 files, 393 tests pass.
- `pnpm --filter @paperclipai/server typecheck` passes.
## Risks
- Low risk. The check only blocks a delete or a disable of a user secret
definition or value. The disconnect flows remove the sign-in through a
different path (`secrets.remove` after the grant is revoked), so they do
not change.
- These deletes and disables now wait for the company's secret mutation
lock. A concurrent secret write can delay them for a short time.
- A person who wants to remove the secret must now disconnect the
account first. This is the intended order.
- This change does not repair a connection whose secret is already gone.
Such a connection still shows as healthy. The owner must disconnect it
and connect the account again.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) 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
- [ ] 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