fix(utils): atomic writers refuse to resurrect a deleted named profile home

Background writers that still carry a tombstoned profile as their Hermes
home (reasoning-caps warm thread, models cache, models.dev ETag, gateway
lifecycle ledger, MCP OAuth tokens, memory store) re-created
profiles/<name>/ with a bare mkdir right before an atomic write. Route the
parent-dir creation through mkdir_under_hermes_home so a deleted named
profile raises FileNotFoundError and stays gone, matching the tombstone
contract already enforced for logging and state.
This commit is contained in:
Konstantin Khlopkov
2026-09-16 07:46:07 +03:00
committed by Teknium
parent 91a38622db
commit 7f7d229f83
6 changed files with 191 additions and 11 deletions
+6 -2
View File
@@ -87,7 +87,9 @@ def _write_sentinel(payload: Dict[str, Any], home: Optional[Path]) -> None:
from utils import atomic_json_write
path = get_lifecycle_sentinel_path(home)
path.parent.mkdir(parents=True, exist_ok=True)
from hermes_constants import mkdir_under_hermes_home
mkdir_under_hermes_home(path.parent)
atomic_json_write(path, payload, indent=None)
except Exception:
logger.debug("Failed to write lifecycle sentinel", exc_info=True)
@@ -97,7 +99,9 @@ def _append_exit_diag(record: Dict[str, Any], home: Optional[Path]) -> None:
"""Append a JSON line to gateway-exit-diag.log (same format as the CLI's ``_exit_diag``)."""
try:
path = _home_path(home, "logs", "gateway-exit-diag.log")
path.parent.mkdir(parents=True, exist_ok=True)
from hermes_constants import mkdir_under_hermes_home
mkdir_under_hermes_home(path.parent)
with path.open("a", encoding="utf-8") as fh:
fh.write(json.dumps(record, default=str) + "\n")
except OSError: