Repository navigation
Python: [Bug]: Memory topic contributor session IDs change on reload #9197
Description
Observed Behavior
Memory topic contributor IDs are changed or lost when saving and reloading a topic:
IDs supplied to MemoryTopicRecord |
IDs returned by MemoryFileStore.get_topic() |
|---|---|
['session-a', 'session-b'] |
['session-a', 'session-b'] |
['Run-A', 'run-a'] |
['Run-A'] |
['conversation,1'] |
['conversation', '1'] |
['-'] |
[] |
AgentSession accepts these IDs and FileHistoryProvider saves and loads the corresponding transcript under the exact original ID. The public write_memory tool reproduces the same changes without constructing a record directly. A later MemoryContextProvider.before_run() consequently reports missing or altered contributor IDs in the loaded memory metadata.
Expected Behavior
Distinct session IDs retain their exact spelling and round-trip as distinct values. Repeated identical IDs remain deduplicated in first-seen order. Ordinary short IDs and existing memory text should retain their behavior.
Steps to Reproduce
- Create a file-backed memory store and a session with an owner key.
- Write a topic with one of the contributor lists above.
- Reload the topic and compare its contributor list with the original list.
Minimal Reproduction
from tempfile import TemporaryDirectory
from agent_framework import AgentSession, MemoryFileStore, MemoryTopicRecord
for ids in (["session-a", "session-b"], ["Run-A", "run-a"], ["conversation,1"], ["-"]):
with TemporaryDirectory() as directory:
store = MemoryFileStore(directory, owner_state_key="owner")
session = AgentSession(session_id="reader")
session.state["owner"] = "local-owner"
record = MemoryTopicRecord(
topic="Preferences",
summary="Preferences on editor themes",
memories=["Prefer light editor theme"],
updated_at="2026-10-08T00:00:00+00:00",
session_ids=ids,
)
store.write_topic(session, record, source_id="memory")
loaded = store.get_topic(session, source_id="memory", topic="Preferences")
print(ids, "->", loaded.session_ids)Error Messages and Stack Traces
No exception is raised; the contributor list changes silently as shown above.
Package Versions
The reproduction executed the complete tracked public core package from ca936db37708539bd502240a48543f6094259ce5 (core source version 1.20.0), with cached dependencies. Current main 91ab44faa4824a30247d00c341f3498ba46b1ca3 has the identical core package source. Within this package scope, pyproject.toml changes the version to 1.21.0 and raises optional all extra package requirements; base dependency requirements are unchanged. A fresh install of the 1.21.0 dependency set or optional all extra has not been tested.
Python Version
Python 3.14.3
Operating System
Windows
Regression
Unknown
Additional Context
The constructor currently reuses case-insensitive memory-text deduplication for session IDs. The Markdown writer joins IDs with commas and uses - for the empty list; the reader splits by comma and interprets - as empty. A correction needs to preserve existing records while defining a reversible representation for literal IDs; an old comma-joined record alone cannot distinguish one literal comma-containing ID from two IDs.
Related changes have distinct scopes: #7041 supplies aggregate contributor IDs to context messages; #9079 preserves metadata-looking summary text; #9153 preserves custom topic filenames. This report concerns contributor ID deduplication and persistence. No product patch has been implemented. Please confirm the desired compatibility approach before implementation.
AI Assistance
AI-assisted issue analysis and reproduction tests.
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 fieldsNo status
Activity
github-actions commentedon Oct 8, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
Repro:
python/packages/core/agent_framework/_harness/_memory.py::MemoryTopicRecord.__init__,to_markdown, andfrom_markdownalter case-distinct, comma-containing, and literal-hyphen contributor IDs. The failures occur when these values pass throughMemoryFileStore.write_topic()andget_topic(). Minimal repro: construct records with the issue’s four ID lists, persist and reload each through a temporaryMemoryFileStore, then compareloaded.session_idswith the input.python/packages/core/tests/core/test_harness_memory.py::test_memory_file_store_preserves_contributor_session_ids1.20.01.21.0