Skip to content

The agent that grows with you

fix(memory): any column-0 non-bullet line opens a new dedupe section

kshitijk4pooraf0305c95af4
diff --git a/agent/memory_manager.py b/agent/memory_manager.py
index 8835fa2b685..604e4f50b2e 100644
--- a/agent/memory_manager.py
+++ b/agent/memory_manager.py
@@ -277,8 +277,9 @@ def _drop_repeated_recall_lines(text: str) -> str:
into the user row's ``api_content`` sidecar and replayed verbatim on every later request for as
long as that row is in context, so each duplicate is paid once per turn, forever.
- The ``seen`` set is scoped per section — every heading or ``---`` separator starts a new one — so
- a repeat is only dropped when the SAME section already states it.
+ The ``seen`` set is scoped per section — every non-bullet line at column 0 (a heading of any
+ style, a ``---`` rule, prose) starts a new one — so a repeat is only dropped when the SAME
+ section already states it.
Only a SELF-CONTAINED bullet is considered — a marker, whitespace, content, and no continuation
line indented beneath it. A bullet that carries continuation lines is never dropped and never
@@ -293,11 +294,12 @@ def _drop_repeated_recall_lines(text: str) -> str:
kept: list[str] = []
for index, line in enumerate(lines):
stripped = line.strip()
- # Dedupe is scoped per section: a heading (``## …`` / ``**…**``) or a ``---`` separator opens a
- # fresh scope. Without it, identical placeholder bullets under different headings
- # (``- (none recorded)`` twice) collapse into the first section and the second heading is left
- # claiming nothing.
- if stripped.startswith("#") or stripped.startswith("**") or stripped == "---":
+ # Dedupe is scoped per section: any non-bullet line at column 0 — a ``## …`` / ``**…**`` /
+ # ``Profile:`` prose heading, a ``---`` rule, a paragraph — opens a fresh scope. Only bullets
+ # and indented continuation lines stay inside the current one. Without it, identical
+ # placeholder bullets under different headings (``- (none recorded)`` twice) collapse into
+ # the first section and the second heading is left claiming nothing.
+ if stripped and not line[0].isspace() and not _RECALL_BULLET_RE.match(stripped):
seen.clear()
if _RECALL_BULLET_RE.match(stripped):
following = lines[index + 1] if index + 1 < len(lines) else ""
diff --git a/tests/agent/test_memory_context_dedupe.py b/tests/agent/test_memory_context_dedupe.py
index c78c5f58caf..6771d3f9c53 100644
--- a/tests/agent/test_memory_context_dedupe.py
+++ b/tests/agent/test_memory_context_dedupe.py
@@ -35,3 +35,15 @@ def test_a_bullet_with_continuation_lines_is_never_touched():
"- prefers draft PRs\n (logged 3 Feb, source: builtin)\n")
assert _body(build_memory_context_block(raw)) == raw
+
+
+def test_identical_placeholder_bullets_under_different_headings_both_survive():
+ """A section is delimited by a heading of ANY style. RetainDB writes prose headings
+ (``Profile:`` / ``Relevant memories:``); other providers write markdown ones. In both shapes a
+ placeholder bullet repeated under the second heading belongs to that heading and must stay, or
+ the heading is left claiming nothing."""
+ prose = "Profile:\n- None\nRelevant memories:\n- None\n"
+ markdown = "## A\n- (none recorded)\n\n## B\n- (none recorded)\n"
+
+ assert _body(build_memory_context_block(prose)) == prose
+ assert _body(build_memory_context_block(markdown)) == markdown