Skip to content

Fix chunk delete deadlock ordering#2570

Merged
benfrank241 merged 1 commit into
vectorize-io:mainfrom
oldnicke:fix-chunk-delete-deadlock
Jul 7, 2026
Merged

Fix chunk delete deadlock ordering#2570
benfrank241 merged 1 commit into
vectorize-io:mainfrom
oldnicke:fix-chunk-delete-deadlock

Conversation

@oldnicke

@oldnicke oldnicke commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • pre-delete memory_links for chunks in deterministic key order before deleting chunks
  • delete chunk rows through an ordered CTE so concurrent chunk removals acquire locks consistently
  • add regression coverage for the ordered delete sequence

Why

Concurrent DELETE FROM chunks ... statements can let PostgreSQL's FK cascade lock overlapping memory_links rows in executor-chosen order. When two writers delete overlapping chunk graphs, that can produce AB/BA row-lock deadlocks. Explicitly deleting the affected links in a stable order removes the unordered cascade as the first lock owner.

Fixes #2560.

Supersedes #2569, which was closed when the fork branch was renamed.

Validation

  • uv run --project hindsight-api-slim pytest -q hindsight-api-slim/tests/test_chunk_storage_delete_ordering.py
  • uv run --project hindsight-api-slim ruff format --check hindsight-api-slim/hindsight_api/engine/retain/chunk_storage.py hindsight-api-slim/tests/test_chunk_storage_delete_ordering.py
  • uv run --project hindsight-api-slim ruff check hindsight-api-slim/hindsight_api/engine/retain/chunk_storage.py hindsight-api-slim/tests/test_chunk_storage_delete_ordering.py

@oldnicke oldnicke changed the title [codex] Fix chunk delete deadlock ordering Fix chunk delete deadlock ordering Jul 5, 2026
@oldnicke oldnicke marked this pull request as ready for review July 5, 2026 13:09
@benfrank241 benfrank241 merged commit 11da432 into vectorize-io:main Jul 7, 2026
87 checks passed
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.

Concurrent DELETE FROM chunks statements deadlock on memory_links FK cascade (still occurring on 0.8.4)

2 participants