Summary
The optimize metrics flush loop in unified_daemon.py calls CacheDB() on every iteration rather than reusing a single instance. Every 60 seconds this:
- Constructs a new
DatabaseManager and calls initialize() → logs "Schema initialized at llmcache.db" even though the schema already exists
- Re-runs the SQLite corruption check
- Reloads or regenerates the AES-256-GCM salt and derives the encryption key from scratch
None of this work is needed after the first open. It's purely noise, but it fills the daemon log at a rate of once per minute indefinitely.
Observed behaviour
2026-06-16 19:23:51 Schema initialized at /Users/barrygfo/.superlocalmemory/llmcache.db
2026-06-16 19:24:51 Schema initialized at /Users/barrygfo/.superlocalmemory/llmcache.db
2026-06-16 19:25:51 Schema initialized at /Users/barrygfo/.superlocalmemory/llmcache.db
... (every 60s, indefinitely)
Root cause
server/unified_daemon.py — _metrics_flush_loop():
async def _metrics_flush_loop():
while True:
await asyncio.sleep(60)
try:
MetricsPersistence().flush(
MetricsCollector.get_instance(), CacheDB() # ← new instance each tick
)
CacheDB.__init__ always runs self._db.initialize(_schema) (which logs "Schema initialized"), the corruption integrity check, and AES key derivation — all of which are one-time setup operations, not per-flush ones.
The startup load call on the line before the loop has the same issue:
MetricsPersistence().load(MetricsCollector.get_instance(), CacheDB()) # ← also a fresh instance
Fix
CacheDB already provides a thread-safe singleton via CacheDB.get_default() (used correctly at shutdown). The flush loop should use it:
# startup load
MetricsPersistence().load(MetricsCollector.get_instance(), CacheDB.get_default())
# flush loop
async def _metrics_flush_loop():
while True:
await asyncio.sleep(60)
try:
MetricsPersistence().flush(
MetricsCollector.get_instance(), CacheDB.get_default()
)
Two-character change per call site. The singleton is already created, thread-safe, and cleared at shutdown (CacheDB.reset_default() is called in the shutdown path).
Environment
- SLM version: 3.6.13 (also present in current
main)
- Python: 3.14
- Platform: macOS Darwin 25.5.0
Summary
The optimize metrics flush loop in
unified_daemon.pycallsCacheDB()on every iteration rather than reusing a single instance. Every 60 seconds this:DatabaseManagerand callsinitialize()→ logs "Schema initialized at llmcache.db" even though the schema already existsNone of this work is needed after the first open. It's purely noise, but it fills the daemon log at a rate of once per minute indefinitely.
Observed behaviour
Root cause
server/unified_daemon.py—_metrics_flush_loop():CacheDB.__init__always runsself._db.initialize(_schema)(which logs "Schema initialized"), the corruption integrity check, and AES key derivation — all of which are one-time setup operations, not per-flush ones.The startup load call on the line before the loop has the same issue:
Fix
CacheDBalready provides a thread-safe singleton viaCacheDB.get_default()(used correctly at shutdown). The flush loop should use it:Two-character change per call site. The singleton is already created, thread-safe, and cleared at shutdown (
CacheDB.reset_default()is called in the shutdown path).Environment
main)