Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/model_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _save_model_metadata_disk_cache(data: Dict[str, Dict[str, Any]]) -> None:
data,
indent=0,
separators=(",", ":"),
mode=0o600,
)
except Exception as e:
logger.debug("Failed to save OpenRouter model metadata disk cache: %s", e)
Expand Down
9 changes: 2 additions & 7 deletions hermes_cli/model_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from typing import Any

from hermes_cli import __version__ as _HERMES_VERSION
from utils import atomic_replace
from utils import atomic_json_write

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -219,12 +219,7 @@ def _read_disk_cache() -> tuple[dict[str, Any] | None, float]:
def _write_disk_cache(data: dict[str, Any]) -> None:
path = _cache_path()
try:
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(path.suffix + ".tmp")
with open(tmp, "w", encoding="utf-8") as fh:
json.dump(data, fh, indent=2)
fh.write("\n")
atomic_replace(tmp, path)
atomic_json_write(path, data, indent=2, mode=0o600)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend this owner-only write policy to the sibling persisted model caches: agent/models_dev.py:235, hermes_cli/models.py:2727, hermes_cli/models.py:4011, and the direct temporary-file write at hermes_cli/models.py:861-884 remain umask-dependent.

except OSError as exc:
logger.info("model catalog cache write failed: %s", exc)

Expand Down
4 changes: 4 additions & 0 deletions tests/agent/test_model_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Persistent cache — save/load, corruption, update, provider isolation
"""

import os
import stat
import time

import pytest
Expand Down Expand Up @@ -1213,6 +1215,8 @@ def test_network_success_writes_disk_cache(self, tmp_path, monkeypatch):
fetch_model_metadata(force_refresh=True)

assert cache_path.exists()
if os.name != "nt":
assert stat.S_IMODE(cache_path.stat().st_mode) == 0o600
Comment on lines +1218 to +1219
assert "live/model" in cache_path.read_text(encoding="utf-8")

def test_network_failure_falls_back_to_stale_disk_cache(self, tmp_path, monkeypatch):
Expand Down
3 changes: 3 additions & 0 deletions tests/hermes_cli/test_model_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import os
import stat
import time
from pathlib import Path
from unittest.mock import patch
Expand Down Expand Up @@ -108,6 +109,8 @@ def test_fetch_and_cache_writes_disk(self, isolated_home):

cache_file = model_catalog._cache_path()
assert cache_file.exists()
if os.name != "nt":
assert stat.S_IMODE(cache_file.stat().st_mode) == 0o600
Comment on lines +112 to +113
with open(cache_file) as fh:
assert json.load(fh) == manifest

Expand Down