Skip to content

session_store

diapason.learning.spec_search.storage.session_store

SQLite-backed storage for spec-search LearningSession records.

Mirrors the style of diapason.learning.optimize.store.OptimizationStore:

  • stdlib sqlite3 in WAL mode
  • inline DDL as module-level constants
  • persistent connection stored as self._conn
  • _migrate() runs additive ALTER TABLEs that swallow OperationalError

The store does NOT share its database file with OptimizationStore (see spec §8.1 / brainstorming Q8). The two SQLite files live side-by-side in ~/.diapason/learning/ but are independent.

SessionStore

SQLite-backed storage for LearningSession and EditOutcome records.

The full LearningSession is also serialized to disk as <session_dir>/session.json — that file is the authoritative source if SQLite is ever lost. This store is the index used for fast queries.

close()

Close the underlying SQLite connection.

get_session(session_id)

Return the LearningSession with the given id, or None if missing.

list_outcomes(session_id)

Return all EditOutcomes for a session, ordered by insertion id.

list_sessions(status=None, limit=None)

List sessions ordered by started_at DESC.

save_outcome(session_id, outcome, *, pillar, op, target, risk_tier, rationale='')

Insert an EditOutcome row.

pillar, op, target, risk_tier, and rationale come from the parent Edit (which is not stored on the EditOutcome model). They are kept as columns to make WHERE op = ? queries possible without joining against the on-disk plan.json.

save_session(session)

Insert or update a LearningSession (idempotent on session.id).