fix: Fix daemon export leaving JSONL newer than database (issues #301, #321)

After daemon auto-export, JSONL mtime could be newer than database mtime
due to SQLite WAL mode not updating beads.db until checkpoint. This caused
validatePreExport to incorrectly block subsequent exports with "JSONL is
newer than database" error, leading to daemon shutdown.

Solution: Call TouchDatabaseFile after all export operations to ensure
database mtime >= JSONL mtime. This prevents false positives in validation
This commit is contained in:
Charles P. Cross
2025-11-18 17:25:32 -05:00
parent aeea3532cd
commit 04a1996fd9
6 changed files with 298 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ import (
"time"
)
// TestTouchDatabaseFile verifies the touchDatabaseFile helper function
// TestTouchDatabaseFile verifies the TouchDatabaseFile helper function
func TestTouchDatabaseFile(t *testing.T) {
tmpDir := t.TempDir()
testFile := filepath.Join(tmpDir, "test.db")
@@ -27,8 +27,8 @@ func TestTouchDatabaseFile(t *testing.T) {
time.Sleep(1 * time.Second)
// Touch the file
if err := touchDatabaseFile(testFile, ""); err != nil {
t.Fatalf("touchDatabaseFile failed: %v", err)
if err := TouchDatabaseFile(testFile, ""); err != nil {
t.Fatalf("TouchDatabaseFile failed: %v", err)
}
// Get new mtime
@@ -64,8 +64,8 @@ func TestTouchDatabaseFileWithClockSkew(t *testing.T) {
}
// Touch the DB file with JSONL path
if err := touchDatabaseFile(dbFile, jsonlFile); err != nil {
t.Fatalf("touchDatabaseFile failed: %v", err)
if err := TouchDatabaseFile(dbFile, jsonlFile); err != nil {
t.Fatalf("TouchDatabaseFile failed: %v", err)
}
// Get DB mtime