fix(mcp): paginate taxonomy tools and log instead of swallowing errors#307
fix(mcp): paginate taxonomy tools and log instead of swallowing errors#307dr-robert-li wants to merge 2 commits intoMemPalace:developfrom
Conversation
tool_list_wings, tool_list_rooms, and tool_get_taxonomy each fetched col.get(limit=10000) once and wrapped the call in 'except Exception: pass'. Two compounding bugs:
1. Palaces with >10k drawers silently truncated at the first 10k page, returning incomplete counts.
2. Any error from col.get (e.g., ChromaDB version incompatibility) was swallowed, returning empty {} with no diagnostic, which is exactly the symptom reporters saw on 95k-drawer palaces under ChromaDB 1.5.x.
Extracts a tiny _iter_all_metadatas helper that paginates via offset until exhausted and logs errors to the existing mempalace_mcp logger (already wired to stderr by logging.basicConfig). All three tools now use it and shrink in the process. Closes MemPalace#171
PR Review: fix(mcp): paginate taxonomy tools and log instead of swallowing errorsExecutive Summary
Affected Areas: Business Impact: Palaces with >10k drawers now return correct counts instead of silently truncated data. Errors surface in logs instead of vanishing. Flow Changes: Three tool functions now delegate to a shared paginating generator ( Ratings
PR Health
High Priority Issues(Must fix before merge) 🔗 #1:
|
…rrors tool_status used its own col.get(limit=10000, include=["metadatas"]) wrapped in `try/except: pass` — the exact truncation + swallowed-error pattern that MemPalace#171 set out to fix. Route it through _iter_all_metadatas so palaces with >10k drawers report accurate wing/room counts. Also make the generator re-raise after logging: partial-page failures previously returned truncated counts disguised as a full result. The MCP handle_request boundary already converts raised exceptions into a proper JSON-RPC error response, so re-raising is the right escalation. Parameterized pagination test covers the three taxonomy tools that lacked direct coverage (list_rooms, get_taxonomy, status). Existing list_wings error test updated to expect propagation. Deferred (not in this commit): mempalace/miner.py status() has the same limit=10000 truncation shape but lives in the CLI path with no shared helper yet — worth a separate targeted PR. Closes review on MemPalace#171.
|
Addresses review feedback in 75fd84a.
Deferred: Full suite green. |
- pyproject.toml: widen chromadb to <2.0 for Python 3.14 compat (MemPalace#302) - config.py + miner/convo_miner/mcp_server: add hnsw:space=cosine so similarity = 1 - distance stays in [0,1] instead of negative L2 (MemPalace#304) - searcher.py + layers.py: guard against ChromaDB 1.x empty-outer query results (IndexError on fresh collections) (MemPalace#305) - mcp_server.py: redirect stdout→stderr at import to protect JSON-RPC wire from chromadb/posthog chatter (MemPalace#306) - mcp_server.py: replace 10k-limited col.get with paginating _iter_all_metadatas helper; stop swallowing errors silently (MemPalace#307) - mcp_server.py: drop undocumented wait_for_previous arg injected by Gemini MCP clients (MemPalace#322) - searcher.py + hybrid_searcher.py + mcp_server.py: add min_similarity threshold filter so callers get a clean "no results" signal (MemPalace#350) - entity_detector.py: add CODE_KEYWORDS blocklist (~80 terms) to stop Rust types / React / framework names being detected as entities (MemPalace#349) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
web3guru888
left a comment
There was a problem hiding this comment.
This is an excellent fix — and it directly addresses the class of silent failures we flagged in #338 and #339. The pattern of except Exception: pass around ChromaDB calls was one of the most painful debugging traps in the codebase.
What I like:
_iter_all_metadatasgenerator — clean extraction that all three taxonomy tools share. The pagination logic (offset += PAGEuntillen(metas) < PAGE) is correct and handles the empty-collection case gracefully.- Log-then-raise — this is the right balance. Callers get the exception for control flow, and operators get the error in logs for diagnostics. Much better than silently returning
{}. - Test coverage — the parameterized test across all three taxonomy tools + the error propagation test are thorough. The 15k-drawer two-page mock perfectly validates the pagination boundary.
One minor thought: the where parameter passthrough in _iter_all_metadatas is a nice touch — it keeps tool_list_rooms(wing=...) working correctly without duplicating the pagination logic.
We run a ~700-entity palace and haven't hit the 10k ceiling yet, but this fix future-proofs us nicely. Strong +1.
🔭 Reviewed as part of the MemPalace-AGI integration project — autonomous research with perfect memory. Community interaction updates are posted regularly on the dashboard.
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
…lace#171) Replaces the single col.get(limit=10000) call in status() with a 500-item pagination loop, matching the fix applied to MCP taxonomy tools in MemPalace#307. Palaces with >10k drawers now report correct drawer counts instead of silently truncating at 10k.
|
Closing — this is superseded by recently merged PRs to develop. Thank you for the contribution! |
What does this PR do?
tool_list_wings,tool_list_rooms, andtool_get_taxonomyeach fetchedcol.get(limit=10000)once and wrapped the call inexcept Exception: pass. Two compounding bugs:col.get(e.g., ChromaDB version incompatibility) was swallowed, returning empty{}with no diagnostic — exactly the symptom reporters saw on 95k-drawer palaces under ChromaDB 1.5.x.Extracts a tiny
_iter_all_metadatashelper that paginates viaoffsetuntil exhausted and logs errors to the existingmempalace_mcplogger (already wired to stderr). All three tools now use it and shrink in the process.Fixes #171.
How to test
python -m pytest tests/test_mcp_server.py::test_tool_list_wings_paginates_beyond_10k \ tests/test_mcp_server.py::test_tool_list_wings_logs_chromadb_error_instead_of_swallowing -vTests use a mocked collection that returns multi-page results (15k drawers across 2 pages) and a collection that raises
RuntimeErrorfromcol.get. Both tests fail without the fix — the pagination test sees only 10k drawers, the log test gets an emptycaplog.Checklist
python -m pytest tests/ -v) — 119 passed, 0 failedruff check .)