refactor(state): one canonical-path helper for holder scans

Follow-up on the #97330 salvage (#97329): main grew `_canonical_sqlite_path`
after the PR's base; the holder module re-implemented it as a closure. Export
`canonical_sqlite_path` from hermes_state_holders and alias the legacy name in
hermes_state. Drop the unused `_read_proc_argv` / `_looks_like_hermes`
re-exports (no in-tree callers).
This commit is contained in:
kshitijk4poor
2026-09-03 02:55:50 +05:30
committed by kshitij
parent 06d7b77b1c
commit 5e01b8fa7a
2 changed files with 11 additions and 16 deletions
+1 -7
View File
@@ -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_path
def _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 (see
+10 -9
View File
@@ -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 watched
try:
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]]:
continue
for 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(