fix(bd-53c): Add reverse ZFC check to prevent stale DB from corrupting JSONL

Root cause: bd sync exports DB to JSONL BEFORE pulling from remote.
If the local DB is stale (fewer issues than JSONL), the stale data gets
exported and committed, potentially corrupting the remote when pushed.

The existing ZFC (Zero-Fill Check) only detected when DB had MORE issues
than JSONL, missing the dangerous reverse case.

Fix: Added "reverse ZFC" check in sync.go that detects when JSONL has
significantly more issues than DB (>20% divergence or empty DB).
When detected, it imports JSONL first to sync the database before
any export occurs.

This prevents stale/fresh clones from exporting their incomplete
database state over a well-populated JSONL file.

Version bump: 0.26.0 -> 0.26.1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-29 17:01:36 -08:00
parent 5a0d6db4dd
commit 340016c9c6
4 changed files with 53 additions and 27 deletions

View File

@@ -180,8 +180,9 @@ func validatePreExport(ctx context.Context, store storage.Storage, jsonlPath str
return fmt.Errorf("refusing to export empty DB over %d issues in JSONL (would cause data loss)", jsonlCount)
}
// Note: ZFC (JSONL First Consistency - bd-l0r) is now enforced in sync.go
// by always importing before export. This validation is kept for direct bd export calls.
// Note: The main bd-53c protection is the reverse ZFC check in sync.go
// which runs BEFORE this validation. Here we only block empty DB.
// This allows legitimate deletions while sync.go catches stale DBs.
return nil
}