fix: sync --import-only fails with "no database store available" when daemon was connected

When running `bd sync --import-only` while the daemon is connected, the command
fails with "no database store available for inline import".

Root cause:
1. PersistentPreRun connects to daemon and returns early without initializing
   the store global
2. sync command closes the daemon connection (for consistency)
3. sync --import-only calls importFromJSONLInline which requires store != nil
4. Without ensureStoreActive(), the store is never initialized after daemon disconnect

Fix: Call ensureStoreActive() after closing the daemon connection in sync.go.
This ensures the local SQLite store is initialized for all sync operations
that need direct database access.

- Add ensureStoreActive() call after daemon disconnect in sync.go
- Add test documenting the bug and verifying the fix

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Juan Reyero
2026-01-09 12:02:02 +01:00
parent 2ee0995f51
commit b27d00ac89
2 changed files with 143 additions and 0 deletions

View File

@@ -71,6 +71,14 @@ Use --merge to merge the sync branch back to main branch.`,
daemonClient = nil
}
// Initialize local store after daemon disconnect.
// When daemon was connected, PersistentPreRun returns early without initializing
// the store global. Commands like --import-only need the store, so we must
// initialize it here after closing the daemon connection.
if err := ensureStoreActive(); err != nil {
FatalError("failed to initialize store: %v", err)
}
// Resolve noGitHistory based on fromMain (fixes #417)
noGitHistory = resolveNoGitHistoryForFromMain(fromMain, noGitHistory)