Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Apr 6, 2025

This PR fixes issue #71

Changes Summary

Fixed a bug in the EntityParser class related to handling absolute file paths:

  1. Modified the parse_file method in src/basic_memory/markdown/entity_parser.py to correctly handle both absolute and relative paths.

    • Added a check to detect if a path is absolute before trying to join it with base_path
    • If path is absolute, use it directly; otherwise, join with base_path
  2. Added a new test case in tests/markdown/test_entity_parser.py to verify that files with absolute paths can be parsed correctly:

    • Created a comprehensive test named test_parse_file_with_absolute_path
    • The test constructs an absolute path and verifies the parser can handle it

This fix ensures that when users provide absolute paths to files, they will be processed correctly rather than incorrectly joined with the base path, which would result in an invalid path.

Original Issue

Human Summary

write_note kept failing to edit existing files, so I had Claude troubleshoot. Something I've done has caused some path discrepancies that I might expect the sync command to fix, but it's not. Calude came up with a two step workaround to use write_note. Details below.

Bug Description
The write_note tool fails to update existing files in Basic Memory with an error message indicating the file already exists, despite the tool supposedly supporting updates to existing notes. The synchronization process that should reconcile path differences appears to be failing. write_note behaves differently depending on the exact path given.

Steps To Reproduce

Install Basic Memory with persistence enabled
Create a note using write_note tool with a specific folder and title
Attempt to update the same note using write_note with identical folder and title
Receive error: Error executing tool write_note: file for entity [path] already exists

Expected Behavior
When using write_note on an existing note, the function should detect the existing file and update its content, returning a message like: "Updated [path] (checksum)" as shown in the test cases.
Actual Behavior
Instead of updating the note, the system throws an error:
CopyError executing tool write_note: file for entity The First Kings - v2\Project_Narrative\Characters/Seren Thorne already exists: The First Kings - v2\Project_Narrative\Characters\Seren Thorne.md
The error occurs even though the test suite includes tests explicitly verifying that write_note can update existing files. The automatic sync process that should reconcile path differences isn't working as expected.
Environment

OS: Windows 10
Python version: 3.11
Basic Memory version: 0.10.0
Claude Desktop version: 0.9.0

Additional Context
The issue appears to be related to file path handling:

Existing files have permalinks like: first-kings-project/narrative/characters/seren-thorne
We're attempting to write to: The First Kings - v2\Project_Narrative\Characters

When using the exact folder structure of the existing file (First Kings Project/Narrative/Characters), the update works properly, indicating a file path normalization or persistence issue.
Test files confirm that file updates should work:
pythonCopy@pytest.mark.asyncio
async def test_write_note_update_existing(app):
# Creates and then updates a note successfully
# Verifies with "# Updated test/Test Note.md (a8eb4d44)"
Possible Solution
Several potential fixes:

Path Normalization: Ensure consistent normalization of paths between creation and update operations
Permalink-Based Updates: Add a mode to the write_note function that accepts permalinks directly
Synchronization Fix: Debug why the sync process isn't reconciling path differences
Two-Step Process: Implement a workflow that first reads an entity to get its exact path structure before updating

For immediate use, the workaround is to match the exact folder structure of existing files when attempting to update them.

(Written by Claude)


🤖 Generated with Claude Code GitHub Action

@phernandez phernandez changed the title Fix: [BUG] write_note Tool Fails to Update Existing Files in Some Situations. fix: [BUG] write_note Tool Fails to Update Existing Files in Some Situations. Apr 6, 2025
…n Some Situations.

Automated fix generated by Claude Code based on issue analysis.

---
🤖 Generated with Claude Code GitHub Action

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez force-pushed the fix-issue-71-20250406012335 branch from 53fe45d to 3d55674 Compare April 6, 2025 03:20
@phernandez phernandez merged commit 9bff1f7 into main Apr 6, 2025
8 checks passed
@phernandez phernandez deleted the fix-issue-71-20250406012335 branch April 6, 2025 03:31
phernandez pushed a commit that referenced this pull request Apr 6, 2025
…uations. (#80)

Signed-off-by: phernandez <paul@basicmachines.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants