Skip to content

BUG: build_context empty results on valid note identifiers (fallback resolution + diagnostics) #582

Description

@phernandez

Problem

build_context can return empty results for notes that are retrievable via read-note, especially when callers pass path-like identifiers that are valid from user perspective but not exact permalink matches.

Related downstream issue: basicmachines-co/openclaw-basic-memory#17

Why this looks upstream

ContextService.build_context performs exact permalink lookup for non-wildcard URLs and currently has no fallback resolution path:

  • src/basic_memory/services/context_service.py
  • src/basic_memory/mcp/tools/build_context.py
  • src/basic_memory/mcp/project_context.py (resolve_project_and_path)

Requested fix

Improve context identifier resolution and empty-result diagnostics:

  1. If exact permalink lookup returns 0 primaries, try a fallback resolver path:
    • alternate project-prefix normalization (with/without project prefix), and/or
    • resolve via entity resolver (same strategy family used by read tooling).
  2. Include normalized/resolved lookup path in JSON metadata when results are empty.
  3. Return a machine-readable "no primary match" reason (not just empty list) so clients can distinguish "no relations" from "lookup miss".

Acceptance criteria

  • build_context finds primary note for common memory URL forms when note exists.
  • Empty result payload includes enough diagnostics to debug path mismatch quickly.
  • Backward compatibility: existing successful exact lookups behave unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions