{"record":{"id":"40ccbf8eb90b7c95","repo":"headroomlabs-ai/headroom","slug":"cache-max-size-must-be-positive-got-self-cache-m","errorCode":null,"errorMessage":"cache_max_size must be positive, got {self.cache_max_size}","messagePattern":"cache_max_size must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/config.py","lineNumber":151,"sourceCode":"\n    def __post_init__(self) -> None:\n        \"\"\"Validate configuration after initialization.\"\"\"\n        if self.vector_dimension < 1:\n            raise ValueError(f\"vector_dimension must be positive, got {self.vector_dimension}\")\n\n        if self.hnsw_ef_construction < 1:\n            raise ValueError(\n                f\"hnsw_ef_construction must be positive, got {self.hnsw_ef_construction}\"\n            )\n\n        if self.hnsw_m < 1:\n            raise ValueError(f\"hnsw_m must be positive, got {self.hnsw_m}\")\n\n        if self.hnsw_ef_search < 1:\n            raise ValueError(f\"hnsw_ef_search must be positive, got {self.hnsw_ef_search}\")\n\n        if self.cache_max_size < 1:\n            raise ValueError(f\"cache_max_size must be positive, got {self.cache_max_size}\")\n\n        if self.embedder_backend == EmbedderBackend.OPENAI and not self.openai_api_key:\n            raise ValueError(\"openai_api_key is required when using OpenAI embedder backend\")\n\n        # Ensure db_path is a Path object\n        if isinstance(self.db_path, str):\n            self.db_path = Path(self.db_path)\n","sourceCodeStart":133,"sourceCodeEnd":159,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/config.py#L133-L159","documentation":"ValueError raised in MemoryConfig.__post_init__ when cache_max_size < 1. The memory system keeps an in-memory result/entry cache bounded by this size; a zero or negative bound is invalid (and would silently disable caching, which the config forbids), so it fails at construction.","triggerScenarios":"MemoryConfig(cache_max_size=0) — frequently an intentional attempt to disable the cache that the config rejects; or a negative value from arithmetic on another setting.","commonSituations":"Trying to turn caching off for benchmarking by setting size 0; configs where '0' is the sentinel for 'unset'; cache sizing derived from machine specs producing 0 on tiny instances.","solutions":["Use cache_max_size=1 as the smallest legal cache if you want it effectively off, or a realistic bound like 1000","To disable caching entirely, set cache_enabled=False instead of zeroing the size","Validate derived size computations (e.g. int(mem * ratio)) with a floor of 1"],"exampleFix":"# before\ncfg = MemoryConfig(cache_max_size=0)  # ValueError: cache_max_size must be positive\n\n# after\ncfg = MemoryConfig(cache_enabled=False)  # actually disable caching\ncfg = MemoryConfig(cache_max_size=1000)  # or size it properly","handlingStrategy":"validation","validationCode":"# want caching off? use the enabled flag, not size 0\nif not want_cache:\n    cfg = MemoryConfig(cache_enabled=False)\nelse:\n    size = max(1, int(cache_size))  # floor at 1\n    cfg = MemoryConfig(cache_enabled=True, cache_max_size=size)","typeGuard":"def is_valid_cache_size(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 1","tryCatchPattern":"try:\n    cfg = MemoryConfig(cache_max_size=size)\nexcept ValueError:\n    cfg = MemoryConfig(cache_max_size=1000)","preventionTips":["Use cache_enabled=False to disable caching; never size=0","Floor derived cache sizes at 1 in autoscaling formulas","Document that all memory-config integers are minimum 1"],"tags":["python","config","validation","cache","range-check"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}