Skip to content

feat: improve architecture, remove redundacies and duplicaions, centralize ChromaDB into palace_db singleton, consolidate MCP tools 19→14, add test suite - #25

Closed
bgauryy wants to merge 6 commits into
MemPalace:mainfrom
bgauryy:improvements
Closed

Conversation

@bgauryy

@bgauryy bgauryy commented Apr 7, 2026

Copy link
Copy Markdown

PR Review: cleanups

Executive Summary

Aspect Value
PR Goal Eliminate code duplication, extract shared modules, consolidate MCP tools (19→14), remove dead code, unify versioning
Files Changed 20
Risk Level 🟢 LOW — Mechanical refactoring, zero behavior changes, 9/9 tests pass
Review Effort 3/5 — Large diff (−1,310 net lines) but repetitive consolidation pattern
Recommendation ✅ APPROVE (with 2 medium suggestions)

Affected Areas: palace_db.py (new), constants.py (new), mcp_server.py, layers.py, searcher.py, miner.py, convo_miner.py, palace_graph.py, knowledge_graph.py, cli.py, config.py, normalize.py, onboarding.py, entity_registry.py, room_detector_local.py

Business Impact: None — internal refactoring only. MCP tool surface shrinks from 19 to 14 tools (AI agents will need fewer calls).

Flow Changes: All ChromaDB access now routes through palace_db.py singleton. Where-filter construction centralized. KG queries use named column access.

Ratings

Aspect Score
Correctness 5/5
Security 5/5
Performance 4/5
Maintainability 4/5

PR Health

  • References ticket/issue (RFC file included in PR)
  • Has relevant tests (9/9 pass, zero regressions)

Medium Priority Issues

No medium priority issues remaining — #1 was fixed during review.


🎨 #2: PR description is empty

Location: PR body | Confidence: ✅ HIGH

The PR template is unfilled — "What does this PR do?" and "How to test" are blank. The RFC file (.octocode/rfc/RFC-mempalace-cleanup.md) covers everything thoroughly, but the PR description should at least link to it and provide a one-liner summary for reviewers scanning the PR list.


Low Priority Issues

🎨 #3: Shadow MIN_CHUNK_SIZE has no comment

Location: mempalace/convo_miner.py:20 (local MIN_CHUNK_SIZE = 30) vs mempalace/constants.py:45 (MIN_CHUNK_SIZE = 50) | Confidence: ✅ HIGH

The RFC acknowledges this is intentional (conversations need smaller chunks than project files), but the code has no comment explaining the divergence. A reader will see from .constants import CONVO_EXTENSIONS, SKIP_DIRS right above and wonder why MIN_CHUNK_SIZE wasn't imported too.

+ # Conversations use smaller minimum chunks than project files (constants.MIN_CHUNK_SIZE=50)
  MIN_CHUNK_SIZE = 30

#4: MempalaceConfig() created per function call in palace_db.py

Location: mempalace/palace_db.py:15,25,67 | Confidence: ⚠️ MED

get_client, get_collection, and no_palace_error each instantiate MempalaceConfig() on every call. The old pattern in mcp_server.py was _config = MempalaceConfig() at module level (singleton). Config reads from ~/.mempalace/config.json, so repeated instantiation means repeated file I/O.

+ _cfg = MempalaceConfig()
+
  def get_client(palace_path: str = None) -> chromadb.ClientAPI:
-     cfg = MempalaceConfig()
-     path = palace_path or cfg.palace_path
+     path = palace_path or _cfg.palace_path

Not blocking — config files are tiny and OS-cached, but it's inconsistent with the module-level pattern used in mcp_server.py.


🏗️ #5: Stub method without deprecation signal

Location: mempalace/entity_registry.py:553-554 | Confidence: ⚠️ MED

learn_from_text returns [] with a docstring "Stub — entity detection removed." The same pattern appears in onboarding.py:_auto_detect. These stubs are functionally correct, but callers have no programmatic signal that the feature is gone. A warnings.warn("entity detection removed", DeprecationWarning) or removal of the method entirely (with callers updated) would be cleaner.


What's Good

  • palace_db.py singleton — Clean extraction. Cache key (path, name) handles multi-palace scenarios. reset() for testing is thoughtful.
  • knowledge_graph.py Row factoryrow["obj_name"] instead of row[10] is a major robustness win. One schema change would have broken the old code silently.
  • MCP tool consolidationmempalace_status now returns graph stats + protocol + AAAK spec in one call. AI agents get full context in a single tool call instead of 3-4.
  • constants.py — Simple, correct. No over-engineering.
  • build_where_filter() — The 6→1 consolidation of where-filter logic is exactly the kind of DRY that prevents subtle divergence bugs.
  • RFC included — Thorough documentation of what changed and why. Verification section with AST audit is above average.

Created by Octocode MCP https://octocode.ai 🔍🐙

@bgauryy bgauryy changed the title cleanups feat: centralize ChromaDB into palace_db singleton, consolidate MCP tools 19→14, add test suite Apr 7, 2026
@bgauryy bgauryy changed the title feat: centralize ChromaDB into palace_db singleton, consolidate MCP tools 19→14, add test suite feat: improve architecture, remove redundacies and duplicaions, centralize ChromaDB into palace_db singleton, consolidate MCP tools 19→14, add test suite Apr 7, 2026
@bensig

bensig commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Hey, really appreciate the effort here — it's clear you put serious thought into the architecture. However a +2798/-1887 rewrite is too large to review safely at this stage, especially with so many changes landing in parallel right now.

We'd love your help in a different way — reviewing incoming PRs is incredibly valuable and helps you understand the codebase patterns before proposing structural changes. Once you have that context, smaller focused PRs that tackle one thing at a time are much easier for us to review and merge. Thanks for understanding!

@bensig bensig closed this Apr 7, 2026
@bgauryy

bgauryy commented Apr 8, 2026

Copy link
Copy Markdown
Author

@bensig - I just buit a tool for that :)
https://www.youtube.com/watch?v=ZCqFLKItk8s

Will help in pleasure - let me know if you need help with specific PRs
there are dozens.

Check this out:

#223
#260
#264
#223
#261
#262

You can use octocode-mcp with the /review_pull_request prompt and add the PR URL for this..
Ping me if you want to automate it ..

kostadis added a commit to kostadis/mempalace-fork that referenced this pull request Aug 21, 2026
Completes `git merge v3.3.6` on merge/v3.5.0-into-kostadis-dev. 18 conflict
files resolved keeping local design at the divergence sites; §2 parallel-mine
mechanics ported into the local pipeline (chunk-cap MemPalace#1455, Tier 6a content-date
MemPalace#1584, config chunking, skip_reason); §embedding unified (provider switch +
within-onnx model select, case-insensitive embedding_model).

Fixed a silent auto-merge defect in backends/chroma.py: the merge dropped the
`_HNSW_MISSING_METADATA_DATA_FLOOR` constant while keeping its usages, breaking
15 backend/HNSW tests with a NameError. Restored per upstream.

Deferred (documented in docs/v3.5.0-merge-notes.md): MemPalace#1383 KG realpath cache
canonicalization (kept local _kg_cache keying per §7); prefetch_mined_set.

Tests: 2538 passed, 33 skipped, 2 pre-existing failures (baseline), no new
failures. ruff-clean on merge-touched files. version.py = 3.3.6.

Refs MemPalace#23.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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