Skip to content

[BUG] Basic_memory MCP server needs to use .gitignore #285

Closed as duplicate

Description

@FellowTraveler

Basic Memory MCP Server - .gitignore Bug Report

Summary

The basic_memory MCP server fails to respect .gitignore patterns and attempts to sync build artifacts, causing sync failures on Rust projects with complex incremental compilation filenames.

Bug Description

Expected Behavior

The basic_memory MCP server should:

  1. Read and respect all patterns in the project's .gitignore file
  2. Skip directories and files that match .gitignore patterns
  3. Never attempt to sync build artifacts (e.g., target/, node_modules/, dist/, build/)
  4. Handle complex filenames gracefully without crashing

Actual Behavior

The server:

  1. Attempts to sync files in backend/target/ despite it being in .gitignore
  2. Fails with file move errors on Rust's incremental compilation artifacts
  3. Reports sync failures that block other operations

Error Message

❌ Sync failed for project 'ai-robot-security': Cannot move entity from 
'backend/target/debug/incremental/angel_security-3jhmxh0kgxo7h/s-hadf7wssc0-1pd28gt-2u4rvv79i4alxt84s5c72zkiy/5w0grk96adxa0x4j2z8bqoffm.o' to 
'backend/target/debug/deps/angel_security-db91db90048569b2.5w0grk96adxa0x4j2z8bqoffm.rcgu.o': 
destination path is already occupied by another file.

Reproduction Steps

  1. Create a Rust project with basic_memory configured
  2. Add backend/target/ to .gitignore (or target/ for a standard Rust project)
  3. Run cargo build to generate build artifacts
  4. Attempt to sync with basic_memory
  5. Observe sync failure on incremental compilation files

Project Structure

/Users/au/Documents/idea_AI_robot_drone_security/
├── .gitignore (contains "backend/target/" on line 8)
├── backend/
│   ├── Cargo.toml
│   ├── src/
│   └── target/           # ← Should be ignored but isn't
│       └── debug/
│           ├── incremental/
│           └── deps/
├── frontend/
└── memory-bank/

.gitignore Content (Relevant Lines)

# Rust Backend
backend/target/
backend/Cargo.lock
backend/**/*.rs.bk
backend/**/*.pdb

Root Cause Analysis

Primary Issues:

  1. Gitignore Parsing: The server is not properly parsing or applying .gitignore patterns

    • Pattern backend/target/ should exclude the entire directory
    • The server is still attempting to process files within this directory
  2. File Naming Conflicts: Rust's incremental compilation creates files with:

    • Long hash-based names (e.g., 5w0grk96adxa0x4j2z8bqoffm.o)
    • Similar names in different directories
    • Multiple files with the same base name but different paths
    • The server's file moving/renaming logic can't handle these edge cases
  3. Missing Default Exclusions: The server should have built-in exclusions for common build directories:

    • target/ (Rust)
    • node_modules/ (Node.js)
    • dist/, build/ (Various build systems)
    • *.o, *.so, *.dll (Compiled objects)

Suggested Fixes

1. Properly Implement .gitignore Support

# Pseudocode for proper gitignore handling
import pathspec  # or similar gitignore parsing library

def should_sync_file(file_path, project_root):
    gitignore_path = os.path.join(project_root, '.gitignore')
    if os.path.exists(gitignore_path):
        with open(gitignore_path) as f:
            spec = pathspec.PathSpec.from_lines('gitwildmatch', f)
        
        # Check if file matches any gitignore pattern
        relative_path = os.path.relpath(file_path, project_root)
        if spec.match_file(relative_path):
            return False  # Skip this file
    
    return True

2. Add Default Exclusions

DEFAULT_EXCLUSIONS = [
    'target/',      # Rust
    'node_modules/', # Node.js
    'dist/',        # Build output
    'build/',       # Build output
    '.git/',        # Git directory
    '*.o',          # Object files
    '*.so',         # Shared libraries
    '*.dll',        # Windows libraries
    '*.pyc',        # Python bytecode
    '__pycache__/', # Python cache
]

3. Handle Complex Filenames Gracefully

  • Don't attempt to move/rename files during sync
  • Use content hashing instead of filename-based deduplication
  • Handle Unicode and special characters properly
  • Implement proper error recovery instead of failing entire sync

4. Add Configuration Option

Allow users to manually specify exclusions in basic_memory config:

{
  "projects": {
    "ai-robot-security": {
      "path": "/Users/au/Documents/idea_AI_robot_drone_security",
      "exclude": [
        "backend/target/**",
        "frontend/node_modules/**",
        "**/*.o"
      ]
    }
  }
}

Impact

  • Severity: High - Blocks sync for any Rust project
  • Affected Users: Anyone using basic_memory with compiled languages (Rust, C++, Go, etc.)
  • Workaround: Delete build artifacts before sync (not practical)

Test Cases

  1. Create a Rust project with target/ in .gitignore → Should not sync any files in target/
  2. Create files with complex names containing hashes → Should handle gracefully
  3. Add custom patterns to .gitignore → Should respect all patterns
  4. Use nested .gitignore files → Should respect hierarchy
  5. Test with symlinks in ignored directories → Should not follow symlinks in ignored paths

Environment

  • OS: macOS (Darwin)
  • Basic Memory Version: (current MCP server version)
  • Project Type: Rust + TypeScript/React
  • File System: APFS (case-insensitive)

Additional Notes

  • The sync fails consistently on the same files
  • The error suggests the server is trying to move/rename files during sync (why?)
  • Other projects without build artifacts sync successfully
  • The server continues to work partially (can read/write notes) despite sync failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions