Skip to content

fix(threads): avoid deadlocks during archive and delete - #1088

Merged
nixuuu merged 1 commit into
devfrom
fix/thread-archive-deadlock
Nov 21, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/thread-archive-deadlock

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 21, 2026

Copy link
Copy Markdown
Member

Change

Thread lifecycle writes now take PostgreSQL's FOR NO KEY UPDATE lock on thread rows. A cascade still serializes with other writes. A worker transaction updating a side thread can finish a foreign-key check on its parent while the cascade waits for the side thread.

In CI, archive held the parent row while waiting on the child. The ingest transaction held the child and was waiting on the parent during the second update of the tuple. Added a regression that observes the lock wait in PostgreSQL and then lets the child transaction finish against both archive and soft delete.

Related: #1087

Verification

  • The new archive regression failed with PostgreSQL 40P01 before the fix.
  • Eight focused runs under the same two-CPU limit used to reproduce the race passed all 40 tests in thread-snooze.test.ts.
  • The existing schedule-writer concurrency test, integration typecheck, edited-file lint and diff checks passed. CI handles the full repository gate.

@nixuuu
nixuuu enabled auto-merge (squash) November 21, 2026 17:33
@nixuuu
nixuuu merged commit 6d81ea2 into dev Nov 21, 2026
16 checks passed
@nixuuu
nixuuu deleted the fix/thread-archive-deadlock branch November 21, 2026 17:42
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