Skip to content

feat(checkpoint-redis): implement adelete_thread and delete_thread … #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025

Conversation

bsbodden
Copy link
Contributor

@bsbodden bsbodden commented Jun 1, 2025

…methods (#51)

  • Add adelete_thread method to AsyncRedisSaver to delete all checkpoints, blobs, and writes for a thread
  • Add delete_thread method to RedisSaver for sync operations
  • Use Redis search indices instead of keys() command for better performance
  • Batch deletions using Redis pipeline for efficiency

…ethods (#51)

  - Add adelete_thread method to AsyncRedisSaver to delete all checkpoints, blobs, and writes for a thread
  - Add delete_thread method to RedisSaver for sync operations
  - Use Redis search indices instead of keys() command for better performance
  - Batch deletions using Redis pipeline for efficiency
@bsbodden bsbodden self-assigned this Jun 1, 2025
@bsbodden bsbodden requested a review from Copilot June 1, 2025 16:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements asynchronous and synchronous thread deletion methods for the checkpoint Redis saving mechanisms, improving performance by using Redis search indices and pipelining.

  • Added adelete_thread method in AsyncRedisSaver for async checkpoint, blob, and writes deletion.
  • Added delete_thread method in RedisSaver for synchronous deletion following similar logic.
  • Introduced comprehensive tests to validate the deletion behavior for both implementations.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/test_issue_51_adelete_thread.py Added tests for async and sync thread deletion functionality.
langgraph/checkpoint/redis/aio.py Implemented async adelete_thread using Redis search indices and pipelines.
langgraph/checkpoint/redis/init.py Implemented sync delete_thread mirroring the async deletion logic.

checkpoint_query = FilterQuery(
filter_expression=Tag("thread_id") == storage_safe_thread_id,
return_fields=["checkpoint_ns", "checkpoint_id"],
num_results=10000, # Get all checkpoints for this thread
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider defining a named constant for the magic number 10000 to improve maintainability and readability.

Suggested change
num_results=10000, # Get all checkpoints for this thread
num_results=DEFAULT_NUM_RESULTS, # Get all checkpoints for this thread

Copilot uses AI. Check for mistakes.

checkpoint_query = FilterQuery(
filter_expression=Tag("thread_id") == storage_safe_thread_id,
return_fields=["checkpoint_ns", "checkpoint_id"],
num_results=10000, # Get all checkpoints for this thread
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a named constant instead of hardcoding 10000 to enhance clarity and ease future adjustments.

Suggested change
num_results=10000, # Get all checkpoints for this thread
num_results=DEFAULT_NUM_RESULTS, # Get all checkpoints for this thread

Copilot uses AI. Check for mistakes.

@@ -575,6 +575,78 @@ def _load_pending_sends(
# Extract type and blob pairs
return [(doc.type, doc.blob) for doc in sorted_writes]

def delete_thread(self, thread_id: str) -> None:
Copy link
Preview

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Both async and sync deletion methods share very similar logic; consider refactoring the common deletion routines into a shared utility to reduce duplication.

Copilot uses AI. Check for mistakes.

@bsbodden bsbodden merged commit 21a34fd into main Jun 1, 2025
19 checks passed
@bsbodden bsbodden deleted the bsb/issue-51 branch June 1, 2025 16:22
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