Mining a known source that shrinks below min_chunk_size leaves its old drawers searchable
What happened?
When a source file that was already mined shrinks below min_chunk_size (default 50 characters), the next mine run skips it before the per-source lock and the drawer/closet purge. Its old drawers and closets stay stored, and search keeps returning the obsolete content.
sync --apply does not clean this up either, because it keeps the shortened file as kept.
What did you expect?
The second mine run removes the source's old drawers and closets. A source that is now too short creates no replacement drawers, so a search for the old content returns nothing.
How to reproduce:
- Create a text file longer than 50 characters that contains a unique sentinel such as
OLD_SENTINEL, and mine it in project mode. - Confirm that a search finds
OLD_SENTINEL. - Replace the file contents with a string shorter than 50 characters (e.g.
short) and mine the same project again. - Search for
OLD_SENTINELagain: it is still found.
Root cause
In mempalace/miner.py, process_file() returns early for content shorter than min_chunk_size:
content = content.strip()
if len(content) < effective_min:
return 0, "general", NoneThis happens before with mine_lock(source_file): and the stale-drawer / purge_file_closets path, so a known source that shrank is never purged. Still present on main at 8c4865f (lines ~1886–1888 vs. the lock/purge block below).
Proposed fix
Drop the early return and let short files take the normal lock/purge path. chunk_text() already honors min_chunk_size, so it returns no chunks; the purge removes the stale entries and no new drawers are written. Newly encountered short files still create no drawers.
- effective_min = min_chunk_size if min_chunk_size is not None else MIN_CHUNK_SIZE
-
# Skip if already filed
@@
content = content.strip()
- if len(content) < effective_min:
- return 0, "general", None
+ # Keep too-short files on the normal lock/purge path: chunk_text() returns
+ # no chunks, which removes stale drawers/closets after a source shrinks.
+ # The caller still counts this zero-drawer outcome under "Files skipped".Verification (local repro script against 3.10.0)
| Case | Check | Without patch | With patch |
|---|---|---|---|
| 1 | Long file contains OLD_SENTINEL after mining |
PASS | PASS |
| 2 | Shrinking below 50 characters removes old drawers and closets | FAIL | PASS |
| 3 | Re-expanded file contains only NEW_SENTINEL |
PASS | PASS |
| 4 | A new short file creates no drawers | PASS | PASS |
| 5 | The exact 49/50-character boundary is honored | PASS | PASS |
Happy to open a PR with the change and a regression test if that helps.
Environment:
- OS: Windows 11
- Python version: 3.14
- MemPal version: 3.10.0 (bug also present on
mainat 8c4865f); project mode,minilmembeddings
Source: MemPalace/mempalace