rebuildDue selects a due source with a plain SELECT ... LIMIT 1 (no locking). Two workers can pick the same source, both call rebuildDirectory, and both run deleteMany + createMany in overlapping transactions. The second commit hits archive_team_sides_pkey with P2002.
Fix
Add pg_try_advisory_xact_lock(hashtext(sourceId)) at the start of the rebuildDirectory transaction. If another worker already holds the lock, the second worker skips the delete/create cycle entirely — no PK collision.
The advisory lock is transaction-scoped (xact), so it is released automatically when the transaction commits or rolls back.
Lock held by another worker → all three skipped, returns 0.
Paperclip-Issue: BIT-33539
## Root cause
`rebuildDue` selects a due source with a plain `SELECT ... LIMIT 1` (no locking). Two workers can pick the same source, both call `rebuildDirectory`, and both run `deleteMany` + `createMany` in overlapping transactions. The second commit hits `archive_team_sides_pkey` with P2002.
## Fix
Add `pg_try_advisory_xact_lock(hashtext(sourceId))` at the start of the `rebuildDirectory` transaction. If another worker already holds the lock, the second worker skips the delete/create cycle entirely — no PK collision.
The advisory lock is transaction-scoped (`xact`), so it is released automatically when the transaction commits or rolls back.
## Test
Two new tests in `service.test.ts`:
- Lock acquired → deleteMany + createMany + updateMany all run, row count returned.
- Lock held by another worker → all three skipped, returns 0.
Paperclip-Issue: BIT-33539
Two workers could pick the same due source from rebuildDue (the SELECT
has no locking), both call deleteMany + createMany in overlapping
transactions, and the second commit hit archive_team_sides_pkey with
P2002. Add pg_try_advisory_xact_lock(hashtext(sourceId)) at the start
of the transaction: the second worker skips instead of colliding.
Paperclip-Issue: BIT-33539
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Root cause
rebuildDueselects a due source with a plainSELECT ... LIMIT 1(no locking). Two workers can pick the same source, both callrebuildDirectory, and both rundeleteMany+createManyin overlapping transactions. The second commit hitsarchive_team_sides_pkeywith P2002.Fix
Add
pg_try_advisory_xact_lock(hashtext(sourceId))at the start of therebuildDirectorytransaction. If another worker already holds the lock, the second worker skips the delete/create cycle entirely — no PK collision.The advisory lock is transaction-scoped (
xact), so it is released automatically when the transaction commits or rolls back.Test
Two new tests in
service.test.ts:Paperclip-Issue: BIT-33539
auto-approve: CI success on
941688d2c9(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
941688d2c9(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
941688d2c9(gitea_auto_approve_open_prs_once.py)