Skip to content

The agent that grows with you

fix(memory): never dedupe indented recall lines

kshitijk4poor28bd8cc08c7e
diff --git a/agent/memory_manager.py b/agent/memory_manager.py
index 9e0dcd08c72..20443b35ad3 100644
--- a/agent/memory_manager.py
+++ b/agent/memory_manager.py
@@ -294,15 +294,18 @@ def _drop_repeated_recall_lines(text: str) -> str:
kept: list[str] = []
for index, line in enumerate(lines):
stripped = line.strip()
+ # An indented line is a continuation of the bullet above it (nested child, provenance,
+ # wrapped prose). It never participates in dedupe and is never dropped.
+ if stripped and line[0].isspace():
+ kept.append(line)
+ continue
is_bullet = bool(_RECALL_BULLET_RE.match(stripped))
# Any column-0 non-bullet line (heading, rule, paragraph) opens a fresh dedupe scope.
- if stripped and not line[0].isspace() and not is_bullet:
+ if stripped and not is_bullet:
seen.clear()
if is_bullet:
following = lines[index + 1] if index + 1 < len(lines) else ""
- indent = len(line) - len(line.lstrip())
- carries_continuation = bool(following.strip()) and (
- len(following) - len(following.lstrip())) > indent
+ carries_continuation = bool(following.strip()) and following[0].isspace()
if not carries_continuation:
if stripped in seen:
continue
diff --git a/tests/agent/test_memory_context_dedupe.py b/tests/agent/test_memory_context_dedupe.py
index 6ad7bf03e51..7b0a5b717fc 100644
--- a/tests/agent/test_memory_context_dedupe.py
+++ b/tests/agent/test_memory_context_dedupe.py
@@ -43,5 +43,7 @@ def test_a_bullet_with_continuation_lines_is_never_touched():
provenance under the other and invent a record neither provider reported."""
raw = ("- prefers draft PRs\n (logged 12 Jan, source: supermemory)\n"
"- prefers draft PRs\n (logged 3 Feb, source: builtin)\n")
+ nested = "- Project A\n - status: active\n- Project B\n - status: active\n"
assert _body(build_memory_context_block(raw)) == raw
+ assert _body(build_memory_context_block(nested)) == nested