fix(sync): prevent daemon race condition from dirtying working directory

After bd sync completes with sync.branch mode, the daemon or next CLI
command could see a hash mismatch between the restored JSONL file and
the DB metadata, triggering auto-import which then schedules re-export,
dirtying the working directory.

Two fixes:
1. sync.go: Update jsonl_content_hash after restoreBeadsDirFromBranch
   to match the restored file hash
2. daemon_sync.go: Update jsonl_content_hash after performAutoImport
   succeeds (was missing, unlike CLI import path)

Fixes: bd-lw0x, bd-hxou

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-13 06:45:13 -08:00
parent 7d35f9b196
commit 97500a8de0
2 changed files with 21 additions and 0 deletions

View File

@@ -598,6 +598,18 @@ func performAutoImport(ctx context.Context, store storage.Storage, skipGit bool,
return
}
// Update jsonl_content_hash after successful import to prevent repeated imports
// Uses repoKey for multi-repo support (bd-ar2.10, bd-ar2.11)
hashKey := "jsonl_content_hash"
if repoKey != "" {
hashKey += ":" + repoKey
}
if currentHash, err := computeJSONLHash(jsonlPath); err == nil {
if err := store.SetMetadata(importCtx, hashKey, currentHash); err != nil {
log.log("Warning: failed to update %s after import: %v", hashKey, err)
}
}
if skipGit {
log.log("Local auto-import complete")
} else {