From 2f0294165cfecc4e933134f6494386efa939f500 Mon Sep 17 00:00:00 2001 From: Kian Jones <11655409+kianjones9@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:19:03 -0800 Subject: [PATCH] debug: log statement_timeout + connection pid on session checkout (#9472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * debug: log statement_timeout + connection pid on every session checkout Temporary instrumentation to diagnose why some PlanetScale connections have statement_timeout=5s while others have 0 (disabled). 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta * debug: log statement_timeout on every checkout, not just non-zero 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta * fix: rollback implicit transaction from debug query The SELECT implicitly begins a transaction, causing "A transaction is already begun" errors for code that calls session.begin() explicitly. 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta --------- Co-authored-by: Letta --- letta/server/db.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/letta/server/db.py b/letta/server/db.py index 980e3ecd..e7c40db3 100644 --- a/letta/server/db.py +++ b/letta/server/db.py @@ -3,7 +3,7 @@ import uuid from contextlib import asynccontextmanager from typing import AsyncGenerator -from sqlalchemy import NullPool +from sqlalchemy import NullPool, text from sqlalchemy.ext.asyncio import ( AsyncEngine, AsyncSession, @@ -88,6 +88,10 @@ class DatabaseRegistry: try: async with async_session_factory() as session: try: + result = await session.execute(text("SELECT pg_backend_pid(), current_setting('statement_timeout')")) + pid, timeout = result.one() + logger.warning(f"[stmt_timeout_debug] pid={pid} statement_timeout={timeout}") + await session.rollback() yield session await session.commit() except asyncio.CancelledError: