gastownhall/beads · error
failed to get current commit for state: %w
Error message
failed to get current commit for state: %w
What it means
During 'bd backup' export, after creating the backup, the code reads the current Dolt commit hash via store.GetCurrentCommit(ctx) to record it as a watermark in the backup state. If that read fails, the export is aborted and this wrapped error is returned. It indicates the Dolt storage layer could not report its HEAD commit despite the backup itself succeeding up to that point.
Source
Thrown at cmd/bd/backup_export.go:175
// interval (checked by maybeAutoBackup via state.Timestamp)
// applies to the next command. Without this, a sync that keeps
// failing — e.g. a slow/overloaded shared Dolt server — retries
// on EVERY bd command instead of once per interval, turning a
// transient slowdown into a self-amplifying storm (the 2026-07
// shared-dolt CPU-pin incident). LastDoltCommit is deliberately
// left unchanged so change-detection still sees pending work and
// a real backup runs once the failure clears.
state.Timestamp = time.Now().UTC()
if saveErr := saveBackupState(dir, state); saveErr != nil {
debug.Logf("backup: failed to persist throttle state after error: %v\n", saveErr)
}
return nil, err
}
// Update watermarks
currentCommit, err := store.GetCurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
}
state.LastDoltCommit = currentCommit
state.Timestamp = time.Now().UTC()
if err := saveBackupState(dir, state); err != nil {
return nil, err
}
return state, nil
}
// truncateHash returns the first 8 characters of a hash, or the full string if shorter.
func truncateHash(h string) string {
if len(h) > 8 {
return h[:8]
}
return h
}View on GitHub (pinned to 71377f2769)
Solutions
- Inspect the wrapped underlying error (%w) for the actual Dolt/driver failure and fix that first
- Run 'bd dolt' style checks or re-initialize the database: ensure at least one commit exists (bd init / a sync creates commits)
- Delete or repair the corrupted .beads/dolt state and restore from a previous backup
- If auto-backup keeps failing, fix the DB then run 'bd backup sync' manually to refresh watermarks
Example fix
// before
state.LastDoltCommit = state.LastDoltCommit // stale value on failure
// after
currentCommit, err := store.GetCurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
}
state.LastDoltCommit = currentCommit Defensive patterns
Strategy: retry
Validate before calling
// ensure the DB has at least one commit before backup
if out, err := exec.Command("bd", "list", "--limit", "1").Output(); err != nil || len(out) == 0 {
return fmt.Errorf("database has no commits; run bd init / bd sync first")
} Type guard
if store == nil || store.GetCurrentCommit == nil { /* cannot read commit watermark */ } Try / catch
currentCommit, err := store.GetCurrentCommit(ctx)
if err != nil {
var derr *driver.Error
if errors.As(err, &derr) { /* repair/reinit DB */ }
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
} Prevention
- Never back up a workspace that has never been committed; run bd init + a sync first
- Monitor disk health and Dolt directory integrity on backup hosts
- Retry transient commit-read failures with backoff before failing the backup
- Keep watermarks optional so a watermark read failure can degrade to a warning
When it happens
Trigger: store.GetCurrentCommit(ctx) returns an error inside runBackupExport, e.g. the Dolt database has no commits (empty/uninitialized dolt_dir), the Dolt session/engine is corrupted, or an underlying SQL/driver failure occurs while querying the commit log. Called from maybeAutoBackup and tests like TestRunBackupExport_PersistsThrottleOnFailure.
Common situations: Backing up a beads workspace whose .beads database directory exists but has never been committed; disk corruption or partial clone leaving the Dolt log unreadable; transient driver/IO errors during auto-backup after sync.
Related errors
- storage backend does not support backup operations
- no storage backend is open
- no backup destination configured
- failed to remove backup: %w
- failed to get current commit: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/18b44a171c37cf41.
Report an issue: GitHub.