-
Notifications
You must be signed in to change notification settings - Fork 149
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