7 Commits

Author SHA1 Message Date
Teknium
b6412b81be fix(backup): wait out SQLITE_BUSY_RECOVERY in WAL snapshots
A WAL snapshot failed at once with "database is locked" when it met
another connection rebuilding the WAL index: sqlite3's backup loop
retries only plain SQLITE_BUSY/LOCKED, so the extended
SQLITE_BUSY_RECOVERY (261) ended the copy as an error, and the progress
callback compared the unmasked status, so the 10 s busy deadline never
applied. Mask the status and restart the one-step backup on a busy
error until that same deadline, in both hermes_cli/backup_sqlite.py and
persistence/sqlite/admin/_backup.py. Still fails closed past the
deadline; never copies the main file alone.
2026-11-19 10:36:13 -08:00
yoniebans
68bb692467 fix(storage): a browse read checks schema drift on its own connection
Every Desktop and dashboard session read opened state.db twice: an admin handle ran the declared-schema probe on a fresh connection, then the reader the read uses opened another. The read-only SessionDB browse the storage interface replaced ran that probe on its one reader connection, so each open and page read became about a third slower at the median.

open_persistence_reader gains check_drift, passed through the backend to the read-only holder the way patience_s is. With it, the holder's open runs the probe on its own connection and raises the core DeclarativeDrift with the reason StoreAdmin.schema_drift_reason gives; both now share one helper, declared_schema_drift. The browse open binds its reader with the check, and on drift runs the existing one-time catch-up and opens again, so a store that lags the declared schema is still caught up or refused by name exactly as before. A browse open's failures are reported in its 503 only and no longer reach the process's last session-store init error; main's browse wrote it only when its reader failed after the separate probe had passed.
2026-11-18 15:12:51 +01:00
yoniebans
be3d6affc8 refactor(state)!: remove the old session store
hermes_state.py becomes the stand-in plugins import, the rest of the legacy store and its test folder go, and the per-process modules the backend imported from main move under persistence/sqlite/_state/. The backend checks PID namespaces and lease holders through process_identity and its WAL setup through sqlite_support, and its error module takes the shared predicates and classification from storage_errors, so neither helper set has a second copy. The backend, sqlite_support.py and the tests that pin those modules reach their final imports, and the backend-import guard allows no file outside persistence/. The modules no caller imports any more go with it: the agent's onboarding rules (now in session_rules) and gateway/session_admission.py.

The stand-in's SessionDB releases its store on close() and, used again afterwards, opens it again with a warning, as the old class reopened its connection, unless the file at its path was replaced or the store is latched corrupt; a read-only one raises. A close during a call releases the store when the call returns. A named source wins over a source list in its session listing and count.

An agent given a writable stand-in SessionDB as session_db= and no persistence= takes the store handle that SessionDB forwards to as its persistence, so its turn flush, token counts, compression and session row writes go through the storage interface, as an agent given the old SessionDB wrote through it.

The backend-import guard also holds the backend's remaining reads of the process or task home, each with its reason, and refuses any other and any import of the stand-in inside persistence/sqlite/.

Plugin context engines get the agent's store as persistence= beside the deprecated session_db=, in each hook whose signature accepts that keyword, including the rebind after /new, /resume and /branch, and the context engine guide and the plugin guide's replacement table name it. A test fails once the running release reaches the stand-in's removal release, listing what goes with the stand-in.

release_unheld_media and collect_unheld_api_images take a store only: their SessionDB branches, which no caller reaches, go with the gateway's own copies of the admission and transcript queries.
2026-11-17 19:10:57 +01:00
yoniebans
a4d4026690 feat(persistence): add sessions.prompt_cache_clock to the SQLite schema
The sessions table gains the nullable prompt_cache_clock TEXT column after transcript_revision, as main's DDL has it, and the schema history records it as entry 33 with main's text. Existing stores gain the column through the declarative reconcile, and offline recovery now copies the same columns as main's.
2026-11-17 17:49:49 +01:00
yoniebans
6c8bdc2fd4 fix(persistence): route the store admin's and readiness probe's state.db opens through connect_tracked
The SQLite backend's copies take main's bodies: the session row counts, the runtime-ledger rows probe, the doctor's session count, the write-health snapshot source, the integrity check, the journal-mode read and the journal-mode switch open through hermes_cli.sqlite_safe_read.connect_tracked with tracking_path, so has_live_connection() and offline_file_access() see them before any raw byte probe. The readiness probe opens read_only_db_uri(path) through connect_tracked, so a profile path containing a reserved URI character opens the tracked file.
The offline opens main keeps raw (the restore staging copy, the preflight staged copy, the write-health temp snapshot and the downgrade-guard snapshot probe) carry main's HX015 waivers.
2026-11-17 17:49:49 +01:00
yoniebans
35bfb1fa50 fix(persistence): route the backup admin's state.db opens through connect_tracked
The SQLite backend's backup copies take main's bodies: the read-only integrity query, the restore-epoch read and the restore destination open through hermes_cli.sqlite_safe_read.connect_tracked, so has_live_connection() sees them before any raw byte probe, and the header read uses the module-level import.
2026-11-17 17:49:49 +01:00
yoniebans
0b5c93ae43 feat(persistence/sqlite): store admin and profile repair
The SQLite implementation of the store administration and profile repair operations. The resolution allowlist lists the salvage's sqlite3 command-line lookup beside main's own row for the same lookup.
2026-11-17 17:49:46 +01:00