From 9dff345e7a1f6888fd9d3df65da03e3fa97e5adb Mon Sep 17 00:00:00 2001 From: Matteo Landi Date: Wed, 12 Nov 2025 19:37:32 +0100 Subject: [PATCH] Fix: Update DB mtime after import even with 0 changes (#296) When bd import finds no changes (0 created, 0 updated), it now updates the database modification timestamp to signal sync validation passed. This fixes 'bd sync' refusing to export with 'JSONL is newer than database' error that occurs after git pull updates JSONL mtime without content changes. Root cause: Import validated DB/JSONL are in sync but didn't update DB mtime, causing timestamp-based sync validation to perpetually fail. Amp-Thread-ID: https://ampcode.com/threads/T-560b9c11-e368-45e6-b1e3-512b6d6010a1 Co-authored-by: Amp --- cmd/bd/import.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/bd/import.go b/cmd/bd/import.go index b9377ed3..ab3b452a 100644 --- a/cmd/bd/import.go +++ b/cmd/bd/import.go @@ -309,12 +309,13 @@ NOTE: Import requires direct database access and does not work with daemon mode. } // Update database mtime to reflect it's now in sync with JSONL - // This prevents bd doctor from incorrectly warning that JSONL is newer - // Only touch if actual changes were made (not dry-run, not unchanged-only) - if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 { - if err := touchDatabaseFile(dbPath, input); err != nil { - debug.Logf("Warning: failed to update database mtime: %v", err) - } + // This is CRITICAL even when import found 0 changes, because: + // 1. Import validates DB and JSONL are in sync (no content divergence) + // 2. Without mtime update, bd sync refuses to export (thinks JSONL is newer) + // 3. This can happen after git pull updates JSONL mtime but content is identical + // Fix for: refusing to export: JSONL is newer than database (import first to avoid data loss) + if err := touchDatabaseFile(dbPath, input); err != nil { + debug.Logf("Warning: failed to update database mtime: %v", err) } // Print summary