Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(context): normalize timestamps in _markdown_record_matches for idempotency

Sameer630540d6fa05d0f1
diff --git a/semantica/context/agent_memory.py b/semantica/context/agent_memory.py
index 7442a636..53e5816c 100644
--- a/semantica/context/agent_memory.py
+++ b/semantica/context/agent_memory.py
@@ -2126,7 +2126,8 @@ class AgentMemory:
return (
existing.content == memory["content"]
- and existing.timestamp == memory["timestamp"]
+ and self._timestamp_comparison_key(existing.timestamp)
+ == self._timestamp_comparison_key(memory["timestamp"])
and existing.metadata == memory["metadata"]
and existing.entities == memory["entities"]
and existing.relationships == memory["relationships"]
diff --git a/tests/context/test_agent_memory_markdown.py b/tests/context/test_agent_memory_markdown.py
index 49c74989..ce1a00d2 100644
--- a/tests/context/test_agent_memory_markdown.py
+++ b/tests/context/test_agent_memory_markdown.py
@@ -257,6 +257,29 @@ def test_reimporting_unchanged_markdown_does_not_rewrite_memory():
assert memory.count() == 1
+def test_naive_and_aware_equivalent_timestamps_match_idempotently():
+ memory = AgentMemory()
+ utc_dt = datetime(2026, 7, 22, 9, 0, 0, tzinfo=timezone.utc)
+ naive_dt = utc_dt.astimezone().replace(tzinfo=None)
+ memory.store(
+ "Unchanged",
+ metadata={"type": "note", "updated_at": "2026-07-22T10:00:00+00:00"},
+ memory_id="mem_test",
+ timestamp=naive_dt,
+ )
+ document = markdown_document(
+ required_frontmatter("mem_test", created_at="2026-07-22T09:00:00+00:00"),
+ "Unchanged",
+ )
+
+ with patch.object(
+ memory, "_replace_memory_item", wraps=memory._replace_memory_item
+ ) as replace:
+ assert memory.import_data(document, format="markdown") == 1
+
+ replace.assert_not_called()
+
+
def test_kind_is_accepted_as_the_type_alias():
frontmatter = required_frontmatter()
frontmatter["kind"] = frontmatter.pop("type")