Skip to content

Python: fix(core): give each file memory its own description sidecar - #8621

Open
Anish Mehta (anishmehta24) wants to merge 1 commit into
microsoft:mainfrom
anishmehta24:fix/file-memory-description-sidecar-collision
Open

Anish Mehta (anishmehta24) wants to merge 1 commit into
microsoft:mainfrom
anishmehta24:fix/file-memory-description-sidecar-collision

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Motivation & Context

FileMemoryProvider named the description sidecar by replacing the file's extension, so notes.md and notes.json both mapped to notes_description.md. Writing one of them without a description deleted the other's description, writing one with a description made file_memory_ls and memories.md show it for both, and file_memory_delete on a file that did not exist still removed the sidecar. Repro and output are in the linked issue.

Description & Review Guide

  • What are the major changes?
    • _description_file_name now appends the suffix to the whole name (notes.mdnotes.md_description.md), so files that differ only by extension no longer share a sidecar. _is_internal_file is unchanged; the new names still end in _description.md and stay hidden.
    • _legacy_description_file_name keeps the old extension-replacing name. _read_description (used by file_memory_ls and _rebuild_index) prefers the current sidecar and falls back to the legacy one, so descriptions written by earlier versions keep showing up.
    • _delete_description removes the current sidecar and removes the legacy one only when no other remaining memory file still maps to it (_legacy_sidecar_is_shared), since under the old scheme that sidecar may belong to a sibling.
    • file_memory_delete only touches sidecars and rebuilds the index when the file was actually deleted; a "not found" delete is now side-effect free.
  • What is the impact of these changes?
    • New descriptions are written under the new name. Existing stores keep working: legacy sidecars are read until a new description replaces them and are cleaned up when their last owner is deleted.
    • The .NET FileMemoryProvider (GetDescriptionFileName) uses the same extension-replacing scheme and has the same collision; this PR only changes Python. Happy to do the .NET side as a follow-up if you want the layouts to match.
  • What do you want reviewers to focus on?
    • Whether keeping the legacy read/cleanup path is wanted, or whether you would rather drop it and accept that pre-1.20 descriptions are no longer surfaced.

Tests: test_description_file_name_keeps_extension, test_legacy_description_file_name_replaces_extension, test_legacy_sidecar_is_shared_only_with_other_visible_files, test_files_differing_only_by_extension_keep_separate_descriptions (the three symptoms from the issue), test_legacy_description_sidecar_is_still_read_and_cleaned_up; existing sidecar tests updated to the new name. test_harness_file_memory.py: 39 passed. poe fmt, poe lint, poe typing -P core clean.

Related Issue

Fixes #8620

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • 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. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

🤖 Generated with Claude Code

The description sidecar replaced the extension, so `notes.md` and
`notes.json` shared `notes_description.md`: writing one without a
description deleted the other's, writing one with a description showed
it on both, and deleting a missing file removed the sidecar anyway.

Keep the extension in the sidecar name (`notes.md_description.md`), keep
reading legacy `notes_description.md` sidecars so existing descriptions
survive, only remove the legacy sidecar once no file maps to it, and only
touch sidecars when the file itself was deleted.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 21, 2026
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.

.NET: Python: [Bug]: FileMemoryProvider description sidecars collide for files that differ only by extension

2 participants