Repository navigation
Description
Observed Behavior
consolidate_memories accepts a valid JSON response whose memories array contains a string with an ordinary line break and returns {"consolidated_topics": 1}. A fresh MemoryFileStore then returns only the first line of that memory.
For example, the supplied memory is Deploy staging.\nThen deploy production., but a fresh read returns ['Deploy staging.']. The continuation is still present in the raw Markdown file immediately after consolidation; it is omitted by the record parser. This report concerns that parsed-memory discrepancy, not a model-quality result or a general storage-loss claim.
The same string through the public write_memory tool retains both sentences by normalizing whitespace. A single-line consolidation result round-trips normally. The default consolidation prompt asks for strings in a memories array and does not prohibit line breaks.
Expected Behavior
A successful consolidation should not silently omit part of an accepted memory when the file is read again. Either preserve all of the memory text, normalize it to the existing single-line representation, or reject unsupported formatting while preserving the previous record.
Steps to Reproduce
- Create a
MemoryFileStoreandMemoryContextProviderwith the deterministic offline client below. - Write a normal memory using the provider's public tool.
- Consolidate with one valid JSON memory containing LF or CRLF.
- Open a fresh store and compare the memory with the supplied text. The single-line case is a normal control.
Minimal Reproduction
The client returns an actual SDK ChatResponse; there are no private provider calls, network requests or model calls.
import asyncio
import json
import tempfile
from agent_framework import (
AgentSession, ChatResponse, MemoryContextProvider, MemoryFileStore,
Message, SessionContext,
)
class OfflineClient:
def __init__(self, memory):
self.memory = memory
async def get_response(self, messages, **kwargs):
result = {"summary": "Deployment", "memories": [self.memory]}
return ChatResponse(messages=[Message(role="assistant", contents=[json.dumps(result)])])
async def reproduce(memory):
with tempfile.TemporaryDirectory() as directory:
session = AgentSession(session_id="example")
session.state["owner"] = "example-owner"
store = MemoryFileStore(directory, owner_state_key="owner")
provider = MemoryContextProvider(
store=store, recent_turns=0, max_extractions=0,
consolidation_client=OfflineClient(memory),
)
context = SessionContext(session_id=session.session_id, input_messages=[])
await provider.before_run(agent=None, session=session, context=context, state={})
tools = {tool.name: tool for tool in context.tools}
await tools["write_memory"].invoke(
arguments={"topic": "Deployment", "memory": "Deploy staging then production."},
skip_parsing=True,
)
response = await tools["consolidate_memories"].invoke(arguments={}, skip_parsing=True)
fresh = MemoryFileStore(directory, owner_state_key="owner").get_topic(
session, source_id="memory", topic="Deployment"
)
print({"input": memory, "result": response, "reloaded": fresh.memories})
async def main():
await reproduce("Deploy staging then production.")
await reproduce("Deploy staging.\nThen deploy production.")
await reproduce("Deploy staging.\r\nThen deploy production.")
asyncio.run(main())Observed output, with the experimental warning retained:
single-line: result={"consolidated_topics": 1}; reloaded=['Deploy staging then production.']
LF: result={"consolidated_topics": 1}; reloaded=['Deploy staging.']
CRLF: result={"consolidated_topics": 1}; reloaded=['Deploy staging.']
Package Versions
agent-framework-core source at current main 2d9cc3f8ae465baf1aed3022f89b6848db4ffa7b (pyproject.toml version 1.21.0). All 84 checked package Python files match that commit's Git blobs. The cached dependency environment reports Core 1.20.0 metadata; the imported executable source is the verified main source. No fresh workspace-lock installation or full core-suite claim.
Python Version
Python 3.14.3.
Operating System
Windows.
Regression
Unknown.
Additional Context
The original memory harness and Markdown format belong to #5613. Its review already called for heading-marker round-trip preservation; this observation uses an ordinary continuation line and the accepted consolidation response path. #9078/#9079 concern summary text resembling metadata; #9153 and #9205/#9227 concern topic identity; #9218 concerns consolidation scheduling markers. Their existing scope and authorship are preserved.
Public provider/store/tool controls covered single lines, ordinary LF/CRLF continuations, list continuations and heading controls. A separate independent check confirms LF/CRLF omissions and normal single-line, two-item, list and Unicode controls. Matrices overlap and are not added. No product patch, live model, remote store, other operating system or performance validation.
Please confirm the desired single-line normalization or unsupported-format handling before implementation. This report does not propose a new file format or attempt to reconstruct already omitted content.
AI Assistance
AI-assisted analysis, reproduction, and writing.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
- I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Oct 9, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
Repro:
python/packages/core/agent_framework/_harness/_memory.py::MemoryTopicRecord.to_markdown/from_markdownloses continuation lines whenMemoryContextProvider._consolidate_topicaccepts a memory string containing LF or CRLF. Minimal repro: consolidate an existing topic withmemories=["Deploy staging.\nThen deploy production."], confirm{"consolidated_topics": 1}, then read it through a freshMemoryFileStore; onlyDeploy staging.is returned.python/packages/core/tests/core/test_harness_memory.py::test_memory_consolidation_round_trips_multiline_memories1.21.01.21.0he-yufeng commentedon Oct 9, 2026
Reproduced on current main (65a12f9, core 1.21.0). The write path already normalizes:
_merge_memoryruns every memory through_normalize_memory_text, sowrite_memorynever persists a line break. The consolidation path skips that step:_consolidate_topicpasses the LLM'smemoriesstrings straight intoMemoryTopicRecord,to_markdownwrites the break verbatim as a non-bullet line, andfrom_markdownonly reads-bullets, so the continuation vanishes on the next load while the raw file still shows it.I'd like to take this. Proposed fix: normalize memories in
MemoryTopicRecord.__init__with the same_normalize_memory_textthe write path uses (keeping the current drop-empty tolerance), so single-line memories become a record invariant and the markdown round-trip is stable by construction. That covers consolidation, extraction, and any future JSON-sourced path at once, matching thewrite_memorybehavior you noted as the reference. Regression coverage: LF and CRLF consolidation memories read back intact (normalized) through a fresh store, plus a record-level markdown round-trip.he-yufeng commentedon Oct 10, 2026
This is exactly what #9240 fixes:
to_markdownwrote the line break verbatim as a non-bullet line, and the reload path only collected bullet items, so everything after the first break was dropped. The PR makes multi-line memory strings survive the round trip; verified with the same fresh-store reload scenario.eavanvalkenburg commentedon Nov 3, 2026
/plan Settle the smallest complete repair for accepted consolidation memory continuation text disappearing on fresh reload, with owner westey-m and existing #9240 rather than competing implementation. Main consolidate_memories accepts LF/CRLF strings and reports success, but the Markdown parser collects only bullet lines; ordinary write_memory already normalizes. This is parsed-memory fidelity, not general deletion or model quality. Current #9240 normalizes every MemoryTopicRecord constructor and the author reports legacy bare-line folding in 51fe190; verify that candidate rather than repeat the older legacy-omission finding as unfixed. Compare narrow producer normalization with a public record-wide single-line invariant: settle whether collapsing all whitespace/deduplicating constructor inputs changes previously supported direct-record values, and how already-written ordinary continuations are handled without swallowing headings/metadata. Coordinate the shared #9727/#9725 escaped-marker/placeholder format plan, but do not assume that distinct plan already approves this constructor/parser policy or introduce a parallel format migration. Cover public deterministic consolidation plus fresh-store LF/CRLF/list/heading/Unicode/empty controls, raw legacy disk input, ordinary single-line/whitespace stability and unchanged write_memory behavior. Estimate executable runtime lines excluding docs/tests; a small diff is not implementation-ready while representation/legacy compatibility remains unresolved. No new ready label or assignment is implied.
eavanvalkenburg commentedon Nov 12, 2026
/plan Settle the smallest complete repair for accepted consolidation memory continuation text disappearing on fresh reload, with owner westey-m and existing #9240 rather than competing implementation. Main consolidate_memories accepts LF/CRLF strings and reports success, but the Markdown parser collects only bullet lines; ordinary write_memory already normalizes. This is parsed-memory fidelity, not general deletion or model quality. Current #9240 normalizes every MemoryTopicRecord constructor and the author reports legacy bare-line folding in 51fe190; verify that candidate rather than repeat the older legacy-omission finding as unfixed. Compare narrow producer normalization with a public record-wide single-line invariant: settle whether collapsing all whitespace/deduplicating constructor inputs changes previously supported direct-record values, and how already-written ordinary continuations are handled without swallowing headings/metadata. Coordinate the shared #9727/#9725 escaped-marker/placeholder format plan, but do not assume that distinct plan already approves this constructor/parser policy or introduce a parallel format migration. Cover public deterministic consolidation plus fresh-store LF/CRLF/list/heading/Unicode/empty controls, raw legacy disk input, ordinary single-line/whitespace stability and unchanged write_memory behavior. Estimate executable runtime lines excluding docs/tests; a small diff is not implementation-ready while representation/legacy compatibility remains unresolved. No new ready label or assignment is implied.
github-actions commentedon Nov 12, 2026
Summary
consolidate_memoriesaccepts a model-supplied memory string that contains a line break and reports success. The file writer then emits the break as a plain line. The file reader only keeps lines that start with-, so the continuation is lost on the next fresh load. Ordinarywrite_memorydoes not have this problem because it collapses whitespace first. This is about fidelity of parsed memories, not general deletion or model quality.Evidence (current
main, read-only):_normalize_memory_textcollapses all whitespace and rejects empty text. It is called only from_merge_memory(thewrite_memorypath)._memory.pyL105_consolidate_topicpasses model strings straight intoMemoryTopicRecord(...). L1707-L1790MemoryTopicRecordconstructor runs_dedupe_strings, which onlystrip()s the ends and dedupes bycasefold(). It does not touch inner newlines. L138from_markdownappends a memory only for-lines in the Memories section. Any other line there is silently ignored. L420-L480_coerce_summary, so only memories are affected.What I could not check
I did not read the open PR #9240 or commit
51fe190b9, per this workflow's rules. I therefore cannot confirm that the candidate's legacy folding works. That has to be verified by running it against the test list below. I could not find the #9727/#9725 plans through search, so I did not rely on them.Recommendation
Code change, small, in
_memory.py. The bug is real and confined to one module. There is no workaround except asking the model for single-line strings, and the default prompt does not forbid line breaks.Producer-only vs record-wide. Normalizing only in
_consolidate_topicfixes the reported path. It leavesfrom_dict, extraction and any directMemoryTopicRecord(memories=["a\nb"])writing a file that cannot be read back. A record-wide rule closes all of those.Settled constraint: the record-wide rule should NOT reuse
_normalize_memory_text(collapse all whitespace). That would change values that round-trip today. For example"a b"or a tab-separated memory is stored and reloaded unchanged now. Collapsing also makes"a b"and"a b"count as duplicates, which they are not today. Memories containing a line break never round-tripped, so changing them is not a regression.Preferred invariant: in the constructor only, replace line breaks with a single space. Use
splitlines()(the same splitterfrom_markdownuses, so it covers\r,\x85,\u2028and similar), strip each piece, drop empty pieces, and join with a space. Keep inner spacing and the existing empty-drop and casefold-dedupe behavior. Single-line, whitespace and Unicode values stay identical.write_memoryis unchanged.Legacy files (already-written continuations). Normalization cannot repair files that already have bare continuation lines. A small reader change can: in the Memories section, a non-empty line that is not
--prefixed folds into the previous memory with a space. Limits needed so it does not swallow structure:#,## Summary,## Memories, and any line before the first bullet (nothing to attach to).Updated:/Sessions:checks already only apply before any section, so those lines inside Memories are treated as text.-cannot be told apart from a new bullet, so it stays a separate memory. Document this as an accepted limit.#-leading lines is unchanged, so no new marker or file format is introduced. Anything beyond this (escaped markers, placeholder text) belongs to the Python: memory lines starting with backslash hash gain a backslash on every round trip #9727/Python: a memory whose text equals the none yet placeholder is silently dropped on read #9725 plan. This change should not assume that plan approves it, and it needs no migration.Runtime size estimate (no tests/docs): about 5-8 lines for the constructor line-break join, plus about 6-10 for the reader fold. Roughly 12-18 lines total. The constructor part alone is about 4-6. Because the legacy fold changes how existing files are read, I would settle the points above before calling it ready. I am not applying any label or assignment.
Proposed plan (proposal only; nothing has been changed)
Add a private helper in
_memory.pythat joinssplitlines()pieces with a space, drops empties, and leaves other whitespace alone. Use it in_dedupe_stringsfor memories only (not session ids), or in theMemoryTopicRecordconstructor before dedupe.Update
from_markdownto fold bare continuation lines into the previous bullet, with the limits above.Leave
_merge_memory,_normalize_memory_text,to_markdownescaping, topic and summary handling unchanged.Tests in
test_harness_memory.py:\r, list-marker (- x\n- y), heading-like (ok\n# Title,## Memories) and Unicode (\u2028, non-ASCII) input. Read back through a freshMemoryFileStore. Expect one normalized line each.Updated:, a blank line, and a stray line before the first bullet. Check which fold and which do not.write_memoryoutput is byte-identical to today.Success means the issue's LF/CRLF repro reloads as
Deploy staging. Then deploy production., the control cases are unchanged, and Python: fix(core): stop losing multiline consolidated memories on reload #9240's behavior matches or the differences are noted on that PR.Questions for the owner (westey (@westey-m))
write_memoryparity (collapse everything)? The latter changes today's round-trip for inner double spaces.--leading continuation limit?westey-m commentedon Nov 12, 2026
This feature is being deprecated in favor of FileMemoryProvider. See #10273.
Therefore closing this issue as won't fix.