Skip to content

Data dir resolution hardcoded in several places — ignores BASIC_MEMORY_CONFIG_DIR #742

Description

@groksrc

Summary

Several modules hardcode Path.home() / \".basic-memory\" to locate Basic Memory state instead of using BasicMemoryConfig.data_dir_path / ConfigManager.config_dir. This means they ignore the BASIC_MEMORY_CONFIG_DIR environment variable, which users/tests rely on to redirect Basic Memory state (for isolated worktrees, containerized runs, multi-instance setups, etc.).

Any feature accessed through these call sites will silently read/write the wrong directory when BASIC_MEMORY_CONFIG_DIR is set.

Known offending call sites

  • src/basic_memory/utils.py:284log_path = Path.home() / \".basic-memory\" / log_filename (file logging)
  • src/basic_memory/ignore_utils.py:66return Path.home() / \".basic-memory\" / \".bmignore\" (global ignore file lookup)
  • src/basic_memory/sync/watch_service.py:92self.status_path = Path.home() / \".basic-memory\" / WATCH_STATUS_JSON
  • src/basic_memory/services/project_service.py:1140watch_status_path = Path.home() / \".basic-memory\" / WATCH_STATUS_JSON
  • src/basic_memory/cli/commands/cloud/rclone_commands.py:147return Path.home() / \".basic-memory\" / \"bisync-state\" / project_name

Example impact

If a user runs with BASIC_MEMORY_CONFIG_DIR=/opt/bm-sandbox:

  • Config and the SQLite DB live under /opt/bm-sandbox/ (correct — honors the env var).
  • But the watch status file, log file, .bmignore, and rclone bisync state all end up under ~/.basic-memory/ (wrong).

This causes split state, stale watchers, log leakage across isolated instances, and broken .bmignore behavior depending on which code path the user hits first.

Proposed fix

Follow-up to #741:

  1. #741 introduces resolve_data_dir() as a module-level helper in config.py (the single source of truth, honoring BASIC_MEMORY_CONFIG_DIR).
  2. This issue: update every call site above to use resolve_data_dir() (or an equivalent already-available config accessor) instead of hardcoding Path.home() / \".basic-memory\".
  3. Add a regression test that exercises each of those code paths under a non-default BASIC_MEMORY_CONFIG_DIR and asserts the file/dir they touch lives under the redirected data dir.

Keeping it out of #741 to avoid scope creep on the FastEmbed cache fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions