You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Order concurrent relation inserts deterministically to prevent PostgreSQL batch deadlocks #1208
A development Cloud batch index ran two relation-persistence tasks concurrently and both deadlocked while inserting relation rows with ON CONFLICT DO NOTHING. The enclosing index_file_batch failed with an ExceptionGroup.
This is distinct from the Entity/Observation lock-order defect fixed by #1202: both participants here are relation inserts.
Root cause
Concurrent batch tasks acquire PostgreSQL relation/index locks in input-dependent order. ON CONFLICT DO NOTHING prevents duplicate-row errors but does not establish a common lock order, so overlapping relation sets can deadlock.
Fix direction
At the Core repository boundary, normalize and deterministically order relation identities before bulk persistence. Keep deduplication and stale-relation validation semantics intact. If one transaction must own a project's relation-write batch, make that ownership explicit rather than adding a broad retry around arbitrary transactions.
Acceptance criteria
Relation writes use one deterministic order derived from their complete conflict identity.
A PostgreSQL concurrency regression runs overlapping relation batches in opposing input order without deadlock.
Superseded by #1209 after reviewing the complete #2372 transaction graph. The deadlock is created by holding a pessimistic lock on each source Entity while relation foreign-key checks touch other concurrently locked Entity rows. Deterministically ordering the final relation batch cannot remove that cross-entity lock graph. #1209 tracks the root fix: database-native upsert/CAS outcomes, single-note transaction ownership, and separate idempotent relation resolution.
Activity
phernandez commentedon Aug 6, 2026
Superseded by #1209 after reviewing the complete #2372 transaction graph. The deadlock is created by holding a pessimistic lock on each source Entity while relation foreign-key checks touch other concurrently locked Entity rows. Deterministically ordering the final relation batch cannot remove that cross-entity lock graph. #1209 tracks the root fix: database-native upsert/CAS outcomes, single-note transaction ownership, and separate idempotent relation resolution.