paperclip/packages/db/src/migrations
Dotta d2e3f7dce5
fix(db): correct 0130 responsible-user backfill in place (inbox resurface) (#9111)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Users triage agent work through the issue inbox, which suppresses
archived issues by comparing issue `updated_at` against the archive
timestamp
> - Migration `0130_run_responsible_user_invariant` backfilled
responsible-user columns but also set `updated_at = now()` on every row
it touched (companies, issues, routines, routine_runs, heartbeat_runs)
> - That blanket timestamp bump made every archived issue look newly
updated, resurfacing thousands of archived issues into every user's
inbox
> - This pull request corrects the 0130 backfill in place so it only
fills `NULL` responsible-user columns and never touches timestamps, and
adds tests that prevent this class of bug from being reintroduced
> - The benefit is that inbox archive suppression stays intact across
migrations, and no future migration backfill can silently bump
`updated_at` on user-visible tables

## Linked Issues or Issue Description

**Bug description (no public issue exists):**

- **What happened:** after upgrading a dev instance across migration
0130, every previously archived inbox item resurfaced as unread/new for
all users.
- **Expected:** data backfills must not alter row modification
timestamps; archived issues stay archived unless genuinely updated.
- **Root cause:** the 0130 backfill's `UPDATE` statements set
`updated_at = now()` alongside the responsible-user columns.

## What Changed

- `packages/db/src/migrations/0130_run_responsible_user_invariant.sql`:
removed all `updated_at = now()` assignments from the backfill UPDATEs;
the migration now only fills `NULL` responsible-user columns. The file
is corrected **in place** (no new migration number, journal untouched)
because 0130 has never shipped in a published release.
- `packages/db/src/client.test.ts`: added a guard test that scans every
migration and rejects backfills that bump `updated_at` on user-visible
tables (with an explicit allowlist for the pre-existing 0131 repair
migration).
- `packages/db/src/client.test.ts`: added a replay test that simulates
an already-migrated database picking up the corrected file (deletes the
0130 ledger hash, re-applies mid-journal) and asserts issue `updated_at`
and inbox-archive suppression ordering are untouched.

### Why an in-place edit is safe

- 0130 only exists on master/canary builds; the latest published release
(v2026.626.0) predates it.
- The migration ledger is content-hash based: databases that already
applied the old 0130 keep an orphaned hash row (harmless) and see the
corrected file as pending, so they replay the corrected backfill — which
is idempotent (fills `NULL`s only, no timestamp writes).
- Fresh databases simply run the corrected 0130 in journal order.

## Verification

- `pnpm --filter @paperclipai/db run check:migrations` — clean
- `cd packages/db && npx vitest run src/client.test.ts` — 11/11 passing
against embedded Postgres, including the new guard and mid-journal
replay tests

## Risks

- Migration safety: the corrected backfill is idempotent and only writes
`NULL` columns; replay on already-migrated databases is exercised
directly by the new test. No schema changes.
- Databases that already ran the old 0130 keep the bumped timestamps
from that run; repairing historical damage is intentionally out of scope
here (no released build ever contained the bug).

## Model Used

- Claude Opus 4.7 (`claude-opus-4-7`, extended thinking, tool use) via
Claude Code / Paperclip agent runtime

## 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 (backup health alert work split into #9113; no other related
open PRs)
- [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 (none
needed for a migration content fix)
- [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

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-06 16:56:30 -05:00
..
meta [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00
0000_mature_masked_marvel.sql Expand data model with companies, approvals, costs, and heartbeats 2026-02-17 09:07:22 -06:00
0001_fast_northstar.sql Add agent runtime DB schemas and expand shared types 2026-02-17 12:24:38 -06:00
0002_big_zaladane.sql Add agent runtime DB schemas and expand shared types 2026-02-17 12:24:38 -06:00
0003_shallow_quentin_quire.sql Add issue identifiers, activity run tracking, and migration inspection 2026-02-19 09:09:26 -06:00
0004_issue_identifiers.sql Add issue identifiers, activity run tracking, and migration inspection 2026-02-19 09:09:26 -06:00
0005_chief_luke_cage.sql Add agent config revisions, issue-approval links, and robust migration reconciliation 2026-02-19 13:02:14 -06:00
0006_overjoyed_mister_sinister.sql Add agent config revisions, issue-approval links, and robust migration reconciliation 2026-02-19 13:02:14 -06:00
0007_new_quentin_quire.sql Add agent task sessions table, session types, and programmatic DB backup 2026-02-19 14:01:40 -06:00
0008_amused_zzzax.sql Add secrets infrastructure: DB tables, shared types, env binding model, and migration improvements 2026-02-19 15:43:43 -06:00
0009_fast_jackal.sql Add secrets infrastructure: DB tables, shared types, env binding model, and migration improvements 2026-02-19 15:43:43 -06:00
0010_stale_justin_hammer.sql chore: add assets/attachments DB migration, CLI docs, and lockfile 2026-02-20 10:33:36 -06:00
0011_windy_corsair.sql feat: add project_goals many-to-many join table 2026-02-20 13:43:25 -06:00
0012_perpetual_ser_duncan.sql Implement issue execution lock with deferred wake promotion 2026-02-20 15:48:22 -06:00
0013_dashing_wasp.sql Implement issue execution lock with deferred wake promotion 2026-02-20 15:48:22 -06:00
0014_many_mikhail_rasputin.sql feat: add auth/access foundation - deps, DB schema, shared types, and config 2026-02-23 14:40:16 -06:00
0015_project_color_archived.sql feat: foldable PROJECTS section in sidebar with color support 2026-02-23 09:14:08 -06:00
0016_agent_icon.sql feat: add agent icons with picker and collapsible sidebar section 2026-02-23 12:25:13 -06:00
0017_tiresome_gabe_jones.sql fix(db): cast REPEAT count to integer in migration 0017 2026-02-23 16:25:23 -06:00
0018_flat_sleepwalker.sql feat: add issue labels (DB schema, API, and service) 2026-02-25 08:38:37 -06:00
0019_public_victor_mancha.sql feat: add project workspaces (DB, API, service, and UI) 2026-02-25 08:38:46 -06:00
0020_white_anita_blake.sql feat: workspace improvements - nullable cwd, repo-only workspaces, and resolution refactor 2026-02-25 21:35:33 -06:00
0021_chief_vindicator.sql feat: per-issue assignee adapter overrides (model, effort, workspace) 2026-02-26 10:32:44 -06:00
0022_company_brand_color.sql feat: join request claim secrets, onboarding API, and company branding 2026-02-26 16:33:20 -06:00
0023_fair_lethal_legion.sql feat: join request claim secrets, onboarding API, and company branding 2026-02-26 16:33:20 -06:00
0024_far_beast.sql Add touched/unread inbox issue semantics 2026-03-06 08:21:03 -06:00
0025_nasty_salo.sql Persist issue read state and clear unread on open 2026-03-06 08:34:19 -06:00
0026_lying_pete_wisdom.sql Add worktree-aware workspace runtime support 2026-03-10 10:58:38 -05:00
0027_tranquil_tenebrous.sql Add project-first execution workspace policies 2026-03-10 10:58:43 -05:00
0028_harsh_goliath.sql feat(issues): add issue documents and inline editing 2026-03-13 21:30:48 -05:00
0029_plugin_tables.sql Merge public-gh/master into feature/plugin-runtime-instance-cleanup 2026-03-14 10:46:19 -05:00
0030_rich_magneto.sql Use asset-backed company logos 2026-03-16 09:25:39 -05:00
0031_zippy_magma.sql feat(costs): add billing, quota, and budget control plane 2026-03-16 15:11:01 -05:00
0032_pretty_doctor_octopus.sql feat(costs): add billing, quota, and budget control plane 2026-03-16 15:11:01 -05:00
0033_shiny_black_tarantula.sql Harden budget enforcement and migration startup 2026-03-16 15:11:34 -05:00
0034_fat_dormammu.sql Fix budget incident resolution edge cases 2026-03-16 16:48:13 -05:00
0035_marvelous_satana.sql Merge remote-tracking branch 'public-gh/master' into paperclip-subissues 2026-03-16 17:19:55 -05:00
0036_cheerful_nitro.sql Add instance experimental setting for isolated workspaces 2026-03-17 09:24:28 -05:00
0037_friendly_eddie_brock.sql Add workspace operation tracking and fix project properties JSX 2026-03-17 09:36:35 -05:00
0038_careless_iron_monger.sql Improve orphaned local heartbeat recovery 2026-03-20 06:05:15 -05:00
0039_fat_magneto.sql fix: renumber worktree merge history migrations 2026-03-20 17:23:45 -05:00
0040_eager_shotgun.sql fix: renumber worktree merge history migrations 2026-03-20 17:23:45 -05:00
0041_curly_maria_hill.sql fix: renumber worktree merge history migrations 2026-03-20 17:23:45 -05:00
0042_spotty_the_renegades.sql fix: renumber worktree merge history migrations 2026-03-20 17:23:45 -05:00
0043_reflective_captain_universe.sql fix: renumber worktree merge history migrations 2026-03-20 17:23:45 -05:00
0044_illegal_toad.sql Address Greptile review on board CLI auth 2026-03-23 08:46:05 -05:00
0045_workable_shockwave.sql Add the inbox mine tab and archive flow 2026-03-26 16:09:43 -05:00
0046_smooth_sentinels.sql fix(db): make document revision migration replay-safe 2026-03-31 08:09:00 -05:00
0047_overjoyed_groot.sql fix: make feedback migration replay-safe after rebase 2026-04-02 10:54:56 -05:00
0048_flashy_marrow.sql feat(routines): add workspace-aware routine runs 2026-04-02 11:38:57 -05:00
0049_flawless_abomination.sql fix: address greptile feedback for blocker dependencies 2026-04-06 09:03:13 -05:00
0050_stiff_luckman.sql Add project-level environment variables 2026-04-06 21:23:30 -05:00
0051_young_korg.sql Speed up issue search 2026-04-06 21:25:41 -05:00
0052_mushy_trauma.sql Generate execution policy migration 2026-04-07 17:43:10 -05:00
0053_sharp_wild_child.sql Persist non-issue inbox dismissals 2026-04-09 06:16:05 -05:00
0054_draft_routines.sql Add draft routine defaults and run-time overrides 2026-04-09 10:19:52 -05:00
0055_kind_weapon_omega.sql fix: harden heartbeat and adapter runtime workflows 2026-04-10 22:26:21 -05:00
0056_spooky_ultragirl.sql [codex] Improve workspace runtime and navigation ergonomics (#3680) 2026-04-14 12:57:11 -05:00
0057_tidy_join_requests.sql feat: implement multi-user access and invite flows (#3784) 2026-04-17 09:44:19 -05:00
0058_wealthy_starbolt.sql [codex] Add run liveness continuations (#4083) 2026-04-20 06:01:49 -05:00
0059_plugin_database_namespaces.sql [codex] Add plugin orchestration host APIs (#4114) 2026-04-20 08:52:51 -05:00
0060_orange_annihilus.sql Add first-class issue references (#4214) 2026-04-21 10:02:52 -05:00
0061_lively_thor_girl.sql [codex] Harden heartbeat scheduling and runtime controls (#4223) 2026-04-21 12:24:11 -05:00
0062_routine_run_dispatch_fingerprint.sql [codex] Harden heartbeat scheduling and runtime controls (#4223) 2026-04-21 12:24:11 -05:00
0063_issue_thread_interactions.sql [codex] Add structured issue-thread interactions (#4244) 2026-04-21 20:15:11 -05:00
0064_issue_thread_interaction_idempotency.sql [codex] Add structured issue-thread interactions (#4244) 2026-04-21 20:15:11 -05:00
0065_environments.sql Add local environment lifecycle (#4297) 2026-04-22 20:07:41 -07:00
0066_issue_tree_holds.sql [codex] Add issue subtree pause, cancel, and restore controls (#4332) 2026-04-23 14:51:46 -05:00
0067_agent_default_environment.sql Add SSH environment support (#4358) 2026-04-23 19:15:22 -07:00
0068_environment_local_driver_unique.sql Add SSH environment support (#4358) 2026-04-23 19:15:22 -07:00
0069_liveness_recovery_dedupe.sql [codex] Add runtime lifecycle recovery and live issue visibility (#4419) 2026-04-24 15:50:32 -05:00
0070_active_run_output_watchdog.sql [codex] Add runtime lifecycle recovery and live issue visibility (#4419) 2026-04-24 15:50:32 -05:00
0071_default_hire_approval_off.sql [codex] Harden recovery issue handling (#4600) 2026-04-27 15:02:47 -05:00
0072_large_sandman.sql [codex] Harden recovery issue handling (#4600) 2026-04-27 15:02:47 -05:00
0073_shiny_salo.sql [codex] Split backend control-plane QoL slice (#4700) 2026-04-28 16:46:45 -05:00
0074_striped_genesis.sql [codex] Split backend control-plane QoL slice (#4700) 2026-04-28 16:46:45 -05:00
0075_cultured_sebastian_shaw.sql [codex] Add issue monitor liveness controls (#4988) 2026-05-03 08:58:53 -05:00
0076_useful_elektra.sql Expand plugin host surface (#5205) 2026-05-05 07:42:57 -05:00
0077_unusual_karnak.sql Add routine revision history and restore flow (#5285) 2026-05-05 11:54:52 -05:00
0078_white_darwin.sql Show workspace changes and stale notices in issue threads (#5356) 2026-05-06 09:00:54 -05:00
0079_company_search_document_indexes.sql Add full company search page (#5293) 2026-05-06 06:32:37 -05:00
0080_company_search_fuzzystrmatch.sql Add full company search page (#5293) 2026-05-06 06:32:37 -05:00
0081_optimal_dormammu.sql Add planning mode for issue work (#5353) 2026-05-06 07:01:28 -05:00
0082_dry_vision.sql Add secrets provider vaults and remote import (#5429) 2026-05-09 18:22:17 -05:00
0083_company_secret_provider_configs.sql Add secrets provider vaults and remote import (#5429) 2026-05-09 18:22:17 -05:00
0084_issue_recovery_actions.sql [codex] Add source-scoped recovery actions (#5599) 2026-05-12 09:37:15 -05:00
0085_tranquil_the_executioner.sql [codex] Add issue document locking (#6009) 2026-05-15 08:54:55 -05:00
0086_routine_env_runtime_contract.sql [codex] Add routine env secrets support (#6212) 2026-05-17 16:30:34 -05:00
0087_backfill_environment_manage_human_defaults.sql [codex] Add agent permissions and controls plan (#6386) 2026-05-22 08:12:52 -05:00
0088_backfill_principal_access_compatibility.sql [codex] Add agent permissions and controls plan (#6386) 2026-05-22 08:12:52 -05:00
0089_cloud_upstreams.sql [codex] Add local Cloud Upstream sync (#6548) 2026-05-22 09:56:22 -05:00
0090_resource_memberships.sql [codex] Add resource membership controls (#6677) 2026-05-25 13:12:41 -05:00
0091_old_swarm.sql [codex] Add document annotations and comments (#6733) 2026-05-26 06:41:23 -07:00
0092_mighty_puma.sql Add accepted-plan decomposition exact-once guards and UI state (#6831) 2026-05-28 23:30:18 -07:00
0093_giant_green_goblin.sql PAPA-430: workspace finalize gates + no-remote-git enforcement (#6969) 2026-05-29 08:25:29 -07:00
0094_backfill_archived_company_agent_pauses.sql fix: Stop archived companies from waking agents (#7478) 2026-06-03 21:07:14 -07:00
0095_issue_comment_tombstones.sql Redact deleted issue comments 2026-06-05 03:20:46 +00:00
0096_document_annotation_issue_comment_links.sql Redact deleted issue comments 2026-06-05 03:20:46 +00:00
0097_low_trust_source_trust.sql Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
0098_project_icon.sql Information Architecture + project/agent visual refresh (experimental) (#7543) 2026-06-06 09:17:27 -05:00
0099_skills_store_foundation.sql Build the Skills Store (#7990) 2026-06-11 14:02:09 -05:00
0100_skill_install_count_backfill.sql Build the Skills Store (#7990) 2026-06-11 14:02:09 -05:00
0101_plugin_company_id_tenant_isolation.sql feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
0102_managed_sandbox_dedup_index.sql fix(environments): partial unique index to dedup managed sandbox rows (#8247) 2026-06-17 16:09:45 -07:00
0103_agent_error_reason.sql fix(server): enforce agent secret binding sync across lifecycle flows (#8307) 2026-06-18 21:26:36 -07:00
0104_issue_watchdogs.sql [codex] feat(watchdog): add task watchdog control plane (#8339) 2026-06-19 15:38:52 -05:00
0105_instance_scoped_environments.sql refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
0106_external_object_references.sql External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
0107_external_object_display_metadata.sql External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
0108_workspace_operations_issue_id.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0109_routine_description_annotations.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0110_document_company_cascade.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0111_backfill_skill_create_human_defaults.sql [codex] Gate skill mutations with skills:create permission (#8616) 2026-06-25 09:49:10 -05:00
0112_rename_skill_create_permission_key.sql [codex] Gate skill mutations with skills:create permission (#8616) 2026-06-25 09:49:10 -05:00
0113_pipeline_foundation.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0114_pipeline_case_issue_unlinked_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0115_pipeline_routine_origin.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0116_pipeline_upstream_drift_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0117_pipeline_transition_forced_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0118_pipeline_case_agent_fanout.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0119_pipeline_drift_acknowledged_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0120_pipeline_stage_working_primitives.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0121_pipeline_automation_retry_effects.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0122_pipeline_case_documents.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0123_document_annotation_source_trust.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0124_agent_api_key_scope_config.sql [codex] Add built-in Hermes adapters (#8543) 2026-06-26 16:04:58 -05:00
0125_environment_custom_image_templates.sql Add reusable sandbox custom images (#8794) 2026-06-30 09:57:49 -07:00
0127_environment_custom_images_instance_scoped.sql Scope environment custom images to instance environments (#8850) 2026-07-01 23:57:31 -07:00
0128_user_specific_secrets.sql feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
0129_agent_api_key_responsible_user.sql feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
0130_run_responsible_user_invariant.sql fix(db): correct 0130 responsible-user backfill in place (inbox resurface) (#9111) 2026-07-06 16:56:30 -05:00
0131_repair_run_responsible_user_context_refs.sql Fix heartbeat run responsible user migration for identifier refs (#9107) 2026-07-06 13:14:18 -05:00
0132_issue_comment_derived_attribution_fast.sql fix(db): relocate slow 0126 issue-comment attribution backfill to fast idempotent 0132 (#9108) 2026-07-06 11:41:24 -07:00
0133_resource_membership_stars.sql [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00