mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-21 22:54:00 +08:00
fix: Prevent shallow copy mutation in async_get_history with include_metadata
When include_metadata=True, the metadata dict was added directly to the original history entry objects (shallow copy of list, same dict refs). Now creates per-entry dict copies before enriching with metadata.
This commit is contained in:
@@ -407,14 +407,18 @@ class HistoryManager:
|
||||
history = history[:limit]
|
||||
|
||||
if include_metadata:
|
||||
enriched = []
|
||||
for entry in history:
|
||||
entry["metadata"] = {
|
||||
enriched_entry = dict(entry)
|
||||
enriched_entry["metadata"] = {
|
||||
"entry_size": len(str(entry)),
|
||||
"question_length": len(entry.get("question", "")),
|
||||
"response_length": len(entry.get("response", "")),
|
||||
"model_used": entry.get("model", default_model),
|
||||
"instance": self.instance_name,
|
||||
}
|
||||
enriched.append(enriched_entry)
|
||||
return enriched
|
||||
|
||||
return history
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user