From 9546e1449378129a9ce2e05eb5479b5855053084 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Tue, 7 Jul 2026 07:57:42 -0700 Subject: [PATCH 1/2] Using async locks --- .../hosting/core/storage/memory_storage.py | 8 ++++---- .../hosting/core/storage/transcript_memory_store.py | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/memory_storage.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/memory_storage.py index 17ba2d1f..7a0aaab4 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/memory_storage.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/memory_storage.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -from threading import Lock +from asyncio import Lock from typing import TypeVar from ._type_aliases import JSON @@ -26,7 +26,7 @@ async def read( raise ValueError("Storage.read(): target_cls cannot be None.") result: dict[str, StoreItem] = {} - with self._lock: + async with self._lock: for key in keys: if key == "": raise ValueError("MemoryStorage.read(): key cannot be empty") @@ -48,7 +48,7 @@ async def write(self, changes: dict[str, StoreItem]): if not changes: raise ValueError("MemoryStorage.write(): changes cannot be None") - with self._lock: + async with self._lock: for key in changes: if key == "": raise ValueError("MemoryStorage.write(): key cannot be empty") @@ -58,7 +58,7 @@ async def delete(self, keys: list[str]): if not keys: raise ValueError("Storage.delete(): Keys are required when deleting.") - with self._lock: + async with self._lock: for key in keys: if key == "": raise ValueError("MemoryStorage.delete(): key cannot be empty") diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py index 6ae74684..282a8061 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py @@ -1,9 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -from threading import Lock +from asyncio import Lock from datetime import datetime, timezone -from typing import List from .transcript_logger import TranscriptLogger, PagedResult from .transcript_info import TranscriptInfo from microsoft_agents.activity import Activity @@ -43,7 +42,7 @@ async def log_activity(self, activity: Activity) -> None: if not activity.conversation.id: raise ValueError("Activity.Conversation.id cannot be None") - with self.lock: + async with self.lock: self._transcript.append(activity) async def get_transcript_activities( @@ -68,7 +67,7 @@ async def get_transcript_activities( if not conversation_id: raise ValueError("conversation_id cannot be None") - with self.lock: + async with self.lock: # Get the activities that match on channel and conversation id relevant_activities = [ a @@ -115,7 +114,7 @@ async def delete_transcript(self, channel_id: str, conversation_id: str) -> None if not conversation_id: raise ValueError("conversation_id cannot be None") - with self.lock: + async with self.lock: self._transcript = [ a for a in self._transcript @@ -140,7 +139,7 @@ async def list_transcripts( if not channel_id: raise ValueError("channel_id cannot be None") - with self.lock: + async with self.lock: relevant_activities = [ a for a in self._transcript if a.channel_id == channel_id ] From bead5f21b9fd4c83ade6aa6d04d12fc96f1bb2b5 Mon Sep 17 00:00:00 2001 From: Rodrigo Brandao Date: Tue, 7 Jul 2026 08:06:23 -0700 Subject: [PATCH 2/2] Updating docstring --- .../hosting/core/storage/transcript_memory_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py index 282a8061..6d8fb7a6 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_memory_store.py @@ -12,7 +12,7 @@ class TranscriptMemoryStore(TranscriptLogger): """ An in-memory implementation of the TranscriptLogger for storing and retrieving activities. - This class is thread-safe and stores all activities in a list. It supports logging activities, + This class is async-safe and stores all activities in a list. It supports logging activities, retrieving activities for a specific channel and conversation, and filtering by timestamp. Activities with a None timestamp are treated as the earliest possible datetime.