The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_state): one canonical_sqlite_path
kshitijk4poorefca6efdc850
diff --git a/hermes_state.py b/hermes_state.pyindex 8070e6ae3a6..84aa323d98d 100644--- a/hermes_state.py+++ b/hermes_state.py@@ -47,7 +47,7 @@ from hermes_state_schema import SessionSchemaMixinimport hermes_state_holders as _state_holdersimport hermes_state_lockguard as _lockguardfrom hermes_state_dbfile import (- _canonical_sqlite_path, _connect_tracked_db, _fd_is_truly_unlinked, _prepare_connection_retirement,+ _connect_tracked_db, _fd_is_truly_unlinked, _prepare_connection_retirement,_read_sqlite_application_id, _stat_sqlite_sidecar_identity,_watched_sqlite_sidecar_paths, has_invalid_sqlite_header_preopen, is_zeroed_state_db, quarantine_cross_process_lock,quarantine_invalid_state_db,@@ -1114,7 +1114,7 @@ class SessionDB(watched = _watched_sqlite_sidecar_paths(self.db_path)try:for target, fd_path in _proc_fd_targets(os.getpid()):- canonical = _canonical_sqlite_path(target)+ canonical = _state_holders.canonical_sqlite_path(target)if (" (deleted)" in target and canonical in watchedand _fd_is_truly_unlinked(fd_path, watched[canonical])):return Truediff --git a/hermes_state_dbfile.py b/hermes_state_dbfile.pyindex ac07cccf68f..271d98f3896 100644--- a/hermes_state_dbfile.py+++ b/hermes_state_dbfile.py@@ -23,6 +23,7 @@ import timefrom pathlib import Pathfrom typing import Any, Callable, Dict, List, Optional, Tuple+from hermes_state_holders import canonical_sqlite_pathfrom hermes_state_common import (FTS_REBUILD_DEFERRAL_KEY, stat_db_file_identity as _stat_db_file_identity)@@ -131,17 +132,12 @@ def _stat_sqlite_sidecar_identity(db_path: Path) -> Dict[str, tuple]:return {suffix: ident for suffix, ident in idents.items() if ident is not None}-def _canonical_sqlite_path(path: str) -> str:- """Normalize a /proc fd target, stripping the Linux `` (deleted)`` suffix."""- return os.path.normcase(os.path.abspath(path.removesuffix(" (deleted)")))--def _watched_sqlite_sidecar_paths(db_path) -> Dict[str, str]:"""Map each sidecar's canonical (/proc-comparable) form to its literal, still-named path,so a canonical match can be re-``stat``'d for identity rather than trusted as text."""base = os.path.abspath(os.fspath(db_path))literal = (base + "-wal", base + "-shm")- return {_canonical_sqlite_path(path): path for path in literal}+ return {canonical_sqlite_path(path): path for path in literal}def _identity_is_truly_unlinked(identity: "Tuple[int, int]", watched_path: str) -> bool:@@ -327,7 +323,7 @@ def iter_deleted_sqlite_sidecar_holders(db_path) -> List[Tuple[int, str]]:elif sys.platform.startswith("linux"):watched = _watched_sqlite_sidecar_paths(db_path)for pid, target, fd_path in _iter_proc_fd_targets():- canonical = _canonical_sqlite_path(target)+ canonical = canonical_sqlite_path(target)if (" (deleted)" in target and canonical in watchedand _fd_is_truly_unlinked(fd_path, watched[canonical])):holders.append((pid, target))@@ -793,4 +789,4 @@ def _concrete_state_db_holder_pids(db_path: Path, holders: List[Tuple[int, str]]canonical_db = os.path.normcase(os.path.abspath(os.fspath(db_path)))watched = {canonical_db, canonical_db + "-wal", canonical_db + "-shm"}return list(dict.fromkeys(- pid for pid, path in holders if pid > 0 and _canonical_sqlite_path(path) in watched))+ pid for pid, path in holders if pid > 0 and canonical_sqlite_path(path) in watched))