Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions mempalace/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,22 +847,32 @@ def status(palace_path: str):
print(" Run: mempalace init <dir> then mempalace mine <dir>")
return

# Count by wing and room
# Count by wing and room. Paginate col.get() in 10K-drawer batches:
# a single col.get(limit=total) hits SQLite's SQLITE_MAX_VARIABLE_NUMBER
# (default 32,766) on palaces with many thousands of drawers — see #802,
# #1015. Pagination keeps each query under the variable cap.
total = col.count()
r = col.get(limit=total, include=["metadatas"]) if total else {"metadatas": []}
metas = r["metadatas"]

wing_rooms = defaultdict(lambda: defaultdict(int))
for m in metas:
m = m or {}
wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1
scanned = 0
batch = 10000
offset = 0
while offset < total:
r = col.get(limit=batch, offset=offset, include=["metadatas"])
metas = r.get("metadatas") or []
if not metas:
break
for m in metas:
m = m or {}
wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1
scanned += len(metas)
offset += len(metas)
Comment on lines +856 to +868
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

The new pagination/offset loop isn’t covered by tests. There are existing unit tests for status() in tests/test_miner.py, but none assert multi-page behavior (e.g., that col.get() is called with offset advancing and that results across pages are fully tallied). Please add a regression test using a fake collection with count() > batch and a get(limit, offset, ...) that returns deterministic slices, then assert the output totals match the full dataset and multiple get() calls occur.

Copilot uses AI. Check for mistakes.

print(f"\n{'=' * 55}")
print(f" MemPalace Status — {len(metas)} drawers")
print(f" MemPalace Status — {scanned:,} drawers")
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

The header prints scanned (rows successfully fetched) rather than total (from col.count()). If count() and paged get() ever disagree (concurrent deletes, backend truncation/bug), the command will silently under-report drawers. Consider printing total as the authoritative count, and if scanned != total emit a clear “partial” indicator (similar to how tool_status exposes partial).

Suggested change
print(f" MemPalace Status — {scanned:,} drawers")
print(f" MemPalace Status — {total:,} drawers")
if scanned != total:
print(f" partial: scanned {scanned:,} of {total:,} drawers")

Copilot uses AI. Check for mistakes.
print(f"{'=' * 55}\n")
for wing, rooms in sorted(wing_rooms.items()):
print(f" WING: {wing}")
for room, count in sorted(rooms.items(), key=lambda x: x[1], reverse=True):
print(f" ROOM: {room:20} {count:5} drawers")
print(f" ROOM: {room:20} {count:>8,} drawers")
print()
print(f"{'=' * 55}\n")
Loading