Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
Files with missing or empty title fields in frontmatter cause infinite retry loops during sync, leading to:
- Database constraint violations every 30 seconds
- Continuous directory rescanning (e.g., 737 files every 30 seconds)
- Elevated memory usage from retry state accumulation
- Poor user experience with no clear error reporting
Evidence
Tenant production-basic-memory-tenant-cb6aad6f showing repeated errors:
Failed to upsert entity for RESEARCH/_Templates/Research Library Card.md:
(sqlite3.IntegrityError) NOT NULL constraint failed: entity.title
[SQL: INSERT INTO entity (title, entity_type, ...) VALUES (?, ?, ...)]
[parameters: (None, 'note', ...)]
This file is detected as "changed" on every 30-second sync cycle because it never successfully syncs.
Root Cause
The file has either:
- No
title:field in frontmatter - Empty
title:field (title:with no value) title: nullor similar
Current sync behavior:
- Tries to insert with
title=None - Hits NOT NULL constraint
- Logs error but doesn't skip file permanently
- Circuit breaker doesn't trigger because each 30-second sync is treated as a fresh attempt
Expected Behavior
When encountering a file with missing/empty title:
- Validation: Detect missing title during entity creation
- Generate default: Create a title from filename (e.g., "Research Library Card" from "Research Library Card.md")
- Log warning: Inform user that title was auto-generated
- Succeed sync: Don't retry indefinitely
- Optional: Add to sync report as "files with auto-generated titles"
Alternative Approach
If we want to keep strict validation:
- Skip file permanently: Add to failure cache with permanent skip flag
- Report to user: Include in sync status endpoint with actionable error
- Don't retry: Circuit breaker should prevent infinite retries
Impact
High - Affects production tenants with template files, research notes, or any files with missing frontmatter. Causes:
- Memory pressure from continuous scanning
- Database I/O waste
- Poor system resource utilization
Files to Modify
src/basic_memory/services/entity_service.py- Add title generation/validationsrc/basic_memory/sync/sync_service.py- Enhance circuit breaker for constraint violationssrc/basic_memory/file_utils.py- Addgenerate_title_from_filename()helper
Example Fix
def generate_title_from_filename(file_path: Path) -> str:
"""Generate a title from filename when frontmatter is missing title."""
# Remove extension and clean up
title = file_path.stem
# Replace underscores/hyphens with spaces
title = re.sub(r'[_-]+', ' ', title)
return title.strip()
# In entity creation:
if not frontmatter_data.get('title'):
title = generate_title_from_filename(file_path)
logger.warning(
f"Missing title in {file_path}, auto-generated: {title}"
)
frontmatter_data['title'] = titlePriority
P1 - Affects production stability and resource usage
Related Issues
- fix: preserve permalink when editing notes without frontmatter permalink #184 - entity.title constraint violations (this is a different manifestation)
- basic-memory-cloud#198 - Memory optimization (infinite retries contribute to memory pressure)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
claude commentedon Oct 17, 2025
Claude finished @phernandez's task —— View job
Issue Triage Complete ✓
Classification:
Analysis:
I've analyzed the issue and traced through the code. The root cause is subtle:
Current Behavior:
EntityParser.parse_file_content()(line 133) sets a default title:This works when
titlekey is missing entirely.However, when frontmatter has
title:with empty value,title: null, ortitle: "", theget()returns the falsy value (not the default), sometadata["title"]becomesNoneor"".This gets passed through to
entity_model_from_markdown()which blindly uses it:Database insert fails:
NOT NULL constraint failed: entity.titleCircuit breaker doesn't trigger because each 30-second sync cycle treats the file as a fresh attempt, not a retry of the same operation.
The Fix:
The issue author's suggested approach is correct. We need to handle empty/null title values at parsing time:
Related Issues:
Would you like me to implement this fix? I can:
Let me know if you'd like me to proceed with the implementation!
Labels Applied: bug
phernandez commentedon Oct 22, 2025
@claude can you confirm the fix for this has been implemented and merged?
claude commentedon Oct 22, 2025
Claude finished @phernandez's task —— View job
Implementation Status Confirmed ✓
Summary
Yes, the fix has been implemented and merged to main! ✓
Evidence
1. Code Implementation (
src/basic_memory/markdown/entity_parser.py:132-138):2. Comprehensive Test Coverage (
tests/markdown/test_entity_parser_error_handling.py):test_parse_file_with_null_title(line 187) - Handlestitle: nulltest_parse_file_with_empty_title(line 212) - Handlestitle:(empty)test_parse_file_with_string_none_title(line 238) - Handlestitle: "None"test_parse_file_with_empty_frontmatter(line 111) - Handles missing title entirely3. Current Status:
mainand current branch are at commitc7e6eabHow It Works
When a file has a missing, null, empty, or string "None" title:
Resolution
The issue described in #381 has been fully resolved. Files with problematic title fields will now:
Issue #381 can be closed as completed.
View job • Branch:
claude/issue-381-20251022-1947