Skip to content

mempalace status crashes on palaces >~32K drawers (SQLite variable limit) #1015

@eldar702

Description

@eldar702

Summary

mempalace status (any version that ships the current miner.py::status) fails with an uncaught Chroma InternalError on any palace that has more than ~32,766 drawers.

Symptom

$ mempalace status
Traceback (most recent call last):
  File ".../mempalace", line 7, in <module>
    sys.exit(main())
  File ".../mempalace/cli.py", line 681, in main
    dispatch[args.command](args)
  File ".../mempalace/cli.py", line 217, in cmd_status
    status(palace_path=palace_path)
  File ".../mempalace/miner.py", line 844, in status
    r = col.get(limit=total, include=["metadatas"]) if total else {"metadatas": []}
  File ".../mempalace/backends/chroma.py", line 65, in get
    return self._collection.get(**kwargs)
  File ".../chromadb/api/models/Collection.py", line 161, in get
    get_results = self._client._get(...)
  File ".../chromadb/api/rust.py", line 440, in _get
    rust_response = self.bindings.get(...)
chromadb.errors.InternalError: Error executing plan:
  Internal error: error returned from database:
  (code: 1) too many SQL variables

Exit code: 1.

Root cause

miner.py::status() calls:

total = col.count()
r = col.get(limit=total, include=["metadatas"]) if total else {"metadatas": []}

Chroma's backend issues a SQL statement whose host-parameter count grows with the limit. Once the limit exceeds SQLite's default SQLITE_MAX_VARIABLE_NUMBER (32766 on most standard SQLite builds), SQLite refuses the statement and Chroma surfaces InternalError: too many SQL variables.

The inflection point is exactly 32766: limits up to and including 32766 succeed; 32767+ fail.

Reproducer

On any environment with a palace that has more than 32 766 drawers — which is roughly what you get after mining a few months of conversations with the auto-save hooks enabled — simply:

mempalace status

Minimal programmatic repro:

from mempalace.config import MempalaceConfig
from mempalace.palace import get_collection
col = get_collection(MempalaceConfig().palace_path)
print(col.count())               # > 32766
col.get(limit=col.count(), include=["metadatas"])
# → chromadb.errors.InternalError: too many SQL variables

Proposed fix

Paginate col.get() at a batch size well below the SQLite limit (10 000 is safe) and aggregate metadatas. Diff is 9 added / 3 removed lines, no behavior change for smaller palaces. PR forthcoming.

Why this matters

mempalace status is the primary "is my palace healthy?" command. Power users with active auto-save tend to cross 32 K drawers within weeks, and when the command starts failing the traceback doesn't hint at the real cause (variable limit), which made it hard to diagnose.

Environment

  • mempalace 3.3.1 (pip)
  • chromadb 1.5.8
  • Python 3.12.12
  • macOS 15.1 (arm64), miniforge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions