gastownhall/beads · critical
failed to initialize database: %w
Error message
failed to initialize database: %w
What it means
After deleting the old database in option [2], the fix re-creates it in-process via `dolt.NewFromConfig(ctx, beadsDir)`, which initializes a fresh Dolt store and auto-bootstraps issues from `.beads/issues.jsonl`. If store creation or bootstrap fails, the error is wrapped as `failed to initialize database: %w`. At this point the old database is already removed, so recovery depends on the JSONL export.
Source
Thrown at cmd/bd/doctor/fix/repo_fingerprint.go:175
fmt.Printf(" → Removing %s...\n", dbPath)
if isDolt {
if err := os.RemoveAll(dbPath); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove Dolt database: %w", err)
}
} else {
if err := os.Remove(dbPath); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove database: %w", err)
}
_ = os.Remove(dbPath + "-wal")
_ = os.Remove(dbPath + "-shm")
}
// Reinitialize by creating a new store (auto-bootstraps from JSONL)
fmt.Println(" → Reinitializing database from JSONL...")
ctx := context.Background()
store, err := dolt.NewFromConfig(ctx, beadsDir)
if err != nil {
return fmt.Errorf("failed to initialize database: %w", err)
}
defer func() { _ = store.Close() }()
fmt.Println(" ✓ Database reinitialized")
return nil
case "s", "":
fmt.Println(" → Skipped")
return nil
default:
fmt.Printf(" → Unrecognized input '%s', skipping\n", response)
return nil
}
}
View on GitHub (pinned to 71377f2769)
Solutions
- Check `.beads/issues.jsonl` exists and is valid JSONL — it is the bootstrap source for the new database.
- Free disk space and ensure `.beads` is writable, then re-run the fix (or any bd command that re-initializes the store).
- Inspect the wrapped error from `dolt.NewFromConfig` for the precise cause (config parse, IO, bootstrap) and fix accordingly.
- If the JSONL is stale, restore the database from git history or a Dolt remote (`bd dolt pull`) instead of reinitializing.
Example fix
# before: stale/missing export leaves an empty or failing reinit ls .beads/issues.jsonl # missing or truncated # after: restore the export from git, then retry git checkout -- .beads/issues.jsonl bd doctor --fix --yes
Defensive patterns
Strategy: fallback
Validate before calling
jsonl := filepath.Join(beadsDir, "issues.jsonl")
info, err := os.Stat(jsonl)
if err != nil {
return fmt.Errorf("bootstrap export missing: %w", err)
}
if info.Size() == 0 {
return errors.New("issues.jsonl is empty; restore from git or dolt remote before reinit")
}
if avail := freeDisk(beadsDir); avail < 64*1024*1024 {
return errors.New("insufficient disk space for reinitialization")
} Try / catch
if err := fix.RepoFingerprint(path, true); err != nil && strings.Contains(err.Error(), "failed to initialize database") {
// old DB is gone; recover from export or remote
_ = exec.Command("git", "checkout", "--", ".beads/issues.jsonl").Run()
_ = exec.Command("bd", "dolt", "pull").Run()
// retry initialization before giving up
if err2 := fix.RepoFingerprint(path, true); err2 != nil {
log.Fatalf("reinit failed after recovery attempt: %v", err2)
}
} Prevention
- Always keep `.beads/issues.jsonl` committed and current before running destructive fixes.
- Run `bd dolt push` so a remote copy exists as a recovery path before deleting the database.
- Verify free disk space and .beads writability before choosing option [2].
- Take a backup (`cp -a .beads .beads.bak`) before any fix that deletes the database.
When it happens
Trigger: `dolt.NewFromConfig` fails right after the old DB was deleted: corrupt or missing `.beads/issues.jsonl` to bootstrap from, `.beads` not writable, disk full, corrupted Dolt config in `.beads`, or leftover Dolt metadata/locks confusing initialization.
Common situations: User deleted the database with a stale or never-synced issues.jsonl (data loss risk); .beads directory made read-only mid-flow; interrupted previous init leaving partial Dolt files; out-of-disk during re-initialization.
Related errors
- schema: capture fresh-bootstrap identity: %w
- schema: verify fresh-bootstrap history: %w
- schema: verify fresh-bootstrap history: got %d commits, want
- schema: verify fresh-bootstrap working set: %w
- schema: verify fresh-bootstrap working set: got %d dirty ent
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/93768f63b6c3ad61.
Report an issue: GitHub.