fix: release Chroma handles before migrate swap on Windows#890
Open
fuzzymoomoo wants to merge 1 commit intoMemPalace:developfrom
Open
fix: release Chroma handles before migrate swap on Windows#890fuzzymoomoo wants to merge 1 commit intoMemPalace:developfrom
fuzzymoomoo wants to merge 1 commit intoMemPalace:developfrom
Conversation
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a Windows-specific
mempalace migratefailure where the final palace swap can raisePermissionError: [WinError 32]onchroma.sqlite3even after the import finished successfully.Root cause
migrate()was importing drawers into a fresh palace and then immediately callingshutil.rmtree(palace_path).On Windows, Chroma-backed clients can keep SQLite handles alive longer than plain object deletion suggests. In the current codebase, those handles can sit behind:
ChromaCollection_clientscacheThat means the migrate path can successfully import everything and still fail at the last filesystem step.
Changes
_release_chroma_handles()to stop/clear best-effort Chroma client state before directory replacement_clients) as well as wrapped collection/client objects_replace_palace_dir()with bounded retry onPermissionErrortests/test_migrate.pyto match the currentChromaBackendpathWhy this is scoped this way
This keeps the fix local to
migrate.pyrather than changing backend lifecycle semantics for the whole app.That felt like the safest way to land a real Windows fix quickly while staying aligned with the current architecture.
Validation
Local targeted checks:
python -m pytest tests/test_migrate.py -qpython -m ruff check mempalace/migrate.py tests/test_migrate.pyReal Windows reproduction / rerun:
python -m mempalace.cli --palace C:\Users\fuzzy\.mempalace\palace-upgrade-eval migrate --yesstatuson the migrated copy reports all 16,468 drawers correctlyRelated context
This is in the same family as other Windows Chroma handle issues already seen in the repo, but I did not find an open PR specifically fixing the migrate swap path.
Related prior Windows handle discussions / fixes: