Skip to content

feat: palace maintenance — junk filter, purge, status pagination, repair (#478 #586 #587 #581) - #627

Closed
jphein wants to merge 1 commit into
MemPalace:mainfrom
techempower-org:pr/palace-maintenance
Closed

feat: palace maintenance — junk filter, purge, status pagination, repair (#478 #586 #587 #581)#627
jphein wants to merge 1 commit into
MemPalace:mainfrom
techempower-org:pr/palace-maintenance

Conversation

@jphein

@jphein jphein commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Palace maintenance features split from #562 per maintainer request.

Test plan

  • Mine with junk files present, verify they're skipped
  • Dry-run on directory with unreadable files, verify no crash
  • Status on palace with >10K drawers, verify correct count
  • Purge by wing, verify remaining drawers are intact
  • Repair on corrupted palace, verify clean rebuild

🤖 Generated with Claude Code

…air fix, chromadb upgrade

- Add SKIP_PATTERNS and JUNK_FILE_SIZE to filter noise during mining (MemPalace#587)
- Fix dry-run room=None crash with fallback to 'general' (MemPalace#586)
- Fix status 10K ceiling with paginated offset loop (MemPalace#478)
- Add mempalace purge command for targeted drawer removal
- Fix repair to nuke palace dir for clean HNSW index rebuild
- Upgrade chromadb pin to >=1.5.4 (MemPalace#581)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 14:10

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.

Pull request overview

This PR adds “palace maintenance” improvements to MemPalace: filtering low-value junk files during mining, fixing --dry-run room counting, making status reporting accurate for large palaces via pagination, introducing a selective purge command that rebuilds the index, improving repair by fully nuking/recreating the palace directory, and upgrading ChromaDB for Python 3.13/3.14 compatibility.

Changes:

  • Upgrade ChromaDB dependency to chromadb>=1.5.4,<2.
  • Add scan-time junk filtering (suffix patterns + 500KB “junk” size cutoff) and fix dry-run room counting.
  • Implement paginated status counting and add mempalace purge plus a safer repair rebuild strategy.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
pyproject.toml Bumps ChromaDB to >=1.5.4,<2 to restore compatibility with newer Python versions.
mempalace/miner.py Adds junk file filters, fixes dry-run room=None counting, and paginates status metadata fetching.
mempalace/cli.py Introduces purge subcommand and updates repair to rebuild by deleting/recreating the palace directory and re-inserting drawers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mempalace/cli.py
Comment on lines +251 to +254
palace_path = palace_path.rstrip(os.sep)
print(" Rebuilding palace...")
shutil.rmtree(palace_path)
os.makedirs(palace_path, mode=0o700)

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

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

palace_path.rstrip(os.sep) can turn dangerous inputs into unexpected targets (e.g., Windows C:\\C:), and then shutil.rmtree(palace_path) will delete the wrong directory or fail in surprising ways. Consider normalizing with os.path.normpath()/Path(...).resolve() and explicitly refusing root/drive-root/empty paths before deleting; also surface the resolved path in the confirmation prompt.

Copilot uses AI. Check for mistakes.
Comment thread mempalace/cli.py
Comment on lines 336 to 340
palace_path = palace_path.rstrip(os.sep)
backup_path = palace_path + ".backup"
if os.path.exists(backup_path):
shutil.rmtree(backup_path)
print(f" Backing up to {backup_path}...")

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

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

palace_path = palace_path.rstrip(os.sep) is now used on the destructive delete path later in this function; on Windows this can collapse C:\\ into C: (drive-relative) and on some inputs can produce an empty/unsafe path. Use a safer normalization (e.g., os.path.normpath / Path.resolve) and add guards to prevent deleting anything that isn’t a dedicated palace directory.

Copilot uses AI. Check for mistakes.
Comment thread mempalace/cli.py
Comment on lines +200 to +208
# Count matching drawers
match_ids = set()
offset = 0
while True:
batch = col.get(limit=10000, offset=offset, where=where, include=[])
if not batch["ids"]:
break
match_ids.update(batch["ids"])
offset += len(batch["ids"])

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

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

Building match_ids as an in-memory set of every matching drawer can be very large for big palaces and can double the total scan work (first to collect IDs, then to re-scan everything to extract keepers). Since you already fetch metadatas during extraction, you can decide “purge vs keep” based on wing/room directly and avoid storing all IDs (and potentially avoid the first pass by counting matches from metadatas only).

Copilot uses AI. Check for mistakes.
Comment thread mempalace/cli.py
Comment on lines 690 to 733
@@ -585,6 +727,7 @@ def main():
"wake-up": cmd_wakeup,
"repair": cmd_repair,
"migrate": cmd_migrate,
"purge": cmd_purge,
"status": cmd_status,
}
dispatch[args.command](args)

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

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

The new purge subcommand is added to argparse/dispatch, but there’s no corresponding CLI test coverage (e.g., main dispatches purge, and cmd_purge resolves palace path / validates args / prompts as expected). Adding a minimal tests/test_cli.py case similar to the existing test_main_*_dispatches tests would prevent regressions.

Copilot uses AI. Check for mistakes.
Comment thread mempalace/miner.py
Comment on lines 535 to 553
@@ -524,7 +545,11 @@ def scan_project(
continue
# Skip files exceeding size limit
try:
if filepath.stat().st_size > MAX_FILE_SIZE:
fsize = filepath.stat().st_size
if fsize > MAX_FILE_SIZE:
continue
# Skip suspiciously large text files (SQL dumps, generated JSON, etc.)
if not force_include and fsize > JUNK_FILE_SIZE:
continue

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

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

scan_project() now skips additional suffix-based junk files (SKIP_PATTERNS) and skips files over JUNK_FILE_SIZE unless explicitly included. There are already detailed scan_project tests in tests/test_miner.py, but none cover these new filters or the include-override behavior; adding tests would lock in the intended behavior and avoid surprises/regressions.

Copilot uses AI. Check for mistakes.
@jphein jphein closed this Apr 11, 2026
@jphein
jphein deleted the pr/palace-maintenance branch April 11, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants