4 Commits

Author SHA1 Message Date
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
499db5e413 fix(persistence): the SQLite holder fails closed on a symlinked state.db path
The holder's state.db hardening now raises OSError(ELOOP) on a symlinked state.db, -wal or -shm instead of skipping it, so sqlite3.connect() never follows a planted link; a state.db link the operator made to a store of their own still opens. Modes are tightened through _chmod_pinned_inode, which never re-resolves the path to a swapped-in link. The registry judges the link with refuse_planted_state_db_link before resolve() hides it.

Main's fail-closed cases run against the holder, the registry and the backend's open.
2026-11-17 17:49:49 +01:00
yoniebans
7a21a2d1f8 fix(persistence): the holder registry releases header-probe fds when close_all_under sweeps a home
hermes_state_dbfile caches one O_RDONLY fd per state.db so the on-write header probe never closes a descriptor SQLite has locked, and nothing evicted those entries: a multiplexed gateway kept one fd for every profile it had unserved. close_all_under in persistence/sqlite/_registry.py now releases the probe fds under the swept home, never while another descriptor in the process holds the probe's inode: one descriptor scan per sweep under the paths' lifecycle locks, then an inode rescan inside offline_file_access before each close, so a tracked open through another pathname (a hard link) after the first scan keeps the probe. _path_is_under is hermes_state_common.path_is_under.

Tests: test_header_probe_release.py ports the SessionDB registry cases against the holder registry.
2026-11-17 17:49:48 +01:00
yoniebans
c9f3a2ffd4 feat(persistence/sqlite): one store holder per state.db, handed out by a registry
_holder.py owns the writer connection and its lock, BEGIN IMMEDIATE write transactions with jittered replay, the bounded read pool, WAL setup, file and WAL-generation guards, quarantine and close; _registry.py hands out one holder per state.db per process.
2026-11-17 17:49:46 +01:00