Skip to content

Commit 1288548

Browse files
committed
code review
1 parent 714bd25 commit 1288548

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/agents/extensions/memory/advanced_sqlite_session.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ async def _add_structure_metadata(self, items: list[TResponseInputItem]) -> None
187187

188188
def _add_structure_sync():
189189
conn = self._get_connection()
190+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
190191
with self._lock if self._is_memory_db else threading.Lock():
191192
# Get the IDs of messages we just inserted, in order
192193
with closing(conn.cursor()) as cursor:
@@ -290,6 +291,7 @@ async def _cleanup_orphaned_messages(self) -> None:
290291

291292
def _cleanup_sync():
292293
conn = self._get_connection()
294+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
293295
with self._lock if self._is_memory_db else threading.Lock():
294296
with closing(conn.cursor()) as cursor:
295297
# Find messages without structure metadata
@@ -381,6 +383,7 @@ async def get_items(
381383
# Get all items for this branch
382384
def _get_all_items_sync():
383385
conn = self._get_connection()
386+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
384387
with self._lock if self._is_memory_db else threading.Lock():
385388
with closing(conn.cursor()) as cursor:
386389
if limit is None:
@@ -424,6 +427,7 @@ def _get_all_items_sync():
424427

425428
def _get_items_sync():
426429
conn = self._get_connection()
430+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
427431
with self._lock if self._is_memory_db else threading.Lock():
428432
with closing(conn.cursor()) as cursor:
429433
# Get message IDs in correct order for this branch
@@ -471,6 +475,7 @@ async def _copy_messages_to_new_branch(self, new_branch_id: str, from_turn_numbe
471475

472476
def _copy_sync():
473477
conn = self._get_connection()
478+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
474479
with self._lock if self._is_memory_db else threading.Lock():
475480
with closing(conn.cursor()) as cursor:
476481
# Get all messages before the branch point
@@ -603,7 +608,7 @@ def _validate_turn():
603608
old_branch = self._current_branch_id
604609
self._current_branch_id = branch_name
605610

606-
self._logger.info(
611+
self._logger.debug(
607612
f"Created branch '{branch_name}' from turn {turn_number} ('{turn_content}') in '{old_branch}'" # noqa: E501
608613
)
609614
return branch_name
@@ -671,6 +676,7 @@ async def delete_branch(self, branch_id: str, force: bool = False) -> None:
671676

672677
def _delete_sync():
673678
conn = self._get_connection()
679+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
674680
with self._lock if self._is_memory_db else threading.Lock():
675681
with closing(conn.cursor()) as cursor:
676682
# First verify the branch exists
@@ -748,7 +754,8 @@ def _get_turns_sync():
748754
FROM message_structure ms
749755
JOIN agent_messages am ON ms.message_id = am.id
750756
WHERE ms.session_id = ? AND ms.branch_id = ?
751-
AND ms.message_type = 'user' ORDER BY ms.branch_turn_number
757+
AND ms.message_type = 'user'
758+
ORDER BY ms.branch_turn_number
752759
""",
753760
(self.session_id, branch_id),
754761
)
@@ -801,7 +808,8 @@ def _search_sync():
801808
FROM message_structure ms
802809
JOIN agent_messages am ON ms.message_id = am.id
803810
WHERE ms.session_id = ? AND ms.branch_id = ?
804-
AND ms.message_type = 'user' AND am.message_data LIKE ?
811+
AND ms.message_type = 'user'
812+
AND am.message_data LIKE ?
805813
ORDER BY ms.branch_turn_number
806814
""",
807815
(self.session_id, branch_id, f"%{search_term}%"),
@@ -904,6 +912,7 @@ async def _update_turn_usage_internal(self, user_turn_number: int, usage_data: U
904912

905913
def _update_sync():
906914
conn = self._get_connection()
915+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
907916
with self._lock if self._is_memory_db else threading.Lock():
908917
# Serialize token details as JSON
909918
input_details_json = None
@@ -961,6 +970,7 @@ async def get_session_usage(self, branch_id: str | None = None) -> dict[str, int
961970

962971
def _get_usage_sync():
963972
conn = self._get_connection()
973+
# TODO: Refactor SQLiteSession to use asyncio.Lock instead of threading.Lock and update this code # noqa: E501
964974
with self._lock if self._is_memory_db else threading.Lock():
965975
if branch_id:
966976
# Branch-specific usage

0 commit comments

Comments
 (0)