fix: Use filesystem timestamps for entity sync instead of database operation time (#138)#369
Conversation
…eration time (#138) Modified sync_service.py to capture and use actual file modification times (st_mtime) and creation times (st_ctime) from the filesystem instead of using datetime.now() when syncing entities. This ensures that the updated_at and created_at fields in the database reflect when files were actually modified on disk, not when the database operation occurred. Changes: - sync_markdown_file: Capture file timestamps and update entity with them - sync_regular_file: Capture file mtime when updating existing files - Added comprehensive test to validate timestamp preservation on file modification This fix ensures accurate temporal ordering in search and recent_activity queries, resolving the issue where modified times showed as db creation dates in the cloud. Signed-off-by: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task —— View job Code Review Complete ✅I've completed a thorough review of PR #369 against the Basic Memory team checklist. Here are my findings: ✅ Code Quality & StandardsPasses all requirements:
✅ Testing & DocumentationExcellent test coverage:
Documentation:
✅ Basic Memory ArchitectureMaintains architectural integrity:
Implementation quality:
✅ Security & PerformanceNo security concerns:
Performance considerations:
🎯 Specific Code Review Commentssrc/basic_memory/sync/sync_service.pyLines 550-553 - Excellent placement: # Get file timestamps for tracking modification times
file_stats = self.file_service.file_stats(path)
created = datetime.fromtimestamp(file_stats.st_ctime).astimezone()
modified = datetime.fromtimestamp(file_stats.st_mtime).astimezone()✅ Good: Captures timestamps early, before any file modifications Lines 593-597 - Critical fix for markdown files: # Update checksum and timestamps from file system
# This ensures temporal ordering in search and recent activity uses actual file modification times
await self.entity_repository.update(
entity.id, {"checksum": final_checksum, "created_at": created, "updated_at": modified}
)✅ Good: Updates both created_at and updated_at consistently Lines 670-682 - Critical fix for regular files (was missing!): # Get file timestamps for updating modification time
file_stats = self.file_service.file_stats(path)
modified = datetime.fromtimestamp(file_stats.st_mtime).astimezone()
# Update checksum and modification time from file system
updated = await self.entity_repository.update(
entity.id, {"file_path": path, "checksum": checksum, "updated_at": modified}
)✅ Good: Now captures filesystem mtime when updating existing files tests/sync/test_sync_service.pyLines 648-730 - Comprehensive test: tests/markdown/test_entity_parser_error_handling.pyLines 1-2 - Minor cleanup (unrelated): -import pytest
from textwrap import dedent
+import pytest✅ Good: Import ordering fix (consistent with style guide) 📋 Checklist SummaryCode Quality & Standards
Testing & Documentation
Basic Memory Architecture
Security & Performance
🎉 Final AssessmentAPPROVED ✅ This is an excellent fix that directly addresses issue #138. The implementation is:
The code quality is high, follows all project conventions, and the test coverage is thorough. No issues found. Recommendation: Ready to merge 🚀 --- | Branch: |
Summary
Fixes issue #138 from basic-memory-cloud where modified times were showing as the database creation date in the cloud instead of actual file modification times.
Root Cause
The sync service was using
datetime.now()(database operation time) instead of capturing filesystem timestamps when syncing files. This affected:updated_atwasn't refreshed with the file's actual modification time when re-syncing modified filesChanges Made
src/basic_memory/sync/sync_service.py:st_mtimeandst_ctimefor markdown filescreated_atandupdated_atfields with filesystem timestampstests/sync/test_sync_service.py:test_sync_updates_timestamps_on_file_modificationthat validates:updated_atmatches file's modification time, not db operation timeImpact
This fix ensures that temporal ordering in search and recent_activity queries accurately reflects when files were actually modified on the filesystem, not when they were processed by the database.
Test Plan
test_sync_preserves_timestampscontinues to pass (validates new files)🤖 Generated with Claude Code