fix: staleness check fails after write in git worktrees (#399)
After write operations in git worktrees, subsequent reads failed with "Database out of sync with JSONL" even though the hash check passed. Root cause: flushToJSONLWithState() updated last_import_hash but not last_import_time after export. CheckStaleness() compares last_import_time against JSONL mtime, so after export the JSONL appeared "newer" than the last import. Additional issue: RFC3339 only has second precision but file mtimes have nanosecond precision, causing false positives when times were within the same second. Fix: - Update last_import_time after export in flushToJSONLWithState() - Use RFC3339Nano format for nanosecond precision - Update CheckStaleness() to parse both formats for backward compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -274,10 +274,15 @@ func CheckStaleness(ctx context.Context, store storage.Storage, dbPath string) (
|
||||
return false, nil
|
||||
}
|
||||
|
||||
lastImportTime, err := time.Parse(time.RFC3339, lastImportStr)
|
||||
// Try RFC3339Nano first (has nanosecond precision), fall back to RFC3339
|
||||
// This supports both old timestamps (RFC3339) and new ones with nanoseconds (fixes #399)
|
||||
lastImportTime, err := time.Parse(time.RFC3339Nano, lastImportStr)
|
||||
if err != nil {
|
||||
// Corrupted metadata - this is abnormal and should be reported
|
||||
return false, fmt.Errorf("corrupted last_import_time in metadata (cannot parse as RFC3339): %w", err)
|
||||
lastImportTime, err = time.Parse(time.RFC3339, lastImportStr)
|
||||
if err != nil {
|
||||
// Corrupted metadata - this is abnormal and should be reported
|
||||
return false, fmt.Errorf("corrupted last_import_time in metadata (cannot parse as RFC3339): %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Find JSONL using database directory
|
||||
|
||||
Reference in New Issue
Block a user