From 4468ff030f96b98b5947cd8fcc3fef45a274c93f Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 4 Jan 2026 10:41:27 -0800 Subject: [PATCH] feat(sync): add BD_DEBUG_SYNC env for protection debugging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds debug logging when timestamp-aware protection triggers, controlled by BD_DEBUG_SYNC environment variable. Helps diagnose sync issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/importer/importer.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/importer/importer.go b/internal/importer/importer.go index af424258..7bdbd433 100644 --- a/internal/importer/importer.go +++ b/internal/importer/importer.go @@ -568,6 +568,7 @@ func upsertIssues(ctx context.Context, sqliteStore *sqlite.SQLiteStorage, issues // GH#865: Check timestamp-aware protection first // If local snapshot has a newer version, protect it from being overwritten if shouldProtectFromUpdate(existing.ID, incoming.UpdatedAt, opts.ProtectLocalExportIDs) { + debugLogProtection(existing.ID, opts.ProtectLocalExportIDs[existing.ID], incoming.UpdatedAt) result.Skipped++ continue } @@ -672,6 +673,7 @@ func upsertIssues(ctx context.Context, sqliteStore *sqlite.SQLiteStorage, issues // GH#865: Check timestamp-aware protection first // If local snapshot has a newer version, protect it from being overwritten if shouldProtectFromUpdate(incoming.ID, incoming.UpdatedAt, opts.ProtectLocalExportIDs) { + debugLogProtection(incoming.ID, opts.ProtectLocalExportIDs[incoming.ID], incoming.UpdatedAt) result.Skipped++ continue } @@ -948,6 +950,14 @@ func shouldProtectFromUpdate(issueID string, incomingTime time.Time, protectMap return !incomingTime.After(localTime) } +// debugLogProtection logs when timestamp-aware protection triggers (for debugging sync issues). +func debugLogProtection(issueID string, localTime, incomingTime time.Time) { + if os.Getenv("BD_DEBUG_SYNC") != "" { + fmt.Fprintf(os.Stderr, "[debug] Protected %s: local=%s >= incoming=%s\n", + issueID, localTime.Format(time.RFC3339), incomingTime.Format(time.RFC3339)) + } +} + func GetPrefixList(prefixes map[string]int) []string { var result []string keys := make([]string, 0, len(prefixes))