From c6f9f7ee052c8ab4c30745a69af2d1086206b312 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Mon, 24 Nov 2025 23:57:42 -0800 Subject: [PATCH] fix: prevent ZFC resurrection by propagating skipExport flag (with debug) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cmd/bd/sync.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index 40dda36a..b013ea9c 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -300,20 +300,24 @@ Use --merge to merge the sync branch back to main branch.`, } } - // Post-pull ZFC check (bd-l0r fix): if DB has significantly more issues - // than pulled JSONL, trust JSONL as source of truth and skip re-export. + // Post-pull ZFC check: if skipExport was set by initial ZFC detection, + // or if DB has more issues than JSONL, skip re-export. // This prevents resurrection of deleted issues when syncing stale clones. - skipReexport := false - if err := ensureStoreActive(); err == nil && store != nil { - dbCountPostImport, dbErr := countDBIssuesFast(ctx, store) - jsonlCountPostPull, jsonlErr := countIssuesInJSONL(jsonlPath) - if dbErr == nil && jsonlErr == nil && jsonlCountPostPull > 0 { - if dbCountPostImport > jsonlCountPostPull*2 { // DB has >2x issues - fmt.Printf("→ DB (%d) has >2x more issues than JSONL (%d) after pull\n", - dbCountPostImport, jsonlCountPostPull) - fmt.Println("→ Trusting JSONL as source of truth (skipping re-export)") - fmt.Println(" Hint: Run 'bd import --delete-missing' to fully sync DB with JSONL") - skipReexport = true + skipReexport := skipExport // Carry forward initial ZFC detection + fmt.Printf("DEBUG: skipExport=%v, skipReexport=%v\n", skipExport, skipReexport) + if !skipReexport { + if err := ensureStoreActive(); err == nil && store != nil { + dbCountPostImport, dbErr := countDBIssuesFast(ctx, store) + jsonlCountPostPull, jsonlErr := countIssuesInJSONL(jsonlPath) + if dbErr == nil && jsonlErr == nil && jsonlCountPostPull > 0 { + // Skip re-export if DB has more issues than JSONL (any amount) + if dbCountPostImport > jsonlCountPostPull { + fmt.Printf("→ DB (%d) has more issues than JSONL (%d) after pull\n", + dbCountPostImport, jsonlCountPostPull) + fmt.Println("→ Trusting JSONL as source of truth (skipping re-export)") + fmt.Println(" Hint: Run 'bd import --delete-missing' to fully sync DB with JSONL") + skipReexport = true + } } } }