Skip to content

[Fix] Test DB keeps stale partial-index predicates after push - #1897

Open
mrubens wants to merge 1 commit into
developfrom
claude/eager-taussig-c1149a
Open

[Fix] Test DB keeps stale partial-index predicates after push#1897
mrubens wants to merge 1 commit into
developfrom
claude/eager-taussig-c1149a

Conversation

@mrubens

@mrubens mrubens commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Problem

The enqueue-task test "allows retrying a resume that was canceled before queue publication" fails against a persistent roomote_test database with:

duplicate key value violates unique constraint "task_runs_launch_idempotency_key_unique"

#1779 added AND canceled_at IS NULL to that index's predicate (migration 0067_clean_storm.sql) so canceled runs release their launch idempotency key. Real databases pick that up via migrations, but the test database is synced exclusively through drizzle-kit push, which cannot detect WHERE-predicate changes on expression indexes: it reports "Changes applied" while leaving the old index in place. Any test DB created before #1779 keeps the stale predicate, so the canceled run still blocks the retry insert.

Fix

  • Add packages/db/scripts/reconcile-test-indexes.ts: after push, recreate predicate-bearing expression indexes whose live pg_indexes.indexdef is missing the expected predicate fragments (currently the launch-idempotency and Discord source-event unique indexes).
  • Chain it into db:push:test, so pnpm test, infra:up, and db:up self-heal a drifted test database.

The script guards with assertSafeTestDatabaseUrl, so it refuses to run against anything but a localhost test database.

Verification

  • On a stale test DB, pnpm --filter @roomote/db db:push:test logs Recreated task_runs_launch_idempotency_key_unique (was stale).
  • packages/cloud-agents/src/server/__tests__/enqueue-task.test.ts then passes twice consecutively (69 tests per run).
  • oxfmt, oxlint, tsc, and pre-push (check-types:fast + knip) all clean.

drizzle-kit push does not detect WHERE-predicate changes on expression
indexes, so persistent test databases kept the pre-#1779 version of
task_runs_launch_idempotency_key_unique (missing canceled_at IS NULL)
and failed the snapshot-resume retry test with a duplicate-key error.
Run a reconcile pass after db:push:test that recreates predicate-bearing
indexes whose live definition has drifted from schema.ts.
@roomote-community

roomote-community Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

Reviewed 3390b06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant