fix(state): holder scan resolves symlinked homes; doctor's ro URI escapes reserved chars

Review findings on #110914 (@ehz0ah): the psutil leg compared watched
abspath against the kernel-resolved path psutil reports, so a symlinked
HERMES_HOME on macOS returned no holders and let the fallback probe mint
replacement sidecars under a live writer. Both sides now realpath.
doctor's `file:{path}?mode=ro` truncated at '?'/'#' in a home name;
build the URI with as_uri().
This commit is contained in:
teknium1
2026-09-14 08:30:49 -07:00
committed by Teknium
parent 12173db5b7
commit 9b419a2d3c
4 changed files with 50 additions and 3 deletions

View File

@@ -188,7 +188,9 @@ def foreign_state_db_holders(db_path: Path) -> List[Tuple[int, str]]:
if _IS_WINDOWS:
return []
db_path_str = os.path.abspath(os.fspath(db_path))
# realpath, not abspath: psutil/libproc report the kernel-resolved pathname, so a symlinked
# HERMES_HOME would otherwise make every holder invisible and let maintenance proceed.
db_path_str = os.path.realpath(os.fspath(db_path))
watched = {
canonical_sqlite_path(db_path_str),
canonical_sqlite_path(db_path_str + "-wal"),
@@ -303,7 +305,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_sqlite_path(path) in watched:
if path and canonical_sqlite_path(os.path.realpath(path)) in watched:
holders.append((pid, path))
except Exception as exc:
logger.warning(