Skip to content

Python: [Bug]: Memory topic contributor session IDs change on reload #9197

Open

Description

@ktz03

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

  1. Create a file-backed memory store and a session with an owner key.
  2. Write a topic with one of the contributor lists above.
  3. 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.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 8, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 8, 2026
  3. github-actions commented on Oct 8, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: python/packages/core/agent_framework/_harness/_memory.py::MemoryTopicRecord.__init__, to_markdown, and from_markdown alter case-distinct, comma-containing, and literal-hyphen contributor IDs. The failures occur when these values pass through MemoryFileStore.write_topic() and get_topic(). Minimal repro: construct records with the issue’s four ID lists, persist and reload each through a temporary MemoryFileStore, then compare loaded.session_ids with the input.

    • Failing test: python/packages/core/tests/core/test_harness_memory.py::test_memory_file_store_preserves_contributor_session_ids
    • Files examined: python/packages/core/agent_framework/_harness/_memory.py, python/packages/core/tests/core/test_harness_memory.py, python/packages/core/pyproject.toml
    • Tests run: test_memory_topic_record_round_trips_through_dict_and_markdown, test_memory_file_store_preserves_contributor_session_ids
    • Reported version: 1.20.0
    • Current version: 1.21.0
  4. added
    harness[Issues, PRs], Target: harness-level items
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

harness[Issues, PRs], Target: harness-level itemspythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions