ulysses/routes
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
..
__init__.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
admin_wipe_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
api_token_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
assistant_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
auth_routes.py Add admin user rename 2026-06-01 12:52:58 +09:00
backup_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
calendar_routes.py Fix YEARLY recurring CalDAV events only showing on DTSTART year (#179) 2026-06-01 13:42:44 +09:00
chat_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
chat_routes.py fix: stop leaking DB connections when persisting session mode (#64) 2026-06-01 13:57:48 +09:00
cleanup_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
compare_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
contacts_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
cookbook_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
cookbook_routes.py Clarify Cookbook diffusion dependencies 2026-06-01 11:45:26 +09:00
diagnostics_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
document_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
document_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
editor_draft_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
email_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
email_pollers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
email_routes.py Prefetch adjacent emails while reading 2026-06-01 13:14:47 +09:00
embedding_routes.py Gate embedding routes behind admin auth 2026-06-01 10:47:11 +09:00
emoji_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
font_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
gallery_helpers.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
gallery_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
history_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
hwfit_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
mcp_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
memory_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
model_routes.py Improve Ollama setup and model endpoint handling 2026-06-01 10:00:15 +09:00
note_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
personal_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
prefs_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
preset_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
research_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
search_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
session_routes.py Improve Ollama setup and model endpoint handling 2026-06-01 10:00:15 +09:00
shell_routes.py Secure cookbook package probe endpoint 2026-06-01 13:22:37 +09:00
signature_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
skills_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
stt_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
task_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
tts_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
upload_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
vault_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
webhook_routes.py Odysseus v1.0 2026-05-31 23:58:26 +09:00