A session still bound to profile b survives `hermes profile delete b` and
`hermes profile rename b c`. Its next plugin write recreated profiles/b
through a raw mkdir, and nothing raised.
Seven plugin state writers now create their directories through
mkdir_under_hermes_home, which refuses a missing or tombstoned named home
with its existing FileNotFoundError: plugin_data_dir (and the
hermes-achievements fallback that duplicates it), the CLI plugins dir,
the update-check markers, disk-cleanup state, the Discord recovery ledger,
the Weixin account dir and the A2A audit log.
Callers that already catch keep skipping the write (Discord recovery,
the update-check writers, the disk-cleanup session-end hook and audit log,
the A2A audit). The disk-cleanup slash commands reply that the profile no
longer exists instead of raising. plugin_data_dir documents the refusal.
Review follow-up. The recovery test released the WAL-index locks as soon as the copy met
SQLITE_BUSY_RECOVERY, so it passed even if the new retry loop never gave up. The new
recovery-stuck case keeps the locks held until the copy returns, with a 1 s deadline, on both
backup paths: the copy must return False and leave no snapshot behind. With the busy-status
mask reverted, the retry loop spins past the deadline and both stuck cases go red.
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.
referenced_archive_refs read at most 20,001 rows and answered "unknown"
past 20,000, and the sweep then kept every file in cache/pruned and
cache/spillover. Every prune stub row counts toward that number, so a
busy home passed it and was never swept again.
Rows are now read one at a time with no cap; memory is bounded by the
reference set. Any database error still answers "unknown", so the sweep
still fails closed. Below the old cap the cost is unchanged (the filter
has no index, so the whole table was already scanned). Past it the read
used to stop at the 20,001st match and now runs to the end, so on a
large home it stays open longer. The docs sentence about the cap is
removed.
(cherry picked from commit a5bed1d2d9fb436f6129388b237330a509abb6aa)
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.
session's model_config, but the managed-worker sidecar allowlist only knew the
runway key. Every worker turn's runway clear (both keys) was refused as
invalid_params, which poisoned the worker store and failed the turn
(tests/gateway/test_surface_admission.py managed-worker case, CI 1/3).
Add the key to SIDECAR_KEYS; the worker-context test now restores and clears
both keys through the worker store.
From the final-head gate wave on b12ce8e275:
- Two openers that both saw the retired marker before rebuild admission each
ran the full rebuild in turn (about 130 s on a 1.35M-row store), because
the admitted callback did not re-check whether a peer had already
aligned. align_locked now re-reads the layout and the marker under
BEGIN IMMEDIATE and skips when there is nothing left to do. New test: the
opener admitted second runs no rebuild; red on b12ce8e275
(['second', 'first']).
- messages._display_set uses the shared sql_common._in_one_read instead of
its own copy of the same BEGIN/ROLLBACK wrapper.
- Docstrings corrected where they no longer matched the code: the probe's
IOERR may be persistent; _attribute_ranked_corruption raises it for a
replay; _fts_match_read publishes the unattributed error after the retry
budget; a writable write as well as a search detaches a damaged index;
the skip decision is re-read under the lock.
Second-model review of e468bba3ce: an exception's __context__ is not proof
that it came from the rank probe. A plain ranked-read IOERR raised while the
caller was handling an unrelated DatabaseError was treated as an exhausted
probe and latched that ambient error. The probe now raises _RankProbeIoerr,
an OperationalError (still retried by _read_retrying_ioerr) that carries the
corruption it was diagnosing, and only that type is restored after the
budget is spent.
Test: a plain ranked-read IOERR inside a handler for an unrelated corruption
error answers [] and latches nothing. Red on e468bba3ce.
The delta review of 6410cd3ca1 showed the probe re-raised every
OperationalError. "database is locked", "interrupted" or "no such function"
then replaced the bare SQLITE_CORRUPT, and the primary search route turned
it into an empty answer with nothing latched, where 5046fe2946 failed
closed. The probe now re-raises only disk I/O errors and keeps the original
error otherwise. An IOERR that outlasts the read retry budget restores the
unattributed corruption the probe was diagnosing (latched and raised)
instead of surfacing as the IOERR the search maps to [].
Test: a locked probe and a probe whose IOERR persists both leave
SQLITE_CORRUPT raised and latched, and only the IOERR case replays the read.
Both cases are red on 6410cd3ca1. The transient-IOERR test now asserts
exactly one failed probe.
Second-model review of 5046fe2946: the attribution probe caught every
DatabaseError, including a transient "disk I/O error" OperationalError, and
then returned the original bare SQLITE_CORRUPT. _read_retrying_ioerr retries
only IOERR, so it published the unattributed error to the storage-health
latch: the bug this PR fixes, reachable when index damage and the WAL
transition window coincide. The probe now re-raises OperationalError so the
holder replays the whole read.
Also from the gate wave:
- _in_one_read moves unchanged from stored_reads to sql_common, so search no
longer imports a private helper from the transcript module.
- The interrupted-realign test raises only after the FTS DDL, not after any
script the executor runs.
New test: a disk I/O error on the first probe replays the read, answers from
canonical rows and leaves storage ok. Red with the re-raise removed.
From the gate wave on 529797fa7c and BearHuddleston's re-review:
- The rank-only MATCH pins its snapshot through the existing
stored_reads._in_one_read instead of a local copy of the same
BEGIN/ROLLBACK wrapper.
- _migrate_misaligned_fts_source: one locked helper owns the population
recheck and the realign; the admitted callback is named instead of a
lambda returning an ignored value.
- New test: a realign interrupted after its DDL leaves the old index hit and
the retired marker in place, and the next open realigns. Red with the
BEGIN IMMEDIATE removed.
- Reopens in the realign tests assert FTS stays enabled instead of skipping.
- _search_messages_stale docstring narrowed to the Latin retries (Bear's
suggestion: a triggering CJK trigram failure still takes _search_cjk's
any-term fallback, as on main). The empty-store test no longer names a
savepoint.
From the gate wave and second-model review of 83d9fa65b3:
- A store whose FTS is detached now answers through one helper on the
triggering request and every later one: LIKE on the exact terms, then on
any term after a miss (CJK skipped, as the FTS OR-relaxed retry does). Before,
the triggering OR-relaxed request found a row the next identical request
did not. The primary-route detach returns that answer directly, which
removes the detached_before_retries flag.
- _mark_fts_detached owns the three in-memory flag writes shared by
writable fail-open, deferred admission, the cross-process stale refresh and
the read-only detach.
- Read-only detach: the warning and docstring no longer promise that the next
writable open repairs the index (nothing is persisted); they name the real
paths, a writable search or `hermes sessions optimize-storage`. The test
checks state_meta through a raw read-only connection instead of after a
writer open.
- Realign: the marker check is inlined with its rationale, the rebuild timer
starts inside do_align, and the warning states what is known (the marker
only pre-v3 releases write) instead of asserting the history.
- The injected-error latch test is named for what it injects.
From BearHuddleston's review of 8678b050ac (three inline patches):
- Realign: the unlocked message check only routes populated stores to
rebuild admission; the skip-rebuild decision, the DDL, any rebuild and the
marker removal now commit together under BEGIN IMMEDIATE. A peer insert
between the empty check and the old savepoint was indexed and then lost;
an interrupted rebuild now rolls back to the old index.
- Ranked MATCH: pin a read transaction for the rank-only route so the
diagnostic bm25 probe sees the same index generation as the failed read
(a peer rebuild in between otherwise let code 11 escape and latch a
healthy store). An existing transaction is left alone; the read-only
transaction is ended by ROLLBACK.
- Test: delete one cut tool row while the pre-v3 trigger is installed, so a
repair that only swaps triggers and keeps the old postings fails.
[Salvage: ported onto 83d9fa65b3 by kshitijk4poor; the _schema.py hunk was
re-applied by hand around the post-rebuild realign warning.]
Read-only handles (dashboard and TUI cross-profile browsing) cannot write
the stale breadcrumb, so _enter_fts_fail_open refused and the newly
index-scoped error propagated instead of answering from canonical rows.
Search now detaches FTS for that handle's own lifetime and serves LIKE,
leaving the persistent detach and the rebuild to the next writable open.
The pre-v3-marker realign now logs after the rebuild has run, with its
duration (130 s on a 1.35M-row / 8.9 GB store clone), instead of claiming a
rebuild before admission decides. A deferred open logs only the existing
deferral line.
The gate wave on 764c751 found that the `rescope` keyword threaded through
StoreHolder._read_all/_read_retrying_ioerr put FTS policy on the shared read
boundary, and that the diagnostic probe ran on a second pooled reader, after
the failing read had released its snapshot.
Search now owns one MATCH read (_fts_match_read) that runs inside
_read_retrying_ioerr's callback. It attributes a bare SQLITE_CORRUPT on the
rank-only route on the SAME connection before the error reaches the
storage-health latch. _holder.py is back to main, and both ranked call sites
share the read.
The genuine-corruption test now drives search_messages instead of the private
closure.
- Empty realigned store: the marker realign of a store with no messages runs
inside SAVEPOINT fts_align_empty; run its DDL through
_execute_ddl_script_transactional so executescript's implicit COMMIT no
longer ends the savepoint ("no such savepoint: fts_align_empty" on open).
- Trigram / OR-relaxed retry that detaches the indexes now answers the
triggering request from canonical rows (exact terms, then any term)
instead of returning an empty miss.
- _read_all passes rescope only when set, keeping the one-argument
_read_retrying_ioerr call shape other callers and test spies rely on.
- Rank detection compares against the rank-only ORDER BY constant instead
of a substring test on the SQL fragment.
Tests: empty-store reopen with the retired marker; trigram and OR-relaxed
retries return the stored row on the first request.
A dashboard search could take a whole profile's session storage down until restart
although state.db was intact (PRAGMA quick_check: ok).
FTS5 evaluates `ORDER BY rank` in a nested sorter statement and SQLite masks that
statement's error to the primary code, so index damage bm25 reports as
SQLITE_CORRUPT_VTAB (e.g. a posting whose _docsize row is gone) reached the read path as
bare SQLITE_CORRUPT. _read_retrying_ioerr published it before the search's existing
fail-open could run, it classified as structural, and the process-wide latch refused
every session.create/resume with storage_unavailable.
- StoreHolder._read_all/_read_retrying_ioerr take an optional `rescope` applied before
the storage-health latch. The ranked MATCH reads pass one that, only for bare
SQLITE_CORRUPT on a rank-ordered statement, re-asks the index alone (unsorted bm25
keeps the extended code). An index-scoped answer replaces the error, so the existing
fail-open answers from canonical rows and the error, if raised, maps to
SearchIndexCorrupt; anything else keeps the original and still fails closed.
- The zero-hit trigram retry now fails open like the other ranked routes.
- _migrate_misaligned_fts_source also realigns a store whose retired
fts_tool_full_content_high_water marker is back. A release before FTS storage v3
reopening a realigned store re-stamps it at MAX(id) and reinstalls id-gated triggers
whose 'delete' sends full content for tool rows the v3 rebuild indexed as the bounded
prefix; each such delete leaves the token cut at the boundary behind with no _docsize
row, which is the damage above.
Wire error codes are unchanged.
Main's network-filesystem detection reads /proc/self/mountinfo on Linux only and answers False elsewhere; tests/AGENTS.md ("Don't fake the host OS") says such a case runs on its host under @pytest.mark.platforms("linux") and never patches sys.platform.
The removal commit's copies of test_network_fs_wal_warn.py and test_network_fs_journal_default.py added a `_linux` fixture that set sqlite_support.sys.platform to "linux", so the Linux-only detection cases ran on every host over a faked platform.
The fixture is gone and the three cases that used it (16 parametrised runs) carry @pytest.mark.platforms("linux"). The other cases, host-independent, stay unmarked.
Proof: before, on darwin, both files passed 26 with the fake (19 + 7) and grep finds the two `monkeypatch.setattr(sqlite_support.sys, "platform", "linux")` lines; after, on darwin, 10 passed and 16 skipped with "platforms(linux); host is darwin" (4 passed, 15 skipped; 6 passed, 1 skipped), and no sys.platform patch is left. The 16 cases read only the mountinfo file they are given, so on Linux they run as they ran under the fake; the main Linux CI lane runs them. ruff clean.
Reported-by: greptile-apps[bot]
Six cases drive the backend through the storage interface: the lineage is published as a compression child and each rename is a runtime sidebar mutation. A rename addressed to the ended segment lands on the live tip and is what the listing shows, a name the ancestor holds moves to the tip, an older copy of any segment is stale after a tip rename, a clear through the segment clears the listed name, a name taken from an abandoned chat advances that chat's revision, and a clear never empties the canonical Bot Chat ancestor.
The removal gave the backend's dbfile module its own copy of hermes_cli.backup.is_zeroed_sqlite_file, because the backend does not import hermes_cli.backup, and the test that kept the copy equal to backup's went with the old store's parity tests. So the detector existed twice, plus the header probe is_zeroed_state_db falls back on, and a fix to the live-connection guard or the header test had to land in both copies. The function now lives once in sqlite_support, the neutral SQLite helper module both sides already import, moved from hermes_cli/backup.py unchanged; backup.py and the backend import it from there, and the backend's copy goes. is_zeroed_state_db keeps main's fallback probe for the case where the detector raises.
The new case checks that the backend, the backup and sqlite_support name the same function; it fails before this commit. Greptile raised the duplicate in review.
The case that compared process_identity's two option tables with copies of their contents is replaced by cases through the readers that use such tables. Each operand-taking option (-Q, -W, -X, --check-hash-based-pycs, --jit), with its operand as the next token or attached, goes in front of a program: gateway.status_inline_source must still find the -c behind it and must not report inline source for a -m module, and the SQLite backend's holder reader must still name the -m module or the script. Dropping any one option from either table turns its cases red.
The append batch, automatic ended stamp and FTS fail-open cases fetch the SQLite holder of their store handle through tests/fixtures/storage_holder.raw_holder, the one test helper that names the backend, instead of calling the handle's holder() themselves.
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.
Ten tests written on main after the old base still built the authority on a SessionDB and read admissions through authority.db, SessionAuthority(db=), SessionStore._db and _admit_native_write(authorize=). They now build it with persistence= (storage_handle or open_persistence) and read through the interface the gateway uses: admissions.list/claim/settle/admit, runtime.begin_epoch, sessions.get, bindings.receipt, admission_row, AuthorityRefusal and the vocabulary's ADMITTED_REQUEST_CONFLICT. Setup only: every assertion keeps its subject and expected value.
The resumable_subagents schema test pins main's table statement as a literal instead of reading it from the legacy schema module.
The delegation ledger reaches state.db through the process-shared store, whose schema reconcile runs when the profile's StoreHolder opens. While the process holds the store, as the TUI gateway does for its lifetime, repeated orphan sweeps, reads and writes borrow that one holder and do not reconcile again, and each profile's file is reconciled on its own. The legacy test of the tool's own per-connection schema cache is retired: that cache no longer exists.
store_location() answers None for a provider whose store is not a file, but callers used the file as the store's identity: the delivery and async-delegation ledgers rebuilt their scope from the file's parent, the session authority keyed its epoch fence and checked ownership on the resolved file, and handle caches, the media sweep, the subagent roster and the group controls compared or keyed stores by path. With no file each of those raised or skipped its work.
Those callers now carry the profile scope: the ledgers open their scope directly (the tests that redirected the ledgers' file now redirect the scope), keys and comparisons use the scope's home key, and the gateway's ownership check keeps main's resolved-file test when the store has a file. persistence_assembly gains store_exists(scope), answered by the store's readiness probe, which replaces the .exists() and .is_file() checks that asked whether a profile has a store before a reader opens it; readers open the profile home rather than its file.
Identity that is written down and read back keeps main's format for a file store and names the profile home otherwise: the Kanban owner receipt and the -w worktree lock, whose readers open either. The standalone hosted-rooms import has no legacy file beside a store without one, so it moves nothing. Features that work on the file itself (session repair, journal mode, the dashboard sidebar's file cache) refuse and say they need a file-backed store.
Twelve test files called holder() directly on a Persistence handle; they now call raw_holder(handle) from tests/fixtures/storage_holder.py, the one helper that reaches the backend's holder, so the handle never has to forward a backend name.
Calls on the SQLite backend's own store (backend.open in test_message_uid.py) keep holder(), which is that store's own method.
These cases exercise the backend through callers that now use the interface, so they land after them. The legacy tests/hermes_state copies of the same cases go with them.
The agent, run_agent.py and their helpers take a persistence handle instead of SessionDB. The store-side transcript repair moves beside the legacy store until the store is removed; agent/transcript_repair.py keeps the marker logic.
session_rules.turns is the one home of the message rules the agent shares with storage: the 56 agent functions whose bodies equal a session_rules.turns function are deleted, the agent and every other caller import them from session_rules.turns, and agent/message_content.py and agent/context_compressor_retry.py, left empty, go.
SessionDB keeps its methods and opens no connection of its own: it takes its writer, read pool and write transactions from the SQLite backend's holder, handed out by the backend's registry, so a process holds one writer per state.db whichever door a caller uses. The legacy tests that reached the old connection fields follow the new owner, and the mixed-caller cases pin one writer, one VACUUM gate and one profile release for a process that uses both doors.
A SessionDB built without a holder takes its own reference on the registry's holder for its file, as the backend's stores do, and returns it once: at close, or when the handle is collected unclosed. When that close is the last release and the holder could not close (a lost WAL generation whose capture failed keeps it open), close() raises the holder's error as the legacy close did; a handle collected unclosed only logs it. A read-only one opens a read-only holder, as the read-only backend does. Tests that stand for a second writer in the process open it on a holder of their own.
Tests that patched names this change moves follow them: the registry's holder open, the read lock wait, the clock the store stamps rows with, and the token writer's seam, whose loop-thread read case runs on the backend's holder.
The desktop source-backend fixture copies persistence and session_rules into its test install, since hermes_state imports persistence.
Two SQLite handles serve one store while they share one holder: the registry hands every handle on a profile the same holder for the file's current generation, and a handle opened after state.db was replaced takes a new one while the older handle keeps the generation it held, as main's registry identity check compares its objects. SQLiteStore.serves_same_store compares holders, and the assembly's Persistence forwards it between the stores the two handles are bound to. A handle opened after the file was replaced reads the replacement and does not serve the same store as the owner; red without the method (the case raises AttributeError), green with it.
Reported-by: Greptile
Reported-by: BearHuddleston
The two test modules added for the lease holder and the ledger setup described the code before the fix and the other implementation's writes. Their docstrings now state the rule each case pins. Docstrings only; the syntax trees with docstrings blanked are identical.
The boundary case pinned five of _store_error's mappings, so the transient I/O, FTS corruption, malformed schema and generic corruption branches could each be removed without a failure: the error then fell through to a wider class. The case gains one row per branch and asserts the exact class, not a parent. Removing each branch in turn fails exactly its row (four mutants, 8 passed and 1 failed each); the code is unchanged.
Reported-by: unsupportedpastels
_ledger_setup took the process-wide setup lock and the holder's writer lock with bare with blocks, and its deadline covered only the retry loop: a long write elsewhere held the setup, and every ledger verb behind it, with no bound. Both locks are now taken against that deadline, the writer lock through writer_mutex_until as every write takes it, so a held lock refuses the setup with StoreContention, which the existing retry loop and callers already handle. A case holds the writer lock from another thread and asserts the setup refuses within the wait and runs nothing; it hung before the fix.
Reported-by: Greptile
Reported-by: unsupportedpastels
The four turn-lease verbs called self._store.holder() inside their write transaction to find the conversation key. After a profile sweep (close_all_under) cleared the holder's registry ownership, that call reacquired from the registry, which waits on the sweep's teardown, which waits on the write lock the transaction holds: a deadlock. Main's lease writes resolve nothing inside the transaction. Each verb now resolves the holder once before the write and the closure uses that object, so a sweep during the write completes after it. A case starts a profile sweep from inside the write of try_acquire, refresh and release, and asserts both finish; it hung before the fix (stopped by its recorded pid after 150 s) and passes after. The only other in-closure holder calls in the backend are the topic reads' lambdas in gateway/routing.py, which run outside any transaction.
Reported-by: Greptile
Reported-by: unsupportedpastels
The delegation ledger has no delivered-acknowledgement call any more; these cases need only a write that opens the ledger's store, and a delivery claim is that write.
The SQLite ledger matches the contract: every in-flight filter on `async_delegations` (prune counts and deletes, the orphan sweep and its reads, the finished read, the in-flight read) and the worker delivery claim test `state='running'` or `state!='running'`, since no writer stores `finalizing`. The abandoned-delegation recovery parity case now expects the one running row recovered.
The plain-message branch of the listing preview SQL now left-trims the content before the 63-character head cut, as main's listing does, so leading whitespace no longer eats into the cut and every cut preview carries the ... marker.
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.
The backend's begin_runtime_epoch now runs main's owner guard before the bump: while another process holds the profile's gateway.lock, the bump raises AuthorityRefusal('ownership_conflict', field='runtime_epoch') and the owner's epoch stays where it was. A reservation this process holds grants the bump, the flock decides rather than the lock record, and a store with no directory of its own never refuses.
Main's ownership cases run against the backend's runtime.begin_epoch.
The holder keys prompt_cache_clock like a route field, so queued deltas carrying different cache events apply in order and are never merged. The usage delta passes its clock to the token update, which writes the column only when a clock is given, with main's statement. The usage repository gains prompt_cache_clock (one statement: the stored clock, the resume fallback only for sessions whose cache counters are non-zero, and the archived-row generation, after draining the queue) and prompt_cache_generation, and the session record carries the column.
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.
A new store on an nfs/cifs/smb/sshfs mount starts in DELETE unless database.journal_mode is set explicitly, with one WARNING naming the override; an existing WAL store there keeps WAL (never live-downgraded) and gets one WARNING with the offline remedy, on both already-WAL paths. Stores opening through sqlite_support.open_db, including the hosted-room shared-state.db, follow the same policy as hermes_state_wal.
Tests: tests/persistence_sqlite/core/test_sqlite_support_network_fs.py and test_sqlite_support_network_fs_store_coverage.py.
The on_session_delete dispatch keeps main's legacy profile setter: under a bound local scope it binds the store's whole profile for the hook, so that profile's plugins run with its own secrets and terminal policy, and in a hosted scope it refuses as main's does. push_state(home=...) would have moved only the home and left a plugin of one profile reading another profile's secrets. The store open keeps push_state, binding only the home for its configuration read. The line carries the health waiver for the setter main itself uses at this point.
The store open's _home_bound and the on_session_delete dispatch in session_retention bound the store's profile home through the legacy set_hermes_home_override, which under a bound scope moves the whole scope (secrets and terminal policy with it) or refuses in a hosted one. Both now push the home alone with hermes_scope.push_state(home=...), keeping the bind condition and resetting the token afterwards, so the caller's scope stays its own.
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.
The SQLite backend's peer-recovery queries now exclude rows carrying _delegate_from unless the row is the chat's /new continuation (_reset_from) or a delegate the user resumed the chat onto (_chat_adopted), as main's store does. The session insert strips a delegate marker from a keyed /new continuation and from a config upserted onto a reset row, and a compression rotation carries _chat_adopted onto the new tip.
A chat's /new continuation (session_key and _reset_from set) that picked up _delegate_from is hidden from every session list while the gateway keeps routing into it. The SQLite backend's schema open now strips the stray marker, as main's store does, and indexes the healed rows' messages into the trigram index under the same rebuild-window rule as the triggers.
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.