From 92300b5d679d17dec92d426d076df246d7ca89df Mon Sep 17 00:00:00 2001 From: Kenny Van de Maele Date: Sun, 7 Jun 2026 23:37:12 +0200 Subject: [PATCH] fix(search): write cache under DATA_DIR, guard mkdir against read-only path (#3334) services/search/cache.py set CACHE_DIR = services/cache (the source tree) and mkdir'd it at import, unguarded. In Docker services/ is the read-only image layer, so the mkdir fails at import (same class as the analytics bug #2366). Move the cache under DATA_DIR/cache (writable on Docker and native) and wrap the mkdir so an unwritable path disables disk cache instead of crashing import. Part of #3331. Co-authored-by: Claude Opus 4.8 --- services/search/cache.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/search/cache.py b/services/search/cache.py index 11fe72215..222682c7b 100644 --- a/services/search/cache.py +++ b/services/search/cache.py @@ -6,17 +6,23 @@ from datetime import datetime, timedelta from pathlib import Path from typing import Dict +from core.constants import DATA_DIR + logger = logging.getLogger(__name__) # Cache directories -CACHE_DIR = Path(__file__).resolve().parent.parent / "cache" +CACHE_DIR = Path(DATA_DIR) / "cache" SEARCH_CACHE_DIR = CACHE_DIR / "search" CONTENT_CACHE_DIR = CACHE_DIR / "content" CACHE_MAX_ENTRIES = 1000 -# Create cache directories -SEARCH_CACHE_DIR.mkdir(parents=True, exist_ok=True) -CONTENT_CACHE_DIR.mkdir(parents=True, exist_ok=True) +# Create cache directories. Guarded so an unwritable path (e.g. a read-only +# mount) degrades to no-disk-cache instead of crashing module import. +try: + SEARCH_CACHE_DIR.mkdir(parents=True, exist_ok=True) + CONTENT_CACHE_DIR.mkdir(parents=True, exist_ok=True) +except OSError as _e: + logger.warning("Search cache directory unavailable (%s); disk cache disabled", _e) # Track cache size for LRU eviction search_cache_index: Dict[str, datetime] = {}