ulysses/tests
Collin 0a7de1fdf4
fix: stop leaking DB connections when persisting session mode (#64)
chat_routes.py persisted a session's "mode" in three best-effort spots —
reading the current mode, writing the effective mode, and setting
research_pending on the stream path. Each opened a session with SessionLocal()
and called .close() as the LAST statement inside a try/except, so if anything
before close() raised (e.g. a SQLite "database is locked" under concurrent chat
streams) the except only logged and the connection was never returned to the
pool.

DATABASE_URL defaults to file-backed SQLite, whose engine uses SQLAlchemy's
default QueuePool (5 connections + 10 overflow). Repeated leaks on these hot
paths exhaust the pool; later requests then block for pool_timeout and fail
with "QueuePool limit ... reached", taking the app down until restart.

Move the logic into two best-effort helpers in core.database, next to the
existing session helpers (update_session_last_accessed, get_session_by_id):

  - get_session_mode(session_id) -> Optional[str]
  - set_session_mode(session_id, mode) -> bool

Both route through the existing get_db_session() context manager, which commits
on success, rolls back on error, and always closes in a finally, so the
connection is returned to the pool on every path. chat_routes.py now calls
these instead of hand-rolling sessions, also removing three copies of the same
try/except.

Add tests/test_session_mode_helpers.py: the helpers commit+close on success
and, on a mid-operation DB error, swallow + roll back + close (no leak). The
error-path tests fail against the old close()-inside-try pattern.
2026-06-01 13:57:48 +09:00
..
bombadil-spec.ts Odysseus v1.0 2026-05-31 23:58:26 +09:00
conftest.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_agent_loop.py Fix fresh checkout test failures 2026-06-01 02:22:17 +00:00
test_app.py Fix fresh checkout test failures 2026-06-01 02:22:17 +00:00
test_auth_regressions.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_calendar_recurrence.py Fix YEARLY recurring CalDAV events only showing on DTSTART year (#179) 2026-06-01 13:42:44 +09:00
test_compare_js.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_context_compactor.py Preserve large pasted messages in context 2026-06-01 12:38:35 +09:00
test_cookbook_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_endpoint_resolver.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_model_context.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_model_routes.py Fix fresh checkout test failures 2026-06-01 02:22:17 +00:00
test_null_owner_gates.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_rate_limiter.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_research_utils.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_review_regressions.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_search_ranking.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_security_regressions.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
test_session_mode_helpers.py fix: stop leaking DB connections when persisting session mode (#64) 2026-06-01 13:57:48 +09:00
test_shell_routes.py Fix shell routes on Windows without PTY support 2026-06-01 13:15:40 +09:00
test_vision_model_detection.py Recognize local vision models so their images aren't dropped (#185) 2026-06-01 13:09:21 +09:00