session store: lazy persistence — no empty sessions in DB
POST /sessions no longer inserts a DB row. The Session is registered in an
in-memory _pending registry on PgSessionStore and only upserted on the first
save() (first user message / meaningful state change). Empty sessions that
never receive a message never reach the DB and vanish on server restart or
via the hourly pending sweep.

- pg_session_store: _pending dict + lock; create() registers, get() checks
  _pending first, save() upserts the sessions row (INSERT ... ON CONFLICT)
  and pops _pending so the session_messages FK is satisfied; sweep_pending()
  drops abandoned entries; pending_sweep_loop() background task.
- main.py: start/cancel pending_sweep_loop in lifespan.
- tests: 7 new tests for create/get/save/list/sweep semantics; updated
  existing save() test comments for the upsert.
1 parent 6b83f73 commit f78ede1ad6807a7dff03256b91ceb63a93eb9daf
@Eugene Sukhodolskiy Eugene Sukhodolskiy authored 1 day ago
Showing 3 changed files
View
navi/core/pg_session_store.py
View
navi/main.py
View
tests/unit/core/test_pg_session_store.py