Skip to content

index_repository with relative repo_path (".") corrupts and auto-deletes the project DB every run #794

Description

@Phantom-Star829

Summary

Calling index_repository with a relative repo_path of "." reliably corrupts the store and triggers auto-deletion of the whole project DB on every run. 100% reproducible (tested 3x back-to-back). The tool still returns "status":"indexed" in the same response, which masks the fact that the database was just deleted.

Steps to reproduce

cd /some/large/repo
codebase-memory-mcp cli index_repository '{"repo_path": "."}'

Observed

Indexing runs to completion (in my case: 128,696 nodes, ~485K edges, 6,920 files), then immediately after the dump phase:

level=info  msg=pipeline.done nodes=0 edges=485295 ...
ERROR store.corrupt table=projects bad_root_path=.
level=error msg=store.auto_clean project=root path=~/.cache/codebase-memory-mcp/root.db action=deleting corrupt db — re-index required
{"project":"root","status":"indexed", ...}

So the DB is deleted, yet the JSON response reports "status":"indexed" with a full node/edge count — misleading.

Reproduced identically twice more with a fresh rm -f ~/.cache/codebase-memory-mcp/root.db between runs. Always fails the same way when repo_path is ".".

Workaround (confirmed)

Passing an absolute path for the same directory works perfectly:

codebase-memory-mcp cli index_repository '{"repo_path": "/Users/me/some/large/repo"}'

This indexed the identical directory cleanly (128,696 nodes / 485,363 edges), the DB persisted (<project>.db, 376 MB on disk), and subsequent search_graph queries returned correct results with accurate file:line locations. The only difference is relative . vs the resolved absolute path.

Suspected cause

The root_path for the projects table appears to be stored verbatim as . rather than resolved to an absolute path first. The post-write integrity check then sees bad_root_path=., flags the store corrupt, and the auto-clean recovery path deletes the entire DB instead of normalizing the path.

Suggested fix

Resolve repo_path to an absolute canonical path (e.g. realpath / abspath) at the entry point of index_repository, before it flows into the pipeline or the projects table — so no relative path (., ./, ../foo, ~/...) can ever reach the corruption-detection logic. Bonus: don't return "status":"indexed" on a run that ended in store.auto_clean deletion.

Environment

  • codebase-memory-mcp 0.8.1 (standard variant, no --ui)
  • macOS (Darwin), arm64
  • Installed via install.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting-reporterWaiting on the reporter for info/repro; stale bot will warn then closebugSomething isn't workingpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.stability/performanceServer crashes, OOM, hangs, high CPU/memoryux/behaviorDisplay bugs, docs, adoption UX

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions