Skip to content

Commit b4087c7

Browse files
committed
fix(mem_reader): pass sources=[] explicitly when creating split chunk items
Dropping the sources kwarg entirely broke the _make_memory_item call-site contract: callers intercepting the keyword with a strict signature (e.g. the existing project-id propagation test whose fake requires sources=) fail, and the broad except in _split_large_memory_item turns the TypeError into a silent fall-back to the unsplit item, so large items stopped being chunked at all. Passing an explicit empty list keeps the #2453 no-duplication behaviour identical while restoring the stable kwarg contract. Also drop the vacuous no-parent-sources test case: with an empty parent sources list the old and new code both produced sources == [], so the assertion could never distinguish the bug from the fix. The non-vacuous test_split_chunks_do_not_carry_parent_sources already pins the invariant with a parent that does carry sources.
1 parent a213f5c commit b4087c7

2 files changed

Lines changed: 3 additions & 13 deletions

File tree

‎src/memos/mem_reader/multi_modal_struct.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def _create_chunk_item(chunk_idx: int, chunk):
160160
"chunk_total": chunk_total,
161161
}
162162
# Create a new memory item for each chunk, preserving original
163-
# metadata. We drop the parent's ``sources`` list deliberately:
164-
# the parent already carries those source messages, and chunks
163+
# metadata. We pass an empty ``sources`` list deliberately: the
164+
# parent already carries those source messages, and chunks
165165
# are *derived* fragments — not original messages — so they
166166
# should not multiply the full source list (issue #2453, which
167167
# produced N byte-identical ``SourceMessage`` copies per chunk
@@ -175,6 +175,7 @@ def _create_chunk_item(chunk_idx: int, chunk):
175175
memory_type=item.metadata.memory_type,
176176
tags=item.metadata.tags or [],
177177
key=item.metadata.key,
178+
sources=[],
178179
background=item.metadata.background or "",
179180
need_embed=False,
180181
)

‎tests/mem_reader/test_split_sources_no_duplication.py‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,6 @@ def test_split_chunks_preserve_provenance_via_internal_info(self):
109109
self.assertEqual(chunk.metadata.internal_info["chunk_total"], 2)
110110
self.assertIn("ingest_batch_id", chunk.metadata.internal_info)
111111

112-
def test_split_with_no_parent_sources_yields_no_sources(self):
113-
"""Sanity: a parent without sources still produces sources-less
114-
chunks (no spurious empty list creation)."""
115-
parent = _build_parent_item([])
116-
reader = _build_reader(["chunk 1"])
117-
118-
chunks = reader._split_large_memory_item(parent, max_tokens=512)
119-
120-
self.assertEqual(len(chunks), 1)
121-
self.assertEqual(chunks[0].metadata.sources, [])
122-
123112

124113
if __name__ == "__main__":
125114
unittest.main()

0 commit comments

Comments
 (0)