paperclip/packages/db/src
Dotta 0f08c2b526
fix(db): repair responsible user migration timestamps (#9146)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The database migration layer keeps local and deployed instances
moving forward safely as schema/data contracts evolve.
> - The responsible-user backfill migration could make historical issues
look newly updated by bumping user-visible `updated_at` columns during a
backfill.
> - That timestamp churn can invalidate inbox/archive state and make old
work appear fresh even though no user-facing activity happened.
> - This pull request moves the responsible-user invariant migration
later in the current migration sequence, keeps it from touching
user-visible timestamps, and adds a repair sweep for databases that
already saw the timestamp bump.
> - The benefit is safer migration replay and regression coverage for
future backfills that might otherwise mutate visible timestamps.

## Linked Issues or Issue Description

No public GitHub issue exists. Inline bug report:

**Pre-submission checklist**

- [x] I have searched existing open and closed issues and this is not a
duplicate.
- [x] I am on the latest released version of Paperclip (or can reproduce
on `master`).
- [x] I have confirmed the error originates in Paperclip itself — not in
my agent adapter, API provider, or local configuration.

**What happened?**

A responsible-user migration backfill could update user-visible
`updated_at` columns while filling missing responsible-user data. That
makes historical issues/runs/routines appear newer even when no
user-facing activity happened.

**Expected behavior**

Responsible-user backfills should populate ownership metadata without
mutating user-visible recency fields, and databases already affected by
a timestamp sweep should be repairable.

**Steps to reproduce**

1. Start from current `master` with the responsible-user migration
sequence.
2. Apply migrations to a database containing historical issues, runs,
routines, and companies with older activity timestamps.
3. Replay the responsible-user invariant migration and inspect
user-visible `updated_at` values.

**Paperclip version or commit**

`master` at the PR base.

**Deployment mode**

Local dev (`pnpm dev`) and deployed instances using the same migrations.

**Installation method**

Built from source (`pnpm dev` / `pnpm build`).

**Agent adapter(s) involved**

- [x] Not adapter-specific (core bug)

**Database mode**

External Postgres and embedded development Postgres migration paths.

**Access context**

Board and agent-visible issue recency can both be affected.

**Relevant logs or output**

Covered by the added embedded-Postgres regression tests.

**Relevant config (if applicable)**

Not applicable.

**Additional context**

This PR adapts an extracted local migration fix onto the current master
migration sequence, where `0133` is already occupied.

**Privacy checklist**

- [x] I have reviewed all pasted output for PII (usernames, file paths,
API keys, tokens, company names) and redacted where necessary.

## What Changed

- Renumbered the responsible-user invariant migration onto the current
master migration sequence.
- Added a repair migration that detects broad timestamp sweeps and
restores safer `updated_at` values for issues, heartbeat runs, routines,
routine runs, and companies.
- Added focused embedded-Postgres regression coverage for the relocated
migration, repair migration, and updated-at backfill allowlist.

## Verification

- `pnpm --filter @paperclipai/db run check:migrations`
- `/srv/paperclip/home/paperclipai/paperclip/node_modules/.bin/vitest
run packages/db/src/client.test.ts -t "migration 0134|migration
0135|unallowlisted migration backfills"`

## Risks

Migration behavior is the main risk. The PR intentionally changes the
active migration sequence by removing the old responsible-user invariant
slot and replaying that work later with a repair migration. Reviewers
should confirm this matches the intended release/migration policy for
installations that may already have applied the earlier migration.

> 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

OpenAI Codex, GPT-5.5 coding agent with repository tool use and local
shell execution. Context window was not surfaced by the 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
- [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
- [ ] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-07 05:54:17 -05:00
..
migrations fix(db): repair responsible user migration timestamps (#9146) 2026-07-07 05:54:17 -05:00
schema [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00
backup-lib.test.ts [codex] Runtime control-plane fixes (#6380) 2026-05-20 10:37:11 -05:00
backup-lib.ts [codex] Runtime control-plane fixes (#6380) 2026-05-20 10:37:11 -05:00
backup.ts [codex] Add LLM Wiki plugin host support (#5597) 2026-05-10 07:34: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.test.ts fix(db): repair responsible user migration timestamps (#9146) 2026-07-07 05:54:17 -05:00
client.ts Add routines automation workflows 2026-03-19 08:39:24 -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-native.test.ts [codex] Improve runtime and import reliability (#6549) 2026-05-22 09:57:22 -05: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
index.ts [codex] Improve runtime and import reliability (#6549) 2026-05-22 09:57:22 -05: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
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-status.ts feat(costs): add billing, quota, and budget control plane 2026-03-16 15:11:01 -05:00
pipelines-schema.test.ts Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -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
table-size-estimates.ts feat(db): add migration safety lint 2026-07-07 01:43:12 +00:00
test-embedded-postgres.ts [codex] Improve runtime and import reliability (#6549) 2026-05-22 09:57:22 -05:00