fix: respect --project flag in background sync (fixes #434) #436
+75
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #434 - Background sync and watch service now respect the
--projectflag, providing complete project isolation.Problem
When starting the MCP server with
--project=<project-name>:This architectural inconsistency meant the
--projectflag only provided partial isolation:Solution
Added filtering logic in
initialize_file_sync()to check theBASIC_MEMORY_MCP_PROJECTenvironment variable and filteractive_projectsaccordingly.Changes
src/basic_memory/services/initialization.py
osimportactive_projectsbyBASIC_MEMORY_MCP_PROJECTenv var (lines 105-109)tests/services/test_initialization.py
test_initialize_file_sync_respects_project_constraint@patch.dict("os.environ", {"BASIC_MEMORY_MCP_PROJECT": "project1"})Testing
All existing tests pass (7/7):
$ uv run pytest tests/services/test_initialization.py -v ... ============================== 7 passed in 4.52s ===============================New test specifically verifies:
BASIC_MEMORY_MCP_PROJECT=project1is setImpact
Before
With 12 projects configured:
After
With 12 projects configured +
--project=myproject:Project Constraint Behavior
The
--projectflag creates absolute project isolation via theBASIC_MEMORY_MCP_PROJECTenvironment variable:MCP Tools (existing behavior - unchanged)
BASIC_MEMORY_MCP_PROJECThas Priority 1 inresolve_project_parameter()projectparameters in tool calls--project=foo+read_note(..., project="bar")→ usesfoo, notbarBackground Sync (new behavior - now aligned)
active_projectsbyBASIC_MEMORY_MCP_PROJECTNo Constraint Cases (unchanged)
--projectflag: All projects available to MCP tools, all projects synceddefault_project_mode=true: MCP tools default to configured project, all projects still synceddefault_project_modeis a convenience default, not isolation--projectflagBackwards Compatibility
✅ Fully backwards compatible:
--projectflag is NOT used: syncs all projects (existing behavior)--projectflag IS used: syncs only specified project (new behavior, aligns with MCP tool constraint)default_project_modebehavior unchanged (doesn't constrain sync)Security Analysis
Ran Semgrep security scan on changed files:
Result: ✅ No security issues detected
The changes are safe:
os.environ.get())Checklist
PR implementation assisted by Claude Code (Anthropic)