Skip to content

Python: preserve custom memory topic slugs on reload - #9153

Open
Kunyan (Kunyanli230) wants to merge 1 commit into
microsoft:mainfrom
Kunyanli230:fix/memory-topic-slug
Open

Kunyan (Kunyanli230) wants to merge 1 commit into
microsoft:mainfrom
Kunyanli230:fix/memory-topic-slug

Conversation

@Kunyanli230

@Kunyanli230 Kunyan (Kunyanli230) commented Oct 7, 2026 •

Copy link
Copy Markdown

Motivation & Context

A memory topic with topic="Preferred Tools" and slug="tools" is saved as tools.md, but reloading it derives preferred-tools from the heading. The rebuilt index then points to a missing file, and MemoryContextProvider.before_run() raises FileNotFoundError when selecting the memory.

Description & Review Guide

  • What are the major changes? Restore the slug from the filename in both file-store read paths. Add round-trip, write-back, and context-loading regressions.
  • What is the impact of these changes? Custom topic filenames keep their identity after a reload. Default slugs, the Markdown format, and public signatures are unchanged.
  • What do you want reviewers to focus on? Both read paths and the index entry used by the context provider, including normalized custom slugs and write-back without duplicate topics.

Three of the four regression cases fail on the base revision; all four pass with the fix. The full core unit suite passed 8,385 tests (21 skipped, 2 xfailed, 46 warnings). Source Pyright, all five test type checkers, Ruff, formatting, pre-commit hooks, and the core sdist/wheel build passed. Integration tests were not run.

Related Issue

Pending a tracking issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible (affected core package)
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation correctly preserves filename identity and includes appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Preserves custom memory topic slugs when file-backed records are reloaded.

Changes:

  • Restores topic slugs from filenames during reads.
  • Adds reload, update, indexing, and context-injection coverage.
File Description
python/​packages/​core/​agent_framework/​_harness/​_memory.py Derives reloaded record slugs from file stems.
python/​packages/​core/​tests/​core/​test_harness_memory.py Tests custom-slug persistence and loading.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@Kunyanli230

Copy link
Copy Markdown
Author

Kunyan (Kunyan (@Kunyanli230)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

This branch was successfully deployed

1 active deployment
github-app-auth — 694ce8a3 Deployed Oct 7, 2026 by Kunyanli230 via add_label #24657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants