The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(state): one canonical-path helper for holder scans
kshitijk4poor5e01b8fa7a51
diff --git a/hermes_state.py b/hermes_state.pyindex 38a969083e6..1d225138e65 100644--- a/hermes_state.py+++ b/hermes_state.py@@ -4541,9 +4541,7 @@ def _stat_sqlite_sidecar_identity(db_path: Path) -> Dict[str, tuple]:return identities-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)")))+_canonical_sqlite_path = _state_holders.canonical_sqlite_pathdef _watched_sqlite_sidecar_paths(db_path) -> Set[str]:@@ -5074,10 +5072,6 @@ def _concrete_state_db_holder_pids(return pids-_read_proc_argv = _state_holders._read_proc_argv-_looks_like_hermes = _state_holders._looks_like_hermes--# Lifecycle statuses surfaced by session pickers. Classification looks ONLY at# a session's final message row — role, whether it carries tool_calls, and its# finish_reason — so it stays O(1) per session (seediff --git a/hermes_state_holders.py b/hermes_state_holders.pyindex 5b542c4e4c9..9f4176d40a8 100644--- a/hermes_state_holders.py+++ b/hermes_state_holders.py@@ -120,6 +120,11 @@ def _looks_like_hermes(argv: Sequence[str]) -> bool:)+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 foreign_state_db_holders(db_path: Path) -> List[Tuple[int, str]]:"""Return foreign holders of the DB or one of its WAL sidecars.@@ -130,15 +135,11 @@ def foreign_state_db_holders(db_path: Path) -> List[Tuple[int, str]]:if _IS_WINDOWS:return []- def _canonical(path: str) -> str:- clean = path.removesuffix(" (deleted)")- return os.path.normcase(os.path.abspath(clean))-db_path_str = os.path.abspath(os.fspath(db_path))watched = {- _canonical(db_path_str),- _canonical(db_path_str + "-wal"),- _canonical(db_path_str + "-shm"),+ canonical_sqlite_path(db_path_str),+ canonical_sqlite_path(db_path_str + "-wal"),+ canonical_sqlite_path(db_path_str + "-shm"),}holders: List[Tuple[int, str]] = []watched_ids: Set[Tuple[int, int]] = set()@@ -190,7 +191,7 @@ def foreign_state_db_holders(db_path: Path) -> List[Tuple[int, str]]:))continue- target_is_watched = _canonical(target) in watched+ target_is_watched = canonical_sqlite_path(target) in watchedtry:fd_stat = os.stat(fd_path)except OSError as exc:@@ -237,7 +238,7 @@ def foreign_state_db_holders(db_path: Path) -> List[Tuple[int, str]]:continuefor opened in info.get("open_files") or ():path = getattr(opened, "path", "")- if path and _canonical(path) in watched:+ if path and canonical_sqlite_path(path) in watched:holders.append((pid, path))except Exception as exc:logger.warning(