Fix bd-khnb: Prevent auto-import from resurrecting deleted issues
Replace mtime-based staleness detection with content-based (SHA256 hash) to prevent git operations from resurrecting deleted issues. **Problem:** Auto-import used file modification time to detect if JSONL was "newer" than database. Git operations (checkout, merge, pull) restore old files with recent mtimes, causing auto-import to load stale data over current database state, resurrecting deleted issues. **Solution:** - Added computeJSONLHash() to compute SHA256 of JSONL content - Added hasJSONLChanged() with two-tier check: 1. Fast-path: Check mtime first (99% of checks are instant) 2. Slow-path: Compute hash only if mtime changed (catches git operations) - Store metadata: last_import_hash, last_import_mtime, last_import_time - Updated auto-import in daemon_sync.go to use content-based check - Updated validatePreExport to use content-based check (bd-xwo) - Graceful degradation: metadata failures are non-fatal warnings **Changes:** - cmd/bd/integrity.go: Add computeJSONLHash(), hasJSONLChanged() - cmd/bd/integrity_test.go: Add comprehensive tests for new functions - cmd/bd/import.go: Update metadata after import - cmd/bd/sync.go: Use hasJSONLChanged() instead of isJSONLNewer() - cmd/bd/daemon_sync.go: Use hasJSONLChanged() in auto-import **Testing:** - Unit tests pass (TestHasJSONLChanged with 7 scenarios) - Integration test passes (test_bd_khnb_fix.sh) - Verified git resurrection scenario prevented Fixes: bd-khnb Related: bd-3bg, bd-xwo, bd-39o, bd-56p, bd-m8t, bd-rfj, bd-t5o 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -385,26 +385,13 @@ func createAutoImportFunc(ctx context.Context, store storage.Storage, log daemon
|
||||
log.log("Removed stale lock (%s), proceeding", holder)
|
||||
}
|
||||
|
||||
// Check JSONL modification time to avoid redundant imports
|
||||
jsonlInfo, err := os.Stat(jsonlPath)
|
||||
if err != nil {
|
||||
log.log("Failed to stat JSONL: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get database modification time
|
||||
dbPath := filepath.Join(beadsDir, "beads.db")
|
||||
dbInfo, err := os.Stat(dbPath)
|
||||
if err != nil {
|
||||
log.log("Failed to stat database: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Skip if JSONL is older than database (nothing new to import)
|
||||
if !jsonlInfo.ModTime().After(dbInfo.ModTime()) {
|
||||
log.log("Skipping import: JSONL not newer than database")
|
||||
// Check JSONL content hash to avoid redundant imports
|
||||
// Use content-based check (not mtime) to avoid git resurrection bug (bd-khnb)
|
||||
if !hasJSONLChanged(importCtx, store, jsonlPath) {
|
||||
log.log("Skipping import: JSONL content unchanged")
|
||||
return
|
||||
}
|
||||
log.log("JSONL content changed, proceeding with import...")
|
||||
|
||||
// Pull from git (try sync branch first)
|
||||
pulled, err := syncBranchPull(importCtx, store, log)
|
||||
|
||||
Reference in New Issue
Block a user