[memory] Duplicated entry validation logic in _validate_entries() and save() #759

Closed
opened 2026-06-03 00:20:57 +02:00 by sleepy · 0 comments
Owner

"File: services/memory/memory.py _validate_entries() (line 142) and save() (line 184) both do the same field-defaulting logic: python if "id" not in entry: entry["id"] = str(uuid.uuid4()) if "timestamp" not in entry: entry["timestamp"] = int(time.time()) if "source" not in entry: entry["source"] = "..." if "category" not in entry: entry["category"] = "fact" This validation runs on every load_all() AND every save(). For a list of N entries, that's 2N validation passes per write cycle. The save() path should trust that _validate_entries already ran during load, or the validation should be a single method called once. Additionally, _validate_entries mutates the input list in place AND returns it — confusing contract."

"**File**: `services/memory/memory.py` `_validate_entries()` (line 142) and `save()` (line 184) both do the same field-defaulting logic: ```python if "id" not in entry: entry["id"] = str(uuid.uuid4()) if "timestamp" not in entry: entry["timestamp"] = int(time.time()) if "source" not in entry: entry["source"] = "..." if "category" not in entry: entry["category"] = "fact" ``` This validation runs on every `load_all()` AND every `save()`. For a list of N entries, that's 2N validation passes per write cycle. The `save()` path should trust that `_validate_entries` already ran during load, or the validation should be a single method called once. Additionally, `_validate_entries` mutates the input list in place AND returns it — confusing contract."
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/odysseus#759
No description provided.