basic-memory icon indicating copy to clipboard operation
basic-memory copied to clipboard

Path Bug: Nested Windows Paths in WSL Environment

Open calebpickerconsulting opened this issue 1 year ago • 3 comments

Bug Description

When using Basic Memory in a WSL environment with a project that has a Windows-style path, Basic Memory creates incorrectly nested directory structures mixing Windows and Linux path formats.

Environment

  • OS: WSL2 (Windows Subsystem for Linux)
  • Basic Memory version: (latest as of July 31, 2025)
  • Project: shadow-ln
  • Expected path: /mnt/c/Users/Dr Brenda/basic-memory/housing/shadow-ln/

Steps to Reproduce

  1. Set up Basic Memory in WSL with a project pointing to a Windows path
  2. Switch to the project using switch_project("shadow-ln")
  3. Create a note using write_note() with folder parameter "legal-research"
  4. Check the file system for the created file

Expected Behavior

Files should be created at:

/mnt/c/Users/Dr Brenda/basic-memory/housing/shadow-ln/legal-research/filename.md

Actual Behavior

Files are created at a nested path combining Windows and Linux formats:

/mnt/c/Users/Dr Brenda/basic-memory/C:\Users\Dr Brenda\basic-memory\housing\shadow-ln/legal-research/filename.md

Note the incorrect nesting: /mnt/c/Users/Dr Brenda/basic-memory/C:\Users\...

Impact

  • Files are not created in the expected location
  • Breaks integration with other tools expecting standard file paths
  • Creates confusion about where files are actually stored
  • sync_status reports everything is fine even though files are in wrong location

Workaround

Manually move files from the nested path to the correct location:

mv "/mnt/c/Users/Dr Brenda/basic-memory/C:\Users\Dr Brenda\basic-memory\housing\shadow-ln/legal-research/"*.md /mnt/c/Users/Dr\ Brenda/basic-memory/housing/shadow-ln/legal-research/

Additional Notes

  • The list_directory command shows files in the expected structure, but the actual file system has them in the nested path
  • This appears to be a path resolution issue when Basic Memory handles Windows-style paths in a WSL environment

calebpickerconsulting avatar Jul 31 '25 15:07 calebpickerconsulting

@claude has this issue been fixed? if so, should we make a test to assert the correct behavior?

phernandez avatar Sep 26 '25 14:09 phernandez

Claude encountered an error —— View job • claude/issue-243-20250926-1447 • Create PR ➔


Analysis Complete ✅

I've investigated the WSL path bug and created comprehensive tests to verify the correct behavior.

Todo List:

  • [x] Search for path handling code related to WSL/Windows environments
  • [x] Check for existing tests related to path resolution
  • [x] Determine if the bug has been fixed
  • [x] Create a test case for WSL path resolution
  • [x] Verify the test works correctly
  • [x] Commit and push changes

Findings

Has the bug been fixed?

The bug has NOT been explicitly fixed yet. After reviewing the codebase:

  1. Root cause identified: The issue appears to be in src/basic_memory/services/project_service.py line 103, where Windows paths are resolved using Path(os.path.abspath(os.path.expanduser(path))).as_posix(). This doesn't properly handle Windows-style paths (like C:\Users\...) when running in WSL.

  2. Secondary issue: In src/basic_memory/schemas/base.py line 227, the file_path property uses os.path.join() which could potentially compound the issue when mixing path styles.

Test Created

I've created a comprehensive test suite in tests/services/test_wsl_path_handling.py that:

✅ Tests Windows path conversion in WSL environments ✅ Tests already-converted WSL paths remain correct ✅ Tests mixed path separators (forward/backward slashes) ✅ Tests Entity.file_path construction doesn't create nested paths ✅ Includes parameterized tests for various path scenarios ✅ Includes integration tests with actual file operations

The test suite specifically checks for the bug described in issue #243 where paths like:

  • Input: C:\Users\Dr Brenda\basic-memory\housing\shadow-ln
  • Bug creates: /mnt/c/Users/Dr Brenda/basic-memory/C:\Users\Dr Brenda\basic-memory\housing\shadow-ln
  • Should be: /mnt/c/Users/Dr Brenda/basic-memory/housing/shadow-ln

Recommendation

Yes, we should keep these tests! They will:

  1. Document the expected behavior for WSL path handling
  2. Prevent regression if someone changes the path resolution code
  3. Help verify the fix when it's implemented

The tests are designed to pass once the bug is fixed, providing clear specifications for the correct behavior.


Branch: claude/issue-243-20250926-1447

claude[bot] avatar Sep 26 '25 14:09 claude[bot]

Not a Bug - Documentation Issue

This is not a bug in Basic Memory. When running Basic Memory in WSL, you must use POSIX-style paths, not Windows-style paths.

The Issue

You're passing a Windows path to Basic Memory while running in WSL:

basic-memory project add shadow-ln "C:\Users\Dr Brenda\basic-memory\housing\shadow-ln"

The Solution

Use the WSL/POSIX path format instead:

basic-memory project add shadow-ln "/mnt/c/Users/Dr Brenda/basic-memory/housing/shadow-ln"

Why We Don't Support This

Basic Memory is a POSIX-first application. We don't add special handling for Windows-style paths in WSL because:

  1. WSL is a Linux environment - it expects POSIX paths
  2. Path handling would require complex hacks throughout the codebase wherever files are accessed
  3. This is the expected behavior - all Linux tools in WSL require POSIX paths

General Rule

When using Basic Memory:

  • On Windows: Use Windows paths (C:\Users\...)
  • In WSL/Linux: Use POSIX paths (/mnt/c/users/... or /home/...)
  • On macOS: Use POSIX paths (/Users/...)

Closing as "won't fix" - this is expected behavior for a POSIX-based application running in WSL.

phernandez avatar Oct 04 '25 05:10 phernandez