paperclip/packages/db/src
Dotta 8d1f0c20af
fix: let responsible users choose either AI subscription or API key (#13351)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - AI Connections select the account used for each run.
> - A responsible-user binding must follow the person whose work the
agent performs.
> - The saved sign-in method currently blocks users with another method
for the same provider.
> - This pull request resolves a personal default by company, user, and
provider.
> - Each user can use a subscription or API key with the same bot and
model.

## Linked Issues or Issue Description

Refs #13247, #13248, #13346, #13347.

**What happened?**
A bot configured with a Claude subscription rejects another responsible
user’s Claude API key. Inline repair also limits that person to the
original sign-in method.

**Expected behavior**
The same bot uses each responsible user’s default Claude account,
whether it is a subscription or API key. Explicit shared account
selections remain fixed.

**Steps to reproduce**
1. User A connects a Claude subscription and creates a bot using the
responsible user’s connection.
2. User C connects a personal Claude API key.
3. User C runs the same bot. Before this fix, credential resolution
fails.

## What Changed

- Add a personal provider-default table. Preserve legacy per-method
preferences and backfill the most recently updated preference, including
unavailable defaults. Repeated migration does not replace a selection. A
database trigger propagates old-server default updates without treating
new accounts as replacement defaults.
- Resolve responsible-user bindings by provider. Retain the method as a
wire compatibility hint for old servers. Explicit selections still
require the exact method and grant.
- Use the selected account’s method for credential isolation, refresh
locking, and run attribution.
- Update onboarding, agent setup, the picker, and inline task repair.
Keep existing authentication components and harness/model settings.
- Add mixed-method runtime, migration, repair, and Storybook coverage.
Include upstream’s duplicate Anthropic option fix through the base
branch.

## Verification

- Focused resolver, migration, connection-intent, onboarding, agent
setup, model, and connector UI suites: 331 tests passed.
- Onboarding and new-agent regression suites passed during the initial
focused run.
- UI typecheck, token gates, and Storybook build passed.
- Live browser checks passed for Claude and Codex API-default execution,
switching both back to subscriptions, and both existing shared-account
bots. Bot configuration remained unchanged.
- One Daytona startup command stalled before Claude launched. The test
run was cancelled, its sandbox stopped, and the same account/task passed
on retry. Startup cancellation remains a separate environment finding;
this PR does not change that command transport.
- Browser review: all eight assertions passed in the new mixed-method
story, including shared selection, return to responsible-user selection,
and unchanged harness/model.
- Repository build and typecheck passed after refreshing upstream
dependencies. Final resolver and historical rollback verification: 38
tests passed. All latest-head CI gates passed, including
server/workspace/serialized suites, browser E2E, build, typecheck, and
runner verification. The extra serial local full-suite run was stopped
after equivalent CI passed; focused local checks completed.

## Risks

- Users with both historical method defaults get their most recently
updated preference as the initial provider default. They can change it
explicitly in Connections.
- A revoked or unavailable default blocks. Connecting an additional
account does not silently replace it.
- Existing legacy authentication is unchanged. Managed responsible-user
bindings intentionally stop pinning a method.
- Live staging: the same Claude and Codex bots completed real API-key
runs after changing only the personal default, then completed
subscription runs after restoring the original defaults. Read-only
database verification confirms unchanged bot configuration and actual
method attribution. Distinct-user concurrency is covered by automated
real-database tests with synthetic credentials, not two live human
logins.

## Model Used

OpenAI GPT-6 (Codex), with reasoning, repository tools, code execution,
and browser interaction. The runtime does not expose a more specific
model ID or context-window size.

## 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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-09-12 20:27:26 -05:00
..
migrations fix: let responsible users choose either AI subscription or API key (#13351) 2026-09-12 20:27:26 -05:00
schema fix: let responsible users choose either AI subscription or API key (#13351) 2026-09-12 20:27:26 -05:00
adapter-auth-sessions-schema.test.ts feat(auth): normalize agent login in the sandbox onto one session table and a capability contract (#11730) 2026-08-19 11:51:31 -07:00
agent-chat-migration.test.ts feat: add experimental persistent agent chat (#13284) 2026-09-12 08:56:04 -05:00
agent-wakeup-requests-schema.test.ts fix: preserve recovery retries across restarts (#11817) 2026-08-20 17:09:42 -05:00
backup-lib.test.ts feat(connections): add self-serve intent runtime (#12345) 2026-08-29 12:08:34 -05:00
backup-lib.ts feat(connections): add self-serve intent runtime (#12345) 2026-08-29 12:08:34 -05:00
backup.ts [codex] Add LLM Wiki plugin host support (#5597) 2026-05-10 07:34:12 -05:00
better-auth-account-issuer-migration.test.ts Add the Better Auth issuer column so signup and sign-in work (#12396) 2026-08-27 22:31:35 -07:00
built-in-agent-unique-marker-migration.test.ts fix: prevent duplicate built-in agents and self-heal reconciliation (#10223) 2026-07-28 11:12:58 -07:00
chat-identity-migration-reconciliation.test.ts feat: add opt-in chat provider and data foundation (#13100) 2026-09-09 13:49:12 -05:00
chat-telegram-draft-ids-migration.test.ts feat: add opt-in chat provider and data foundation (#13100) 2026-09-09 13:49:12 -05:00
chat-tenant-foreign-keys.test.ts feat: add opt-in chat provider and data foundation (#13100) 2026-09-09 13:49:12 -05:00
check-migration-numbering.ts feat(routines): add workspace-aware routine runs 2026-04-02 11:38:57 -05:00
check-migration-safety.test.ts feat(db): add migration safety lint 2026-07-07 01:43:12 +00:00
check-migration-safety.ts feat(db): add migration safety lint 2026-07-07 01:43:12 +00:00
client-options.test.ts fix(db): reap idle pool connections, name the pool, and end it on shutdown (#12956) 2026-09-08 08:56:39 -07:00
client-teardown-registry.test.ts fix(db): close test database clients before the embedded Postgres cluster stops (#12335) 2026-08-27 13:39:42 -07:00
client.test.ts feat: add opt-in chat provider and data foundation (#13100) 2026-09-09 13:49:12 -05:00
client.ts fix(db): reap idle pool connections, name the pool, and end it on shutdown (#12956) 2026-09-08 08:56:39 -07:00
company-secret-proposals-migration.test.ts Add governed secret alias confirmation cards (#11486) 2026-08-18 09:44:24 -05:00
connection-grants-phase2-migration.test.ts feat(apps): add connection grants and delegated identities (#12341) 2026-08-29 12:08:33 -05:00
connection-grants-phase4-migration.test.ts feat(apps): add connection grants and delegated identities (#12341) 2026-08-29 12:08:33 -05:00
connections-v3-schema-core-migration.test.ts fix: let responsible users choose either AI subscription or API key (#13351) 2026-09-12 20:27:26 -05:00
decision-queue-migrations.test.ts feat(decisions): add desk workflow and retention (#10672) 2026-08-02 10:47:03 -05:00
embedded-postgres-error.test.ts Improve embedded Postgres bootstrap errors 2026-03-26 12:35:19 -05:00
embedded-postgres-error.ts Improve embedded Postgres bootstrap errors 2026-03-26 12:35:19 -05:00
embedded-postgres-lifecycle.test.ts fix(workspaces): keep deferred seed databases reliable (#11706) 2026-08-19 10:41:29 -05:00
embedded-postgres-lifecycle.ts fix(workspaces): keep deferred seed databases reliable (#11706) 2026-08-19 10:41:29 -05:00
embedded-postgres-native.test.ts feat(cli): add managed install, update, and service lifecycle (#10045) 2026-07-31 18:52:23 -07:00
embedded-postgres-native.ts [codex] Improve runtime and import reliability (#6549) 2026-05-22 09:57:22 -05:00
environment-custom-images-schema.test.ts Scope environment custom images to instance environments (#8850) 2026-07-01 23:57:31 -07:00
external-objects-schema.test.ts External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
heartbeat-context-snapshot-index-migration.test.ts perf(server): cut steady-state DB hot paths in dashboard, attention, and productivity sweeps (#10992) 2026-08-06 11:56:40 -05:00
inbox-archive-agent-policies-migration.test.ts feat(authz): govern agent inbox archive access (#9658) 2026-07-16 09:51:48 -05:00
index.ts fix(cli): make embedded-Postgres tests survive runner contention (#12466) 2026-08-28 13:51:54 -07:00
issue-comment-derived-attribution-migration.test.ts fix(db): relocate slow 0126 issue-comment attribution backfill to fast idempotent 0132 (#9108) 2026-07-06 11:41:24 -07:00
issue-comment-on-behalf-migration.test.ts feat(issues): contain cross-issue agent side effects (#10837) 2026-08-04 13:17:49 -05:00
issue-thread-interaction-resolver-policy-migration.test.ts fix(interactions): authorize resolvers consistently (#11376) 2026-08-16 13:46:50 -05:00
migrate.ts Fix dev migration prompt and embedded db:migrate 2026-03-10 15:31:05 -05:00
migration-runtime.ts [codex] Improve runtime and import reliability (#6549) 2026-05-22 09:57:22 -05:00
migration-safety-baseline.ts feat(db): add migration safety lint 2026-07-07 01:43:12 +00:00
migration-snapshot-drift.test.ts Repair the drizzle snapshot so generate emits no spurious migration (#12333) 2026-08-27 12:56:07 -07:00
migration-status.ts feat(costs): add billing, quota, and budget control plane 2026-03-16 15:11:01 -05:00
native-runner-recovery-migration.test.ts fix(runner): recover native sessions across restarts (#12845) 2026-09-04 15:03:53 -05:00
nested-skill-folders-migration.test.ts feat: organize skills with nested folders and My Skills (#9633) 2026-07-16 15:50:45 -05:00
pipelines-schema.test.ts Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
question-response-delivery-migration.test.ts fix(interactions): deliver question answers durably (#12307) 2026-08-27 12:12:21 -05:00
run-event-payload.test.ts fix: preserve NUL characters in run-event payloads (#13325) 2026-09-12 13:34:45 -05:00
run-event-payload.ts fix: preserve NUL characters in run-event payloads (#13325) 2026-09-12 13:34:45 -05:00
run-identity-migration.test.ts feat: use the responsible person's GitHub for shared agent operations (#13005) 2026-09-07 14:32:20 -05:00
runtime-config.test.ts [codex] Add LLM Wiki plugin host support (#5597) 2026-05-10 07:34:12 -05:00
runtime-config.ts [codex] Add LLM Wiki plugin host support (#5597) 2026-05-10 07:34:12 -05:00
seed.ts Expand data model with companies, approvals, costs, and heartbeats 2026-02-17 09:07:22 -06:00
session-goal-migration.test.ts Add end-to-end session goals to Paperclip Runner 2026-09-08 16:18:47 -05:00
status-card-migrations.test.ts fix(db): give the last two embedded-Postgres migration tests a timeout (#11313) 2026-08-12 21:30:50 -07:00
summary-slots-schema.test.ts feat: add built-in summarizer and summary slots (#9713) 2026-07-17 11:03:07 -05:00
table-size-estimates.ts Replace host-to-host Cloud Sync with full-fidelity company Import/Export (#10507) 2026-07-30 11:37:00 -07:00
test-embedded-postgres.test.ts fix(db): harden embedded Postgres test start with bounded retry (#10540) 2026-07-30 22:22:31 -07:00
test-embedded-postgres.ts fix(cli): make embedded-Postgres tests survive runner contention (#12466) 2026-08-28 13:51:54 -07:00
vercel-connect-credential-source-migration.test.ts feat(connections): add managed external MCP connectors (#12346) 2026-08-29 12:08:34 -05:00