Skip to content

The agent that grows with you

fix(local-runtime): an unwritable boot lock degrades to an unlocked boot, never an OSError

teknium156b7a0fb3769
diff --git a/hermes_cli/local_runtime/bootstrap.py b/hermes_cli/local_runtime/bootstrap.py
index a67b062ed96..5f4dfcb41fa 100644
--- a/hermes_cli/local_runtime/bootstrap.py
+++ b/hermes_cli/local_runtime/bootstrap.py
@@ -215,10 +215,17 @@ def _cross_process_boot_lock(timeout_s: float = 130.0):
Two profiles booting in the same second each see no ``server.json`` yet and each spawn a
router on the stable port (#116682); an OS-held lock makes the second caller wait for the
first to publish its state file, so it re-checks and adopts instead of spawning a duplicate.
- Bounded, not indefinite: never hang session start dead if the lock is somehow stuck."""
+ Bounded, not indefinite: never hang session start dead if the lock is somehow stuck, and
+ never raise into session start: an unwritable runtimes dir (or a foreign-owned lock file)
+ proceeds unlocked with a warning, like the contention timeout."""
path = runtimes_root() / "boot.lock"
- path.parent.mkdir(parents=True, exist_ok=True)
- fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
+ try:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
+ except OSError as exc:
+ logger.warning("boot lock unavailable (%s); proceeding without it", exc)
+ yield
+ return
try:
deadline = time.monotonic() + timeout_s
while not _try_lock_boot_fd(fd):
diff --git a/tests/hermes_cli/test_local_runtime.py b/tests/hermes_cli/test_local_runtime.py
index 46f06b488ff..d5580fa62c7 100644
--- a/tests/hermes_cli/test_local_runtime.py
+++ b/tests/hermes_cli/test_local_runtime.py
@@ -10,6 +10,7 @@ exercise detection fingerprinting and supervisor logic without a GPU.
from __future__ import annotations
import json
+import logging
import os
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
@@ -1024,6 +1025,29 @@ def test_ensure_local_runtime_serializes_racing_callers(tmp_path, monkeypatch):
"first's published state (#116682)")
+def test_ensure_local_runtime_proceeds_when_boot_lock_is_unwritable(tmp_path, monkeypatch, caplog):
+ """The boot lock lives outside the body's ``try/except``: an unwritable runtimes dir must
+ degrade to a warning and an unlocked boot, never an OSError out of session start."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ from hermes_cli.local_runtime import bootstrap
+
+ monkeypatch.setattr(bootstrap, "_SUPERVISOR", None)
+ mdir = bootstrap.models_dir()
+ mdir.mkdir(parents=True, exist_ok=True)
+ (mdir / "stub-Q4_K_M.gguf").touch()
+ blocker = tmp_path / "not-a-dir"
+ blocker.write_text("", encoding="utf-8")
+ monkeypatch.setattr(bootstrap, "runtimes_root", lambda: blocker / "runtimes") # mkdir -> OSError
+ monkeypatch.setattr("hermes_cli.local_runtime.endpoint._state_endpoint", lambda: None)
+ monkeypatch.setattr("hermes_cli.local_runtime.binaries.installed_tags", lambda: [])
+
+ with caplog.at_level(logging.WARNING, logger=bootstrap.logger.name):
+ result = bootstrap.ensure_local_runtime({"local_runtime": {"enabled": True}})
+
+ assert result is None # no exception escaped
+ assert any("boot lock unavailable" in rec.getMessage() for rec in caplog.records)
+
+
def test_manifest_verified_tolerates_non_dict_manifest(tmp_path):
"""A parseable-but-non-object manifest used to raise AttributeError out of
manifest_verified (the .get ran inside a try that only caught decode/OSError),