From 9d22ea7ff4a6d2370ded570ccd7935bb3a68b768 Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Sat, 25 Apr 2026 18:38:06 -0700 Subject: [PATCH] fix: move models disk cache from /dev/shm to STATE_DIR for per-instance isolation (#1064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using /dev/shm caused cross-instance cache pollution: any server started on a different port (QA harness on 8789, test runs) would write its own provider set to the shared file, and the production server on 8787 would load it on next restart — showing only OpenRouter (or whatever the test environment had configured) instead of the real provider list. Moving the cache file to STATE_DIR / "models_cache.json" gives each server instance its own isolated cache (each port uses a different HERMES_WEBUI_STATE_DIR). Also fixes macOS/Windows portability where /dev/shm does not exist. Co-authored-by: nesquena-hermes --- api/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/config.py b/api/config.py index 10943322..341c0027 100644 --- a/api/config.py +++ b/api/config.py @@ -1104,7 +1104,11 @@ _provider_models_invalidated_ts: dict[str, float] = {} # provider_id -> timesta # config.yaml changes. A TTL is still used as a fallback in case the invalidation # signal is somehow missed, but the cache will always be warm after the first # page load following a server start. -_models_cache_path = Path("/dev/shm") / "hermes_webui_models_cache.json" +# Cache file lives inside STATE_DIR so each server instance (different +# HERMES_WEBUI_STATE_DIR / port) has its own file and test runs never +# pollute the production server's cache. Also works on macOS and Windows +# where /dev/shm does not exist. +_models_cache_path = STATE_DIR / "models_cache.json" def _delete_models_cache_on_disk() -> None: @@ -1150,7 +1154,7 @@ def invalidate_models_cache(): not immediately reload a stale disk snapshot and skip the fresh build. This is essential for test isolation: without the disk delete, tests that call invalidate_models_cache() still get back the previous test's - result from /dev/shm because the disk hit is checked before the memory + result from the disk cache because the disk hit is checked before the memory cache rebuild runs. """ global _cache_build_in_progress, _available_models_cache, _available_models_cache_ts, _cache_build_cv