fix(memory): add thread-safe singleton initialization

- Add threading.Lock with double-check locking to ScopeManager
- Add asyncio.Lock with double-check locking to MemoryReflection
- Make reset_memory_metrics async with proper locking
- Update test fixtures to handle async reset functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-05 17:39:39 +01:00
parent 33ec889fc4
commit f057c2f0b6
5 changed files with 36 additions and 17 deletions

View File

@@ -499,10 +499,11 @@ async def get_memory_metrics() -> MemoryMetrics:
return _metrics
def reset_memory_metrics() -> None:
async def reset_memory_metrics() -> None:
"""Reset the singleton instance (for testing)."""
global _metrics
_metrics = None
async with _lock:
_metrics = None
# Convenience functions