Skip to content

[codex] Fix chunk delete deadlock ordering - #2569

Closed
oldnicke wants to merge 1 commit into
vectorize-io:mainfrom
oldnicke:codex/fix-chunk-delete-deadlock
Closed

[codex] Fix chunk delete deadlock ordering#2569
oldnicke wants to merge 1 commit into
vectorize-io:mainfrom
oldnicke:codex/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.

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 closed this Jul 5, 2026
@oldnicke
oldnicke deleted the codex/fix-chunk-delete-deadlock branch July 5, 2026 13:00
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)

1 participant