Skip to content

[BUG] Validation error on edit_note while it successfully edits the note #170

Closed

Description

@Narsail

I get the following error when asking Claude Desktop to edit a note:

Edit Failed

Error editing note 'note.md': 1 validation error for EntityResponse
permalink
Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]

Interestingly enough, the actual action (appending to the note) goes through successfully.

Activity

  1. Narsail commented on Jun 24, 2025

    @Narsail
    Author

    @claude Can you do your magic? (I think he doesn't like me)

  2. phernandez commented on Jun 24, 2025

    @phernandez
    Member

    thanks for the bug @Narsail. You have to be a member of our org to have Claude summoning powers :). It uses our api key. If you don't mind, can you share your log from ~/.basic-memory/basic-memory-mcp.log? It may have more info about the error.

  3. phernandez commented on Jun 24, 2025

    @phernandez
    Member

    @claude can you look at the error message the user received? I think this issue may be related to #155

  4. claude commented on Jun 24, 2025

    @claude
    Contributor

    Claude finished @phernandez's task —— View job • claude/issue-170-20250624_132506 • Create PR ➔


    Fixed edit_note validation error ✅

    Todo List:

    • Read codebase structure and understand edit_note implementation
    • Examine EntityResponse schema and permalink validation
    • Check issue [BUG] Validation error moving a file in basic memory #155 for potential relation
    • Identify root cause of None permalink value
    • Implement fix for validation error
    • Test fix if possible
    • Run linting and type checking

    Root Cause Analysis

    Found and fixed the issue! The problem was in the edit_entity workflow:

    1. edit_note calls PATCH /knowledge/entities/{identifier} → edit_entity API endpoint
    2. edit_entity API calls entity_service.edit_entity() method
    3. This method re-parses the file after editing: await self.entity_parser.parse_file(file_path)
    4. The parsed EntityMarkdown object gets passed to entity_model_from_markdown()
    5. The bug: entity_model_from_markdown() unconditionally set model.permalink = markdown.frontmatter.permalink

    When markdown files don't have a permalink field in their frontmatter (which is common), the frontmatter.permalink is None, so it overwrote the existing permalink in the database entity with None.

    The API then tried to validate this with EntityResponse.model_validate(entity) but EntityResponse requires permalink: Permalink (which is Annotated[str, MinLen(1)]), causing the validation error.

    The Fix

    File: src/basic_memory/markdown/utils.py:41-43

    Changed from:

    model.permalink = markdown.frontmatter.permalink

    To:

    # Only update permalink if it exists in frontmatter, otherwise preserve existing
    if markdown.frontmatter.permalink is not None:
        model.permalink = markdown.frontmatter.permalink

    This preserves the existing permalink when the markdown frontmatter doesn't contain one, preventing the validation error.

    Testing

    Added a comprehensive regression test in tests/mcp/test_tool_edit_note.py that specifically tests the scenario where a note is edited multiple times without a permalink in frontmatter. This ensures the bug doesn't recur.

    The edit operation now succeeds without validation errors while preserving all existing functionality.

    --- | Branch: claude/issue-170-20250624_132506

  5. Narsail commented on Jun 24, 2025

    @Narsail
    Author

    @phernandez I checked the log. Here are the events at the time it happened. I had to redact the actual note name:

    2025-06-24 12:13:59.222 | INFO     | basic_memory.mcp.tools.search:search_notes:272 - Searching for permalink=None permalink_match=None text='Note' title=None types=None entity_types=None after_date=None
    2025-06-24 12:13:59.260 | INFO     | basic_memory.mcp.tools.search:search_notes:285 - Search returned no results for query: Note
    2025-06-24 12:14:01.740 | INFO     | basic_memory.mcp.tools.search:search_notes:272 - Searching for permalink=None permalink_match=None text='Note' title=None types=None entity_types=None after_date=None
    2025-06-24 12:14:04.928 | INFO     | basic_memory.mcp.tools.read_note:read_note:68 - Attempting to read note from URL: /Note.md
    2025-06-24 12:14:04.947 | INFO     | basic_memory.mcp.tools.read_note:read_note:76 - Returning read_note result from resource: Note.md
    2025-06-24 12:15:03.441 | INFO     | basic_memory.mcp.tools.edit_note:edit_note:206 - MCP tool call
    2025-06-24 12:15:03.451 | INFO     | basic_memory.api.routers.knowledge_router:edit_entity:121 - API request: endpoint='edit_entity', identifier='Note.md', operation='append'
    2025-06-24 12:15:03.462 | INFO     | basic_memory.services.file_service:write_file:132 - Writing file: path=Note.md, content_length=15331, is_markdown=True
    2025-06-24 12:15:03.517 | ERROR    | basic_memory.api.routers.knowledge_router:edit_entity:154 - Error editing entity: 1 validation error for EntityResponse
    permalink
      Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
        For further information visit https://errors.pydantic.dev/2.11/v/string_type
    2025-06-24 12:15:03.517 | INFO     | basic_memory.mcp.tools.utils:call_patch:321 - Client error: PATCH Note.md: 1 validation error for EntityResponse
    permalink
      Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
        For further information visit https://errors.pydantic.dev/2.11/v/string_type
    2025-06-24 12:15:03.518 | ERROR    | basic_memory.mcp.tools.edit_note:edit_note:300 - Error editing note: 1 validation error for EntityResponse
    permalink
      Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
        For further information visit https://errors.pydantic.dev/2.11/v/string_type
    

    What are you using to run Claude against this repo like it does? Is that something 'off the shelf' or self built?

  6. phernandez commented on Jun 24, 2025

    @phernandez
    Member

    @Narsail We use the claude code actions https://docs.anthropic.com/en/docs/claude-code/github-actions

    It's been working great

  7. added this to the v0.14.0 milestone on Jun 24, 2025
  8. phernandez commented on Jun 26, 2025

    @phernandez
    Member

    fixed in #184

  9. bm-claudeai commented on Jun 26, 2025

    @bm-claudeai
    Contributor

    Test comment

  10. jcelliott commented on Jul 25, 2025

    @jcelliott

    I'm seeing the same behavior on the latest version of basic-memory. It seems that PR didn't actually fix it?

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions