You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Classification: Bug + Enhancement | Priority: Medium-High | Component: MCP / Context Service | Complexity: Medium
Root cause:ContextService.build_context performed a single exact permalink= lookup with no fallback. In contrast, read_note uses a full LinkResolver pipeline (external_id → permalink → title → file path → fuzzy). When path-like identifiers don't exactly match stored permalinks (e.g., due to project-prefix mismatch), build_context returned empty silently.
No duplicates found. Labels added: bug, enhancement.
Implementation checklist:
Read relevant source files
Check for duplicate issues
Add labels and classify issue
Add no_primary_match and resolved_path diagnostic fields to ContextMetadata + MemoryMetadata
Add 3-stage fallback to ContextService.build_context: wildcard-prefix → strip-prefix → title FTS search
Update to_graph_context to pass through new diagnostic fields to API response
Write tests (5 new test cases) for fallback cases + diagnostics
Commit and push changes
Changes made
src/basic_memory/services/context_service.py
Added resolved_path and no_primary_match fields to ContextMetadata dataclass
When exact permalink lookup returns 0 results, now tries three fallbacks:
Wildcard prefix match*/path — for when stored permalink has extra leading segment (e.g. project prefix) that caller omitted
Strip-prefix exact lookup — strips the first path segment and retries, for when caller over-specified the path
Title FTS search on the last path segment — catches normalization drift between caller and stored values
Sets no_primary_match diagnostic string when all fallbacks are exhausted
src/basic_memory/schemas/memory.py
Added resolved_path: Optional[str] and no_primary_match: Optional[str] to MemoryMetadata
src/basic_memory/api/v2/utils.py
to_graph_context now maps the two new diagnostic fields through to the API response
tests/services/test_context_service.py — 5 new tests:
test_build_context_fallback_wildcard_prefix — missing project prefix case
test_build_context_fallback_strip_prefix — extra leading prefix case
test_build_context_fallback_title_search — title FTS fallback case
test_build_context_diagnostics_no_match — all fallbacks exhausted, diagnostic fields populated
test_build_context_diagnostics_exact_match_no_diagnostic — exact match, no diagnostics (backward compat)
Confirmed the bug is still present on main. Here's what I found:
Reproduction
# read-note resolves fine (uses full LinkResolver pipeline)
bm tool read-note "2026-02-24" --project claw ✅ returns note
# build-context fails with the same identifier
bm tool build-context "memory://memory/2026-02-24" --project claw ❌ empty results
bm tool build-context "memory://2026-02-24" --project claw ❌ empty results
# Only works with exact title match
bm tool build-context "memory://MEMORY" --project claw ✅ works
Root Cause Confirmed
The note's frontmatter has permalink: memory/2026-02-24. When build_context processes a memory:// URL, it constructs the lookup path and the project prefix (claw/) gets involved, but the exact permalink match fails because:
memory://memory/2026-02-24 → looks for permalink claw/memory/2026-02-24 (over-specified with project prefix)
memory://2026-02-24 → looks for permalink claw/2026-02-24 (missing the memory/ path segment)
Meanwhile read_note uses the full LinkResolver pipeline (external_id → permalink → title → file path → fuzzy) which handles all these cases gracefully.
The Gap
build_context does a single exact permalink lookup with no fallback. read_note has robust multi-strategy resolution. This asymmetry means the OpenClaw plugin's build_context tool (used for memory:// URL navigation) silently returns empty on identifiers that read_note handles fine.
Branch Status
Claude's branch claude/issue-582-20260218-1654 has a solid fix (3-stage fallback: wildcard prefix → strip-prefix → title FTS). It's 29 commits behind main though — may need a rebase before PR. The approach looks correct based on my testing.
Activity
claude commentedon Feb 18, 2026
Claude finished @phernandez's task in 9m 3s —— View job •
claude/issue-582-20260218-1654• Create PR ➔Triage + Implementation Complete
Classification: Bug + Enhancement | Priority: Medium-High | Component: MCP / Context Service | Complexity: Medium
Root cause:
ContextService.build_contextperformed a single exactpermalink=lookup with no fallback. In contrast,read_noteuses a fullLinkResolverpipeline (external_id → permalink → title → file path → fuzzy). When path-like identifiers don't exactly match stored permalinks (e.g., due to project-prefix mismatch),build_contextreturned empty silently.No duplicates found. Labels added:
bug,enhancement.Implementation checklist:
no_primary_matchandresolved_pathdiagnostic fields toContextMetadata+MemoryMetadataContextService.build_context: wildcard-prefix → strip-prefix → title FTS searchto_graph_contextto pass through new diagnostic fields to API responseChanges made
src/basic_memory/services/context_service.pyresolved_pathandno_primary_matchfields toContextMetadatadataclass*/path— for when stored permalink has extra leading segment (e.g. project prefix) that caller omittedno_primary_matchdiagnostic string when all fallbacks are exhaustedsrc/basic_memory/schemas/memory.pyresolved_path: Optional[str]andno_primary_match: Optional[str]toMemoryMetadatasrc/basic_memory/api/v2/utils.pyto_graph_contextnow maps the two new diagnostic fields through to the API responsetests/services/test_context_service.py— 5 new tests:test_build_context_fallback_wildcard_prefix— missing project prefix casetest_build_context_fallback_strip_prefix— extra leading prefix casetest_build_context_fallback_title_search— title FTS fallback casetest_build_context_diagnostics_no_match— all fallbacks exhausted, diagnostic fields populatedtest_build_context_diagnostics_exact_match_no_diagnostic— exact match, no diagnostics (backward compat)|
fix: add fallback resolution and diagnostics to build_context
phernandez commentedon Feb 18, 2026
Downstream tracking
bm-clawd commentedon Feb 24, 2026
Investigation from current main (v0.18.3)
Confirmed the bug is still present on main. Here's what I found:
Reproduction
Root Cause Confirmed
The note's frontmatter has
permalink: memory/2026-02-24. Whenbuild_contextprocesses amemory://URL, it constructs the lookup path and the project prefix (claw/) gets involved, but the exact permalink match fails because:memory://memory/2026-02-24→ looks for permalinkclaw/memory/2026-02-24(over-specified with project prefix)memory://2026-02-24→ looks for permalinkclaw/2026-02-24(missing thememory/path segment)Meanwhile
read_noteuses the fullLinkResolverpipeline (external_id → permalink → title → file path → fuzzy) which handles all these cases gracefully.The Gap
build_contextdoes a single exact permalink lookup with no fallback.read_notehas robust multi-strategy resolution. This asymmetry means the OpenClaw plugin'sbuild_contexttool (used formemory://URL navigation) silently returns empty on identifiers thatread_notehandles fine.Branch Status
Claude's branch
claude/issue-582-20260218-1654has a solid fix (3-stage fallback: wildcard prefix → strip-prefix → title FTS). It's 29 commits behind main though — may need a rebase before PR. The approach looks correct based on my testing.fix: use LinkResolver fallback in build_context for flexible identifi…