Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,12 @@ async def delete(self, checkpoint_id: CheckpointID) -> bool:
file_path = self._validate_file_path(checkpoint_id)

def _delete() -> bool:
if file_path.exists():
try:
file_path.unlink()
logger.info(f"Deleted checkpoint {checkpoint_id} from {file_path}")
return True
return False
except FileNotFoundError:
return False
logger.info(f"Deleted checkpoint {checkpoint_id} from {file_path}")
return True

return await asyncio.to_thread(_delete)

Expand Down
32 changes: 32 additions & 0 deletions python/packages/core/tests/workflow/test_checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright (c) Microsoft. All rights reserved.

import asyncio
import json
import tempfile
import threading
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -1258,6 +1261,35 @@ async def test_file_checkpoint_storage_delete():
assert result is False


async def test_file_checkpoint_storage_concurrent_delete():
with tempfile.TemporaryDirectory() as temp_dir:
storage = FileCheckpointStorage(temp_dir)
checkpoint = WorkflowCheckpoint(
workflow_name="test-workflow",
graph_signature_hash="test-hash",
checkpoint_id="same",
)
await storage.save(checkpoint)

file_path = (Path(temp_dir) / "same.json").resolve()
original_exists = Path.exists
barrier = threading.Barrier(2)

def synchronized_exists(path: Path) -> bool:
result = original_exists(path)
if path.resolve() == file_path:
barrier.wait(timeout=5)
return result

with patch.object(Path, "exists", synchronized_exists):
results = await asyncio.gather(
storage.delete(checkpoint.checkpoint_id),
storage.delete(checkpoint.checkpoint_id),
)

assert sorted(results) == [False, True]


async def test_file_checkpoint_storage_directory_creation():
with tempfile.TemporaryDirectory() as temp_dir:
nested_path = Path(temp_dir) / "nested" / "checkpoint" / "storage"
Expand Down
Loading