fix: add sqlite wal mode and timeout#101
Conversation
- Update kwargs to inject timeout for SQLite - Add SQLAlchemy event listener for WAL mode
There was a problem hiding this comment.
Code Review
This pull request configures SQLite connection settings for the ADK runtime, introducing a 15-second connection timeout and setting the journal_mode to WAL and synchronous to NORMAL upon connection. It also updates the corresponding unit tests. The reviewer recommended wrapping the SQLite cursor operations in a try...finally block to ensure proper resource cleanup in case of exceptions, and suggested enabling PRAGMA foreign_keys=ON to enforce referential integrity.
| cursor = dbapi_connection.cursor() | ||
| cursor.execute("PRAGMA journal_mode=WAL") | ||
| cursor.execute("PRAGMA synchronous=NORMAL") | ||
| cursor.close() |
There was a problem hiding this comment.
To ensure proper resource cleanup even if an exception occurs during the execution of the PRAGMA statements, wrap the cursor operations in a try...finally block. Additionally, consider enabling PRAGMA foreign_keys=ON to enforce referential integrity constraints, keeping it consistent with how SQLite is configured in src/blacki/storage/sqlite.py.
| cursor = dbapi_connection.cursor() | |
| cursor.execute("PRAGMA journal_mode=WAL") | |
| cursor.execute("PRAGMA synchronous=NORMAL") | |
| cursor.close() | |
| cursor = dbapi_connection.cursor() | |
| try: | |
| cursor.execute("PRAGMA journal_mode=WAL") | |
| cursor.execute("PRAGMA synchronous=NORMAL") | |
| cursor.execute("PRAGMA foreign_keys=ON") | |
| finally: | |
| cursor.close() |
- Add mocked tests for SQLite event listener - Add mocked test for PostgreSQL session instantiation
What
Add WAL mode and connection timeout to SQLite for ADK sessions.
Why
Rapid Telegram messages trigger concurrent database access. When a turn is cancelled mid-flight, its database connection is not fully released before a new turn starts writing, causing a
database is lockedOperationalError.How
build_session_db_kwargsto injectconnect_args={"timeout": 15}for SQLite connectionsconnectevent listener increate_session_servicethat executesPRAGMA journal_mode=WALandPRAGMA synchronous=NORMALtest_adk_runtime.pyto assert the new kwargs configTests
uv run pytest tests/test_adk_runtime.py