Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add more granular logging for event loop (#8318)
cthomas8da7a0886149
diff --git a/letta/monitoring/event_loop_watchdog.py b/letta/monitoring/event_loop_watchdog.pyindex b405bb2b5..2d707753e 100644--- a/letta/monitoring/event_loop_watchdog.py+++ b/letta/monitoring/event_loop_watchdog.py@@ -230,6 +230,13 @@ class EventLoopWatchdog:idx = frame.f_code.co_filename.find("letta/")path = frame.f_code.co_filename[idx + 6 :] if idx != -1 else frame.f_code.co_filenamelocation = f"{path}:{frame.f_lineno}:{frame.f_code.co_name}"++ # For bounded tasks, use wrapped coroutine location instead+ if frame.f_code.co_name == "bounded_coro":+ task_name = task.get_name()+ if task_name and task_name.startswith("bounded["):+ location = task_name[8:-1] # Extract "file:line:func" from "bounded[...]"+tasks_by_location[location].append((task, stack))breakexcept Exception:diff --git a/letta/utils.py b/letta/utils.pyindex c4f75539f..6b77b5fc0 100644--- a/letta/utils.py+++ b/letta/utils.py@@ -1444,13 +1444,27 @@ async def bounded_gather(coros: list[Coroutine], max_concurrency: int = 10) -> lsemaphore = asyncio.Semaphore(max_concurrency)- async def bounded_coro(index: int, coro: Coroutine):+ async def bounded_coro(index: int, coro: Coroutine, coro_name: str):async with semaphore:+ # Set task name for diagnostics+ task = asyncio.current_task()+ if task:+ task.set_name(f"bounded[{coro_name}]")result = await cororeturn (index, result)- # Wrap all coroutines with semaphore control- tasks = [bounded_coro(i, coro) for i, coro in enumerate(coros)]+ # Wrap all coroutines with semaphore control, extracting location for diagnostics+ tasks = []+ for i, coro in enumerate(coros):+ coro_code = getattr(coro, "cr_code", None)+ if coro_code:+ filename = coro_code.co_filename+ idx = filename.find("letta/")+ filename = filename[idx + 6 :] if idx != -1 else filename.split("/")[-1]+ coro_name = f"{filename}:{coro_code.co_firstlineno}:{coro_code.co_name}"+ else:+ coro_name = "unknown"+ tasks.append(bounded_coro(i, coro, coro_name))indexed_results = await asyncio.gather(*tasks)# Sort by original index to preserve order